Revert "default-profile: keep a restore and save list"

This reverts commit de71618b99.

Doesn't work when the device is removed and added again.
This commit is contained in:
Wim Taymans 2020-08-17 16:04:16 +02:00
parent d337abf690
commit e544f82004

View file

@ -59,8 +59,7 @@ struct impl {
struct spa_hook meta_listener;
struct pw_properties *to_restore;
struct pw_properties *to_save;
struct pw_properties *properties;
};
struct device {
@ -71,6 +70,10 @@ struct device {
char *name;
struct spa_hook listener;
unsigned int restored:1;
uint32_t active_profile;
};
struct find_data {
@ -85,7 +88,7 @@ static void remove_idle_timeout(struct impl *impl)
int res;
if (impl->idle_timeout) {
if ((res = sm_media_session_save_state(impl->session, SESSION_KEY, impl->to_save)) < 0)
if ((res = sm_media_session_save_state(impl->session, SESSION_KEY, impl->properties)) < 0)
pw_log_error("can't save "SESSION_KEY" state: %s", spa_strerror(res));
pw_loop_destroy_source(main_loop, impl->idle_timeout);
impl->idle_timeout = NULL;
@ -117,8 +120,7 @@ static void session_destroy(void *data)
struct impl *impl = data;
remove_idle_timeout(impl);
spa_hook_remove(&impl->listener);
pw_properties_free(impl->to_restore);
pw_properties_free(impl->to_save);
pw_properties_free(impl->properties);
free(impl);
}
@ -142,10 +144,16 @@ static uint32_t find_profile_id(struct device *dev, const char *name)
return SPA_ID_INVALID;
}
static int restore_profile(struct device *dev, const char *name)
static int restore_profile(struct device *dev)
{
struct impl *impl = dev->impl;
const char *name;
uint32_t index = SPA_ID_INVALID;
name = pw_properties_get(impl->properties, dev->name);
if (name == NULL)
return -ENOENT;
pw_log_debug("device %d: find profile '%s'", dev->id, name);
index = find_profile_id(dev, name);
@ -159,6 +167,7 @@ static int restore_profile(struct device *dev, const char *name)
spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamProfile, SPA_PARAM_Profile,
SPA_PARAM_PROFILE_index, SPA_POD_Int(index)));
dev->active_profile = index;
}
return -ENOENT;
}
@ -166,14 +175,12 @@ static int restore_profile(struct device *dev, const char *name)
static int handle_profile(struct device *dev, struct sm_param *p)
{
struct impl *impl = dev->impl;
const char *name;
uint32_t index;
int res;
name = pw_properties_get(impl->to_restore, dev->name);
if (name) {
restore_profile(dev, name);
pw_properties_set(impl->to_restore, dev->name, NULL);
if (!dev->restored) {
restore_profile(dev);
dev->restored = true;
} else {
const char *name;
if ((res = spa_pod_parse_object(p->param,
@ -183,8 +190,12 @@ static int handle_profile(struct device *dev, struct sm_param *p)
pw_log_warn("device %d: can't parse profile: %s", dev->id, spa_strerror(res));
return res;
}
if (dev->active_profile == index)
return 0;
dev->active_profile = index;
pw_log_debug("device %d: current profile %d %s", dev->id, index, name);
pw_properties_set(impl->to_save, dev->name, name);
pw_properties_set(impl->properties, dev->name, name);
add_idle_timeout(impl);
}
return 0;
@ -284,28 +295,16 @@ int sm_default_profile_start(struct sm_media_session *session)
impl->session = session;
impl->context = session->context;
impl->to_restore = pw_properties_new(NULL, NULL);
if (impl->to_restore == NULL) {
res = -errno;
goto exit_free;
impl->properties = pw_properties_new(NULL, NULL);
if (impl->properties == NULL) {
free(impl);
return -ENOMEM;
}
if ((res = sm_media_session_load_state(impl->session, SESSION_KEY, impl->to_restore)) < 0)
if ((res = sm_media_session_load_state(impl->session, SESSION_KEY, impl->properties)) < 0)
pw_log_info("can't load "SESSION_KEY" state: %s", spa_strerror(res));
impl->to_save = pw_properties_copy(impl->to_restore);
if (impl->to_save == NULL) {
res = -errno;
goto exit_free_props;
}
sm_media_session_add_listener(impl->session, &impl->listener, &session_events, impl);
return 0;
exit_free_props:
pw_properties_free(impl->to_restore);
exit_free:
free(impl);
return res;
}