• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2016 The Android Open Source Project
4  *  Copyright (C) 2009-2012 Broadcom Corporation
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 
20 #define LOG_TAG "bt_btif_a2dp"
21 
22 #include <stdbool.h>
23 
24 #include "audio_a2dp_hw/include/audio_a2dp_hw.h"
25 #include "bt_common.h"
26 #include "bta_av_api.h"
27 #include "btif_a2dp.h"
28 #include "btif_a2dp_control.h"
29 #include "btif_a2dp_sink.h"
30 #include "btif_a2dp_source.h"
31 #include "btif_av.h"
32 #include "btif_util.h"
33 #include "osi/include/log.h"
34 
btif_a2dp_on_idle(void)35 void btif_a2dp_on_idle(void) {
36   APPL_TRACE_WARNING("## ON A2DP IDLE ## peer_sep = %d",
37                      btif_av_get_peer_sep());
38   if (btif_av_get_peer_sep() == AVDT_TSEP_SNK) {
39     btif_a2dp_source_on_idle();
40   } else if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
41     btif_a2dp_sink_on_idle();
42   }
43 }
44 
btif_a2dp_on_started(tBTA_AV_START * p_av_start,bool pending_start)45 bool btif_a2dp_on_started(tBTA_AV_START* p_av_start, bool pending_start) {
46   bool ack = false;
47 
48   APPL_TRACE_WARNING("## ON A2DP STARTED ##");
49 
50   if (p_av_start == NULL) {
51     /* ack back a local start request */
52     btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
53     return true;
54   }
55 
56   APPL_TRACE_WARNING(
57       "%s: pending_start = %d status = %d suspending = %d initiator = %d",
58       __func__, pending_start, p_av_start->status, p_av_start->suspending,
59       p_av_start->initiator);
60 
61   if (p_av_start->status == BTA_AV_SUCCESS) {
62     if (!p_av_start->suspending) {
63       if (p_av_start->initiator) {
64         if (pending_start) {
65           btif_a2dp_command_ack(A2DP_CTRL_ACK_SUCCESS);
66           ack = true;
67         }
68       } else {
69         /* We were remotely started, make sure codec
70          * is setup before datapath is started.
71          */
72         btif_a2dp_source_setup_codec();
73       }
74 
75       /* media task is autostarted upon a2dp audiopath connection */
76     }
77   } else if (pending_start) {
78     APPL_TRACE_WARNING("%s: A2DP start request failed: status = %d", __func__,
79                        p_av_start->status);
80     btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
81     ack = true;
82   }
83   return ack;
84 }
85 
btif_a2dp_on_stopped(tBTA_AV_SUSPEND * p_av_suspend)86 void btif_a2dp_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
87   APPL_TRACE_WARNING("## ON A2DP STOPPED ##");
88 
89   if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
90     btif_a2dp_sink_on_stopped(p_av_suspend);
91     return;
92   }
93 
94   btif_a2dp_source_on_stopped(p_av_suspend);
95 }
96 
btif_a2dp_on_suspended(tBTA_AV_SUSPEND * p_av_suspend)97 void btif_a2dp_on_suspended(tBTA_AV_SUSPEND* p_av_suspend) {
98   APPL_TRACE_WARNING("## ON A2DP SUSPENDED ##");
99   if (btif_av_get_peer_sep() == AVDT_TSEP_SRC) {
100     btif_a2dp_sink_on_suspended(p_av_suspend);
101   } else {
102     btif_a2dp_source_on_suspended(p_av_suspend);
103   }
104 }
105 
btif_a2dp_on_offload_started(tBTA_AV_STATUS status)106 void btif_a2dp_on_offload_started(tBTA_AV_STATUS status) {
107   tA2DP_CTRL_ACK ack;
108   APPL_TRACE_EVENT("%s status %d", __func__, status);
109 
110   switch (status) {
111     case BTA_AV_SUCCESS:
112       ack = A2DP_CTRL_ACK_SUCCESS;
113       break;
114     case BTA_AV_FAIL_RESOURCES:
115       APPL_TRACE_ERROR("%s FAILED UNSUPPORTED", __func__);
116       ack = A2DP_CTRL_ACK_UNSUPPORTED;
117       break;
118     default:
119       APPL_TRACE_ERROR("%s FAILED: status = %d", __func__, status);
120       ack = A2DP_CTRL_ACK_FAILURE;
121       break;
122   }
123   btif_a2dp_command_ack(ack);
124 }
125 
btif_debug_a2dp_dump(int fd)126 void btif_debug_a2dp_dump(int fd) {
127   btif_a2dp_source_debug_dump(fd);
128   btif_a2dp_sink_debug_dump(fd);
129 }
130