Revise cpp codes
[platform/core/api/audio-io.git] / src / cpp / CPulseAudioClient.cpp
index 4423dda..0676cb8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
git st* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #include "CAudioIODef.h"
 #include <unistd.h>
 #include <inttypes.h>
+
 #ifdef ENABLE_DPM
 #include <dpm/restriction.h>
 #endif
@@ -40,13 +41,13 @@ CPulseAudioClient::CPulseAudioClient(
     __mDirection(direction),
     __mSpec(spec),
     __mpListener(listener),
-    __mpMainloop(NULL),
-    __mpContext(NULL),
-    __mpStream(NULL),
-    __mpPropList(NULL),
+    __mpMainloop(nullptr),
+    __mpContext(nullptr),
+    __mpStream(nullptr),
+    __mpPropList(nullptr),
     __mIsInit(false),
     __mIsOperationSuccess(false),
-    __mpSyncReadDataPtr(NULL),
+    __mpSyncReadDataPtr(nullptr),
     __mSyncReadIndex(0),
     __mSyncReadLength(0),
     __mIsUsedSyncRead(false),
@@ -60,7 +61,7 @@ CPulseAudioClient::~CPulseAudioClient() {
 }
 
 void CPulseAudioClient::__contextStateChangeCb(pa_context* c, void* user_data) {
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
     assert(pClient);
     assert(c);
 
@@ -85,21 +86,10 @@ void CPulseAudioClient::__contextStateChangeCb(pa_context* c, void* user_data) {
 }
 
 //LCOV_EXCL_START
-void CPulseAudioClient::__successContextCb(pa_context* c, int success, void* user_data) {
-    AUDIO_IO_LOGD("pa_context[%p], success[%d], user_data[%p]", c, success, user_data);
-    assert(c);
-    assert(user_data);
-
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
-    pClient->__mIsOperationSuccess = static_cast<bool>(success);
-
-    pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
-}
-
 static bool __is_microphone_restricted(void) {
     int state = 1;
 #ifdef ENABLE_DPM
-    device_policy_manager_h dpm_h = NULL;
+    device_policy_manager_h dpm_h = nullptr;
     int ret = 0;
 
     if ((dpm_h = dpm_manager_create())) {
@@ -120,7 +110,7 @@ void CPulseAudioClient::__streamStateChangeCb(pa_stream* s, void* user_data) {
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
 
     switch (pa_stream_get_state(s)) {
     case PA_STREAM_READY:
@@ -157,13 +147,12 @@ void CPulseAudioClient::__streamCaptureCb(pa_stream* s, size_t length, void* use
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
     assert(pClient->__mpListener);
     assert(pClient->__mpMainloop);
 
-    if (pClient->__mIsUsedSyncRead == true) {
+    if (pClient->__mIsUsedSyncRead)
         pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
-    }
 
     pClient->__mpListener->onStream(pClient, length);
 }
@@ -181,11 +170,11 @@ void CPulseAudioClient::__streamPlaybackCb(pa_stream* s, size_t length, void* us
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
     assert(pClient->__mpListener);
 
 #ifndef DISABLE_MOBILE_BACK_COMP
-    if (pClient->__mIsInit == false) {
+    if (!pClient->__mIsInit) {
         AUDIO_IO_LOGD("Occurred this listener when an out stream is on the way to create : Write dummy, length[%zu]", length);
         __dummy_write(s, length);
         return;
@@ -215,7 +204,7 @@ void CPulseAudioClient::__streamLatencyUpdateCb(pa_stream* s, void* user_data) {
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
 
     pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
 }
@@ -224,7 +213,7 @@ void CPulseAudioClient::__streamStartedCb(pa_stream* s, void* user_data) {
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
 
     AUDIO_IO_LOGD("stream %p started.", pClient);
 
@@ -235,7 +224,7 @@ void CPulseAudioClient::__streamUnderflowCb(pa_stream* s, void* user_data) {
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
 
     AUDIO_IO_LOGD("stream %p UnderFlow...", pClient);
 
@@ -249,10 +238,9 @@ void CPulseAudioClient::__streamEventCb(pa_stream* s, const char *name, pa_propl
 
     AUDIO_IO_LOGE("NAME : %s, Prop : %p", name, pl);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
-    if (strcmp(name, PA_STREAM_EVENT_POP_TIMEOUT) == 0) {
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
+    if (strcmp(name, PA_STREAM_EVENT_POP_TIMEOUT) == 0)
         pa_operation_unref(pa_stream_cork(pClient->__mpStream, 1, NULL, NULL));
-    }
 }
 //LCOV_EXCL_STOP
 
@@ -261,7 +249,7 @@ void CPulseAudioClient::__successStreamCb(pa_stream* s, int success, void* user_
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
     pClient->__mIsOperationSuccess = static_cast<bool>(success);
 
     pa_threaded_mainloop_signal(pClient->__mpMainloop, 0);
@@ -273,7 +261,7 @@ void CPulseAudioClient::__successDrainCbInThread(pa_stream* s, int success, void
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
     pClient->__mIsOperationSuccess = static_cast<bool>(success);
     pClient->__mIsDraining = false;
 }
@@ -284,7 +272,7 @@ void CPulseAudioClient::__successDrainCb(pa_stream* s, int success, void* user_d
     assert(s);
     assert(user_data);
 
-    CPulseAudioClient* pClient = static_cast<CPulseAudioClient*>(user_data);
+    auto pClient = static_cast<CPulseAudioClient*>(user_data);
     pClient->__mIsOperationSuccess = static_cast<bool>(success);
     pClient->__mIsDraining = false;
 
@@ -292,9 +280,8 @@ void CPulseAudioClient::__successDrainCb(pa_stream* s, int success, void* user_d
 }
 
 void CPulseAudioClient::initialize() {
-    if (__mIsInit == true) {
+    if (__mIsInit)
         return;
-    }
 
     int ret = 0;
     int err = 0;
@@ -302,20 +289,18 @@ void CPulseAudioClient::initialize() {
     try {
         // Allocates PA proplist
         __mpPropList = pa_proplist_new();
-        if (__mpPropList == NULL) {
+        if (!__mpPropList)
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_proplist_new()"); //LCOV_EXCL_LINE
-        }
 
         // Adds values on proplist for delivery to PULSEAUDIO
-        char *streamType = NULL;
+        char *streamType = nullptr;
         CAudioInfo::EAudioType audioType = __mSpec.getAudioInfo().getAudioType();
         __mSpec.getAudioInfo().convertAudioType2StreamType(audioType, &streamType);
         pa_proplist_sets(__mpPropList, PA_PROP_MEDIA_ROLE, streamType);
 
         int index = __mSpec.getAudioInfo().getAudioIndex();
-        if (index >= 0) {
+        if (index >= 0)
             pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_PARENT_ID, "%u", (unsigned int) index);
-        }
 
         // Adds latency on proplist for delivery to PULSEAUDIO
         AUDIO_IO_LOGD("LATENCY : %s[%d]", __mSpec.getStreamLatencyToString(), static_cast<int>(__mSpec.getStreamLatency()));
@@ -323,23 +308,20 @@ void CPulseAudioClient::initialize() {
 
         // Allocates PA mainloop
         __mpMainloop = pa_threaded_mainloop_new();
-        if (__mpMainloop == NULL) {
+        if (!__mpMainloop)
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_threaded_mainloop_new()"); //LCOV_EXCL_LINE
-        }
 
         // Allocates PA context
         __mpContext = pa_context_new(pa_threaded_mainloop_get_api(__mpMainloop), CLIENT_NAME);
-        if (__mpContext == NULL) {
+        if (!__mpContext)
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_new()"); //LCOV_EXCL_LINE
-        }
 
         // Sets context state changed callback
         pa_context_set_state_callback(__mpContext, __contextStateChangeCb, this);
 
         // Connects this client with PA server
-        if (pa_context_connect(__mpContext, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0) {
+        if (pa_context_connect(__mpContext, NULL, PA_CONTEXT_NOFLAGS, NULL) < 0)
             THROW_ERROR_MSG(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed pa_context_connect()"); //LCOV_EXCL_LINE
-        }
 
         // LOCK for synchronous connection
         pa_threaded_mainloop_lock(__mpMainloop);
@@ -357,9 +339,8 @@ void CPulseAudioClient::initialize() {
             pa_context_state_t state;
             state = pa_context_get_state(__mpContext);
 
-            if (state == PA_CONTEXT_READY) {
+            if (state == PA_CONTEXT_READY)
                 break;
-            }
 
             if (!PA_CONTEXT_IS_GOOD(state)) {
 //LCOV_EXCL_START
@@ -378,7 +359,7 @@ void CPulseAudioClient::initialize() {
         pa_channel_map map  = __mSpec.getChannelMap();
 
         __mpStream = pa_stream_new_with_proplist(__mpContext, __mSpec.getStreamName(), &ss, &map, __mpPropList);
-        if (__mpStream == NULL) {
+        if (!__mpStream) {
 //LCOV_EXCL_START
             pa_threaded_mainloop_unlock(__mpMainloop);
             THROW_ERROR_MSG(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_new_with_proplist()");
@@ -399,7 +380,7 @@ void CPulseAudioClient::initialize() {
         // Connect stream with PA Server
 
         if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
-            pa_stream_flags_t flags = static_cast<pa_stream_flags_t>(
+            auto flags = static_cast<pa_stream_flags_t>(
                     PA_STREAM_INTERPOLATE_TIMING |
                     PA_STREAM_ADJUST_LATENCY     |
 #ifndef DISABLE_MOBILE_BACK_COMP
@@ -409,7 +390,7 @@ void CPulseAudioClient::initialize() {
 
             ret = pa_stream_connect_playback(__mpStream, NULL, NULL, flags, NULL, NULL);
         } else {
-            pa_stream_flags_t flags = static_cast<pa_stream_flags_t>(
+            auto flags = static_cast<pa_stream_flags_t>(
                     PA_STREAM_INTERPOLATE_TIMING |
                     PA_STREAM_ADJUST_LATENCY     |
 #ifndef DISABLE_MOBILE_BACK_COMP
@@ -429,8 +410,7 @@ void CPulseAudioClient::initialize() {
         }
 
         while (true) {
-            pa_stream_state_t state;
-            state = pa_stream_get_state(__mpStream);
+            pa_stream_state_t state = pa_stream_get_state(__mpStream);
 
             if (state == PA_STREAM_READY) {
                 AUDIO_IO_LOGD("STREAM READY");
@@ -440,11 +420,10 @@ void CPulseAudioClient::initialize() {
             if (!PA_STREAM_IS_GOOD(state)) {
                 err = pa_context_errno(__mpContext);
                 pa_threaded_mainloop_unlock(__mpMainloop);
-                if (err == PA_ERR_ACCESS) {
+                if (err == PA_ERR_ACCESS)
                     THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_DEVICE_POLICY_RESTRICTION, "pa_stream's state is not good : err[%d]", err);
-                } else {
+                else
                     THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "pa_stream's state is not good : err[%d]", err); //LCOV_EXCL_LINE
-                }
             }
 
             /* Wait until the stream is ready */
@@ -464,7 +443,7 @@ void CPulseAudioClient::initialize() {
 void CPulseAudioClient::finalize() {
     AUDIO_IO_LOGD("");
 
-    if (__mpMainloop && isInThread() == false)
+    if (__mpMainloop && !isInThread())
         pa_threaded_mainloop_lock(__mpMainloop);
 
     /* clear callbacks */
@@ -477,62 +456,57 @@ void CPulseAudioClient::finalize() {
         pa_stream_set_event_callback(__mpStream, NULL, NULL);
     }
 
-    if (__mpMainloop && isInThread() == false)
+    if (__mpMainloop && !isInThread())
         pa_threaded_mainloop_unlock(__mpMainloop);
 
     /* Wait for drain complete if draining before finalize */
     if (__mIsDraining) {
         unsigned int drain_wait_count = 0;
-        while (__mIsDraining && drain_wait_count++ < drain_wait_max_count) {
+        while (__mIsDraining && drain_wait_count++ < drain_wait_max_count)
             usleep(drain_wait_interval);
-        }
         AUDIO_IO_LOGD("wait for drain complete!!!! [%d * %d usec]",
                       drain_wait_count, drain_wait_interval);
     }
 
-    if (__mpMainloop != NULL) {
+    if (__mpMainloop)
         pa_threaded_mainloop_stop(__mpMainloop);
-    }
 
-    if (__mpStream != NULL) {
+    if (__mpStream) {
         pa_stream_disconnect(__mpStream);
         pa_stream_unref(__mpStream);
-        __mpStream = NULL;
+        __mpStream = nullptr;
     }
 
-    if (__mpContext != NULL) {
+    if (__mpContext) {
         pa_context_disconnect(__mpContext);
         pa_context_unref(__mpContext);
-        __mpContext = NULL;
+        __mpContext = nullptr;
     }
 
-    if (__mpMainloop != NULL) {
+    if (__mpMainloop) {
         pa_threaded_mainloop_free(__mpMainloop);
-        __mpMainloop = NULL;
+        __mpMainloop = nullptr;
     }
 
-    if (__mpPropList != NULL) {
+    if (__mpPropList) {
         pa_proplist_free(__mpPropList);
-        __mpPropList = NULL;
+        __mpPropList = nullptr;
     }
 
     __mIsInit = false;
 }
 
 int CPulseAudioClient::read(void* buffer, size_t length) {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
-    if (buffer == NULL) {
+    if (!buffer)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The parameter is invalid : buffer[%p]", buffer);
-    }
 
-    if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+    if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
-    }
 
     size_t lengthIter = length;
     int ret = 0;
@@ -545,33 +519,30 @@ int CPulseAudioClient::read(void* buffer, size_t length) {
         while (lengthIter > 0) {
             size_t l;
 
-            while (__mpSyncReadDataPtr == NULL) {
+            while (!__mpSyncReadDataPtr) {
                 ret = pa_stream_peek(__mpStream, &__mpSyncReadDataPtr, &__mSyncReadLength);
-                if (ret != 0) {
+                if (ret != 0)
                     THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pa_stream_peek() : ret[%d]", ret);
-                }
 
                 if (__mSyncReadLength <= 0) {
 #ifdef _AUDIO_IO_DEBUG_TIMING_
                     AUDIO_IO_LOGD("readLength(%zu byte) is not valid. wait...", __mSyncReadLength);
 #endif
                     pa_threaded_mainloop_wait(__mpMainloop);
-                } else if (__mpSyncReadDataPtr == NULL) {
+                } else if (!__mpSyncReadDataPtr) {
                     // Data peeked, but it doesn't have any data
                     ret = pa_stream_drop(__mpStream);
-                    if (ret != 0) {
+                    if (ret != 0)
                         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pa_stream_drop() : ret[%d]", ret); //LCOV_EXCL_LINE
-                    }
                 } else {
                     __mSyncReadIndex = 0;
                 }
             }
 
-            if (__mSyncReadLength < lengthIter) {
+            if (__mSyncReadLength < lengthIter)
                 l = __mSyncReadLength;
-            } else {
+            else
                 l = lengthIter;
-            }
 
             // Copy partial pcm data on out parameter
 #ifdef _AUDIO_IO_DEBUG_TIMING_
@@ -592,12 +563,11 @@ int CPulseAudioClient::read(void* buffer, size_t length) {
                 AUDIO_IO_LOGD("__mSyncReadLength is zero, do drop()");
 #endif
                 ret = pa_stream_drop(__mpStream);
-                if (ret != 0) {
+                if (ret != 0)
                     THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INTERNAL_OPERATION, "Failed pa_stream_drop() : ret[%d]", ret); //LCOV_EXCL_LINE
-                }
 
                 // Reset the internal pointer
-                __mpSyncReadDataPtr = NULL;
+                __mpSyncReadDataPtr = nullptr;
                 __mSyncReadLength   = 0;
                 __mSyncReadIndex    = 0;
             }
@@ -615,23 +585,20 @@ int CPulseAudioClient::read(void* buffer, size_t length) {
 }
 
 int CPulseAudioClient::peek(const void** buffer, size_t* length) {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
-    if (buffer == NULL || length == NULL) {
+    if (!buffer || !length)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The parameter is invalid : buffer[%p], length[%p]", buffer, length);
-    }
 
-    if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+    if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
-    }
 
     int ret = 0;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
         ret = pa_stream_peek(__mpStream, buffer, length);
         pa_threaded_mainloop_unlock(__mpMainloop);
@@ -643,17 +610,15 @@ int CPulseAudioClient::peek(const void** buffer, size_t* length) {
     AUDIO_IO_LOGD("buffer[%p], length[%zu]", *buffer, *length);
 #endif
 
-    if (ret < 0) {
+    if (ret < 0)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_peek() : err[%d]", ret); //LCOV_EXCL_LINE
-    }
 
     return ret;
 }
 
 int CPulseAudioClient::drop() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
 #ifdef _AUDIO_IO_DEBUG_TIMING_
     AUDIO_IO_LOGD("");
@@ -661,13 +626,12 @@ int CPulseAudioClient::drop() {
 
     checkRunningState();
 
-    if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+    if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
-    }
 
     int ret = 0;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
         ret = pa_stream_drop(__mpStream);
         pa_threaded_mainloop_unlock(__mpMainloop);
@@ -675,21 +639,18 @@ int CPulseAudioClient::drop() {
         ret = pa_stream_drop(__mpStream);
     }
 
-    if (ret < 0) {
+    if (ret < 0)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_drop() : err[%d]", ret); //LCOV_EXCL_LINE
-    }
 
     return ret;
 }
 
 int CPulseAudioClient::write(const void* data, size_t length) {
-    if (data == NULL) {
+    if (!data)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_INVALID_ARGUMENT, "The parameter is invalid");
-    }
 
-    if (__mDirection == EStreamDirection::STREAM_DIRECTION_RECORD) {
+    if (__mDirection == EStreamDirection::STREAM_DIRECTION_RECORD)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client couldn't use this function");
-    }
 
     int ret = 0;
 
@@ -697,7 +658,7 @@ int CPulseAudioClient::write(const void* data, size_t length) {
     AUDIO_IO_LOGD("data[%p], length[%zu], First[%d]", data, length, __mIsFirstStream);
 #endif
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
         if (pa_stream_is_corked(__mpStream)) {
             AUDIO_IO_LOGW("stream is corked...do uncork here first!!!!");
@@ -730,9 +691,8 @@ int CPulseAudioClient::write(const void* data, size_t length) {
         ret = pa_stream_write(__mpStream, data, length, NULL, 0LL, PA_SEEK_RELATIVE);
     }
 
-    if (ret < 0) {
+    if (ret < 0)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_write() : err[%d]", ret); //LCOV_EXCL_LINE
-    }
 
     return ret;
 }
@@ -740,41 +700,36 @@ int CPulseAudioClient::write(const void* data, size_t length) {
 void CPulseAudioClient::cork(bool cork) {
     AUDIO_IO_LOGD("cork[%d]", cork);
 
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
-    if (isInThread() == true) {
+    if (isInThread())
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "This operation is not supported in callback");
-    }
 
     checkRunningState();
 
     // Set __mIsFirstStream flag when uncork(resume) stream, because prebuf will be enable again
-    if (cork == false)
+    if (!cork)
         __mIsFirstStream = true;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
         pa_operation_unref(pa_stream_cork(__mpStream, static_cast<int>(cork), __successStreamCb, this));
         pa_threaded_mainloop_unlock(__mpMainloop);
     } else {
         pa_operation_unref(pa_stream_cork(__mpStream, static_cast<int>(cork), __successStreamCb, this));
     }
-
-    return;
 }
 
 bool CPulseAudioClient::isCorked() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
     int isCork = 0;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
         isCork = pa_stream_is_corked(__mpStream);
         pa_threaded_mainloop_unlock(__mpMainloop);
@@ -789,9 +744,8 @@ bool CPulseAudioClient::isCorked() {
 }
 
 bool CPulseAudioClient::drain() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
@@ -810,14 +764,14 @@ bool CPulseAudioClient::drain() {
         return true;
     }
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         AUDIO_IO_LOGD("drain");
         pa_threaded_mainloop_lock(__mpMainloop);
         pa_operation* o = pa_stream_drain(__mpStream, __successDrainCb, this);
         __mIsDraining = true;
-        while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
+        while (pa_operation_get_state(o) == PA_OPERATION_RUNNING)
             pa_threaded_mainloop_wait(__mpMainloop);
-        }
+
         pa_operation_unref(o);
         pa_threaded_mainloop_unlock(__mpMainloop);
         AUDIO_IO_LOGD("drain done");
@@ -831,13 +785,12 @@ bool CPulseAudioClient::drain() {
 }
 
 bool CPulseAudioClient::flush() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         AUDIO_IO_LOGD("flush");
         pa_threaded_mainloop_lock(__mpMainloop);
         pa_operation_unref(pa_stream_flush(__mpStream, __successStreamCb, this));
@@ -851,19 +804,17 @@ bool CPulseAudioClient::flush() {
 }
 
 size_t CPulseAudioClient::getWritableSize() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
-    if (__mDirection != EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
+    if (__mDirection != EStreamDirection::STREAM_DIRECTION_PLAYBACK)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "This client is used for Playback");
-    }
 
     size_t ret = 0;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
         ret = pa_stream_writable_size(__mpStream);
         pa_threaded_mainloop_unlock(__mpMainloop);
@@ -875,22 +826,21 @@ size_t CPulseAudioClient::getWritableSize() {
 }
 
 void CPulseAudioClient::checkRunningState() {
-    if (__mpContext == NULL || PA_CONTEXT_IS_GOOD(pa_context_get_state(__mpContext)) == 0) {
+    if (!__mpContext || !PA_CONTEXT_IS_GOOD(pa_context_get_state(__mpContext)))
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_INITIALIZED, "The context[%p] is not created or not good state", __mpContext);
-    }
-    if (__mpStream == NULL || PA_STREAM_IS_GOOD(pa_stream_get_state(__mpStream)) == 0) {
+
+    if (!__mpStream || !PA_STREAM_IS_GOOD(pa_stream_get_state(__mpStream)))
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_INITIALIZED, "The stream[%p] is not created or not good state", __mpStream);
-    }
-    if (pa_context_get_state(__mpContext) != PA_CONTEXT_READY || pa_stream_get_state(__mpStream) != PA_STREAM_READY) {
+
+    if (pa_context_get_state(__mpContext) != PA_CONTEXT_READY || pa_stream_get_state(__mpStream) != PA_STREAM_READY)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_INITIALIZED, "The context[%p] or stream[%p] state is not ready", __mpContext, __mpStream);
-    }
 
 #ifdef _AUDIO_IO_DEBUG_TIMING_
     AUDIO_IO_LOGD("This client is running");
 #endif
 }
 
-bool CPulseAudioClient::isInThread() {
+bool CPulseAudioClient::isInThread() noexcept {
     int ret = pa_threaded_mainloop_in_thread(__mpMainloop);
 
 #ifdef _AUDIO_IO_DEBUG_TIMING_
@@ -901,21 +851,19 @@ bool CPulseAudioClient::isInThread() {
 
 //LCOV_EXCL_START
 size_t CPulseAudioClient::getReadableSize() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
-    if (__mDirection != EStreamDirection::STREAM_DIRECTION_RECORD) {
+    if (__mDirection != EStreamDirection::STREAM_DIRECTION_RECORD)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "This client is used for Capture");
-    }
 
     size_t ret = 0;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         pa_threaded_mainloop_lock(__mpMainloop);
-        ret = pa_stream_writable_size(__mpStream);
+        ret = pa_stream_readable_size(__mpStream);
         pa_threaded_mainloop_unlock(__mpMainloop);
     } else {
         ret = pa_stream_writable_size(__mpStream);
@@ -925,21 +873,19 @@ size_t CPulseAudioClient::getReadableSize() {
 }
 
 size_t CPulseAudioClient::getBufferSize() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
     size_t ret = 0;
 
     try {
-        if (isInThread() == false) {
+        if (!isInThread())
             pa_threaded_mainloop_lock(__mpMainloop);
-        }
 
         const pa_buffer_attr* attr = pa_stream_get_buffer_attr(__mpStream);
-        if (attr == NULL) {
+        if (!attr) {
             int _err = pa_context_errno(__mpContext);
             THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_get_buffer_attr() : err[%d]", _err);
         }
@@ -952,35 +898,31 @@ size_t CPulseAudioClient::getBufferSize() {
             AUDIO_IO_LOGD("RECORD buffer size[%zu]", ret);
         }
     } catch (CAudioError& e) {
-        if (isInThread() == false) {
+        if (!isInThread())
             pa_threaded_mainloop_unlock(__mpMainloop);
-        }
         throw;
     }
 
-    if (isInThread() == false) {
+    if (!isInThread())
         pa_threaded_mainloop_unlock(__mpMainloop);
-    }
 
     return ret;
 }
 
 pa_usec_t CPulseAudioClient::getLatency() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
     pa_usec_t ret = 0;
     int negative  = 0;
 
-    if (isInThread() == false) {
+    if (!isInThread()) {
         if (pa_stream_get_latency(__mpStream, &ret, &negative) < 0) {
             int _err = pa_context_errno(__mpContext);
-            if (_err != PA_ERR_NODATA) {
+            if (_err != PA_ERR_NODATA)
                 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_get_latency() : err[%d]", _err);
-            }
         }
         return negative ? 0 : ret;
     }
@@ -989,14 +931,12 @@ pa_usec_t CPulseAudioClient::getLatency() {
 
     try {
         while (true) {
-            if (pa_stream_get_latency(__mpStream, &ret, &negative) >= 0) {
+            if (pa_stream_get_latency(__mpStream, &ret, &negative) >= 0)
                 break;
-            }
 
             int _err = pa_context_errno(__mpContext);
-            if (_err != PA_ERR_NODATA) {
+            if (_err != PA_ERR_NODATA)
                 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_FAILED_OPERATION, "Failed pa_stream_get_latency() : err[%d]", _err);
-            }
 
             /* Wait until latency data is available again */
             pa_threaded_mainloop_wait(__mpMainloop);
@@ -1012,30 +952,26 @@ pa_usec_t CPulseAudioClient::getLatency() {
 }
 
 pa_usec_t CPulseAudioClient::getFinalLatency() {
-    if (__mIsInit == false) {
+    if (!__mIsInit)
         THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
-    }
 
     checkRunningState();
 
     pa_usec_t ret = 0;
-    uint32_t  ver = 0;
 
     try {
-        if (isInThread() == false) {
+        if (!isInThread())
             pa_threaded_mainloop_lock(__mpMainloop);
-        }
 
-        ver = pa_context_get_server_protocol_version(__mpContext);
+        uint32_t ver = pa_context_get_server_protocol_version(__mpContext);
         if (ver >= 13) {
             const pa_buffer_attr* buffer_attr = pa_stream_get_buffer_attr(__mpStream);
             const pa_sample_spec* sample_spec = pa_stream_get_sample_spec(__mpStream);
             const pa_timing_info* timing_info = pa_stream_get_timing_info(__mpStream);
 
-            if (buffer_attr == NULL || sample_spec == NULL || timing_info == NULL) {
+            if (!buffer_attr || !sample_spec || !timing_info)
                 THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_OUT_OF_MEMORY, "Failed to get buffer_attr[%p] or sample_spec[%p] or timing_info[%p] from a pa_stream",
                         buffer_attr, sample_spec, timing_info);
-            }
 
             if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK) {
                 ret = (pa_bytes_to_usec(buffer_attr->tlength, sample_spec) + timing_info->configured_sink_usec);
@@ -1048,24 +984,14 @@ pa_usec_t CPulseAudioClient::getFinalLatency() {
             THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED, "This version(ver.%d) is not supported", ver);
         }
 
-        if (isInThread() == false) {
+        if (!isInThread())
             pa_threaded_mainloop_unlock(__mpMainloop);
-        }
     } catch (CAudioError& e) {
-        if (isInThread() == false) {
+        if (!isInThread())
             pa_threaded_mainloop_unlock(__mpMainloop);
-        }
         throw;
     }
 
     return ret;
 }
-
-CPulseAudioClient::EStreamDirection CPulseAudioClient::getStreamDirection() {
-    return __mDirection;
-}
-
-CPulseStreamSpec CPulseAudioClient::getStreamSpec() {
-    return __mSpec;
-}
 //LCOV_EXCL_STOP