Remove audio type dependency from vcd_recorder 12/238212/9
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 9 Jul 2020 05:11:31 +0000 (14:11 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 8 Jun 2021 08:05:46 +0000 (17:05 +0900)
Change-Id: I2942e9fc0eee43027284b4d3d5c6a040f94be2fd
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
audio-manager/inc/vc_audio_manager.h
audio-manager/src/vc_audio_manager.cpp
server/dependency_audio_manager.cpp
server/dependency_audio_manager.h
server/vcd_recorder.c

index 16230dd5d1b78d2a9478e19391affe0c99787080..59354e24dc1fa1b3eff84d9c3fcbc809618cab54 100644 (file)
@@ -29,6 +29,7 @@ typedef int (*dependency_audio_manager_feed_audio_data)(const void* data, const
 int vcd_dependency_initialize(sound_stream_info_h stream_info_h, dependency_audio_manager_feed_audio_data callback);
 int vcd_dependency_deinitialize(void);
 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);
+int vcd_dependency_get_audio_source_type(char** audio_source_type);
 int vcd_dependency_start_recording(void);
 int vcd_dependency_stop_recording(void);
 
index e676d2b92cfbe17bc4b442b2b54928ac82ed1aa9..32631f3657217008c1ca6a5b8684503439ba9939 100644 (file)
@@ -40,7 +40,6 @@ static audio_in_h g_audio_h = nullptr;
 static vce_audio_type_e g_audio_type = VCE_AUDIO_TYPE_PCM_S16_LE;
 static int g_audio_rate = 0;
 static int g_audio_channel = 0;
-static char* g_audio_source_type = nullptr;
 
 volatile static bool g_is_recording = false;
 
@@ -148,7 +147,6 @@ int vcd_dependency_initialize(sound_stream_info_h stream_info_h, dependency_audi
                return VCE_ERROR_OPERATION_FAILED;
        }
 
-       g_audio_source_type = strdup(VCE_AUDIO_ID_NONE);
        g_feed_audio_data = callback;
        g_is_recording = false;
 
@@ -189,19 +187,23 @@ int vcd_dependency_set_audio_info(sound_stream_info_h stream_info_h, const char*
                return VCE_ERROR_INVALID_PARAMETER;
        }
 
-       if (nullptr == g_audio_h || nullptr == g_audio_source_type) {
+       if (nullptr == g_audio_h) {
                VCAM_LOGE("[ERROR] Audio in handle is not valid.");
                return VCE_ERROR_INVALID_STATE;
        }
 
-       if (0 == strncmp(g_audio_source_type, audio_source_type, strlen(g_audio_source_type)) ||
-                       (g_audio_type == type && g_audio_rate == rate && g_audio_channel == channel)) {
+       if (g_audio_type == type && g_audio_rate == rate && g_audio_channel == channel) {
                VCAM_LOGI("No changed information");
                return VCE_ERROR_NONE;
        }
 
-       VCAM_LOGI("New audio type(%d) rate(%d) channel(%d)", type, rate, channel);
-       audio_in_destroy(g_audio_h);
+       VCAM_LOGI("New audio type(%d), rate(%d), channel(%d)", type, rate, channel);
+
+       int ret = audio_in_destroy(g_audio_h);
+       if (0 != ret) {
+               VCAM_LOGE("[ERROR] Fail to audio in destroy. [ret(%d)]", ret);
+               return VCE_ERROR_OPERATION_FAILED;
+       }
 
        audio_channel_e audio_ch = AUDIO_CHANNEL_MONO;
        audio_sample_type_e audio_sample_type = AUDIO_SAMPLE_TYPE_U8;
@@ -214,11 +216,10 @@ int vcd_dependency_set_audio_info(sound_stream_info_h stream_info_h, const char*
                return VCE_ERROR_INVALID_PARAMETER;
        }
 
-       int ret = 0;
        ret = audio_in_create(rate, audio_ch, audio_sample_type, &g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
                VCAM_LOGE("[ERROR] Fail to create audio handle. [ret(%d)]", ret);
-               return ret;
+               return VCE_ERROR_OPERATION_FAILED;
        }
 
        if (0 != audio_in_set_sound_stream_info(g_audio_h, stream_info_h)) {
@@ -230,9 +231,22 @@ int vcd_dependency_set_audio_info(sound_stream_info_h stream_info_h, const char*
        g_audio_channel = channel;
 
        VCAM_LOGI("");
-       return ret;
+       return VCE_ERROR_NONE;
+}
+
+int vcd_dependency_get_audio_source_type(char** audio_source_type)
+{
+       if (nullptr == audio_source_type) {
+               VCAM_LOGE("audio_source_type is null");
+               return VCE_ERROR_INVALID_PARAMETER;
+       }
+
+       *audio_source_type = strdup(VCE_AUDIO_ID_NONE);
+
+       return VCE_ERROR_NONE;
 }
 
+
 int vcd_dependency_start_recording(void)
 {
        VCAM_LOGI("");
@@ -272,7 +286,6 @@ int vcd_dependency_stop_recording(void)
 
        if (nullptr == g_audio_h) {
                VCAM_LOGE("[ERROR] Audio in handle is not valid.");
-
                return VCE_ERROR_INVALID_STATE;
        }
 
@@ -281,7 +294,8 @@ int vcd_dependency_stop_recording(void)
        ret = audio_in_unprepare(g_audio_h);
        if (AUDIO_IO_ERROR_NONE != ret) {
                VCAM_LOGE("[ERROR] Fail to stop audio : %d", ret);
+               return VCE_ERROR_OPERATION_FAILED;
        }
 
-       return ret;
+       return VCE_ERROR_NONE;
 }
\ No newline at end of file
index b604995382c7f344a20a7ce72165c693a43a1489..762a813cdf455ef68823b54f199208c2eaf94cad 100644 (file)
@@ -65,6 +65,8 @@ int dependency_audio_manager_initialize(sound_stream_info_h stream_info_h, depen
                (vcd_dependency_deinitialize)dlsym(g_lib_handle, VCD_DEPENDENCY_FUNC_DEINITIALIZE);
        g_interface.set_audio_info =
                (vcd_dependency_set_audio_info)dlsym(g_lib_handle, VCD_DEPENDENCY_FUNC_SET_AUDIO_INFO);
+       g_interface.get_audio_source_type =
+               (vcd_dependency_get_audio_source_type)dlsym(g_lib_handle, VCD_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
        g_interface.start_recording =
                (vcd_dependency_start_recording)dlsym(g_lib_handle, VCD_DEPENDENCY_FUNC_START_RECORDING);
        g_interface.stop_recording =
@@ -157,7 +159,36 @@ int dependency_audio_manager_set_audio_info(sound_stream_info_h stream_info_h, c
        return ret;
 }
 
-int dependency_audio_manager_start_recording()
+int dependency_audio_manager_get_audio_source_type(char** audio_source_type)
+{
+       SLOG(LOG_DEBUG, LOG_TAG, "@@@ Get audio source type");
+       int ret = 0;
+       if (NULL != g_lib_handle) {
+               vcd_dependency_get_audio_source_type func = g_interface.get_audio_source_type;
+
+               if (NULL == func) {
+                       SLOG(LOG_ERROR, LOG_TAG, "[ERROR] symbol lookup failed : %s", VCD_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
+               } else {
+                       try {
+                               ret = func(audio_source_type);
+                       } catch (const std::exception& e) {
+                               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] %s of dependency module threw exception : %s",
+                                       VCD_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE, e.what());
+                       }
+
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] Fail to initialize, ret(%d)", ret);
+                       }
+               }
+       } else {
+               SLOG(LOG_ERROR, LOG_TAG, "[ERROR] g_lib_handle is not valid");
+       }
+
+       SLOG(LOG_DEBUG, LOG_TAG, "@@@");
+       return ret;
+}
+
+int dependency_audio_manager_start_recording(void)
 {
        SLOG(LOG_DEBUG, LOG_TAG, "@@@ Start recording");
        int ret = 0;
index caa0445875d4cc7a19279558e9f6172938b0f564..5f5ce7b58d4a26385b026284dd1fc27f9e289dd9 100644 (file)
@@ -43,6 +43,8 @@ typedef int (*vcd_dependency_initialize)(sound_stream_info_h stream_info_h, depe
 typedef int (*vcd_dependency_deinitialize)(void);
 #define VCD_DEPENDENCY_FUNC_SET_AUDIO_INFO "vcd_dependency_set_audio_info"
 typedef 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);
+#define VCD_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE "vcd_dependency_get_audio_source_type"
+typedef int (*vcd_dependency_get_audio_source_type)(char** audio_source_type);
 #define VCD_DEPENDENCY_FUNC_START_RECORDING "vcd_dependency_start_recording"
 typedef int (*vcd_dependency_start_recording)(void);
 #define VCD_DEPENDENCY_FUNC_STOP_RECORDING "vcd_dependency_stop_recording"
@@ -50,17 +52,19 @@ typedef int (*vcd_dependency_stop_recording)(void);
 
 
 typedef struct {
-       vcd_dependency_initialize               initialize;
-       vcd_dependency_deinitialize             deinitialize;
-       vcd_dependency_set_audio_info   set_audio_info;
-       vcd_dependency_start_recording  start_recording;
-       vcd_dependency_stop_recording   stop_recording;
+       vcd_dependency_initialize                               initialize;
+       vcd_dependency_deinitialize                             deinitialize;
+       vcd_dependency_set_audio_info                   set_audio_info;
+       vcd_dependency_get_audio_source_type    get_audio_source_type;
+       vcd_dependency_start_recording                  start_recording;
+       vcd_dependency_stop_recording                   stop_recording;
 } vcd_dependency_module_interface;
 
 
 int dependency_audio_manager_initialize(sound_stream_info_h stream_info_h, dependency_audio_manager_feed_audio_data callback);
 int dependency_audio_manager_deinitialize(void);
 int dependency_audio_manager_set_audio_info(sound_stream_info_h stream_info_h, const char* audio_source_type, vce_audio_type_e type, int rate, int channel);
+int dependency_audio_manager_get_audio_source_type(char** audio_source_type);
 int dependency_audio_manager_start_recording(void);
 int dependency_audio_manager_stop_recording(void);
 
index 969d5b4c0f1727bde5bd77528c0a45993689ef20..0b757418c578f3c069d1dfa32595751b3c1b8bbd 100644 (file)
@@ -399,7 +399,7 @@ static int __feed_audio_data_cb(const void* data, const unsigned int length)
        fwrite(data, 1, BUFFER_LENGTH, g_normal_file);
 #endif
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 
@@ -428,10 +428,6 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb
        /* set init value */
        g_is_valid_audio_in = false;
        g_is_valid_bt_in = false;
-       g_current_audio_type = NULL;
-
-       g_pcm_fp = NULL;
-       g_pcm_path = NULL;
 
        ret = sound_manager_add_device_connection_changed_cb(SOUND_DEVICE_IO_DIRECTION_IN_MASK, __device_connection_changed_cb, NULL, &g_device_id);
        if (0 != ret)
@@ -479,6 +475,7 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb
                g_is_valid_bt_in = true;
        }
 #endif
+
        /* Select default audio type */
        if (true == g_is_valid_audio_in) {
                g_current_audio_type = strdup(VCE_AUDIO_ID_NONE);
@@ -576,16 +573,16 @@ int vcd_recorder_destroy()
        return VCD_ERROR_NONE;
 }
 
-static int __set_audio_source_type(const char* audio_type)
+static int __set_audio_source_type(const char* audio_source_type)
 {
-       if (NULL == audio_type) {
-               SLOG(LOG_INFO, TAG_VCD, "[Recorder] Audio type is NULL");
+       if (NULL == audio_source_type) {
+               SLOG(LOG_INFO, TAG_VCD, "[Recorder] Audio source type is NULL");
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
        if (NULL != g_current_audio_type) {
-               if (0 == strncmp(g_current_audio_type, audio_type, strlen(g_current_audio_type))) {
-                       SLOG(LOG_INFO, TAG_VCD, "[Recorder] Current audio type is already set : %s", audio_type);
+               if (0 == strncmp(g_current_audio_type, audio_source_type, strlen(g_current_audio_type))) {
+                       SLOG(LOG_INFO, TAG_VCD, "[Recorder] Current audio type is already set : %s", audio_source_type);
                        return VCD_ERROR_NONE;
                }
        } else {
@@ -593,35 +590,16 @@ static int __set_audio_source_type(const char* audio_type)
                return VCD_ERROR_INVALID_STATE;
        }
 
-       SLOG(LOG_INFO, TAG_VCD, "[Recorder] set audio type (%s)", audio_type);
-       vcd_engine_set_audio_type(audio_type);
-
-       if (VCD_RECORDER_STATE_READY != g_recorder_state) {
-               if (NULL != g_current_audio_type) {
-                       if ((!strncmp(g_current_audio_type, VCE_AUDIO_ID_NONE, strlen(g_current_audio_type)) &&
-                                               strncmp(audio_type, VCE_AUDIO_ID_BLUETOOTH, strlen(audio_type)) &&
-                                               strncmp(audio_type, VCE_AUDIO_ID_FFV, strlen(audio_type)) &&
-                                               strncmp(audio_type, VCE_AUDIO_ID_WIFI, strlen(audio_type))) ||
-                                       (strncmp(g_current_audio_type, VCE_AUDIO_ID_BLUETOOTH, strlen(g_current_audio_type)) &&
-                                        strncmp(g_current_audio_type, VCE_AUDIO_ID_FFV, strlen(g_current_audio_type)) &&
-                                        strncmp(g_current_audio_type, VCE_AUDIO_ID_WIFI, strlen(g_current_audio_type)) &&
-                                        strncmp(g_current_audio_type, VCE_AUDIO_ID_NONE, strlen(g_current_audio_type)) &&
-                                        !strncmp(audio_type, VCE_AUDIO_ID_NONE, strlen(audio_type)))) {
-                               SLOG(LOG_INFO, TAG_VCD, "[Recorder] Skip stop recording while Recorder is NOT ready");
-                       } else {
-                               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Recorder is NOT ready");
-                               vcd_recorder_stop();
-                               //return VCD_ERROR_INVALID_STATE;
-                       }
-               }
-       }
+       SLOG(LOG_INFO, TAG_VCD, "[Recorder] set audio type (%s)", audio_source_type);
+       vcd_engine_set_audio_type(audio_source_type);
 
+       // Set new audio source type
        if (NULL != g_current_audio_type) {
                free(g_current_audio_type);
                g_current_audio_type = NULL;
        }
 
-       g_current_audio_type = strdup(audio_type);
+       g_current_audio_type = strdup(audio_source_type);
 
        return VCD_ERROR_NONE;
 }
@@ -647,17 +625,17 @@ int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, in
                        SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Audio-in is NOT valid");
                        return VCD_ERROR_OPERATION_REJECTED;
                }
+       }
 
-               ret = dependency_audio_manager_set_audio_info(g_stream_info_h, audio_type, type, rate, channel);
-               if (0 != ret) {
-                       g_is_valid_audio_in = false;
-                       SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set audio information");
-               }
+       ret = dependency_audio_manager_set_audio_info(g_stream_info_h, audio_type, type, rate, channel);
+       if (0 != ret) {
+               g_is_valid_audio_in = false;
+               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set audio information");
        }
 
        SLOG(LOG_INFO, TAG_VCD, "[Recorder] Current audio type is changed : %s", g_current_audio_type);
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 int vcd_recorder_get(char** audio_type)
@@ -666,14 +644,13 @@ int vcd_recorder_get(char** audio_type)
                return VCD_ERROR_INVALID_PARAMETER;
        }
 
-       if (NULL != g_current_audio_type) {
-               *audio_type = strdup(g_current_audio_type);
-       } else {
+       if (0 != dependency_audio_manager_get_audio_source_type(audio_type)) {
                SLOG(LOG_WARN, TAG_VCD, "[Recorder] Current audio type(%s) is NOT ready", *audio_type);
                *audio_type = NULL;
+               return VCD_ERROR_INVALID_STATE;
        }
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 // TODO: make common function?
@@ -734,9 +711,8 @@ Eina_Bool __read_test_func(void *data)
 
        buffer_size = MIN(buffer_size, BUFFER_LENGTH);
 
-       // TODO: change to __feed_audio_data_cb
-       if (NULL != g_audio_cb && buffer_size != 0)
-               g_audio_cb(buffer, buffer_size);
+       if (buffer_size != 0)
+               __feed_audio_data_cb(buffer, buffer_size);
 
        float vol_db = get_volume_decibel(buffer, buffer_size);
        if (0 != vcdc_send_set_volume(vcd_client_manager_get_pid(), vol_db))
@@ -747,6 +723,7 @@ Eina_Bool __read_test_func(void *data)
                g_pcm_fp = NULL;
                return EINA_FALSE;
        }
+
        return EINA_TRUE;
 }
 
@@ -756,31 +733,6 @@ static void __timer_read_test_func(void *data)
        return;
 }
 
-static void __check_audio_format()
-{
-       vce_audio_type_e type;
-       int rate;
-       int channel;
-
-       int ret = vcd_engine_get_audio_format(VCE_AUDIO_ID_NONE, &type, &rate, &channel);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to get audio format : %d", ret);
-               return;
-       }
-
-       if (false == g_is_valid_audio_in) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Audio-in is NOT valid");
-               return;
-       }
-
-       ret = dependency_audio_manager_set_audio_info(g_stream_info_h, VCE_AUDIO_ID_NONE, type, rate, channel);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set audio information");
-               g_is_valid_audio_in = false;
-               return;
-       }
-}
-
 int vcd_recorder_start_streaming()
 {
        SLOG(LOG_INFO, TAG_VCD, "[Recorder] start streaming");
@@ -822,7 +774,7 @@ int vcd_recorder_start_streaming()
        }
 #endif
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 int vcd_recorder_send_streaming(const void* buffer, const unsigned int length)
@@ -849,7 +801,7 @@ int vcd_recorder_send_streaming(const void* buffer, const unsigned int length)
                fwrite(buffer, 1, length, g_normal_file);
 #endif
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 int vcd_recorder_stop_streaming()
@@ -868,7 +820,7 @@ int vcd_recorder_stop_streaming()
                fclose(g_normal_file);
 #endif
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 int vcd_recorder_change_system_volume()
@@ -897,7 +849,7 @@ int vcd_recorder_change_system_volume()
                }
        }
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 int vcd_recorder_recover_system_volume()
@@ -927,7 +879,7 @@ int vcd_recorder_recover_system_volume()
                g_stream_for_volume_h = NULL;
        }
 
-       return 0;
+       return VCD_ERROR_NONE;
 }
 
 int vcd_recorder_start()
@@ -955,19 +907,13 @@ int vcd_recorder_start()
                // For testing
                ecore_main_loop_thread_safe_call_async(__timer_read_test_func, NULL);
        } else {
-               if (NULL != g_current_audio_type && 0 == strncmp(VCE_AUDIO_ID_NONE, g_current_audio_type, strlen(VCE_AUDIO_ID_NONE))) {
-                       /* check audio format */
-                       __check_audio_format();
+               ret = dependency_audio_manager_start_recording();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start recording, [ret(%d)]", ret);
+                       return VCD_ERROR_OPERATION_FAILED;
                }
        }
 
-       ret = dependency_audio_manager_start_recording();
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start recording, [ret(%d)]", ret);
-
-               return ret;
-       }
-
        g_recorder_state = VCD_RECORDER_STATE_RECORDING;
 
 #ifdef BUF_SAVE_MODE
@@ -1023,21 +969,22 @@ int vcd_recorder_stop()
        fclose(g_normal_file);
 #endif
 
-       if (g_pcm_path)
-               free(g_pcm_path);
-       g_pcm_path = NULL;
-
-       if (g_pcm_fp)
+       if (NULL != g_pcm_fp) {
                fclose(g_pcm_fp);
-       g_pcm_fp = NULL;
-
-       ret = dependency_audio_manager_stop_recording();
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to stop audio : %d", ret);
-               return ret;
+               g_pcm_fp = NULL;
        }
 
-       __set_audio_source_type(VCE_AUDIO_ID_NONE);
+       if (NULL != g_pcm_path) {
+               // For testing
+               free(g_pcm_path);
+               g_pcm_path = NULL;
+       } else {
+               ret = dependency_audio_manager_stop_recording();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to stop audio : %d", ret);
+                       return ret;
+               }
+       }
 
        return VCD_ERROR_NONE;
 }
@@ -1049,15 +996,16 @@ int vcd_recorder_get_state()
 
 int vcd_recorder_set_pcm_path(const char *path)
 {
-       SLOG(LOG_INFO, TAG_VCD, "[Recorder] set pcm path : %s", path);
-
-       if (path == NULL)
-               return 0;
+       if (path == NULL) {
+               return VCD_ERROR_INVALID_PARAMETER;
+       }
 
-       if (g_pcm_path)
+       SLOG(LOG_INFO, TAG_VCD, "[Recorder] set pcm path : %s", path);
+       if (NULL != g_pcm_path) {
                free(g_pcm_path);
-       g_pcm_path = NULL;
+               g_pcm_path = NULL;
+       }
 
        g_pcm_path = strdup(path);
-       return 0;
+       return VCD_ERROR_NONE;
 }