aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-04 21:38:46 +0100
committerMax Kellermann <max@duempel.org>2013-01-04 21:38:46 +0100
commite9b71a0d2846321dcf3f985b9f6332d051374edd (patch)
treecc916958e67731f68e496459383a913e28509bda
parentefbfe66f21a8865454bc7a9e32305c84c09ba4be (diff)
MusicChunk: move functions to methods
-rw-r--r--src/DecoderAPI.cxx10
-rw-r--r--src/DecoderInternal.cxx2
-rw-r--r--src/MusicChunk.cxx68
-rw-r--r--src/MusicChunk.hxx97
-rw-r--r--src/MusicPipe.cxx6
-rw-r--r--src/OutputAll.cxx2
-rw-r--r--src/OutputThread.cxx4
-rw-r--r--src/PlayerThread.cxx4
8 files changed, 89 insertions, 104 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx
index 015d64d2..9ea22200 100644
--- a/src/DecoderAPI.cxx
+++ b/src/DecoderAPI.cxx
@@ -429,10 +429,10 @@ decoder_data(struct decoder *decoder,
return dc->command;
}
- void *dest = music_chunk_write(chunk, &dc->out_audio_format,
- decoder->timestamp -
- dc->song->start_ms / 1000.0,
- kbit_rate, &nbytes);
+ void *dest = chunk->Write(dc->out_audio_format,
+ decoder->timestamp -
+ dc->song->start_ms / 1000.0,
+ kbit_rate, &nbytes);
if (dest == NULL) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
@@ -451,7 +451,7 @@ decoder_data(struct decoder *decoder,
/* expand the music pipe chunk */
- full = music_chunk_expand(chunk, &dc->out_audio_format, nbytes);
+ full = chunk->Expand(dc->out_audio_format, nbytes);
if (full) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
diff --git a/src/DecoderInternal.cxx b/src/DecoderInternal.cxx
index 00749b89..d68f7856 100644
--- a/src/DecoderInternal.cxx
+++ b/src/DecoderInternal.cxx
@@ -88,7 +88,7 @@ decoder_flush_chunk(struct decoder *decoder)
assert(decoder != NULL);
assert(decoder->chunk != NULL);
- if (music_chunk_is_empty(decoder->chunk))
+ if (decoder->chunk->IsEmpty())
music_buffer_return(dc->buffer, decoder->chunk);
else
music_pipe_push(dc->pipe, decoder->chunk);
diff --git a/src/MusicChunk.cxx b/src/MusicChunk.cxx
index 24f21f66..e79cc3ee 100644
--- a/src/MusicChunk.cxx
+++ b/src/MusicChunk.cxx
@@ -27,79 +27,61 @@ extern "C" {
#include <assert.h>
-void
-music_chunk_init(struct music_chunk *chunk)
+music_chunk::~music_chunk()
{
- chunk->other = NULL;
- chunk->length = 0;
- chunk->tag = NULL;
- chunk->replay_gain_serial = 0;
-}
-
-void
-music_chunk_free(struct music_chunk *chunk)
-{
- if (chunk->tag != NULL)
- tag_free(chunk->tag);
+ if (tag != NULL)
+ tag_free(tag);
}
#ifndef NDEBUG
bool
-music_chunk_check_format(const struct music_chunk *chunk,
- const struct audio_format *audio_format)
+music_chunk::CheckFormat(const struct audio_format &other_format) const
{
- assert(chunk != NULL);
- assert(audio_format != NULL);
- assert(audio_format_valid(audio_format));
+ assert(audio_format_valid(&other_format));
- return chunk->length == 0 ||
- audio_format_equals(&chunk->audio_format, audio_format);
+ return length == 0 ||
+ audio_format_equals(&audio_format, &other_format);
}
#endif
void *
-music_chunk_write(struct music_chunk *chunk,
- const struct audio_format *audio_format,
- float data_time, uint16_t bit_rate,
- size_t *max_length_r)
+music_chunk::Write(const struct audio_format &af,
+ float data_time, uint16_t _bit_rate,
+ size_t *max_length_r)
{
- const size_t frame_size = audio_format_frame_size(audio_format);
- size_t num_frames;
-
- assert(music_chunk_check_format(chunk, audio_format));
- assert(chunk->length == 0 || audio_format_valid(&chunk->audio_format));
+ assert(CheckFormat(af));
+ assert(length == 0 || audio_format_valid(&audio_format));
- if (chunk->length == 0) {
+ if (length == 0) {
/* if the chunk is empty, nobody has set bitRate and
times yet */
- chunk->bit_rate = bit_rate;
- chunk->times = data_time;
+ bit_rate = _bit_rate;
+ times = data_time;
}
- num_frames = (sizeof(chunk->data) - chunk->length) / frame_size;
+ const size_t frame_size = audio_format_frame_size(&af);
+ size_t num_frames = (sizeof(data) - length) / frame_size;
if (num_frames == 0)
return NULL;
#ifndef NDEBUG
- chunk->audio_format = *audio_format;
+ audio_format = af;
#endif
*max_length_r = num_frames * frame_size;
- return chunk->data + chunk->length;
+ return data + length;
}
bool
-music_chunk_expand(struct music_chunk *chunk,
- const struct audio_format *audio_format, size_t length)
+music_chunk::Expand(const struct audio_format &af, size_t _length)
{
- const size_t frame_size = audio_format_frame_size(audio_format);
+ const size_t frame_size = audio_format_frame_size(&af);
- assert(chunk != NULL);
- assert(chunk->length + length <= sizeof(chunk->data));
- assert(audio_format_equals(&chunk->audio_format, audio_format));
+ assert(length + _length <= sizeof(data));
+ assert(audio_format_equals(&audio_format, &af));
- chunk->length += length;
+ length += _length;
- return chunk->length + frame_size > sizeof(chunk->data);
+ return length + frame_size > sizeof(data);
}
diff --git a/src/MusicChunk.hxx b/src/MusicChunk.hxx
index 0ed72006..c03e4551 100644
--- a/src/MusicChunk.hxx
+++ b/src/MusicChunk.hxx
@@ -91,60 +91,63 @@ struct music_chunk {
#ifndef NDEBUG
struct audio_format audio_format;
#endif
-};
-void
-music_chunk_init(struct music_chunk *chunk);
+ music_chunk()
+ :other(nullptr),
+ length(0),
+ tag(nullptr),
+ replay_gain_serial(0) {}
-void
-music_chunk_free(struct music_chunk *chunk);
+ ~music_chunk();
-static inline bool
-music_chunk_is_empty(const struct music_chunk *chunk)
-{
- return chunk->length == 0 && chunk->tag == NULL;
-}
+ bool IsEmpty() const {
+ return length == 0 && tag == nullptr;
+ }
#ifndef NDEBUG
-/**
- * Checks if the audio format if the chunk is equal to the specified
- * audio_format.
- */
-bool
-music_chunk_check_format(const struct music_chunk *chunk,
- const struct audio_format *audio_format);
+ /**
+ * Checks if the audio format if the chunk is equal to the
+ * specified audio_format.
+ */
+ gcc_pure
+ bool CheckFormat(const struct audio_format &audio_format) const;
#endif
-/**
- * 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
- * @return a writable buffer, or NULL if the chunk is full
- */
-void *
-music_chunk_write(struct music_chunk *chunk,
- const struct audio_format *audio_format,
- float data_time, uint16_t bit_rate,
- size_t *max_length_r);
+ /**
+ * 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
+ * @return a writable buffer, or NULL if the chunk is full
+ */
+ void *Write(const struct audio_format &af,
+ float data_time, uint16_t bit_rate,
+ size_t *max_length_r);
-/**
- * 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
- */
-bool
-music_chunk_expand(struct music_chunk *chunk,
- const struct audio_format *audio_format, size_t length);
+ /**
+ * 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
+ */
+ bool Expand(const struct audio_format &af, size_t length);
+};
+
+void
+music_chunk_init(struct music_chunk *chunk);
+
+void
+music_chunk_free(struct music_chunk *chunk);
#endif
diff --git a/src/MusicPipe.cxx b/src/MusicPipe.cxx
index 010da97b..6f25eff8 100644
--- a/src/MusicPipe.cxx
+++ b/src/MusicPipe.cxx
@@ -111,7 +111,7 @@ music_pipe_shift(struct music_pipe *mp)
struct music_chunk *chunk = mp->head;
if (chunk != NULL) {
- assert(!music_chunk_is_empty(chunk));
+ assert(!chunk->IsEmpty());
mp->head = chunk->next;
--mp->size;
@@ -150,14 +150,14 @@ music_pipe_clear(struct music_pipe *mp, struct music_buffer *buffer)
void
music_pipe_push(struct music_pipe *mp, struct music_chunk *chunk)
{
- assert(!music_chunk_is_empty(chunk));
+ assert(!chunk->IsEmpty());
assert(chunk->length == 0 || audio_format_valid(&chunk->audio_format));
const ScopeLock protect(mp->mutex);
assert(mp->size > 0 || !audio_format_defined(&mp->audio_format));
assert(!audio_format_defined(&mp->audio_format) ||
- music_chunk_check_format(chunk, &mp->audio_format));
+ chunk->CheckFormat(mp->audio_format));
#ifndef NDEBUG
if (!audio_format_defined(&mp->audio_format) && chunk->length > 0)
diff --git a/src/OutputAll.cxx b/src/OutputAll.cxx
index 811d93a1..113eca43 100644
--- a/src/OutputAll.cxx
+++ b/src/OutputAll.cxx
@@ -282,7 +282,7 @@ audio_output_all_play(struct music_chunk *chunk, GError **error_r)
assert(g_music_buffer != NULL);
assert(g_mp != NULL);
assert(chunk != NULL);
- assert(music_chunk_check_format(chunk, &input_audio_format));
+ assert(chunk->CheckFormat(input_audio_format));
ret = audio_output_all_update();
if (!ret) {
diff --git a/src/OutputThread.cxx b/src/OutputThread.cxx
index e88efd38..6fddf15d 100644
--- a/src/OutputThread.cxx
+++ b/src/OutputThread.cxx
@@ -327,8 +327,8 @@ ao_chunk_data(struct audio_output *ao, const struct music_chunk *chunk,
size_t *length_r)
{
assert(chunk != NULL);
- assert(!music_chunk_is_empty(chunk));
- assert(music_chunk_check_format(chunk, &ao->in_audio_format));
+ assert(!chunk->IsEmpty());
+ assert(chunk->CheckFormat(ao->in_audio_format));
const void *data = chunk->data;
size_t length = chunk->length;
diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx
index a394b844..624698f5 100644
--- a/src/PlayerThread.cxx
+++ b/src/PlayerThread.cxx
@@ -686,7 +686,7 @@ play_chunk(struct player_control *pc,
const struct audio_format *format,
GError **error_r)
{
- assert(music_chunk_check_format(chunk, format));
+ assert(chunk->CheckFormat(*format));
if (chunk->tag != NULL)
update_song_tag(song, chunk->tag);
@@ -766,7 +766,7 @@ play_next_chunk(struct player *player)
chunk->mix_ratio = nan("");
}
- if (music_chunk_is_empty(other_chunk)) {
+ if (other_chunk->IsEmpty()) {
/* the "other" chunk was a music_chunk
which had only a tag, but no music
data - we cannot cross-fade that;