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:
33
src/pipe.c
33
src/pipe.c
@@ -36,6 +36,10 @@ struct music_pipe {
|
||||
|
||||
/** a mutex which protects #head and #tail_r */
|
||||
GMutex *mutex;
|
||||
|
||||
#ifndef NDEBUG
|
||||
struct audio_format audio_format;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct music_pipe *
|
||||
@@ -48,6 +52,10 @@ music_pipe_new(void)
|
||||
mp->size = 0;
|
||||
mp->mutex = g_mutex_new();
|
||||
|
||||
#ifndef NDEBUG
|
||||
audio_format_clear(&mp->audio_format);
|
||||
#endif
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
@@ -61,6 +69,19 @@ music_pipe_free(struct music_pipe *mp)
|
||||
g_free(mp);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool
|
||||
music_pipe_check_format(const struct music_pipe *pipe,
|
||||
const struct audio_format *audio_format)
|
||||
{
|
||||
assert(pipe != NULL);
|
||||
assert(audio_format != NULL);
|
||||
|
||||
return !audio_format_defined(&pipe->audio_format) ||
|
||||
audio_format_equals(&pipe->audio_format, audio_format);
|
||||
}
|
||||
#endif
|
||||
|
||||
const struct music_chunk *
|
||||
music_pipe_peek(const struct music_pipe *mp)
|
||||
{
|
||||
@@ -94,6 +115,9 @@ music_pipe_shift(struct music_pipe *mp)
|
||||
#ifndef NDEBUG
|
||||
/* poison the "next" reference */
|
||||
chunk->next = (void*)0x01010101;
|
||||
|
||||
if (mp->size == 0)
|
||||
audio_format_clear(&mp->audio_format);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -118,6 +142,15 @@ music_pipe_push(struct music_pipe *mp, struct music_chunk *chunk)
|
||||
|
||||
g_mutex_lock(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));
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!audio_format_defined(&mp->audio_format) && chunk->length > 0)
|
||||
mp->audio_format = chunk->audio_format;
|
||||
#endif
|
||||
|
||||
chunk->next = NULL;
|
||||
*mp->tail_r = chunk;
|
||||
mp->tail_r = &chunk->next;
|
||||
|
Reference in New Issue
Block a user