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