config-policy: use the default session endpoint if target-endpoint is not defined

This commit is contained in:
Julian Bouzas
2019-12-13 11:26:59 -05:00
parent 5348239ccb
commit eda8507ef7
3 changed files with 70 additions and 30 deletions

View File

@@ -279,8 +279,9 @@ static WpBaseEndpoint *
wp_config_policy_find_endpoint (WpPolicy *policy, GVariant *props,
guint32 *stream_id)
{
g_autoptr (WpCore) core = NULL;
g_autoptr (WpPolicyManager) pmgr = NULL;
g_autoptr (WpCore) core = wp_policy_get_core (policy);
g_autoptr (WpPolicyManager) pmgr = wp_policy_manager_get_instance (core);
g_autoptr (WpSession) session = wp_policy_manager_get_session (pmgr);
const struct WpParserEndpointLinkData *data = NULL;
g_autoptr (GPtrArray) endpoints = NULL;
guint i;
@@ -294,9 +295,10 @@ wp_config_policy_find_endpoint (WpPolicy *policy, GVariant *props,
if (!data)
return NULL;
/* If target-endpoint data was defined in the configuration file, find the
* matching endpoint based on target-endpoint data */
if (data->has_te) {
/* Get all the endpoints matching the media class */
core = wp_policy_get_core (policy);
pmgr = wp_policy_manager_get_instance (core);
endpoints = wp_policy_manager_list_endpoints (pmgr,
data->te.endpoint_data.media_class);
if (!endpoints)
@@ -309,6 +311,41 @@ wp_config_policy_find_endpoint (WpPolicy *policy, GVariant *props,
&data->te.endpoint_data))
break;
}
}
/* Otherwise, use the default session endpoint if the session is valid */
else if (session) {
/* Get the default type */
WpDefaultEndpointType type;
switch (data->me.endpoint_data.direction) {
case PW_DIRECTION_INPUT:
type = WP_DEFAULT_ENDPOINT_TYPE_AUDIO_SOURCE;
break;
case PW_DIRECTION_OUTPUT:
type = WP_DEFAULT_ENDPOINT_TYPE_AUDIO_SINK;
break;
default:
g_warn_if_reached ();
return NULL;
}
/* Get all the endpoints */
endpoints = wp_policy_manager_list_endpoints (pmgr, NULL);
if (!endpoints)
return NULL;
/* Find the default session endpoint */
for (i = 0; i < endpoints->len; i++) {
target = g_ptr_array_index (endpoints, i);
guint def_id = wp_session_get_default_endpoint (session, type);
if (def_id == wp_base_endpoint_get_global_id (target))
break;
}
}
/* If no target data has been defined and session is not valid, return null */
else
return NULL;
/* If target did not match any data, return NULL */
if (i >= endpoints->len)

View File

@@ -199,10 +199,11 @@ wp_parser_endpoint_link_data_new (const gchar *location)
/* Get the match endpoint properties (Optional) */
res->me.endpoint_data.props = parse_properties (me, "properties");
/* Get the target-endpoint table */
/* Get the target-endpoint table (Optional) */
res->has_te = FALSE;
te = wp_toml_table_get_table (table, "target-endpoint");
if (!te)
goto error;
if (te) {
res->has_te = TRUE;
/* Get the name from the match endpoint table (Optional) */
res->te.endpoint_data.name = wp_toml_table_get_string (te, "name");
@@ -220,6 +221,7 @@ wp_parser_endpoint_link_data_new (const gchar *location)
/* Get the target endpoint stream */
res->te.stream = wp_toml_table_get_string (te, "stream");
}
/* Get the target-endpoint table */
el = wp_toml_table_get_table (table, "endpoint-link");

View File

@@ -27,6 +27,7 @@ struct WpParserEndpointLinkData {
guint priority;
struct WpParserEndpointLinkEndpointData endpoint_data;
} me;
gboolean has_te;
struct TargetEndpoint {
struct WpParserEndpointLinkEndpointData endpoint_data;
char *stream;