aboutsummaryrefslogtreecommitdiffstats
path: root/src/pipe.c
diff options
context:
space:
mode:
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;