volume control: second part
[profile/ivi/pulseaudio-module-murphy-ivi.git] / murphy / fader.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5
6 #include <pulsecore/pulsecore-config.h>
7
8 #include <pulse/proplist.h>
9 #include <pulsecore/core-util.h>
10 #include <pulsecore/sink.h>
11 #include <pulsecore/sink-input.h>
12
13 #include "fader.h"
14 #include "node.h"
15 #include "discover.h"
16 #include "volume.h"
17 #include "utils.h"
18
19 static void set_stream_volume_limit(struct userdata *, pa_sink_input *, double);
20
21 void pa_fader_apply_volume_limits(struct userdata *u, uint32_t stamp)
22 {
23     pa_core       *core;
24     pa_sink       *sink;
25     pa_sink_input *sinp;
26     mir_node      *node;
27     double         atten;
28     uint32_t       i,j;
29     int            class;
30
31     pa_assert(u);
32     pa_assert_se((core = u->core));
33
34     pa_log_debug("applying volume limits ...");
35
36     PA_IDXSET_FOREACH(sink, core->sinks, i) {
37         if ((node = pa_discover_find_node_by_ptr(u, sink))) {
38             pa_log_debug("   node '%s'", node->amname);
39             
40             PA_IDXSET_FOREACH(sinp, sink->inputs, j) {
41                 class = pa_utils_get_stream_class(sinp->proplist);
42                 atten = mir_volume_apply_limits(u, node, class, stamp);
43                 
44                 pa_log_debug("     stream %u attenuation %.2lf dB", sinp->index, atten);
45
46                 set_stream_volume_limit(u, sinp, atten);
47             }
48         }
49     }
50 }
51
52
53 static void set_stream_volume_limit(struct userdata *u, pa_sink_input *sinp, double limit)
54 {
55     pa_sink *sink;
56     pa_volume_t vol;
57
58     pa_assert(u);
59     pa_assert(sinp);
60     pa_assert_se((sink = sinp->sink));
61
62     vol = pa_sw_volume_from_dB(limit);
63     pa_cvolume_set(&sinp->volume_factor, sinp->volume.channels, vol);
64
65     if (pa_sink_flat_volume_enabled(sink)) {
66         pa_sink_set_volume(sink, NULL, TRUE, FALSE);
67     }
68     else {
69         pa_sw_cvolume_multiply(&sinp->soft_volume, &sinp->real_ratio, &sinp->volume_factor);
70
71         pa_asyncmsgq_send(sink->asyncmsgq, PA_MSGOBJECT(sinp),
72                           PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL);
73     }
74     
75
76 }
77
78
79 /*
80  * Local Variables:
81  * c-basic-offset: 4
82  * indent-tabs-mode: nil
83  * End:
84  *
85  */