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