]> code.delx.au - pulseaudio/commitdiff
sink,source: Update sample rate if possible on stream uncork
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Sun, 6 Nov 2011 13:42:19 +0000 (19:12 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 7 Nov 2011 10:08:31 +0000 (15:38 +0530)
If a stream is being uncorked and no other stream is running, we try to
update the sink/source sample rate to match it and avoid resampling.

src/pulsecore/sink-input.c
src/pulsecore/source-output.c

index fbede0196a0b482b0e79adaa338de5df83969bfe..d57ad779f8962f97fb553cce7841c620dfc576fe 100644 (file)
@@ -556,6 +556,12 @@ static void sink_input_set_state(pa_sink_input *i, pa_sink_input_state_t state)
     if (i->state == state)
         return;
 
+    if (i->state == PA_SINK_INPUT_CORKED && state == PA_SINK_INPUT_RUNNING && pa_sink_used_by(i->sink) == 0) {
+        /* We were uncorked and the sink was not playing anything -- let's try
+         * to update the sample rate to avoid resampling */
+        pa_sink_update_rate(i->sink, i->sample_spec.rate, pa_sink_input_is_passthrough(i));
+    }
+
     pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0);
 
     update_n_corked(i, state);
index 47b93a9323277d3ea65dcc09ee92ce84a75aec4d..7b0cb84e372a15be4324224a381bb1c29e4b015b 100644 (file)
@@ -515,6 +515,12 @@ static void source_output_set_state(pa_source_output *o, pa_source_output_state_
     if (o->state == state)
         return;
 
+    if (o->state == PA_SOURCE_OUTPUT_CORKED && state == PA_SOURCE_OUTPUT_RUNNING && pa_source_used_by(o->source) == 0) {
+        /* We were uncorked and the source was not playing anything -- let's try
+         * to update the sample rate to avoid resampling */
+        pa_source_update_rate(o->source, o->sample_spec.rate, pa_source_output_is_passthrough(o));
+    }
+
     pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_STATE, PA_UINT_TO_PTR(state), 0, NULL) == 0);
 
     update_n_corked(o, state);