media-session: save last target_node

Keep a per node entry of the saved target node and use this when
there is no other target node.
When explicitly moving a stream, save the new target node.
This commit is contained in:
Wim Taymans 2020-10-14 12:35:27 +02:00
parent 1bd31c1cf1
commit 3733a5e219
4 changed files with 66 additions and 45 deletions

View file

@ -74,12 +74,6 @@ struct stream {
struct spa_hook listener;
};
struct find_data {
struct impl *impl;
const char *name;
uint32_t id;
};
static void remove_idle_timeout(struct impl *impl)
{
struct pw_loop *main_loop = pw_context_get_main_loop(impl->context);
@ -129,7 +123,6 @@ static char *serialize_props(struct stream *str, const struct spa_pod *param)
float val = 0.0f;
bool b = false;
char *ptr;
const char *v;
size_t size;
FILE *f;
@ -156,15 +149,16 @@ static char *serialize_props(struct stream *str, const struct spa_pod *param)
fprintf(f, "volumes:%d", n_vals);
for (i = 0; i < n_vals; i++)
fprintf(f, ",%f", vals[i]);
fprintf(f, " ");
break;
}
default:
break;
}
}
if ((v = pw_properties_get(str->obj->obj.props, PW_KEY_NODE_TARGET)) != NULL) {
fprintf(f, "target-node:%s", v);
}
if (str->obj->target_node != NULL)
fprintf(f, "target-node:%s", str->obj->target_node);
fclose(f);
return ptr;
}
@ -192,7 +186,7 @@ static int restore_stream(struct stream *str, const char *val)
{
const char *p;
char *end;
char buf[1024], target[256];
char buf[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
struct spa_pod_frame f[2];
struct spa_pod *param;
@ -243,13 +237,10 @@ static int restore_stream(struct stream *str, const char *val)
}
else if (strstr(p, "target-node:") == p) {
p += 12;
end = strstr(p, " ");
if (end == NULL)
continue;
i = end - p;
strncpy(target, p, i);
target[i-1] = 0;
i = strlen(p);
pw_log_info("stream %d: target '%s'", str->obj->obj.id, p);
free(str->obj->target_node);
str->obj->target_node = i > 0 ? strndup(p, i) : NULL;
} else {
p++;
}