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.
This commit is contained in:
Max Kellermann
2009-03-08 13:45:24 +01:00
parent 359f9871b2
commit 94d1a87d04
5 changed files with 89 additions and 0 deletions

View File

@@ -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;