CPulseAudioClient: Add null check for pa_operation 47/250047/3 accepted/tizen/unified/20201224.151525 submit/tizen/20201223.054528
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 18 Dec 2020 11:04:43 +0000 (20:04 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 22 Dec 2020 08:18:55 +0000 (17:18 +0900)
[Version] 0.5.39
[Issue Type] Error Handling

Change-Id: Id5b3acce73ccb3c04445d619c6f3d2c539d33a22

packaging/capi-media-audio-io.spec
src/cpp/CPulseAudioClient.cpp

index 6930ec3..f62cb95 100644 (file)
@@ -1,6 +1,6 @@
 Name:           capi-media-audio-io
 Summary:        An Audio Input & Audio Output library in Tizen Native API
-Version:        0.5.38
+Version:        0.5.39
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
index 92d2a79..105a293 100644 (file)
@@ -33,7 +33,7 @@ using namespace tizen_media_audio;
 /**
  * class CMainloopLocker
  */
-CPulseAudioClient::CPulseThreadLocker::CPulseThreadLocker(pa_threaded_mainloop *mainloop) : ml(nullptr) {
+CPulseAudioClient::CPulseThreadLocker::CPulseThreadLocker(pa_threaded_mainloopmainloop) : ml(nullptr) {
     if (!mainloop || pa_threaded_mainloop_in_thread(mainloop))
         return;
 
@@ -43,7 +43,7 @@ CPulseAudioClient::CPulseThreadLocker::CPulseThreadLocker(pa_threaded_mainloop *
 
 CPulseAudioClient::CPulseThreadLocker::~CPulseThreadLocker() {
     if (ml)
-        pa_threaded_mainloop_unlock(const_cast<pa_threaded_mainloop *>(ml));
+        pa_threaded_mainloop_unlock(const_cast<pa_threaded_mainloop*>(ml));
     ml = nullptr;
 }
 
@@ -276,7 +276,7 @@ void CPulseAudioClient::__streamUnderflowCb(pa_stream* s, void* user_data) {
 }
 
 //LCOV_EXCL_START
-void CPulseAudioClient::__streamEventCb(pa_stream* s, const char *name, pa_proplist *pl, void *user_data) {
+void CPulseAudioClient::__streamEventCb(pa_stream* s, const char* name, pa_proplist* pl, void* user_data) {
     assert(s);
     assert(user_data);
 
@@ -284,8 +284,14 @@ void CPulseAudioClient::__streamEventCb(pa_stream* s, const char *name, pa_propl
 
     AUDIO_IO_LOGW("pClient[%p] pa_stream[%p] : name[%s], proplist[%p]", pClient, s, name, pl);
 
-    if (strcmp(name, PA_STREAM_EVENT_POP_TIMEOUT) == 0)
-        pa_operation_unref(pa_stream_cork(pClient->__mpStream, 1, NULL, NULL));
+    if (strcmp(name, PA_STREAM_EVENT_POP_TIMEOUT) == 0) {
+        pa_operation* o = pa_stream_cork(pClient->__mpStream, 1, NULL, NULL);
+        if (!o) {
+            AUDIO_IO_LOGE("pa_stream[%p] : cork failed", pClient->__mpStream);
+            return;
+        }
+        pa_operation_unref(o);
+    }
 }
 //LCOV_EXCL_STOP
 
@@ -331,7 +337,7 @@ void CPulseAudioClient::__successDrainCb(pa_stream* s, int success, void* user_d
     pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
 }
 
-void CPulseAudioClient::__successVolumeCb(pa_context *c, int success, void *user_data) {
+void CPulseAudioClient::__successVolumeCb(pa_context* c, int success, void* user_data) {
     AUDIO_IO_LOGD("pa_context[%p], success[%d], user_data[%p]", c, success, user_data);
 }
 
@@ -726,16 +732,24 @@ int CPulseAudioClient::write(const void* data, size_t length) {
     if (!isInThread()) {
         CPulseThreadLocker locker{__mpMainloop};
         if (pa_stream_is_corked(__mpStream)) {
-            AUDIO_IO_LOGW("stream is corked...do uncork here first!!!!");
-            pa_operation_unref(pa_stream_cork(__mpStream, 0, NULL, this));
+            AUDIO_IO_LOGW("pa_stream[%p] is corked...do uncork here first!!!!", __mpStream);
+            pa_operation* o = pa_stream_cork(__mpStream, 0, NULL, NULL);
+            if (!o)
+                AUDIO_IO_LOGE("pa_stream[%p] : uncork failed", __mpStream);
+            else
+                pa_operation_unref(o);
         }
 
         ret = pa_stream_write(__mpStream, data, length, NULL, 0LL, PA_SEEK_RELATIVE);
     } else {
 // LCOV_EXCL_START
         if (pa_stream_is_corked(__mpStream)) {
-            AUDIO_IO_LOGW("stream is corked...do uncork here first!!!!");
-            pa_operation_unref(pa_stream_cork(__mpStream, 0, NULL, this));
+            AUDIO_IO_LOGW("pa_stream[%p] is corked...do uncork here first!!!!", __mpStream);
+            pa_operation* o = pa_stream_cork(__mpStream, 0, NULL, NULL);
+            if (!o)
+                AUDIO_IO_LOGE("pa_stream[%p] : uncork failed", __mpStream);
+            else
+                pa_operation_unref(o);
         }
 
         if (__mIsFirstStream) {
@@ -778,8 +792,12 @@ void CPulseAudioClient::cork(bool cork) {
     CPulseThreadLocker locker{__mpMainloop};
 
     /* FIXME: wait for completion like drain? */
-    pa_operation_unref(pa_stream_cork(__mpStream, static_cast<int>(cork), __successStreamCb, this));
-
+    pa_operation* o = pa_stream_cork(__mpStream, static_cast<int>(cork), __successStreamCb, this);
+    if (!o) {
+        AUDIO_IO_LOGE("pa_stream[%p] : cork[%d] failed", __mpStream, cork);
+        return;
+    }
+    pa_operation_unref(o);
     AUDIO_IO_LOGD("cork[%d] done", cork);
 }
 
@@ -833,7 +851,12 @@ bool CPulseAudioClient::drain() {
         AUDIO_IO_LOGD("drain done");
     } else {
         AUDIO_IO_LOGD("drain in thread");
-        pa_operation_unref(pa_stream_drain(__mpStream, __successDrainCbInThread, this));
+        pa_operation* o = pa_stream_drain(__mpStream, __successDrainCbInThread, this);
+        if (!o) {
+            AUDIO_IO_LOGE("pa_stream[%p] : drain failed", __mpStream);
+            return false;
+        }
+        pa_operation_unref(o);
         __mIsDraining = true;
     }
 
@@ -849,7 +872,12 @@ bool CPulseAudioClient::flush() {
     CPulseThreadLocker locker{__mpMainloop};
 
     /* FIXME: wait for completion like drain? */
-    pa_operation_unref(pa_stream_flush(__mpStream, __successStreamCb, this));
+    pa_operation* o = pa_stream_flush(__mpStream, __successStreamCb, this);
+    if (!o) {
+        AUDIO_IO_LOGE("pa_stream[%p] : flush failed", __mpStream);
+        return false;
+    }
+    pa_operation_unref(o);
 
     return true;
 }