summaryrefslogtreecommitdiffstats
path: root/include/hardware
diff options
context:
space:
mode:
authorDima Zavin <dima@android.com>2011-03-11 11:20:49 -0800
committerDima Zavin <dima@android.com>2011-04-27 14:08:57 -0700
commitf1504dbca386fc454b8ded7669012f3d4d27eab7 (patch)
tree5b28333600fdef0551d42b2ce697a2069db2b2e1 /include/hardware
parentfa9c285fed2c09fac909a0f1b65b1b07ab67f7b3 (diff)
downloadhardware_libhardware-f1504dbca386fc454b8ded7669012f3d4d27eab7.zip
hardware_libhardware-f1504dbca386fc454b8ded7669012f3d4d27eab7.tar.gz
hardware_libhardware-f1504dbca386fc454b8ded7669012f3d4d27eab7.tar.bz2
libhardware: add audio defines and HAL headers
Change-Id: Iae523059834c252f0d39f7efc6e15832e6273101 Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'include/hardware')
-rw-r--r--include/hardware/audio.h393
-rw-r--r--include/hardware/audio_hal.h298
-rw-r--r--include/hardware/audio_policy.h106
-rw-r--r--include/hardware/audio_policy_hal.h384
4 files changed, 1181 insertions, 0 deletions
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
new file mode 100644
index 0000000..8f2ac0c
--- /dev/null
+++ b/include/hardware/audio.h
@@ -0,0 +1,393 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_CORE_H
+#define ANDROID_AUDIO_CORE_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+__BEGIN_DECLS
+
+/* The enums were moved here mostly from
+ * frameworks/base/include/media/AudioSystem.h
+ */
+
+typedef int audio_io_handle_t;
+
+/* Audio stream types */
+typedef enum {
+ AUDIO_STREAM_DEFAULT = -1,
+ AUDIO_STREAM_VOICE_CALL = 0,
+ AUDIO_STREAM_SYSTEM = 1,
+ AUDIO_STREAM_RING = 2,
+ AUDIO_STREAM_MUSIC = 3,
+ AUDIO_STREAM_ALARM = 4,
+ AUDIO_STREAM_NOTIFICATION = 5,
+ AUDIO_STREAM_BLUETOOTH_SCO = 6,
+ AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */
+ AUDIO_STREAM_DTMF = 8,
+ AUDIO_STREAM_TTS = 9,
+
+ AUDIO_STREAM_CNT,
+ AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1,
+} audio_stream_type_t;
+
+/* Do not change these values without updating their counterparts
+ * in media/java/android/media/MediaRecorder.java!
+ */
+typedef enum {
+ AUDIO_SOURCE_DEFAULT = 0,
+ AUDIO_SOURCE_MIC = 1,
+ AUDIO_SOURCE_VOICE_UPLINK = 2,
+ AUDIO_SOURCE_VOICE_DOWNLINK = 3,
+ AUDIO_SOURCE_VOICE_CALL = 4,
+ AUDIO_SOURCE_CAMCORDER = 5,
+ AUDIO_SOURCE_VOICE_RECOGNITION = 6,
+ AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
+
+ AUDIO_SOURCE_CNT,
+ AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1,
+} audio_source_t;
+
+/* special audio session values
+ * (XXX: should this be living in the audio effects land?)
+ */
+typedef enum {
+ /* session for effects attached to a particular output stream
+ * (value must be less than 0)
+ */
+ AUDIO_SESSION_OUTPUT_STAGE = -1,
+
+ /* session for effects applied to output mix. These effects can
+ * be moved by audio policy manager to another output stream
+ * (value must be 0)
+ */
+ AUDIO_SESSION_OUTPUT_MIX = 0,
+} audio_session_t;
+
+/* Audio sub formats (see enum audio_format). */
+
+/* PCM sub formats */
+typedef enum {
+ AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE */
+ AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE */
+} audio_format_pcm_sub_fmt_t;
+
+/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
+ * frame header to specify bit rate, stereo mode, version...
+ */
+typedef enum {
+ AUDIO_FORMAT_MP3_SUB_NONE = 0x0,
+} audio_format_mp3_sub_fmt_t;
+
+/* AMR NB/WB sub format field definition: specify frame block interleaving,
+ * bandwidth efficient or octet aligned, encoding mode for recording...
+ */
+typedef enum {
+ AUDIO_FORMAT_AMR_SUB_NONE = 0x0,
+} audio_format_amr_sub_fmt_t;
+
+/* AAC sub format field definition: specify profile or bitrate for recording... */
+typedef enum {
+ AUDIO_FORMAT_AAC_SUB_NONE = 0x0,
+} audio_format_aac_sub_fmt_t;
+
+/* VORBIS sub format field definition: specify quality for recording... */
+typedef enum {
+ AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0,
+} audio_format_vorbis_sub_fmt_t;
+
+/* Audio format consists in a main format field (upper 8 bits) and a sub format
+ * field (lower 24 bits).
+ *
+ * The main format indicates the main codec type. The sub format field
+ * indicates options and parameters for each format. The sub format is mainly
+ * used for record to indicate for instance the requested bitrate or profile.
+ * It can also be used for certain formats to give informations not present in
+ * the encoded audio stream (e.g. octet alignement for AMR).
+ */
+typedef enum {
+ AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL,
+ AUDIO_FORMAT_DEFAULT = 0,
+ AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */
+ AUDIO_FORMAT_MP3 = 0x01000000UL,
+ AUDIO_FORMAT_AMR_NB = 0x02000000UL,
+ AUDIO_FORMAT_AMR_WB = 0x03000000UL,
+ AUDIO_FORMAT_AAC = 0x04000000UL,
+ AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL,
+ AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL,
+ AUDIO_FORMAT_VORBIS = 0x07000000UL,
+ AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL,
+ AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL,
+
+ /* Aliases */
+ AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM |
+ AUDIO_FORMAT_PCM_SUB_16_BIT),
+ AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
+ AUDIO_FORMAT_PCM_SUB_8_BIT),
+} audio_format_t;
+
+/* Channel mask definitions must be kept in sync with JAVA values in
+ * frameworks/base/media/java/android/media/AudioFormat.java */
+typedef enum {
+ /* output channels */
+ AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x4,
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x8,
+ AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x10,
+ AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x20,
+ AUDIO_CHANNEL_OUT_BACK_LEFT = 0x40,
+ AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x80,
+ AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
+ AUDIO_CHANNEL_OUT_BACK_CENTER = 0x400,
+
+ AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT,
+ AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT),
+ AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT |
+ AUDIO_CHANNEL_OUT_BACK_LEFT |
+ AUDIO_CHANNEL_OUT_BACK_RIGHT),
+ AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT |
+ AUDIO_CHANNEL_OUT_FRONT_CENTER |
+ AUDIO_CHANNEL_OUT_BACK_CENTER),
+ AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT |
+ AUDIO_CHANNEL_OUT_FRONT_CENTER |
+ AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
+ AUDIO_CHANNEL_OUT_BACK_LEFT |
+ AUDIO_CHANNEL_OUT_BACK_RIGHT),
+ AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT |
+ AUDIO_CHANNEL_OUT_FRONT_CENTER |
+ AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
+ AUDIO_CHANNEL_OUT_BACK_LEFT |
+ AUDIO_CHANNEL_OUT_BACK_RIGHT |
+ AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER),
+ AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT |
+ AUDIO_CHANNEL_OUT_FRONT_CENTER |
+ AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
+ AUDIO_CHANNEL_OUT_BACK_LEFT |
+ AUDIO_CHANNEL_OUT_BACK_RIGHT |
+ AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
+ AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
+ AUDIO_CHANNEL_OUT_BACK_CENTER),
+
+ /* input channels */
+ AUDIO_CHANNEL_IN_LEFT = 0x4,
+ AUDIO_CHANNEL_IN_RIGHT = 0x8,
+ AUDIO_CHANNEL_IN_FRONT = 0x10,
+ AUDIO_CHANNEL_IN_BACK = 0x20,
+ AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40,
+ AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
+ AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
+ AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200,
+ AUDIO_CHANNEL_IN_PRESSURE = 0x400,
+ AUDIO_CHANNEL_IN_X_AXIS = 0x800,
+ AUDIO_CHANNEL_IN_Y_AXIS = 0x1000,
+ AUDIO_CHANNEL_IN_Z_AXIS = 0x2000,
+ AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000,
+ AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000,
+
+ AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT,
+ AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
+ AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT |
+ AUDIO_CHANNEL_IN_RIGHT |
+ AUDIO_CHANNEL_IN_FRONT |
+ AUDIO_CHANNEL_IN_BACK|
+ AUDIO_CHANNEL_IN_LEFT_PROCESSED |
+ AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
+ AUDIO_CHANNEL_IN_FRONT_PROCESSED |
+ AUDIO_CHANNEL_IN_BACK_PROCESSED|
+ AUDIO_CHANNEL_IN_PRESSURE |
+ AUDIO_CHANNEL_IN_X_AXIS |
+ AUDIO_CHANNEL_IN_Y_AXIS |
+ AUDIO_CHANNEL_IN_Z_AXIS |
+ AUDIO_CHANNEL_IN_VOICE_UPLINK |
+ AUDIO_CHANNEL_IN_VOICE_DNLINK),
+} audio_channels_t;
+
+typedef enum {
+ AUDIO_MODE_INVALID = -2,
+ AUDIO_MODE_CURRENT = -1,
+ AUDIO_MODE_NORMAL = 0,
+ AUDIO_MODE_RINGTONE = 1,
+ AUDIO_MODE_IN_CALL = 2,
+ AUDIO_MODE_IN_COMMUNICATION = 3,
+
+ AUDIO_MODE_CNT,
+ AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1,
+} audio_mode_t;
+
+typedef enum {
+ AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
+ AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
+ AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
+ AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
+ AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
+ AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
+} audio_in_acoustics_t;
+
+typedef enum {
+ /* output devices */
+ AUDIO_DEVICE_OUT_EARPIECE = 0x1,
+ AUDIO_DEVICE_OUT_SPEAKER = 0x2,
+ AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
+ AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10,
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
+ AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400,
+ AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
+ AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
+ AUDIO_DEVICE_OUT_DEFAULT = 0x8000,
+ AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE |
+ AUDIO_DEVICE_OUT_SPEAKER |
+ AUDIO_DEVICE_OUT_WIRED_HEADSET |
+ AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
+ AUDIO_DEVICE_OUT_AUX_DIGITAL |
+ AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
+ AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
+ AUDIO_DEVICE_OUT_DEFAULT),
+ AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
+ AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
+ AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
+ AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
+
+ /* input devices */
+ AUDIO_DEVICE_IN_COMMUNICATION = 0x10000,
+ AUDIO_DEVICE_IN_AMBIENT = 0x20000,
+ AUDIO_DEVICE_IN_BUILTIN_MIC = 0x40000,
+ AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
+ AUDIO_DEVICE_IN_WIRED_HEADSET = 0x100000,
+ AUDIO_DEVICE_IN_AUX_DIGITAL = 0x200000,
+ AUDIO_DEVICE_IN_VOICE_CALL = 0x400000,
+ AUDIO_DEVICE_IN_BACK_MIC = 0x800000,
+ AUDIO_DEVICE_IN_DEFAULT = 0x80000000,
+
+ AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION |
+ AUDIO_DEVICE_IN_AMBIENT |
+ AUDIO_DEVICE_IN_BUILTIN_MIC |
+ AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
+ AUDIO_DEVICE_IN_WIRED_HEADSET |
+ AUDIO_DEVICE_IN_AUX_DIGITAL |
+ AUDIO_DEVICE_IN_VOICE_CALL |
+ AUDIO_DEVICE_IN_BACK_MIC |
+ AUDIO_DEVICE_IN_DEFAULT),
+ AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
+} audio_devices_t;
+
+static inline bool audio_is_output_device(audio_devices_t device)
+{
+ if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
+ return true;
+ else
+ return false;
+}
+
+static inline bool audio_is_input_device(audio_devices_t device)
+{
+ if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
+ return true;
+ else
+ return false;
+}
+
+static inline bool audio_is_a2dp_device(audio_devices_t device)
+{
+ if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
+ return true;
+ else
+ return false;
+}
+
+static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
+{
+ if ((popcount(device) == 1) && (device & (AUDIO_DEVICE_OUT_ALL_SCO |
+ AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET)))
+ return true;
+ else
+ return false;
+}
+
+static inline bool audio_is_input_channel(uint32_t channel)
+{
+ if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0)
+ return true;
+ else
+ return false;
+}
+
+static inline bool audio_is_output_channel(uint32_t channel)
+{
+ if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0)
+ return true;
+ else
+ return false;
+}
+
+static inline bool audio_is_valid_format(uint32_t format)
+{
+ switch (format & AUDIO_FORMAT_MAIN_MASK) {
+ case AUDIO_FORMAT_PCM:
+ case AUDIO_FORMAT_MP3:
+ case AUDIO_FORMAT_AMR_NB:
+ case AUDIO_FORMAT_AMR_WB:
+ case AUDIO_FORMAT_AAC:
+ case AUDIO_FORMAT_HE_AAC_V1:
+ case AUDIO_FORMAT_HE_AAC_V2:
+ case AUDIO_FORMAT_VORBIS:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static inline bool audio_is_linear_pcm(uint32_t format)
+{
+ switch (format) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ case AUDIO_FORMAT_PCM_8_BIT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_CORE_H
diff --git a/include/hardware/audio_hal.h b/include/hardware/audio_hal.h
new file mode 100644
index 0000000..50675bd
--- /dev/null
+++ b/include/hardware/audio_hal.h
@@ -0,0 +1,298 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_HAL_INTERFACE_H
+#define ANDROID_AUDIO_HAL_INTERFACE_H
+
+#include <stdint.h>
+#include <strings.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+#include <hardware/hardware.h>
+#include <hardware/audio.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define AUDIO_HARDWARE_MODULE_ID "audio"
+
+/**
+ * Name of the audio devices to open
+ */
+#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
+
+/**************************************/
+
+/* common audio stream parameters and operations */
+struct audio_stream {
+
+ /**
+ * sampling rate is in Hz - eg. 44100
+ */
+ uint32_t (*get_sample_rate)(const struct audio_stream *stream);
+ int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
+
+ /**
+ * size of output buffer in bytes - eg. 4800
+ */
+ size_t (*get_buffer_size)(const struct audio_stream *stream);
+
+ /**
+ * the channel mask -
+ * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
+ */
+ uint32_t (*get_channels)(const struct audio_stream *stream);
+
+ /**
+ * audio format - eg. AUDIO_FORMAT_PCM_16_BIT
+ */
+ int (*get_format)(const struct audio_stream *stream);
+ int (*set_format)(struct audio_stream *stream, int format);
+
+ /**
+ * Put the audio hardware input/output into standby mode.
+ * Returns 0 on success and <0 on failure.
+ */
+ int (*standby)(struct audio_stream *stream);
+
+ /** dump the state of the audio input/output device */
+ int (*dump)(const struct audio_stream *stream, int fd);
+
+ audio_devices_t (*get_device)(const struct audio_stream *stream);
+ int (*set_device)(struct audio_stream *stream, audio_devices_t device);
+
+ /**
+ * set/get audio stream parameters. The function accepts a list of
+ * parameter key value pairs in the form: key1=value1;key2=value2;...
+ *
+ * Some keys are reserved for standard parameters (See AudioParameter class)
+ *
+ * If the implementation does not accept a parameter change while
+ * the output is active but the parameter is acceptable otherwise, it must
+ * return -ENOSYS.
+ *
+ * The audio flinger will put the stream in standby and then change the
+ * parameter value.
+ */
+ int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
+
+ /*
+ * Returns a pointer to a heap allocated string. The caller is responsible
+ * for freeing the memory for it.
+ */
+ char * (*get_parameters)(const struct audio_stream *stream,
+ const char *keys);
+};
+typedef struct audio_stream audio_stream_t;
+
+/**
+ * audio_stream_out is the abstraction interface for the audio output hardware.
+ *
+ * It provides information about various properties of the audio output
+ * hardware driver.
+ */
+
+struct audio_stream_out {
+ struct audio_stream common;
+
+ /**
+ * return the audio hardware driver latency in milli seconds.
+ */
+ uint32_t (*get_latency)(const struct audio_stream_out *stream);
+
+ /**
+ * Use this method in situations where audio mixing is done in the
+ * hardware. This method serves as a direct interface with hardware,
+ * allowing you to directly set the volume as apposed to via the framework.
+ * This method might produce multiple PCM outputs or hardware accelerated
+ * codecs, such as MP3 or AAC.
+ */
+ int (*set_volume)(struct audio_stream_out *stream, float left, float right);
+
+ /**
+ * write audio buffer to driver. Returns number of bytes written
+ */
+ ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
+ size_t bytes);
+
+ /* return the number of audio frames written by the audio dsp to DAC since
+ * the output has exited standby
+ */
+ int (*get_render_position)(const struct audio_stream_out *stream,
+ uint32_t *dsp_frames);
+};
+typedef struct audio_stream_out audio_stream_out_t;
+
+struct audio_stream_in {
+ struct audio_stream common;
+
+ /** set the input gain for the audio driver. This method is for
+ * for future use */
+ int (*set_gain)(struct audio_stream_in *stream, float gain);
+
+ /** read audio buffer in from audio driver */
+ ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
+ size_t bytes);
+
+ /**
+ * Return the amount of input frames lost in the audio driver since the
+ * last call of this function.
+ * Audio driver is expected to reset the value to 0 and restart counting
+ * upon returning the current value by this function call.
+ * Such loss typically occurs when the user space process is blocked
+ * longer than the capacity of audio driver buffers.
+ *
+ * Unit: the number of input audio frames
+ */
+ uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
+};
+typedef struct audio_stream_in audio_stream_in_t;
+
+/**
+ * return the frame size (number of bytes per sample).
+ */
+static inline uint32_t audio_stream_frame_size(struct audio_stream *s)
+{
+ int chan_samp_sz;
+
+ switch (s->get_format(s)) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ chan_samp_sz = sizeof(int16_t);
+ break;
+ case AUDIO_FORMAT_PCM_8_BIT:
+ default:
+ chan_samp_sz = sizeof(int8_t);
+ break;
+ }
+
+ return popcount(s->get_channels(s)) * chan_samp_sz;
+}
+
+
+/**********************************************************************/
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+struct audio_module {
+ struct hw_module_t common;
+};
+
+struct audio_hw_device {
+ struct hw_device_t common;
+
+ /**
+ * used by audio flinger to enumerate what devices are supported by
+ * each audio_hw_device implementation.
+ *
+ * Return value is a bitmask of 1 or more values of audio_devices_t
+ */
+ uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
+
+ /**
+ * check to see if the audio hardware interface has been initialized.
+ * returns 0 on success, -ENODEV on failure.
+ */
+ int (*init_check)(const struct audio_hw_device *dev);
+
+ /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
+ int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
+
+ /**
+ * set the audio volume for all audio activities other than voice call.
+ * Range between 0.0 and 1.0. If any value other than 0 is returned,
+ * the software mixer will emulate this capability.
+ */
+ int (*set_master_volume)(struct audio_hw_device *dev, float volume);
+
+ /**
+ * setMode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
+ * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
+ * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
+ */
+ int (*set_mode)(struct audio_hw_device *dev, int mode);
+
+ /* mic mute */
+ int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
+ int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
+
+ /* set/get global audio parameters */
+ int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
+
+ /*
+ * Returns a pointer to a heap allocated string. The caller is responsible
+ * for freeing the memory for it.
+ */
+ char * (*get_parameters)(const struct audio_hw_device *dev,
+ const char *keys);
+
+ /* Returns audio input buffer size according to parameters passed or
+ * 0 if one of the parameters is not supported
+ */
+ size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
+ uint32_t sample_rate, int format,
+ int channel_count);
+
+ /** This method creates and opens the audio hardware output stream */
+ int (*open_output_stream)(struct audio_hw_device *dev, uint32_t devices,
+ int *format, uint32_t *channels,
+ uint32_t *sample_rate,
+ struct audio_stream_out **out);
+
+ void (*close_output_stream)(struct audio_hw_device *dev,
+ struct audio_stream_out* out);
+
+ /** This method creates and opens the audio hardware input stream */
+ int (*open_input_stream)(struct audio_hw_device *dev, uint32_t devices,
+ int *format, uint32_t *channels,
+ uint32_t *sample_rate,
+ audio_in_acoustics_t acoustics,
+ struct audio_stream_in **stream_in);
+
+ void (*close_input_stream)(struct audio_hw_device *dev,
+ struct audio_stream_in *in);
+
+ /** This method dumps the state of the audio hardware */
+ int (*dump)(const struct audio_hw_device *dev, int fd);
+};
+typedef struct audio_hw_device audio_hw_device_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int audio_hw_device_open(const struct hw_module_t* module,
+ struct audio_hw_device** device)
+{
+ return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
+ (struct hw_device_t**)device);
+}
+
+static inline int audio_hw_device_close(struct audio_hw_device* device)
+{
+ return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_INTERFACE_H
diff --git a/include/hardware/audio_policy.h b/include/hardware/audio_policy.h
new file mode 100644
index 0000000..1e0af7d
--- /dev/null
+++ b/include/hardware/audio_policy.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_POLICY_CORE_H
+#define ANDROID_AUDIO_POLICY_CORE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+__BEGIN_DECLS
+
+/* The enums were moved here mostly from
+ * frameworks/base/include/media/AudioSystem.h
+ */
+
+/* request to open a direct output with get_output() (by opposition to
+ * sharing an output with other AudioTracks)
+ */
+typedef enum {
+ AUDIO_POLICY_OUTPUT_FLAG_INDIRECT = 0x0,
+ AUDIO_POLICY_OUTPUT_FLAG_DIRECT = 0x1
+} audio_policy_output_flags_t;
+
+/* device categories used for audio_policy->set_force_use() */
+typedef enum {
+ AUDIO_POLICY_FORCE_NONE,
+ AUDIO_POLICY_FORCE_SPEAKER,
+ AUDIO_POLICY_FORCE_HEADPHONES,
+ AUDIO_POLICY_FORCE_BT_SCO,
+ AUDIO_POLICY_FORCE_BT_A2DP,
+ AUDIO_POLICY_FORCE_WIRED_ACCESSORY,
+ AUDIO_POLICY_FORCE_BT_CAR_DOCK,
+ AUDIO_POLICY_FORCE_BT_DESK_DOCK,
+ AUDIO_POLICY_FORCE_ANALOG_DOCK,
+ AUDIO_POLICY_FORCE_DIGITAL_DOCK,
+
+ AUDIO_POLICY_FORCE_CFG_CNT,
+ AUDIO_POLICY_FORCE_CFG_MAX = AUDIO_POLICY_FORCE_CFG_CNT - 1,
+
+ AUDIO_POLICY_FORCE_DEFAULT = AUDIO_POLICY_FORCE_NONE,
+} audio_policy_forced_cfg_t;
+
+/* usages used for audio_policy->set_force_use() */
+typedef enum {
+ AUDIO_POLICY_FORCE_FOR_COMMUNICATION,
+ AUDIO_POLICY_FORCE_FOR_MEDIA,
+ AUDIO_POLICY_FORCE_FOR_RECORD,
+ AUDIO_POLICY_FORCE_FOR_DOCK,
+
+ AUDIO_POLICY_FORCE_USE_CNT,
+ AUDIO_POLICY_FORCE_USE_MAX = AUDIO_POLICY_FORCE_USE_CNT - 1,
+} audio_policy_force_use_t;
+
+/* device connection states used for audio_policy->set_device_connection_state()
+ */
+typedef enum {
+ AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
+ AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
+
+ AUDIO_POLICY_DEVICE_STATE_CNT,
+ AUDIO_POLICY_DEVICE_STATE_MAX = AUDIO_POLICY_DEVICE_STATE_CNT - 1,
+} audio_policy_dev_state_t;
+
+typedef enum {
+ /* Used to generate a tone to notify the user of a
+ * notification/alarm/ringtone while they are in a call. */
+ AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION = 0,
+
+ AUDIO_POLICY_TONE_CNT,
+ AUDIO_POLICY_TONE_MAX = AUDIO_POLICY_TONE_CNT - 1,
+} audio_policy_tone_t;
+
+
+static inline bool audio_is_low_visibility(audio_stream_type_t stream)
+{
+ switch (stream) {
+ case AUDIO_STREAM_SYSTEM:
+ case AUDIO_STREAM_NOTIFICATION:
+ case AUDIO_STREAM_RING:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_POLICY_CORE_H
diff --git a/include/hardware/audio_policy_hal.h b/include/hardware/audio_policy_hal.h
new file mode 100644
index 0000000..37be011
--- /dev/null
+++ b/include/hardware/audio_policy_hal.h
@@ -0,0 +1,384 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_POLICY_INTERFACE_H
+#define ANDROID_AUDIO_POLICY_INTERFACE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+#include <hardware/audio.h>
+#include <hardware/audio_policy.h>
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define AUDIO_POLICY_HARDWARE_MODULE_ID "audio_policy"
+
+/**
+ * Name of the audio devices to open
+ */
+#define AUDIO_POLICY_INTERFACE "policy"
+
+/* ---------------------------------------------------------------------------- */
+
+/*
+ * The audio_policy and audio_policy_service_ops structs define the
+ * communication interfaces between the platform specific audio policy manager
+ * and Android generic audio policy manager.
+ * The platform specific audio policy manager must implement methods of the
+ * audio_policy struct.
+ * This implementation makes use of the audio_policy_service_ops to control
+ * the activity and configuration of audio input and output streams.
+ *
+ * The platform specific audio policy manager is in charge of the audio
+ * routing and volume control policies for a given platform.
+ * The main roles of this module are:
+ * - keep track of current system state (removable device connections, phone
+ * state, user requests...).
+ * System state changes and user actions are notified to audio policy
+ * manager with methods of the audio_policy.
+ *
+ * - process get_output() queries received when AudioTrack objects are
+ * created: Those queries return a handler on an output that has been
+ * selected, configured and opened by the audio policy manager and that
+ * must be used by the AudioTrack when registering to the AudioFlinger
+ * with the createTrack() method.
+ * When the AudioTrack object is released, a release_output() query
+ * is received and the audio policy manager can decide to close or
+ * reconfigure the output depending on other streams using this output and
+ * current system state.
+ *
+ * - similarly process get_input() and release_input() queries received from
+ * AudioRecord objects and configure audio inputs.
+ * - process volume control requests: the stream volume is converted from
+ * an index value (received from UI) to a float value applicable to each
+ * output as a function of platform specific settings and current output
+ * route (destination device). It also make sure that streams are not
+ * muted if not allowed (e.g. camera shutter sound in some countries).
+ */
+
+/* XXX: this should be defined OUTSIDE of frameworks/base */
+struct effect_descriptor_s;
+
+struct audio_policy {
+ /*
+ * configuration functions
+ */
+
+ /* indicate a change in device connection status */
+ int (*set_device_connection_state)(struct audio_policy *pol,
+ audio_devices_t device,
+ audio_policy_dev_state_t state,
+ const char *device_address);
+
+ /* retreive a device connection status */
+ audio_policy_dev_state_t (*get_device_connection_state)(
+ const struct audio_policy *pol,
+ audio_devices_t device,
+ const char *device_address);
+
+ /* indicate a change in phone state. Valid phones states are defined
+ * by audio_mode_t */
+ void (*set_phone_state)(struct audio_policy *pol, int state);
+
+ /* indicate a change in ringer mode */
+ void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode,
+ uint32_t mask);
+
+ /* force using a specific device category for the specified usage */
+ void (*set_force_use)(struct audio_policy *pol,
+ audio_policy_force_use_t usage,
+ audio_policy_forced_cfg_t config);
+
+ /* retreive current device category forced for a given usage */
+ audio_policy_forced_cfg_t (*get_force_use)(const struct audio_policy *pol,
+ audio_policy_force_use_t usage);
+
+ /* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
+ * can still be muted. */
+ void (*set_can_mute_enforced_audible)(struct audio_policy *pol,
+ bool can_mute);
+
+ /* check proper initialization */
+ int (*init_check)(const struct audio_policy *pol);
+
+ /*
+ * Audio routing query functions
+ */
+
+ /* request an output appriate for playback of the supplied stream type and
+ * parameters */
+ audio_io_handle_t (*get_output)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ uint32_t samplingRate,
+ uint32_t format,
+ uint32_t channels,
+ audio_policy_output_flags_t flags);
+
+ /* indicates to the audio policy manager that the output starts being used
+ * by corresponding stream. */
+ int (*start_output)(struct audio_policy *pol,
+ audio_io_handle_t output,
+ audio_stream_type_t stream,
+ int session);
+
+ /* indicates to the audio policy manager that the output stops being used
+ * by corresponding stream. */
+ int (*stop_output)(struct audio_policy *pol,
+ audio_io_handle_t output,
+ audio_stream_type_t stream,
+ int session);
+
+ /* releases the output. */
+ void (*release_output)(struct audio_policy *pol, audio_io_handle_t output);
+
+ /* request an input appriate for record from the supplied device with
+ * supplied parameters. */
+ audio_io_handle_t (*get_input)(struct audio_policy *pol, int inputSource,
+ uint32_t samplingRate,
+ uint32_t format,
+ uint32_t channels,
+ audio_in_acoustics_t acoustics);
+
+ /* indicates to the audio policy manager that the input starts being used */
+ int (*start_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+ /* indicates to the audio policy manager that the input stops being used. */
+ int (*stop_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+ /* releases the input. */
+ void (*release_input)(struct audio_policy *pol, audio_io_handle_t input);
+
+ /*
+ * volume control functions
+ */
+
+ /* initialises stream volume conversion parameters by specifying volume
+ * index range. */
+ void (*init_stream_volume)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index_min,
+ int index_max);
+
+ /* sets the new stream volume at a level corresponding to the supplied
+ * index */
+ int (*set_stream_volume_index)(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index);
+
+ /* retreive current volume index for the specified stream */
+ int (*get_stream_volume_index)(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int *index);
+
+ /* return the strategy corresponding to a given stream type */
+ uint32_t (*get_strategy_for_stream)(const struct audio_policy *pol,
+ audio_stream_type_t stream);
+
+ /* return the enabled output devices for the given stream type */
+ uint32_t (*get_devices_for_stream)(const struct audio_policy *pol,
+ audio_stream_type_t stream);
+
+ /* Audio effect management */
+ audio_io_handle_t (*get_output_for_effect)(struct audio_policy *pol,
+ struct effect_descriptor_s *desc);
+
+ int (*register_effect)(struct audio_policy *pol,
+ struct effect_descriptor_s *desc,
+ audio_io_handle_t output,
+ uint32_t strategy,
+ int session,
+ int id);
+
+ int (*unregister_effect)(struct audio_policy *pol, int id);
+
+ bool (*is_stream_active)(const struct audio_policy *pol,
+ int stream,
+ uint32_t in_past_ms);
+
+ /* dump state */
+ int (*dump)(const struct audio_policy *pol, int fd);
+};
+
+struct audio_policy_service_ops {
+ /*
+ * Audio output Control functions
+ */
+
+ /* Opens an audio output with the requested parameters.
+ *
+ * The parameter values can indicate to use the default values in case the
+ * audio policy manager has no specific requirements for the output being
+ * opened.
+ *
+ * When the function returns, the parameter values reflect the actual
+ * values used by the audio hardware output stream.
+ *
+ * The audio policy manager can check if the proposed parameters are
+ * suitable or not and act accordingly.
+ */
+ audio_io_handle_t (*open_output)(void *service,
+ uint32_t *pDevices,
+ uint32_t *pSamplingRate,
+ uint32_t *pFormat,
+ uint32_t *pChannels,
+ uint32_t *pLatencyMs,
+ audio_policy_output_flags_t flags);
+
+ /* creates a special output that is duplicated to the two outputs passed as
+ * arguments. The duplication is performed by
+ * a special mixer thread in the AudioFlinger.
+ */
+ audio_io_handle_t (*open_duplicate_output)(void *service,
+ audio_io_handle_t output1,
+ audio_io_handle_t output2);
+
+ /* closes the output stream */
+ int (*close_output)(void *service, audio_io_handle_t output);
+
+ /* suspends the output.
+ *
+ * When an output is suspended, the corresponding audio hardware output
+ * stream is placed in standby and the AudioTracks attached to the mixer
+ * thread are still processed but the output mix is discarded.
+ */
+ int (*suspend_output)(void *service, audio_io_handle_t output);
+
+ /* restores a suspended output. */
+ int (*restore_output)(void *service, audio_io_handle_t output);
+
+ /* */
+ /* Audio input Control functions */
+ /* */
+
+ /* opens an audio input */
+ audio_io_handle_t (*open_input)(void *service,
+ uint32_t *pDevices,
+ uint32_t *pSamplingRate,
+ uint32_t *pFormat,
+ uint32_t *pChannels,
+ uint32_t acoustics);
+
+ /* closes an audio input */
+ int (*close_input)(void *service, audio_io_handle_t input);
+
+ /* */
+ /* misc control functions */
+ /* */
+
+ /* set a stream volume for a particular output.
+ *
+ * For the same user setting, a given stream type can have different
+ * volumes for each output (destination device) it is attached to.
+ */
+ int (*set_stream_volume)(void *service,
+ audio_stream_type_t stream,
+ float volume,
+ audio_io_handle_t output,
+ int delay_ms);
+
+ /* reroute a given stream type to the specified output */
+ int (*set_stream_output)(void *service,
+ audio_stream_type_t stream,
+ audio_io_handle_t output);
+
+ /* function enabling to send proprietary informations directly from audio
+ * policy manager to audio hardware interface. */
+ void (*set_parameters)(void *service,
+ audio_io_handle_t io_handle,
+ const char *kv_pairs,
+ int delay_ms);
+
+ /* function enabling to receive proprietary informations directly from
+ * audio hardware interface to audio policy manager.
+ *
+ * Returns a pointer to a heap allocated string. The caller is responsible
+ * for freeing the memory for it.
+ */
+
+ char * (*get_parameters)(void *service, audio_io_handle_t io_handle,
+ const char *keys);
+
+ /* request the playback of a tone on the specified stream.
+ * used for instance to replace notification sounds when playing over a
+ * telephony device during a phone call.
+ */
+ int (*start_tone)(void *service,
+ audio_policy_tone_t tone,
+ audio_stream_type_t stream);
+
+ int (*stop_tone)(void *service);
+
+ /* set down link audio volume. */
+ int (*set_voice_volume)(void *service,
+ float volume,
+ int delay_ms);
+
+ /* move effect to the specified output */
+ int (*move_effects)(void *service,
+ int session,
+ audio_io_handle_t src_output,
+ audio_io_handle_t dst_output);
+};
+
+/**********************************************************************/
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct audio_policy_module {
+ struct hw_module_t common;
+} audio_policy_module_t;
+
+struct audio_policy_device {
+ struct hw_device_t common;
+
+ int (*create_audio_policy)(const struct audio_policy_device *device,
+ struct audio_policy_service_ops *aps_ops,
+ void *service,
+ struct audio_policy **ap);
+
+ int (*destroy_audio_policy)(const struct audio_policy_device *device,
+ struct audio_policy *ap);
+};
+
+/** convenience API for opening and closing a supported device */
+
+static inline int audio_policy_dev_open(const hw_module_t* module,
+ struct audio_policy_device** device)
+{
+ return module->methods->open(module, AUDIO_POLICY_INTERFACE,
+ (hw_device_t**)device);
+}
+
+static inline int audio_policy_dev_close(struct audio_policy_device* device)
+{
+ return device->common.close(&device->common);
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_POLICY_INTERFACE_H