mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
introspect: implement enough to make gnome-control-center work
We can see sources and sink and change the volume/mute of streams
This commit is contained in:
parent
faccc8d506
commit
01aa9a5960
4 changed files with 76 additions and 21 deletions
|
|
@ -336,6 +336,7 @@ struct pa_stream {
|
|||
uint32_t buffer_offset;
|
||||
|
||||
float volume;
|
||||
bool mute;
|
||||
pa_operation *drain;
|
||||
uint64_t queued;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -923,13 +923,16 @@ static void sink_input_callback(struct sink_input_data *d)
|
|||
pa_stream *s;
|
||||
|
||||
pw_log_debug("index %d", g->id);
|
||||
if (info == NULL)
|
||||
return;
|
||||
|
||||
s = find_stream(d->context, g->id);
|
||||
|
||||
spa_zero(i);
|
||||
i.index = g->id;
|
||||
i.name = info->name;
|
||||
i.owner_module = g->parent_id;
|
||||
i.client = PA_INVALID_INDEX;
|
||||
i.owner_module = PA_INVALID_INDEX;
|
||||
i.client = g->parent_id;
|
||||
i.sink = PA_INVALID_INDEX;
|
||||
pa_cvolume_init(&i.volume);
|
||||
if (s && s->sample_spec.channels > 0) {
|
||||
|
|
@ -980,6 +983,8 @@ pa_operation* pa_context_get_sink_input_info(pa_context *c, uint32_t idx, pa_sin
|
|||
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(c, idx != PA_INVALID_INDEX, PA_ERR_INVALID);
|
||||
|
||||
pw_log_debug("context %p: info for %d", c, idx);
|
||||
|
||||
if ((g = pa_context_find_global(c, idx)) == NULL)
|
||||
return NULL;
|
||||
if (!(g->mask & PA_SUBSCRIPTION_MASK_SINK_INPUT))
|
||||
|
|
@ -1024,6 +1029,8 @@ pa_operation* pa_context_get_sink_input_info_list(pa_context *c, pa_sink_input_i
|
|||
|
||||
PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
|
||||
|
||||
pw_log_debug("context %p", c);
|
||||
|
||||
ensure_types(c, PA_SUBSCRIPTION_MASK_SINK_INPUT);
|
||||
o = pa_operation_new(c, NULL, sink_input_info_list, sizeof(struct sink_input_data));
|
||||
d = o->userdata;
|
||||
|
|
@ -1079,7 +1086,7 @@ pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, cons
|
|||
|
||||
if (s) {
|
||||
s->volume = v;
|
||||
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, s->volume);
|
||||
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, s->mute ? 0.0 : s->volume);
|
||||
}
|
||||
else if (g) {
|
||||
char buf[1024];
|
||||
|
|
@ -1090,7 +1097,6 @@ pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, cons
|
|||
spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
|
||||
SPA_PROP_volume, &SPA_POD_Float(v),
|
||||
SPA_PROP_mute, &SPA_POD_Bool(false),
|
||||
0));
|
||||
}
|
||||
o = pa_operation_new(c, NULL, on_success, sizeof(struct success_ack));
|
||||
|
|
@ -1105,17 +1111,30 @@ pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, cons
|
|||
pa_operation* pa_context_set_sink_input_mute(pa_context *c, uint32_t idx, int mute, pa_context_success_cb_t cb, void *userdata)
|
||||
{
|
||||
pa_stream *s;
|
||||
struct global *g;
|
||||
pa_operation *o;
|
||||
struct success_ack *d;
|
||||
|
||||
if ((s = find_stream(c, idx)) == NULL)
|
||||
if ((s = find_stream(c, idx)) == NULL) {
|
||||
if ((g = pa_context_find_global(c, idx)) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mute)
|
||||
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, 0.0);
|
||||
else
|
||||
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, s->volume);
|
||||
if (s) {
|
||||
s->mute = mute;
|
||||
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, s->mute ? 0.0 : s->volume);
|
||||
}
|
||||
else if (g) {
|
||||
char buf[1024];
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
|
||||
|
||||
pw_node_proxy_set_param((struct pw_node_proxy*)g->proxy,
|
||||
SPA_PARAM_Props, 0,
|
||||
spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
|
||||
SPA_PROP_mute, &SPA_POD_Bool(mute),
|
||||
0));
|
||||
}
|
||||
o = pa_operation_new(c, NULL, on_success, sizeof(struct success_ack));
|
||||
d = o->userdata;
|
||||
d->cb = cb;
|
||||
|
|
@ -1147,13 +1166,16 @@ static void source_output_callback(struct source_output_data *d)
|
|||
pa_stream *s;
|
||||
|
||||
pw_log_debug("index %d", g->id);
|
||||
if (info == NULL)
|
||||
return;
|
||||
|
||||
s = find_stream(d->context, g->id);
|
||||
|
||||
spa_zero(i);
|
||||
i.index = g->id;
|
||||
i.name = info->name;
|
||||
i.owner_module = g->parent_id;
|
||||
i.client = PA_INVALID_INDEX;
|
||||
i.owner_module = PA_INVALID_INDEX;
|
||||
i.client = g->parent_id;
|
||||
i.source = PA_INVALID_INDEX;
|
||||
pa_cvolume_init(&i.volume);
|
||||
if (s && s->sample_spec.channels > 0) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/debug/mem.h>
|
||||
|
||||
#include <pipewire/log.h>
|
||||
#include <pipewire/properties.h>
|
||||
|
||||
|
|
@ -73,14 +75,36 @@ int pa_proplist_key_valid(const char *key)
|
|||
|
||||
int pa_proplist_sets(pa_proplist *p, const char *key, const char *value)
|
||||
{
|
||||
pa_assert(p);
|
||||
pa_assert(key);
|
||||
pa_assert(value);
|
||||
|
||||
if (!pa_proplist_key_valid(key))
|
||||
return -1;
|
||||
|
||||
pw_properties_set(p->props, key, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_proplist_setp(pa_proplist *p, const char *pair)
|
||||
{
|
||||
pw_log_warn("Not Implemented");
|
||||
const char *t;
|
||||
char *c;
|
||||
int idx;
|
||||
|
||||
pa_assert(p);
|
||||
pa_assert(pair);
|
||||
|
||||
if (!(t = strchr(pair, '=')))
|
||||
return -1;
|
||||
|
||||
idx = pair - t;
|
||||
c = strdup(pair);
|
||||
c[idx] = 0;
|
||||
pa_properties_sets(p, c, &c[idx]+1);
|
||||
free(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_proplist_setf(pa_proplist *p, const char *key, const char *format, ...)
|
||||
|
|
@ -96,8 +120,15 @@ int pa_proplist_setf(pa_proplist *p, const char *key, const char *format, ...)
|
|||
|
||||
int pa_proplist_set(pa_proplist *p, const char *key, const void *data, size_t nbytes)
|
||||
{
|
||||
pw_log_warn("Not Implemented");
|
||||
pa_assert(p);
|
||||
pa_assert(key);
|
||||
pa_assert(data || nbytes == 0);
|
||||
|
||||
if (!pa_proplist_key_valid(key))
|
||||
return -1;
|
||||
|
||||
pw_properties_set(p->props, key, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *pa_proplist_gets(pa_proplist *p, const char *key)
|
||||
|
|
|
|||
|
|
@ -793,6 +793,7 @@ static int create_stream(pa_stream_direction_t direction,
|
|||
s->volume = pa_cvolume_avg(volume) / (float) PA_VOLUME_NORM;
|
||||
else
|
||||
s->volume = 1.0;
|
||||
s->mute = false;
|
||||
|
||||
pa_stream_set_state(s, PA_STREAM_CREATING);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue