[polypaudio-commits] r587 - in /trunk/src: polyp/ polypcore/

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Feb 23 04:04:32 PST 2006


Author: ossman
Date: Thu Feb 23 13:04:31 2006
New Revision: 587

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=587&root=polypaudio&view=rev
Log:
Mute switch for sinks and sources. This is independent of the volume
setting (similar to ALSA).

Modified:
    trunk/src/polyp/introspect.c
    trunk/src/polyp/introspect.h
    trunk/src/polypcore/cli-command.c
    trunk/src/polypcore/native-common.h
    trunk/src/polypcore/protocol-native.c
    trunk/src/polypcore/sample-util.c
    trunk/src/polypcore/sample-util.h
    trunk/src/polypcore/sink.c
    trunk/src/polypcore/sink.h
    trunk/src/polypcore/source.c
    trunk/src/polypcore/source.h

Modified: trunk/src/polyp/introspect.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/introspect.c?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polyp/introspect.c (original)
+++ trunk/src/polyp/introspect.c Thu Feb 23 13:04:31 2006
@@ -146,6 +146,7 @@
                 pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
                 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
                 pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
+                pa_tagstruct_get_boolean(t, &i.mute) < 0 ||
                 pa_tagstruct_getu32(t, &i.monitor_source) < 0 ||
                 pa_tagstruct_gets(t, &i.monitor_source_name) < 0 ||
                 pa_tagstruct_get_usec(t, &i.latency) < 0 ||
@@ -249,6 +250,7 @@
                 pa_tagstruct_get_channel_map(t, &i.channel_map) < 0 ||
                 pa_tagstruct_getu32(t, &i.owner_module) < 0 ||
                 pa_tagstruct_get_cvolume(t, &i.volume) < 0 ||
+                pa_tagstruct_get_boolean(t, &i.mute) < 0 ||
                 pa_tagstruct_getu32(t, &i.monitor_of_sink) < 0 ||
                 pa_tagstruct_gets(t, &i.monitor_of_sink_name) < 0 ||
                 pa_tagstruct_get_usec(t, &i.latency) < 0 ||
@@ -682,6 +684,52 @@
     return o;
 }
 
+pa_operation* pa_context_set_sink_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >= 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+
+    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_MUTE, &tag);
+    pa_tagstruct_putu32(t, idx);
+    pa_tagstruct_puts(t, NULL);
+    pa_tagstruct_put_boolean(t, mute);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o));
+
+    return o;
+}
+
+pa_operation* pa_context_set_sink_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >= 1);
+    assert(name);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
+    
+    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t = pa_tagstruct_command(c, PA_COMMAND_SET_SINK_MUTE, &tag);
+    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+    pa_tagstruct_puts(t, name);
+    pa_tagstruct_put_boolean(t, mute);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o));
+
+    return o;
+}
+
 pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata) {
     pa_operation *o;
     pa_tagstruct *t;
@@ -750,6 +798,52 @@
     pa_tagstruct_putu32(t, PA_INVALID_INDEX);
     pa_tagstruct_puts(t, name);
     pa_tagstruct_put_cvolume(t, volume);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o));
+
+    return o;
+}
+
+pa_operation* pa_context_set_source_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >= 1);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+
+    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_MUTE, &tag);
+    pa_tagstruct_putu32(t, idx);
+    pa_tagstruct_puts(t, NULL);
+    pa_tagstruct_put_boolean(t, mute);
+    pa_pstream_send_tagstruct(c->pstream, t);
+    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o));
+
+    return o;
+}
+
+pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata) {
+    pa_operation *o;
+    pa_tagstruct *t;
+    uint32_t tag;
+
+    assert(c);
+    assert(c->ref >= 1);
+    assert(name);
+
+    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !name || *name, PA_ERR_INVALID);
+    
+    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
+
+    t = pa_tagstruct_command(c, PA_COMMAND_SET_SOURCE_MUTE, &tag);
+    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
+    pa_tagstruct_puts(t, name);
+    pa_tagstruct_put_boolean(t, mute);
     pa_pstream_send_tagstruct(c->pstream, t);
     pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o));
 

Modified: trunk/src/polyp/introspect.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/introspect.h?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polyp/introspect.h (original)
+++ trunk/src/polyp/introspect.h Thu Feb 23 13:04:31 2006
@@ -58,6 +58,7 @@
     pa_channel_map channel_map;        /**< Channel map \since 0.9 */
     uint32_t owner_module;             /**< Index of the owning module of this sink, or PA_INVALID_INDEX */
     pa_cvolume volume;                 /**< Volume of the sink */
+    int mute;                          /**< Mute switch of the sink \since 0.8 */
     uint32_t monitor_source;           /**< Index of the monitor source connected to this sink */
     const char *monitor_source_name;   /**< The name of the monitor source */
     pa_usec_t latency;                 /**< Length of filled playback buffer of this sink */
@@ -85,6 +86,7 @@
     pa_channel_map channel_map;         /**< Channel map \since 0.9 */
     uint32_t owner_module;              /**< Owning module index, or PA_INVALID_INDEX */
     pa_cvolume volume;                  /**< Volume of the source \since 0.8 */
+    int mute;                           /**< Mute switch of the sink \since 0.8 */
     uint32_t monitor_of_sink;           /**< If this is a monitor source the index of the owning sink, otherwise PA_INVALID_INDEX */
     const char *monitor_of_sink_name;   /**< Name of the owning sink, or PA_INVALID_INDEX */
     pa_usec_t latency;                  /**< Length of filled record buffer of this source. \since 0.5 */
@@ -211,6 +213,12 @@
 /** Set the volume of a sink device specified by its name */
 pa_operation* pa_context_set_sink_volume_by_name(pa_context *c, const char *name, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
 
+/** Set the mute switch of a sink device specified by its index \since 0.8 */
+pa_operation* pa_context_set_sink_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a sink device specified by its name \since 0.8 */
+pa_operation* pa_context_set_sink_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata);
+
 /** Set the volume of a sink input stream */
 pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
 
@@ -219,6 +227,12 @@
 
 /** Set the volume of a source device specified by its name \since 0.8 */
 pa_operation* pa_context_set_source_volume_by_name(pa_context *c, const char *name, const pa_cvolume *volume, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a source device specified by its index \since 0.8 */
+pa_operation* pa_context_set_source_mute_by_index(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata);
+
+/** Set the mute switch of a source device specified by its name \since 0.8 */
+pa_operation* pa_context_set_source_mute_by_name(pa_context *c, const char *name, int mute, pa_context_success_cb_t cb, void *userdata);
 
 /** Memory block statistics */
 typedef struct pa_stat_info {

Modified: trunk/src/polypcore/cli-command.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/cli-command.c?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/cli-command.c (original)
+++ trunk/src/polypcore/cli-command.c Thu Feb 23 13:04:31 2006
@@ -78,6 +78,8 @@
 static int pa_cli_command_sink_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
 static int pa_cli_command_sink_input_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
 static int pa_cli_command_source_volume(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
+static int pa_cli_command_sink_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
+static int pa_cli_command_source_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
 static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
 static int pa_cli_command_source_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
 static int pa_cli_command_kill_client(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, int *fail);
@@ -116,6 +118,8 @@
     { "set-sink-volume",         pa_cli_command_sink_volume,        "Set the volume of a sink (args: index|name, volume)",             3},
     { "set-sink-input-volume",   pa_cli_command_sink_input_volume,  "Set the volume of a sink input (args: index|name, volume)", 3},
     { "set-source-volume",       pa_cli_command_source_volume,      "Set the volume of a source (args: index|name, volume)", 3},
+    { "set-sink-mute",           pa_cli_command_sink_mute,          "Set the mute switch of a sink (args: index|name, mute)", 3},
+    { "set-source-mute",         pa_cli_command_source_mute,        "Set the mute switch of a source (args: index|name, mute)", 3},
     { "set-default-sink",        pa_cli_command_sink_default,       "Set the default sink (args: index|name)", 2},
     { "set-default-source",      pa_cli_command_source_default,     "Set the default source (args: index|name)", 2},
     { "kill-client",             pa_cli_command_kill_client,        "Kill a client (args: index)", 2},
@@ -409,6 +413,64 @@
     return 0;
 }
 
+static int pa_cli_command_sink_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) {
+    const char *n, *m;
+    pa_sink *sink;
+    int mute;
+
+    if (!(n = pa_tokenizer_get(t, 1))) {
+        pa_strbuf_puts(buf, "You need to specify a sink either by its name or its index.\n");
+        return -1;
+    }
+
+    if (!(m = pa_tokenizer_get(t, 2))) {
+        pa_strbuf_puts(buf, "You need to specify a mute switch setting (0/1).\n");
+        return -1;
+    }
+
+    if (pa_atoi(m, &mute) < 0) {
+        pa_strbuf_puts(buf, "Failed to parse mute switch.\n");
+        return -1;
+    }
+
+    if (!(sink = pa_namereg_get(c, n, PA_NAMEREG_SINK, 1))) {
+        pa_strbuf_puts(buf, "No sink found by this name or index.\n");
+        return -1;
+    }
+
+    pa_sink_set_mute(sink, PA_MIXER_HARDWARE, mute);
+    return 0;
+}
+
+static int pa_cli_command_source_mute(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) {
+    const char *n, *m;
+    pa_source *source;
+    int mute;
+
+    if (!(n = pa_tokenizer_get(t, 1))) {
+        pa_strbuf_puts(buf, "You need to specify a source either by its name or its index.\n");
+        return -1;
+    }
+
+    if (!(m = pa_tokenizer_get(t, 2))) {
+        pa_strbuf_puts(buf, "You need to specify a mute switch setting (0/1).\n");
+        return -1;
+    }
+
+    if (pa_atoi(m, &mute) < 0) {
+        pa_strbuf_puts(buf, "Failed to parse mute switch.\n");
+        return -1;
+    }
+
+    if (!(source = pa_namereg_get(c, n, PA_NAMEREG_SOURCE, 1))) {
+        pa_strbuf_puts(buf, "No sink found by this name or index.\n");
+        return -1;
+    }
+
+    pa_source_set_mute(source, PA_MIXER_HARDWARE, mute);
+    return 0;
+}
+
 static int pa_cli_command_sink_default(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_GCC_UNUSED int *fail) {
     const char *n;
     assert(c && t);
@@ -711,6 +773,7 @@
         }
 
         pa_strbuf_printf(buf, "set-sink-volume %s 0x%03x\n", sink->name, pa_cvolume_avg(pa_sink_get_volume(sink, PA_MIXER_HARDWARE)));
+        pa_strbuf_printf(buf, "set-sink-mute %s %d\n", sink->name, pa_sink_get_mute(sink, PA_MIXER_HARDWARE));
     }
 
     for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) {
@@ -723,6 +786,7 @@
         }
 
         pa_strbuf_printf(buf, "set-source-volume %s 0x%03x\n", source->name, pa_cvolume_avg(pa_source_get_volume(source, PA_MIXER_HARDWARE)));
+        pa_strbuf_printf(buf, "set-source-mute %s %d\n", source->name, pa_source_get_mute(source, PA_MIXER_HARDWARE));
     }
 
 

Modified: trunk/src/polypcore/native-common.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/native-common.h?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/native-common.h (original)
+++ trunk/src/polypcore/native-common.h Thu Feb 23 13:04:31 2006
@@ -72,6 +72,9 @@
     PA_COMMAND_SET_SINK_VOLUME,
     PA_COMMAND_SET_SINK_INPUT_VOLUME,
     PA_COMMAND_SET_SOURCE_VOLUME,
+
+    PA_COMMAND_SET_SINK_MUTE,
+    PA_COMMAND_SET_SOURCE_MUTE,
     
     PA_COMMAND_CORK_PLAYBACK_STREAM,
     PA_COMMAND_FLUSH_PLAYBACK_STREAM,

Modified: trunk/src/polypcore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/protocol-native.c?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/protocol-native.c (original)
+++ trunk/src/polypcore/protocol-native.c Thu Feb 23 13:04:31 2006
@@ -161,6 +161,7 @@
 static void command_get_server_info(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_subscribe(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_set_volume(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
+static void command_set_mute(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_cork_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_flush_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
 static void command_trigger_or_prebuf_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata);
@@ -220,6 +221,9 @@
     [PA_COMMAND_SET_SINK_INPUT_VOLUME] = command_set_volume,
     [PA_COMMAND_SET_SOURCE_VOLUME] = command_set_volume,
     
+    [PA_COMMAND_SET_SINK_MUTE] = command_set_mute,
+    [PA_COMMAND_SET_SOURCE_MUTE] = command_set_mute,
+
     [PA_COMMAND_CORK_PLAYBACK_STREAM] = command_cork_playback_stream,
     [PA_COMMAND_FLUSH_PLAYBACK_STREAM] = command_flush_playback_stream,
     [PA_COMMAND_TRIGGER_PLAYBACK_STREAM] = command_trigger_or_prebuf_playback_stream,
@@ -1184,6 +1188,7 @@
         PA_TAG_CHANNEL_MAP, &sink->channel_map,
         PA_TAG_U32, sink->owner ? sink->owner->index : PA_INVALID_INDEX,
         PA_TAG_CVOLUME, pa_sink_get_volume(sink, PA_MIXER_HARDWARE),
+        PA_TAG_BOOLEAN, pa_sink_get_mute(sink, PA_MIXER_HARDWARE),
         PA_TAG_U32, sink->monitor_source->index,
         PA_TAG_STRING, sink->monitor_source->name,
         PA_TAG_USEC, pa_sink_get_latency(sink),
@@ -1202,6 +1207,7 @@
         PA_TAG_CHANNEL_MAP, &source->channel_map,
         PA_TAG_U32, source->owner ? source->owner->index : PA_INVALID_INDEX,
         PA_TAG_CVOLUME, pa_source_get_volume(source, PA_MIXER_HARDWARE),
+        PA_TAG_BOOLEAN, pa_source_get_mute(source, PA_MIXER_HARDWARE),
         PA_TAG_U32, source->monitor_of ? source->monitor_of->index : PA_INVALID_INDEX,
         PA_TAG_STRING, source->monitor_of ? source->monitor_of->name : NULL,
         PA_TAG_USEC, pa_source_get_latency(source),
@@ -1530,6 +1536,55 @@
     pa_pstream_send_simple_ack(c->pstream, tag);
 }
 
+static void command_set_mute(
+        PA_GCC_UNUSED pa_pdispatch *pd,
+        uint32_t command,
+        uint32_t tag,
+        pa_tagstruct *t,
+        void *userdata) {
+    
+    struct connection *c = userdata;
+    uint32_t idx;
+    int mute;
+    pa_sink *sink = NULL;
+    pa_source *source = NULL;
+    const char *name = NULL;
+    assert(c && t);
+
+    if (pa_tagstruct_getu32(t, &idx) < 0 ||
+        pa_tagstruct_gets(t, &name) < 0 ||
+        pa_tagstruct_get_boolean(t, &mute) ||
+        !pa_tagstruct_eof(t)) {
+        protocol_error(c);
+        return;
+    }
+    
+    CHECK_VALIDITY(c->pstream, c->authorized, tag, PA_ERR_ACCESS);
+    CHECK_VALIDITY(c->pstream, idx != PA_INVALID_INDEX || !name || *name, tag, PA_ERR_INVALID);
+
+    if (command == PA_COMMAND_SET_SINK_MUTE) {
+        if (idx != PA_INVALID_INDEX)
+            sink = pa_idxset_get_by_index(c->protocol->core->sinks, idx);
+        else
+            sink = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SINK, 1);
+    } else {
+        assert(command == PA_COMMAND_SET_SOURCE_MUTE);
+        if (idx != (uint32_t) -1)
+            source = pa_idxset_get_by_index(c->protocol->core->sources, idx);
+        else
+            source = pa_namereg_get(c->protocol->core, name, PA_NAMEREG_SOURCE, 1);
+    }
+
+    CHECK_VALIDITY(c->pstream, sink || source, tag, PA_ERR_NOENTITY);
+
+    if (sink)
+        pa_sink_set_mute(sink, PA_MIXER_HARDWARE, mute);
+    else if (source)
+        pa_source_set_mute(source, PA_MIXER_HARDWARE, mute);
+
+    pa_pstream_send_simple_ack(c->pstream, tag);
+}
+
 static void command_cork_playback_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_UNUSED uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
     struct connection *c = userdata;
     uint32_t idx;

Modified: trunk/src/polypcore/sample-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sample-util.c?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/sample-util.c (original)
+++ trunk/src/polypcore/sample-util.c Thu Feb 23 13:04:31 2006
@@ -85,7 +85,8 @@
     void *data,
     size_t length,
     const pa_sample_spec *spec,
-    const pa_cvolume *volume) {
+    const pa_cvolume *volume,
+    int mute) {
     
     assert(streams && data && length && spec);
 
@@ -100,7 +101,7 @@
                 if (d >= length)
                     return d;
 
-                if (volume->values[channel] != PA_VOLUME_MUTED) {
+                if (!mute && volume->values[channel] != PA_VOLUME_MUTED) {
                     unsigned i;
                     
                     for (i = 0; i < nstreams; i++) {
@@ -152,7 +153,7 @@
                 if (d >= length)
                     return d;
 
-                if (volume->values[channel] != PA_VOLUME_MUTED) {
+                if (!mute && volume->values[channel] != PA_VOLUME_MUTED) {
                     unsigned i;
                     
                     for (i = 0; i < nstreams; i++) {
@@ -204,7 +205,7 @@
                 if (d >= length)
                     return d;
                 
-                if (volume->values[channel] != PA_VOLUME_MUTED) {
+                if (!mute && volume->values[channel] != PA_VOLUME_MUTED) {
                     unsigned i;
                     
                     for (i = 0; i < nstreams; i++) {

Modified: trunk/src/polypcore/sample-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sample-util.h?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/sample-util.h (original)
+++ trunk/src/polypcore/sample-util.h Thu Feb 23 13:04:31 2006
@@ -44,7 +44,8 @@
     void *data,
     size_t length,
     const pa_sample_spec *spec,
-    const pa_cvolume *volume);
+    const pa_cvolume *volume,
+    int mute);
 
 void pa_volume_memchunk(
     pa_memchunk*c,

Modified: trunk/src/polypcore/sink.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sink.c?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/sink.c (original)
+++ trunk/src/polypcore/sink.c Thu Feb 23 13:04:31 2006
@@ -84,11 +84,15 @@
 
     pa_cvolume_reset(&s->sw_volume, spec->channels);
     pa_cvolume_reset(&s->hw_volume, spec->channels);
+    s->sw_muted = 0;
+    s->hw_muted = 0;
 
     s->get_latency = NULL;
     s->notify = NULL;
     s->set_hw_volume = NULL;
     s->get_hw_volume = NULL;
+    s->set_hw_mute = NULL;
+    s->get_hw_mute = NULL;
     s->userdata = NULL;
 
     r = pa_idxset_put(core->sinks, s, &s->index);
@@ -131,6 +135,8 @@
     s->notify = NULL;
     s->get_hw_volume = NULL;
     s->set_hw_volume = NULL;
+    s->set_hw_mute = NULL;
+    s->get_hw_mute = NULL;
     
     s->state = PA_SINK_DISCONNECTED;
     pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
@@ -262,9 +268,12 @@
 
         pa_sw_cvolume_multiply(&volume, &s->sw_volume, &info[0].volume);
         
-        if (!pa_cvolume_is_norm(&volume)) {
+        if (s->sw_muted || !pa_cvolume_is_norm(&volume)) {
             pa_memchunk_make_writable(result, s->core->memblock_stat, 0);
-            pa_volume_memchunk(result, &s->sample_spec, &volume);
+            if (s->sw_muted)
+                pa_silence_memchunk(result, &s->sample_spec);
+            else
+                pa_volume_memchunk(result, &s->sample_spec, &volume);
         }
     } else {
         result->memblock = pa_memblock_new(length, s->core->memblock_stat);
@@ -272,7 +281,8 @@
 
 /*          pa_log("mixing %i", n);  */
 
-        result->length = pa_mix(info, n, result->memblock->data, length, &s->sample_spec, &s->sw_volume);
+        result->length = pa_mix(info, n, result->memblock->data, length,
+            &s->sample_spec, &s->sw_volume, s->sw_muted);
         result->index = 0;
     }
 
@@ -317,15 +327,18 @@
                target->length);
 
         pa_sw_cvolume_multiply(&volume, &s->sw_volume, &info[0].volume);
-        
-        if (!pa_cvolume_is_norm(&volume))
+
+        if (s->sw_muted)
+            pa_silence_memchunk(target, &s->sample_spec);        
+        else if (!pa_cvolume_is_norm(&volume))
             pa_volume_memchunk(target, &s->sample_spec, &volume);
     } else
         target->length = pa_mix(info, n,
                                 (uint8_t*) target->memblock->data + target->index,
                                 target->length,
                                 &s->sample_spec,
-                                &s->sw_volume);
+                                &s->sw_volume,
+                                s->sw_muted);
     
     inputs_drop(s, info, n, target->length);
     pa_source_post(s->monitor_source, target);
@@ -446,3 +459,40 @@
     } else
         return &s->sw_volume;
 }
+
+void pa_sink_set_mute(pa_sink *s, pa_mixer_t m, int mute) {
+    int *t;
+    
+    assert(s);
+    assert(s->ref >= 1);
+
+    if (m == PA_MIXER_HARDWARE && s->set_hw_mute) 
+        t = &s->hw_muted;
+    else
+        t = &s->sw_muted;
+
+    if (!!*t == !!mute)
+        return;
+        
+    *t = !!mute;
+
+    if (t == &s->hw_muted)
+        if (s->set_hw_mute(s) < 0)
+            s->sw_muted = !!mute;
+
+    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
+}
+
+int pa_sink_get_mute(pa_sink *s, pa_mixer_t m) {
+    assert(s);
+    assert(s->ref >= 1);
+
+    if (m == PA_MIXER_HARDWARE && s->set_hw_mute) {
+
+        if (s->get_hw_mute)
+            s->get_hw_mute(s);
+        
+        return s->hw_muted;
+    } else
+        return s->sw_muted;
+}

Modified: trunk/src/polypcore/sink.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sink.h?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/sink.h (original)
+++ trunk/src/polypcore/sink.h Thu Feb 23 13:04:31 2006
@@ -58,11 +58,14 @@
     pa_source *monitor_source;
     
     pa_cvolume hw_volume, sw_volume;
+    int hw_muted, sw_muted;
 
     void (*notify)(pa_sink*sink);
     pa_usec_t (*get_latency)(pa_sink *s);
     int (*set_hw_volume)(pa_sink *s);
     int (*get_hw_volume)(pa_sink *s);
+    int (*set_hw_mute)(pa_sink *s);
+    int (*get_hw_mute)(pa_sink *s);
     
     void *userdata;
 };
@@ -92,5 +95,7 @@
 
 void pa_sink_set_volume(pa_sink *sink, pa_mixer_t m, const pa_cvolume *volume);
 const pa_cvolume *pa_sink_get_volume(pa_sink *sink, pa_mixer_t m);
+void pa_sink_set_mute(pa_sink *sink, pa_mixer_t m, int mute);
+int pa_sink_get_mute(pa_sink *sink, pa_mixer_t m);
 
 #endif

Modified: trunk/src/polypcore/source.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/source.c?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/source.c (original)
+++ trunk/src/polypcore/source.c Thu Feb 23 13:04:31 2006
@@ -80,11 +80,15 @@
 
     pa_cvolume_reset(&s->sw_volume, spec->channels);
     pa_cvolume_reset(&s->hw_volume, spec->channels);
+    s->sw_muted = 0;
+    s->hw_muted = 0;
 
     s->get_latency = NULL;
     s->notify = NULL;
     s->set_hw_volume = NULL;
     s->get_hw_volume = NULL;
+    s->set_hw_mute = NULL;
+    s->get_hw_mute = NULL;
     s->userdata = NULL;
 
     r = pa_idxset_put(core->sources, s, &s->index);
@@ -118,6 +122,8 @@
     s->notify = NULL;
     s->get_hw_volume = NULL;
     s->set_hw_volume = NULL;
+    s->set_hw_mute = NULL;
+    s->get_hw_mute = NULL;
     
     s->state = PA_SOURCE_DISCONNECTED;
     pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
@@ -182,12 +188,15 @@
 
     pa_source_ref(s);
 
-    if (!pa_cvolume_is_norm(&s->sw_volume)) {
+    if (s->sw_muted || !pa_cvolume_is_norm(&s->sw_volume)) {
         pa_memchunk vchunk = *chunk;
         
         pa_memblock_ref(vchunk.memblock);
         pa_memchunk_make_writable(&vchunk, s->core->memblock_stat, 0);
-        pa_volume_memchunk(&vchunk, &s->sample_spec, &s->sw_volume);
+        if (s->sw_muted)
+            pa_silence_memchunk(&vchunk, &s->sample_spec);
+        else
+            pa_volume_memchunk(&vchunk, &s->sample_spec, &s->sw_volume);
         pa_idxset_foreach(s->outputs, do_post, &vchunk);
         pa_memblock_unref(vchunk.memblock);
     } else
@@ -250,3 +259,40 @@
     } else
         return &s->sw_volume;
 }
+
+void pa_source_set_mute(pa_source *s, pa_mixer_t m, int mute) {
+    int *t;
+    
+    assert(s);
+    assert(s->ref >= 1);
+
+    if (m == PA_MIXER_HARDWARE && s->set_hw_mute) 
+        t = &s->hw_muted;
+    else
+        t = &s->sw_muted;
+
+    if (!!*t == !!mute)
+        return;
+        
+    *t = !!mute;
+
+    if (t == &s->hw_muted)
+        if (s->set_hw_mute(s) < 0)
+            s->sw_muted = !!mute;
+
+    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
+}
+
+int pa_source_get_mute(pa_source *s, pa_mixer_t m) {
+    assert(s);
+    assert(s->ref >= 1);
+
+    if (m == PA_MIXER_HARDWARE && s->set_hw_mute) {
+
+        if (s->get_hw_mute)
+            s->get_hw_mute(s);
+        
+        return s->hw_muted;
+    } else
+        return s->sw_muted;
+}

Modified: trunk/src/polypcore/source.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/source.h?rev=587&root=polypaudio&r1=586&r2=587&view=diff
==============================================================================
--- trunk/src/polypcore/source.h (original)
+++ trunk/src/polypcore/source.h Thu Feb 23 13:04:31 2006
@@ -60,11 +60,14 @@
     pa_sink *monitor_of;
 
     pa_cvolume hw_volume, sw_volume;
+    int hw_muted, sw_muted;
     
     void (*notify)(pa_source*source);
     pa_usec_t (*get_latency)(pa_source *s);
     int (*set_hw_volume)(pa_source *s);
     int (*get_hw_volume)(pa_source *s);
+    int (*set_hw_mute)(pa_source *s);
+    int (*get_hw_mute)(pa_source *s);
     
     void *userdata;
 };
@@ -92,5 +95,7 @@
 
 void pa_source_set_volume(pa_source *source, pa_mixer_t m, const pa_cvolume *volume);
 const pa_cvolume *pa_source_get_volume(pa_source *source, pa_mixer_t m);
+void pa_source_set_mute(pa_source *source, pa_mixer_t m, int mute);
+int pa_source_get_mute(pa_source *source, pa_mixer_t m);
 
 #endif




More information about the pulseaudio-commits mailing list