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 #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 
29 
30 namespace android {
31 
32 class AudioStreamOut;
33 
34 class AudioHwDevice {
35 public:
36     enum Flags {
37         AHWD_CAN_SET_MASTER_VOLUME  = 0x1,
38         AHWD_CAN_SET_MASTER_MUTE    = 0x2,
39     };
40 
AudioHwDevice(audio_module_handle_t handle,const char * moduleName,audio_hw_device_t * hwDevice,Flags flags)41     AudioHwDevice(audio_module_handle_t handle,
42                   const char *moduleName,
43                   audio_hw_device_t *hwDevice,
44                   Flags flags)
45         : mHandle(handle)
46         , mModuleName(strdup(moduleName))
47         , mHwDevice(hwDevice)
48         , mFlags(flags) { }
~AudioHwDevice()49     virtual ~AudioHwDevice() { free((void *)mModuleName); }
50 
canSetMasterVolume()51     bool canSetMasterVolume() const {
52         return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
53     }
54 
canSetMasterMute()55     bool canSetMasterMute() const {
56         return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
57     }
58 
handle()59     audio_module_handle_t handle() const { return mHandle; }
moduleName()60     const char *moduleName() const { return mModuleName; }
hwDevice()61     audio_hw_device_t *hwDevice() const { return mHwDevice; }
version()62     uint32_t version() const { return mHwDevice->common.version; }
63 
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 
79 private:
80     const audio_module_handle_t mHandle;
81     const char * const          mModuleName;
82     audio_hw_device_t * const   mHwDevice;
83     const Flags                 mFlags;
84 };
85 
86 } // namespace android
87 
88 #endif // ANDROID_AUDIO_HW_DEVICE_H
89