1 /******************************************************************************
2  *
3  *  Copyright 2016 The Android Open Source Project
4  *  Copyright 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 #ifndef BTIF_A2DP_SOURCE_H
21 #define BTIF_A2DP_SOURCE_H
22 
23 #include <cstdint>
24 #include <future>
25 #include <vector>
26 
27 #include "bta/include/bta_av_api.h"
28 #include "include/hardware/bt_av.h"
29 #include "stack/include/bt_hdr.h"
30 #include "types/raw_address.h"
31 
32 // Initialize the A2DP Source module.
33 // This function should be called by the BTIF state machine prior to using the
34 // module.
35 bool btif_a2dp_source_init(void);
36 
37 // Startup the A2DP Source module.
38 // This function should be called by the BTIF state machine after
39 // btif_a2dp_source_init() to prepare to start streaming.
40 bool btif_a2dp_source_startup(void);
41 
42 // Start the A2DP Source session.
43 // This function should be called by the BTIF state machine after
44 // btif_a2dp_source_startup() to start the streaming session for |peer_address|.
45 bool btif_a2dp_source_start_session(const RawAddress& peer_address,
46                                     std::promise<void> peer_ready_promise);
47 
48 // Restart the A2DP Source session.
49 // This function should be called by the BTIF state machine after
50 // btif_a2dp_source_startup() to restart the streaming session.
51 // |old_peer_address| is the peer address of the old session. This address
52 // can be empty.
53 // |new_peer_address| is the peer address of the new session. This address
54 // cannot be empty.
55 bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address,
56                                       const RawAddress& new_peer_address,
57                                       std::promise<void> peer_ready_promise);
58 
59 // End the A2DP Source session.
60 // This function should be called by the BTIF state machine to end the
61 // streaming session for |peer_address|.
62 bool btif_a2dp_source_end_session(const RawAddress& peer_address);
63 
64 // Shutdown the A2DP Source module.
65 // This function should be called by the BTIF state machine to stop streaming.
66 void btif_a2dp_source_shutdown(std::promise<void>);
67 
68 // Cleanup the A2DP Source module.
69 // This function should be called by the BTIF state machine during graceful
70 // cleanup.
71 void btif_a2dp_source_cleanup(void);
72 
73 // Check whether the A2DP Source media task is running.
74 // Returns true if the A2DP Source media task is running, otherwise false.
75 bool btif_a2dp_source_media_task_is_running(void);
76 
77 // Check whether the A2DP Source media task is shutting down.
78 // Returns true if the A2DP Source media task is shutting down.
79 bool btif_a2dp_source_media_task_is_shutting_down(void);
80 
81 // Return true if the A2DP Source module is streaming.
82 bool btif_a2dp_source_is_streaming(void);
83 
84 // Process a request to start the A2DP audio encoding task.
85 void btif_a2dp_source_start_audio_req(void);
86 
87 // Process a request to stop the A2DP audio encoding task.
88 void btif_a2dp_source_stop_audio_req(void);
89 
90 // Process a request to update the A2DP audio encoder with user preferred
91 // codec configuration.
92 // The peer address is |peer_addr|.
93 // |codec_user_config| contains the preferred codec user configuration.
94 void btif_a2dp_source_encoder_user_config_update_req(
95     const RawAddress& peer_addr,
96     const std::vector<btav_a2dp_codec_config_t>& codec_user_preferences,
97     std::promise<void> peer_ready_promise);
98 
99 // Process a request to update the A2DP audio encoding with new audio
100 // configuration feeding parameters stored in |codec_audio_config|.
101 // The fields that are used are: |codec_audio_config.sample_rate|,
102 // |codec_audio_config.bits_per_sample| and |codec_audio_config.channel_mode|.
103 void btif_a2dp_source_feeding_update_req(
104     const btav_a2dp_codec_config_t& codec_audio_config);
105 
106 // Process 'idle' request from the BTIF state machine during initialization.
107 void btif_a2dp_source_on_idle(void);
108 
109 // Process 'stop' request from the BTIF state machine to stop A2DP streaming.
110 // |p_av_suspend| is the data associated with the request - see
111 // |tBTA_AV_SUSPEND|.
112 void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);
113 
114 // Process 'suspend' request from the BTIF state machine to suspend A2DP
115 // streaming.
116 // |p_av_suspend| is the data associated with the request - see
117 // |tBTA_AV_SUSPEND|.
118 void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);
119 
120 // Enable/disable discarding of transmitted frames.
121 // If |enable| is true, the discarding is enabled, otherwise is disabled.
122 void btif_a2dp_source_set_tx_flush(bool enable);
123 
124 // Get the next A2DP buffer to send.
125 // Returns the next A2DP buffer to send if available, otherwise NULL.
126 BT_HDR* btif_a2dp_source_audio_readbuf(void);
127 
128 // Dump debug-related information for the A2DP Source module.
129 // |fd| is the file descriptor to use for writing the ASCII formatted
130 // information.
131 void btif_a2dp_source_debug_dump(int fd);
132 
133 // Set the dynamic audio buffer size
134 void btif_a2dp_source_set_dynamic_audio_buffer_size(
135     uint8_t dynamic_audio_buffer_size);
136 
137 #endif /* BTIF_A2DP_SOURCE_H */
138