From 8592301913d01e074b0789d6a450cd8a930c8a65 Mon Sep 17 00:00:00 2001 From: Sohyeon Choi Date: Wed, 21 Feb 2024 21:58:38 +0900 Subject: [PATCH] change stream type and modify HFP version and feature for DA Change-Id: Ic30d8c8346346f20ce6e07457b759331da0c75c1 Signed-off-by: Anuj Jain --- hf-agent/bluetooth-hf-agent.c | 118 ++++++++++++++++++++++++++++++++++++++++-- hf-agent/bluetooth-hf-agent.h | 5 +- 2 files changed, 117 insertions(+), 6 deletions(-) diff --git a/hf-agent/bluetooth-hf-agent.c b/hf-agent/bluetooth-hf-agent.c index 7e5b53e..a2fae12 100644 --- a/hf-agent/bluetooth-hf-agent.c +++ b/hf-agent/bluetooth-hf-agent.c @@ -2571,7 +2571,8 @@ static void __release_audio_out(bt_hf_agent_info_t *bt_hf_info) INFO("+"); if (bt_hf_info->audio_output != NULL) { - audio_out_drain((audio_out_h)bt_hf_info->audio_output); + /* Skip audio drain */ + //audio_out_drain((audio_out_h)bt_hf_info->audio_output); audio_out_unprepare((audio_out_h)bt_hf_info->audio_output); audio_out_destroy((audio_out_h)bt_hf_info->audio_output); bt_hf_info->audio_output = NULL; @@ -3027,7 +3028,7 @@ static gboolean __bt_establish_service_level_conn(bt_hf_agent_info_t *bt_hf_info if (TIZEN_MODEL_NAME_DA) feature = BT_HF_FEATURE_CLI_PRESENTATION | BT_HF_FEATURE_REMOTE_VOLUME_CONTROL | - BT_HF_FEATURE_ENHANCED_CALL_STATUS; + BT_HF_FEATURE_ESCO_S4; else { feature = BT_HF_FEATURE_EC_ANDOR_NR | BT_HF_FEATURE_CALL_WAITING_AND_3WAY | @@ -3305,6 +3306,100 @@ done: return FALSE; } +static void __unprepare_stream_info(void) +{ + int ret; + + if (!g_stream_info_write_h) { + ERR("no stream to destroy"); + return; + } + + ret = sound_manager_destroy_stream_information(g_stream_info_write_h); + if (ret != SOUND_MANAGER_ERROR_NONE) { + ERR("Failed to destroy stream information"); + return; + } + + g_stream_info_write_h = NULL; +} + +void stream_focus_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, + sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data) +{ + return; +} + +static gboolean __prepare_stream_info(void) +{ + int ret; + sound_device_list_h g_device_list = NULL; + sound_device_h device = NULL; + sound_device_type_e selected_type = SOUND_DEVICE_BUILTIN_SPEAKER; + sound_device_type_e type = SOUND_DEVICE_BUILTIN_SPEAKER; + + if (TIZEN_MODEL_NAME_FHUB) { + char *processor = NULL; + + system_info_get_platform_string("tizen.org/system/platform.processor", &processor); + if (processor) { + if (!strcasecmp(processor, "SDP1601")) { + DBG("set specific sound type"); + selected_type = SOUND_DEVICE_BUILTIN_RECEIVER; + type = SOUND_DEVICE_BUILTIN_RECEIVER; + } + free(processor); + } + } + + if (g_stream_info_write_h) { + ERR("there is already created one %p", g_stream_info_write_h); + __unprepare_stream_info(); + } + + ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOIP, stream_focus_cb, NULL, &g_stream_info_write_h); + if (ret != SOUND_MANAGER_ERROR_NONE) { + ERR("Failed to create stream information"); + return FALSE; + } + INFO("created stream info %p", g_stream_info_write_h); + + ret = sound_manager_get_device_list(SOUND_DEVICE_IO_DIRECTION_OUT_MASK, &g_device_list); + if (ret != SOUND_MANAGER_ERROR_NONE) { + ERR("fail to get current device list, ret(0x%x)\n", ret); + return FALSE; + } + + // find voip device + while (!sound_manager_get_next_device(g_device_list, &device)) { + if ((ret = sound_manager_get_device_type(device, &type))) { + ERR("fail to get type of device, ret(0x%x)\n", ret); + break; + } + + if (selected_type == type) { + DBG("try to set route for device\n"); + ret = sound_manager_add_device_for_stream_routing(g_stream_info_write_h, device); + if (ret == SOUND_MANAGER_ERROR_NONE) { + ret = sound_manager_apply_stream_routing(g_stream_info_write_h); + if (ret != SOUND_MANAGER_ERROR_NONE) + ERR("failed to sound_manager_apply_stream_routing(), ret(0x%x)\n", ret); + } else { + ERR("failed to sound_manager_add_device_for_stream_routing(), ret(0x%x)\n", ret); + } + break; + } + } + + ret = sound_manager_free_device_list(g_device_list); + if (ret != SOUND_MANAGER_ERROR_NONE) + ERR("fail to free device list, ret[0x%x]\n", ret); + else + g_device_list = NULL; + + return TRUE; +} + static gboolean __bt_hf_agent_connection(gint32 fd, const gchar *obj_path) { GIOFlags flags; @@ -3336,6 +3431,9 @@ static gboolean __bt_hf_agent_connection(gint32 fd, const gchar *obj_path) __bt_convert_addr_type_to_rev_string(bt_hf_info.remote_addr, address.remote_bdaddr.b); + if (TIZEN_MODEL_NAME_DA) + __prepare_stream_info(); + g_idle_add(__bt_agent_request_service_level_conn, NULL); return TRUE; @@ -3351,6 +3449,9 @@ static gboolean __bt_hf_agent_release(void) int bt_device_state = VCONFKEY_BT_DEVICE_NONE; GDBusConnection *conn; + if (TIZEN_MODEL_NAME_DA) + __unprepare_stream_info(); + if (clcc_timer) { g_source_remove(clcc_timer); clcc_timer = 0; @@ -4039,7 +4140,8 @@ static uint32_t __bt_hf_agent_get_hf_features(void) if (TIZEN_MODEL_NAME_DA) hf_features = BT_HF_FEATURE_CLI_PRESENTATION | - BT_HF_FEATURE_REMOTE_VOLUME_CONTROL; + BT_HF_FEATURE_REMOTE_VOLUME_CONTROL | + BT_HF_FEATURE_ESCO_S4; else { hf_features = BT_HF_FEATURE_EC_ANDOR_NR | BT_HF_FEATURE_CALL_WAITING_AND_3WAY | @@ -4052,7 +4154,10 @@ static uint32_t __bt_hf_agent_get_hf_features(void) hf_features = hf_features | BT_HF_FEATURE_CODEC_NEGOTIATION; } - hf_ver = HFP_VERSION_1_6; + if (TIZEN_MODEL_NAME_DA) + hf_ver = HFP_VERSION_1_7; + else + hf_ver = HFP_VERSION_1_6; return hf_features; } @@ -4069,7 +4174,10 @@ int main(void) g_type_init(); #endif hf_features = __bt_hf_agent_get_hf_features(); - bt_hf_info.feature = (uint16_t) hf_features & 0x3F; + if (TIZEN_MODEL_NAME_DA) + bt_hf_info.feature = (uint16_t) hf_features & 0xFFFF; + else + bt_hf_info.feature = (uint16_t) hf_features & 0x3F; bt_hf_info.audio_input = NULL; bt_hf_info.audio_output = NULL; diff --git a/hf-agent/bluetooth-hf-agent.h b/hf-agent/bluetooth-hf-agent.h index bbac08a..14b4861 100644 --- a/hf-agent/bluetooth-hf-agent.h +++ b/hf-agent/bluetooth-hf-agent.h @@ -126,6 +126,8 @@ extern "C" { #define BT_HF_FEATURE_ENHANCED_CALL_STATUS 0x0020 #define BT_HF_FEATURE_ENHANCED_CALL_CONTROL 0x0040 #define BT_HF_FEATURE_CODEC_NEGOTIATION 0x0080 +#define BT_HF_FEATURE_HF_INDICATORS 0x0100 +#define BT_HF_FEATURE_ESCO_S4 0x0200 /* Audio Gateway features */ #define BT_AG_FEATURE_3WAY 0x1 @@ -187,7 +189,8 @@ extern "C" { enum hfp_version { HFP_VERSION_1_5 = 0x0105, HFP_VERSION_1_6 = 0x0106, - HFP_VERSION_LATEST = HFP_VERSION_1_6, + HFP_VERSION_1_7 = 0x0107, + HFP_VERSION_LATEST = HFP_VERSION_1_7, }; typedef enum { -- 2.7.4