AudioHwDevice.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifndef ANDROID_AUDIO_HW_DEVICE_H
  18. #define ANDROID_AUDIO_HW_DEVICE_H
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <sys/types.h>
  22. #include <media/audiohal/DeviceHalInterface.h>
  23. #include <utils/Errors.h>
  24. #include <system/audio.h>
  25. namespace android {
  26. class AudioStreamOut;
  27. class AudioHwDevice {
  28. public:
  29. enum Flags {
  30. AHWD_CAN_SET_MASTER_VOLUME = 0x1,
  31. AHWD_CAN_SET_MASTER_MUTE = 0x2,
  32. // Means that this isn't a terminal module, and software patches
  33. // are used to transport audio data further.
  34. AHWD_IS_INSERT = 0x4,
  35. };
  36. AudioHwDevice(audio_module_handle_t handle,
  37. const char *moduleName,
  38. sp<DeviceHalInterface> hwDevice,
  39. Flags flags)
  40. : mHandle(handle)
  41. , mModuleName(strdup(moduleName))
  42. , mHwDevice(hwDevice)
  43. , mFlags(flags) { }
  44. virtual ~AudioHwDevice() { free((void *)mModuleName); }
  45. bool canSetMasterVolume() const {
  46. return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
  47. }
  48. bool canSetMasterMute() const {
  49. return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
  50. }
  51. bool isInsert() const {
  52. return (0 != (mFlags & AHWD_IS_INSERT));
  53. }
  54. audio_module_handle_t handle() const { return mHandle; }
  55. const char *moduleName() const { return mModuleName; }
  56. sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
  57. /** This method creates and opens the audio hardware output stream.
  58. * The "address" parameter qualifies the "devices" audio device type if needed.
  59. * The format format depends on the device type:
  60. * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
  61. * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
  62. * - Other devices may use a number or any other string.
  63. */
  64. status_t openOutputStream(
  65. AudioStreamOut **ppStreamOut,
  66. audio_io_handle_t handle,
  67. audio_devices_t devices,
  68. audio_output_flags_t flags,
  69. struct audio_config *config,
  70. const char *address);
  71. bool supportsAudioPatches() const;
  72. private:
  73. const audio_module_handle_t mHandle;
  74. const char * const mModuleName;
  75. sp<DeviceHalInterface> mHwDevice;
  76. const Flags mFlags;
  77. };
  78. } // namespace android
  79. #endif // ANDROID_AUDIO_HW_DEVICE_H