1062e67a26e0553dd142be622821f493df541f0c6Phil Burk/*
2062e67a26e0553dd142be622821f493df541f0c6Phil Burk**
3062e67a26e0553dd142be622821f493df541f0c6Phil Burk** Copyright 2007, The Android Open Source Project
4062e67a26e0553dd142be622821f493df541f0c6Phil Burk**
5062e67a26e0553dd142be622821f493df541f0c6Phil Burk** Licensed under the Apache License, Version 2.0 (the "License");
6062e67a26e0553dd142be622821f493df541f0c6Phil Burk** you may not use this file except in compliance with the License.
7062e67a26e0553dd142be622821f493df541f0c6Phil Burk** You may obtain a copy of the License at
8062e67a26e0553dd142be622821f493df541f0c6Phil Burk**
9062e67a26e0553dd142be622821f493df541f0c6Phil Burk**     http://www.apache.org/licenses/LICENSE-2.0
10062e67a26e0553dd142be622821f493df541f0c6Phil Burk**
11062e67a26e0553dd142be622821f493df541f0c6Phil Burk** Unless required by applicable law or agreed to in writing, software
12062e67a26e0553dd142be622821f493df541f0c6Phil Burk** distributed under the License is distributed on an "AS IS" BASIS,
13062e67a26e0553dd142be622821f493df541f0c6Phil Burk** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14062e67a26e0553dd142be622821f493df541f0c6Phil Burk** See the License for the specific language governing permissions and
15062e67a26e0553dd142be622821f493df541f0c6Phil Burk** limitations under the License.
16062e67a26e0553dd142be622821f493df541f0c6Phil Burk*/
17062e67a26e0553dd142be622821f493df541f0c6Phil Burk
18062e67a26e0553dd142be622821f493df541f0c6Phil Burk#ifndef ANDROID_AUDIO_HW_DEVICE_H
19062e67a26e0553dd142be622821f493df541f0c6Phil Burk#define ANDROID_AUDIO_HW_DEVICE_H
20062e67a26e0553dd142be622821f493df541f0c6Phil Burk
21062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <stdint.h>
22062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <stdlib.h>
23062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <sys/types.h>
24062e67a26e0553dd142be622821f493df541f0c6Phil Burk
25a0c91339814f37ea78365afb436c9f3d1f0a0090Mikhail Naganov#include <media/audiohal/DeviceHalInterface.h>
26062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <utils/Errors.h>
27062e67a26e0553dd142be622821f493df541f0c6Phil Burk#include <system/audio.h>
28062e67a26e0553dd142be622821f493df541f0c6Phil Burk
29062e67a26e0553dd142be622821f493df541f0c6Phil Burknamespace android {
30062e67a26e0553dd142be622821f493df541f0c6Phil Burk
31062e67a26e0553dd142be622821f493df541f0c6Phil Burkclass AudioStreamOut;
32062e67a26e0553dd142be622821f493df541f0c6Phil Burk
33062e67a26e0553dd142be622821f493df541f0c6Phil Burkclass AudioHwDevice {
34062e67a26e0553dd142be622821f493df541f0c6Phil Burkpublic:
35062e67a26e0553dd142be622821f493df541f0c6Phil Burk    enum Flags {
36062e67a26e0553dd142be622821f493df541f0c6Phil Burk        AHWD_CAN_SET_MASTER_VOLUME  = 0x1,
37062e67a26e0553dd142be622821f493df541f0c6Phil Burk        AHWD_CAN_SET_MASTER_MUTE    = 0x2,
38062e67a26e0553dd142be622821f493df541f0c6Phil Burk    };
39062e67a26e0553dd142be622821f493df541f0c6Phil Burk
40062e67a26e0553dd142be622821f493df541f0c6Phil Burk    AudioHwDevice(audio_module_handle_t handle,
41062e67a26e0553dd142be622821f493df541f0c6Phil Burk                  const char *moduleName,
42e4f1f63a2c54ee8687ad8cca18df0f6639ad7c81Mikhail Naganov                  sp<DeviceHalInterface> hwDevice,
43062e67a26e0553dd142be622821f493df541f0c6Phil Burk                  Flags flags)
44062e67a26e0553dd142be622821f493df541f0c6Phil Burk        : mHandle(handle)
45062e67a26e0553dd142be622821f493df541f0c6Phil Burk        , mModuleName(strdup(moduleName))
46062e67a26e0553dd142be622821f493df541f0c6Phil Burk        , mHwDevice(hwDevice)
47062e67a26e0553dd142be622821f493df541f0c6Phil Burk        , mFlags(flags) { }
48062e67a26e0553dd142be622821f493df541f0c6Phil Burk    virtual ~AudioHwDevice() { free((void *)mModuleName); }
49062e67a26e0553dd142be622821f493df541f0c6Phil Burk
50062e67a26e0553dd142be622821f493df541f0c6Phil Burk    bool canSetMasterVolume() const {
51062e67a26e0553dd142be622821f493df541f0c6Phil Burk        return (0 != (mFlags & AHWD_CAN_SET_MASTER_VOLUME));
52062e67a26e0553dd142be622821f493df541f0c6Phil Burk    }
53062e67a26e0553dd142be622821f493df541f0c6Phil Burk
54062e67a26e0553dd142be622821f493df541f0c6Phil Burk    bool canSetMasterMute() const {
55062e67a26e0553dd142be622821f493df541f0c6Phil Burk        return (0 != (mFlags & AHWD_CAN_SET_MASTER_MUTE));
56062e67a26e0553dd142be622821f493df541f0c6Phil Burk    }
57062e67a26e0553dd142be622821f493df541f0c6Phil Burk
58062e67a26e0553dd142be622821f493df541f0c6Phil Burk    audio_module_handle_t handle() const { return mHandle; }
59062e67a26e0553dd142be622821f493df541f0c6Phil Burk    const char *moduleName() const { return mModuleName; }
60e4f1f63a2c54ee8687ad8cca18df0f6639ad7c81Mikhail Naganov    sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
61062e67a26e0553dd142be622821f493df541f0c6Phil Burk
62062e67a26e0553dd142be622821f493df541f0c6Phil Burk    /** This method creates and opens the audio hardware output stream.
63062e67a26e0553dd142be622821f493df541f0c6Phil Burk     * The "address" parameter qualifies the "devices" audio device type if needed.
64062e67a26e0553dd142be622821f493df541f0c6Phil Burk     * The format format depends on the device type:
65062e67a26e0553dd142be622821f493df541f0c6Phil Burk     * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
66062e67a26e0553dd142be622821f493df541f0c6Phil Burk     * - USB devices use the ALSA card and device numbers in the form  "card=X;device=Y"
67062e67a26e0553dd142be622821f493df541f0c6Phil Burk     * - Other devices may use a number or any other string.
68062e67a26e0553dd142be622821f493df541f0c6Phil Burk     */
69062e67a26e0553dd142be622821f493df541f0c6Phil Burk    status_t openOutputStream(
70062e67a26e0553dd142be622821f493df541f0c6Phil Burk            AudioStreamOut **ppStreamOut,
71062e67a26e0553dd142be622821f493df541f0c6Phil Burk            audio_io_handle_t handle,
72062e67a26e0553dd142be622821f493df541f0c6Phil Burk            audio_devices_t devices,
73062e67a26e0553dd142be622821f493df541f0c6Phil Burk            audio_output_flags_t flags,
74062e67a26e0553dd142be622821f493df541f0c6Phil Burk            struct audio_config *config,
75062e67a26e0553dd142be622821f493df541f0c6Phil Burk            const char *address);
76062e67a26e0553dd142be622821f493df541f0c6Phil Burk
779ee0540d3a61bff03d561ca431a371c3d9335d2bMikhail Naganov    bool supportsAudioPatches() const;
789ee0540d3a61bff03d561ca431a371c3d9335d2bMikhail Naganov
79062e67a26e0553dd142be622821f493df541f0c6Phil Burkprivate:
80062e67a26e0553dd142be622821f493df541f0c6Phil Burk    const audio_module_handle_t mHandle;
81062e67a26e0553dd142be622821f493df541f0c6Phil Burk    const char * const          mModuleName;
82e4f1f63a2c54ee8687ad8cca18df0f6639ad7c81Mikhail Naganov    sp<DeviceHalInterface>      mHwDevice;
83062e67a26e0553dd142be622821f493df541f0c6Phil Burk    const Flags                 mFlags;
84062e67a26e0553dd142be622821f493df541f0c6Phil Burk};
85062e67a26e0553dd142be622821f493df541f0c6Phil Burk
86062e67a26e0553dd142be622821f493df541f0c6Phil Burk} // namespace android
87062e67a26e0553dd142be622821f493df541f0c6Phil Burk
88062e67a26e0553dd142be622821f493df541f0c6Phil Burk#endif // ANDROID_AUDIO_HW_DEVICE_H
89