clean pulseaudio recipes
[scm/bb/meta-tizen.git] / recipes-multimedia / pulseaudio / pulseaudio_5.0 / 0099-sink-input-source-output-Assign-to-reference_ratio-f.patch
1 From: Tanu Kaskinen <tanu.kaskinen@linux.intel.com>
2 Date: Mon, 4 Aug 2014 20:57:55 +0300
3 Subject: sink-input,
4  source-output: Assign to reference_ratio from a single place
5
6 This makes it easy to log a message every time the reference ratio
7 changes. I also need to add a hook for reference ratio changes, but
8 that need will go away if the stream relative volume controls will be
9 created by the core in the future.
10
11 Change-Id: I2344ba7825f76cd72241599bd138b21e16555e01
12 ---
13  src/pulsecore/sink-input.c    | 28 ++++++++++++++++++++++++++--
14  src/pulsecore/sink-input.h    |  6 ++++++
15  src/pulsecore/sink.c          | 11 +++++++----
16  src/pulsecore/source-output.c | 26 +++++++++++++++++++++++++-
17  src/pulsecore/source-output.h |  6 ++++++
18  src/pulsecore/source.c        | 11 +++++++----
19  6 files changed, 77 insertions(+), 11 deletions(-)
20
21 diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
22 index 9d13269..57c906d 100644
23 --- a/src/pulsecore/sink-input.c
24 +++ b/src/pulsecore/sink-input.c
25 @@ -1305,7 +1305,7 @@ void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, bool s
26          /* OK, we are in normal volume mode. The volume only affects
27           * ourselves */
28          set_real_ratio(i, volume);
29 -        i->reference_ratio = i->volume;
30 +        pa_sink_input_set_reference_ratio(i, &i->volume);
31  
32          /* Copy the new soft_volume to the thread_info struct */
33          pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
34 @@ -1757,7 +1757,7 @@ static void update_volume_due_to_moving(pa_sink_input *i, pa_sink *dest) {
35  
36              pa_cvolume_reset(&new_volume, i->volume.channels);
37              pa_sink_input_set_volume_direct(i, &new_volume);
38 -            pa_cvolume_reset(&i->reference_ratio, i->reference_ratio.channels);
39 +            pa_sink_input_set_reference_ratio(i, &new_volume);
40              pa_assert(pa_cvolume_is_norm(&i->real_ratio));
41              pa_assert(pa_cvolume_equal(&i->soft_volume, &i->volume_factor));
42          }
43 @@ -2329,3 +2329,27 @@ void pa_sink_input_set_volume_direct(pa_sink_input *i, const pa_cvolume *volume)
44      pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
45      pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_VOLUME_CHANGED], i);
46  }
47 +
48 +/* Called from the main thread. */
49 +void pa_sink_input_set_reference_ratio(pa_sink_input *i, const pa_cvolume *ratio) {
50 +    pa_cvolume old_ratio;
51 +    char old_ratio_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
52 +    char new_ratio_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
53 +
54 +    pa_assert(i);
55 +    pa_assert(ratio);
56 +
57 +    old_ratio = i->reference_ratio;
58 +
59 +    if (pa_cvolume_equal(ratio, &old_ratio))
60 +        return;
61 +
62 +    i->reference_ratio = *ratio;
63 +
64 +    if (!PA_SINK_INPUT_IS_LINKED(i->state))
65 +        return;
66 +
67 +    pa_log_debug("Sink input %u reference ratio changed from %s to %s.", i->index,
68 +                 pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &i->channel_map, true),
69 +                 pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &i->channel_map, true));
70 +}
71 diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
72 index 1bd3eee..e5b0ae8 100644
73 --- a/src/pulsecore/sink-input.h
74 +++ b/src/pulsecore/sink-input.h
75 @@ -437,6 +437,12 @@ pa_memchunk* pa_sink_input_get_silence(pa_sink_input *i, pa_memchunk *ret);
76   * and fires change notifications. */
77  void pa_sink_input_set_volume_direct(pa_sink_input *i, const pa_cvolume *volume);
78  
79 +/* Called from the main thread, from sink.c only. This shouldn't be a public
80 + * function, but the flat volume logic in sink.c currently needs a way to
81 + * directly set the sink input reference ratio. This function simply sets
82 + * i->reference_ratio and logs a message if the value changes. */
83 +void pa_sink_input_set_reference_ratio(pa_sink_input *i, const pa_cvolume *ratio);
84 +
85  #define pa_sink_input_assert_io_context(s) \
86      pa_assert(pa_thread_mq_get() || !PA_SINK_INPUT_IS_LINKED((s)->state))
87  
88 diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
89 index 41cffcc..400d06d 100644
90 --- a/src/pulsecore/sink.c
91 +++ b/src/pulsecore/sink.c
92 @@ -1670,6 +1670,7 @@ void pa_sink_leave_passthrough(pa_sink *s) {
93  static void compute_reference_ratio(pa_sink_input *i) {
94      unsigned c = 0;
95      pa_cvolume remapped;
96 +    pa_cvolume ratio;
97  
98      pa_assert(i);
99      pa_assert(pa_sink_flat_volume_enabled(i->sink));
100 @@ -1684,7 +1685,7 @@ static void compute_reference_ratio(pa_sink_input *i) {
101      remapped = i->sink->reference_volume;
102      pa_cvolume_remap(&remapped, &i->sink->channel_map, &i->channel_map);
103  
104 -    i->reference_ratio.channels = i->sample_spec.channels;
105 +    ratio = i->reference_ratio;
106  
107      for (c = 0; c < i->sample_spec.channels; c++) {
108  
109 @@ -1694,14 +1695,16 @@ static void compute_reference_ratio(pa_sink_input *i) {
110  
111          /* Don't update the reference ratio unless necessary */
112          if (pa_sw_volume_multiply(
113 -                    i->reference_ratio.values[c],
114 +                    ratio.values[c],
115                      remapped.values[c]) == i->volume.values[c])
116              continue;
117  
118 -        i->reference_ratio.values[c] = pa_sw_volume_divide(
119 +        ratio.values[c] = pa_sw_volume_divide(
120                  i->volume.values[c],
121                  remapped.values[c]);
122      }
123 +
124 +    pa_sink_input_set_reference_ratio(i, &ratio);
125  }
126  
127  /* Called from main context. Only called for the root sink in volume sharing
128 @@ -2195,7 +2198,7 @@ static void propagate_real_volume(pa_sink *s, const pa_cvolume *old_real_volume)
129  
130              /* 2. Since the sink's reference and real volumes are equal
131               * now our ratios should be too. */
132 -            i->reference_ratio = i->real_ratio;
133 +            pa_sink_input_set_reference_ratio(i, &i->real_ratio);
134  
135              /* 3. Recalculate the new stream reference volume based on the
136               * reference ratio and the sink's reference volume.
137 diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
138 index d3d15f1..0012be3 100644
139 --- a/src/pulsecore/source-output.c
140 +++ b/src/pulsecore/source-output.c
141 @@ -1313,7 +1313,7 @@ static void update_volume_due_to_moving(pa_source_output *o, pa_source *dest) {
142  
143              pa_cvolume_reset(&new_volume, o->volume.channels);
144              pa_source_output_set_volume_direct(o, &new_volume);
145 -            pa_cvolume_reset(&o->reference_ratio, o->reference_ratio.channels);
146 +            pa_source_output_set_reference_ratio(o, &new_volume);
147              pa_assert(pa_cvolume_is_norm(&o->real_ratio));
148              pa_assert(pa_cvolume_equal(&o->soft_volume, &o->volume_factor));
149          }
150 @@ -1695,3 +1695,27 @@ void pa_source_output_set_volume_direct(pa_source_output *o, const pa_cvolume *v
151      pa_subscription_post(o->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE, o->index);
152      pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_VOLUME_CHANGED], o);
153  }
154 +
155 +/* Called from the main thread. */
156 +void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume *ratio) {
157 +    pa_cvolume old_ratio;
158 +    char old_ratio_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
159 +    char new_ratio_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
160 +
161 +    pa_assert(o);
162 +    pa_assert(ratio);
163 +
164 +    old_ratio = o->reference_ratio;
165 +
166 +    if (pa_cvolume_equal(ratio, &old_ratio))
167 +        return;
168 +
169 +    o->reference_ratio = *ratio;
170 +
171 +    if (!PA_SOURCE_OUTPUT_IS_LINKED(o->state))
172 +        return;
173 +
174 +    pa_log_debug("Source output %u reference ratio changed from %s to %s.", o->index,
175 +                 pa_cvolume_snprint_verbose(old_ratio_str, sizeof(old_ratio_str), &old_ratio, &o->channel_map, true),
176 +                 pa_cvolume_snprint_verbose(new_ratio_str, sizeof(new_ratio_str), ratio, &o->channel_map, true));
177 +}
178 diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
179 index 73170d3..3ed950b 100644
180 --- a/src/pulsecore/source-output.h
181 +++ b/src/pulsecore/source-output.h
182 @@ -359,6 +359,12 @@ pa_usec_t pa_source_output_set_requested_latency_within_thread(pa_source_output
183   * o->volume and fires change notifications. */
184  void pa_source_output_set_volume_direct(pa_source_output *o, const pa_cvolume *volume);
185  
186 +/* Called from the main thread, from source.c only. This shouldn't be a public
187 + * function, but the flat volume logic in source.c currently needs a way to
188 + * directly set the source output reference ratio. This function simply sets
189 + * o->reference_ratio and logs a message if the value changes. */
190 +void pa_source_output_set_reference_ratio(pa_source_output *o, const pa_cvolume *ratio);
191 +
192  #define pa_source_output_assert_io_context(s) \
193      pa_assert(pa_thread_mq_get() || !PA_SOURCE_OUTPUT_IS_LINKED((s)->state))
194  
195 diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
196 index db7f667..293ab28 100644
197 --- a/src/pulsecore/source.c
198 +++ b/src/pulsecore/source.c
199 @@ -1214,6 +1214,7 @@ void pa_source_leave_passthrough(pa_source *s) {
200  static void compute_reference_ratio(pa_source_output *o) {
201      unsigned c = 0;
202      pa_cvolume remapped;
203 +    pa_cvolume ratio;
204  
205      pa_assert(o);
206      pa_assert(pa_source_flat_volume_enabled(o->source));
207 @@ -1228,7 +1229,7 @@ static void compute_reference_ratio(pa_source_output *o) {
208      remapped = o->source->reference_volume;
209      pa_cvolume_remap(&remapped, &o->source->channel_map, &o->channel_map);
210  
211 -    o->reference_ratio.channels = o->sample_spec.channels;
212 +    ratio = o->reference_ratio;
213  
214      for (c = 0; c < o->sample_spec.channels; c++) {
215  
216 @@ -1238,14 +1239,16 @@ static void compute_reference_ratio(pa_source_output *o) {
217  
218          /* Don't update the reference ratio unless necessary */
219          if (pa_sw_volume_multiply(
220 -                    o->reference_ratio.values[c],
221 +                    ratio.values[c],
222                      remapped.values[c]) == o->volume.values[c])
223              continue;
224  
225 -        o->reference_ratio.values[c] = pa_sw_volume_divide(
226 +        ratio.values[c] = pa_sw_volume_divide(
227                  o->volume.values[c],
228                  remapped.values[c]);
229      }
230 +
231 +    pa_source_output_set_reference_ratio(o, &ratio);
232  }
233  
234  /* Called from main context. Only called for the root source in volume sharing
235 @@ -1712,7 +1715,7 @@ static void propagate_real_volume(pa_source *s, const pa_cvolume *old_real_volum
236  
237              /* 2. Since the source's reference and real volumes are equal
238               * now our ratios should be too. */
239 -            o->reference_ratio = o->real_ratio;
240 +            pa_source_output_set_reference_ratio(o, &o->real_ratio);
241  
242              /* 3. Recalculate the new stream reference volume based on the
243               * reference ratio and the sink's reference volume.