Move drain method to subclass CAudioOutput
[platform/core/api/audio-io.git] / src / cpp / CAudioOutput.cpp
index 8a84f29..3f7b79a 100644 (file)
@@ -231,7 +231,19 @@ void CAudioOutput::drain() {
     if (mStreamCallback.onStream)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_OPERATION, "async type don't support drain");
 
-    CAudioIO::drain();
+    try {
+        if (mpPulseAudioClient->isInThread()) {
+            mpPulseAudioClient->drain();
+        } else {
+            internalLock();
+            mpPulseAudioClient->drain();
+            internalUnlock();
+        }
+    } catch (const CAudioError& e) {
+        if (!mpPulseAudioClient->isInThread())
+            internalUnlock();
+        throw;
+    }
 }
 
 void CAudioOutput::flush() {