introduce new flag that marks sinks/sources which can adjust the latency dynamically
authorLennart Poettering <lennart@poettering.net>
Tue, 24 Mar 2009 23:30:54 +0000 (00:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 24 Mar 2009 23:30:54 +0000 (00:30 +0100)
src/modules/alsa/alsa-sink.c
src/modules/alsa/alsa-source.c
src/modules/module-ladspa-sink.c
src/modules/module-remap-sink.c
src/pulse/def.h
src/pulsecore/cli-text.c
src/pulsecore/sink.c
src/pulsecore/source.c

index bcca57d..a7728a0 100644 (file)
@@ -1662,7 +1662,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     pa_alsa_init_description(data.proplist);
 
-    u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
+    u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY|(u->use_tsched ? PA_SINK_DYNAMIC_LATENCY : 0));
     pa_sink_new_data_done(&data);
 
     if (!u->sink) {
index 7c09c00..8b76ee5 100644 (file)
@@ -1514,7 +1514,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
 
     pa_alsa_init_description(data.proplist);
 
-    u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
+    u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY|(u->use_tsched ? PA_SOURCE_DYNAMIC_LATENCY : 0));
     pa_source_new_data_done(&data);
 
     if (!u->source) {
index 81546ff..e619acd 100644 (file)
@@ -705,7 +705,7 @@ int pa__init(pa_module*m) {
     pa_proplist_sets(sink_data.proplist, "device.ladspa.copyright", d->Copyright);
     pa_proplist_setf(sink_data.proplist, "device.ladspa.unique_id", "%lu", (unsigned long) d->UniqueID);
 
-    u->sink = pa_sink_new(m->core, &sink_data, PA_SINK_LATENCY);
+    u->sink = pa_sink_new(m->core, &sink_data, PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY);
     pa_sink_new_data_done(&sink_data);
 
     if (!u->sink) {
index 8c43a72..f9777be 100644 (file)
@@ -354,7 +354,7 @@ int pa__init(pa_module*m) {
     pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_MASTER_DEVICE, master->name);
     pa_proplist_sets(sink_data.proplist, PA_PROP_DEVICE_CLASS, "filter");
 
-    u->sink = pa_sink_new(m->core, &sink_data, PA_SINK_LATENCY);
+    u->sink = pa_sink_new(m->core, &sink_data, PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY);
     pa_sink_new_data_done(&sink_data);
 
     if (!u->sink) {
index 3629aab..8bcb691 100644 (file)
@@ -702,9 +702,13 @@ typedef enum pa_sink_flags {
     /**< Volume can be translated to dB with pa_sw_volume_to_dB()
      * \since 0.9.11 */
 
-    PA_SINK_FLAT_VOLUME = 0x0040U
+    PA_SINK_FLAT_VOLUME = 0x0040U,
     /**< This sink is in flat volume mode, i.e. always the maximum of
      * the volume of all connected inputs. \since 0.9.15 */
+
+    PA_SINK_DYNAMIC_LATENCY = 0x0080U
+    /**< The latency can be adjusted dynamically depending on the
+     * needs of the connected streams. \since 0.9.15 */
 } pa_sink_flags_t;
 
 /** \cond fulldocs */
@@ -715,6 +719,7 @@ typedef enum pa_sink_flags {
 #define PA_SINK_HW_MUTE_CTRL PA_SINK_HW_MUTE_CTRL
 #define PA_SINK_DECIBEL_VOLUME PA_SINK_DECIBEL_VOLUME
 #define PA_SINK_FLAT_VOLUME PA_SINK_FLAT_VOLUME
+#define PA_SINK_DYNAMIC_LATENCY PA_SINK_DYNAMIC_LATENCY
 /** \endcond */
 
 /** Sink state. \since 0.9.15 */
@@ -780,9 +785,13 @@ typedef enum pa_source_flags {
     PA_SOURCE_HW_MUTE_CTRL = 0x0010U,
     /**< Supports hardware mute control \since 0.9.11 */
 
-    PA_SOURCE_DECIBEL_VOLUME = 0x0020U
+    PA_SOURCE_DECIBEL_VOLUME = 0x0020U,
     /**< Volume can be translated to dB with pa_sw_volume_to_dB()
      * \since 0.9.11 */
+
+    PA_SOURCE_DYNAMIC_LATENCY = 0x0080U
+    /**< The latency can be adjusted dynamically depending on the
+     * needs of the connected streams. \since 0.9.15 */
 } pa_source_flags_t;
 
 /** \cond fulldocs */
@@ -792,6 +801,7 @@ typedef enum pa_source_flags {
 #define PA_SOURCE_NETWORK PA_SOURCE_NETWORK
 #define PA_SOURCE_HW_MUTE_CTRL PA_SOURCE_HW_MUTE_CTRL
 #define PA_SOURCE_DECIBEL_VOLUME PA_SOURCE_DECIBEL_VOLUME
+#define PA_SOURCE_DYNAMIC_LATENCY PA_SOURCE_DYNAMIC_LATENCY
 /** \endcond */
 
 /** Source state. \since 0.9.15 */
index 76adc4d..8d39dcf 100644 (file)
@@ -220,19 +220,17 @@ char *pa_sink_list_to_string(pa_core *c) {
             v[PA_VOLUME_SNPRINT_MAX],
             vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
             cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
-        pa_usec_t min_latency, max_latency;
         const char *cmn;
 
         cmn = pa_channel_map_to_pretty_name(&sink->channel_map);
 
-        pa_sink_get_latency_range(sink, &min_latency, &max_latency);
 
         pa_strbuf_printf(
             s,
             "  %c index: %u\n"
             "\tname: <%s>\n"
             "\tdriver: <%s>\n"
-            "\tflags: %s%s%s%s%s%s%s\n"
+            "\tflags: %s%s%s%s%s%s%s%s\n"
             "\tstate: %s\n"
             "\tvolume: %s%s%s\n"
             "\t        balance %0.2f\n"
@@ -240,7 +238,6 @@ char *pa_sink_list_to_string(pa_core *c) {
             "\tvolume steps: %u\n"
             "\tmuted: %s\n"
             "\tcurrent latency: %0.2f ms\n"
-            "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
             "\tmax request: %lu KiB\n"
             "\tmax rewind: %lu KiB\n"
             "\tmonitor source: %u\n"
@@ -259,6 +256,7 @@ char *pa_sink_list_to_string(pa_core *c) {
             sink->flags & PA_SINK_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
             sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
             sink->flags & PA_SINK_FLAT_VOLUME ? "FLAT_VOLUME" : "",
+            sink->flags & PA_SINK_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
             sink_state_to_string(pa_sink_get_state(sink)),
             pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink, FALSE)),
             sink->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t        " : "",
@@ -270,9 +268,6 @@ char *pa_sink_list_to_string(pa_core *c) {
             sink->n_volume_steps,
             pa_yes_no(pa_sink_get_mute(sink, FALSE)),
             (double) pa_sink_get_latency(sink) / (double) PA_USEC_PER_MSEC,
-            (double) pa_sink_get_requested_latency(sink) / (double) PA_USEC_PER_MSEC,
-            (double) min_latency / PA_USEC_PER_MSEC,
-            (double) max_latency / PA_USEC_PER_MSEC,
             (unsigned long) pa_sink_get_max_request(sink) / 1024,
             (unsigned long) pa_sink_get_max_rewind(sink) / 1024,
             sink->monitor_source ? sink->monitor_source->index : PA_INVALID_INDEX,
@@ -283,6 +278,18 @@ char *pa_sink_list_to_string(pa_core *c) {
             pa_sink_used_by(sink),
             pa_sink_linked_by(sink));
 
+        if (sink->flags & PA_SINK_DYNAMIC_LATENCY) {
+            pa_usec_t min_latency, max_latency;
+            pa_sink_get_latency_range(sink, &min_latency, &max_latency);
+
+            pa_strbuf_printf(
+                    s,
+                    "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n",
+                    (double) pa_sink_get_requested_latency(sink) / (double) PA_USEC_PER_MSEC,
+                    (double) min_latency / PA_USEC_PER_MSEC,
+                    (double) max_latency / PA_USEC_PER_MSEC);
+        }
+
         if (sink->card)
             pa_strbuf_printf(s, "\tcard: %u <%s>\n", sink->card->index, sink->card->name);
         if (sink->module)
@@ -313,19 +320,16 @@ char *pa_source_list_to_string(pa_core *c) {
             v[PA_VOLUME_SNPRINT_MAX],
             vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
             cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
-        pa_usec_t min_latency, max_latency;
         const char *cmn;
 
         cmn = pa_channel_map_to_pretty_name(&source->channel_map);
 
-        pa_source_get_latency_range(source, &min_latency, &max_latency);
-
         pa_strbuf_printf(
             s,
             "  %c index: %u\n"
             "\tname: <%s>\n"
             "\tdriver: <%s>\n"
-            "\tflags: %s%s%s%s%s%s\n"
+            "\tflags: %s%s%s%s%s%s%s\n"
             "\tstate: %s\n"
             "\tvolume: %s%s%s\n"
             "\t        balance %0.2f\n"
@@ -333,7 +337,6 @@ char *pa_source_list_to_string(pa_core *c) {
             "\tvolume steps: %u\n"
             "\tmuted: %s\n"
             "\tcurrent latency: %0.2f ms\n"
-            "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n"
             "\tmax rewind: %lu KiB\n"
             "\tsample spec: %s\n"
             "\tchannel map: %s%s%s\n"
@@ -349,6 +352,7 @@ char *pa_source_list_to_string(pa_core *c) {
             source->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "",
             source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
             source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
+            source->flags & PA_SOURCE_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
             source_state_to_string(pa_source_get_state(source)),
             pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source, FALSE)),
             source->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t        " : "",
@@ -360,9 +364,6 @@ char *pa_source_list_to_string(pa_core *c) {
             source->n_volume_steps,
             pa_yes_no(pa_source_get_mute(source, FALSE)),
             (double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
-            (double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC,
-            (double) min_latency / PA_USEC_PER_MSEC,
-            (double) max_latency / PA_USEC_PER_MSEC,
             (unsigned long) pa_source_get_max_rewind(source) / 1024,
             pa_sample_spec_snprint(ss, sizeof(ss), &source->sample_spec),
             pa_channel_map_snprint(cm, sizeof(cm), &source->channel_map),
@@ -371,6 +372,18 @@ char *pa_source_list_to_string(pa_core *c) {
             pa_source_used_by(source),
             pa_source_linked_by(source));
 
+        if (source->flags & PA_SOURCE_DYNAMIC_LATENCY) {
+            pa_usec_t min_latency, max_latency;
+            pa_source_get_latency_range(source, &min_latency, &max_latency);
+
+            pa_strbuf_printf(
+                    s,
+                    "\tconfigured latency: %0.2f ms; range is %0.2f .. %0.2f ms\n",
+                    (double) pa_source_get_requested_latency(source) / PA_USEC_PER_MSEC,
+                    (double) min_latency / PA_USEC_PER_MSEC,
+                    (double) max_latency / PA_USEC_PER_MSEC);
+        }
+
         if (source->monitor_of)
             pa_strbuf_printf(s, "\tmonitor_of: %u\n", source->monitor_of->index);
         if (source->card)
index 1fec018..c2012df 100644 (file)
@@ -1869,6 +1869,11 @@ void pa_sink_set_latency_range(pa_sink *s, pa_usec_t min_latency, pa_usec_t max_
 
     pa_assert(min_latency <= max_latency);
 
+    /* Hmm, let's see if someone forgot to set PA_SINK_DYNAMIC_LATENCY here... */
+    pa_assert((min_latency == ABSOLUTE_MIN_LATENCY &&
+               max_latency == ABSOLUTE_MAX_LATENCY) ||
+              (s->flags & PA_SINK_DYNAMIC_LATENCY));
+
     if (PA_SINK_IS_LINKED(s->state)) {
         pa_usec_t r[2];
 
@@ -1917,6 +1922,11 @@ void pa_sink_set_latency_range_within_thread(pa_sink *s, pa_usec_t min_latency,
     pa_assert(max_latency <= ABSOLUTE_MAX_LATENCY);
     pa_assert(min_latency <= max_latency);
 
+    /* Hmm, let's see if someone forgot to set PA_SINK_DYNAMIC_LATENCY here... */
+    pa_assert((min_latency == ABSOLUTE_MIN_LATENCY &&
+               max_latency == ABSOLUTE_MAX_LATENCY) ||
+              (s->flags & PA_SINK_DYNAMIC_LATENCY));
+
     s->thread_info.min_latency = min_latency;
     s->thread_info.max_latency = max_latency;
 
index f1f8ef7..0fe6f8d 100644 (file)
@@ -1152,6 +1152,11 @@ void pa_source_set_latency_range(pa_source *s, pa_usec_t min_latency, pa_usec_t
 
     pa_assert(min_latency <= max_latency);
 
+    /* Hmm, let's see if someone forgot to set PA_SOURCE_DYNAMIC_LATENCY here... */
+    pa_assert((min_latency == ABSOLUTE_MIN_LATENCY &&
+               max_latency == ABSOLUTE_MAX_LATENCY) ||
+              (s->flags & PA_SOURCE_DYNAMIC_LATENCY));
+
     if (PA_SOURCE_IS_LINKED(s->state)) {
         pa_usec_t r[2];
 
@@ -1196,6 +1201,11 @@ void pa_source_set_latency_range_within_thread(pa_source *s, pa_usec_t min_laten
     pa_assert(max_latency <= ABSOLUTE_MAX_LATENCY);
     pa_assert(min_latency <= max_latency);
 
+    /* Hmm, let's see if someone forgot to set PA_SOURCE_DYNAMIC_LATENCY here... */
+    pa_assert((min_latency == ABSOLUTE_MIN_LATENCY &&
+               max_latency == ABSOLUTE_MAX_LATENCY) ||
+              (s->flags & PA_SOURCE_DYNAMIC_LATENCY));
+
     s->thread_info.min_latency = min_latency;
     s->thread_info.max_latency = max_latency;