Clean up and Add log into dependency audio manager 49/266849/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Fri, 19 Nov 2021 11:09:42 +0000 (20:09 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 19 Nov 2021 11:10:35 +0000 (20:10 +0900)
Change-Id: Ic19d1d18c9737e35985db7ff80ea4b0b5c1d026b
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
audio-manager/src/vc_audio_manager.cpp

index 79cf981..51c7a97 100644 (file)
@@ -109,25 +109,27 @@ static Eina_Bool __recorder_timer_func(void *data)
        const int FRAME_LENGTH = 160;
        const int BUFFER_LENGTH = FRAME_LENGTH * 2;
 
-       if (g_is_recording) {
-               unsigned char buffer[BUFFER_LENGTH];
-               memset(buffer, '\0', BUFFER_LENGTH);
+       if (!g_is_recording) {
+               VCAM_LOGD("[DEBUG] Recording is finished");
+               return ECORE_CALLBACK_DONE;
+       }
 
-               int read_bytes = audio_in_read(g_audio_h, buffer, BUFFER_LENGTH);
-               if (0 > read_bytes) {
-                       VCAM_LOGW("Fail to read audio : %d", read_bytes);
-                       return ECORE_CALLBACK_DONE;
-               }
+       unsigned char buffer[BUFFER_LENGTH];
+       memset(buffer, '\0', BUFFER_LENGTH);
 
-               // TODO: check return value?
-               if (nullptr != g_feed_audio_data) {
-                       g_feed_audio_data(buffer, read_bytes);
-               }
-       } else {
-               VCAM_LOGD("[DEBUG] Recording is finished");
+       int read_bytes = audio_in_read(g_audio_h, buffer, BUFFER_LENGTH);
+       if (0 > read_bytes) {
+               VCAM_LOGW("Fail to read audio : %d", read_bytes);
                return ECORE_CALLBACK_DONE;
        }
 
+       if (nullptr != g_feed_audio_data) {
+               int ret = g_feed_audio_data(buffer, read_bytes);
+               if (VCE_ERROR_NONE != ret) {
+                       VCAM_LOGW("[WARN] Fail to feed audio data (%d)", ret);
+               }
+       }
+
        return ECORE_CALLBACK_RENEW;
 }
 
@@ -168,6 +170,7 @@ int vcd_dependency_initialize(sound_stream_info_h stream_info_h, dependency_audi
        if (AUDIO_IO_ERROR_NONE != ret) {
                VCAM_LOGE("[ERROR] Fail to set stream info : %d", ret);
                audio_in_destroy(g_audio_h);
+               g_audio_h = nullptr;
                return VCE_ERROR_OPERATION_FAILED;
        }
 
@@ -207,7 +210,7 @@ int vcd_dependency_deinitialize(void)
        g_audio_rate = 0;
        g_audio_channel = 0;
 
-       return ret;
+       return VCE_ERROR_NONE;
 }
 
 int vcd_dependency_set_audio_info(sound_stream_info_h stream_info_h, const char* audio_source_type, vce_audio_type_e type, int rate, int channel)
@@ -287,6 +290,7 @@ int vcd_dependency_set_streaming_mode(vc_audio_streaming_mode_e mode)
                return VCE_ERROR_INVALID_STATE;
        }
 
+       VCAM_LOGI("[INFO] Set streaming mode (%d)", mode);
        g_streaming_mode = mode;
 
        return VCE_ERROR_NONE;
@@ -295,33 +299,32 @@ int vcd_dependency_set_streaming_mode(vc_audio_streaming_mode_e mode)
 int vcd_dependency_start_recording(void)
 {
        VCAM_LOGI("");
-       int ret = 0;
-
        if (nullptr == g_audio_h) {
                VCAM_LOGE("[ERROR] Audio in handle is not valid.");
                return VCE_ERROR_INVALID_STATE;
        }
 
-       ret = audio_in_prepare(g_audio_h);
+       int ret = audio_in_prepare(g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
                if (AUDIO_IO_ERROR_SOUND_POLICY == ret) {
                        VCAM_LOGE("[ERROR] Audio is busy.");
-               } else {
-                       VCAM_LOGE("[ERROR] Fail to start audio : %d", ret);
                }
 
-               return ret;
+               VCAM_LOGE("[ERROR] Fail to start audio : %d", ret);
+               return VCE_ERROR_OPERATION_FAILED;
        }
 
        g_is_recording = true;
 
        /* Add ecore timer to read audio data */
        ecore_main_loop_thread_safe_call_async([](void* data)->void
-                       {
-                               ecore_timer_add(0, __recorder_timer_func, NULL);
-                       }, NULL);
+               {
+                       ecore_timer_add(0, __recorder_timer_func, NULL);
+               },
+               NULL);
 
-       return ret;
+       VCAM_LOGI("");
+       return VCE_ERROR_NONE;
 }
 
 int vcd_dependency_stop_recording(void)
@@ -342,5 +345,6 @@ int vcd_dependency_stop_recording(void)
                return VCE_ERROR_OPERATION_FAILED;
        }
 
+       VCAM_LOGI("");
        return VCE_ERROR_NONE;
 }
\ No newline at end of file