static audio_in_h g_audio_h;
-#if 1
static sound_stream_info_h g_stream_info_h;
-#endif
static vcp_audio_type_e g_audio_type;
static int g_buffer_count;
+static int g_device_id = -1;
+
/* Sound buf save */
/*
#define BUF_SAVE_MODE
return -1;
}
+static void __device_connection_changed_cb(sound_device_h device, bool is_connected, void *user_data)
+{
+ sound_device_type_e type;
+ if (is_connected) {
+ if (0 != sound_manager_get_device_type(device, &type)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to get device tyep");
+ return;
+ }
+ if (type == SOUND_DEVICE_USB_AUDIO) {
+ bool is_recording_state = false;
+ if (VCD_RECORDER_STATE_RECORDING == g_recorder_state) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Stop recorder");
+ vcd_recorder_stop();
+ is_recording_state = true;
+ }
+ if (0 != sound_manager_remove_device_for_stream_routing(g_stream_info_h, device))
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to remove device");
+
+ if (0 != sound_manager_add_device_for_stream_routing(g_stream_info_h, device)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to add device");
+ return;
+ }
+ if (0 != sound_manager_apply_stream_routing(g_stream_info_h)) {
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR} Fail to apply stream routing");
+ return;
+ }
+ if (true == is_recording_state) {
+ SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Start recorder");
+ vcd_recorder_start();
+ }
+ SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Apply device for stream routing");
+ }
+ }
+ return;
+}
+
int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb interrupt_cb)
{
if (NULL == audio_cb || NULL == interrupt_cb) {
g_is_valid_audio_in = false;
}
-#if 1
+ 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)
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to add device connection changed callback");
+
if (0 != sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE, __recorder_focus_state_cb, NULL, &g_stream_info_h)) {
SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create stream info");
} else {
if (0 != audio_in_set_sound_stream_info(g_audio_h, g_stream_info_h)) {
SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set stream info");
}
-#endif
g_audio_cb = audio_cb;
g_interrupt_cb = interrupt_cb;
g_recorder_state = VCD_RECORDER_STATE_READY;
}
-#if 0
- if (0 != sound_manager_destroy_stream_information(g_stream_info_h)) {
- SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream info");
- }
-#endif
+ int ret = sound_manager_remove_device_connection_changed_cb(g_device_id);
+ if (0 != ret)
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to remove device connection changed callback, ret(%d)", ret);
+
+ ret = sound_manager_destroy_stream_information(g_stream_info_h);
+ if (0 != ret)
+ SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream info, ret(%d)", ret);
audio_in_destroy(g_audio_h);