Make not to acquire sound focus when screen reader and notification modes 38/307438/1
authorsooyeon <sooyeon.kim@samsung.com>
Fri, 8 Mar 2024 08:09:53 +0000 (17:09 +0900)
committerSooyeon Kim <sooyeon.kim@samsung.com>
Fri, 8 Mar 2024 08:18:34 +0000 (08:18 +0000)
- Issue:
In Tizen 7.0 FHub, media-type playing is stopped, because TTS screen-reader mode acquires a sound focus.

- Solution:
Rollback to the previous TTS sound focus policy.
* Default / Interrupt modes: acquire sound focus
* Screen-reader / Notification modes: NOT acquire sound focus

Change-Id: I73a63743f20e341988db42190435ca9ade271eba
Signed-off-by: sooyeon <sooyeon.kim@samsung.com>
(cherry picked from commit ff6316a4b2a1d4ece22c949486d038e8561b0e26)

server/ttsd_player.cpp

index c55a461..fd858a5 100644 (file)
@@ -138,18 +138,28 @@ static void write_buffer_dump_file(const void* buffer, size_t length)
 }
 #endif
 
-static void set_policy_for_playing(void)
+static void set_policy_for_playing(unsigned int uid)
 {
-       g_audio_stream->acquireSoundFocus();
+       /* In case of DEFAULT and INTERRUPT mode, acquire sound focus */
+       ttsd_mode_e mode = ttsd_data_get_mode(uid);
+       SLOG(LOG_INFO, tts_tag(), "[Player INFO] Current uid(%d)'s mode(%d)", uid, (int)mode);
+       if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode)
+               g_audio_stream->acquireSoundFocus();
+
        g_background_volume->applyVolumeRatio();
        g_is_set_policy = true;
        SLOG(LOG_ERROR, tts_tag(), "[BG] g_is_set_policy(%d)", static_cast<int>(g_is_set_policy.load()));
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
 }
 
-static void unset_policy_for_playing()
+static void unset_policy_for_playing(unsigned int uid)
 {
-       g_audio_stream->releaseSoundFocus();
+/* In case of DEFAULT and INTERRUPT mode, release sound focus */
+       ttsd_mode_e mode = ttsd_data_get_mode(uid);
+       SLOG(LOG_INFO, tts_tag(), "[Player INFO] Current uid(%d)'s mode(%d)", uid, (int)mode);
+       if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode)
+               g_audio_stream->releaseSoundFocus();
+
        g_background_volume->recoverVolumeRatio();
        g_is_set_policy = false;
        SLOG(LOG_ERROR, tts_tag(), "[BG] g_is_set_policy(%d)", static_cast<int>(g_is_set_policy.load()));
@@ -211,8 +221,8 @@ static int play_sound_data(PlayerThread* player, unsigned int uid, sound_data_s*
 
        // Check whether set_policy is done or not
        if (false == g_is_set_policy.load()) {
-               SLOG(LOG_INFO, tts_tag(), "[Player INFO] Set policy");
-               set_policy_for_playing();
+               SLOG(LOG_INFO, tts_tag(), "[Player INFO] Set policy. uid(%d)", uid);
+               set_policy_for_playing(uid);
        }
 
        if (TTSD_ERROR_NONE != g_audio_stream->prepareAudioOut()) {
@@ -278,7 +288,7 @@ static void wait_sound_data(PlayerThread* player, unsigned int uid)
                if (TTSD_SYNTHESIS_CONTROL_DOING != synth_control) {
                        if (AudioStream::AUDIO_STATE_PLAY == g_audio_stream->getState()) {
                                g_audio_stream->unprepareAudioOut();
-                               unset_policy_for_playing();
+                               unset_policy_for_playing(uid);  // uid == current uid
                        }
                }
                prev_synth_control = synth_control;
@@ -347,7 +357,7 @@ static void play_utterance_cb(PlayerThread* player, unsigned int uid)
 
                                SLOG(LOG_INFO, tts_tag(), "[Player] No Sound data. Event(%d), uid(%u), uttid(%d)", event, uid, utt_id);
                                if (TTSE_RESULT_EVENT_FINISH == event) {
-                                       unset_policy_for_playing();
+                                       unset_policy_for_playing(uid);
                                        if (TTSD_ERROR_INVALID_PARAMETER == notify_utterance_completed_event(uid, utt_id)) {
                                                break;
                                        }
@@ -376,7 +386,7 @@ static void play_utterance_cb(PlayerThread* player, unsigned int uid)
                sound_data = nullptr;
 
                if (TTSE_RESULT_EVENT_FINISH == event) {
-                       unset_policy_for_playing();
+                       unset_policy_for_playing(uid);
                        if (TTSD_ERROR_NONE != notify_utterance_completed_event(uid, utt_id)) {
                                break;
                        }
@@ -391,7 +401,7 @@ static void play_utterance_cb(PlayerThread* player, unsigned int uid)
        }
 
        g_audio_stream->unprepareAudioOut();
-       unset_policy_for_playing();
+       unset_policy_for_playing(uid);
 
 #ifdef BUF_SAVE_MODE
        close_buffer_dump_file();