1 /******************************************************************************
2  *
3  *  Copyright 2009-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 #ifndef BTIF_AV_CO_H
20 #define BTIF_AV_CO_H
21 
22 #include "btif/include/btif_a2dp_source.h"
23 #include "stack/include/a2dp_codec_api.h"
24 #include "types/raw_address.h"
25 
26 // Sets the active peer to |peer_addr|.
27 // Returns true on success, otherwise false.
28 bool bta_av_co_set_active_peer(const RawAddress& peer_addr);
29 
30 /**
31  * Sets the active peer within the sink profile of the bta av co instance.
32  * @param peer_address peer address of the remote device.
33  * @return true on success, otherwise false.
34  */
35 bool bta_av_co_set_active_sink_peer(const RawAddress& peer_address);
36 
37 /**
38  * Sets the active peer within the sink profile of the bta av co instance.
39  * @param peer_address peer address of the remote device.
40  * @return true on success, otherwise false.
41  */
42 bool bta_av_co_set_active_source_peer(const RawAddress& peer_address);
43 
44 void bta_av_co_save_codec(const uint8_t* new_codec_config);
45 
46 // Gets the A2DP peer parameters that are used to initialize the encoder.
47 // The peer address is |peer_addr|.
48 // The parameters are stored in |p_peer_params|.
49 // |p_peer_params| cannot be null.
50 void bta_av_co_get_peer_params(const RawAddress& peer_addr,
51                                tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params);
52 
53 // Gets the current A2DP encoder interface that can be used to encode and
54 // prepare A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
55 // Returns the A2DP encoder interface if the current codec is setup,
56 // otherwise NULL.
57 const tA2DP_ENCODER_INTERFACE* bta_av_co_get_encoder_interface(void);
58 
59 // Sets the user preferred codec configuration.
60 // The peer address is |peer_addr|.
61 // |codec_user_config| contains the preferred codec configuration.
62 // |restart_output| is used to know whether AV is reconfiguring with remote.
63 // Returns true on success, otherwise false.
64 bool bta_av_co_set_codec_user_config(
65     const RawAddress& peer_addr,
66     const btav_a2dp_codec_config_t& codec_user_config, bool* p_restart_output);
67 
68 // Sets the Audio HAL selected audio feeding parameters.
69 // Those parameters are applied only to the currently selected codec.
70 // |codec_audio_config| contains the selected audio feeding configuration.
71 // Returns true on success, otherwise false.
72 bool bta_av_co_set_codec_audio_config(
73     const btav_a2dp_codec_config_t& codec_audio_config);
74 
75 // Initializes the control block.
76 // |codec_priorities| contains the A2DP Source codec priorities to use.
77 // |supported_codecs| returns the list of supported A2DP Source codecs.
78 void bta_av_co_init(
79     const std::vector<btav_a2dp_codec_config_t>& codec_priorities,
80     std::vector<btav_a2dp_codec_info_t>* supported_codecs);
81 
82 // Checks whether the codec for |codec_index| is supported.
83 // Returns true if the codec is supported, otherwise false.
84 bool bta_av_co_is_supported_codec(btav_a2dp_codec_index_t codec_index);
85 
86 // Gets the current A2DP codec for the active peer.
87 // Returns a pointer to the current |A2dpCodecConfig| if valid, otherwise
88 // nullptr.
89 A2dpCodecConfig* bta_av_get_a2dp_current_codec(void);
90 
91 // Gets the current A2DP codec for a peer identified by |peer_address|.
92 // Returns a pointer to the current |A2dpCodecConfig| if valid, otherwise
93 // nullptr.
94 A2dpCodecConfig* bta_av_get_a2dp_peer_current_codec(
95     const RawAddress& peer_address);
96 
97 // Gets the A2DP effective frame size from the current encoder.
98 // Returns the effective frame size if the encoder is configured, otherwise 0.
99 int bta_av_co_get_encoder_effective_frame_size();
100 
101 // Dump A2DP codec debug-related information for the A2DP module.
102 // |fd| is the file descriptor to use for writing the ASCII formatted
103 // information.
104 void btif_a2dp_codec_debug_dump(int fd);
105 
106 #endif  // BTIF_AV_CO_H
107