]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/play-memblockq.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / play-memblockq.c
index 44aa6bf0ec6a2ce99c8d5c40b75054552a99f5af..ff0c52b26857e0ff0459a6afb04bb8919e6993fc 100644 (file)
@@ -5,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 
 #include <pulse/xmalloc.h>
-#include <pulse/gccmacro.h>
 
 #include <pulsecore/sink-input.h>
 #include <pulsecore/thread-mq.h>
-#include <pulsecore/sample-util.h>
 
 #include "play-memblockq.h"
 
@@ -47,9 +44,8 @@ enum {
     MEMBLOCKQ_STREAM_MESSAGE_UNLINK,
 };
 
-PA_DECLARE_CLASS(memblockq_stream);
+PA_DEFINE_PRIVATE_CLASS(memblockq_stream, pa_msgobject);
 #define MEMBLOCKQ_STREAM(o) (memblockq_stream_cast(o))
-static PA_DEFINE_CHECK_TYPE(memblockq_stream, pa_msgobject);
 
 static void memblockq_stream_unlink(memblockq_stream *u) {
     pa_assert(u);
@@ -109,7 +105,7 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s
      * we are heard right-away. */
     if (PA_SINK_INPUT_IS_LINKED(state) &&
         i->thread_info.state == PA_SINK_INPUT_INIT)
-        pa_sink_input_request_rewind(i, 0, FALSE, TRUE, TRUE);
+        pa_sink_input_request_rewind(i, 0, false, true, true);
 }
 
 static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
@@ -136,6 +132,15 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
         return -1;
     }
 
+    /* If there's no memblock, there's going to be data in the memblockq after
+     * a gap with length chunk->length. Drop the gap and peek the actual
+     * data. There should always be some data coming - hence the assert. The
+     * gap will occur if the memblockq is rewound beyond index 0.*/
+    if (!chunk->memblock) {
+        pa_memblockq_drop(u->memblockq, chunk->length);
+        pa_assert_se(pa_memblockq_peek(u->memblockq, chunk) >= 0);
+    }
+
     chunk->length = PA_MIN(chunk->length, nbytes);
     pa_memblockq_drop(u->memblockq, chunk->length);
 
@@ -174,7 +179,8 @@ pa_sink_input* pa_memblockq_sink_input_new(
         const pa_channel_map *map,
         pa_memblockq *q,
         pa_cvolume *volume,
-        pa_proplist *p) {
+        pa_proplist *p,
+        pa_sink_input_flags_t flags) {
 
     memblockq_stream *u = NULL;
     pa_sink_input_new_data data;
@@ -193,14 +199,15 @@ pa_sink_input* pa_memblockq_sink_input_new(
     u->memblockq = NULL;
 
     pa_sink_input_new_data_init(&data);
-    data.sink = sink;
+    pa_sink_input_new_data_set_sink(&data, sink, false);
     data.driver = __FILE__;
     pa_sink_input_new_data_set_sample_spec(&data, ss);
     pa_sink_input_new_data_set_channel_map(&data, map);
     pa_sink_input_new_data_set_volume(&data, volume);
     pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p);
+    data.flags |= flags;
 
-    pa_sink_input_new(&u->sink_input, sink->core, &data, 0);
+    pa_sink_input_new(&u->sink_input, sink->core, &data);
     pa_sink_input_new_data_done(&data);
 
     if (!u->sink_input)
@@ -238,6 +245,7 @@ int pa_play_memblockq(
         pa_memblockq *q,
         pa_cvolume *volume,
         pa_proplist *p,
+        pa_sink_input_flags_t flags,
         uint32_t *sink_input_index) {
 
     pa_sink_input *i;
@@ -246,7 +254,7 @@ int pa_play_memblockq(
     pa_assert(ss);
     pa_assert(q);
 
-    if (!(i = pa_memblockq_sink_input_new(sink, ss, map, q, volume, p)))
+    if (!(i = pa_memblockq_sink_input_new(sink, ss, map, q, volume, p, flags)))
         return -1;
 
     pa_sink_input_put(i);