]> code.delx.au - pulseaudio/commitdiff
core: introduce pa_{sink,source}_set_fixed_latency()
authorLennart Poettering <lennart@poettering.net>
Thu, 7 May 2009 23:56:21 +0000 (01:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 8 May 2009 00:04:48 +0000 (02:04 +0200)
This allows us to forward the fixed latency directly from the sink to
the monitor source withut having to wait for pa_sink_put().

src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c
src/modules/bluetooth/module-bluetooth-device.c
src/modules/module-pipe-sink.c
src/modules/module-pipe-source.c
src/modules/module-sine-source.c
src/modules/oss/module-oss.c
src/pulsecore/sink.c
src/pulsecore/sink.h
src/pulsecore/source.c
src/pulsecore/source.h

index 4d8dade37c7438e5c956824815d1b6b206e55058..2745a14efb1ac1e07bb7ba3fde0fa6d68af68919 100644 (file)
@@ -473,7 +473,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polle
             u->since_start += frames * u->frame_size;
 
 #ifdef DEBUG_TIMING
-            pa_log_debug("Wrote %lu bytes", (unsigned long) (frames * u->frame_size));
+            pa_log_debug("Wrote %lu bytes (of possible %lu bytes)", (unsigned long) (frames * u->frame_size), (unsigned long) n_bytes);
 #endif
 
             if ((size_t) frames * u->frame_size >= n_bytes)
@@ -1730,7 +1730,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
         pa_log_info("Time scheduling watermark is %0.2fms",
                     (double) pa_bytes_to_usec(u->tsched_watermark, &ss) / PA_USEC_PER_MSEC);
     } else
-        u->sink->fixed_latency = pa_bytes_to_usec(u->hwbuf_size, &ss);
+        pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(u->hwbuf_size, &ss));
 
     reserve_update(u);
 
index d49035cc5500545054d97cd1db9a1cab5c8e85e4..af567c909305b8af56700c73febf5a750445f617 100644 (file)
@@ -455,7 +455,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, pa_bool_t polled
             u->read_count += frames * u->frame_size;
 
 #ifdef DEBUG_TIMING
-            pa_log_debug("Read %lu bytes", (unsigned long) (frames * u->frame_size));
+            pa_log_debug("Read %lu bytes (of possible %lu bytes)", (unsigned long) (frames * u->frame_size), (unsigned long) n_bytes);
 #endif
 
             if ((size_t) frames * u->frame_size >= n_bytes)
@@ -1582,7 +1582,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         pa_log_info("Time scheduling watermark is %0.2fms",
                     (double) pa_bytes_to_usec(u->tsched_watermark, &ss) / PA_USEC_PER_MSEC);
     } else
-        u->source->fixed_latency = pa_bytes_to_usec(u->hwbuf_size, &ss);
+        pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->hwbuf_size, &ss));
 
     reserve_update(u);
 
index ecb5e83d811141914b7402455db7b75219c48bea..c5c55a18803abdae9e08f1f5dc7a9dd5092ba422 100644 (file)
@@ -1608,9 +1608,9 @@ static int add_sink(struct userdata *u) {
         u->sink->parent.process_msg = sink_process_msg;
 
         pa_sink_set_max_request(u->sink, u->block_size);
-        u->sink->fixed_latency =
-            (u->profile == PROFILE_A2DP ? FIXED_LATENCY_PLAYBACK_A2DP : FIXED_LATENCY_PLAYBACK_HSP) +
-            pa_bytes_to_usec(u->block_size, &u->sample_spec);
+        pa_sink_set_fixed_latency(u->sink,
+                                  (u->profile == PROFILE_A2DP ? FIXED_LATENCY_PLAYBACK_A2DP : FIXED_LATENCY_PLAYBACK_HSP) +
+                                  pa_bytes_to_usec(u->block_size, &u->sample_spec));
     }
 
     if (u->profile == PROFILE_HSP) {
@@ -1659,9 +1659,9 @@ static int add_source(struct userdata *u) {
         u->source->userdata = u;
         u->source->parent.process_msg = source_process_msg;
 
-        u->source->fixed_latency =
-            (/* u->profile == PROFILE_A2DP ? FIXED_LATENCY_RECORD_A2DP : */ FIXED_LATENCY_RECORD_HSP) +
-            pa_bytes_to_usec(u->block_size, &u->sample_spec);
+        pa_source_set_fixed_latency(u->source,
+                                    (/* u->profile == PROFILE_A2DP ? FIXED_LATENCY_RECORD_A2DP : */ FIXED_LATENCY_RECORD_HSP) +
+                                    pa_bytes_to_usec(u->block_size, &u->sample_spec));
     }
 
     if (u->profile == PROFILE_HSP) {
index 9d3e55d8e9efbc020d68334667358e9ae5792dbf..304d01c7518b9686226eceb893842eb36791511c 100644 (file)
@@ -293,7 +293,7 @@ int pa__init(pa_module*m) {
     pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
     pa_sink_set_rtpoll(u->sink, u->rtpoll);
     pa_sink_set_max_request(u->sink, PIPE_BUF);
-    u->sink->fixed_latency = pa_bytes_to_usec(PIPE_BUF, &u->sink->sample_spec);
+    pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(PIPE_BUF, &u->sink->sample_spec));
 
     u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
     pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
index df72d7984567ffc49be5ce825a93879ff4efb05f..6ed4fbfe281c7a35ec62187731c6f1fb324c43e5 100644 (file)
@@ -277,7 +277,7 @@ int pa__init(pa_module*m) {
 
     pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
     pa_source_set_rtpoll(u->source, u->rtpoll);
-    u->source->fixed_latency = pa_bytes_to_usec(PIPE_BUF, &u->source->sample_spec);
+    pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(PIPE_BUF, &u->source->sample_spec));
 
     u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
     pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
index a5f1ce7050b5255c7953fc8199dd0214cfe4607a..a6e15d8107cad5cb8618b576eca1aa795e72db50 100644 (file)
@@ -264,8 +264,7 @@ int pa__init(pa_module*m) {
 
     pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
     pa_source_set_rtpoll(u->source, u->rtpoll);
-    u->source->fixed_latency = u->block_usec;
-
+    pa_source_set_fixed_latency(u->source, u->block_usec);
 
     if (!(u->thread = pa_thread_new(thread_func, u))) {
         pa_log("Failed to create thread.");
index 9f7863f502b406a5a64a233d835e80497dcf340e..ab26137f4fa7194d94cbc32a66dbc29674d2295f 100644 (file)
@@ -1325,8 +1325,8 @@ int pa__init(pa_module*m) {
 
         pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
         pa_source_set_rtpoll(u->source, u->rtpoll);
+        pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->in_hwbuf_size, &u->source->sample_spec));
         u->source->refresh_volume = TRUE;
-        u->source->fixed_latency = pa_bytes_to_usec(u->in_hwbuf_size, &u->source->sample_spec);
 
         if (use_mmap)
             u->in_mmap_memblocks = pa_xnew0(pa_memblock*, u->in_nfrags);
@@ -1387,8 +1387,8 @@ int pa__init(pa_module*m) {
 
         pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
         pa_sink_set_rtpoll(u->sink, u->rtpoll);
+        pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(u->out_hwbuf_size, &u->sink->sample_spec));
         u->sink->refresh_volume = TRUE;
-        u->sink->fixed_latency = pa_bytes_to_usec(u->out_hwbuf_size, &u->sink->sample_spec);
 
         pa_sink_set_max_request(u->sink, u->out_hwbuf_size);
 
index 30fa55790118f6512b8f2798381381947826ab61..06c8b520ef46653a838275785784e607f33675a1 100644 (file)
@@ -2050,6 +2050,22 @@ void pa_sink_set_latency_range_within_thread(pa_sink *s, pa_usec_t min_latency,
     pa_source_set_latency_range_within_thread(s->monitor_source, min_latency, max_latency);
 }
 
+/* Called from main thread, before the sink is put */
+void pa_sink_set_fixed_latency(pa_sink *s, pa_usec_t latency) {
+    pa_sink_assert_ref(s);
+
+    pa_assert(pa_sink_get_state(s) == PA_SINK_INIT);
+
+    if (latency < ABSOLUTE_MIN_LATENCY)
+        latency = ABSOLUTE_MIN_LATENCY;
+
+    if (latency > ABSOLUTE_MAX_LATENCY)
+        latency = ABSOLUTE_MAX_LATENCY;
+
+    s->fixed_latency = latency;
+    pa_source_set_fixed_latency(s->monitor_source, latency);
+}
+
 /* Called from main context */
 size_t pa_sink_get_max_rewind(pa_sink *s) {
     size_t r;
index 352282b8f8dcf6aa2aaad4196dfd410986d9938a..e33b3cfc2c0a606d5c03763c2bda967fc4e5545e 100644 (file)
@@ -229,6 +229,7 @@ void pa_sink_set_rtpoll(pa_sink *s, pa_rtpoll *p);
 void pa_sink_set_max_rewind(pa_sink *s, size_t max_rewind);
 void pa_sink_set_max_request(pa_sink *s, size_t max_request);
 void pa_sink_set_latency_range(pa_sink *s, pa_usec_t min_latency, pa_usec_t max_latency);
+void pa_sink_set_fixed_latency(pa_sink *s, pa_usec_t latency);
 
 void pa_sink_detach(pa_sink *s);
 void pa_sink_attach(pa_sink *s);
index 219025095f20b52193d15f8d142285fe6091fa97..a772dc652077f3eeac63dea46568f635ed779834 100644 (file)
@@ -1276,6 +1276,21 @@ void pa_source_set_latency_range_within_thread(pa_source *s, pa_usec_t min_laten
     pa_source_invalidate_requested_latency(s);
 }
 
+/* Called from main thread, before the source is put */
+void pa_source_set_fixed_latency(pa_source *s, pa_usec_t latency) {
+    pa_source_assert_ref(s);
+
+    pa_assert(pa_source_get_state(s) == PA_SOURCE_INIT);
+
+    if (latency < ABSOLUTE_MIN_LATENCY)
+        latency = ABSOLUTE_MIN_LATENCY;
+
+    if (latency > ABSOLUTE_MAX_LATENCY)
+        latency = ABSOLUTE_MAX_LATENCY;
+
+    s->fixed_latency = latency;
+}
+
 /* Called from main thread */
 size_t pa_source_get_max_rewind(pa_source *s) {
     size_t r;
index b502c228f13a919fa6b8fd3bb5a9f954dbbc1c70..2978f57babbcd643e842eb57d0f97279ae13f260 100644 (file)
@@ -210,6 +210,7 @@ void pa_source_set_rtpoll(pa_source *s, pa_rtpoll *p);
 
 void pa_source_set_max_rewind(pa_source *s, size_t max_rewind);
 void pa_source_set_latency_range(pa_source *s, pa_usec_t min_latency, pa_usec_t max_latency);
+void pa_source_set_fixed_latency(pa_source *s, pa_usec_t latency);
 
 void pa_source_detach(pa_source *s);
 void pa_source_attach(pa_source *s);