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) 5773b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) 5873b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0 59447cae749c7bb4906bc21c645df5eb7e6d664027Eric Laurent/* Minimal audio HAL version supported by the audio framework */ 60447cae749c7bb4906bc21c645df5eb7e6d664027Eric Laurent#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0 6155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 62431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent/** 63431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * List of known audio HAL modules. This is the base name of the audio HAL 64431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * library composed of the "audio." prefix, one of the base names below and 65431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * a suffix specific to the device. 66431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent * e.g: audio.primary.goldfish.so or audio.a2dp.default.so 67431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent */ 68431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent 69431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary" 70431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp" 71431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent#define AUDIO_HARDWARE_MODULE_ID_USB "usb" 7288b79cb001d1c733275c7cad490c32b143f78860Jean-Michel Trivi#define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix" 73f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload" 74431fc78c112646f43d6d6f51b06d45d248d2f317Eric Laurent 75f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/**************************************/ 76f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 7770e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/** 7870e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent * standard audio parameters that the HAL may need to handle 7970e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent */ 8070e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 8170e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/** 8270e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent * audio device parameters 8370e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent */ 8470e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 85ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent/* BT SCO Noise Reduction + Echo Cancellation parameters */ 86ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec" 87ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent#define AUDIO_PARAMETER_VALUE_ON "on" 88ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent#define AUDIO_PARAMETER_VALUE_OFF "off" 89ed9928c76d107d02452a25a0d62803197c47f673Eric Laurent 9070e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/* TTY mode selection */ 9170e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode" 9270e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off" 9370e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco" 9470e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco" 9570e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full" 9670e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 97d1a1b1c4df8b892aaafc9fb5d52045b41915b4d8Eric Laurent/* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off 98d1a1b1c4df8b892aaafc9fb5d52045b41915b4d8Eric Laurent Strings must be in sync with CallFeaturesSetting.java */ 99d1a1b1c4df8b892aaafc9fb5d52045b41915b4d8Eric Laurent#define AUDIO_PARAMETER_KEY_HAC "HACSetting" 100d1a1b1c4df8b892aaafc9fb5d52045b41915b4d8Eric Laurent#define AUDIO_PARAMETER_VALUE_HAC_ON "ON" 101d1a1b1c4df8b892aaafc9fb5d52045b41915b4d8Eric Laurent#define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF" 102d1a1b1c4df8b892aaafc9fb5d52045b41915b4d8Eric Laurent 103a70c5d0cafe1ef9e4531627d3d009e80b9a8eec4Eric Laurent/* A2DP sink address set by framework */ 104a70c5d0cafe1ef9e4531627d3d009e80b9a8eec4Eric Laurent#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address" 105a70c5d0cafe1ef9e4531627d3d009e80b9a8eec4Eric Laurent 1062d4d96574ee496f646149b2c00a25d8a7df9fcd1Mike Lockwood/* A2DP source address set by framework */ 1072d4d96574ee496f646149b2c00a25d8a7df9fcd1Mike Lockwood#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address" 1082d4d96574ee496f646149b2c00a25d8a7df9fcd1Mike Lockwood 10934afb68c0cd1de315f0250f6a95b9dba234133aeGlenn Kasten/* Screen state */ 11034afb68c0cd1de315f0250f6a95b9dba234133aeGlenn Kasten#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state" 11134afb68c0cd1de315f0250f6a95b9dba234133aeGlenn Kasten 112d930d92c9730b13ba14e46aff588d6b7252e68c9Glenn Kasten/* Bluetooth SCO wideband */ 113d930d92c9730b13ba14e46aff588d6b7252e68c9Glenn Kasten#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs" 114d930d92c9730b13ba14e46aff588d6b7252e68c9Glenn Kasten 115bc19a3de775b6a1e4a5576c6447927637fc3b5b5Eric Laurent/* Get a new HW synchronization source identifier. 116bc19a3de775b6a1e4a5576c6447927637fc3b5b5Eric Laurent * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs 117bc19a3de775b6a1e4a5576c6447927637fc3b5b5Eric Laurent * or no HW sync is available. */ 118bc19a3de775b6a1e4a5576c6447927637fc3b5b5Eric Laurent#define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync" 1194ea9b95684508f25d9aa5d55396fc48bdde3085bEric Laurent 12070e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/** 12170e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent * audio stream parameters 12270e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent */ 12370e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 124f5e2469c02825f018df6336125882812003b8e64Eric Laurent#define AUDIO_PARAMETER_STREAM_ROUTING "routing" /* audio_devices_t */ 125f5e2469c02825f018df6336125882812003b8e64Eric Laurent#define AUDIO_PARAMETER_STREAM_FORMAT "format" /* audio_format_t */ 126f5e2469c02825f018df6336125882812003b8e64Eric Laurent#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" /* audio_channel_mask_t */ 127f5e2469c02825f018df6336125882812003b8e64Eric Laurent#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" /* size_t */ 128f5e2469c02825f018df6336125882812003b8e64Eric Laurent#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" /* audio_source_t */ 129f5e2469c02825f018df6336125882812003b8e64Eric Laurent#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */ 13057dde28fb80e1a166db283296812f5fb078ca24aDima Zavin 131d5f7dbec0cac2d0e638025e43f8fb0d611d22bfaHaynes Mathew George#define AUDIO_PARAMETER_DEVICE_CONNECT "connect" /* audio_devices_t */ 1322c6196f20c2ca25f6e7f8e0f752c2cbc00113538Paul McLean#define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect" /* audio_devices_t */ 1332c6196f20c2ca25f6e7f8e0f752c2cbc00113538Paul McLean 13441eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent/* Query supported formats. The response is a '|' separated list of strings from 13541eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */ 13641eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats" 13741eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent/* Query supported channel masks. The response is a '|' separated list of strings from 13841eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */ 13941eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels" 14041eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent/* Query supported sampling rates. The response is a '|' separated list of integer values e.g: 14141eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent * "sup_sampling_rates=44100|48000" */ 14241eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates" 14341eeb4fe9f0a043dc207111893dbea26827217a6Eric Laurent 144bc19a3de775b6a1e4a5576c6447927637fc3b5b5Eric Laurent/* Set the HW synchronization source for an output stream. */ 1454ea9b95684508f25d9aa5d55396fc48bdde3085bEric Laurent#define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync" 1464ea9b95684508f25d9aa5d55396fc48bdde3085bEric Laurent 147f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/** 148f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * audio codec parameters 149f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 150f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 151f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param" 152f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample" 153f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate" 154f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate" 155f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id" 156f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align" 157f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate" 158f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option" 159f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels" 160f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling" 161f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples" 162f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald#define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples" 16355786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent 16470e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent/**************************************/ 16570e8110fcf2c35d1ac67f0eb4a2702014a16719bEric Laurent 166f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/* common audio stream parameters and operations */ 167f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_stream { 168f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 169f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1700cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the sampling rate in Hz - eg. 44100. 171f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 172f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_sample_rate)(const struct audio_stream *stream); 17357dde28fb80e1a166db283296812f5fb078ca24aDima Zavin 17457dde28fb80e1a166db283296812f5fb078ca24aDima Zavin /* currently unused - use set_parameters with key 17557dde28fb80e1a166db283296812f5fb078ca24aDima Zavin * AUDIO_PARAMETER_STREAM_SAMPLING_RATE 17657dde28fb80e1a166db283296812f5fb078ca24aDima Zavin */ 177f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate); 178f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 179f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1800cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return size of input/output buffer in bytes for this stream - eg. 4800. 1810cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * It should be a multiple of the frame size. See also get_input_buffer_size. 182f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 183f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t (*get_buffer_size)(const struct audio_stream *stream); 184f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 185f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1860cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the channel mask - 187f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO 188f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 18955786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_channel_mask_t (*get_channels)(const struct audio_stream *stream); 190f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 191f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 1920cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT 193f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 194fe79eb3f06967f863a637e546eb4421d0da2283bGlenn Kasten audio_format_t (*get_format)(const struct audio_stream *stream); 19557dde28fb80e1a166db283296812f5fb078ca24aDima Zavin 19657dde28fb80e1a166db283296812f5fb078ca24aDima Zavin /* currently unused - use set_parameters with key 19757dde28fb80e1a166db283296812f5fb078ca24aDima Zavin * AUDIO_PARAMETER_STREAM_FORMAT 19857dde28fb80e1a166db283296812f5fb078ca24aDima Zavin */ 199fe79eb3f06967f863a637e546eb4421d0da2283bGlenn Kasten int (*set_format)(struct audio_stream *stream, audio_format_t format); 200f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 201f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 202f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Put the audio hardware input/output into standby mode. 2030cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Driver should exit from standby mode at the next I/O operation. 204f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Returns 0 on success and <0 on failure. 205f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 206f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*standby)(struct audio_stream *stream); 207f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 208f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** dump the state of the audio input/output device */ 209f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*dump)(const struct audio_stream *stream, int fd); 210f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 2110cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten /** Return the set of device(s) which this stream is connected to */ 212f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin audio_devices_t (*get_device)(const struct audio_stream *stream); 2130cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten 2140cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten /** 2150cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Currently unused - set_device() corresponds to set_parameters() with key 2160cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * AUDIO_PARAMETER_STREAM_ROUTING for both input and output. 2170cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by 2180cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * input streams only. 2190cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten */ 220f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_device)(struct audio_stream *stream, audio_devices_t device); 221f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 222f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 223f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * set/get audio stream parameters. The function accepts a list of 224f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * parameter key value pairs in the form: key1=value1;key2=value2;... 225f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 226f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Some keys are reserved for standard parameters (See AudioParameter class) 227f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 228f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * If the implementation does not accept a parameter change while 229f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * the output is active but the parameter is acceptable otherwise, it must 230f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * return -ENOSYS. 231f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 232f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * The audio flinger will put the stream in standby and then change the 233f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * parameter value. 234f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 235f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs); 236f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 237f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* 238f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Returns a pointer to a heap allocated string. The caller is responsible 2390cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * for freeing the memory for it using free(). 240f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 241f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin char * (*get_parameters)(const struct audio_stream *stream, 242f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin const char *keys); 243f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent int (*add_audio_effect)(const struct audio_stream *stream, 244f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent effect_handle_t effect); 245f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent int (*remove_audio_effect)(const struct audio_stream *stream, 246f3008aa707c1c302e8c8f9c8b759f170d972ddceEric Laurent effect_handle_t effect); 247f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 248f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_stream audio_stream_t; 249f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 250f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/* type of asynchronous write callback events. Mutually exclusive */ 251f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgeraldtypedef enum { 252f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */ 253f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald STREAM_CBK_EVENT_DRAIN_READY /* drain completed */ 254f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald} stream_callback_event_t; 255f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 256f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgeraldtypedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie); 257f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 258f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */ 259f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgeraldtypedef enum { 260f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */ 261f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data 262f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald from the current track has been played to 263f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald give time for gapless track switch */ 264f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald} audio_drain_type_t; 265f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 266f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 267f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * audio_stream_out is the abstraction interface for the audio output hardware. 268f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 269f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * It provides information about various properties of the audio output 270f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * hardware driver. 271f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 272f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 273f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_stream_out { 27484d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles /** 27584d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * Common methods of the audio stream out. This *must* be the first member of audio_stream_out 27684d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts 27784d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * where it's known the audio_stream references an audio_stream_out. 27884d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles */ 279f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_stream common; 280f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 281f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 2820cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Return the audio hardware driver estimated latency in milliseconds. 283f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 284f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_latency)(const struct audio_stream_out *stream); 285f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 286f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 287f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Use this method in situations where audio mixing is done in the 288f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * hardware. This method serves as a direct interface with hardware, 289f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * allowing you to directly set the volume as apposed to via the framework. 290f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * This method might produce multiple PCM outputs or hardware accelerated 291f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * codecs, such as MP3 or AAC. 292f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 293f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_volume)(struct audio_stream_out *stream, float left, float right); 294f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 295f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 2960cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * Write audio buffer to driver. Returns number of bytes written, or a 2970cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * negative status_t. If at least one frame was written successfully prior to the error, 2980cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * it is suggested that the driver return that successful (short) byte count 2990cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * and then return an error in the subsequent call. 300f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 301f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If set_callback() has previously been called to enable non-blocking mode 302f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * the write() is not allowed to block. It must write only the number of 303f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * bytes that currently fit in the driver/hardware buffer and then return 304f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * this byte count. If this is less than the requested write size the 305f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * callback function must be called when more space is available in the 306f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * driver/hardware buffer. 307f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 308f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin ssize_t (*write)(struct audio_stream_out *stream, const void* buffer, 309f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t bytes); 310f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 311f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* return the number of audio frames written by the audio dsp to DAC since 312f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * the output has exited standby 313f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 314f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*get_render_position)(const struct audio_stream_out *stream, 315f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t *dsp_frames); 3165ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen 3175ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen /** 3180cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * get the local time at which the next write to the audio driver will be presented. 3190cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * The units are microseconds, where the epoch is decided by the local audio HAL. 3205ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen */ 3215ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen int (*get_next_write_timestamp)(const struct audio_stream_out *stream, 3225ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen int64_t *timestamp); 3235ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen 324f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 325f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * set the callback function for notifying completion of non-blocking 326f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * write and drain. 327f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Calling this function implies that all future write() and drain() 328f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * must be non-blocking and use the callback to signal completion. 329f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 330f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*set_callback)(struct audio_stream_out *stream, 331f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald stream_callback_t callback, void *cookie); 332f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 333f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 334f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Notifies to the audio driver to stop playback however the queued buffers are 335f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * retained by the hardware. Useful for implementing pause/resume. Empty implementation 336f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * if not supported however should be implemented for hardware with non-trivial 337f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * latency. In the pause state audio hardware could still be using power. User may 338f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * consider calling suspend after a timeout. 339f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 340f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 341f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 342f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*pause)(struct audio_stream_out* stream); 343f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 344f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 345f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Notifies to the audio driver to resume playback following a pause. 346f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Returns error if called without matching pause. 347f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 348f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 349f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 350f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*resume)(struct audio_stream_out* stream); 351f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 352f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 353f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Requests notification when data buffered by the driver/hardware has 354f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * been played. If set_callback() has previously been called to enable 355f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * non-blocking mode, the drain() must not block, instead it should return 356f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * quickly and completion of the drain is notified through the callback. 357f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If set_callback() has not been called, the drain() must block until 358f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * completion. 359f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written 360f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * data has been played. 361f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all 362f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * data for the current track has played to allow time for the framework 363f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * to perform a gapless track switch. 364f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 365f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Drain must return immediately on stop() and flush() call 366f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 367f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 368f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 369f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type ); 370f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald 371f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald /** 372f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Notifies to the audio driver to flush the queued data. Stream must already 373f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * be paused before calling flush(). 374f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * 375f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald * Implementation of this function is mandatory for offloaded playback. 376f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald */ 377f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald int (*flush)(struct audio_stream_out* stream); 378e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten 379e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten /** 38022a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * Return a recent count of the number of audio frames presented to an external observer. 381e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * This excludes frames which have been written but are still in the pipeline. 382e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * The count is not reset to zero when output enters standby. 383e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * Also returns the value of CLOCK_MONOTONIC as of this presentation count. 38422a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * The returned count is expected to be 'recent', 38522a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * but does not need to be the most recent possible value. 38622a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * However, the associated time should correspond to whatever count is returned. 38722a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * Example: assume that N+M frames have been presented, where M is a 'small' number. 38822a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * Then it is permissible to return N instead of N+M, 38922a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * and the timestamp should correspond to N rather than N+M. 39022a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * The terms 'recent' and 'small' are not defined. 39122a06b752f7c350f8d8eaec029c9df69d708126fGlenn Kasten * They reflect the quality of the implementation. 392e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * 393e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten * 3.0 and higher only. 394e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten */ 395e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten int (*get_presentation_position)(const struct audio_stream_out *stream, 396e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten uint64_t *frames, struct timespec *timestamp); 397e25f9ed3469859ba0b94585549097b8b82dca8b4Glenn Kasten 398f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 399f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_stream_out audio_stream_out_t; 400f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 401f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_stream_in { 40284d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles /** 40384d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * Common methods of the audio stream in. This *must* be the first member of audio_stream_in 40484d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts 40584d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * where it's known the audio_stream references an audio_stream_in. 40684d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles */ 407f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_stream common; 408f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 409f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** set the input gain for the audio driver. This method is for 410f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * for future use */ 411f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_gain)(struct audio_stream_in *stream, float gain); 412f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 4130cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten /** Read audio buffer in from audio driver. Returns number of bytes read, or a 4140cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * negative status_t. If at least one frame was read prior to the error, 4150cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * read should return that byte count and then return an error in the subsequent call. 4160cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten */ 417f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin ssize_t (*read)(struct audio_stream_in *stream, void* buffer, 418f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t bytes); 419f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 420f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 421f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Return the amount of input frames lost in the audio driver since the 422f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * last call of this function. 423f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Audio driver is expected to reset the value to 0 and restart counting 424f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * upon returning the current value by this function call. 425f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Such loss typically occurs when the user space process is blocked 426f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * longer than the capacity of audio driver buffers. 427f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 428f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Unit: the number of input audio frames 429f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 430f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream); 431f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 432f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_stream_in audio_stream_in_t; 433f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 434f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 435f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * return the frame size (number of bytes per sample). 436c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent * 437c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead. 438f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 439c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent__attribute__((__deprecated__)) 44048915acb392773c1fcb86e2711eab468410a0baaGlenn Kastenstatic inline size_t audio_stream_frame_size(const struct audio_stream *s) 441f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin{ 442a26cbac8a0f71ba59a89e250caaa1155f0179751Glenn Kasten size_t chan_samp_sz; 443f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald audio_format_t format = s->get_format(s); 444f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 445f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald if (audio_is_linear_pcm(format)) { 446f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald chan_samp_sz = audio_bytes_per_sample(format); 447f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald return popcount(s->get_channels(s)) * chan_samp_sz; 448f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin } 449f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 450f37f187bbac1fd7bf884eb3ea5c47aa78cb68cdcRichard Fitzgerald return sizeof(int8_t); 451f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin} 452f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 453c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent/** 454c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent * return the frame size (number of bytes per sample) of an output stream. 455c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent */ 456c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurentstatic inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s) 457c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent{ 458c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent size_t chan_samp_sz; 459c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent audio_format_t format = s->common.get_format(&s->common); 460c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent 461c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent if (audio_is_linear_pcm(format)) { 462c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent chan_samp_sz = audio_bytes_per_sample(format); 463c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz; 464c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent } 465c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent 466c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent return sizeof(int8_t); 467c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent} 468c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent 469c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent/** 470c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent * return the frame size (number of bytes per sample) of an input stream. 471c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent */ 472c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurentstatic inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s) 473c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent{ 474c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent size_t chan_samp_sz; 475c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent audio_format_t format = s->common.get_format(&s->common); 476c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent 477c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent if (audio_is_linear_pcm(format)) { 478c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent chan_samp_sz = audio_bytes_per_sample(format); 479c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz; 480c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent } 481c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent 482c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent return sizeof(int8_t); 483c5ae6a030484f83beb3f2120f136cec1c0ef8b0aEric Laurent} 484f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 485f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/**********************************************************************/ 486f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 487f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** 488f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 489f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * and the fields of this data structure must begin with hw_module_t 490f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * followed by module specific information. 491f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 492f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_module { 493f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct hw_module_t common; 494f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 495f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 496f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstruct audio_hw_device { 49784d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles /** 49884d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * Common methods of the audio device. This *must* be the first member of audio_hw_device 49984d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts 50084d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles * where it's known the hw_device_t references an audio_hw_device. 50184d35492b145cebc000f8fd72818eb25b8e65c04Stewart Miles */ 502f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct hw_device_t common; 503f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 504f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 505f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * used by audio flinger to enumerate what devices are supported by 506f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * each audio_hw_device implementation. 507f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * 508f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Return value is a bitmask of 1 or more values of audio_devices_t 50985e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * 51085e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * NOTE: audio HAL implementations starting with 51185e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function. 51285e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * All supported devices should be listed in audio_policy.conf 51385e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * file and the audio policy manager must choose the appropriate 51485e08e26258711f2fd672d9a920d88bf91410f6bEric Laurent * audio module based on information in this file. 515f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 516f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin uint32_t (*get_supported_devices)(const struct audio_hw_device *dev); 517f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 518f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 519f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * check to see if the audio hardware interface has been initialized. 520f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * returns 0 on success, -ENODEV on failure. 521f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 522f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*init_check)(const struct audio_hw_device *dev); 523f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 524f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ 525f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_voice_volume)(struct audio_hw_device *dev, float volume); 526f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 527f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 528f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * set the audio volume for all audio activities other than voice call. 529f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Range between 0.0 and 1.0. If any value other than 0 is returned, 530f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * the software mixer will emulate this capability. 531f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 532f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_master_volume)(struct audio_hw_device *dev, float volume); 533f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 534f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** 5355ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * Get the current master volume value for the HAL, if the HAL supports 5365ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * master volume control. AudioFlinger will query this value from the 5375ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * primary audio HAL when the service starts and use the value for setting 5385ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen * the initial master volume across all HALs. HALs which do not support 53947bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * this method may leave it set to NULL. 5405ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen */ 5415ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen int (*get_master_volume)(struct audio_hw_device *dev, float *volume); 5425ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen 5435ad38a901dcca2961f3ed35ae0b206c13bc515cdMike J. Chen /** 5446df641e269639dbb81bb1c19f47d3b9e5e3ff7d7Glenn Kasten * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode 545f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is 546f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * playing, and AUDIO_MODE_IN_CALL when a call is in progress. 547f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 5486df641e269639dbb81bb1c19f47d3b9e5e3ff7d7Glenn Kasten int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode); 549f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 550f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* mic mute */ 551f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_mic_mute)(struct audio_hw_device *dev, bool state); 552f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state); 553f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 554f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* set/get global audio parameters */ 555f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs); 556f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 557f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* 558f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin * Returns a pointer to a heap allocated string. The caller is responsible 5590cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * for freeing the memory for it using free(). 560f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 561f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin char * (*get_parameters)(const struct audio_hw_device *dev, 562f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin const char *keys); 563f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 564f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /* Returns audio input buffer size according to parameters passed or 5650cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * 0 if one of the parameters is not supported. 5660cacd8d44b3f6ff6ec947bb6b2db1e382ee73bdbGlenn Kasten * See also get_buffer_size which is for a particular stream. 567f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin */ 568f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin size_t (*get_input_buffer_size)(const struct audio_hw_device *dev, 56955786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent const struct audio_config *config); 570f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 571f5e2469c02825f018df6336125882812003b8e64Eric Laurent /** This method creates and opens the audio hardware output stream. 572f5e2469c02825f018df6336125882812003b8e64Eric Laurent * The "address" parameter qualifies the "devices" audio device type if needed. 573f5e2469c02825f018df6336125882812003b8e64Eric Laurent * The format format depends on the device type: 574f5e2469c02825f018df6336125882812003b8e64Eric Laurent * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC" 575f5e2469c02825f018df6336125882812003b8e64Eric Laurent * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y" 576f5e2469c02825f018df6336125882812003b8e64Eric Laurent * - Other devices may use a number or any other string. 577f5e2469c02825f018df6336125882812003b8e64Eric Laurent */ 578f5e2469c02825f018df6336125882812003b8e64Eric Laurent 57955786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent int (*open_output_stream)(struct audio_hw_device *dev, 58055786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_io_handle_t handle, 58155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_devices_t devices, 58255786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_output_flags_t flags, 58355786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_config *config, 584f5e2469c02825f018df6336125882812003b8e64Eric Laurent struct audio_stream_out **stream_out, 585f5e2469c02825f018df6336125882812003b8e64Eric Laurent const char *address); 586f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 587f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin void (*close_output_stream)(struct audio_hw_device *dev, 58855786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_stream_out* stream_out); 589f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 590f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** This method creates and opens the audio hardware input stream */ 59155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent int (*open_input_stream)(struct audio_hw_device *dev, 59255786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_io_handle_t handle, 59355786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent audio_devices_t devices, 59455786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_config *config, 5957d973adff4c9b344b530dd7c585f789d02c605daGlenn Kasten struct audio_stream_in **stream_in, 596f5e2469c02825f018df6336125882812003b8e64Eric Laurent audio_input_flags_t flags, 597f5e2469c02825f018df6336125882812003b8e64Eric Laurent const char *address, 598f5e2469c02825f018df6336125882812003b8e64Eric Laurent audio_source_t source); 599f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 600f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin void (*close_input_stream)(struct audio_hw_device *dev, 60155786bcf3ced97dea8fa7ce79df2889d4d06e8a7Eric Laurent struct audio_stream_in *stream_in); 602f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 603f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin /** This method dumps the state of the audio hardware */ 604f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin int (*dump)(const struct audio_hw_device *dev, int fd); 60547bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman 60647bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman /** 60747bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * set the audio mute status for all audio activities. If any value other 60847bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * than 0 is returned, the software mixer will emulate this capability. 60947bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman */ 61047bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman int (*set_master_mute)(struct audio_hw_device *dev, bool mute); 61147bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman 61247bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman /** 61347bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * Get the current master mute status for the HAL, if the HAL supports 61447bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * master mute control. AudioFlinger will query this value from the primary 61547bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * audio HAL when the service starts and use the value for setting the 61647bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * initial master mute across all HALs. HALs which do not support this 61747bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman * method may leave it set to NULL. 61847bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman */ 61947bf3d7ea5f6c98e615e0a1f93497d241c79cc05John Grossman int (*get_master_mute)(struct audio_hw_device *dev, bool *mute); 62073b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent 62173b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent /** 62273b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * Routing control 62373b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent */ 62473b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent 62573b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent /* Creates an audio patch between several source and sink ports. 62673b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * The handle is allocated by the HAL and should be unique for this 62773b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * audio HAL module. */ 62873b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent int (*create_audio_patch)(struct audio_hw_device *dev, 62973b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent unsigned int num_sources, 63073b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent const struct audio_port_config *sources, 63173b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent unsigned int num_sinks, 63273b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent const struct audio_port_config *sinks, 63373b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent audio_patch_handle_t *handle); 63473b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent 63573b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent /* Release an audio patch */ 63673b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent int (*release_audio_patch)(struct audio_hw_device *dev, 63773b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent audio_patch_handle_t handle); 63873b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent 63973b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent /* Fills the list of supported attributes for a given audio port. 64073b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * As input, "port" contains the information (type, role, address etc...) 64173b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * needed by the HAL to identify the port. 64273b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * As output, "port" contains possible attributes (sampling rates, formats, 64373b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent * channel masks, gain controllers...) for this port. 64473b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent */ 64573b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent int (*get_audio_port)(struct audio_hw_device *dev, 64673b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent struct audio_port *port); 64773b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent 64873b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent /* Set audio port configuration */ 64973b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent int (*set_audio_port_config)(struct audio_hw_device *dev, 65073b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent const struct audio_port_config *config); 65173b8a7414afa5ee3f006468f287695d9c2054d76Eric Laurent 652f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin}; 653f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavintypedef struct audio_hw_device audio_hw_device_t; 654f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 655f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin/** convenience API for opening and closing a supported device */ 656f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 657f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstatic inline int audio_hw_device_open(const struct hw_module_t* module, 658f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin struct audio_hw_device** device) 659f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin{ 660f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin return module->methods->open(module, AUDIO_HARDWARE_INTERFACE, 661f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin (struct hw_device_t**)device); 662f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin} 663f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 664f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavinstatic inline int audio_hw_device_close(struct audio_hw_device* device) 665f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin{ 666f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin return device->common.close(&device->common); 667f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin} 668f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 669f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 670f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin__END_DECLS 671f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin 672f1504dbca386fc454b8ded7669012f3d4d27eab7Dima Zavin#endif // ANDROID_AUDIO_INTERFACE_H 673