1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __BTC_AV_CO_H__
16 #define __BTC_AV_CO_H__
17 
18 #include "btc_a2dp.h"
19 #include "bta/bta_av_co.h"
20 
21 #if (BTA_AV_INCLUDED == TRUE)
22 /*******************************************************************************
23 **  Constants & Macros
24 ********************************************************************************/
25 
26 enum {
27     BTC_SV_AV_AA_SBC_INDEX = 0,
28     BTC_SV_AV_AA_SBC_SINK_INDEX,
29     BTC_SV_AV_AA_SEP_INDEX  /* Last index */
30 };
31 
32 /*****************************************************************************
33 **  Local data
34 *****************************************************************************/
35 typedef struct {
36     UINT8 sep_info_idx;                 /* local SEP index (in BTA tables) */
37     UINT8 seid;                         /* peer SEP index (in peer tables) */
38     UINT8 codec_type;                   /* peer SEP codec type */
39     UINT8 codec_caps[AVDT_CODEC_SIZE];  /* peer SEP codec capabilities */
40     UINT8 num_protect;                  /* peer SEP number of CP elements */
41     UINT8 protect_info[BTA_AV_CP_INFO_LEN];  /* peer SEP content protection info */
42 } tBTA_AV_CO_SINK;
43 
44 typedef struct {
45     BD_ADDR         addr;               /* address of audio/video peer */
46     tBTA_AV_CO_SINK snks[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported sinks */
47     tBTA_AV_CO_SINK srcs[BTC_SV_AV_AA_SEP_INDEX]; /* array of supported srcs */
48     UINT8           num_snks;           /* total number of sinks at peer */
49     UINT8           num_srcs;           /* total number of srcs at peer */
50     UINT8           num_seps;           /* total number of seids at peer */
51     UINT8           num_rx_snks;        /* number of received sinks */
52     UINT8           num_rx_srcs;        /* number of received srcs */
53     UINT8           num_sup_snks;       /* number of supported sinks in the snks array */
54     UINT8           num_sup_srcs;       /* number of supported srcs in the srcs array */
55     tBTA_AV_CO_SINK *p_snk;             /* currently selected sink */
56     tBTA_AV_CO_SINK *p_src;             /* currently selected src */
57     UINT8           codec_cfg[AVDT_CODEC_SIZE]; /* current codec configuration */
58     BOOLEAN         cp_active;          /* current CP configuration */
59     BOOLEAN         acp;                /* acceptor */
60     BOOLEAN         recfg_needed;       /* reconfiguration is needed */
61     BOOLEAN         opened;             /* opened */
62     UINT16          mtu;                /* maximum transmit unit size */
63     UINT16          uuid_to_connect;    /* uuid of peer device */
64 } tBTA_AV_CO_PEER;
65 
66 typedef struct {
67     BOOLEAN active;
68     UINT8 flag;
69 } tBTA_AV_CO_CP;
70 
71 typedef struct {
72     /* Connected peer information */
73     tBTA_AV_CO_PEER peers[BTA_AV_NUM_STRS];
74     /* Current codec configuration - access to this variable must be protected */
75     tBTC_AV_CODEC_INFO codec_cfg;
76     tBTC_AV_CODEC_INFO codec_cfg_setconfig; /* remote peer setconfig preference */
77 
78     tBTA_AV_CO_CP cp;
79 } tBTA_AV_CO_CB;
80 
81 /* Control block instance */
82 #if AVRC_DYNAMIC_MEMORY == FALSE
83 extern tBTA_AV_CO_CB bta_av_co_cb;
84 #else
85 extern tBTA_AV_CO_CB *bta_av_co_cb_ptr;
86 #define bta_av_co_cb (*bta_av_co_cb_ptr)
87 #endif
88 /*******************************************************************************
89 **  Functions
90 ********************************************************************************/
91 
92 /*******************************************************************************
93  **
94  ** Function         bta_av_co_cp_is_active
95  **
96  ** Description      Get the current configuration of content protection
97  **
98  ** Returns          TRUE if the current streaming has CP, FALSE otherwise
99  **
100  *******************************************************************************/
101 BOOLEAN bta_av_co_cp_is_active(void);
102 
103 /*******************************************************************************
104  **
105  ** Function         bta_av_co_cp_get_flag
106  **
107  ** Description      Get content protection flag
108  **                  BTA_AV_CP_SCMS_COPY_NEVER
109  **                  BTA_AV_CP_SCMS_COPY_ONCE
110  **                  BTA_AV_CP_SCMS_COPY_FREE
111  **
112  ** Returns          The current flag value
113  **
114  *******************************************************************************/
115 UINT8 bta_av_co_cp_get_flag(void);
116 
117 /*******************************************************************************
118  **
119  ** Function         bta_av_co_cp_set_flag
120  **
121  ** Description      Set content protection flag
122  **                  BTA_AV_CP_SCMS_COPY_NEVER
123  **                  BTA_AV_CP_SCMS_COPY_ONCE
124  **                  BTA_AV_CP_SCMS_COPY_FREE
125  **
126  ** Returns          TRUE if setting the SCMS flag is supported else FALSE
127  **
128  *******************************************************************************/
129 BOOLEAN bta_av_co_cp_set_flag(UINT8 cp_flag);
130 
131 /*******************************************************************************
132  **
133  ** Function         bta_av_co_audio_codec_reset
134  **
135  ** Description      Reset the current codec configuration
136  **
137  ** Returns          void
138  **
139  *******************************************************************************/
140 void bta_av_co_audio_codec_reset(void);
141 
142 /*******************************************************************************
143  **
144  ** Function         bta_av_co_audio_codec_supported
145  **
146  ** Description      Check if all opened connections are compatible with a codec
147  **                  configuration
148  **
149  ** Returns          TRUE if all opened devices support this codec, FALSE otherwise
150  **
151  *******************************************************************************/
152 BOOLEAN bta_av_co_audio_codec_supported(tBTC_AV_STATUS *p_status);
153 
154 /*******************************************************************************
155  **
156  ** Function         bta_av_co_audio_set_codec
157  **
158  ** Description      Set the current codec configuration from the feeding type.
159  **                  This function is starting to modify the configuration, it
160  **                  should be protected.
161  **
162  ** Returns          TRUE if successful, FALSE otherwise
163  **
164  *******************************************************************************/
165 BOOLEAN bta_av_co_audio_set_codec(const tBTC_AV_MEDIA_FEEDINGS *p_feeding, tBTC_AV_STATUS *p_status);
166 
167 /*******************************************************************************
168  **
169  ** Function         bta_av_co_audio_get_sbc_config
170  **
171  ** Description      Retrieves the SBC codec configuration.  If the codec in use
172  **                  is not SBC, return the default SBC codec configuration.
173  **
174  ** Returns          TRUE if codec is SBC, FALSE otherwise
175  **
176  *******************************************************************************/
177 BOOLEAN bta_av_co_audio_get_sbc_config(tA2D_SBC_CIE *p_sbc_config, UINT16 *p_minmtu);
178 
179 /*******************************************************************************
180  **
181  ** Function         bta_av_co_audio_discard_config
182  **
183  ** Description      Discard the codec configuration of a connection
184  **
185  ** Returns          Nothing
186  **
187  *******************************************************************************/
188 void bta_av_co_audio_discard_config(tBTA_AV_HNDL hndl);
189 
190 /*******************************************************************************
191  **
192  ** Function         bta_av_co_init
193  **
194  ** Description      Initialization
195  **
196  ** Returns          Nothing
197  **
198  *******************************************************************************/
199 void bta_av_co_init(void);
200 
201 
202 /*******************************************************************************
203  **
204  ** Function         bta_av_co_peer_cp_supported
205  **
206  ** Description      Checks if the peer supports CP
207  **
208  ** Returns          TRUE if the peer supports CP
209  **
210  *******************************************************************************/
211 BOOLEAN bta_av_co_peer_cp_supported(tBTA_AV_HNDL hndl);
212 
213 /*******************************************************************************
214  **
215  ** Function         bta_av_co_get_remote_bitpool_pref
216  **
217  ** Description      Check if remote side did a setconfig within the limits
218  **                  of our exported bitpool range. If set we will set the
219  **                  remote preference.
220  **
221  ** Returns          TRUE if config set, FALSE otherwize
222  **
223  *******************************************************************************/
224 BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max);
225 
226 #endif  ///BTA_AV_INCLUDED == TRUE
227 
228 #endif
229