Apply blocking policy in case of prepare() functions 78/155478/1
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 17 Apr 2017 07:04:55 +0000 (16:04 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 13 Oct 2017 08:01:03 +0000 (08:01 +0000)
If audio io handle uses media session with MIX_WITH_OTHERS option and other process
has already acquired a focus which has more higher priority than media, policy error
will be returned from prepare() functions.
 - audio_out_prepare(), audio_in_prepare()

Unnecessary session backward compatibility codes are also removed in some functions
exported since tizen 3.0.
 - audio_out_pause(), audio_in_pause()
 - audio_out_resume(), audio_in_resume()

Original patch is
 : https://review.tizen.org/gerrit/#/c/125413/

[Version] 0.4.1
[Profile] Common
[Issue Type] Backward compatibility

Change-Id: Id0710c2847903cf96cdce38eab909b5c2e103c5f
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
(cherry picked from commit 6035bcf1a578fa1c0533a7d850e0e9f2794a46ab)

include/CAudioSessionHandler.h
packaging/capi-media-audio-io.spec
src/cpp/CAudioInput.cpp
src/cpp/CAudioOutput.cpp
src/cpp/CAudioSessionHandler.cpp

index 363714e..9aa8f0a 100644 (file)
@@ -118,6 +118,7 @@ namespace tizen_media_audio {
         bool __isFocusDisableReacquisitionRequired(MMSessionType type, int options);
         void __lockFocusCBMutex();
         void __unlockFocusCBMutex();
+        bool __checkNeedBlock(const char *focus_acquired_by);
 
         /* Static Member */
         static int                  __sCaptureRef;
index 40332fa..e7f667e 100644 (file)
@@ -1,6 +1,6 @@
 Name:           capi-media-audio-io
 Summary:        An Audio Input & Audio Output library in Tizen Native API
-Version:        0.4.0
+Version:        0.4.1
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
index 93a58da..22f2b01 100644 (file)
@@ -284,12 +284,11 @@ void CAudioInput::prepare() {
         // Create PulseAudio Handler
         mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_RECORD, spec, this);
 
-        // Initialize PulseAudio Handler
-        mpPulseAudioClient->initialize();
-
         if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
             mpAudioSessionHandler->updatePlaying();
 
+        // Initialize PulseAudio Handler
+        mpPulseAudioClient->initialize();
 #ifndef DISABLE_MOBILE_BACK_COMP
         // Uncork stream which is created with CORKED flag */
         mpPulseAudioClient->cork(false);
@@ -361,18 +360,8 @@ void CAudioInput::pause() {
     try {
         CAudioIO::pause();
 
-        internalLock();
-
-        /* Updates ASM to STOP */
-        if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false) {
-            mpAudioSessionHandler->updateStop();
-        }
-
-        internalUnlock();
-
         CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
     } catch (CAudioError& e) {
-        internalUnlock();
         throw;
     }
 }
@@ -393,18 +382,10 @@ void CAudioInput::resume() {
     }
 
     try {
-        internalLock();
-
-        if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
-            mpAudioSessionHandler->updatePlaying();
-
-        internalUnlock();
-
         CAudioIO::resume();
 
         CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
     } catch (CAudioError& e) {
-        internalUnlock();
         throw;
     }
 }
index 6760f2e..80f17b9 100644 (file)
@@ -183,12 +183,11 @@ void CAudioOutput::prepare() {
         // Create PulseAudio Handler
         mpPulseAudioClient = new CPulseAudioClient(CPulseAudioClient::EStreamDirection::STREAM_DIRECTION_PLAYBACK, spec, this);
 
-        // Initialize PulseAudio Handler
-        mpPulseAudioClient->initialize();
-
         if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
             mpAudioSessionHandler->updatePlaying();
 
+        // Initialize PulseAudio Handler
+        mpPulseAudioClient->initialize();
 #ifndef DISABLE_MOBILE_BACK_COMP
         // Uncork stream which is created with CORKED flag */
         mpPulseAudioClient->cork(false);
@@ -266,17 +265,8 @@ void CAudioOutput::pause() {
     try {
         CAudioIO::pause();
 
-        internalLock();
-
-        /* Updates ASM to STOP */
-        if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
-            mpAudioSessionHandler->updateStop();
-
-        internalUnlock();
-
         CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_PAUSED);
     } catch (CAudioError& e) {
-        internalUnlock();
         throw;
     }
 }
@@ -297,18 +287,10 @@ void CAudioOutput::resume() {
     }
 
     try {
-        internalLock();
-
-        if (isForceIgnore() == false && mpAudioSessionHandler->isSkipSession() == false)
-            mpAudioSessionHandler->updatePlaying();
-
-        internalUnlock();
-
         CAudioIO::resume();
 
         CAudioIO::onStateChanged(CAudioInfo::EAudioIOState::AUDIO_IO_STATE_RUNNING);
     } catch (CAudioError& e) {
-        internalUnlock();
         throw;
     }
 }
index f56d73e..771910e 100644 (file)
@@ -186,6 +186,22 @@ bool CAudioSessionHandler::__isFocusDisableReacquisitionRequired(MMSessionType t
     return false;
 }
 
+bool CAudioSessionHandler::__checkNeedBlock(const char *focus_acquired_by) {
+    assert(focus_acquired_by != NULL);
+
+    if (!strcmp(focus_acquired_by, "alarm") ||
+        !strcmp(focus_acquired_by, "ringtone-voip") ||
+        !strcmp(focus_acquired_by, "ringtone-call") ||
+        !strcmp(focus_acquired_by, "voip") ||
+        !strcmp(focus_acquired_by, "call-voice") ||
+        !strcmp(focus_acquired_by, "call-video")) {
+        AUDIO_IO_LOGW("Blocked by session policy, focus_acquired_by[%s]", focus_acquired_by);
+        return true;
+    }
+
+    return false;
+}
+
 int CAudioSessionHandler::getId() {
     return __mId;
 }
@@ -465,6 +481,8 @@ void CAudioSessionHandler::updatePlaying() {
     if (__mIsInit == false) {
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Doesn't initialize CAudioSessionHandler");
     }
+    if (!__mUseFocus || __mId < 0)
+        return;
 
     if (__mUseFocus && __isFocusRequired(__mMultimediaSession, __mOptions)) {
         if (__mId >= 0) {
@@ -501,6 +519,24 @@ void CAudioSessionHandler::updatePlaying() {
             if (!is_focus_cb_thread)
                 __unlockFocusCBMutex();
         }
+    } else {
+        int ret = MM_ERROR_NONE;
+        char *stream_type = NULL;
+        char *ext_info = NULL;
+        int option = 0;
+
+        if ((ret = mm_sound_get_stream_type_of_acquired_focus(FOCUS_FOR_BOTH, &stream_type, &option, &ext_info)))
+            return;
+
+        AUDIO_IO_LOGD("Focus is acquired by stream_type[%s], option[%d], ext_info[%s]", stream_type, option, ext_info);
+
+        if (__checkNeedBlock((const char*)stream_type)) {
+            free(stream_type);
+            free(ext_info);
+            THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_POLICY_BLOCKED, "Blocked by an acquired focus");
+        }
+        free(stream_type);
+        free(ext_info);
     }
 }