metadata: improve default sink/source

Only check defaults when subject is PW_ID_CORE
Handle NULL keys: remove the defaults
This commit is contained in:
Wim Taymans 2020-08-18 17:56:05 +02:00
parent 759e1ccb6b
commit 0c04481ba7
6 changed files with 53 additions and 57 deletions

View file

@ -969,11 +969,12 @@ static int metadata_property(void *object,
struct global *g = object;
snd_ctl_pipewire_t *ctl = g->ctl;
if (key) {
if (strcmp(key, "default.audio.sink") == 0)
ctl->sink = value ? (uint32_t)atoi(value) : 0;
if (strcmp(key, "default.audio.source") == 0)
ctl->source = value ? (uint32_t)atoi(value) : 0;
if (subject == PW_ID_CORE) {
uint32_t val = (key && value) ? (uint32_t)atoi(value) : 0;
if (key == NULL || strcmp(key, "default.audio.sink") == 0)
ctl->sink = val;
if (key == NULL || strcmp(key, "default.audio.source") == 0)
ctl->source = val;
}
return 0;
}

View file

@ -2004,17 +2004,11 @@ static int metadata_property(void *object, uint32_t id,
pw_log_info("set id:%u key:'%s' value:'%s' type:'%s'", id, key, value, type);
if (id == PW_ID_CORE) {
if (key) {
uint32_t val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (strcmp(key, "default.audio.sink") == 0) {
c->metadata->default_audio_sink = val;
} else if (strcmp(key, "default.audio.source") == 0) {
c->metadata->default_audio_source = val;
}
} else {
c->metadata->default_audio_source = SPA_ID_INVALID;
c->metadata->default_audio_sink = SPA_ID_INVALID;
}
uint32_t val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (key == NULL || strcmp(key, "default.audio.sink") == 0)
c->metadata->default_audio_sink = val;
if (key == NULL || strcmp(key, "default.audio.source") == 0)
c->metadata->default_audio_source = val;
} else {
o = pw_map_lookup(&c->context.globals, id);
if (o == NULL)

View file

@ -1013,14 +1013,16 @@ static int metadata_property(void *object,
uint32_t val;
bool changed = false;
if (key && strcmp(key, METADATA_DEFAULT_SINK) == 0) {
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
changed = c->default_sink != val;
c->default_sink = val;
} else if (key && strcmp(key, METADATA_DEFAULT_SOURCE) == 0) {
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
changed = c->default_source != val;
c->default_source = val;
if (subject == PW_ID_CORE) {
val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (key == NULL || strcmp(key, METADATA_DEFAULT_SINK) == 0) {
changed = c->default_sink != val;
c->default_sink = val;
}
if (key == NULL || strcmp(key, METADATA_DEFAULT_SOURCE) == 0) {
changed = c->default_source != val;
c->default_source = val;
}
}
if (changed)
emit_event(global->context, global, PA_SUBSCRIPTION_EVENT_CHANGE);

View file

@ -153,26 +153,27 @@ static int metadata_property(void *object, uint32_t subject,
uint32_t val;
bool changed = false;
if (key == NULL)
return 0;
if (subject == PW_ID_CORE) {
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (strcmp(key, "default.audio.sink") == 0) {
val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (key == NULL || strcmp(key, "default.audio.sink") == 0) {
changed = val != impl->default_audio_sink;
impl->default_audio_sink = val;
} else if (strcmp(key, "default.audio.source") == 0) {
}
if (key == NULL || strcmp(key, "default.audio.source") == 0) {
changed = val != impl->default_audio_source;
impl->default_audio_source = val;
} else if (strcmp(key, "default.video.source") == 0) {
}
if (key == NULL || strcmp(key, "default.video.source") == 0) {
changed = val != impl->default_video_source;
impl->default_video_source = val;
}
}
if (changed) {
const char *name = find_name_for_id(impl, val);
pw_properties_set(impl->properties, key, name);
if (key == NULL)
pw_properties_clear(impl->properties);
else
pw_properties_set(impl->properties, key, name);
add_idle_timeout(impl);
}
return 0;

View file

@ -699,6 +699,9 @@ static int move_node(struct impl *impl, uint32_t source, uint32_t target)
struct node *n, *src_node, *dst_node;
const char *str;
if (source == SPA_ID_INVALID || target == SPA_ID_INVALID)
return 0;
/* find source and dest node */
if ((src_node = find_node_by_id(impl, source)) == NULL)
return -ENOENT;
@ -764,30 +767,26 @@ static int metadata_property(void *object, uint32_t subject,
const char *key, const char *type, const char *value)
{
struct impl *impl = object;
if (key == NULL)
return 0;
uint32_t val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (subject == PW_ID_CORE) {
if (strcmp(key, "default.audio.sink") == 0) {
if (impl->default_audio_sink != SPA_ID_INVALID && value)
move_node(impl, impl->default_audio_sink, atoi(value));
impl->default_audio_sink = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (key == NULL || strcmp(key, "default.audio.sink") == 0) {
move_node(impl, impl->default_audio_sink, val);
impl->default_audio_sink = val;
}
else if (strcmp(key, "default.audio.source") == 0) {
if (impl->default_audio_source != SPA_ID_INVALID && value)
move_node(impl, impl->default_audio_source, atoi(value));
impl->default_audio_source = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
} else if (strcmp(key, "default.video.source") == 0) {
if (impl->default_video_source != SPA_ID_INVALID && value)
move_node(impl, impl->default_video_source, atoi(value));
impl->default_video_source = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (key == NULL || strcmp(key, "default.audio.source") == 0) {
move_node(impl, impl->default_audio_source, val);
impl->default_audio_source = val;
}
if (key == NULL || strcmp(key, "default.video.source") == 0) {
move_node(impl, impl->default_video_source, val);
impl->default_video_source = val;
}
} else {
if (strcmp(key, "target.node") == 0 && value != NULL) {
if (val != SPA_ID_INVALID && strcmp(key, "target.node") == 0) {
struct node *src_node, *dst_node;
dst_node = find_node_by_id(impl, atoi(value));
dst_node = find_node_by_id(impl, val);
src_node = dst_node ? find_node_by_id(impl, subject) : NULL;
if (dst_node && src_node)

View file

@ -649,14 +649,13 @@ static int metadata_property(void *object,
uint32_t subject, const char *key, const char *type, const char *value)
{
struct data *data = object;
uint32_t val;
if (key && strcmp(key, "default.audio.sink") == 0) {
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
data->default_sink = val;
} else if (key && strcmp(key, "default.audio.source") == 0) {
val = value ? (uint32_t)atoi(value) : SPA_ID_INVALID;
data->default_source = val;
if (subject == PW_ID_CORE) {
uint32_t val = (key && value) ? (uint32_t)atoi(value) : SPA_ID_INVALID;
if (key == NULL || strcmp(key, "default.audio.sink") == 0)
data->default_sink = val;
if (key == NULL || strcmp(key, "default.audio.source") == 0)
data->default_source = val;
}
return 0;
}