]> code.delx.au - pulseaudio/commitdiff
add support for volume manipulation
authorLennart Poettering <lennart@poettering.net>
Sun, 15 Aug 2004 13:15:51 +0000 (13:15 +0000)
committerLennart Poettering <lennart@poettering.net>
Sun, 15 Aug 2004 13:15:51 +0000 (13:15 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@125 fefdeb5f-60dc-0310-8127-8f9354f1896f

polyp/cli-command.c
polyp/pdispatch.c
polyp/protocol-native.c
polyp/sample.h
polyp/sink-input.c
polyp/sink-input.h
polyp/sink.c

index 1d454f2a5bc2b23bf7067fa3927878f588b02daf..aa61b10efeaf8f45b0eae8e405b88209c83f2f9e 100644 (file)
@@ -338,7 +338,7 @@ static int pa_cli_command_sink_input_volume(struct pa_core *c, struct pa_tokeniz
         return -1;
     }
 
-    si->volume = (uint32_t) volume;
+    pa_sink_input_set_volume(si, (uint32_t) volume);
     return 0;
 }
 
index 9ed91fc594a4152b2fe2028196338daf808cc402..c46d4f770c6c1b73951c2edecb1d7831e061955c 100644 (file)
@@ -175,13 +175,14 @@ int pa_pdispatch_run(struct pa_pdispatch *pd, struct pa_packet*packet, void *use
         if (r)
             run_action(pd, r, command, ts);
 
-    } else if (pd->command_table && command < pd->n_commands) {
+    } else if (pd->command_table && (command < pd->n_commands) && pd->command_table[command].proc) {
         const struct pa_pdispatch_command *c = pd->command_table+command;
 
-        if (c->proc)
-            c->proc(pd, command, tag, ts, userdata);
-    } else
+        c->proc(pd, command, tag, ts, userdata);
+    } else {
+        fprintf(stderr, "Recieved unsupported command %u\n", command);
         goto finish;
+    }
 
     ret = 0;
         
index 0d265e332f399d6515c95575c2dcb3a15a671d51..7df39fe3f90bbdbf8d61b1516c8ba72b84b82fcd 100644 (file)
@@ -134,6 +134,7 @@ static void command_get_info(struct pa_pdispatch *pd, uint32_t command, uint32_t
 static void command_get_info_list(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
 static void command_get_server_info(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
 static void command_subscribe(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
+static void command_set_volume(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata);
 
 static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
     [PA_COMMAND_ERROR] = { NULL },
@@ -167,6 +168,7 @@ static const struct pa_pdispatch_command command_table[PA_COMMAND_MAX] = {
     [PA_COMMAND_GET_CLIENT_INFO_LIST] = { command_get_info_list },
     [PA_COMMAND_GET_SERVER_INFO] = { command_get_server_info },
     [PA_COMMAND_SUBSCRIBE] = { command_subscribe },
+    [PA_COMMAND_SET_SINK_VOLUME] = { command_set_volume },
 };
 
 /* structure management */
@@ -1164,9 +1166,53 @@ static void command_subscribe(struct pa_pdispatch *pd, uint32_t command, uint32_
         c->subscription = NULL;
 
     pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
+static void command_set_volume(struct pa_pdispatch *pd, uint32_t command, uint32_t tag, struct pa_tagstruct *t, void *userdata) {
+    struct connection *c = userdata;
+    uint32_t index, volume;
+    struct pa_sink *sink = NULL;
+    struct pa_sink_input *si = NULL;
+    const char *name = NULL;
+    assert(c && t);
+
+    if (pa_tagstruct_getu32(t, &index) < 0 ||
+        (command == PA_COMMAND_SET_SINK_VOLUME && pa_tagstruct_gets(t, &name) < 0) ||
+        pa_tagstruct_getu32(t, &volume) ||
+        !pa_tagstruct_eof(t)) {
+        protocol_error(c);
+        return;
+    }
     
+    if (!c->authorized) {
+        pa_pstream_send_error(c->pstream, tag, PA_ERROR_ACCESS);
+        return;
+    }
+
+    if (command == PA_COMMAND_SET_SINK_VOLUME) {
+        if (index != (uint32_t) -1)
+            sink = pa_idxset_get_by_index(c->protocol->core->sinks, index);
+        else
+            sink = pa_namereg_get(c->protocol->core, *name ? name : NULL, PA_NAMEREG_SINK, 1);
+    }  else {
+        assert(command == PA_COMMAND_SET_SINK_INPUT_VOLUME);
+        si = pa_idxset_get_by_index(c->protocol->core->sinks, index);
+    }
+
+    if (!si && !sink) {
+        pa_pstream_send_error(c->pstream, tag, PA_ERROR_NOENTITY);
+        return;
+    }
+
+    if (sink)
+        pa_sink_set_volume(sink, volume);
+    else if (si)
+        pa_sink_input_set_volume(si, volume);
+
+    pa_pstream_send_simple_ack(c->pstream, tag);
 }
 
+
 /*** pstream callbacks ***/
 
 static void pstream_packet_callback(struct pa_pstream *p, struct pa_packet *packet, void *userdata) {
index a7cde093ac478ca34403efb3186751f2a414c8dd..e397a1dfe1f378adbf6331ff652fe41483b435fa 100644 (file)
@@ -65,8 +65,13 @@ int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_s
 #define PA_SAMPLE_SNPRINT_MAX_LENGTH 32
 void pa_sample_snprint(char *s, size_t l, const struct pa_sample_spec *spec);
 
+/** Normal volume (100%) */
 #define PA_VOLUME_NORM (0x100)
+
+/** Muted volume (0%) */
 #define PA_VOLUME_MUTE (0)
+
+/** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
 uint32_t pa_volume_multiply(uint32_t a, uint32_t b);
 
 PA_C_DECL_END
index dd7469e0277592536e85ee2a312e1560f0323122..cf255a07846ca32bd10eff647b361b28a465dbd0 100644 (file)
@@ -168,3 +168,12 @@ void pa_sink_input_drop(struct pa_sink_input *i, size_t length) {
         i->resampled_chunk.index = i->resampled_chunk.length = 0;
     }
 }
+
+void pa_sink_input_set_volume(struct pa_sink_input *i, uint32_t volume) {
+    assert(i);
+
+    if (i->volume != volume) {
+        i->volume = volume;
+        pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+    }
+}
index 63dce71d52b0af9763e1ca0e4f853f615399785f..b21dbf4d01720b8f848919263322e82e30082826 100644 (file)
@@ -64,4 +64,6 @@ uint32_t pa_sink_input_get_latency(struct pa_sink_input *i);
 int pa_sink_input_peek(struct pa_sink_input *i, struct pa_memchunk *chunk);
 void pa_sink_input_drop(struct pa_sink_input *i, size_t length);
 
+void pa_sink_input_set_volume(struct pa_sink_input *i, uint32_t volume);
+
 #endif
index d9a3ae86177d1c70fa809adba11aee76cd2fe9a8..b8617ae1e2ab464eeb471569b904f23997dee1d7 100644 (file)
@@ -285,8 +285,9 @@ void pa_sink_set_owner(struct pa_sink *sink, struct pa_module *m) {
 
 void pa_sink_set_volume(struct pa_sink *sink, uint32_t volume) {
     assert(sink);
+    
     if (sink->volume != volume) {
-        pa_subscription_post(sink->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, sink->index);
         sink->volume = volume;
+        pa_subscription_post(sink->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, sink->index);
     }
 }