• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
19 
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <sys/types.h>
23 
24 #include <android/media/audio/common/AudioMMapPolicyInfo.h>
25 #include <android/media/audio/common/AudioMMapPolicyType.h>
26 #include <media/audiohal/DeviceHalInterface.h>
27 #include <utils/Errors.h>
28 #include <system/audio.h>
29 
30 namespace android {
31 
32 class AudioStreamIn;
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,
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,
43         // This Module supports BT Latency mode control
44         AHWD_SUPPORTS_BT_LATENCY_MODES = 0x8,
45     };
46 
AudioHwDevice(audio_module_handle_t handle,const char * moduleName,const sp<DeviceHalInterface> & hwDevice,Flags flags)47     AudioHwDevice(audio_module_handle_t handle,
48                   const char *moduleName,
49                   const sp<DeviceHalInterface>& hwDevice,
50                   Flags flags)
51         : mHandle(handle)
52         , mModuleName(strdup(moduleName))
53         , mHwDevice(hwDevice)
54         , mFlags(flags) { }
~AudioHwDevice()55     virtual ~AudioHwDevice() { free((void *)mModuleName); }
56 
canSetMasterVolume()57     [[nodiscard]] bool canSetMasterVolume() const {
58         return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
59     }
60 
canSetMasterMute()61     [[nodiscard]] bool canSetMasterMute() const {
62         return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
63     }
64 
isInsert()65     [[nodiscard]] bool isInsert() const {
66         return (0 != (mFlags & AHWD_IS_INSERT));
67     }
68 
supportsBluetoothVariableLatency()69     [[nodiscard]] bool supportsBluetoothVariableLatency() const {
70         return (0 != (mFlags & AHWD_SUPPORTS_BT_LATENCY_MODES));
71     }
72 
handle()73    [[nodiscard]] audio_module_handle_t handle() const { return mHandle; }
moduleName()74    [[nodiscard]] const char *moduleName() const { return mModuleName; }
hwDevice()75    [[nodiscard]] sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
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,
87             audio_devices_t deviceType,
88             audio_output_flags_t flags,
89             struct audio_config *config,
90             const char *address);
91 
92     status_t openInputStream(
93             AudioStreamIn **ppStreamIn,
94             audio_io_handle_t handle,
95             audio_devices_t deviceType,
96             audio_input_flags_t flags,
97             struct audio_config *config,
98             const char *address,
99             audio_source_t source,
100             audio_devices_t outputDevice,
101             const char *outputDeviceAddress);
102 
103     [[nodiscard]] bool supportsAudioPatches() const;
104 
105     [[nodiscard]] status_t getAudioPort(struct audio_port_v7 *port) const;
106 
107     [[nodiscard]] status_t getMmapPolicyInfos(
108             media::audio::common::AudioMMapPolicyType policyType,
109             std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) const;
110 
111     [[nodiscard]] int32_t getAAudioMixerBurstCount() const;
112 
113     [[nodiscard]] int32_t getAAudioHardwareBurstMinUsec() const;
114 
115     [[nodiscard]] status_t getAudioMixPort(const struct audio_port_v7 *devicePort,
116                                            struct audio_port_v7 *mixPort) const;
117 
118 private:
119     const audio_module_handle_t mHandle;
120     const char * const          mModuleName;
121     sp<DeviceHalInterface>      mHwDevice;
122     const Flags                 mFlags;
123 };
124 
125 } // namespace android
126