blob: 54e1d597fccf93d832931e863d9b4ead9358076a [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>
26#include <utils/Errors.h>
27#include <system/audio.h>
28
Mikhail Naganove4f1f632016-08-31 11:35:10 -070029#include "DeviceHalInterface.h"
Phil Burk062e67a2015-02-11 13:40:50 -080030
31namespace 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,
40 };
41
42 AudioHwDevice(audio_module_handle_t handle,
43 const char *moduleName,
Mikhail Naganove4f1f632016-08-31 11:35:10 -070044 sp<DeviceHalInterface> hwDevice,
Phil Burk062e67a2015-02-11 13:40:50 -080045 Flags flags)
46 : mHandle(handle)
47 , mModuleName(strdup(moduleName))
48 , mHwDevice(hwDevice)
49 , mFlags(flags) { }
50 virtual ~AudioHwDevice() { free((void *)mModuleName); }
51
52 bool canSetMasterVolume() const {
53 return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
54 }
55
56 bool canSetMasterMute() const {
57 return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
58 }
59
60 audio_module_handle_t handle() const { return mHandle; }
61 const char *moduleName() const { return mModuleName; }
Mikhail Naganove4f1f632016-08-31 11:35:10 -070062 sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
63 uint32_t version() const;
Phil Burk062e67a2015-02-11 13:40:50 -080064
65 /** This method creates and opens the audio hardware output stream.
66 * The "address" parameter qualifies the "devices" audio device type if needed.
67 * The format format depends on the device type:
68 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
69 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
70 * - Other devices may use a number or any other string.
71 */
72 status_t openOutputStream(
73 AudioStreamOut **ppStreamOut,
74 audio_io_handle_t handle,
75 audio_devices_t devices,
76 audio_output_flags_t flags,
77 struct audio_config *config,
78 const char *address);
79
80private:
81 const audio_module_handle_t mHandle;
82 const char * const mModuleName;
Mikhail Naganove4f1f632016-08-31 11:35:10 -070083 sp<DeviceHalInterface> mHwDevice;
Phil Burk062e67a2015-02-11 13:40:50 -080084 const Flags mFlags;
85};
86
87} // namespace android
88
89#endif // ANDROID_AUDIO_HW_DEVICE_H