]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/play-memblockq.c
Use LGPL 2.1 on all files previously using LGPL 2
[pulseaudio] / src / pulsecore / play-memblockq.c
index 3d435c8b23ef3ca097f237c20974d8d6360118c4..fceb2ca146cbc102c7e9e99715e75a11facb54f0 100644 (file)
@@ -1,13 +1,11 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
-  Copyright 2006 Lennart Poettering
+  Copyright 2006-2008 Lennart Poettering
 
   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
@@ -99,6 +97,21 @@ static void sink_input_kill_cb(pa_sink_input *i) {
     memblockq_stream_unlink(u);
 }
 
+/* Called from IO thread context */
+static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t state) {
+    memblockq_stream *u;
+
+    pa_sink_input_assert_ref(i);
+    u = MEMBLOCKQ_STREAM(i->userdata);
+    memblockq_stream_assert_ref(u);
+
+    /* If we are added for the first time, ask for a rewinding so that
+     * 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);
+}
+
 static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
     memblockq_stream *u;
 
@@ -116,22 +129,23 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk
 
             pa_memblockq_free(u->memblockq);
             u->memblockq = NULL;
+
             pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(u), MEMBLOCKQ_STREAM_MESSAGE_UNLINK, NULL, 0, NULL, NULL);
         }
 
         return -1;
     }
 
+    chunk->length = PA_MIN(chunk->length, nbytes);
     pa_memblockq_drop(u->memblockq, chunk->length);
 
     return 0;
 }
 
-static void sink_input_rewind_cb(pa_sink_input *i, size_t nbytes) {
+static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
     memblockq_stream *u;
 
     pa_sink_input_assert_ref(i);
-    pa_assert(nbytes > 0);
     u = MEMBLOCKQ_STREAM(i->userdata);
     memblockq_stream_assert_ref(u);
 
@@ -141,7 +155,7 @@ static void sink_input_rewind_cb(pa_sink_input *i, size_t nbytes) {
     pa_memblockq_rewind(u->memblockq, nbytes);
 }
 
-static void sink_input_set_max_rewind(pa_sink_input *i, size_t nbytes) {
+static void sink_input_update_max_rewind_cb(pa_sink_input *i, size_t nbytes) {
     memblockq_stream *u;
 
     pa_sink_input_assert_ref(i);
@@ -186,16 +200,17 @@ pa_sink_input* pa_memblockq_sink_input_new(
     pa_sink_input_new_data_set_volume(&data, volume);
     pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p);
 
-    u->sink_input = pa_sink_input_new(sink->core, &data, 0);
+    pa_sink_input_new(&u->sink_input, sink->core, &data, 0);
     pa_sink_input_new_data_done(&data);
 
     if (!u->sink_input)
         goto fail;
 
     u->sink_input->pop = sink_input_pop_cb;
-    u->sink_input->rewind = sink_input_rewind_cb;
-    u->sink_input->set_max_rewind = sink_input_set_max_rewind;
+    u->sink_input->process_rewind = sink_input_process_rewind_cb;
+    u->sink_input->update_max_rewind = sink_input_update_max_rewind_cb;
     u->sink_input->kill = sink_input_kill_cb;
+    u->sink_input->state_change = sink_input_state_change_cb;
     u->sink_input->userdata = u;
 
     if (q)
@@ -255,18 +270,8 @@ void pa_memblockq_sink_input_set_queue(pa_sink_input *i, pa_memblockq *q) {
         pa_memblockq_free(u->memblockq);
 
     if ((u->memblockq = q)) {
-        pa_memblock *silence;
-
         pa_memblockq_set_prebuf(q, 0);
-
-        silence = pa_silence_memblock_new(
-                i->sink->core->mempool,
-                &i->sample_spec,
-                i->thread_info.resampler ? pa_resampler_max_block_size(i->thread_info.resampler) : 0);
-
-        pa_memblockq_set_silence(q, silence);
-        pa_memblock_unref(silence);
-
+        pa_memblockq_set_silence(q, NULL);
         pa_memblockq_willneed(q);
     }
 }