use auto for constexpr whenever possible
[platform/core/api/audio-io.git] / src / cpp / CPulseAudioClient.cpp
index 2b598d7..5c434cf 100644 (file)
@@ -34,8 +34,8 @@ using namespace tizen_media_audio;
  * class CPulseAudioClient
  */
 const char* CPulseAudioClient::CLIENT_NAME = "AUDIO_IO_PA_CLIENT";
-static constexpr unsigned int drain_wait_interval = 10000;
-static constexpr unsigned int drain_wait_max_count = 30;
+static constexpr auto drain_wait_interval = 10000;
+static constexpr auto drain_wait_max_count = 30;
 
 CPulseAudioClient::CPulseAudioClient(
         EStreamDirection      direction,
@@ -282,6 +282,10 @@ 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) {
+    AUDIO_IO_LOGD("pa_context[%p], success[%d], user_data[%p]", c, success, user_data);
+}
+
 void CPulseAudioClient::initialize() {
     if (__mIsInit)
         return;
@@ -1006,3 +1010,33 @@ pa_usec_t CPulseAudioClient::getFinalLatency() {
     return ret;
 }
 //LCOV_EXCL_STOP
+
+void CPulseAudioClient::applyRecordVolume(double volume) {
+    if (!__mIsInit)
+        THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_INITIALIZED, "Did not initialize CPulseAudioClient");
+
+    checkRunningState();
+
+    if (__mDirection != EStreamDirection::STREAM_DIRECTION_RECORD)
+        THROW_ERROR_MSG(CAudioError::EError::ERROR_NOT_SUPPORTED, "The Playback client can't use this function"); //LCOV_EXCL_LINE
+
+    try {
+        if (!isInThread())
+            pa_threaded_mainloop_lock(__mpMainloop);
+
+        pa_cvolume cv = { 0, };
+        pa_volume_t v = PA_VOLUME_NORM * volume;
+
+        pa_cvolume_set(&cv, __mSpec.getChannelMap().channels, v);
+
+        pa_operation_unref(pa_context_set_source_output_volume(__mpContext,
+                pa_stream_get_index(__mpStream), &cv, __successVolumeCb, NULL));
+
+        if (!isInThread())
+            pa_threaded_mainloop_unlock(__mpMainloop);
+    } catch (const CAudioError& e) {
+        if (!isInThread())
+            pa_threaded_mainloop_unlock(__mpMainloop);
+        throw;
+    }
+}
\ No newline at end of file