mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
Allow read-only or non-existing sink input volume.
There are two known cases where read-only or non-existing sink input volume is relevant: passthrough streams and the planned volume sharing logic. Passthrough streams don't have volume at all, and the volume sharing logic requires read-only sink input volume. This commit is primarily working towards the volume sharing feature, but support for non-existing sink input volume is also added, because it is so closely related to read-only volume. Some unrelated refactoring in iface-stream.c creeped into this commit too (new function: stream_to_string()).
This commit is contained in:
parent
fa12d2a8a8
commit
99ddca89cd
9 changed files with 156 additions and 63 deletions
8
PROTOCOL
8
PROTOCOL
|
|
@ -203,7 +203,13 @@ new flag at end of CREATE_PLAYBACK_STREAM:
|
||||||
|
|
||||||
## v19, implemented by >= 0.9.22
|
## v19, implemented by >= 0.9.22
|
||||||
|
|
||||||
New proplist field for sink input, source output introspection opcodes and at the end:
|
New flag at the end of sink input and source output introspection data:
|
||||||
|
|
||||||
bool corked
|
bool corked
|
||||||
|
|
||||||
|
## v20, implemented by >= 1.0
|
||||||
|
|
||||||
|
Two new flags at the end of sink input introspection data:
|
||||||
|
|
||||||
|
bool has_volume
|
||||||
|
bool read_only_volume
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,9 @@ struct pa_dbusiface_stream {
|
||||||
dbus_bool_t mute;
|
dbus_bool_t mute;
|
||||||
pa_proplist *proplist;
|
pa_proplist *proplist;
|
||||||
|
|
||||||
|
pa_bool_t has_volume;
|
||||||
|
pa_bool_t read_only_volume;
|
||||||
|
|
||||||
pa_dbus_protocol *dbus_protocol;
|
pa_dbus_protocol *dbus_protocol;
|
||||||
pa_subscription *subscription;
|
pa_subscription *subscription;
|
||||||
pa_hook_slot *send_event_slot;
|
pa_hook_slot *send_event_slot;
|
||||||
|
|
@ -189,6 +192,14 @@ static void handle_get_index(DBusConnection *conn, DBusMessage *msg, void *userd
|
||||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &idx);
|
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The returned string has to be freed with pa_xfree() by the caller. */
|
||||||
|
static char *stream_to_string(pa_dbusiface_stream *s) {
|
||||||
|
if (s->type == STREAM_TYPE_PLAYBACK)
|
||||||
|
return pa_sprintf_malloc("Playback stream %u", (unsigned) s->sink_input->index);
|
||||||
|
else
|
||||||
|
return pa_sprintf_malloc("Record stream %u", (unsigned) s->source_output->index);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_get_driver(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
static void handle_get_driver(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||||
pa_dbusiface_stream *s = userdata;
|
pa_dbusiface_stream *s = userdata;
|
||||||
const char *driver = NULL;
|
const char *driver = NULL;
|
||||||
|
|
@ -200,12 +211,11 @@ static void handle_get_driver(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
driver = (s->type == STREAM_TYPE_PLAYBACK) ? s->sink_input->driver : s->source_output->driver;
|
driver = (s->type == STREAM_TYPE_PLAYBACK) ? s->sink_input->driver : s->source_output->driver;
|
||||||
|
|
||||||
if (!driver) {
|
if (!driver) {
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK)
|
char *str = stream_to_string(s);
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
|
|
||||||
"Playback stream %u doesn't have a driver.", s->sink_input->index);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s doesn't have a driver.", str);
|
||||||
else
|
pa_xfree(str);
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
|
|
||||||
"Record stream %u doesn't have a driver.", s->source_output->index);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,12 +234,11 @@ static void handle_get_owner_module(DBusConnection *conn, DBusMessage *msg, void
|
||||||
owner_module = (s->type == STREAM_TYPE_PLAYBACK) ? s->sink_input->module : s->source_output->module;
|
owner_module = (s->type == STREAM_TYPE_PLAYBACK) ? s->sink_input->module : s->source_output->module;
|
||||||
|
|
||||||
if (!owner_module) {
|
if (!owner_module) {
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK)
|
char *str = stream_to_string(s);
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
|
|
||||||
"Playback stream %u doesn't have an owner module.", s->sink_input->index);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s doesn't have an owner module.", str);
|
||||||
else
|
pa_xfree(str);
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
|
|
||||||
"Record stream %u doesn't have an owner module.", s->source_output->index);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,12 +259,11 @@ static void handle_get_client(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
client = (s->type == STREAM_TYPE_PLAYBACK) ? s->sink_input->client : s->source_output->client;
|
client = (s->type == STREAM_TYPE_PLAYBACK) ? s->sink_input->client : s->source_output->client;
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK)
|
char *str = stream_to_string(s);
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
|
|
||||||
"Playback stream %u isn't associated to any client.", s->sink_input->index);
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s isn't associated to any client.", str);
|
||||||
else
|
pa_xfree(str);
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
|
|
||||||
"Record stream %u isn't associated to any client.", s->source_output->index);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,8 +340,12 @@ static void handle_get_volume(DBusConnection *conn, DBusMessage *msg, void *user
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_RECORD) {
|
if (!s->has_volume) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "Record streams don't have volume.");
|
char *str = stream_to_string(s);
|
||||||
|
|
||||||
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s doesn't have volume.", str);
|
||||||
|
pa_xfree(str);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -357,8 +369,15 @@ static void handle_set_volume(DBusConnection *conn, DBusMessage *msg, DBusMessag
|
||||||
pa_assert(iter);
|
pa_assert(iter);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_RECORD) {
|
if (!s->has_volume || s->read_only_volume) {
|
||||||
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "Record streams don't have volume.");
|
char *str = stream_to_string(s);
|
||||||
|
|
||||||
|
if (!s->has_volume)
|
||||||
|
pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY, "%s doesn't have volume.", str);
|
||||||
|
else if (s->read_only_volume)
|
||||||
|
pa_dbus_send_error(conn, msg, DBUS_ERROR_ACCESS_DENIED, "%s has read-only volume.", str);
|
||||||
|
pa_xfree(str);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -509,6 +528,11 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
pa_assert(msg);
|
pa_assert(msg);
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
|
|
||||||
|
if (s->has_volume) {
|
||||||
|
for (i = 0; i < s->volume.channels; ++i)
|
||||||
|
volume[i] = s->volume.values[i];
|
||||||
|
}
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK) {
|
if (s->type == STREAM_TYPE_PLAYBACK) {
|
||||||
idx = s->sink_input->index;
|
idx = s->sink_input->index;
|
||||||
driver = s->sink_input->driver;
|
driver = s->sink_input->driver;
|
||||||
|
|
@ -517,8 +541,6 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
device = pa_dbusiface_core_get_sink_path(s->core, s->sink);
|
device = pa_dbusiface_core_get_sink_path(s->core, s->sink);
|
||||||
sample_format = s->sink_input->sample_spec.format;
|
sample_format = s->sink_input->sample_spec.format;
|
||||||
channel_map = &s->sink_input->channel_map;
|
channel_map = &s->sink_input->channel_map;
|
||||||
for (i = 0; i < s->volume.channels; ++i)
|
|
||||||
volume[i] = s->volume.values[i];
|
|
||||||
buffer_latency = pa_sink_input_get_latency(s->sink_input, &device_latency);
|
buffer_latency = pa_sink_input_get_latency(s->sink_input, &device_latency);
|
||||||
resample_method = pa_resample_method_to_string(s->sink_input->actual_resample_method);
|
resample_method = pa_resample_method_to_string(s->sink_input->actual_resample_method);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -560,7 +582,7 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
|
||||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SAMPLE_RATE].property_name, DBUS_TYPE_UINT32, &s->sample_rate);
|
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SAMPLE_RATE].property_name, DBUS_TYPE_UINT32, &s->sample_rate);
|
||||||
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_CHANNELS].property_name, DBUS_TYPE_UINT32, channels, channel_map->channels);
|
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_CHANNELS].property_name, DBUS_TYPE_UINT32, channels, channel_map->channels);
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK) {
|
if (s->has_volume) {
|
||||||
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_VOLUME].property_name, DBUS_TYPE_UINT32, volume, s->volume.channels);
|
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_VOLUME].property_name, DBUS_TYPE_UINT32, volume, s->volume.channels);
|
||||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_MUTE].property_name, DBUS_TYPE_BOOLEAN, &s->mute);
|
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_MUTE].property_name, DBUS_TYPE_BOOLEAN, &s->mute);
|
||||||
}
|
}
|
||||||
|
|
@ -708,30 +730,33 @@ static void subscription_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->type == STREAM_TYPE_PLAYBACK) {
|
if (s->type == STREAM_TYPE_PLAYBACK) {
|
||||||
pa_cvolume new_volume;
|
|
||||||
pa_bool_t new_mute = FALSE;
|
pa_bool_t new_mute = FALSE;
|
||||||
|
|
||||||
pa_sink_input_get_volume(s->sink_input, &new_volume, TRUE);
|
if (s->has_volume) {
|
||||||
|
pa_cvolume new_volume;
|
||||||
|
|
||||||
if (!pa_cvolume_equal(&s->volume, &new_volume)) {
|
pa_sink_input_get_volume(s->sink_input, &new_volume, TRUE);
|
||||||
dbus_uint32_t volume[PA_CHANNELS_MAX];
|
|
||||||
dbus_uint32_t *volume_ptr = volume;
|
|
||||||
|
|
||||||
s->volume = new_volume;
|
if (!pa_cvolume_equal(&s->volume, &new_volume)) {
|
||||||
|
dbus_uint32_t volume[PA_CHANNELS_MAX];
|
||||||
|
dbus_uint32_t *volume_ptr = volume;
|
||||||
|
|
||||||
for (i = 0; i < s->volume.channels; ++i)
|
s->volume = new_volume;
|
||||||
volume[i] = s->volume.values[i];
|
|
||||||
|
|
||||||
pa_assert_se(signal_msg = dbus_message_new_signal(s->path,
|
for (i = 0; i < s->volume.channels; ++i)
|
||||||
PA_DBUSIFACE_STREAM_INTERFACE,
|
volume[i] = s->volume.values[i];
|
||||||
signals[SIGNAL_VOLUME_UPDATED].name));
|
|
||||||
pa_assert_se(dbus_message_append_args(signal_msg,
|
|
||||||
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &volume_ptr, s->volume.channels,
|
|
||||||
DBUS_TYPE_INVALID));
|
|
||||||
|
|
||||||
pa_dbus_protocol_send_signal(s->dbus_protocol, signal_msg);
|
pa_assert_se(signal_msg = dbus_message_new_signal(s->path,
|
||||||
dbus_message_unref(signal_msg);
|
PA_DBUSIFACE_STREAM_INTERFACE,
|
||||||
signal_msg = NULL;
|
signals[SIGNAL_VOLUME_UPDATED].name));
|
||||||
|
pa_assert_se(dbus_message_append_args(signal_msg,
|
||||||
|
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &volume_ptr, s->volume.channels,
|
||||||
|
DBUS_TYPE_INVALID));
|
||||||
|
|
||||||
|
pa_dbus_protocol_send_signal(s->dbus_protocol, signal_msg);
|
||||||
|
dbus_message_unref(signal_msg);
|
||||||
|
signal_msg = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_mute = pa_sink_input_get_mute(s->sink_input);
|
new_mute = pa_sink_input_get_mute(s->sink_input);
|
||||||
|
|
@ -823,7 +848,14 @@ pa_dbusiface_stream *pa_dbusiface_stream_new_playback(pa_dbusiface_core *core, p
|
||||||
s->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, PLAYBACK_OBJECT_NAME, sink_input->index);
|
s->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, PLAYBACK_OBJECT_NAME, sink_input->index);
|
||||||
s->sink = pa_sink_ref(sink_input->sink);
|
s->sink = pa_sink_ref(sink_input->sink);
|
||||||
s->sample_rate = sink_input->sample_spec.rate;
|
s->sample_rate = sink_input->sample_spec.rate;
|
||||||
pa_sink_input_get_volume(sink_input, &s->volume, TRUE);
|
s->has_volume = pa_sink_input_is_volume_readable(sink_input);
|
||||||
|
s->read_only_volume = s->has_volume ? !pa_sink_input_is_volume_writable(sink_input) : FALSE;
|
||||||
|
|
||||||
|
if (s->has_volume)
|
||||||
|
pa_sink_input_get_volume(sink_input, &s->volume, TRUE);
|
||||||
|
else
|
||||||
|
pa_cvolume_init(&s->volume);
|
||||||
|
|
||||||
s->mute = pa_sink_input_get_mute(sink_input);
|
s->mute = pa_sink_input_get_mute(sink_input);
|
||||||
s->proplist = pa_proplist_copy(sink_input->proplist);
|
s->proplist = pa_proplist_copy(sink_input->proplist);
|
||||||
s->dbus_protocol = pa_dbus_protocol_get(sink_input->core);
|
s->dbus_protocol = pa_dbus_protocol_get(sink_input->core);
|
||||||
|
|
@ -854,6 +886,8 @@ pa_dbusiface_stream *pa_dbusiface_stream_new_record(pa_dbusiface_core *core, pa_
|
||||||
pa_cvolume_init(&s->volume);
|
pa_cvolume_init(&s->volume);
|
||||||
s->mute = FALSE;
|
s->mute = FALSE;
|
||||||
s->proplist = pa_proplist_copy(source_output->proplist);
|
s->proplist = pa_proplist_copy(source_output->proplist);
|
||||||
|
s->has_volume = FALSE;
|
||||||
|
s->read_only_volume = FALSE;
|
||||||
s->dbus_protocol = pa_dbus_protocol_get(source_output->core);
|
s->dbus_protocol = pa_dbus_protocol_get(source_output->core);
|
||||||
s->subscription = pa_subscription_new(source_output->core, PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscription_cb, s);
|
s->subscription = pa_subscription_new(source_output->core, PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscription_cb, s);
|
||||||
s->send_event_slot = pa_hook_connect(&source_output->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_SEND_EVENT],
|
s->send_event_slot = pa_hook_connect(&source_output->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_SEND_EVENT],
|
||||||
|
|
|
||||||
|
|
@ -1168,6 +1168,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sink_input->save_volume) {
|
if (sink_input->save_volume) {
|
||||||
|
pa_assert(pa_sink_input_is_volume_writable(sink_input));
|
||||||
|
|
||||||
entry.channel_map = sink_input->channel_map;
|
entry.channel_map = sink_input->channel_map;
|
||||||
pa_sink_input_get_volume(sink_input, &entry.volume, FALSE);
|
pa_sink_input_get_volume(sink_input, &entry.volume, FALSE);
|
||||||
entry.volume_valid = TRUE;
|
entry.volume_valid = TRUE;
|
||||||
|
|
@ -1327,8 +1329,11 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
|
||||||
if ((e = read_entry(u, name))) {
|
if ((e = read_entry(u, name))) {
|
||||||
|
|
||||||
if (u->restore_volume && e->volume_valid) {
|
if (u->restore_volume && e->volume_valid) {
|
||||||
|
if (!pa_sink_input_new_data_is_volume_writable(new_data))
|
||||||
if (!new_data->volume_is_set) {
|
pa_log_debug("Not restoring volume for sink input %s, because its volume can't be changed.", name);
|
||||||
|
else if (new_data->volume_is_set)
|
||||||
|
pa_log_debug("Not restoring volume for sink input %s, because already set.", name);
|
||||||
|
else {
|
||||||
pa_cvolume v;
|
pa_cvolume v;
|
||||||
|
|
||||||
pa_log_info("Restoring volume for sink input %s.", name);
|
pa_log_info("Restoring volume for sink input %s.", name);
|
||||||
|
|
@ -1339,8 +1344,7 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
|
||||||
|
|
||||||
new_data->volume_is_absolute = FALSE;
|
new_data->volume_is_absolute = FALSE;
|
||||||
new_data->save_volume = TRUE;
|
new_data->save_volume = TRUE;
|
||||||
} else
|
}
|
||||||
pa_log_debug("Not restoring volume for sink input %s, because already set.", name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u->restore_muted && e->muted_valid) {
|
if (u->restore_muted && e->muted_valid) {
|
||||||
|
|
@ -1615,7 +1619,7 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
|
||||||
}
|
}
|
||||||
pa_xfree(n);
|
pa_xfree(n);
|
||||||
|
|
||||||
if (u->restore_volume && e->volume_valid) {
|
if (u->restore_volume && e->volume_valid && pa_sink_input_is_volume_writable(si)) {
|
||||||
pa_cvolume v;
|
pa_cvolume v;
|
||||||
|
|
||||||
v = e->volume;
|
v = e->volume;
|
||||||
|
|
|
||||||
|
|
@ -503,6 +503,8 @@ typedef struct pa_sink_input_info {
|
||||||
int mute; /**< Stream muted \since 0.9.7 */
|
int mute; /**< Stream muted \since 0.9.7 */
|
||||||
pa_proplist *proplist; /**< Property list \since 0.9.11 */
|
pa_proplist *proplist; /**< Property list \since 0.9.11 */
|
||||||
int corked; /**< Stream corked \since 1.0 */
|
int corked; /**< Stream corked \since 1.0 */
|
||||||
|
int has_volume; /**< Stream has volume. If not set, then the meaning of this struct's volume member is unspecified. \since 1.0 */
|
||||||
|
int read_only_volume; /**< Stream volume can only be read. Although volume control is disabled, the stream volume is still not necessarily constant. \since 1.0 */
|
||||||
} pa_sink_input_info;
|
} pa_sink_input_info;
|
||||||
|
|
||||||
/** Callback prototype for pa_context_get_sink_input_info() and friends*/
|
/** Callback prototype for pa_context_get_sink_input_info() and friends*/
|
||||||
|
|
|
||||||
|
|
@ -579,11 +579,16 @@ static int pa_cli_command_sink_input_volume(pa_core *c, pa_tokenizer *t, pa_strb
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(si = pa_idxset_get_by_index(c->sink_inputs, (uint32_t) idx))) {
|
if (!(si = pa_idxset_get_by_index(c->sink_inputs, idx))) {
|
||||||
pa_strbuf_puts(buf, "No sink input found with this index.\n");
|
pa_strbuf_puts(buf, "No sink input found with this index.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pa_sink_input_is_volume_writable(si)) {
|
||||||
|
pa_strbuf_puts(buf, "This sink input's volume can't be changed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pa_cvolume_set(&cvolume, 1, volume);
|
pa_cvolume_set(&cvolume, 1, volume);
|
||||||
pa_sink_input_set_volume(si, &cvolume, TRUE, TRUE);
|
pa_sink_input_set_volume(si, &cvolume, TRUE, TRUE);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -553,8 +553,7 @@ char *pa_sink_input_list_to_string(pa_core *c) {
|
||||||
pa_usec_t cl;
|
pa_usec_t cl;
|
||||||
const char *cmn;
|
const char *cmn;
|
||||||
pa_cvolume v;
|
pa_cvolume v;
|
||||||
|
char *volume_str = NULL;
|
||||||
pa_sink_input_get_volume(i, &v, TRUE);
|
|
||||||
|
|
||||||
cmn = pa_channel_map_to_pretty_name(&i->channel_map);
|
cmn = pa_channel_map_to_pretty_name(&i->channel_map);
|
||||||
|
|
||||||
|
|
@ -565,6 +564,15 @@ char *pa_sink_input_list_to_string(pa_core *c) {
|
||||||
|
|
||||||
pa_assert(i->sink);
|
pa_assert(i->sink);
|
||||||
|
|
||||||
|
if (pa_sink_input_is_volume_readable(i)) {
|
||||||
|
pa_sink_input_get_volume(i, &v, TRUE);
|
||||||
|
volume_str = pa_sprintf_malloc("%s\n\t %s\n\t balance %0.2f",
|
||||||
|
pa_cvolume_snprint(cv, sizeof(cv), &v),
|
||||||
|
pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &v),
|
||||||
|
pa_cvolume_get_balance(&v, &i->channel_map));
|
||||||
|
} else
|
||||||
|
volume_str = pa_xstrdup("n/a");
|
||||||
|
|
||||||
pa_strbuf_printf(
|
pa_strbuf_printf(
|
||||||
s,
|
s,
|
||||||
" index: %u\n"
|
" index: %u\n"
|
||||||
|
|
@ -573,8 +581,6 @@ char *pa_sink_input_list_to_string(pa_core *c) {
|
||||||
"\tstate: %s\n"
|
"\tstate: %s\n"
|
||||||
"\tsink: %u <%s>\n"
|
"\tsink: %u <%s>\n"
|
||||||
"\tvolume: %s\n"
|
"\tvolume: %s\n"
|
||||||
"\t %s\n"
|
|
||||||
"\t balance %0.2f\n"
|
|
||||||
"\tmuted: %s\n"
|
"\tmuted: %s\n"
|
||||||
"\tcurrent latency: %0.2f ms\n"
|
"\tcurrent latency: %0.2f ms\n"
|
||||||
"\trequested latency: %s\n"
|
"\trequested latency: %s\n"
|
||||||
|
|
@ -596,9 +602,7 @@ char *pa_sink_input_list_to_string(pa_core *c) {
|
||||||
i->flags & PA_SINK_INPUT_KILL_ON_SUSPEND ? "KILL_ON_SUSPEND " : "",
|
i->flags & PA_SINK_INPUT_KILL_ON_SUSPEND ? "KILL_ON_SUSPEND " : "",
|
||||||
state_table[pa_sink_input_get_state(i)],
|
state_table[pa_sink_input_get_state(i)],
|
||||||
i->sink->index, i->sink->name,
|
i->sink->index, i->sink->name,
|
||||||
pa_cvolume_snprint(cv, sizeof(cv), &v),
|
volume_str,
|
||||||
pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &v),
|
|
||||||
pa_cvolume_get_balance(&v, &i->channel_map),
|
|
||||||
pa_yes_no(pa_sink_input_get_mute(i)),
|
pa_yes_no(pa_sink_input_get_mute(i)),
|
||||||
(double) pa_sink_input_get_latency(i, NULL) / PA_USEC_PER_MSEC,
|
(double) pa_sink_input_get_latency(i, NULL) / PA_USEC_PER_MSEC,
|
||||||
clt,
|
clt,
|
||||||
|
|
@ -608,6 +612,8 @@ char *pa_sink_input_list_to_string(pa_core *c) {
|
||||||
cmn ? cmn : "",
|
cmn ? cmn : "",
|
||||||
pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
|
pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
|
||||||
|
|
||||||
|
pa_xfree(volume_str);
|
||||||
|
|
||||||
if (i->module)
|
if (i->module)
|
||||||
pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
|
pa_strbuf_printf(s, "\tmodule: %u\n", i->module->index);
|
||||||
if (i->client)
|
if (i->client)
|
||||||
|
|
|
||||||
|
|
@ -3056,12 +3056,19 @@ static void sink_input_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t,
|
||||||
pa_sample_spec fixed_ss;
|
pa_sample_spec fixed_ss;
|
||||||
pa_usec_t sink_latency;
|
pa_usec_t sink_latency;
|
||||||
pa_cvolume v;
|
pa_cvolume v;
|
||||||
|
pa_bool_t has_volume = FALSE;
|
||||||
|
|
||||||
pa_assert(t);
|
pa_assert(t);
|
||||||
pa_sink_input_assert_ref(s);
|
pa_sink_input_assert_ref(s);
|
||||||
|
|
||||||
fixup_sample_spec(c, &fixed_ss, &s->sample_spec);
|
fixup_sample_spec(c, &fixed_ss, &s->sample_spec);
|
||||||
|
|
||||||
|
has_volume = pa_sink_input_is_volume_readable(s);
|
||||||
|
if (has_volume)
|
||||||
|
pa_sink_input_get_volume(s, &v, TRUE);
|
||||||
|
else
|
||||||
|
pa_cvolume_reset(&v, fixed_ss.channels);
|
||||||
|
|
||||||
pa_tagstruct_putu32(t, s->index);
|
pa_tagstruct_putu32(t, s->index);
|
||||||
pa_tagstruct_puts(t, pa_strnull(pa_proplist_gets(s->proplist, PA_PROP_MEDIA_NAME)));
|
pa_tagstruct_puts(t, pa_strnull(pa_proplist_gets(s->proplist, PA_PROP_MEDIA_NAME)));
|
||||||
pa_tagstruct_putu32(t, s->module ? s->module->index : PA_INVALID_INDEX);
|
pa_tagstruct_putu32(t, s->module ? s->module->index : PA_INVALID_INDEX);
|
||||||
|
|
@ -3069,7 +3076,7 @@ static void sink_input_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t,
|
||||||
pa_tagstruct_putu32(t, s->sink->index);
|
pa_tagstruct_putu32(t, s->sink->index);
|
||||||
pa_tagstruct_put_sample_spec(t, &fixed_ss);
|
pa_tagstruct_put_sample_spec(t, &fixed_ss);
|
||||||
pa_tagstruct_put_channel_map(t, &s->channel_map);
|
pa_tagstruct_put_channel_map(t, &s->channel_map);
|
||||||
pa_tagstruct_put_cvolume(t, pa_sink_input_get_volume(s, &v, TRUE));
|
pa_tagstruct_put_cvolume(t, &v);
|
||||||
pa_tagstruct_put_usec(t, pa_sink_input_get_latency(s, &sink_latency));
|
pa_tagstruct_put_usec(t, pa_sink_input_get_latency(s, &sink_latency));
|
||||||
pa_tagstruct_put_usec(t, sink_latency);
|
pa_tagstruct_put_usec(t, sink_latency);
|
||||||
pa_tagstruct_puts(t, pa_resample_method_to_string(pa_sink_input_get_resample_method(s)));
|
pa_tagstruct_puts(t, pa_resample_method_to_string(pa_sink_input_get_resample_method(s)));
|
||||||
|
|
@ -3080,6 +3087,10 @@ static void sink_input_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t,
|
||||||
pa_tagstruct_put_proplist(t, s->proplist);
|
pa_tagstruct_put_proplist(t, s->proplist);
|
||||||
if (c->version >= 19)
|
if (c->version >= 19)
|
||||||
pa_tagstruct_put_boolean(t, (pa_sink_input_get_state(s) == PA_SINK_INPUT_CORKED));
|
pa_tagstruct_put_boolean(t, (pa_sink_input_get_state(s) == PA_SINK_INPUT_CORKED));
|
||||||
|
if (c->version >= 20) {
|
||||||
|
pa_tagstruct_put_boolean(t, has_volume);
|
||||||
|
pa_tagstruct_put_boolean(t, has_volume ? !pa_sink_input_is_volume_writable(s) : FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void source_output_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_source_output *s) {
|
static void source_output_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_source_output *s) {
|
||||||
|
|
@ -3461,6 +3472,7 @@ static void command_set_volume(
|
||||||
pa_log_debug("Client %s changes volume of source %s.", client_name, source->name);
|
pa_log_debug("Client %s changes volume of source %s.", client_name, source->name);
|
||||||
pa_source_set_volume(source, &volume, TRUE);
|
pa_source_set_volume(source, &volume, TRUE);
|
||||||
} else if (si) {
|
} else if (si) {
|
||||||
|
CHECK_VALIDITY(c->pstream, pa_sink_input_is_volume_writable(si), tag, PA_ERR_INVALID);
|
||||||
CHECK_VALIDITY(c->pstream, volume.channels == 1 || pa_cvolume_compatible(&volume, &si->sample_spec), tag, PA_ERR_INVALID);
|
CHECK_VALIDITY(c->pstream, volume.channels == 1 || pa_cvolume_compatible(&volume, &si->sample_spec), tag, PA_ERR_INVALID);
|
||||||
|
|
||||||
pa_log_debug("Client %s changes volume of sink input %s.",
|
pa_log_debug("Client %s changes volume of sink input %s.",
|
||||||
|
|
|
||||||
|
|
@ -112,8 +112,15 @@ void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const
|
||||||
data->channel_map = *map;
|
data->channel_map = *map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pa_bool_t pa_sink_input_new_data_is_volume_writable(pa_sink_input_new_data *data) {
|
||||||
|
pa_assert(data);
|
||||||
|
|
||||||
|
return !(data->flags & PA_SINK_INPUT_PASSTHROUGH);
|
||||||
|
}
|
||||||
|
|
||||||
void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume) {
|
void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume) {
|
||||||
pa_assert(data);
|
pa_assert(data);
|
||||||
|
pa_assert(pa_sink_input_new_data_is_volume_writable(data));
|
||||||
|
|
||||||
if ((data->volume_is_set = !!volume))
|
if ((data->volume_is_set = !!volume))
|
||||||
data->volume = *volume;
|
data->volume = *volume;
|
||||||
|
|
@ -205,6 +212,7 @@ int pa_sink_input_new(
|
||||||
if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], data)) < 0)
|
if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], data)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
pa_assert(!data->volume_is_set || pa_sink_input_new_data_is_volume_writable(data));
|
||||||
pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID);
|
pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID);
|
||||||
|
|
||||||
if (!data->sink) {
|
if (!data->sink) {
|
||||||
|
|
@ -1058,13 +1066,24 @@ static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v) {
|
||||||
/* We don't copy the data to the thread_info data. That's left for someone else to do */
|
/* We don't copy the data to the thread_info data. That's left for someone else to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called from main context */
|
||||||
|
pa_bool_t pa_sink_input_is_volume_readable(pa_sink_input *i) {
|
||||||
|
pa_sink_input_assert_ref(i);
|
||||||
|
pa_assert_ctl_context();
|
||||||
|
|
||||||
|
return !(i->flags & PA_SINK_INPUT_PASSTHROUGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Called from main context */
|
||||||
|
pa_bool_t pa_sink_input_is_volume_writable(pa_sink_input *i) {
|
||||||
|
pa_sink_input_assert_ref(i);
|
||||||
|
pa_assert_ctl_context();
|
||||||
|
|
||||||
|
return !(i->flags & PA_SINK_INPUT_PASSTHROUGH);
|
||||||
|
}
|
||||||
|
|
||||||
/* Called from main context */
|
/* Called from main context */
|
||||||
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
|
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
|
||||||
|
|
||||||
/* Do not allow for volume changes for non-audio types */
|
|
||||||
if (i->flags & PA_SINK_INPUT_PASSTHROUGH)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* test ramping -> return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 2000 * PA_USEC_PER_MSEC); */
|
/* test ramping -> return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 2000 * PA_USEC_PER_MSEC); */
|
||||||
return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 0);
|
return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -1074,6 +1093,7 @@ pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bo
|
||||||
pa_sink_input_assert_ref(i);
|
pa_sink_input_assert_ref(i);
|
||||||
pa_assert_ctl_context();
|
pa_assert_ctl_context();
|
||||||
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
|
||||||
|
pa_assert(pa_sink_input_is_volume_readable(i));
|
||||||
|
|
||||||
if (absolute || !(i->sink->flags & PA_SINK_FLAT_VOLUME))
|
if (absolute || !(i->sink->flags & PA_SINK_FLAT_VOLUME))
|
||||||
*volume = i->volume;
|
*volume = i->volume;
|
||||||
|
|
@ -1854,6 +1874,7 @@ void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *v
|
||||||
pa_assert(volume);
|
pa_assert(volume);
|
||||||
pa_assert(pa_cvolume_valid(volume));
|
pa_assert(pa_cvolume_valid(volume));
|
||||||
pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
|
pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
|
||||||
|
pa_assert(pa_sink_input_is_volume_writable(i));
|
||||||
|
|
||||||
if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
|
if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
|
||||||
v = i->sink->reference_volume;
|
v = i->sink->reference_volume;
|
||||||
|
|
|
||||||
|
|
@ -312,6 +312,7 @@ typedef struct pa_sink_input_new_data {
|
||||||
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);
|
pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);
|
||||||
void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec);
|
void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec);
|
||||||
void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map);
|
void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map);
|
||||||
|
pa_bool_t pa_sink_input_new_data_is_volume_writable(pa_sink_input_new_data *data);
|
||||||
void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume);
|
void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume);
|
||||||
void pa_sink_input_new_data_apply_volume_factor(pa_sink_input_new_data *data, const pa_cvolume *volume_factor);
|
void pa_sink_input_new_data_apply_volume_factor(pa_sink_input_new_data *data, const pa_cvolume *volume_factor);
|
||||||
void pa_sink_input_new_data_apply_volume_factor_sink(pa_sink_input_new_data *data, const pa_cvolume *volume_factor);
|
void pa_sink_input_new_data_apply_volume_factor_sink(pa_sink_input_new_data *data, const pa_cvolume *volume_factor);
|
||||||
|
|
@ -356,6 +357,8 @@ void pa_sink_input_kill(pa_sink_input*i);
|
||||||
|
|
||||||
pa_usec_t pa_sink_input_get_latency(pa_sink_input *i, pa_usec_t *sink_latency);
|
pa_usec_t pa_sink_input_get_latency(pa_sink_input *i, pa_usec_t *sink_latency);
|
||||||
|
|
||||||
|
pa_bool_t pa_sink_input_is_volume_readable(pa_sink_input *i);
|
||||||
|
pa_bool_t pa_sink_input_is_volume_writable(pa_sink_input *i);
|
||||||
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute);
|
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute);
|
||||||
pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bool_t absolute);
|
pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bool_t absolute);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue