Allow a message in the queue to perform both a seek and a post data.
For clients that do not use PA_SEEK_RELATIVE (e g gstreamer), this
cuts the message count - and sometimes even the rewinds - in half.

--
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
>From f07d6d2f692a6e51b01dabd5b4ac4a0c8ad3e270 Mon Sep 17 00:00:00 2001
From: David Henningsson <david.hennings...@canonical.com>
Date: Mon, 6 Dec 2010 16:25:25 +0100
Subject: [PATCH 1/3] Fighting rewinds: Seek and write data in the same message

Allow a message in the queue to perform both a seek and a post data.
For clients that do not use PA_SEEK_RELATIVE (e g gstreamer), this
cuts the message count - and sometimes even the rewinds - in half.

Signed-off-by: David Henningsson <david.hennings...@canonical.com>
---
 src/pulsecore/protocol-native.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 337869d..af44126 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -1351,6 +1351,7 @@ static void flush_write_no_account(pa_memblockq *q) {
 static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk) {
     pa_sink_input *i = PA_SINK_INPUT(o);
     playback_stream *s;
+    int64_t windex_seek = 0;
 
     pa_sink_input_assert_ref(i);
     s = PLAYBACK_STREAM(i->userdata);
@@ -1359,18 +1360,19 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int
     switch (code) {
 
         case SINK_INPUT_MESSAGE_SEEK: {
-            int64_t windex;
 
-            windex = pa_memblockq_get_write_index(s->memblockq);
+            windex_seek = pa_memblockq_get_write_index(s->memblockq);
 
             /* The client side is incapable of accounting correctly
              * for seeks of a type != PA_SEEK_RELATIVE. We need to be
              * able to deal with that. */
 
             pa_memblockq_seek(s->memblockq, offset, PA_PTR_TO_UINT(userdata), PA_PTR_TO_UINT(userdata) == PA_SEEK_RELATIVE);
-
-            handle_seek(s, windex);
-            return 0;
+            if (!chunk) {
+                handle_seek(s, windex_seek);
+                return 0;
+            }
+            /* else fall through and write some data */
         }
 
         case SINK_INPUT_MESSAGE_POST_DATA: {
@@ -1379,6 +1381,8 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int
             pa_assert(chunk);
 
             windex = pa_memblockq_get_write_index(s->memblockq);
+            if (code == SINK_INPUT_MESSAGE_SEEK)
+                windex = PA_MIN(windex, windex_seek);
 
 /*             pa_log("sink input post: %lu %lli", (unsigned long) chunk->length, (long long) windex); */
 
@@ -4440,9 +4444,9 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o
 
         if (chunk->memblock) {
             if (seek != PA_SEEK_RELATIVE || offset != 0)
-                pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_SEEK, PA_UINT_TO_PTR(seek), offset, NULL, NULL);
-
-            pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, chunk, NULL);
+                pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_SEEK, PA_UINT_TO_PTR(seek), offset, chunk, NULL);
+            else
+                pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, chunk, NULL);
         } else
             pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_SEEK, PA_UINT_TO_PTR(seek), offset+chunk->length, NULL, NULL);
 
-- 
1.7.1

_______________________________________________
pulseaudio-discuss mailing list
pulseaudio-discuss@mail.0pointer.de
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss

Reply via email to