Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef ANDROID_AUDIO_HW_DEVICE_H |
| 19 | #define ANDROID_AUDIO_HW_DEVICE_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <sys/types.h> |
| 24 | |
jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 25 | #include <android/media/audio/common/AudioMMapPolicyInfo.h> |
| 26 | #include <android/media/audio/common/AudioMMapPolicyType.h> |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 27 | #include <media/audiohal/DeviceHalInterface.h> |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 28 | #include <utils/Errors.h> |
| 29 | #include <system/audio.h> |
| 30 | |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 31 | namespace android { |
| 32 | |
| 33 | class AudioStreamOut; |
| 34 | |
| 35 | class AudioHwDevice { |
| 36 | public: |
| 37 | enum Flags { |
| 38 | AHWD_CAN_SET_MASTER_VOLUME = 0x1, |
| 39 | AHWD_CAN_SET_MASTER_MUTE = 0x2, |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 40 | // Means that this isn't a terminal module, and software patches |
| 41 | // are used to transport audio data further. |
| 42 | AHWD_IS_INSERT = 0x4, |
Eric Laurent | 5205764 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 43 | // This Module supports BT Latency mode control |
| 44 | AHWD_SUPPORTS_BT_LATENCY_MODES = 0x8, |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | AudioHwDevice(audio_module_handle_t handle, |
| 48 | const char *moduleName, |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 49 | const sp<DeviceHalInterface>& hwDevice, |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 50 | Flags flags) |
| 51 | : mHandle(handle) |
| 52 | , mModuleName(strdup(moduleName)) |
| 53 | , mHwDevice(hwDevice) |
| 54 | , mFlags(flags) { } |
| 55 | virtual ~AudioHwDevice() { free((void *)mModuleName); } |
| 56 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 57 | [[nodiscard]] bool canSetMasterVolume() const { |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 58 | return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME)); |
| 59 | } |
| 60 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 61 | [[nodiscard]] bool canSetMasterMute() const { |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 62 | return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE)); |
| 63 | } |
| 64 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 65 | [[nodiscard]] bool isInsert() const { |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 66 | return (0 != (mFlags & AHWD_IS_INSERT)); |
| 67 | } |
| 68 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 69 | [[nodiscard]] bool supportsBluetoothVariableLatency() const { |
Eric Laurent | 5205764 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 70 | return (0 != (mFlags & AHWD_SUPPORTS_BT_LATENCY_MODES)); |
| 71 | } |
| 72 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 73 | [[nodiscard]] audio_module_handle_t handle() const { return mHandle; } |
| 74 | [[nodiscard]] const char *moduleName() const { return mModuleName; } |
| 75 | [[nodiscard]] sp<DeviceHalInterface> hwDevice() const { return mHwDevice; } |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 76 | |
| 77 | /** This method creates and opens the audio hardware output stream. |
| 78 | * The "address" parameter qualifies the "devices" audio device type if needed. |
| 79 | * The format format depends on the device type: |
| 80 | * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC" |
| 81 | * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y" |
| 82 | * - Other devices may use a number or any other string. |
| 83 | */ |
| 84 | status_t openOutputStream( |
| 85 | AudioStreamOut **ppStreamOut, |
| 86 | audio_io_handle_t handle, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 87 | audio_devices_t deviceType, |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 88 | audio_output_flags_t flags, |
| 89 | struct audio_config *config, |
| 90 | const char *address); |
| 91 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 92 | [[nodiscard]] bool supportsAudioPatches() const; |
Mikhail Naganov | 9ee0540 | 2016-10-13 15:58:17 -0700 | [diff] [blame] | 93 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 94 | [[nodiscard]] status_t getAudioPort(struct audio_port_v7 *port) const; |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 95 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 96 | [[nodiscard]] status_t getMmapPolicyInfos( |
jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 97 | media::audio::common::AudioMMapPolicyType policyType, |
| 98 | std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) const; |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 99 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 100 | [[nodiscard]] int32_t getAAudioMixerBurstCount() const; |
jiabin | e504e7b | 2021-09-18 00:27:08 +0000 | [diff] [blame] | 101 | |
Andy Hung | 6cf2612 | 2023-06-15 14:50:18 -0700 | [diff] [blame^] | 102 | [[nodiscard]] int32_t getAAudioHardwareBurstMinUsec() const; |
jiabin | e504e7b | 2021-09-18 00:27:08 +0000 | [diff] [blame] | 103 | |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 104 | private: |
| 105 | const audio_module_handle_t mHandle; |
| 106 | const char * const mModuleName; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 107 | sp<DeviceHalInterface> mHwDevice; |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 108 | const Flags mFlags; |
| 109 | }; |
| 110 | |
| 111 | } // namespace android |
| 112 | |
| 113 | #endif // ANDROID_AUDIO_HW_DEVICE_H |