From 801af62cc645436a3040a394e52347cb98679d86 Mon Sep 17 00:00:00 2001 From: Sangki Park Date: Fri, 21 Jun 2019 11:22:12 +0900 Subject: [PATCH] AVC : prevent ear-shock sound [Model] Renaissance [BinType] AP [Customer] ALL [Issue#] N/A [Request] N/A [Occurrence Version] N/A [Problem] N/A [Cause & Measure] N/A [Checking Method] N/A [Team] Bluetooth [Developer] Sangki Park [Solution company] Samsung [Change Type] Specification change Change-Id: If6adfdeab296821d4e6409685fcdbb0c73bebbcc --- profiles/audio/transport.c | 48 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c index 3dd4c12..68aba25 100644 --- a/profiles/audio/transport.c +++ b/profiles/audio/transport.c @@ -856,14 +856,42 @@ static void source_state_changed(struct btd_service *service, transport_update_playing(transport, FALSE); } -static int media_transport_init_source(struct media_transport *transport) -{ - struct btd_service *service; - struct a2dp_transport *a2dp; #ifdef TIZEN_FEATURE_BLUEZ_MODIFY +#define AVC_MAX_VOLUME 127 +#define AVC_INITIAL_MAX_VOLUME (AVC_MAX_VOLUME * 3 / 5 + 1) +#define DEVICE_MAX_VOLUME 150 +#define DEVICE_INITIAL_MAX_VOLUME (DEVICE_MAX_VOLUME * 3 / 5) + +static void media_transport_init_volume(struct media_transport *transport) { + struct a2dp_transport *a2dp = transport->data; uint8_t vol = 0; int ret; + + ret = avrcp_get_target_volume(transport->device, &vol); + + if (ret) /* not support AVC */ + return; + + if (vol > AVC_MAX_VOLUME) + return; + + a2dp->volume = vol; + + /* Ear-shock issue */ + if (a2dp->volume > AVC_INITIAL_MAX_VOLUME) { + a2dp->volume = AVC_INITIAL_MAX_VOLUME; + avrcp_set_volume(transport->device, AVC_INITIAL_MAX_VOLUME, 0x00); + } + + DBG("Get AVC volume from controller : volume [%d])", a2dp->volume); +} #endif + +static int media_transport_init_source(struct media_transport *transport) +{ + struct btd_service *service; + struct a2dp_transport *a2dp; + service = btd_device_get_service(transport->device, A2DP_SINK_UUID); if (service == NULL) return -EINVAL; @@ -876,18 +904,12 @@ static int media_transport_init_source(struct media_transport *transport) transport->data = a2dp; transport->destroy = destroy_a2dp; -#ifdef TIZEN_FEATURE_BLUEZ_MODIFY - ret = avrcp_get_target_volume(transport->device, &vol); - - if (!ret) /* error none */ - a2dp->volume = vol; - else a2dp->volume = -1; - DBG("Check AVRCP volume and update it (ret [%d] vol [%d])", ret, vol); -#else - a2dp->volume = -1; +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + media_transport_init_volume(transport); #endif + transport->sink_watch = sink_add_state_cb(service, sink_state_changed, transport); -- 2.7.4