• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <hardware/audio.h>
20 #include <system/audio.h>
21 
22 #include "device_port_proxy.h"
23 
24 constexpr unsigned int kBluetoothDefaultSampleRate = 44100;
25 constexpr audio_format_t kBluetoothDefaultAudioFormatBitsPerSample =
26     AUDIO_FORMAT_PCM_16_BIT;
27 
28 constexpr unsigned int kBluetoothDefaultInputBufferMs = 20;
29 
30 constexpr unsigned int kBluetoothDefaultOutputBufferMs = 10;
31 constexpr audio_channel_mask_t kBluetoothDefaultOutputChannelModeMask =
32     AUDIO_CHANNEL_OUT_STEREO;
33 
34 enum class BluetoothStreamState : uint8_t {
35   DISABLED = 0,  // This stream is closing or set param "suspend=true"
36   STANDBY,
37   STARTING,
38   STARTED,
39   SUSPENDING,
40   UNKNOWN,
41 };
42 
43 std::ostream& operator<<(std::ostream& os, const BluetoothStreamState& state);
44 
45 struct BluetoothStreamOut {
46   // Must be the first member so it can be cast from audio_stream
47   // or audio_stream_out pointer
48   audio_stream_out stream_out_;
49   ::android::bluetooth::audio::BluetoothAudioPortOut bluetooth_output_;
50   int64_t last_write_time_us_;
51   // Audio PCM Configs
52   uint32_t sample_rate_;
53   audio_channel_mask_t channel_mask_;
54   audio_format_t format_;
55   // frame is the number of samples per channel
56   // frames count per tick
57   size_t frames_count_;
58   // total frames written, reset on standby
59   uint64_t frames_rendered_;
60   // total frames written after opened, never reset
61   uint64_t frames_presented_;
62   mutable std::mutex mutex_;
63 };
64 
65 int adev_open_output_stream(struct audio_hw_device* dev,
66                             audio_io_handle_t handle, audio_devices_t devices,
67                             audio_output_flags_t flags,
68                             struct audio_config* config,
69                             struct audio_stream_out** stream_out,
70                             const char* address __unused);
71 
72 void adev_close_output_stream(struct audio_hw_device* dev,
73                               struct audio_stream_out* stream);
74 
75 size_t adev_get_input_buffer_size(const struct audio_hw_device* dev,
76                                   const struct audio_config* config);
77 
78 int adev_open_input_stream(struct audio_hw_device* dev,
79                            audio_io_handle_t handle, audio_devices_t devices,
80                            struct audio_config* config,
81                            struct audio_stream_in** stream_in,
82                            audio_input_flags_t flags __unused,
83                            const char* address __unused,
84                            audio_source_t source __unused);
85 
86 void adev_close_input_stream(struct audio_hw_device* dev,
87                              struct audio_stream_in* in);
88