summaryrefslogtreecommitdiff
path: root/system/btif/include/btif_a2dp_sink.h
blob: af98b9c5fd672ba3af3772984a1af10297f9dfc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/******************************************************************************
 *
 *  Copyright 2016 The Android Open Source Project
 *  Copyright 2009-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#ifndef BTIF_A2DP_SINK_H
#define BTIF_A2DP_SINK_H

#include <cstdint>
#include <future>

#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "bta/include/bta_av_api.h"
#include "stack/include/bt_hdr.h"
#include "types/raw_address.h"

//
// Audio focus state for audio track.
//
// NOTE: The values must be same as:
//  - A2dpSinkStreamingStateMachine.STATE_FOCUS_LOST = 0
//  - A2dpSinkStreamingStateMachine.STATE_FOCUS_GRANTED = 1
//
typedef enum {
  BTIF_A2DP_SINK_FOCUS_NOT_GRANTED = 0,
  BTIF_A2DP_SINK_FOCUS_GRANTED = 1
} btif_a2dp_sink_focus_state_t;

// Initialize the A2DP Sink module.
// This function should be called by the BTIF state machine prior to using the
// module.
bool btif_a2dp_sink_init(void);

// Startup the A2DP Sink module.
// This function should be called by the BTIF state machine after
// btif_a2dp_sink_init() to prepare for receiving and processing audio
// streaming.
bool btif_a2dp_sink_startup(void);

// Start the A2DP Sink session.
// This function should be called by the BTIF state machine after
// btif_a2dp_sink_startup() to start the streaming session for |peer_address|.
bool btif_a2dp_sink_start_session(const RawAddress& peer_address,
                                  std::promise<void> peer_ready_promise);

// Restart the A2DP Sink session.
// This function should be called by the BTIF state machine after
// btif_a2dp_sink_startup() to restart the streaming session.
// |old_peer_address| is the peer address of the old session. This address
// can be empty.
// |new_peer_address| is the peer address of the new session. This address
// cannot be empty.
bool btif_a2dp_sink_restart_session(const RawAddress& old_peer_address,
                                    const RawAddress& new_peer_address,
                                    std::promise<void> peer_ready_promise);

// End the A2DP Sink session.
// This function should be called by the BTIF state machine to end the
// streaming session for |peer_address|.
bool btif_a2dp_sink_end_session(const RawAddress& peer_address);

// Shutdown the A2DP Sink module.
// This function should be called by the BTIF state machine before
// btif_a2dp_sink_cleanup() to shutdown the processing of the audio streaming.
void btif_a2dp_sink_shutdown(void);

// Cleanup the A2DP Sink module.
// This function should be called by the BTIF state machine during graceful
// cleanup.
void btif_a2dp_sink_cleanup(void);

// Get the audio sample rate for the A2DP Sink module.
tA2DP_SAMPLE_RATE btif_a2dp_sink_get_sample_rate(void);

// Get the audio channel count for the A2DP Sink module.
tA2DP_CHANNEL_COUNT btif_a2dp_sink_get_channel_count(void);

// Get the audio bits per sample for the A2DP Sink module.
tA2DP_BITS_PER_SAMPLE btif_a2dp_sink_get_bits_per_sample(void);

// Update the decoder for the A2DP Sink module.
// |p_codec_info| contains the new codec information.
void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info);

// Process 'idle' request from the BTIF state machine during initialization.
void btif_a2dp_sink_on_idle(void);

// Process 'stop' request from the BTIF state machine to stop A2DP streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);

// Process 'suspend' request from the BTIF state machine to suspend A2DP
// streaming.
// |p_av_suspend| is the data associated with the request - see
// |tBTA_AV_SUSPEND|.
void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);

// Start the decoder for the A2DP Sink module.
bool btif_a2dp_sink_on_start(void);

// Enable/disable discarding of received A2DP frames.
// If |enable| is true, the discarding is enabled, otherwise is disabled.
void btif_a2dp_sink_set_rx_flush(bool enable);

// Enqueue a buffer to the A2DP Sink queue. If the queue has reached its
// maximum size |MAX_INPUT_A2DP_FRAME_QUEUE_SZ|, the oldest buffer is
// removed from the queue.
// |p_buf| is the buffer to enqueue.
// Returns the number of buffers in the Sink queue after the enqueing.
uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_buf);

// Dump debug-related information for the A2DP Sink module.
// |fd| is the file descriptor to use for writing the ASCII formatted
// information.
void btif_a2dp_sink_debug_dump(int fd);

// Create a request to set the audio focus state for the audio track.
// |state| is the new state value - see |btif_a2dp_sink_focus_state_t|
// for valid values.
void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state);

// Set the audio track gain for the audio track.
// |gain| is the audio track gain value to use.
void btif_a2dp_sink_set_audio_track_gain(float gain);

#endif /* BTIF_A2DP_SINK_H */