1 /******************************************************************************
2  *
3  *  Copyright 2005-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This is the implementation file for advanced audio/video call-in
22  *  functions.
23  *
24  ******************************************************************************/
25 
26 #define LOG_TAG "bluetooth-a2dp"
27 
28 #include "bta/include/bta_av_ci.h"
29 
30 #include <bluetooth/log.h>
31 
32 #include <cstdint>
33 
34 #include "a2dp_constants.h"
35 #include "bta/av/bta_av_int.h"
36 #include "bta_av_api.h"
37 #include "bta_sys.h"
38 #include "osi/include/allocator.h"
39 #include "stack/include/bt_hdr.h"
40 
41 using namespace bluetooth;
42 
43 /*******************************************************************************
44  *
45  * Function         bta_av_ci_src_data_ready
46  *
47  * Description      This function sends an event to the AV indicating that
48  *                  the phone has audio stream data ready to send and AV
49  *                  should call bta_av_co_audio_source_data_path().
50  *
51  * Returns          void
52  *
53  ******************************************************************************/
bta_av_ci_src_data_ready(tBTA_AV_CHNL chnl)54 void bta_av_ci_src_data_ready(tBTA_AV_CHNL chnl) {
55   BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
56 
57   p_buf->layer_specific = chnl;
58   p_buf->event = BTA_AV_CI_SRC_DATA_READY_EVT;
59 
60   bta_sys_sendmsg(p_buf);
61 }
62 
63 /*******************************************************************************
64  *
65  * Function         bta_av_ci_setconfig
66  *
67  * Description      This function must be called in response to function
68  *                  bta_av_co_audio_setconfig().
69  *                  Parameter err_code is set to an AVDTP status value;
70  *                  AVDT_SUCCESS if the codec configuration is ok,
71  *                  otherwise error.
72  *
73  * Returns          void
74  *
75  ******************************************************************************/
bta_av_ci_setconfig(tBTA_AV_HNDL bta_av_handle,uint8_t err_code,uint8_t category,bool recfg_needed,uint8_t avdt_handle)76 void bta_av_ci_setconfig(tBTA_AV_HNDL bta_av_handle, uint8_t err_code, uint8_t category,
77                          bool recfg_needed, uint8_t avdt_handle) {
78   log::info("bta_av_handle=0x{:x} err_code={} category={} recfg_needed={} avdt_handle={}",
79             bta_av_handle, err_code, category, recfg_needed, avdt_handle);
80 
81   tBTA_AV_CI_SETCONFIG* p_buf = (tBTA_AV_CI_SETCONFIG*)osi_malloc(sizeof(tBTA_AV_CI_SETCONFIG));
82 
83   p_buf->hdr.layer_specific = bta_av_handle;
84   p_buf->hdr.event =
85           (err_code == A2DP_SUCCESS) ? BTA_AV_CI_SETCONFIG_OK_EVT : BTA_AV_CI_SETCONFIG_FAIL_EVT;
86   p_buf->err_code = err_code;
87   p_buf->category = category;
88   p_buf->recfg_needed = recfg_needed;
89   p_buf->avdt_handle = avdt_handle;
90 
91   bta_sys_sendmsg(p_buf);
92 }
93