Skip to content

Commit

Permalink
[dbusif] Add option to route sources first. MER#1725
Browse files Browse the repository at this point in the history
Some devices (at least OnePlus X) need to have sources routed before
sinks to have properly functioning FM Radio. Add option to change the
routing order for these devices.

route_sources_first=<true|false> default to false.
  • Loading branch information
jusa committed Dec 30, 2016
1 parent 8694653 commit 2fa1dfb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/dbusif.c
Expand Up @@ -67,6 +67,7 @@ struct pa_policy_dbusif {
char *strrule; /* match rule to catch stream info signals */
int regist; /* wheter or not registered to policy daemon*/
int re_regist;
bool route_sources_first;
};

struct actdsc { /* action descriptor */
Expand Down Expand Up @@ -129,7 +130,8 @@ struct pa_policy_dbusif *pa_policy_dbusif_init(struct userdata *u,
const char *ifnam,
const char *mypath,
const char *pdpath,
const char *pdnam)
const char *pdnam,
bool route_sources_first)
{
pa_module *m = u->module;
struct pa_policy_dbusif *dbusif = NULL;
Expand All @@ -141,6 +143,8 @@ struct pa_policy_dbusif *pa_policy_dbusif_init(struct userdata *u,

dbusif = pa_xnew0(struct pa_policy_dbusif, 1);

dbusif->route_sources_first = route_sources_first;

dbus_error_init(&error);
dbusif->conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &error);

Expand Down Expand Up @@ -734,6 +738,17 @@ static int audio_route_parser(struct userdata *u, DBusMessageIter *actit)
num_moving = pa_policy_group_start_move_all(u);
pa_log_debug("Policy groups moving: %d", num_moving);

if (u->dbusif->route_sources_first) {
/* Following works only if MAX_ROUTING_DECISIONS is 2, so make sure this is
* caught if the value ever changes. */
pa_assert_se(MAX_ROUTING_DECISIONS == 2);
if (num_decisions > 1 && decisions[0].class != pa_policy_route_to_source) {
struct routing_decision tmp = decisions[0];
decisions[0] = decisions[1];
decisions[1] = tmp;
}
}

/* Set profiles and ports while the groups are detached. */
for (i = 0; i < num_decisions; i++) {
p = pa_proplist_new();
Expand Down
2 changes: 1 addition & 1 deletion src/dbusif.h
Expand Up @@ -7,7 +7,7 @@ struct pa_policy_dbusif;

struct pa_policy_dbusif *pa_policy_dbusif_init(struct userdata *, const char *,
const char *, const char *,
const char *);
const char *, bool);
void pa_policy_dbusif_done(struct userdata *);
void pa_policy_dbusif_send_device_state(struct userdata *, const char *, const char **, int);
void pa_policy_dbusif_send_media_status(struct userdata *, const char *,
Expand Down
11 changes: 9 additions & 2 deletions src/module-policy-enforcement.c
Expand Up @@ -60,6 +60,7 @@ PA_MODULE_USAGE(
"dbus_policyd_name=<policy daemon's name> "
"null_sink_name=<name of the null sink> "
"othermedia_preemption=<on|off> "
"route_sources_first=<true|false> Default false "
"configdir=<configuration directory>"
);

Expand All @@ -71,6 +72,7 @@ static const char* const valid_modargs[] = {
"dbus_policyd_name",
"null_sink_name",
"othermedia_preemption",
"route_sources_first",
"configdir",
NULL
};
Expand All @@ -86,6 +88,7 @@ int pa__init(pa_module *m) {
const char *pdnam;
const char *nsnam;
const char *preempt;
bool route_sources_first = false;
const char *cfgdir;

pa_assert(m);
Expand All @@ -104,7 +107,11 @@ int pa__init(pa_module *m) {
preempt = pa_modargs_get_value(ma, "othermedia_preemption", NULL);
cfgdir = pa_modargs_get_value(ma, "configdir", NULL);


if (pa_modargs_get_value_boolean(ma, "route_sources_first", &route_sources_first) < 0) {
pa_log("Failed to parse \"route_sources_first\" parameter.");
goto fail;
}

u = pa_xnew0(struct userdata, 1);
m->userdata = u;
u->core = m->core;
Expand All @@ -122,7 +129,7 @@ int pa__init(pa_module *m) {
u->groups = pa_policy_groupset_new(u);
u->classify = pa_classify_new(u);
u->context = pa_policy_context_new(u);
u->dbusif = pa_policy_dbusif_init(u, ifnam, mypath, pdpath, pdnam);
u->dbusif = pa_policy_dbusif_init(u, ifnam, mypath, pdpath, pdnam, route_sources_first);
u->shared = pa_shared_data_get(u->core);

if (u->scl == NULL || u->ssnk == NULL || u->ssrc == NULL ||
Expand Down

0 comments on commit 2fa1dfb

Please sign in to comment.