-/* 1. When a2dp headset is connected, we should set 'AVC' mode internaly */
-/* 2. If the avc mode is changed, we should inform 'AVC' mode to pulseaudio */
-/* 3. If BT is off, we should send 'AVC' off mode event for application */
-/* 4. If BT A2DP is disconnected, we should send 'AVC' off mode event for application */
-/* 5. When we recieve the volume changed, we shuld sync up the volume */
+void _bt_audio_handle_adapter_disabled(void)
+{
+ BT_DBG("Reset AVC mode, and volume");
+
+ absolute_volume = ABSOLUTE_VOLUME_MAX + 1;
+ bt_volume = BT_VOLUME_MAX + 1;
+ __bt_audio_set_avc_mode(BT_AVC_OFF);
+ return;
+}
+
+void _bt_audio_handle_a2dp_state_changed(const char *address, bool connected)
+{
+ unsigned int mode = 0;
+
+#ifdef AVC_DEBUG
+ BT_DBG("+");
+#endif
+
+ /* In later, we can check the event for the active headset or not in here */
+
+ if (connected == false) {
+ BT_DBG("Reset AVC mode, and volume");
+
+ absolute_volume = ABSOLUTE_VOLUME_MAX + 1;
+ bt_volume = BT_VOLUME_MAX + 1;
+ __bt_audio_set_avc_mode(BT_AVC_OFF);
+ return;
+ }
+
+ if (_bt_audio_get_avc_mode(&mode) != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Fail to get the avc mode");
+ return;
+ }
+
+ if (mode != BT_AVC_OFF) {
+ __bt_audio_set_avc_mode(mode);
+
+ /* Send the initial volume to application */
+ _bt_send_event(BT_AVRCP_EVENT,
+ BLUETOOTH_EVENT_AVRCP_VOLUME_CHANGED,
+ g_variant_new("(u)", absolute_volume));
+ }
+}
+
+void _bt_audio_handle_transport_volume_changed(unsigned int bt_vol)
+{
+ unsigned int sys_vol = 0;
+ int mode = BT_AVC_OFF;
+ unsigned int prev_vol = absolute_volume;
+
+#ifdef AVC_DEBUG
+ BT_DBG("+");
+#endif
+
+ if (bt_vol > BT_VOLUME_MAX) {
+ /* BT AVC mode off, because bluez transport initiate the volue as MAX */
+ absolute_volume = ABSOLUTE_VOLUME_MAX + 1;
+ bt_volume = BT_VOLUME_MAX + 1;
+ __bt_audio_set_avc_mode(BT_AVC_OFF);
+ return;
+ }
+
+ __bt_audio_covert_bt_to_system_volume(bt_vol, &sys_vol);
+
+ bt_volume = bt_vol;
+ absolute_volume = sys_vol;
+
+ mode = (absolute_volume == 0) ? BT_AVC_NULL : BT_AVC_MAX;
+
+ __bt_audio_set_avc_mode(mode);
+
+ if (prev_vol == absolute_volume) {
+ BT_DBG("Same volume level");
+ return;
+ }
+
+ _bt_send_event(BT_AVRCP_EVENT,
+ BLUETOOTH_EVENT_AVRCP_VOLUME_CHANGED,
+ g_variant_new("(u)", absolute_volume));
+}