blob: 6709d17a2500e3a2380d7066ec6ed94deb99df0d [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
Mikhail Naganova0c91332016-09-19 10:01:12 -070025#include <media/audiohal/DeviceHalInterface.h>
Phil Burk062e67a2015-02-11 13:40:50 -080026#include <utils/Errors.h>
27#include <system/audio.h>
28
Phil Burk062e67a2015-02-11 13:40:50 -080029namespace android {
30
31class AudioStreamOut;
32
33class AudioHwDevice {
34public:
35 enum Flags {
36 AHWD_CAN_SET_MASTER_VOLUME = 0x1,
37 AHWD_CAN_SET_MASTER_MUTE = 0x2,
Mikhail Naganovadca70f2018-07-09 12:49:25 -070038 // Means that this isn't a terminal module, and software patches
39 // are used to transport audio data further.
40 AHWD_IS_INSERT = 0x4,
Phil Burk062e67a2015-02-11 13:40:50 -080041 };
42
43 AudioHwDevice(audio_module_handle_t handle,
44 const char *moduleName,
Mikhail Naganove4f1f632016-08-31 11:35:10 -070045 sp<DeviceHalInterface> hwDevice,
Phil Burk062e67a2015-02-11 13:40:50 -080046 Flags flags)
47 : mHandle(handle)
48 , mModuleName(strdup(moduleName))
49 , mHwDevice(hwDevice)
50 , mFlags(flags) { }
51 virtual ~AudioHwDevice() { free((void *)mModuleName); }
52
53 bool canSetMasterVolume() const {
54 return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
55 }
56
57 bool canSetMasterMute() const {
58 return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
59 }
60
Mikhail Naganovadca70f2018-07-09 12:49:25 -070061 bool isInsert() const {
62 return (0 != (mFlags & AHWD_IS_INSERT));
63 }
64
Phil Burk062e67a2015-02-11 13:40:50 -080065 audio_module_handle_t handle() const { return mHandle; }
66 const char *moduleName() const { return mModuleName; }
Mikhail Naganove4f1f632016-08-31 11:35:10 -070067 sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
Phil Burk062e67a2015-02-11 13:40:50 -080068
69 /** This method creates and opens the audio hardware output stream.
70 * The "address" parameter qualifies the "devices" audio device type if needed.
71 * The format format depends on the device type:
72 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
73 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
74 * - Other devices may use a number or any other string.
75 */
76 status_t openOutputStream(
77 AudioStreamOut **ppStreamOut,
78 audio_io_handle_t handle,
jiabin43810402019-10-24 14:58:31 -070079 audio_devices_t deviceType,
Phil Burk062e67a2015-02-11 13:40:50 -080080 audio_output_flags_t flags,
81 struct audio_config *config,
82 const char *address);
83
Mikhail Naganov9ee05402016-10-13 15:58:17 -070084 bool supportsAudioPatches() const;
85
Phil Burk062e67a2015-02-11 13:40:50 -080086private:
87 const audio_module_handle_t mHandle;
88 const char * const mModuleName;
Mikhail Naganove4f1f632016-08-31 11:35:10 -070089 sp<DeviceHalInterface> mHwDevice;
Phil Burk062e67a2015-02-11 13:40:50 -080090 const Flags mFlags;
91};
92
93} // namespace android
94
95#endif // ANDROID_AUDIO_HW_DEVICE_H