2009-03-03 22:23:25 +01:00
|
|
|
/*
|
2013-01-04 10:16:16 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-03-03 22:23:25 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-03-03 22:23:25 +01:00
|
|
|
*/
|
|
|
|
|
2013-01-04 10:16:16 +01:00
|
|
|
#ifndef MPD_MUSIC_CHUNK_HXX
|
|
|
|
#define MPD_MUSIC_CHUNK_HXX
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2013-10-02 12:22:12 +02:00
|
|
|
#include "ReplayGainInfo.hxx"
|
2010-02-14 17:04:39 +01:00
|
|
|
|
2009-03-08 13:45:24 +01:00
|
|
|
#ifndef NDEBUG
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2009-03-08 13:45:24 +01:00
|
|
|
#endif
|
|
|
|
|
2009-03-03 22:23:25 +01:00
|
|
|
#include <stdint.h>
|
2009-03-05 17:37:11 +01:00
|
|
|
#include <stddef.h>
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2013-09-26 21:49:26 +02:00
|
|
|
static constexpr size_t CHUNK_SIZE = 4096;
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
struct AudioFormat;
|
2013-07-30 20:11:57 +02:00
|
|
|
struct Tag;
|
2009-03-05 17:37:11 +01:00
|
|
|
|
2009-03-03 22:23:25 +01:00
|
|
|
/**
|
|
|
|
* A chunk of music data. Its format is defined by the
|
2013-09-26 21:51:45 +02:00
|
|
|
* MusicPipe::Push() caller.
|
2009-03-03 22:23:25 +01:00
|
|
|
*/
|
|
|
|
struct music_chunk {
|
2009-03-06 00:42:03 +01:00
|
|
|
/** the next chunk in a linked list */
|
|
|
|
struct music_chunk *next;
|
|
|
|
|
2010-05-02 15:16:59 +02:00
|
|
|
/**
|
|
|
|
* An optional chunk which should be mixed into this chunk.
|
|
|
|
* This is used for cross-fading.
|
|
|
|
*/
|
|
|
|
struct music_chunk *other;
|
|
|
|
|
2010-05-02 15:31:31 +02:00
|
|
|
/**
|
|
|
|
* The current mix ratio for cross-fading: 1.0 means play 100%
|
|
|
|
* of this chunk, 0.0 means play 100% of the "other" chunk.
|
|
|
|
*/
|
|
|
|
float mix_ratio;
|
|
|
|
|
2009-03-03 22:23:25 +01:00
|
|
|
/** number of bytes stored in this chunk */
|
|
|
|
uint16_t length;
|
|
|
|
|
|
|
|
/** current bit rate of the source file */
|
|
|
|
uint16_t bit_rate;
|
|
|
|
|
|
|
|
/** the time stamp within the song */
|
|
|
|
float times;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An optional tag associated with this chunk (and the
|
|
|
|
* following chunks); appears at song boundaries. The tag
|
|
|
|
* object is owned by this chunk, and must be freed when this
|
2013-09-26 22:34:43 +02:00
|
|
|
* chunk is deinitialized.
|
2009-03-03 22:23:25 +01:00
|
|
|
*/
|
2013-07-30 20:11:57 +02:00
|
|
|
Tag *tag;
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2010-02-14 17:04:39 +01:00
|
|
|
/**
|
|
|
|
* Replay gain information associated with this chunk.
|
|
|
|
* Only valid if the serial is not 0.
|
|
|
|
*/
|
2013-10-25 19:09:22 +02:00
|
|
|
ReplayGainInfo replay_gain_info;
|
2010-02-14 17:04:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A serial number for checking if replay gain info has
|
|
|
|
* changed since the last chunk. The magic value 0 indicates
|
|
|
|
* that there is no replay gain info available.
|
|
|
|
*/
|
|
|
|
unsigned replay_gain_serial;
|
|
|
|
|
2009-03-03 22:23:25 +01:00
|
|
|
/** the data (probably PCM) */
|
2013-10-28 17:08:14 +01:00
|
|
|
uint8_t data[CHUNK_SIZE];
|
2009-03-08 13:45:24 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat audio_format;
|
2009-03-08 13:45:24 +01:00
|
|
|
#endif
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2013-01-04 21:38:46 +01:00
|
|
|
music_chunk()
|
|
|
|
:other(nullptr),
|
|
|
|
length(0),
|
|
|
|
tag(nullptr),
|
|
|
|
replay_gain_serial(0) {}
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2013-01-04 21:38:46 +01:00
|
|
|
~music_chunk();
|
2009-03-03 22:23:25 +01:00
|
|
|
|
2013-01-04 21:38:46 +01:00
|
|
|
bool IsEmpty() const {
|
|
|
|
return length == 0 && tag == nullptr;
|
|
|
|
}
|
2009-03-07 21:40:27 +01:00
|
|
|
|
2009-03-08 13:45:24 +01:00
|
|
|
#ifndef NDEBUG
|
2013-01-04 21:38:46 +01:00
|
|
|
/**
|
|
|
|
* Checks if the audio format if the chunk is equal to the
|
|
|
|
* specified audio_format.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2013-08-03 21:00:50 +02:00
|
|
|
bool CheckFormat(AudioFormat audio_format) const;
|
2009-03-08 13:45:24 +01:00
|
|
|
#endif
|
|
|
|
|
2013-01-04 21:38:46 +01:00
|
|
|
/**
|
|
|
|
* Prepares appending to the music chunk. Returns a buffer
|
|
|
|
* where you may write into. After you are finished, call
|
|
|
|
* music_chunk_expand().
|
|
|
|
*
|
|
|
|
* @param chunk the music_chunk object
|
|
|
|
* @param audio_format the audio format for the appended data;
|
|
|
|
* must stay the same for the life cycle of this chunk
|
|
|
|
* @param data_time the time within the song
|
|
|
|
* @param bit_rate the current bit rate of the source file
|
|
|
|
* @param max_length_r the maximum write length is returned
|
|
|
|
* here
|
2013-10-19 18:19:03 +02:00
|
|
|
* @return a writable buffer, or nullptr if the chunk is full
|
2013-01-04 21:38:46 +01:00
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
void *Write(AudioFormat af,
|
2013-01-04 21:38:46 +01:00
|
|
|
float data_time, uint16_t bit_rate,
|
|
|
|
size_t *max_length_r);
|
2009-03-05 17:37:11 +01:00
|
|
|
|
2013-01-04 21:38:46 +01:00
|
|
|
/**
|
|
|
|
* Increases the length of the chunk after the caller has written to
|
|
|
|
* the buffer returned by music_chunk_write().
|
|
|
|
*
|
|
|
|
* @param chunk the music_chunk object
|
|
|
|
* @param audio_format the audio format for the appended data; must
|
|
|
|
* stay the same for the life cycle of this chunk
|
|
|
|
* @param length the number of bytes which were appended
|
|
|
|
* @return true if the chunk is full
|
|
|
|
*/
|
2013-08-03 21:00:50 +02:00
|
|
|
bool Expand(AudioFormat af, size_t length);
|
2013-01-04 21:38:46 +01:00
|
|
|
};
|
|
|
|
|
2009-03-03 22:23:25 +01:00
|
|
|
#endif
|