Skip to content

Commit

Permalink
mediamanager: ensure that a manually overriden speaker does not rever…
Browse files Browse the repository at this point in the history
…t to automatic control
  • Loading branch information
z-dule committed Apr 30, 2024
1 parent 8f8667f commit 8878272
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/mediamgr/mediamgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct mm {
bool should_reset;
bool alloc_pending;
bool play_ready;
bool speaker_override;

pthread_t thread;

Expand Down Expand Up @@ -721,6 +722,11 @@ static void enable_speaker(struct mm *mm, bool enable)
enum mediamgr_auplay cur_route = mm_platform_get_route();
enum mediamgr_auplay wanted_route = MEDIAMGR_AUPLAY_UNKNOWN;

if (mm->speaker_override) {
info("enable_speaker: speaker manual override, ignoring\n");
return;
}

info("enable_speaker: enable=%d\n", enable);

mm->router.prefer_loudspeaker = enable;
Expand Down Expand Up @@ -898,6 +904,7 @@ static void exit_call(struct mm *mm)
case MM_SYS_STATE_INCOMING:
case MM_SYS_STATE_ENTERING_CALL:
set_sys_state(mm, MM_SYS_STATE_EXITING_CALL);
mm->speaker_override = false;
mm_platform_exit_call();
break;

Expand Down Expand Up @@ -1396,6 +1403,7 @@ static void sys_left_call_handler(struct mm *mm)
set_sys_state(mm, MM_SYS_STATE_NORMAL);
if (mm->call_state == MEDIAMGR_STATE_NORMAL) {
mm->router.prefer_loudspeaker = false;
mm->speaker_override = false;
update_route(mm, MM_DEVICE_CHANGED);
}
}
Expand Down Expand Up @@ -1534,6 +1542,7 @@ static void call_state_handler(struct mm *mm, enum mediamgr_state new_state)

switch (new_state) {
case MEDIAMGR_STATE_NORMAL:
mm->speaker_override = false;
set_state(mm, new_state);
stop_all_media(mm);
audio_release(mm);
Expand Down Expand Up @@ -1751,7 +1760,9 @@ static void mqueue_handler(int id, void *data, void *arg)
case MM_MARSHAL_ENABLE_SPEAKER: {
bool enable = msg->bool_elem.val;

g_mm->speaker_override = false;
enable_speaker(g_mm, enable);
g_mm->speaker_override = true;
}
break;

Expand Down

0 comments on commit 8878272

Please sign in to comment.