1f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/* 2f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Copyright (C) 2011 The Android Open Source Project 3f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 4f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Licensed under the Apache License, Version 2.0 (the "License"); 5f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * you may not use this file except in compliance with the License. 6f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * You may obtain a copy of the License at 7f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 8f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * http://www.apache.org/licenses/LICENSE-2.0 9f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 10f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Unless required by applicable law or agreed to in writing, software 11f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * distributed under the License is distributed on an "AS IS" BASIS, 12f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * See the License for the specific language governing permissions and 14f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * limitations under the License. 15f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 16f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 17f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 18f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#ifndef ANDROID_AUDIO_HAL_INTERFACE_H 19f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#define ANDROID_AUDIO_HAL_INTERFACE_H 20f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 21f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#include <stdint.h> 22f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#include <strings.h> 23f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#include <sys/cdefs.h> 24f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#include <sys/types.h> 25f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 26f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#include <cutils/bitops.h> 27f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 28f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#include <hardware/hardware.h> 29aa21172bcd4c332eec78d34ffdafd8cc0178ea95Dima Zavin#include <system/audio.h> 30f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent#include <hardware/audio_effect.h> 31f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 32f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin__BEGIN_DECLS 33f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 34f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 35f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * The id of this module 36f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 37f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#define AUDIO_HARDWARE_MODULE_ID "audio" 38f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 39f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 40f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Name of the audio devices to open 41f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 42f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#define AUDIO_HARDWARE_INTERFACE "audio_hw_if" 43f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 4455786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 4555786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent/* Use version 0.1 to be compatible with first generation of audio hw module with version_major 4655786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent * hardcoded to 1. No audio module API change. 4755786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent */ 4855786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) 4955786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1 5055786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 5155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0 5255786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent * will be considered of first generation API. 5355786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent */ 5455786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0) 5555786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) 5685e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) 5785e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_2_0 5855786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 59431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent/** 60431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * List of known audio HAL modules. This is the base name of the audio HAL 61431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * library composed of the "audio." prefix, one of the base names below and 62431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * a suffix specific to the device. 63431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * e.g: audio.primary.goldfish.so or audio.a2dp.default.so 64431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent */ 65431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent 66431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary" 67431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp" 68431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent#define AUDIO_HARDWARE_MODULE_ID_USB "usb" 6988b79cb001d1c733275c7cad490c32b143f78860Jean-Michel Trivi#define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix" 70f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload" 71431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent 72f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/**************************************/ 73f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 7470e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/** 7570e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent * standard audio parameters that the HAL may need to handle 7670e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent */ 7770e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 7870e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/** 7970e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent * audio device parameters 8070e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent */ 8170e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 82ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent/* BT SCO Noise Reduction + Echo Cancellation parameters */ 83ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec" 84ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent#define AUDIO_PARAMETER_VALUE_ON "on" 85ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent#define AUDIO_PARAMETER_VALUE_OFF "off" 86ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent 8770e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/* TTY mode selection */ 8870e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode" 8970e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off" 9070e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco" 9170e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco" 9270e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full" 9370e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 94a70c5d0cafe1ef9e4531627d3d009e80b9a8eec4Eric Laurent/* A2DP sink address set by framework */ 95a70c5d0cafe1ef9e4531627d3d009e80b9a8eec4Eric Laurent#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address" 96a70c5d0cafe1ef9e4531627d3d009e80b9a8eec4Eric Laurent 9734afb68c0cd1de315f0250f6a95b9dba234133aeGlenn Kasten/* Screen state */ 9834afb68c0cd1de315f0250f6a95b9dba234133aeGlenn Kasten#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state" 9934afb68c0cd1de315f0250f6a95b9dba234133aeGlenn Kasten 10070e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/** 10170e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent * audio stream parameters 10270e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent */ 10370e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 1040cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten#define AUDIO_PARAMETER_STREAM_ROUTING "routing" // audio_devices_t 1050cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten#define AUDIO_PARAMETER_STREAM_FORMAT "format" // audio_format_t 1060cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" // audio_channel_mask_t 1070cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" // size_t 1080cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" // audio_source_t 1090cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" // uint32_t 11057dde28fb80e1a166db283296812f5fb078ca24aDima Zavin 11141eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent/* Query supported formats. The response is a '|' separated list of strings from 11241eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */ 11341eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats" 11441eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent/* Query supported channel masks. The response is a '|' separated list of strings from 11541eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */ 11641eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels" 11741eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent/* Query supported sampling rates. The response is a '|' separated list of integer values e.g: 11841eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent * "sup_sampling_rates=44100|48000" */ 11941eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates" 12041eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent 121f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/** 122f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * audio codec parameters 123f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 124f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 125f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param" 126f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample" 127f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate" 128f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate" 129f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id" 130f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align" 131f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate" 132f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option" 133f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels" 134f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling" 135f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples" 136f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples" 13755786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 13870e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/**************************************/ 13970e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 140f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/* common audio stream configuration parameters 141f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * You should memset() the entire structure to zero before use to 142f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * ensure forward compatibility 143f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 14455786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurentstruct audio_config { 14555786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent uint32_t sample_rate; 14655786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_channel_mask_t channel_mask; 14755786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_format_t format; 148f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald audio_offload_info_t offload_info; 14955786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent}; 15055786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurenttypedef struct audio_config audio_config_t; 15155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 152f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/* common audio stream parameters and operations */ 153f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_stream { 154f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 155f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1560cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the sampling rate in Hz - eg. 44100. 157f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 158f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_sample_rate)(const struct audio_stream *stream); 15957dde28fb80e1a166db283296812f5fb078ca24aDima Zavin 16057dde28fb80e1a166db283296812f5fb078ca24aDima Zavin /* currently unused - use set_parameters with key 16157dde28fb80e1a166db283296812f5fb078ca24aDima Zavin * AUDIO_PARAMETER_STREAM_SAMPLING_RATE 16257dde28fb80e1a166db283296812f5fb078ca24aDima Zavin */ 163f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate); 164f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 165f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1660cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return size of input/output buffer in bytes for this stream - eg. 4800. 1670cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * It should be a multiple of the frame size. See also get_input_buffer_size. 168f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 169f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t (*get_buffer_size)(const struct audio_stream *stream); 170f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 171f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1720cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the channel mask - 173f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO 174f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 17555786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_channel_mask_t (*get_channels)(const struct audio_stream *stream); 176f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 177f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1780cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT 179f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 180fe79eb3f06967f863a637e546eb4421d0da2283bGlenn Kasten audio_format_t (*get_format)(const struct audio_stream *stream); 18157dde28fb80e1a166db283296812f5fb078ca24aDima Zavin 18257dde28fb80e1a166db283296812f5fb078ca24aDima Zavin /* currently unused - use set_parameters with key 18357dde28fb80e1a166db283296812f5fb078ca24aDima Zavin * AUDIO_PARAMETER_STREAM_FORMAT 18457dde28fb80e1a166db283296812f5fb078ca24aDima Zavin */ 185fe79eb3f06967f863a637e546eb4421d0da2283bGlenn Kasten int (*set_format)(struct audio_stream *stream, audio_format_t format); 186f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 187f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 188f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Put the audio hardware input/output into standby mode. 1890cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Driver should exit from standby mode at the next I/O operation. 190f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Returns 0 on success and <0 on failure. 191f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 192f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*standby)(struct audio_stream *stream); 193f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 194f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** dump the state of the audio input/output device */ 195f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*dump)(const struct audio_stream *stream, int fd); 196f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 1970cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten /** Return the set of device(s) which this stream is connected to */ 198f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin audio_devices_t (*get_device)(const struct audio_stream *stream); 1990cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten 2000cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten /** 2010cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Currently unused - set_device() corresponds to set_parameters() with key 2020cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * AUDIO_PARAMETER_STREAM_ROUTING for both input and output. 2030cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by 2040cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * input streams only. 2050cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten */ 206f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_device)(struct audio_stream *stream, audio_devices_t device); 207f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 208f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 209f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * set/get audio stream parameters. The function accepts a list of 210f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * parameter key value pairs in the form: key1=value1;key2=value2;... 211f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 212f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Some keys are reserved for standard parameters (See AudioParameter class) 213f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 214f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * If the implementation does not accept a parameter change while 215f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * the output is active but the parameter is acceptable otherwise, it must 216f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * return -ENOSYS. 217f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 218f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * The audio flinger will put the stream in standby and then change the 219f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * parameter value. 220f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 221f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs); 222f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 223f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* 224f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Returns a pointer to a heap allocated string. The caller is responsible 2250cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * for freeing the memory for it using free(). 226f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 227f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin char * (*get_parameters)(const struct audio_stream *stream, 228f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin const char *keys); 229f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent int (*add_audio_effect)(const struct audio_stream *stream, 230f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent effect_handle_t effect); 231f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent int (*remove_audio_effect)(const struct audio_stream *stream, 232f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent effect_handle_t effect); 233f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 234f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_stream audio_stream_t; 235f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 236f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/* type of asynchronous write callback events. Mutually exclusive */ 237f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgeraldtypedef enum { 238f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */ 239f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald STREAM_CBK_EVENT_DRAIN_READY /* drain completed */ 240f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald} stream_callback_event_t; 241f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 242f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgeraldtypedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie); 243f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 244f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */ 245f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgeraldtypedef enum { 246f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */ 247f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data 248f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald from the current track has been played to 249f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald give time for gapless track switch */ 250f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald} audio_drain_type_t; 251f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 252f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 253f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * audio_stream_out is the abstraction interface for the audio output hardware. 254f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 255f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * It provides information about various properties of the audio output 256f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * hardware driver. 257f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 258f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 259f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_stream_out { 260f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_stream common; 261f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 262f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 2630cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the audio hardware driver estimated latency in milliseconds. 264f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 265f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_latency)(const struct audio_stream_out *stream); 266f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 267f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 268f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Use this method in situations where audio mixing is done in the 269f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * hardware. This method serves as a direct interface with hardware, 270f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * allowing you to directly set the volume as apposed to via the framework. 271f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * This method might produce multiple PCM outputs or hardware accelerated 272f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * codecs, such as MP3 or AAC. 273f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 274f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_volume)(struct audio_stream_out *stream, float left, float right); 275f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 276f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 2770cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Write audio buffer to driver. Returns number of bytes written, or a 2780cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * negative status_t. If at least one frame was written successfully prior to the error, 2790cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * it is suggested that the driver return that successful (short) byte count 2800cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * and then return an error in the subsequent call. 281f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 282f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If set_callback() has previously been called to enable non-blocking mode 283f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * the write() is not allowed to block. It must write only the number of 284f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * bytes that currently fit in the driver/hardware buffer and then return 285f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * this byte count. If this is less than the requested write size the 286f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * callback function must be called when more space is available in the 287f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * driver/hardware buffer. 288f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 289f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin ssize_t (*write)(struct audio_stream_out *stream, const void* buffer, 290f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t bytes); 291f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 292f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* return the number of audio frames written by the audio dsp to DAC since 293f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * the output has exited standby 294f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 295f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*get_render_position)(const struct audio_stream_out *stream, 296f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t *dsp_frames); 2975ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen 2985ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen /** 2990cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * get the local time at which the next write to the audio driver will be presented. 3000cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * The units are microseconds, where the epoch is decided by the local audio HAL. 3015ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen */ 3025ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen int (*get_next_write_timestamp)(const struct audio_stream_out *stream, 3035ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen int64_t *timestamp); 3045ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen 305f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 306f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * set the callback function for notifying completion of non-blocking 307f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * write and drain. 308f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Calling this function implies that all future write() and drain() 309f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * must be non-blocking and use the callback to signal completion. 310f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 311f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*set_callback)(struct audio_stream_out *stream, 312f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald stream_callback_t callback, void *cookie); 313f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 314f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 315f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Notifies to the audio driver to stop playback however the queued buffers are 316f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * retained by the hardware. Useful for implementing pause/resume. Empty implementation 317f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * if not supported however should be implemented for hardware with non-trivial 318f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * latency. In the pause state audio hardware could still be using power. User may 319f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * consider calling suspend after a timeout. 320f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 321f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 322f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 323f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*pause)(struct audio_stream_out* stream); 324f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 325f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 326f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Notifies to the audio driver to resume playback following a pause. 327f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Returns error if called without matching pause. 328f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 329f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 330f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 331f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*resume)(struct audio_stream_out* stream); 332f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 333f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 334f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Requests notification when data buffered by the driver/hardware has 335f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * been played. If set_callback() has previously been called to enable 336f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * non-blocking mode, the drain() must not block, instead it should return 337f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * quickly and completion of the drain is notified through the callback. 338f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If set_callback() has not been called, the drain() must block until 339f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * completion. 340f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written 341f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * data has been played. 342f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all 343f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * data for the current track has played to allow time for the framework 344f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * to perform a gapless track switch. 345f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 346f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Drain must return immediately on stop() and flush() call 347f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 348f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 349f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 350f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type ); 351f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 352f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 353f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Notifies to the audio driver to flush the queued data. Stream must already 354f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * be paused before calling flush(). 355f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 356f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 357f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 358f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*flush)(struct audio_stream_out* stream); 359e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten 360e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten /** 36122a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * Return a recent count of the number of audio frames presented to an external observer. 362e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * This excludes frames which have been written but are still in the pipeline. 363e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * The count is not reset to zero when output enters standby. 364e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * Also returns the value of CLOCK_MONOTONIC as of this presentation count. 36522a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * The returned count is expected to be 'recent', 36622a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * but does not need to be the most recent possible value. 36722a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * However, the associated time should correspond to whatever count is returned. 36822a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * Example: assume that N+M frames have been presented, where M is a 'small' number. 36922a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * Then it is permissible to return N instead of N+M, 37022a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * and the timestamp should correspond to N rather than N+M. 37122a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * The terms 'recent' and 'small' are not defined. 37222a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * They reflect the quality of the implementation. 373e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * 374e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * 3.0 and higher only. 375e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten */ 376e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten int (*get_presentation_position)(const struct audio_stream_out *stream, 377e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten uint64_t *frames, struct timespec *timestamp); 378e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten 379f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 380f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_stream_out audio_stream_out_t; 381f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 382f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_stream_in { 383f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_stream common; 384f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 385f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** set the input gain for the audio driver. This method is for 386f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * for future use */ 387f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_gain)(struct audio_stream_in *stream, float gain); 388f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 3890cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten /** Read audio buffer in from audio driver. Returns number of bytes read, or a 3900cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * negative status_t. If at least one frame was read prior to the error, 3910cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * read should return that byte count and then return an error in the subsequent call. 3920cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten */ 393f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin ssize_t (*read)(struct audio_stream_in *stream, void* buffer, 394f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t bytes); 395f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 396f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 397f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Return the amount of input frames lost in the audio driver since the 398f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * last call of this function. 399f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Audio driver is expected to reset the value to 0 and restart counting 400f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * upon returning the current value by this function call. 401f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Such loss typically occurs when the user space process is blocked 402f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * longer than the capacity of audio driver buffers. 403f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 404f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Unit: the number of input audio frames 405f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 406f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream); 407f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 408f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_stream_in audio_stream_in_t; 409f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 410f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 411f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * return the frame size (number of bytes per sample). 412f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 41348915acb392773c1fcb86e2711eab468410a0baaGlenn Kastenstatic inline size_t audio_stream_frame_size(const struct audio_stream *s) 414f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin{ 415a26cbac8a0f71ba59a89e250caaa1155f0179751Glenn Kasten size_t chan_samp_sz; 416f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald audio_format_t format = s->get_format(s); 417f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 418f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald if (audio_is_linear_pcm(format)) { 419f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald chan_samp_sz = audio_bytes_per_sample(format); 420f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald return popcount(s->get_channels(s)) * chan_samp_sz; 421f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin } 422f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 423f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald return sizeof(int8_t); 424f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin} 425f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 426f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 427f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/**********************************************************************/ 428f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 429f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 430f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 431f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * and the fields of this data structure must begin with hw_module_t 432f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * followed by module specific information. 433f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 434f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_module { 435f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct hw_module_t common; 436f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 437f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 438f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_hw_device { 439f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct hw_device_t common; 440f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 441f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 442f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * used by audio flinger to enumerate what devices are supported by 443f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * each audio_hw_device implementation. 444f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 445f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Return value is a bitmask of 1 or more values of audio_devices_t 44685e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * 44785e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * NOTE: audio HAL implementations starting with 44885e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function. 44985e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * All supported devices should be listed in audio_policy.conf 45085e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * file and the audio policy manager must choose the appropriate 45185e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * audio module based on information in this file. 452f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 453f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_supported_devices)(const struct audio_hw_device *dev); 454f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 455f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 456f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * check to see if the audio hardware interface has been initialized. 457f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * returns 0 on success, -ENODEV on failure. 458f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 459f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*init_check)(const struct audio_hw_device *dev); 460f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 461f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ 462f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_voice_volume)(struct audio_hw_device *dev, float volume); 463f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 464f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 465f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * set the audio volume for all audio activities other than voice call. 466f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Range between 0.0 and 1.0. If any value other than 0 is returned, 467f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * the software mixer will emulate this capability. 468f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 469f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_master_volume)(struct audio_hw_device *dev, float volume); 470f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 471f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 4725ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * Get the current master volume value for the HAL, if the HAL supports 4735ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * master volume control. AudioFlinger will query this value from the 4745ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * primary audio HAL when the service starts and use the value for setting 4755ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * the initial master volume across all HALs. HALs which do not support 47647bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * this method may leave it set to NULL. 4775ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen */ 4785ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen int (*get_master_volume)(struct audio_hw_device *dev, float *volume); 4795ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen 4805ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen /** 4816df641e269639dbb81bb1c19f47d3b9e5e3ff7d7Glenn Kasten * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode 482f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is 483f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * playing, and AUDIO_MODE_IN_CALL when a call is in progress. 484f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 4856df641e269639dbb81bb1c19f47d3b9e5e3ff7d7Glenn Kasten int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode); 486f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 487f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* mic mute */ 488f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_mic_mute)(struct audio_hw_device *dev, bool state); 489f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state); 490f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 491f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* set/get global audio parameters */ 492f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs); 493f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 494f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* 495f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Returns a pointer to a heap allocated string. The caller is responsible 4960cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * for freeing the memory for it using free(). 497f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 498f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin char * (*get_parameters)(const struct audio_hw_device *dev, 499f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin const char *keys); 500f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 501f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* Returns audio input buffer size according to parameters passed or 5020cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * 0 if one of the parameters is not supported. 5030cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * See also get_buffer_size which is for a particular stream. 504f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 505f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t (*get_input_buffer_size)(const struct audio_hw_device *dev, 50655786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent const struct audio_config *config); 507f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 508f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** This method creates and opens the audio hardware output stream */ 50955786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent int (*open_output_stream)(struct audio_hw_device *dev, 51055786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_io_handle_t handle, 51155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_devices_t devices, 51255786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_output_flags_t flags, 51355786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_config *config, 51455786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_stream_out **stream_out); 515f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 516f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin void (*close_output_stream)(struct audio_hw_device *dev, 51755786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_stream_out* stream_out); 518f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 519f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** This method creates and opens the audio hardware input stream */ 52055786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent int (*open_input_stream)(struct audio_hw_device *dev, 52155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_io_handle_t handle, 52255786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_devices_t devices, 52355786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_config *config, 524f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_stream_in **stream_in); 525f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 526f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin void (*close_input_stream)(struct audio_hw_device *dev, 52755786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_stream_in *stream_in); 528f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 529f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** This method dumps the state of the audio hardware */ 530f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*dump)(const struct audio_hw_device *dev, int fd); 53147bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman 53247bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman /** 53347bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * set the audio mute status for all audio activities. If any value other 53447bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * than 0 is returned, the software mixer will emulate this capability. 53547bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman */ 53647bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman int (*set_master_mute)(struct audio_hw_device *dev, bool mute); 53747bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman 53847bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman /** 53947bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * Get the current master mute status for the HAL, if the HAL supports 54047bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * master mute control. AudioFlinger will query this value from the primary 54147bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * audio HAL when the service starts and use the value for setting the 54247bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * initial master mute across all HALs. HALs which do not support this 54347bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * method may leave it set to NULL. 54447bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman */ 54547bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman int (*get_master_mute)(struct audio_hw_device *dev, bool *mute); 546f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 547f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_hw_device audio_hw_device_t; 548f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 549f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** convenience API for opening and closing a supported device */ 550f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 551f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstatic inline int audio_hw_device_open(const struct hw_module_t* module, 552f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_hw_device** device) 553f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin{ 554f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin return module->methods->open(module, AUDIO_HARDWARE_INTERFACE, 555f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin (struct hw_device_t**)device); 556f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin} 557f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 558f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstatic inline int audio_hw_device_close(struct audio_hw_device* device) 559f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin{ 560f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin return device->common.close(&device->common); 561f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin} 562f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 563f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 564f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin__END_DECLS 565f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 566f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#endif // ANDROID_AUDIO_INTERFACE_H 567