aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipe.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/pipe.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 '')
-rw-r--r--src/pipe.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/pipe.c b/src/pipe.c
index c433aa254..fe011f3c2 100644
--- a/src/pipe.c
+++ b/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;