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
29namespace android {
30
31class AudioStreamOut;
32
33class AudioHwDevice {
34public:
35    enum Flags {
36        AHWD_CAN_SET_MASTER_VOLUME  = 0x1,
37        AHWD_CAN_SET_MASTER_MUTE    = 0x2,
38    };
39
40    AudioHwDevice(audio_module_handle_t handle,
41                  const char *moduleName,
42                  sp<DeviceHalInterface> hwDevice,
43                  Flags flags)
44        : mHandle(handle)
45        , mModuleName(strdup(moduleName))
46        , mHwDevice(hwDevice)
47        , mFlags(flags) { }
48    virtual ~AudioHwDevice() { free((void *)mModuleName); }
49
50    bool canSetMasterVolume() const {
51        return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
52    }
53
54    bool canSetMasterMute() const {
55        return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
56    }
57
58    audio_module_handle_t handle() const { return mHandle; }
59    const char *moduleName() const { return mModuleName; }
60    sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
61
62    /** This method creates and opens the audio hardware output stream.
63     * The "address" parameter qualifies the "devices" audio device type if needed.
64     * The format format depends on the device type:
65     * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
66     * - USB devices use the ALSA card and device numbers in the form  "card=X;device=Y"
67     * - Other devices may use a number or any other string.
68     */
69    status_t openOutputStream(
70            AudioStreamOut **ppStreamOut,
71            audio_io_handle_t handle,
72            audio_devices_t devices,
73            audio_output_flags_t flags,
74            struct audio_config *config,
75            const char *address);
76
77    bool supportsAudioPatches() const;
78
79private:
80    const audio_module_handle_t mHandle;
81    const char * const          mModuleName;
82    sp<DeviceHalInterface>      mHwDevice;
83    const Flags                 mFlags;
84};
85
86} // namespace android
87
88#endif // ANDROID_AUDIO_HW_DEVICE_H
89