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;
return VCE_ERROR_OPERATION_FAILED;
}
- g_audio_source_type = strdup(VCE_AUDIO_ID_NONE);
g_feed_audio_data = callback;
g_is_recording = false;
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;
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)) {
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("");
if (nullptr == g_audio_h) {
VCAM_LOGE("[ERROR] Audio in handle is not valid.");
-
return VCE_ERROR_INVALID_STATE;
}
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
(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 =
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;
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"
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);
fwrite(data, 1, BUFFER_LENGTH, g_normal_file);
#endif
- return 0;
+ return VCD_ERROR_NONE;
}
/* 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)
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);
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 {
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;
}
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)
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?
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))
g_pcm_fp = NULL;
return EINA_FALSE;
}
+
return EINA_TRUE;
}
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");
}
#endif
- return 0;
+ return VCD_ERROR_NONE;
}
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()
fclose(g_normal_file);
#endif
- return 0;
+ return VCD_ERROR_NONE;
}
int vcd_recorder_change_system_volume()
}
}
- return 0;
+ return VCD_ERROR_NONE;
}
int vcd_recorder_recover_system_volume()
g_stream_for_volume_h = NULL;
}
- return 0;
+ return VCD_ERROR_NONE;
}
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
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;
}
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;
}