mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
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
This commit is contained in:
parent
bd4ae44e9a
commit
04c8926739
11 changed files with 351 additions and 13 deletions
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue