Merge "Deactivate ducking after the activation is completed" into tizen
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 1 Jul 2021 09:33:46 +0000 (09:33 +0000)
committerGerrit Code Review <gerrit@review>
Thu, 1 Jul 2021 09:33:46 +0000 (09:33 +0000)
1  2 
server/ttsd_player.c

index 207cb3607ed6c71a4be6b5172a36b05e943f39a2,8f3ca3413737485db2bac01a385b6fb86c3208a2..b09370e3e914b8257315daf724ea8963831f63b1
@@@ -415,7 -420,15 +420,13 @@@ static void __end_play_thread(void *dat
  
  static void __set_policy_for_playing(int volume)
  {
+       pthread_mutex_lock(&g_delayed_unset_policy_mutex);
+       if (NULL != g_delayed_unset_policy_timer) {
+               ecore_timer_del(g_delayed_unset_policy_timer);
+               g_delayed_unset_policy_timer = NULL;
+       }
+       pthread_mutex_unlock(&g_delayed_unset_policy_mutex);
  
 -      __change_background_volume();
 -
        /* Set stream info */
        int ret;
        ttsd_mode_e mode = ttsd_get_mode();
                SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
        }
  
 +      __change_background_volume();
        g_is_set_policy = true;
 +      SLOG(LOG_ERROR, tts_tag(), "[BG] g_is_set_policy(%d)", g_is_set_policy);
  
+       clock_gettime(CLOCK_MONOTONIC, &g_policy_set_time);
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
  
        return;
@@@ -473,10 -504,27 +504,28 @@@ static void __unset_policy_for_playing(
                }
        }
  
+       struct timespec current_time;
+       clock_gettime(CLOCK_MONOTONIC, &current_time);
+       long long int diff = ((long long int)current_time.tv_sec - (long long int)g_policy_set_time.tv_sec) * 1000
+                       + ((long long int)current_time.tv_nsec - (long long int)g_policy_set_time.tv_nsec) / 1000000;
+       SLOG(LOG_INFO, tts_tag(), "[BG] Time Diff(%lld)", diff);
+       pthread_mutex_lock(&g_delayed_unset_policy_mutex);
+       if (NULL == g_delayed_unset_policy_timer) {
+               if (diff > SND_MGR_DUCKING_DURATION) {
+                       SLOG(LOG_INFO, tts_tag(), "[BG] Direct unset policy");
+                       __recover_background_volume();
+               } else {
+                       ecore_main_loop_thread_safe_call_sync(__set_timer_for_unset, NULL);
+               }
+       }
+       pthread_mutex_unlock(&g_delayed_unset_policy_mutex);
        __recover_background_volume();
 -
        g_is_set_policy = false;
 +      SLOG(LOG_ERROR, tts_tag(), "[BG] g_is_set_policy(%d)", g_is_set_policy);
 +
  
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");