4 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Dohyun Pyun <dh79.pyun@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include <oal-event.h>
25 #include <oal-hardware.h>
26 #include <oal-audio-src.h>
28 #include "bt-service-common.h"
29 #include "bt-service-audio-common.h"
30 #include "bt-service-event.h"
32 static unsigned int absolute_volume = 0;
33 static unsigned int bt_volume = 0;
34 static unsigned int avc_mode = BT_AVC_OFF;
36 int _bt_audio_set_absolute_volume(unsigned int volume)
38 int result = BLUETOOTH_ERROR_NONE;
40 /* 1. Translate the absolute volume to bt volume */
42 /* Convert system gain to BT
43 BT volume range : 0 ~ 127
44 system volume range : 0 ~ 150 */
46 bt_volume = 127 * volume / 150;
49 system volume : 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150
50 avrcp_ volume : 0 9 17 26 34 43 51 60 68 77 85 94 102 111 119 127 */
52 if (bt_volume > 0 && bt_volume < 127)
55 /* 2. Notify the bt_volume to transport (BT Headset) */
57 /* 3. Notify the avc mode to the pulseaudio if it is needed */
62 /* Just return the absolute_volume value */
63 int _bt_audio_get_absolute_volume(unsigned int *volume)
65 int result = BLUETOOTH_ERROR_NONE;
67 *volume = absolute_volume;
72 int _bt_audio_is_avc_activated(bool *activated)
74 *activated = (avc_mode == BT_AVC_OFF) ? false : true;
76 return BLUETOOTH_ERROR_NONE;
79 int _bt_audio_get_avc_mode(unsigned int *mode)
81 /* 1. AVC mode in the vconf value */
83 /* 2. Get active A2DP headset path */
85 /* 3. Get volume info for activae transport for the path */
89 return BLUETOOTH_ERROR_NONE;
92 int _bt_audio_notify_avc_mode_changed(unsigned int avc_mode)
94 GVariant *param = g_variant_new("(u)", avc_mode);
96 _bt_send_event(BT_AUDIO_AVC_EVENT,
97 BLUETOOTH_EVENT_AUDIO_AVC_MODE_CHANGED,
100 return BLUETOOTH_ERROR_NONE;
103 /* 1. When a2dp headset is connected, we should set 'AVC' mode into pulseaudio */
104 /* 2. If the avc mode is changed, we should inform 'AVC' mode to pulseaudio */
105 /* 3. If BT is off, we should send 'AVC' off mode event for application */
106 /* 4. If BT A2DP is disconnected, we should send 'AVC' off mode event for application */