Skip to content

Commit

Permalink
[audiorouting] Derive music playback from media_state. Fixes JB#36733
Browse files Browse the repository at this point in the history
Relying on volume limit heuristics to determine whether some application
is doing audio playback is unreliable. And if MCE makes a wrong guess
it affects for example volume key input policy (volume keys can't be
used for adjusting playback volume).

When possible, use factual media state information instead of heuristics.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Jan 24, 2019
1 parent b245e16 commit bbf886d
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions modules/audiorouting.c
Expand Up @@ -137,6 +137,9 @@ static const struct
/** Audio route; derived from audio sink device name */
static audio_route_t audio_route = AUDIO_ROUTE_UNDEF;

/** Audio playback: derived from media_state */
static tristate_t media_playback_state = TRISTATE_UNKNOWN;

/* Volume limits used for "music playback" heuristics */
static int volume_limit_player = 100;
static int volume_limit_flash = 100;
Expand Down Expand Up @@ -293,6 +296,22 @@ static void context_cb(ohm_decision_t *ohm)
if( have != want )
goto EXIT;

if( !strcmp(ohm->variable, "media_state") ) {
tristate_t state = TRISTATE_UNKNOWN;

if( !strcmp(ohm->value, "active") || !strcmp(ohm->value, "background") )
state = TRISTATE_TRUE;
else
state = TRISTATE_FALSE;

if( media_playback_state != state ) {
mce_log(LL_DEBUG, "media_playback_state: %s -> %s",
tristate_repr(media_playback_state),
tristate_repr(state));
media_playback_state = state;
}
}

EXIT:
return;
}
Expand Down Expand Up @@ -529,9 +548,17 @@ static gboolean actions_dbus_cb(DBusMessage *sig)
goto EXIT;
}

playback = (volume_limit_player > 0 &&
volume_limit_flash <= 0 &&
volume_limit_inputsound <= 0);
if( media_playback_state != TRISTATE_UNKNOWN ) {
/* Use media_state from com.nokia.policy.context
* when it is included in OHM policy signal. */
playback = (media_playback_state == TRISTATE_TRUE);
}
else {
/* Fallback to volume limit heuristics */
playback = (volume_limit_player > 0 &&
volume_limit_flash <= 0 &&
volume_limit_inputsound <= 0);
}

EXIT:
if( datapipe_get_gint(music_playback_ongoing_pipe) != playback ) {
Expand Down

0 comments on commit bbf886d

Please sign in to comment.