Apply to use external USB mic 94/144994/3
authorWonnam Jang <wn.jang@samsung.com>
Mon, 21 Aug 2017 01:47:39 +0000 (10:47 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Mon, 21 Aug 2017 01:58:26 +0000 (10:58 +0900)
Change-Id: I28d8a883964f0c116137e816b2a83f860570fc36
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
client/vc_mgr.c
server/vcd_recorder.c

index eb5e8e9..5ac54e5 100644 (file)
@@ -337,7 +337,6 @@ static void __start_prepare_thread(void *data, Ecore_Thread *thread)
 
        ret = 1;
        retry_count = 0;
-
        while (ret) {
                if (retry_count == 10) {
                        SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to connect daemon !!");
index ce79fee..88a654f 100644 (file)
@@ -55,9 +55,7 @@ static vcd_recorder_interrupt_cb      g_interrupt_cb = NULL;
 
 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;
 
@@ -75,6 +73,8 @@ static char*  g_current_audio_type = NULL;
 
 static int     g_buffer_count;
 
+static int     g_device_id = -1;
+
 /* Sound buf save */
 /*
 #define BUF_SAVE_MODE
@@ -293,6 +293,42 @@ static int __apply_device_for_stream_routing()
        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) {
@@ -356,7 +392,10 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_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 {
@@ -366,7 +405,6 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb
        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;
@@ -431,11 +469,13 @@ int vcd_recorder_destroy()
                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);