mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
default-routes: only restore routes when profile changed
When the profile changes, try to restore the previously saved routes. Otherwise, follow the best route when it changes. See #863
This commit is contained in:
parent
85a102f414
commit
5c91f23c18
1 changed files with 30 additions and 21 deletions
|
|
@ -539,8 +539,12 @@ static int save_profile(struct device *dev, struct profile *pr)
|
||||||
|
|
||||||
val = serialize_routes(dev);
|
val = serialize_routes(dev);
|
||||||
if (pw_properties_set(impl->to_restore, key, val)) {
|
if (pw_properties_set(impl->to_restore, key, val)) {
|
||||||
pw_log_info("device %d: profile routes changed %s %s", dev->id, key, val);
|
pw_log_info("device %d: profile %s routes changed %s %s",
|
||||||
|
dev->id, pr->name, key, val);
|
||||||
add_idle_timeout(impl);
|
add_idle_timeout(impl);
|
||||||
|
} else {
|
||||||
|
pw_log_info("device %d: profile %s unchanged (%s)",
|
||||||
|
dev->id, pr->name, val);
|
||||||
}
|
}
|
||||||
free(val);
|
free(val);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -613,13 +617,14 @@ static int find_saved_route(struct device *dev, const char *val, uint32_t device
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restore_device_route(struct device *dev, const char *val, uint32_t device_id)
|
static int restore_device_route(struct device *dev, const char *val, uint32_t device_id, bool restore)
|
||||||
{
|
{
|
||||||
int res;
|
int res = -ENOENT;
|
||||||
struct route t;
|
struct route t;
|
||||||
|
|
||||||
pw_log_info("device %d: restoring device %u", dev->id, device_id);
|
pw_log_info("device %d: restoring device %u", dev->id, device_id);
|
||||||
|
|
||||||
|
if (restore) {
|
||||||
res = find_saved_route(dev, val, device_id, &t);
|
res = find_saved_route(dev, val, device_id, &t);
|
||||||
if (res >= 0) {
|
if (res >= 0) {
|
||||||
/* we found a saved route */
|
/* we found a saved route */
|
||||||
|
|
@ -635,6 +640,7 @@ static int restore_device_route(struct device *dev, const char *val, uint32_t de
|
||||||
t.save = true;
|
t.save = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
/* we could not find a saved route, try to find a new best */
|
/* we could not find a saved route, try to find a new best */
|
||||||
res = find_best_route(dev, device_id, &t);
|
res = find_best_route(dev, device_id, &t);
|
||||||
|
|
@ -651,7 +657,7 @@ static int restore_device_route(struct device *dev, const char *val, uint32_t de
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reconfigure_profile(struct device *dev, struct profile *pr)
|
static int reconfigure_profile(struct device *dev, struct profile *pr, bool restore)
|
||||||
{
|
{
|
||||||
struct impl *impl = dev->impl;
|
struct impl *impl = dev->impl;
|
||||||
char key[1024];
|
char key[1024];
|
||||||
|
|
@ -691,7 +697,7 @@ static int reconfigure_profile(struct device *dev, struct profile *pr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (i = 0; i < n_devices; i++)
|
for (i = 0; i < n_devices; i++)
|
||||||
restore_device_route(dev, json, devices[i]);
|
restore_device_route(dev, json, devices[i], restore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spa_pod_parser_pop(&prs, &f[0]);
|
spa_pod_parser_pop(&prs, &f[0]);
|
||||||
|
|
@ -723,6 +729,7 @@ static int handle_route(struct device *dev, struct route *r)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
ri->active = true;
|
ri->active = true;
|
||||||
|
ri->save = r->save;
|
||||||
|
|
||||||
if (!ri->prev_active) {
|
if (!ri->prev_active) {
|
||||||
/* a new port has been found, restore the volume and make sure we
|
/* a new port has been found, restore the volume and make sure we
|
||||||
|
|
@ -745,7 +752,7 @@ static int handle_device(struct device *dev)
|
||||||
|
|
||||||
dev->generation++;
|
dev->generation++;
|
||||||
|
|
||||||
/* first look at all routes */
|
/* first look at all routes and update */
|
||||||
spa_list_for_each(p, &dev->obj->param_list, link) {
|
spa_list_for_each(p, &dev->obj->param_list, link) {
|
||||||
struct route r;
|
struct route r;
|
||||||
struct route_info *ri;
|
struct route_info *ri;
|
||||||
|
|
@ -767,6 +774,7 @@ static int handle_device(struct device *dev)
|
||||||
ri->generation = dev->generation;
|
ri->generation = dev->generation;
|
||||||
ri->prev_active = ri->active;
|
ri->prev_active = ri->active;
|
||||||
ri->active = false;
|
ri->active = false;
|
||||||
|
ri->save = false;
|
||||||
}
|
}
|
||||||
/* then check for changes in the active ports */
|
/* then check for changes in the active ports */
|
||||||
spa_list_for_each(p, &dev->obj->param_list, link) {
|
spa_list_for_each(p, &dev->obj->param_list, link) {
|
||||||
|
|
@ -780,8 +788,9 @@ static int handle_device(struct device *dev)
|
||||||
prune_route_info(dev);
|
prune_route_info(dev);
|
||||||
|
|
||||||
if ((res = find_current_profile(dev, &pr)) >= 0) {
|
if ((res = find_current_profile(dev, &pr)) >= 0) {
|
||||||
if (dev->active_profile != pr.index || route_changed)
|
bool restore = dev->active_profile != pr.index;
|
||||||
reconfigure_profile(dev, &pr);
|
if (restore || route_changed)
|
||||||
|
reconfigure_profile(dev, &pr, restore);
|
||||||
|
|
||||||
save_profile(dev, &pr);
|
save_profile(dev, &pr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue