blob: 995ac131a8d283b073074404406bd370004c47dc [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
25#include <hardware/audio.h>
Mikhail Naganova0c91332016-09-19 10:01:12 -070026#include <media/audiohal/DeviceHalInterface.h>
Phil Burk062e67a2015-02-11 13:40:50 -080027#include <utils/Errors.h>
28#include <system/audio.h>
29
Phil Burk062e67a2015-02-11 13:40:50 -080030namespace android {
31
32class AudioStreamOut;
33
34class AudioHwDevice {
35public:
36 enum Flags {
37 AHWD_CAN_SET_MASTER_VOLUME = 0x1,
38 AHWD_CAN_SET_MASTER_MUTE = 0x2,
39 };
40
41 AudioHwDevice(audio_module_handle_t handle,
42 const char *moduleName,
Mikhail Naganove4f1f632016-08-31 11:35:10 -070043 sp<DeviceHalInterface> hwDevice,
Phil Burk062e67a2015-02-11 13:40:50 -080044 Flags flags)
45 : mHandle(handle)
46 , mModuleName(strdup(moduleName))
47 , mHwDevice(hwDevice)
48 , mFlags(flags) { }
49 virtual ~AudioHwDevice() { free((void *)mModuleName); }
50
51 bool canSetMasterVolume() const {
52 return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
53 }
54
55 bool canSetMasterMute() const {
56 return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
57 }
58
59 audio_module_handle_t handle() const { return mHandle; }
60 const char *moduleName() const { return mModuleName; }
Mikhail Naganove4f1f632016-08-31 11:35:10 -070061 sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
62 uint32_t version() const;
Phil Burk062e67a2015-02-11 13:40:50 -080063
64 /** This method creates and opens the audio hardware output stream.
65 * The "address" parameter qualifies the "devices" audio device type if needed.
66 * The format format depends on the device type:
67 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
68 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
69 * - Other devices may use a number or any other string.
70 */
71 status_t openOutputStream(
72 AudioStreamOut **ppStreamOut,
73 audio_io_handle_t handle,
74 audio_devices_t devices,
75 audio_output_flags_t flags,
76 struct audio_config *config,
77 const char *address);
78
79private:
80 const audio_module_handle_t mHandle;
81 const char * const mModuleName;
Mikhail Naganove4f1f632016-08-31 11:35:10 -070082 sp<DeviceHalInterface> mHwDevice;
Phil Burk062e67a2015-02-11 13:40:50 -080083 const Flags mFlags;
84};
85
86} // namespace android
87
88#endif // ANDROID_AUDIO_HW_DEVICE_H