]> code.delx.au - pulseaudio/commitdiff
make memchunk/memblockq streams work with glitch-free
authorLennart Poettering <lennart@poettering.net>
Wed, 7 May 2008 02:22:30 +0000 (02:22 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 7 May 2008 02:22:30 +0000 (02:22 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2382 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulsecore/play-memblockq.c
src/pulsecore/play-memchunk.c

index 99b5913494a31370190de562f8d2bdf41ec2330b..2688f923045e39fd120cb8a372a03ce92962e10d 100644 (file)
@@ -3,7 +3,7 @@
 /***
   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
@@ -99,6 +99,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);
+}
+
 static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
     memblockq_stream *u;
 
@@ -116,6 +131,7 @@ 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);
         }
 
@@ -141,7 +157,7 @@ static void sink_input_process_rewind_cb(pa_sink_input *i, size_t nbytes) {
     pa_memblockq_rewind(u->memblockq, nbytes);
 }
 
-static void sink_input_update_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);
@@ -194,8 +210,9 @@ pa_sink_input* pa_memblockq_sink_input_new(
 
     u->sink_input->pop = sink_input_pop_cb;
     u->sink_input->process_rewind = sink_input_process_rewind_cb;
-    u->sink_input->update_max_rewind = sink_input_update_max_rewind;
+    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,14 +272,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_memchunk silence;
-
         pa_memblockq_set_prebuf(q, 0);
-
-        pa_sink_input_get_silence(i, &silence);
-        pa_memblockq_set_silence(q, &silence);
-        pa_memblock_unref(silence.memblock);
-
+        pa_memblockq_set_silence(q, NULL);
         pa_memblockq_willneed(q);
     }
 }
index e4d24a99efe1ddfae7f5d097f7eca591fa5512cb..67a921383ddff1b531b10fd60b9ad92a50e9c9b2 100644 (file)
@@ -3,7 +3,7 @@
 /***
   This file is part of PulseAudio.
 
-  Copyright 2004-2006 Lennart Poettering
+  Copyright 2004-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
@@ -54,7 +54,7 @@ int pa_play_memchunk(
     pa_assert(ss);
     pa_assert(chunk);
 
-    q = pa_memblockq_new(0, chunk->length, 0, pa_frame_size(ss), 0, 0, 0, NULL);
+    q = pa_memblockq_new(0, chunk->length, 0, pa_frame_size(ss), 1, 1, 0, NULL);
     pa_assert_se(pa_memblockq_push(q, chunk) >= 0);
 
     if ((r = pa_play_memblockq(sink, ss, map, q, volume, p, sink_input_index)) < 0) {