Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2016 The Android Open Source Project |
| 4 | * Copyright 2009-2012 Broadcom Corporation |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 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 <stdbool.h> |
Cheney Ni | f0999d8 | 2018-12-19 18:46:18 +0800 | [diff] [blame] | 24 | #include <future> |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 25 | |
| 26 | #include "bta_av_api.h" |
| 27 | |
Pavlin Radoslavov | ee164d2 | 2018-02-23 09:04:57 -0800 | [diff] [blame] | 28 | // Initialize the A2DP Source module. |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 29 | // This function should be called by the BTIF state machine prior to using the |
| 30 | // module. |
Pavlin Radoslavov | ee164d2 | 2018-02-23 09:04:57 -0800 | [diff] [blame] | 31 | bool btif_a2dp_source_init(void); |
| 32 | |
| 33 | // Startup the A2DP Source module. |
| 34 | // This function should be called by the BTIF state machine after |
| 35 | // btif_a2dp_source_init() to prepare to start streaming. |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 36 | bool btif_a2dp_source_startup(void); |
| 37 | |
Pavlin Radoslavov | 03adb3f | 2018-03-20 16:50:57 -0700 | [diff] [blame] | 38 | // Start the A2DP Source session. |
| 39 | // This function should be called by the BTIF state machine after |
| 40 | // btif_a2dp_source_startup() to start the streaming session for |peer_address|. |
Cheney Ni | f0999d8 | 2018-12-19 18:46:18 +0800 | [diff] [blame] | 41 | bool btif_a2dp_source_start_session(const RawAddress& peer_address, |
| 42 | std::promise<void> peer_ready_promise); |
Pavlin Radoslavov | 03adb3f | 2018-03-20 16:50:57 -0700 | [diff] [blame] | 43 | |
Pavlin Radoslavov | c7a5e60 | 2018-05-10 09:52:58 -0700 | [diff] [blame] | 44 | // Restart the A2DP Source session. |
| 45 | // This function should be called by the BTIF state machine after |
| 46 | // btif_a2dp_source_startup() to restart the streaming session. |
| 47 | // |old_peer_address| is the peer address of the old session. This address |
| 48 | // can be empty. |
| 49 | // |new_peer_address| is the peer address of the new session. This address |
| 50 | // cannot be empty. |
| 51 | bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address, |
Cheney Ni | f0999d8 | 2018-12-19 18:46:18 +0800 | [diff] [blame] | 52 | const RawAddress& new_peer_address, |
| 53 | std::promise<void> peer_ready_promise); |
Pavlin Radoslavov | c7a5e60 | 2018-05-10 09:52:58 -0700 | [diff] [blame] | 54 | |
Pavlin Radoslavov | 03adb3f | 2018-03-20 16:50:57 -0700 | [diff] [blame] | 55 | // End the A2DP Source session. |
| 56 | // This function should be called by the BTIF state machine to end the |
| 57 | // streaming session for |peer_address|. |
| 58 | bool btif_a2dp_source_end_session(const RawAddress& peer_address); |
| 59 | |
Pavlin Radoslavov | ee164d2 | 2018-02-23 09:04:57 -0800 | [diff] [blame] | 60 | // Shutdown the A2DP Source module. |
| 61 | // This function should be called by the BTIF state machine to stop streaming. |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 62 | void btif_a2dp_source_shutdown(void); |
| 63 | |
Pavlin Radoslavov | ee164d2 | 2018-02-23 09:04:57 -0800 | [diff] [blame] | 64 | // Cleanup the A2DP Source module. |
| 65 | // This function should be called by the BTIF state machine during graceful |
| 66 | // cleanup. |
| 67 | void btif_a2dp_source_cleanup(void); |
| 68 | |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 69 | // Check whether the A2DP Source media task is running. |
| 70 | // Returns true if the A2DP Source media task is running, otherwise false. |
| 71 | bool btif_a2dp_source_media_task_is_running(void); |
| 72 | |
| 73 | // Check whether the A2DP Source media task is shutting down. |
| 74 | // Returns true if the A2DP Source media task is shutting down. |
| 75 | bool btif_a2dp_source_media_task_is_shutting_down(void); |
| 76 | |
| 77 | // Return true if the A2DP Source module is streaming. |
| 78 | bool btif_a2dp_source_is_streaming(void); |
| 79 | |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 80 | // Process a request to start the A2DP audio encoding task. |
Pavlin Radoslavov | 1394c19 | 2016-10-02 18:34:46 -0700 | [diff] [blame] | 81 | void btif_a2dp_source_start_audio_req(void); |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 82 | |
| 83 | // Process a request to stop the A2DP audio encoding task. |
Pavlin Radoslavov | 1394c19 | 2016-10-02 18:34:46 -0700 | [diff] [blame] | 84 | void btif_a2dp_source_stop_audio_req(void); |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 85 | |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 86 | // Process a request to update the A2DP audio encoder with user preferred |
| 87 | // codec configuration. |
Pavlin Radoslavov | d752229 | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 88 | // The peer address is |peer_addr|. |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 89 | // |codec_user_config| contains the preferred codec user configuration. |
| 90 | void btif_a2dp_source_encoder_user_config_update_req( |
Pavlin Radoslavov | d752229 | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 91 | const RawAddress& peer_addr, |
Pavlin Radoslavov | 5ce0116 | 2016-12-05 13:02:26 -0800 | [diff] [blame] | 92 | const btav_a2dp_codec_config_t& codec_user_config); |
| 93 | |
| 94 | // Process a request to update the A2DP audio encoding with new audio |
| 95 | // configuration feeding parameters stored in |codec_audio_config|. |
| 96 | // The fields that are used are: |codec_audio_config.sample_rate|, |
| 97 | // |codec_audio_config.bits_per_sample| and |codec_audio_config.channel_mode|. |
| 98 | void btif_a2dp_source_feeding_update_req( |
| 99 | const btav_a2dp_codec_config_t& codec_audio_config); |
| 100 | |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 101 | // Process 'idle' request from the BTIF state machine during initialization. |
| 102 | void btif_a2dp_source_on_idle(void); |
| 103 | |
| 104 | // Process 'stop' request from the BTIF state machine to stop A2DP streaming. |
| 105 | // |p_av_suspend| is the data associated with the request - see |
| 106 | // |tBTA_AV_SUSPEND|. |
Pavlin Radoslavov | 397e5a5 | 2016-10-14 16:13:54 -0700 | [diff] [blame] | 107 | void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend); |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 108 | |
| 109 | // Process 'suspend' request from the BTIF state machine to suspend A2DP |
| 110 | // streaming. |
| 111 | // |p_av_suspend| is the data associated with the request - see |
| 112 | // |tBTA_AV_SUSPEND|. |
Pavlin Radoslavov | 397e5a5 | 2016-10-14 16:13:54 -0700 | [diff] [blame] | 113 | void btif_a2dp_source_on_suspended(tBTA_AV_SUSPEND* p_av_suspend); |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 114 | |
| 115 | // Enable/disable discarding of transmitted frames. |
| 116 | // If |enable| is true, the discarding is enabled, otherwise is disabled. |
| 117 | void btif_a2dp_source_set_tx_flush(bool enable); |
| 118 | |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 119 | // Get the next A2DP buffer to send. |
| 120 | // Returns the next A2DP buffer to send if available, otherwise NULL. |
Pavlin Radoslavov | 397e5a5 | 2016-10-14 16:13:54 -0700 | [diff] [blame] | 121 | BT_HDR* btif_a2dp_source_audio_readbuf(void); |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 122 | |
| 123 | // Dump debug-related information for the A2DP Source module. |
| 124 | // |fd| is the file descriptor to use for writing the ASCII formatted |
| 125 | // information. |
| 126 | void btif_a2dp_source_debug_dump(int fd); |
| 127 | |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 128 | #endif /* BTIF_A2DP_SOURCE_H */ |