diff options
author | Pierre Ossman <ossman@cendio.se> | 2006-02-23 12:04:31 +0000 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2006-02-23 12:04:31 +0000 |
commit | 04c8926739cd5d979077b81b73a0ead0458594a7 (patch) | |
tree | 0de678845142bfef323b0b8a0b3bca7791ab1078 /src | |
parent | bd4ae44e9a4b4cf3071cbbbaf9bbb4f84397cd90 (diff) |
Mute switch for sinks and sources. This is independent of the volume
setting (similar to ALSA).
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@587 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r-- | src/polyp/introspect.c | 94 | ||||
-rw-r--r-- | src/polyp/introspect.h | 14 | ||||
-rw-r--r-- | src/polypcore/cli-command.c | 64 | ||||
-rw-r--r-- | src/polypcore/native-common.h | 3 | ||||
-rw-r--r-- | src/polypcore/protocol-native.c | 55 | ||||
-rw-r--r-- | src/polypcore/sample-util.c | 9 | ||||
-rw-r--r-- | src/polypcore/sample-util.h | 3 | ||||
-rw-r--r-- | src/polypcore/sink.c | 62 | ||||
-rw-r--r-- | src/polypcore/sink.h | 5 | ||||
-rw-r--r-- | src/polypcore/source.c | 50 | ||||
-rw-r--r-- | src/polypcore/source.h | 5 |
11 files changed, 351 insertions, 13 deletions
diff --git a/src/polyp/introspect.c b/src/polyp/introspect.c index 6a9917a7..6a28998c 100644 --- a/src/polyp/introspect.c +++ b/src/polyp/introspect.c @@ -146,6 +146,7 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, P 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 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command, 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 @@ pa_operation* pa_context_set_sink_volume_by_name(pa_context *c, const char *name 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; @@ -756,6 +804,52 @@ pa_operation* pa_context_set_source_volume_by_name(pa_context *c, const char *na 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)); + + return o; +} + /** Sample Cache **/ static void context_get_sample_info_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) { diff --git a/src/polyp/introspect.h b/src/polyp/introspect.h index d7fad9c4..4ef776f8 100644 --- a/src/polyp/introspect.h +++ b/src/polyp/introspect.h @@ -58,6 +58,7 @@ typedef struct pa_sink_info { 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 @@ typedef struct pa_source_info { 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 @@ pa_operation* pa_context_set_sink_volume_by_index(pa_context *c, uint32_t idx, c /** 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); @@ -220,6 +228,12 @@ pa_operation* pa_context_set_source_volume_by_index(pa_context *c, uint32_t idx, /** 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 { uint32_t memblock_total; /**< Currently allocated memory blocks */ diff --git a/src/polypcore/cli-command.c b/src/polypcore/cli-command.c index cd7993a8..0251ab0a 100644 --- a/src/polypcore/cli-command.c +++ b/src/polypcore/cli-command.c @@ -78,6 +78,8 @@ static int pa_cli_command_unload(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, in 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 @@ static const struct command commands[] = { { "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 @@ static int pa_cli_command_source_volume(pa_core *c, pa_tokenizer *t, pa_strbuf * 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 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G } 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 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, PA_G } 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)); } diff --git a/src/polypcore/native-common.h b/src/polypcore/native-common.h index a5ca5c96..1107da55 100644 --- a/src/polypcore/native-common.h +++ b/src/polypcore/native-common.h @@ -72,6 +72,9 @@ enum { 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, diff --git a/src/polypcore/protocol-native.c b/src/polypcore/protocol-native.c index dce6b346..52eaed4f 100644 --- a/src/polypcore/protocol-native.c +++ b/src/polypcore/protocol-native.c @@ -161,6 +161,7 @@ static void command_get_info_list(pa_pdispatch *pd, uint32_t command, uint32_t t 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 @@ static const pa_pdispatch_cb_t command_table[PA_COMMAND_MAX] = { [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 @@ static void sink_fill_tagstruct(pa_tagstruct *t, pa_sink *sink) { 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 @@ static void source_fill_tagstruct(pa_tagstruct *t, pa_source *source) { 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 @@ static void command_set_volume( 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; diff --git a/src/polypcore/sample-util.c b/src/polypcore/sample-util.c index 2c3fbd79..7afb9d11 100644 --- a/src/polypcore/sample-util.c +++ b/src/polypcore/sample-util.c @@ -85,7 +85,8 @@ size_t pa_mix( 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 @@ size_t pa_mix( 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 @@ size_t pa_mix( 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 @@ size_t pa_mix( 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++) { diff --git a/src/polypcore/sample-util.h b/src/polypcore/sample-util.h index 7ea01a30..da7f56e1 100644 --- a/src/polypcore/sample-util.h +++ b/src/polypcore/sample-util.h @@ -44,7 +44,8 @@ size_t pa_mix( 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, diff --git a/src/polypcore/sink.c b/src/polypcore/sink.c index cb072c35..17294059 100644 --- a/src/polypcore/sink.c +++ b/src/polypcore/sink.c @@ -84,11 +84,15 @@ pa_sink* pa_sink_new( 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 @@ void pa_sink_disconnect(pa_sink* s) { 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 @@ int pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) { 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 @@ int pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) { /* 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 @@ int pa_sink_render_into(pa_sink*s, pa_memchunk *target) { 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 @@ const pa_cvolume *pa_sink_get_volume(pa_sink *s, pa_mixer_t m) { } 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; +} diff --git a/src/polypcore/sink.h b/src/polypcore/sink.h index 5f1a6cc8..59d45597 100644 --- a/src/polypcore/sink.h +++ b/src/polypcore/sink.h @@ -58,11 +58,14 @@ struct pa_sink { 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_owner(pa_sink *sink, pa_module *m); 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 diff --git a/src/polypcore/source.c b/src/polypcore/source.c index e97c31d8..9e9415b6 100644 --- a/src/polypcore/source.c +++ b/src/polypcore/source.c @@ -80,11 +80,15 @@ pa_source* pa_source_new( 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 @@ void pa_source_disconnect(pa_source *s) { 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 @@ void pa_source_post(pa_source*s, const pa_memchunk *chunk) { 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 @@ const pa_cvolume *pa_source_get_volume(pa_source *s, pa_mixer_t m) { } 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; +} diff --git a/src/polypcore/source.h b/src/polypcore/source.h index 3c5bb6c4..63b77624 100644 --- a/src/polypcore/source.h +++ b/src/polypcore/source.h @@ -60,11 +60,14 @@ struct pa_source { 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 @@ pa_usec_t pa_source_get_latency(pa_source *s); 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 |