blob: 8c5d239bcb9e1db4c2b78b8c216b26a62990096e [file] [log] [blame]
Phil Burk062e67a2015-02-11 13:40:50 -08001/*
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
jiabine99d0882021-09-17 05:21:25 +000025#include <android/media/audio/common/AudioMMapPolicyInfo.h>
26#include <android/media/audio/common/AudioMMapPolicyType.h>
Mikhail Naganova0c91332016-09-19 10:01:12 -070027#include <media/audiohal/DeviceHalInterface.h>
Phil Burk062e67a2015-02-11 13:40:50 -080028#include <utils/Errors.h>
29#include <system/audio.h>
30
Phil Burk062e67a2015-02-11 13:40:50 -080031namespace android {
32
33class AudioStreamOut;
34
35class AudioHwDevice {
36public:
37 enum Flags {
38 AHWD_CAN_SET_MASTER_VOLUME = 0x1,
39 AHWD_CAN_SET_MASTER_MUTE = 0x2,
Mikhail Naganovadca70f2018-07-09 12:49:25 -070040 // Means that this isn't a terminal module, and software patches
41 // are used to transport audio data further.
42 AHWD_IS_INSERT = 0x4,
Phil Burk062e67a2015-02-11 13:40:50 -080043 };
44
45 AudioHwDevice(audio_module_handle_t handle,
46 const char *moduleName,
Mikhail Naganove4f1f632016-08-31 11:35:10 -070047 sp<DeviceHalInterface> hwDevice,
Phil Burk062e67a2015-02-11 13:40:50 -080048 Flags flags)
49 : mHandle(handle)
50 , mModuleName(strdup(moduleName))
51 , mHwDevice(hwDevice)
52 , mFlags(flags) { }
53 virtual ~AudioHwDevice() { free((void *)mModuleName); }
54
55 bool canSetMasterVolume() const {
56 return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
57 }
58
59 bool canSetMasterMute() const {
60 return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
61 }
62
Mikhail Naganovadca70f2018-07-09 12:49:25 -070063 bool isInsert() const {
64 return (0 != (mFlags & AHWD_IS_INSERT));
65 }
66
Phil Burk062e67a2015-02-11 13:40:50 -080067 audio_module_handle_t handle() const { return mHandle; }
68 const char *moduleName() const { return mModuleName; }
Mikhail Naganove4f1f632016-08-31 11:35:10 -070069 sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
Phil Burk062e67a2015-02-11 13:40:50 -080070
71 /** This method creates and opens the audio hardware output stream.
72 * The "address" parameter qualifies the "devices" audio device type if needed.
73 * The format format depends on the device type:
74 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
75 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
76 * - Other devices may use a number or any other string.
77 */
78 status_t openOutputStream(
79 AudioStreamOut **ppStreamOut,
80 audio_io_handle_t handle,
jiabin43810402019-10-24 14:58:31 -070081 audio_devices_t deviceType,
Phil Burk062e67a2015-02-11 13:40:50 -080082 audio_output_flags_t flags,
83 struct audio_config *config,
84 const char *address);
85
Mikhail Naganov9ee05402016-10-13 15:58:17 -070086 bool supportsAudioPatches() const;
87
jiabinb4fed192020-09-22 14:45:40 -070088 status_t getAudioPort(struct audio_port_v7 *port) const;
89
Jiabin Huangebe64102021-09-07 20:01:07 +000090 status_t getMmapPolicyInfos(
jiabine99d0882021-09-17 05:21:25 +000091 media::audio::common::AudioMMapPolicyType policyType,
92 std::vector<media::audio::common::AudioMMapPolicyInfo> *policyInfos) const;
Jiabin Huangebe64102021-09-07 20:01:07 +000093
jiabine504e7b2021-09-18 00:27:08 +000094 int32_t getAAudioMixerBurstCount() const;
95
96 int32_t getAAudioHardwareBurstMinUsec() const;
97
Phil Burk062e67a2015-02-11 13:40:50 -080098private:
99 const audio_module_handle_t mHandle;
100 const char * const mModuleName;
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700101 sp<DeviceHalInterface> mHwDevice;
Phil Burk062e67a2015-02-11 13:40:50 -0800102 const Flags mFlags;
103};
104
105} // namespace android
106
107#endif // ANDROID_AUDIO_HW_DEVICE_H