From 94d1a87d0432d885756f9d23cfba1f8229cfe453 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 8 Mar 2009 13:45:24 +0100 Subject: 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. --- src/chunk.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/chunk.c') 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; -- cgit v1.2.3