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 RawAddress& peer_address, 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(const RawAddress& peer_address);
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(const RawAddress& peer_addr,
65                                      const btav_a2dp_codec_config_t& codec_user_config,
66                                      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(const btav_a2dp_codec_config_t& codec_audio_config);
73 
74 // Initializes the control block.
75 // |codec_priorities| contains the A2DP Source codec priorities to use.
76 // |supported_codecs| returns the list of supported A2DP Source codecs.
77 void bta_av_co_init(const std::vector<btav_a2dp_codec_config_t>& codec_priorities,
78                     std::vector<btav_a2dp_codec_info_t>* supported_codecs);
79 
80 // Checks whether the codec for |codec_index| is supported.
81 // Returns true if the codec is supported, otherwise false.
82 bool bta_av_co_is_supported_codec(btav_a2dp_codec_index_t codec_index);
83 
84 // Gets the current A2DP codec for the active peer.
85 // Returns a pointer to the current |A2dpCodecConfig| if valid, otherwise
86 // nullptr.
87 A2dpCodecConfig* bta_av_get_a2dp_current_codec(void);
88 
89 // Gets the current A2DP codec for a peer identified by |peer_address|.
90 // Returns a pointer to the current |A2dpCodecConfig| if valid, otherwise
91 // nullptr.
92 A2dpCodecConfig* bta_av_get_a2dp_peer_current_codec(const RawAddress& peer_address);
93 
94 // Gets the A2DP effective frame size from the current encoder.
95 // Returns the effective frame size if the encoder is configured, otherwise 0.
96 int bta_av_co_get_encoder_effective_frame_size(const RawAddress& peer_address);
97 
98 // Gets the preferred encoding interval from the current encoder.
99 // Returns the preferred encoding interval if the encoder is configured,
100 // otherwise 0.
101 int bta_av_co_get_encoder_preferred_interval_us();
102 
103 // Dump A2DP codec debug-related information for the A2DP module.
104 // |fd| is the file descriptor to use for writing the ASCII formatted
105 // information.
106 void btif_a2dp_codec_debug_dump(int fd);
107 
108 /**
109  * Retrieves the cached codec config for the input peer address.
110  * @param peer_address peer address of the remote device.
111  * @return the codec configuration for the corresponding peer address.
112  */
113 uint8_t* bta_av_co_get_codec_config(const RawAddress& peer_address);
114 
115 #endif  // BTIF_AV_CO_H
116