Support voice-information with BT SCO 24/142024/3
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 2 Aug 2017 08:16:45 +0000 (17:16 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 3 Aug 2017 03:42:42 +0000 (12:42 +0900)
Almost similar as voice-recognition case that of previous commit.
 - Open/close hw:0,2 for this case.
 - Refer to bt_wideband to set param of samplerate(narrowband:8k, wideband:16k).

[Version] 0.1.4
[Profile] Wearable
[Issue Type] New feature

Change-Id: I708c5ae01008dea638b7513675a954a3cbceaab1
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/audio-hal-wm1831-tw2.spec
tizen-audio-impl-pcm.c
tizen-audio-impl.h
tizen-audio-routing.c

index bdc00a7..5ead07a 100644 (file)
@@ -1,6 +1,6 @@
 Name:       audio-hal-wm1831-tw2
 Summary:    TIZEN Audio HAL for WM1831(TW2)
-Version:    0.1.3
+Version:    0.1.4
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 9623af0..91a02db 100644 (file)
@@ -248,7 +248,7 @@ error:
     return ret;
 }
 
-audio_return_t _voice_pcm_open(audio_hal_t *ah)
+audio_return_t _voice_pcm_open_all(audio_hal_t *ah)
 {
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
 
@@ -256,7 +256,7 @@ audio_return_t _voice_pcm_open(audio_hal_t *ah)
                              AUDIO_DEVICE_DIRECTION_IN | AUDIO_DEVICE_DIRECTION_OUT, 48000, 2);
 }
 
-audio_return_t _bt_pcm_open(audio_hal_t *ah)
+audio_return_t _bt_pcm_open_all(audio_hal_t *ah)
 {
     uint32_t samplerate;
 
@@ -288,7 +288,7 @@ bool _is_bt_pcm_opened_all(audio_hal_t *ah)
         return false;
 }
 
-audio_return_t _voice_pcm_close(audio_hal_t *ah)
+audio_return_t _voice_pcm_close_all(audio_hal_t *ah)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
 
@@ -301,7 +301,7 @@ audio_return_t _voice_pcm_close(audio_hal_t *ah)
             AUDIO_LOG_ERROR("failed to _pcm_close() for voice pcm out, ret(0x%x)", audio_ret);
         else {
             ah->device.voice_pcm.out = NULL;
-            AUDIO_LOG_INFO("voice pcm_out handle close success");
+            AUDIO_LOG_INFO("voice pcm out handle close success");
         }
     }
     if (ah->device.voice_pcm.in) {
@@ -309,14 +309,14 @@ audio_return_t _voice_pcm_close(audio_hal_t *ah)
             AUDIO_LOG_ERROR("failed to _pcm_close() for voice pcm in, ret(0x%x)", audio_ret);
         else {
             ah->device.voice_pcm.in = NULL;
-            AUDIO_LOG_INFO("voice pcm_in handle close success");
+            AUDIO_LOG_INFO("voice pcm in handle close success");
         }
     }
 
     return audio_ret;
 }
 
-audio_return_t _bt_pcm_close(audio_hal_t *ah)
+audio_return_t _bt_pcm_close_all(audio_hal_t *ah)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
 
@@ -329,7 +329,7 @@ audio_return_t _bt_pcm_close(audio_hal_t *ah)
             AUDIO_LOG_ERROR("failed to _pcm_close() for bt pcm out, ret(0x%x)", audio_ret);
         else {
             ah->device.bt_pcm.out = NULL;
-            AUDIO_LOG_INFO("bt pcm_out handle close success");
+            AUDIO_LOG_INFO("bt pcm out handle close success");
         }
     }
     if (ah->device.bt_pcm.in) {
@@ -337,45 +337,19 @@ audio_return_t _bt_pcm_close(audio_hal_t *ah)
             AUDIO_LOG_ERROR("failed to _pcm_close() for bt pcm in, ret(0x%x)", audio_ret);
         else {
             ah->device.bt_pcm.in = NULL;
-            AUDIO_LOG_INFO("voice pcm_in handle close success");
+            AUDIO_LOG_INFO("bt pcm in handle close success");
         }
     }
 
     return audio_ret;
 }
 
-audio_return_t _reset_pcm_devices(audio_hal_t *ah)
+void _reset_pcm_devices(audio_hal_t *ah)
 {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-
-    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+    AUDIO_RETURN_IF_FAIL(ah);
 
-    if (ah->device.voice_pcm.out) {
-        if (!(audio_ret = _pcm_close(ah->device.voice_pcm.out))) {
-            ah->device.voice_pcm.out = NULL;
-            AUDIO_LOG_INFO("voice pcm out handle close success");
-        }
-    }
-    if (ah->device.voice_pcm.in) {
-        if (!(audio_ret = _pcm_close(ah->device.voice_pcm.in))) {
-            ah->device.voice_pcm.in = NULL;
-            AUDIO_LOG_INFO("voice pcm in handle close success");
-        }
-    }
-    if (ah->device.bt_pcm.out) {
-        if (!(audio_ret = _pcm_close(ah->device.bt_pcm.out))) {
-            ah->device.bt_pcm.out = NULL;
-            AUDIO_LOG_INFO("bt pcm out handle close success");
-        }
-    }
-    if (ah->device.bt_pcm.in) {
-        if (!(audio_ret = _pcm_close(ah->device.bt_pcm.in))) {
-            ah->device.bt_pcm.in = NULL;
-            AUDIO_LOG_INFO("bt pcm in handle close success");
-        }
-    }
-
-    return audio_ret;
+    _voice_pcm_close_all(ah);
+    _bt_pcm_close_all(ah);
 }
 
 audio_return_t _pcm_open(void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods)
index ee48fa9..b744ef0 100644 (file)
 #include <stdbool.h>
 
 /* PCM */
-audio_return_t _voice_pcm_open(audio_hal_t *ah);
-audio_return_t _voice_pcm_close(audio_hal_t *ah);
-audio_return_t _bt_pcm_open(audio_hal_t *ah);
-audio_return_t _bt_pcm_close(audio_hal_t *ah);
+audio_return_t _voice_pcm_open_all(audio_hal_t *ah);
+audio_return_t _voice_pcm_close_all(audio_hal_t *ah);
+audio_return_t _bt_pcm_open_all(audio_hal_t *ah);
+audio_return_t _bt_pcm_close_all(audio_hal_t *ah);
 bool _is_voice_pcm_opened_all(audio_hal_t *ah);
 bool _is_bt_pcm_opened_all(audio_hal_t *ah);
-audio_return_t _reset_pcm_devices(audio_hal_t *ah);
+void _reset_pcm_devices(audio_hal_t *ah);
 audio_return_t _pcm_open(void **pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods);
 audio_return_t _pcm_start(void *pcm_handle);
 audio_return_t _pcm_stop(void *pcm_handle);
index fc1f794..e126712 100644 (file)
@@ -68,22 +68,6 @@ static uint32_t __convert_device_string_to_enum(const char* device_str, uint32_t
     return device;
 }
 
-static void __reset_voice_devices_info(audio_hal_t *ah)
-{
-    AUDIO_RETURN_IF_FAIL(ah);
-
-    AUDIO_LOG_INFO("reset voice device info");
-#if 0
-    if (ah->device.init_call_devices) {
-        free(ah->device.init_call_devices);
-        ah->device.init_call_devices = NULL;
-        ah->device.num_of_call_devices = 0;
-    }
-#endif
-
-    return;
-}
-
 static audio_return_t __set_devices(audio_hal_t *ah, const char *verb, device_info_t *devices, uint32_t num_of_devices)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
@@ -162,9 +146,6 @@ static audio_return_t __update_route_ap_playback_capture(audio_hal_t *ah, audio_
     AUDIO_RETURN_VAL_IF_FAIL(route_info, AUDIO_ERR_PARAMETER);
 
     if (ah->device.mode != VERB_NORMAL) {
-        if (ah->device.mode == VERB_VOICECALL) {
-            __reset_voice_devices_info(ah);
-        }
        _reset_pcm_devices(ah);
        ah->device.mode = VERB_NORMAL;
     }
@@ -206,7 +187,7 @@ static audio_return_t __update_route_voicecall(audio_hal_t *ah, device_info_t *d
             AUDIO_LOG_INFO("voice pcm device is already opened, skip it");
             return audio_ret;
         }
-        if ((audio_ret = _voice_pcm_open(ah))) {
+        if ((audio_ret = _voice_pcm_open_all(ah))) {
             AUDIO_LOG_ERROR("Failed to open voice pcm device: error = 0x%x", audio_ret);
             return audio_ret;
         }
@@ -263,7 +244,43 @@ static audio_return_t __update_route_voice_recognition(audio_hal_t *ah, device_i
             return audio_ret;
         }
 
-        if ((audio_ret = _bt_pcm_open(ah))) {
+        if ((audio_ret = _bt_pcm_open_all(ah))) {
+            AUDIO_LOG_ERROR("Failed to open bt pcm device: error = 0x%x", audio_ret);
+            return audio_ret;
+        }
+    }
+
+    return audio_ret;
+}
+
+static audio_return_t __update_route_voice_information(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
+{
+    audio_return_t audio_ret = AUDIO_RET_OK;
+    const char *verb = mode_to_verb_str[VERB_NORMAL];
+
+    AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
+    AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
+
+    AUDIO_LOG_INFO("update_route_voice_information++");
+
+    audio_ret = __set_devices(ah, verb, devices, num_of_devices);
+    if (audio_ret) {
+        AUDIO_LOG_ERROR("Failed to set devices: error = 0x%x", audio_ret);
+        return audio_ret;
+    }
+
+    if (ah->device.mode != VERB_NORMAL) {
+        ah->device.mode = VERB_NORMAL;
+       _reset_pcm_devices(ah);
+    }
+    /* if this request is for BT SCO device */
+    if (ah->device.active_out & AUDIO_DEVICE_OUT_BT_SCO) {
+        if (_is_bt_pcm_opened_all(ah)) {
+            AUDIO_LOG_INFO("bt pcm device is already opened, skip it");
+            return audio_ret;
+        }
+
+        if ((audio_ret = _bt_pcm_open_all(ah))) {
             AUDIO_LOG_ERROR("Failed to open bt pcm device: error = 0x%x", audio_ret);
             return audio_ret;
         }
@@ -307,17 +324,16 @@ static audio_return_t __update_route_reset(audio_hal_t *ah, uint32_t direction)
     }
 
     if (ah->device.mode == VERB_VOICECALL) {
-        if ((audio_ret = _bt_pcm_close(ah)))
+        if ((audio_ret = _bt_pcm_close_all(ah)))
             AUDIO_LOG_ERROR("failed to _bt_pcm_close(), ret(0x%x)", audio_ret);
-        if ((audio_ret = _voice_pcm_close(ah)))
+        if ((audio_ret = _voice_pcm_close_all(ah)))
             AUDIO_LOG_ERROR("failed to _voice_pcm_close(), ret(0x%x)", audio_ret);
         if (!ah->device.active_in && !ah->device.active_out)
             ah->device.mode = VERB_NORMAL;
-        __reset_voice_devices_info(ah);
     } else if (ah->device.mode == VERB_NORMAL) {
         if (direction == AUDIO_DIRECTION_IN) {
             /* voice-recognition case */
-            if ((audio_ret = _bt_pcm_close(ah)))
+            if ((audio_ret = _bt_pcm_close_all(ah)))
                 AUDIO_LOG_ERROR("failed to _bt_pcm_close(), ret(0x%x)", audio_ret);
         }
     }
@@ -393,12 +409,16 @@ audio_return_t audio_update_route(void *audio_handle, audio_route_info_t *info)
         if ((audio_ret = __update_route_voice_recognition(ah, devices, info->num_of_devices)))
             AUDIO_LOG_WARN("update voice-recognition route return 0x%x", audio_ret);
 
+    } else if (!strncmp("voice-information", info->role, MAX_NAME_LEN)) {
+        if ((audio_ret = __update_route_voice_information(ah, devices, info->num_of_devices)))
+            AUDIO_LOG_WARN("update voice-information route return 0x%x", audio_ret);
+
     } else if (!strncmp("reset", info->role, MAX_NAME_LEN)) {
         if ((audio_ret = __update_route_reset(ah, devices->direction)))
             AUDIO_LOG_WARN("update reset return 0x%x", audio_ret);
 
     } else {
-        /* need to prepare for "alarm","notification","emergency","voice-information","ringtone" */
+        /* need to prepare for "alarm","notification","emergency","ringtone" */
         if ((audio_ret = __update_route_ap_playback_capture(ah, info)))
             AUDIO_LOG_WARN("update playback route return 0x%x", audio_ret);
     }