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 <media/audiohal/DeviceHalInterface.h> 26 #include <utils/Errors.h> 27 #include <system/audio.h> 28 29 namespace android { 30 31 class AudioStreamOut; 32 33 class AudioHwDevice { 34 public: 35 enum Flags { 36 AHWD_CAN_SET_MASTER_VOLUME = 0x1, 37 AHWD_CAN_SET_MASTER_MUTE = 0x2, 38 // Means that this isn't a terminal module, and software patches 39 // are used to transport audio data further. 40 AHWD_IS_INSERT = 0x4, 41 }; 42 43 AudioHwDevice(audio_module_handle_t handle, 44 const char *moduleName, 45 sp<DeviceHalInterface> hwDevice, 46 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 61 bool isInsert() const { 62 return (0 != (mFlags & AHWD_IS_INSERT)); 63 } 64 65 audio_module_handle_t handle() const { return mHandle; } 66 const char *moduleName() const { return mModuleName; } 67 sp<DeviceHalInterface> hwDevice() const { return mHwDevice; } 68 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, 79 audio_devices_t devices, 80 audio_output_flags_t flags, 81 struct audio_config *config, 82 const char *address); 83 84 bool supportsAudioPatches() const; 85 86 private: 87 const audio_module_handle_t mHandle; 88 const char * const mModuleName; 89 sp<DeviceHalInterface> mHwDevice; 90 const Flags mFlags; 91 }; 92 93 } // namespace android 94 95 #endif // ANDROID_AUDIO_HW_DEVICE_H 96