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:
Wim Taymans 2018-10-19 16:57:03 +02:00
parent faccc8d506
commit 01aa9a5960
4 changed files with 76 additions and 21 deletions

View file

@ -336,6 +336,7 @@ struct pa_stream {
uint32_t buffer_offset; uint32_t buffer_offset;
float volume; float volume;
bool mute;
pa_operation *drain; pa_operation *drain;
uint64_t queued; uint64_t queued;
}; };

View file

@ -923,13 +923,16 @@ static void sink_input_callback(struct sink_input_data *d)
pa_stream *s; pa_stream *s;
pw_log_debug("index %d", g->id); pw_log_debug("index %d", g->id);
if (info == NULL)
return;
s = find_stream(d->context, g->id); s = find_stream(d->context, g->id);
spa_zero(i); spa_zero(i);
i.index = g->id; i.index = g->id;
i.name = info->name; i.name = info->name;
i.owner_module = g->parent_id; i.owner_module = PA_INVALID_INDEX;
i.client = PA_INVALID_INDEX; i.client = g->parent_id;
i.sink = PA_INVALID_INDEX; i.sink = PA_INVALID_INDEX;
pa_cvolume_init(&i.volume); pa_cvolume_init(&i.volume);
if (s && s->sample_spec.channels > 0) { 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); 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) if ((g = pa_context_find_global(c, idx)) == NULL)
return NULL; return NULL;
if (!(g->mask & PA_SUBSCRIPTION_MASK_SINK_INPUT)) 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); 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); ensure_types(c, PA_SUBSCRIPTION_MASK_SINK_INPUT);
o = pa_operation_new(c, NULL, sink_input_info_list, sizeof(struct sink_input_data)); o = pa_operation_new(c, NULL, sink_input_info_list, sizeof(struct sink_input_data));
d = o->userdata; d = o->userdata;
@ -1079,19 +1086,18 @@ pa_operation* pa_context_set_sink_input_volume(pa_context *c, uint32_t idx, cons
if (s) { if (s) {
s->volume = v; 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) { else if (g) {
char buf[1024]; char buf[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf)); struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
pw_node_proxy_set_param((struct pw_node_proxy*)g->proxy, pw_node_proxy_set_param((struct pw_node_proxy*)g->proxy,
SPA_PARAM_Props, 0, SPA_PARAM_Props, 0,
spa_pod_builder_object(&b, spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_Props, SPA_PARAM_Props, SPA_TYPE_OBJECT_Props, SPA_PARAM_Props,
SPA_PROP_volume, &SPA_POD_Float(v), SPA_PROP_volume, &SPA_POD_Float(v),
SPA_PROP_mute, &SPA_POD_Bool(false), 0));
0));
} }
o = pa_operation_new(c, NULL, on_success, sizeof(struct success_ack)); o = pa_operation_new(c, NULL, on_success, sizeof(struct success_ack));
d = o->userdata; d = o->userdata;
@ -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_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; pa_stream *s;
struct global *g;
pa_operation *o; pa_operation *o;
struct success_ack *d; struct success_ack *d;
if ((s = find_stream(c, idx)) == NULL) if ((s = find_stream(c, idx)) == NULL) {
return NULL; if ((g = pa_context_find_global(c, idx)) == NULL)
return NULL;
}
if (mute) if (s) {
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, 0.0); s->mute = mute;
else pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, s->mute ? 0.0 : s->volume);
pw_stream_set_control(s->stream, PW_STREAM_CONTROL_VOLUME, 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)); o = pa_operation_new(c, NULL, on_success, sizeof(struct success_ack));
d = o->userdata; d = o->userdata;
d->cb = cb; d->cb = cb;
@ -1147,13 +1166,16 @@ static void source_output_callback(struct source_output_data *d)
pa_stream *s; pa_stream *s;
pw_log_debug("index %d", g->id); pw_log_debug("index %d", g->id);
if (info == NULL)
return;
s = find_stream(d->context, g->id); s = find_stream(d->context, g->id);
spa_zero(i); spa_zero(i);
i.index = g->id; i.index = g->id;
i.name = info->name; i.name = info->name;
i.owner_module = g->parent_id; i.owner_module = PA_INVALID_INDEX;
i.client = PA_INVALID_INDEX; i.client = g->parent_id;
i.source = PA_INVALID_INDEX; i.source = PA_INVALID_INDEX;
pa_cvolume_init(&i.volume); pa_cvolume_init(&i.volume);
if (s && s->sample_spec.channels > 0) { if (s && s->sample_spec.channels > 0) {

View file

@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
#include <spa/debug/mem.h>
#include <pipewire/log.h> #include <pipewire/log.h>
#include <pipewire/properties.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) 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); pw_properties_set(p->props, key, value);
return 0; return 0;
} }
int pa_proplist_setp(pa_proplist *p, const char *pair) int pa_proplist_setp(pa_proplist *p, const char *pair)
{ {
pw_log_warn("Not Implemented"); const char *t;
return -1; 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, ...) 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) int pa_proplist_set(pa_proplist *p, const char *key, const void *data, size_t nbytes)
{ {
pw_log_warn("Not Implemented"); pa_assert(p);
return -1; 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) const char *pa_proplist_gets(pa_proplist *p, const char *key)

View file

@ -793,6 +793,7 @@ static int create_stream(pa_stream_direction_t direction,
s->volume = pa_cvolume_avg(volume) / (float) PA_VOLUME_NORM; s->volume = pa_cvolume_avg(volume) / (float) PA_VOLUME_NORM;
else else
s->volume = 1.0; s->volume = 1.0;
s->mute = false;
pa_stream_set_state(s, PA_STREAM_CREATING); pa_stream_set_state(s, PA_STREAM_CREATING);