[pulseaudio-discuss,6/7] tunnel-new: respect client latency requirements better

Submitted by Pierre Ossman on May 23, 2016, 2:57 p.m.

Details

Message ID 20160523165752.1cb970f6@ossman.lkpg.cendio.se
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in PulseAudio

Not browsing as part of any series.

Commit Message

Pierre Ossman May 23, 2016, 2:57 p.m.
Tell the upstream server to adjust the total latency, as that better
matches what our clients are requesting out of us. Also let the
upstream server pick the record latency when we have no preferences.

Signed-off-by: Pierre Ossman <ossman@cendio.se>
---
 src/modules/module-tunnel-sink-new.c   |  2 +-
 src/modules/module-tunnel-source-new.c | 24 +++++++++++-------------
 2 files changed, 12 insertions(+), 14 deletions(-)

| PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_START_CORKED |
PA_STREAM_ADJUST_LATENCY) < 0) { pa_log_debug("Could not create stream:
%s", pa_strerror(pa_context_errno(u->context)));
u->thread_mainloop_api->quit(u->thread_mainloop_api,
TUNNEL_THREAD_FAILED_MAINLOOP); } @@ -424,7 +424,6 @@ static void
subscribe_cb(pa_context *context, pa_subscription_event_type_t t, ui
static void source_update_requested_latency_cb(pa_source *s) { struct
userdata *u; pa_operation *operation;
-    size_t nbytes;
     pa_usec_t block_usec;
     pa_buffer_attr bufferattr;
 
@@ -432,19 +431,18 @@ static void
source_update_requested_latency_cb(pa_source *s) { pa_assert_se(u =
s->userdata); 
     block_usec = pa_source_get_requested_latency_within_thread(s);
-    if (block_usec == (pa_usec_t) -1)
-        block_usec = s->thread_info.max_latency;
-
-    nbytes = pa_usec_to_bytes(block_usec, &s->sample_spec);
 
     if (u->stream) {
         switch (pa_stream_get_state(u->stream)) {
             case PA_STREAM_READY:
-                if (pa_stream_get_buffer_attr(u->stream)->fragsize ==
nbytes)
+                if (u->req_latency == block_usec)
                     break;
 
+                u->req_latency = block_usec;
+
                 reset_bufferattr(&bufferattr);
-                bufferattr.fragsize = nbytes;
+                if (u->req_latency != (pa_usec_t) -1)
+                    bufferattr.fragsize =
pa_usec_to_bytes(u->req_latency, &s->sample_spec); if ((operation =
pa_stream_set_buffer_attr(u->stream, &bufferattr, NULL, NULL)))
pa_operation_unref(operation); break;

Patch hide | download patch | download mbox

diff --git a/src/modules/module-tunnel-sink-new.c
b/src/modules/module-tunnel-sink-new.c index e49e6df..ebaa7f3 100644
--- a/src/modules/module-tunnel-sink-new.c
+++ b/src/modules/module-tunnel-sink-new.c
@@ -378,7 +378,7 @@  static void context_state_cb(pa_context *c, void
*userdata) { if (pa_stream_connect_playback(u->stream,
                                            u->remote_sink_name,
                                            &bufferattr,
-
PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_START_CORKED |
PA_STREAM_AUTO_TIMING_UPDATE,
+
PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_START_CORKED |
PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY, NULL, NULL) <
0) { pa_log_error("Could not connect stream.");
diff --git a/src/modules/module-tunnel-source-new.c
b/src/modules/module-tunnel-source-new.c index 20a1f2e..e46dda2 100644
--- a/src/modules/module-tunnel-source-new.c
+++ b/src/modules/module-tunnel-source-new.c
@@ -83,6 +83,8 @@  struct userdata {
     bool connected;
     bool new_data;
 
+    pa_usec_t req_latency;
+
     char *cookie_file;
     char *remote_server;
     char *remote_source_name;
@@ -306,7 +308,6 @@  static void context_state_cb(pa_context *c, void
*userdata) { case PA_CONTEXT_READY: {
             pa_proplist *proplist;
             pa_buffer_attr bufferattr;
-            pa_usec_t requested_latency;
             pa_operation *operation;
             char *username = pa_get_user_name_malloc();
             char *hostname = pa_get_host_name_malloc();
@@ -333,19 +334,18 @@  static void context_state_cb(pa_context *c, void
*userdata) { return;
             }
 
-            requested_latency =
pa_source_get_requested_latency_within_thread(u->source);
-            if (requested_latency == (uint32_t) -1)
-                requested_latency = u->source->thread_info.max_latency;
+            u->req_latency =
pa_source_get_requested_latency_within_thread(u->source); 
             reset_bufferattr(&bufferattr);
-            bufferattr.fragsize = pa_usec_to_bytes(requested_latency,
&u->source->sample_spec);
+            if (u->req_latency != (pa_usec_t) -1)
+                bufferattr.fragsize = pa_usec_to_bytes(u->req_latency,
&u->source->sample_spec); 
             pa_stream_set_state_callback(u->stream, stream_state_cb,
userdata); pa_stream_set_read_callback(u->stream, stream_read_cb,
userdata); if (pa_stream_connect_record(u->stream,
                                          u->remote_source_name,
                                          &bufferattr,
-                                         PA_STREAM_INTERPOLATE_TIMING
| PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_START_CORKED) < 0) {
+                                         PA_STREAM_INTERPOLATE_TIMING