Execute background volume control command in a separate thread 19/266319/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 10 Nov 2021 12:45:45 +0000 (21:45 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 10 Nov 2021 12:45:45 +0000 (21:45 +0900)
Change-Id: I1f07ef289514850cc179eb7cd2ff8c16b2918b31

plugins/wakeup-manager/inc/wakeup_audio_manager.h
plugins/wakeup-manager/src/wakeup_audio_manager.cpp

index 16d4059b0fd8f7c4b8ccd707c2a4cfbe88e146ed..7165ce3ebd794d0c705225868f9463f18ef996d7 100644 (file)
@@ -122,6 +122,8 @@ private:
 
        mutex mMutex;
        bool mVoiceKeyPressed{false};
+
+       thread mBackgroundVolumeThread;
 };
 
 } // wakeup
index 656a2975cda74808553614061a667c75e3d5dde5..81ec9faa3115cbbe804f003834e8a7a33158ec3b 100644 (file)
@@ -83,6 +83,15 @@ int CAudioManager::deinitialize(void)
        }
        mStopStreamingThread.store(false);
 
+       if (mBackgroundVolumeThread.joinable()) {
+               MWR_LOGD("mBackgroundVolumeThread is joinable, trying join()");
+               try {
+                       mBackgroundVolumeThread.join();
+               } catch (std::exception &e) {
+                       MWR_LOGE("Exception thrown : %s", e.what());
+               }
+       }
+
        sound_manager_remove_focus_state_watch_cb(mSoundFocusWatchId);
 
        return 0;
@@ -519,10 +528,19 @@ void CAudioManager::stop_streaming_follow_up_data()
        mStopStreamingThread.store(false);
 }
 
-void CAudioManager::set_background_volume(double ratio)
+static void set_background_volume_thread_func(double ratio)
 {
+       MWR_LOGI("[ENTER]");
        dependency_resolver_set_background_volume(ratio);
 }
 
+void CAudioManager::set_background_volume(double ratio)
+{
+       if (mBackgroundVolumeThread.joinable()) {
+               mBackgroundVolumeThread.join();
+       }
+       mBackgroundVolumeThread = thread(&set_background_volume_thread_func, ratio);
+}
+
 } // wakeup
 } // multiassistant