mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
loop: move the loop name to pw_loop
That way, all loops have a name and we can move nodes to specific loops even if they are not a data loop.
This commit is contained in:
parent
fbafaff31b
commit
c12cf748b6
8 changed files with 42 additions and 20 deletions
|
|
@ -266,6 +266,7 @@ static int setup_data_loops(struct impl *impl)
|
||||||
res = -errno;
|
res = -errno;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
pw_log_info("created data loop '%s'", impl->data_loops[i].impl->loop->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pw_log_info("created %d data-loops", impl->n_data_loops);
|
pw_log_info("created %d data-loops", impl->n_data_loops);
|
||||||
|
|
@ -629,9 +630,10 @@ static struct pw_data_loop *acquire_data_loop(struct impl *impl, const char *nam
|
||||||
|
|
||||||
for (i = 0; i < impl->n_data_loops; i++) {
|
for (i = 0; i < impl->n_data_loops; i++) {
|
||||||
struct data_loop *l = &impl->data_loops[i];
|
struct data_loop *l = &impl->data_loops[i];
|
||||||
|
const char *ln = l->impl->loop->name;
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
if (name && l->impl->name && fnmatch(name, l->impl->name, FNM_EXTMATCH) == 0)
|
if (name && ln && fnmatch(name, ln, FNM_EXTMATCH) == 0)
|
||||||
score += 2;
|
score += 2;
|
||||||
if (klass && l->impl->classes) {
|
if (klass && l->impl->classes) {
|
||||||
for (j = 0; l->impl->classes[j]; j++) {
|
for (j = 0; l->impl->classes[j]; j++) {
|
||||||
|
|
@ -643,7 +645,7 @@ static struct pw_data_loop *acquire_data_loop(struct impl *impl, const char *nam
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_log_debug("%d: name:'%s' class:'%s' score:%d ref:%d", i,
|
pw_log_debug("%d: name:'%s' class:'%s' score:%d ref:%d", i,
|
||||||
l->impl->name, l->impl->class, score, l->ref);
|
ln, l->impl->class, score, l->ref);
|
||||||
|
|
||||||
if ((best_loop == NULL) ||
|
if ((best_loop == NULL) ||
|
||||||
(score > best_score) ||
|
(score > best_score) ||
|
||||||
|
|
@ -656,7 +658,7 @@ static struct pw_data_loop *acquire_data_loop(struct impl *impl, const char *nam
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
best_loop->ref++;
|
best_loop->ref++;
|
||||||
pw_log_info("using name:'%s' class:'%s' ref:%d", best_loop->impl->name,
|
pw_log_info("using name:'%s' class:'%s' ref:%d", best_loop->impl->loop->name,
|
||||||
best_loop->impl->class, best_loop->ref);
|
best_loop->impl->class, best_loop->ref);
|
||||||
|
|
||||||
return best_loop->impl;
|
return best_loop->impl;
|
||||||
|
|
@ -682,7 +684,7 @@ struct pw_loop *pw_context_acquire_loop(struct pw_context *context, const struct
|
||||||
pw_log_info("looking for name:'%s' class:'%s'", name, klass);
|
pw_log_info("looking for name:'%s' class:'%s'", name, klass);
|
||||||
|
|
||||||
if ((impl->n_data_loops == 0) ||
|
if ((impl->n_data_loops == 0) ||
|
||||||
(name && fnmatch(name, "main-loop.0", FNM_EXTMATCH) == 0) ||
|
(name && fnmatch(name, context->main_loop->name, FNM_EXTMATCH) == 0) ||
|
||||||
(klass && fnmatch(klass, "main", FNM_EXTMATCH) == 0)) {
|
(klass && fnmatch(klass, "main", FNM_EXTMATCH) == 0)) {
|
||||||
pw_log_info("using main loop num-data-loops:%d", impl->n_data_loops);
|
pw_log_info("using main loop num-data-loops:%d", impl->n_data_loops);
|
||||||
return context->main_loop;
|
return context->main_loop;
|
||||||
|
|
@ -702,7 +704,7 @@ void pw_context_release_loop(struct pw_context *context, struct pw_loop *loop)
|
||||||
struct data_loop *l = &impl->data_loops[i];
|
struct data_loop *l = &impl->data_loops[i];
|
||||||
if (l->impl->loop == loop) {
|
if (l->impl->loop == loop) {
|
||||||
l->ref--;
|
l->ref--;
|
||||||
pw_log_info("release name:'%s' class:'%s' ref:%d", l->impl->name,
|
pw_log_info("release name:'%s' class:'%s' ref:%d", l->impl->loop->name,
|
||||||
l->impl->class, l->ref);
|
l->impl->class, l->ref);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,8 @@ const struct spa_support *pw_context_get_support(struct pw_context *context, uin
|
||||||
/** Get the context main loop. Returns the value passed to pw_context_new(). */
|
/** Get the context main loop. Returns the value passed to pw_context_new(). */
|
||||||
struct pw_loop *pw_context_get_main_loop(struct pw_context *context);
|
struct pw_loop *pw_context_get_main_loop(struct pw_context *context);
|
||||||
|
|
||||||
/** Get the context data loop. This loop runs on the realtime thread.
|
/** Get the context data loop. This loop runs on the realtime thread. This
|
||||||
|
* acquires a loop from the generic data.rt class.
|
||||||
* Since 0.3.56 */
|
* Since 0.3.56 */
|
||||||
struct pw_data_loop *pw_context_get_data_loop(struct pw_context *context);
|
struct pw_data_loop *pw_context_get_data_loop(struct pw_context *context);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,11 +126,12 @@ static struct pw_data_loop *loop_new(struct pw_loop *loop, const struct spa_dict
|
||||||
if (class == NULL)
|
if (class == NULL)
|
||||||
class = this->rt_prio != 0 ? "data.rt" : "data";
|
class = this->rt_prio != 0 ? "data.rt" : "data";
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
name = "pw-data-loop";
|
name = "data-loop";
|
||||||
|
|
||||||
this->class = strdup(class);
|
this->class = strdup(class);
|
||||||
this->classes = pw_strv_parse(class, strlen(class), INT_MAX, NULL);
|
this->classes = pw_strv_parse(class, strlen(class), INT_MAX, NULL);
|
||||||
this->name = strdup(name);
|
if (!this->loop->name[0])
|
||||||
|
pw_loop_set_name(this->loop, name);
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -170,7 +171,6 @@ void pw_data_loop_destroy(struct pw_data_loop *loop)
|
||||||
|
|
||||||
spa_hook_list_clean(&loop->listener_list);
|
spa_hook_list_clean(&loop->listener_list);
|
||||||
|
|
||||||
free(loop->name);
|
|
||||||
free(loop->affinity);
|
free(loop->affinity);
|
||||||
free(loop->class);
|
free(loop->class);
|
||||||
pw_free_strv(loop->classes);
|
pw_free_strv(loop->classes);
|
||||||
|
|
@ -205,7 +205,7 @@ pw_data_loop_get_loop(struct pw_data_loop *loop)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
const char * pw_data_loop_get_name(struct pw_data_loop *loop)
|
const char * pw_data_loop_get_name(struct pw_data_loop *loop)
|
||||||
{
|
{
|
||||||
return loop->name;
|
return loop->loop->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the loop class
|
/** Get the loop class
|
||||||
|
|
@ -244,9 +244,7 @@ int pw_data_loop_start(struct pw_data_loop *loop)
|
||||||
if ((utils = loop->thread_utils) == NULL)
|
if ((utils = loop->thread_utils) == NULL)
|
||||||
utils = pw_thread_utils_get();
|
utils = pw_thread_utils_get();
|
||||||
|
|
||||||
if (loop->name)
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_NAME, loop->loop->name);
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_NAME,
|
|
||||||
loop->name);
|
|
||||||
if (loop->affinity)
|
if (loop->affinity)
|
||||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_AFFINITY,
|
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_AFFINITY,
|
||||||
loop->affinity);
|
loop->affinity);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ PW_LOG_TOPIC_EXTERN(log_loop);
|
||||||
struct impl {
|
struct impl {
|
||||||
struct pw_loop this;
|
struct pw_loop this;
|
||||||
|
|
||||||
|
char name[16];
|
||||||
|
|
||||||
struct spa_handle *system_handle;
|
struct spa_handle *system_handle;
|
||||||
struct spa_handle *loop_handle;
|
struct spa_handle *loop_handle;
|
||||||
|
|
||||||
|
|
@ -42,7 +44,7 @@ struct pw_loop *pw_loop_new(const struct spa_dict *props)
|
||||||
void *iface;
|
void *iface;
|
||||||
struct spa_support support[32];
|
struct spa_support support[32];
|
||||||
uint32_t n_support;
|
uint32_t n_support;
|
||||||
const char *lib;
|
const char *lib, *str, *name = NULL;
|
||||||
|
|
||||||
n_support = pw_get_support(support, 32);
|
n_support = pw_get_support(support, 32);
|
||||||
|
|
||||||
|
|
@ -125,6 +127,14 @@ struct pw_loop *pw_loop_new(const struct spa_dict *props)
|
||||||
}
|
}
|
||||||
this->utils = iface;
|
this->utils = iface;
|
||||||
|
|
||||||
|
if (props != NULL) {
|
||||||
|
if ((str = spa_dict_lookup(props, "loop.name")) != NULL)
|
||||||
|
name = str;
|
||||||
|
}
|
||||||
|
if (name)
|
||||||
|
snprintf(impl->name, sizeof(impl->name), "%s", name);
|
||||||
|
this->name = impl->name;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
error_unload_loop:
|
error_unload_loop:
|
||||||
|
|
@ -160,6 +170,14 @@ pw_loop_set_callbacks(struct pw_loop *loop, const struct pw_loop_callbacks *cb,
|
||||||
impl->cb = cb;
|
impl->cb = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SPA_EXPORT
|
||||||
|
int pw_loop_set_name(struct pw_loop *loop, const char *name)
|
||||||
|
{
|
||||||
|
struct impl *impl = SPA_CONTAINER_OF(loop, struct impl, this);
|
||||||
|
snprintf(impl->name, sizeof(impl->name), "%s", name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int pw_loop_check(struct pw_loop *loop)
|
int pw_loop_check(struct pw_loop *loop)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ struct pw_loop {
|
||||||
struct spa_loop *loop; /**< wrapped loop */
|
struct spa_loop *loop; /**< wrapped loop */
|
||||||
struct spa_loop_control *control; /**< loop control */
|
struct spa_loop_control *control; /**< loop control */
|
||||||
struct spa_loop_utils *utils; /**< loop utils */
|
struct spa_loop_utils *utils; /**< loop utils */
|
||||||
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pw_loop *
|
struct pw_loop *
|
||||||
|
|
@ -39,6 +40,8 @@ pw_loop_new(const struct spa_dict *props);
|
||||||
void
|
void
|
||||||
pw_loop_destroy(struct pw_loop *loop);
|
pw_loop_destroy(struct pw_loop *loop);
|
||||||
|
|
||||||
|
int pw_loop_set_name(struct pw_loop *loop, const char *name);
|
||||||
|
|
||||||
#define pw_loop_add_source(l,...) spa_loop_add_source((l)->loop,__VA_ARGS__)
|
#define pw_loop_add_source(l,...) spa_loop_add_source((l)->loop,__VA_ARGS__)
|
||||||
#define pw_loop_update_source(l,...) spa_loop_update_source((l)->loop,__VA_ARGS__)
|
#define pw_loop_update_source(l,...) spa_loop_update_source((l)->loop,__VA_ARGS__)
|
||||||
#define pw_loop_remove_source(l,...) spa_loop_remove_source((l)->loop,__VA_ARGS__)
|
#define pw_loop_remove_source(l,...) spa_loop_remove_source((l)->loop,__VA_ARGS__)
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,6 @@ static struct pw_main_loop *loop_new(struct pw_loop *loop, const struct spa_dict
|
||||||
goto error_cleanup;
|
goto error_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
pw_log_debug("%p: new", this);
|
|
||||||
|
|
||||||
if (loop == NULL) {
|
if (loop == NULL) {
|
||||||
loop = pw_loop_new(props);
|
loop = pw_loop_new(props);
|
||||||
this->created = true;
|
this->created = true;
|
||||||
|
|
@ -41,8 +39,12 @@ static struct pw_main_loop *loop_new(struct pw_loop *loop, const struct spa_dict
|
||||||
}
|
}
|
||||||
this->loop = loop;
|
this->loop = loop;
|
||||||
|
|
||||||
|
if (!this->loop->name[0])
|
||||||
|
pw_loop_set_name(this->loop, "main-loop");
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
|
|
||||||
|
pw_log_debug("%p: new '%s'", this, loop->name);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
error_free:
|
error_free:
|
||||||
|
|
|
||||||
|
|
@ -441,7 +441,6 @@ struct pw_context {
|
||||||
struct pw_data_loop {
|
struct pw_data_loop {
|
||||||
struct pw_loop *loop;
|
struct pw_loop *loop;
|
||||||
|
|
||||||
char *name;
|
|
||||||
char *affinity;
|
char *affinity;
|
||||||
char *class;
|
char *class;
|
||||||
char **classes;
|
char **classes;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ PW_LOG_TOPIC_EXTERN(log_thread_loop);
|
||||||
/** \cond */
|
/** \cond */
|
||||||
struct pw_thread_loop {
|
struct pw_thread_loop {
|
||||||
struct pw_loop *loop;
|
struct pw_loop *loop;
|
||||||
char name[16];
|
|
||||||
|
|
||||||
struct spa_hook_list listener_list;
|
struct spa_hook_list listener_list;
|
||||||
|
|
||||||
|
|
@ -159,7 +158,7 @@ static struct pw_thread_loop *loop_new(struct pw_loop *loop,
|
||||||
goto clean_this;
|
goto clean_this;
|
||||||
}
|
}
|
||||||
this->loop = loop;
|
this->loop = loop;
|
||||||
snprintf(this->name, sizeof(this->name), "%s", name ? name : "pw-thread-loop");
|
pw_loop_set_name(loop, name ? name : "thread-loop");
|
||||||
|
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
|
|
||||||
|
|
@ -323,7 +322,7 @@ int pw_thread_loop_start(struct pw_thread_loop *loop)
|
||||||
|
|
||||||
loop->running = true;
|
loop->running = true;
|
||||||
|
|
||||||
items[0] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_NAME, loop->name);
|
items[0] = SPA_DICT_ITEM_INIT(SPA_KEY_THREAD_NAME, loop->loop->name);
|
||||||
thr = pw_thread_utils_create(&SPA_DICT_INIT_ARRAY(items), do_loop, loop);
|
thr = pw_thread_utils_create(&SPA_DICT_INIT_ARRAY(items), do_loop, loop);
|
||||||
if (thr == NULL)
|
if (thr == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue