[pulseaudio-commits] 2 commits - src/pulsecore

Arun Raghavan arun at kemper.freedesktop.org
Thu Aug 18 00:34:04 PDT 2011


 src/pulsecore/sink-input.c    |   35 +++++++++++++++++------------------
 src/pulsecore/sink.c          |   35 ++++++++++++++++++++++++++++++++---
 src/pulsecore/sink.h          |    7 +++++++
 src/pulsecore/source-output.c |   21 ++++++++++++++++++---
 src/pulsecore/source.c        |   27 ++++++++++++++++++++++++---
 src/pulsecore/source.h        |    7 +++++++
 6 files changed, 105 insertions(+), 27 deletions(-)

New commits:
commit f0be9c4004669dda0f47a1e9a410e7d7c7da070d
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Thu Aug 18 12:32:14 2011 +0530

    source-output: Ensure no volumes are applied for passthrough streams
    
    This forces passthrough source-outputs and their corresponding sources
    to 0dB gain so that the data is sent unaltered to the receiver.

diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index a9e60f8..d54e7f6 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -298,10 +298,13 @@ int pa_source_output_new(
 
     pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID);
 
-    /* Don't restore (or save) stream volume for passthrough streams */
+    /* Don't restore (or save) stream volume for passthrough streams and
+     * prevent attenuation/gain */
     if (pa_source_output_new_data_is_passthrough(data)) {
-        data->volume_is_set = FALSE;
-        data->volume_factor_is_set = FALSE;
+        data->volume_is_set = TRUE;
+        pa_cvolume_reset(&data->volume, data->sample_spec.channels);
+        data->volume_is_absolute = TRUE;
+        data->save_volume = FALSE;
     }
 
     if (!data->volume_is_set) {
@@ -544,6 +547,9 @@ void pa_source_output_unlink(pa_source_output*o) {
     o->state = PA_SOURCE_OUTPUT_UNLINKED;
 
     if (linked && o->source) {
+        if (pa_source_output_is_passthrough(o))
+            pa_source_leave_passthrough(o->source);
+
         /* We might need to update the source's volume if we are in flat volume mode. */
         if (pa_source_flat_volume_enabled(o->source))
             pa_source_set_volume(o->source, NULL, FALSE, FALSE);
@@ -628,6 +634,9 @@ void pa_source_output_put(pa_source_output *o) {
         set_real_ratio(o, &o->volume);
     }
 
+    if (pa_source_output_is_passthrough(o))
+        pa_source_enter_passthrough(o->source);
+
     o->thread_info.soft_volume = o->soft_volume;
     o->thread_info.muted = o->muted;
 
@@ -1180,6 +1189,9 @@ int pa_source_output_start_move(pa_source_output *o) {
     if (pa_source_output_get_state(o) == PA_SOURCE_OUTPUT_CORKED)
         pa_assert_se(origin->n_corked-- >= 1);
 
+    if (pa_source_output_is_passthrough(o))
+        pa_source_leave_passthrough(o->source);
+
     if (pa_source_flat_volume_enabled(o->source))
         /* We might need to update the source's volume if we are in flat
          * volume mode. */
@@ -1434,6 +1446,9 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t
 
     update_volume_due_to_moving(o, dest);
 
+    if (pa_source_output_is_passthrough(o))
+        pa_source_enter_passthrough(o->source);
+
     pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_ADD_OUTPUT, o, 0, NULL) == 0);
 
     pa_log_debug("Successfully moved source output %i to %s.", o->index, dest->name);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index ae9528f..104bde6 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -978,6 +978,27 @@ pa_bool_t pa_source_is_passthrough(pa_source *s) {
     return (s->monitor_of && pa_sink_is_passthrough(s->monitor_of));
 }
 
+/* Called from main context */
+void pa_source_enter_passthrough(pa_source *s) {
+    pa_cvolume volume;
+
+    /* set the volume to NORM */
+    s->saved_volume = *pa_source_get_volume(s, TRUE);
+    s->saved_save_volume = s->save_volume;
+
+    pa_cvolume_set(&volume, s->sample_spec.channels, PA_VOLUME_NORM);
+    pa_source_set_volume(s, &volume, TRUE, FALSE);
+}
+
+/* Called from main context */
+void pa_source_leave_passthrough(pa_source *s) {
+    /* Restore source volume to what it was before we entered passthrough mode */
+    pa_source_set_volume(s, &s->saved_volume, TRUE, s->saved_save_volume);
+
+    pa_cvolume_init(&s->saved_volume);
+    s->saved_save_volume = FALSE;
+}
+
 /* Called from main context. */
 static void compute_reference_ratio(pa_source_output *o) {
     unsigned c = 0;
@@ -1368,9 +1389,9 @@ void pa_source_set_volume(
     pa_assert(volume || pa_source_flat_volume_enabled(s));
     pa_assert(!volume || volume->channels == 1 || pa_cvolume_compatible(volume, &s->sample_spec));
 
-    /* make sure we don't change the volume when a PASSTHROUGH output is connected */
-    if (pa_source_is_passthrough(s)) {
-        /* FIXME: Need to notify client that volume control is disabled */
+    /* make sure we don't change the volume in PASSTHROUGH mode ...
+     * ... *except* if we're being invoked to reset the volume to ensure 0 dB gain */
+    if (pa_source_is_passthrough(s) && (!volume || !pa_cvolume_is_norm(volume))) {
         pa_log_warn("Cannot change volume, Source is monitor of a PASSTHROUGH sink");
         return;
     }
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 50cec77..a7af097 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -98,6 +98,10 @@ struct pa_source {
     pa_bool_t save_volume:1;
     pa_bool_t save_muted:1;
 
+    /* Saved volume state while we're in passthrough mode */
+    pa_cvolume saved_volume;
+    pa_bool_t saved_save_volume:1;
+
     pa_asyncmsgq *asyncmsgq;
 
     pa_memchunk silence;
@@ -338,6 +342,9 @@ pa_bool_t pa_source_flat_volume_enabled(pa_source *s);
 /* Is the source in passthrough mode? (that is, is this a monitor source for a sink
  * that has a passthrough sink input connected to it. */
 pa_bool_t pa_source_is_passthrough(pa_source *s);
+/* These should be called when a source enters/leaves passthrough mode */
+void pa_source_enter_passthrough(pa_source *s);
+void pa_source_leave_passthrough(pa_source *s);
 
 void pa_source_set_volume(pa_source *source, const pa_cvolume *volume, pa_bool_t sendmsg, pa_bool_t save);
 const pa_cvolume *pa_source_get_volume(pa_source *source, pa_bool_t force_refresh);

commit 0dea35a8185ea846777c3a541f56180ba9dd70ba
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date:   Thu Aug 18 11:51:12 2011 +0530

    sink-input: Ensure no volumes are applied for passthrough streams
    
    This forces passthrough sink-inputs and their corresponding sinks to 0dB
    gain so that the data is sent unaltered to the receiver.

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 4ffa03b..8f157ec 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -320,10 +320,13 @@ int pa_sink_input_new(
 
     pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID);
 
-    /* Don't restore (or save) stream volume for passthrough streams */
+    /* Don't restore (or save) stream volume for passthrough streams and
+     * prevent attenuation/gain */
     if (pa_sink_input_new_data_is_passthrough(data)) {
-        data->volume_is_set = FALSE;
-        data->volume_factor_is_set = FALSE;
+        data->volume_is_set = TRUE;
+        pa_cvolume_reset(&data->volume, data->sample_spec.channels);
+        data->volume_is_absolute = TRUE;
+        data->save_volume = FALSE;
     }
 
     if (!data->volume_is_set) {
@@ -610,16 +613,15 @@ void pa_sink_input_unlink(pa_sink_input *i) {
     i->state = PA_SINK_INPUT_UNLINKED;
 
     if (linked && i->sink) {
+        if (pa_sink_input_is_passthrough(i))
+            pa_sink_leave_passthrough(i->sink);
+
         /* We might need to update the sink's volume if we are in flat volume mode. */
         if (pa_sink_flat_volume_enabled(i->sink))
             pa_sink_set_volume(i->sink, NULL, FALSE, FALSE);
 
         if (i->sink->asyncmsgq)
             pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_REMOVE_INPUT, i, 0, NULL) == 0);
-
-        /* We suspend the monitor if there was a passthrough sink, unsuspend now if required */
-        if (pa_sink_input_is_passthrough(i) && i->sink->monitor_source)
-            pa_source_suspend(i->sink->monitor_source, FALSE, PA_SUSPEND_PASSTHROUGH);
     }
 
     reset_callbacks(i);
@@ -710,9 +712,8 @@ void pa_sink_input_put(pa_sink_input *i) {
         set_real_ratio(i, &i->volume);
     }
 
-    /* If we're entering passthrough mode, disable the monitor */
-    if (pa_sink_input_is_passthrough(i) && i->sink->monitor_source)
-        pa_source_suspend(i->sink->monitor_source, TRUE, PA_SUSPEND_PASSTHROUGH);
+    if (pa_sink_input_is_passthrough(i))
+        pa_sink_enter_passthrough(i->sink);
 
     i->thread_info.soft_volume = i->soft_volume;
     i->thread_info.muted = i->muted;
@@ -1407,6 +1408,9 @@ int pa_sink_input_start_move(pa_sink_input *i) {
     if (pa_sink_input_get_state(i) == PA_SINK_INPUT_CORKED)
         pa_assert_se(i->sink->n_corked-- >= 1);
 
+    if (pa_sink_input_is_passthrough(i))
+        pa_sink_leave_passthrough(i->sink);
+
     if (pa_sink_flat_volume_enabled(i->sink))
         /* We might need to update the sink's volume if we are in flat
          * volume mode. */
@@ -1414,10 +1418,6 @@ int pa_sink_input_start_move(pa_sink_input *i) {
 
     pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_START_MOVE, i, 0, NULL) == 0);
 
-    /* We suspend the monitor if there was a passthrough sink, unsuspend now if required */
-    if (pa_sink_input_is_passthrough(i) && i->sink->monitor_source)
-        pa_source_suspend(i->sink->monitor_source, FALSE, PA_SUSPEND_PASSTHROUGH);
-
     pa_sink_update_status(i->sink);
     pa_cvolume_remap(&i->volume_factor_sink, &i->sink->channel_map, &i->channel_map);
     i->sink = NULL;
@@ -1666,11 +1666,10 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
 
     update_volume_due_to_moving(i, dest);
 
-    pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_FINISH_MOVE, i, 0, NULL) == 0);
+    if (pa_sink_input_is_passthrough(i))
+        pa_sink_enter_passthrough(i->sink);
 
-    /* If we're entering passthrough mode, disable the monitor */
-    if (pa_sink_input_is_passthrough(i) && i->sink->monitor_source)
-        pa_source_suspend(i->sink->monitor_source, TRUE, PA_SUSPEND_PASSTHROUGH);
+    pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_FINISH_MOVE, i, 0, NULL) == 0);
 
     pa_log_debug("Successfully moved sink input %i to %s.", i->index, dest->name);
 
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index e6e410c..3aaa5b7 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1394,6 +1394,35 @@ pa_bool_t pa_sink_is_passthrough(pa_sink *s) {
     return FALSE;
 }
 
+/* Called from main context */
+void pa_sink_enter_passthrough(pa_sink *s) {
+    pa_cvolume volume;
+
+    /* disable the monitor in passthrough mode */
+    if (s->monitor_source)
+        pa_source_suspend(s->monitor_source, TRUE, PA_SUSPEND_PASSTHROUGH);
+
+    /* set the volume to NORM */
+    s->saved_volume = *pa_sink_get_volume(s, TRUE);
+    s->saved_save_volume = s->save_volume;
+
+    pa_cvolume_set(&volume, s->sample_spec.channels, PA_VOLUME_NORM);
+    pa_sink_set_volume(s, &volume, TRUE, FALSE);
+}
+
+/* Called from main context */
+void pa_sink_leave_passthrough(pa_sink *s) {
+    /* Unsuspend monitor */
+    if (s->monitor_source)
+        pa_source_suspend(s->monitor_source, FALSE, PA_SUSPEND_PASSTHROUGH);
+
+    /* Restore sink volume to what it was before we entered passthrough mode */
+    pa_sink_set_volume(s, &s->saved_volume, TRUE, s->saved_save_volume);
+
+    pa_cvolume_init(&s->saved_volume);
+    s->saved_save_volume = FALSE;
+}
+
 /* Called from main context. */
 static void compute_reference_ratio(pa_sink_input *i) {
     unsigned c = 0;
@@ -1784,9 +1813,9 @@ void pa_sink_set_volume(
     pa_assert(volume || pa_sink_flat_volume_enabled(s));
     pa_assert(!volume || volume->channels == 1 || pa_cvolume_compatible(volume, &s->sample_spec));
 
-    /* make sure we don't change the volume when a PASSTHROUGH input is connected */
-    if (pa_sink_is_passthrough(s)) {
-        /* FIXME: Need to notify client that volume control is disabled */
+    /* make sure we don't change the volume when a PASSTHROUGH input is connected ...
+     * ... *except* if we're being invoked to reset the volume to ensure 0 dB gain */
+    if (pa_sink_is_passthrough(s) && (!volume || !pa_cvolume_is_norm(volume))) {
         pa_log_warn("Cannot change volume, Sink is connected to PASSTHROUGH input");
         return;
     }
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 3f89784..e5eaab3 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -110,6 +110,10 @@ struct pa_sink {
     pa_bool_t save_volume:1;
     pa_bool_t save_muted:1;
 
+    /* Saved volume state while we're in passthrough mode */
+    pa_cvolume saved_volume;
+    pa_bool_t saved_save_volume:1;
+
     pa_asyncmsgq *asyncmsgq;
 
     pa_memchunk silence;
@@ -418,6 +422,9 @@ pa_bool_t pa_sink_flat_volume_enabled(pa_sink *s);
 /* Is the sink in passthrough mode? (that is, is there a passthrough sink input
  * connected to this sink? */
 pa_bool_t pa_sink_is_passthrough(pa_sink *s);
+/* These should be called when a sink enters/leaves passthrough mode */
+void pa_sink_enter_passthrough(pa_sink *s);
+void pa_sink_leave_passthrough(pa_sink *s);
 
 void pa_sink_set_volume(pa_sink *sink, const pa_cvolume *volume, pa_bool_t sendmsg, pa_bool_t save);
 const pa_cvolume *pa_sink_get_volume(pa_sink *sink, pa_bool_t force_refresh);



More information about the pulseaudio-commits mailing list