aboutsummaryrefslogtreecommitdiffstats
path: root/src/chunk.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-08 13:45:24 +0100
committerMax Kellermann <max@duempel.org>2009-03-08 13:45:24 +0100
commit94d1a87d0432d885756f9d23cfba1f8229cfe453 (patch)
tree1c5358045a47e07556c8476cefb8c33181e567fd /src/chunk.c
parent359f9871b230b0f3e986ea7fb30e93b9730b683b (diff)
downloadmpd-94d1a87d0432d885756f9d23cfba1f8229cfe453.tar.gz
mpd-94d1a87d0432d885756f9d23cfba1f8229cfe453.tar.xz
mpd-94d1a87d0432d885756f9d23cfba1f8229cfe453.zip
music_chunk: added assertions on the audio format
In !NDEBUG, remember which audio_format is stored in every chunk and every pipe. Check the audio_format of every new data block appended to the music_chunk, and the format of every new chunk appended to the music_pipe.
Diffstat (limited to 'src/chunk.c')
-rw-r--r--src/chunk.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/chunk.c b/src/chunk.c
index 65894f733..54fc11d3c 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -36,6 +36,19 @@ music_chunk_free(struct music_chunk *chunk)
tag_free(chunk->tag);
}
+#ifndef NDEBUG
+bool
+music_chunk_check_format(const struct music_chunk *chunk,
+ const struct audio_format *audio_format)
+{
+ assert(chunk != NULL);
+ assert(audio_format != NULL);
+
+ return chunk->length == 0 ||
+ audio_format_equals(&chunk->audio_format, audio_format);
+}
+#endif
+
void *
music_chunk_write(struct music_chunk *chunk,
const struct audio_format *audio_format,
@@ -45,6 +58,8 @@ music_chunk_write(struct music_chunk *chunk,
const size_t frame_size = audio_format_frame_size(audio_format);
size_t num_frames;
+ assert(music_chunk_check_format(chunk, audio_format));
+
if (chunk->length == 0) {
/* if the chunk is empty, nobody has set bitRate and
times yet */
@@ -57,6 +72,10 @@ music_chunk_write(struct music_chunk *chunk,
if (num_frames == 0)
return NULL;
+#ifndef NDEBUG
+ chunk->audio_format = *audio_format;
+#endif
+
*max_length_r = num_frames * frame_size;
return chunk->data + chunk->length;
}
@@ -69,6 +88,7 @@ music_chunk_expand(struct music_chunk *chunk,
assert(chunk != NULL);
assert(chunk->length + length <= sizeof(chunk->data));
+ assert(audio_format_equals(&chunk->audio_format, audio_format));
chunk->length += length;