media-session: check metadata before using it

The session manager might be configured without metadata support
so check this before attempting to use the metadata. It's not
really a problem because the default sink/source can only be
changed with the pulseaudio API, which activates metadata.
This commit is contained in:
Wim Taymans 2021-03-05 10:34:27 +01:00
parent 93002ecd11
commit b40397d986
2 changed files with 14 additions and 8 deletions

View file

@ -227,12 +227,14 @@ static void session_create(void *data, struct sm_object *object)
if (def->key == NULL)
continue;
char val[16];
snprintf(val, sizeof(val), "%u", d.id);
pw_log_info("found %s with id:%s restore as %s",
name, val, item->key);
pw_metadata_set_property(impl->session->metadata,
PW_ID_CORE, item->key, SPA_TYPE_INFO_BASE"Id", val);
if (impl->session->metadata != NULL) {
char val[16];
snprintf(val, sizeof(val), "%u", d.id);
pw_log_info("found %s with id:%s restore as %s",
name, val, item->key);
pw_metadata_set_property(impl->session->metadata,
PW_ID_CORE, item->key, SPA_TYPE_INFO_BASE"Id", val);
}
}
}
}
@ -248,7 +250,10 @@ static void session_remove(void *data, struct sm_object *object)
for (def = impl->defaults; def->key != NULL; ++def) {
if (def->value == object->id) {
def->value = SPA_ID_INVALID;
pw_metadata_set_property(impl->session->metadata, PW_ID_CORE, def->key, NULL, NULL);
if (impl->session->metadata != NULL) {
pw_metadata_set_property(impl->session->metadata,
PW_ID_CORE, def->key, NULL, NULL);
}
}
}
}