1 /******************************************************************************
2  *
3  *  Copyright (C) 2016 The Android Open Source Project
4  *  Copyright (C) 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_SINK_H
21 #define BTIF_A2DP_SINK_H
22 
23 #include <inttypes.h>
24 #include <stdbool.h>
25 
26 #include "bt_types.h"
27 #include "bta_av_api.h"
28 
29 //
30 // Audio focus state for audio track.
31 //
32 // NOTE: The values must be same as:
33 //  - A2dpSinkStreamingStateMachine.STATE_FOCUS_LOST = 0
34 //  - A2dpSinkStreamingStateMachine.STATE_FOCUS_GRANTED = 1
35 //
36 typedef enum {
37   BTIF_A2DP_SINK_FOCUS_NOT_GRANTED = 0,
38   BTIF_A2DP_SINK_FOCUS_GRANTED = 1
39 } btif_a2dp_sink_focus_state_t;
40 
41 // Initialize and startup the A2DP Sink module.
42 // This function should be called by the BTIF state machine prior to using the
43 // module.
44 bool btif_a2dp_sink_startup(void);
45 
46 // Shutdown and cleanup the A2DP Sink module.
47 // This function should be called by the BTIF state machine during
48 // graceful shutdown and cleanup.
49 void btif_a2dp_sink_shutdown(void);
50 
51 // Get the audio sample rate for the A2DP Sink module.
52 tA2DP_SAMPLE_RATE btif_a2dp_sink_get_sample_rate(void);
53 
54 // Get the audio channel count for the A2DP Sink module.
55 tA2DP_CHANNEL_COUNT btif_a2dp_sink_get_channel_count(void);
56 
57 // Update the decoder for the A2DP Sink module.
58 // |p_codec_info| contains the new codec information.
59 void btif_a2dp_sink_update_decoder(const uint8_t* p_codec_info);
60 
61 // Process 'idle' request from the BTIF state machine during initialization.
62 void btif_a2dp_sink_on_idle(void);
63 
64 // Process 'stop' request from the BTIF state machine to stop A2DP streaming.
65 // |p_av_suspend| is the data associated with the request - see
66 // |tBTA_AV_SUSPEND|.
67 void btif_a2dp_sink_on_stopped(tBTA_AV_SUSPEND* p_av_suspend);
68 
69 // Process 'suspend' request from the BTIF state machine to suspend A2DP
70 // streaming.
71 // |p_av_suspend| is the data associated with the request - see
72 // |tBTA_AV_SUSPEND|.
73 void btif_a2dp_sink_on_suspended(tBTA_AV_SUSPEND* p_av_suspend);
74 
75 // Enable/disable discarding of received A2DP frames.
76 // If |enable| is true, the discarding is enabled, otherwise is disabled.
77 void btif_a2dp_sink_set_rx_flush(bool enable);
78 
79 // Enqueue a buffer to the A2DP Sink queue. If the queue has reached its
80 // maximum size |MAX_INPUT_A2DP_FRAME_QUEUE_SZ|, the oldest buffer is
81 // removed from the queue.
82 // |p_buf| is the buffer to enqueue.
83 // Returns the number of buffers in the Sink queue after the enqueing.
84 uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_buf);
85 
86 // Dump debug-related information for the A2DP Sink module.
87 // |fd| is the file descriptor to use for writing the ASCII formatted
88 // information.
89 void btif_a2dp_sink_debug_dump(int fd);
90 
91 // Update the A2DP Sink related metrics.
92 // This function should be called before collecting the metrics.
93 void btif_a2dp_sink_update_metrics(void);
94 
95 // Create a request to set the audio focus state for the audio track.
96 // |state| is the new state value - see |btif_a2dp_sink_focus_state_t|
97 // for valid values.
98 void btif_a2dp_sink_set_focus_state_req(btif_a2dp_sink_focus_state_t state);
99 
100 // Set the audio track gain for the audio track.
101 // |gain| is the audio track gain value to use.
102 void btif_a2dp_sink_set_audio_track_gain(float gain);
103 
104 #endif /* BTIF_A2DP_SINK_H */
105