Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 #ifndef ANDROID_AUDIO_HAL_INTERFACE_H
     19 #define ANDROID_AUDIO_HAL_INTERFACE_H
     20 
     21 #include <stdint.h>
     22 #include <strings.h>
     23 #include <sys/cdefs.h>
     24 #include <sys/types.h>
     25 
     26 #include <cutils/bitops.h>
     27 
     28 #include <hardware/hardware.h>
     29 #include <system/audio.h>
     30 #include <hardware/audio_effect.h>
     31 
     32 __BEGIN_DECLS
     33 
     34 /**
     35  * The id of this module
     36  */
     37 #define AUDIO_HARDWARE_MODULE_ID "audio"
     38 
     39 /**
     40  * Name of the audio devices to open
     41  */
     42 #define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
     43 
     44 
     45 /* Use version 0.1 to be compatible with first generation of audio hw module with version_major
     46  * hardcoded to 1. No audio module API change.
     47  */
     48 #define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
     49 #define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
     50 
     51 /* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
     52  * will be considered of first generation API.
     53  */
     54 #define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
     55 #define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
     56 #define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
     57 #define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
     58 #define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
     59 /* Minimal audio HAL version supported by the audio framework */
     60 #define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
     61 
     62 /**
     63  * List of known audio HAL modules. This is the base name of the audio HAL
     64  * library composed of the "audio." prefix, one of the base names below and
     65  * a suffix specific to the device.
     66  * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
     67  */
     68 
     69 #define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
     70 #define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
     71 #define AUDIO_HARDWARE_MODULE_ID_USB "usb"
     72 #define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
     73 #define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
     74 
     75 /**************************************/
     76 
     77 /**
     78  *  standard audio parameters that the HAL may need to handle
     79  */
     80 
     81 /**
     82  *  audio device parameters
     83  */
     84 
     85 /* BT SCO Noise Reduction + Echo Cancellation parameters */
     86 #define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
     87 #define AUDIO_PARAMETER_VALUE_ON "on"
     88 #define AUDIO_PARAMETER_VALUE_OFF "off"
     89 
     90 /* TTY mode selection */
     91 #define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
     92 #define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
     93 #define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
     94 #define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
     95 #define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
     96 
     97 /* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off
     98    Strings must be in sync with CallFeaturesSetting.java */
     99 #define AUDIO_PARAMETER_KEY_HAC "HACSetting"
    100 #define AUDIO_PARAMETER_VALUE_HAC_ON "ON"
    101 #define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF"
    102 
    103 /* A2DP sink address set by framework */
    104 #define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
    105 
    106 /* A2DP source address set by framework */
    107 #define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
    108 
    109 /* Screen state */
    110 #define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
    111 
    112 /* Bluetooth SCO wideband */
    113 #define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
    114 
    115 
    116 /**
    117  *  audio stream parameters
    118  */
    119 
    120 #define AUDIO_PARAMETER_STREAM_ROUTING "routing"             /* audio_devices_t */
    121 #define AUDIO_PARAMETER_STREAM_FORMAT "format"               /* audio_format_t */
    122 #define AUDIO_PARAMETER_STREAM_CHANNELS "channels"           /* audio_channel_mask_t */
    123 #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count"     /* size_t */
    124 #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source"   /* audio_source_t */
    125 #define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */
    126 
    127 #define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect"      /* audio_devices_t */
    128 
    129 /* Query supported formats. The response is a '|' separated list of strings from
    130  * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
    131 #define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
    132 /* Query supported channel masks. The response is a '|' separated list of strings from
    133  * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
    134 #define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
    135 /* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
    136  * "sup_sampling_rates=44100|48000" */
    137 #define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
    138 
    139 /* Get the HW synchronization source used for an output stream.
    140  * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs
    141  * or no HW sync source is used. */
    142 #define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync"
    143 
    144 /**
    145  * audio codec parameters
    146  */
    147 
    148 #define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
    149 #define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
    150 #define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
    151 #define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
    152 #define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
    153 #define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
    154 #define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
    155 #define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
    156 #define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL  "music_offload_num_channels"
    157 #define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING  "music_offload_down_sampling"
    158 #define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES  "delay_samples"
    159 #define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES  "padding_samples"
    160 
    161 /**************************************/
    162 
    163 /* common audio stream parameters and operations */
    164 struct audio_stream {
    165 
    166     /**
    167      * Return the sampling rate in Hz - eg. 44100.
    168      */
    169     uint32_t (*get_sample_rate)(const struct audio_stream *stream);
    170 
    171     /* currently unused - use set_parameters with key
    172      *    AUDIO_PARAMETER_STREAM_SAMPLING_RATE
    173      */
    174     int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
    175 
    176     /**
    177      * Return size of input/output buffer in bytes for this stream - eg. 4800.
    178      * It should be a multiple of the frame size.  See also get_input_buffer_size.
    179      */
    180     size_t (*get_buffer_size)(const struct audio_stream *stream);
    181 
    182     /**
    183      * Return the channel mask -
    184      *  e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
    185      */
    186     audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
    187 
    188     /**
    189      * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
    190      */
    191     audio_format_t (*get_format)(const struct audio_stream *stream);
    192 
    193     /* currently unused - use set_parameters with key
    194      *     AUDIO_PARAMETER_STREAM_FORMAT
    195      */
    196     int (*set_format)(struct audio_stream *stream, audio_format_t format);
    197 
    198     /**
    199      * Put the audio hardware input/output into standby mode.
    200      * Driver should exit from standby mode at the next I/O operation.
    201      * Returns 0 on success and <0 on failure.
    202      */
    203     int (*standby)(struct audio_stream *stream);
    204 
    205     /** dump the state of the audio input/output device */
    206     int (*dump)(const struct audio_stream *stream, int fd);
    207 
    208     /** Return the set of device(s) which this stream is connected to */
    209     audio_devices_t (*get_device)(const struct audio_stream *stream);
    210 
    211     /**
    212      * Currently unused - set_device() corresponds to set_parameters() with key
    213      * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
    214      * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
    215      * input streams only.
    216      */
    217     int (*set_device)(struct audio_stream *stream, audio_devices_t device);
    218 
    219     /**
    220      * set/get audio stream parameters. The function accepts a list of
    221      * parameter key value pairs in the form: key1=value1;key2=value2;...
    222      *
    223      * Some keys are reserved for standard parameters (See AudioParameter class)
    224      *
    225      * If the implementation does not accept a parameter change while
    226      * the output is active but the parameter is acceptable otherwise, it must
    227      * return -ENOSYS.
    228      *
    229      * The audio flinger will put the stream in standby and then change the
    230      * parameter value.
    231      */
    232     int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
    233 
    234     /*
    235      * Returns a pointer to a heap allocated string. The caller is responsible
    236      * for freeing the memory for it using free().
    237      */
    238     char * (*get_parameters)(const struct audio_stream *stream,
    239                              const char *keys);
    240     int (*add_audio_effect)(const struct audio_stream *stream,
    241                              effect_handle_t effect);
    242     int (*remove_audio_effect)(const struct audio_stream *stream,
    243                              effect_handle_t effect);
    244 };
    245 typedef struct audio_stream audio_stream_t;
    246 
    247 /* type of asynchronous write callback events. Mutually exclusive */
    248 typedef enum {
    249     STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
    250     STREAM_CBK_EVENT_DRAIN_READY  /* drain completed */
    251 } stream_callback_event_t;
    252 
    253 typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
    254 
    255 /* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
    256 typedef enum {
    257     AUDIO_DRAIN_ALL,            /* drain() returns when all data has been played */
    258     AUDIO_DRAIN_EARLY_NOTIFY    /* drain() returns a short time before all data
    259                                    from the current track has been played to
    260                                    give time for gapless track switch */
    261 } audio_drain_type_t;
    262 
    263 /**
    264  * audio_stream_out is the abstraction interface for the audio output hardware.
    265  *
    266  * It provides information about various properties of the audio output
    267  * hardware driver.
    268  */
    269 
    270 struct audio_stream_out {
    271     /**
    272      * Common methods of the audio stream out.  This *must* be the first member of audio_stream_out
    273      * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
    274      * where it's known the audio_stream references an audio_stream_out.
    275      */
    276     struct audio_stream common;
    277 
    278     /**
    279      * Return the audio hardware driver estimated latency in milliseconds.
    280      */
    281     uint32_t (*get_latency)(const struct audio_stream_out *stream);
    282 
    283     /**
    284      * Use this method in situations where audio mixing is done in the
    285      * hardware. This method serves as a direct interface with hardware,
    286      * allowing you to directly set the volume as apposed to via the framework.
    287      * This method might produce multiple PCM outputs or hardware accelerated
    288      * codecs, such as MP3 or AAC.
    289      */
    290     int (*set_volume)(struct audio_stream_out *stream, float left, float right);
    291 
    292     /**
    293      * Write audio buffer to driver. Returns number of bytes written, or a
    294      * negative status_t. If at least one frame was written successfully prior to the error,
    295      * it is suggested that the driver return that successful (short) byte count
    296      * and then return an error in the subsequent call.
    297      *
    298      * If set_callback() has previously been called to enable non-blocking mode
    299      * the write() is not allowed to block. It must write only the number of
    300      * bytes that currently fit in the driver/hardware buffer and then return
    301      * this byte count. If this is less than the requested write size the
    302      * callback function must be called when more space is available in the
    303      * driver/hardware buffer.
    304      */
    305     ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
    306                      size_t bytes);
    307 
    308     /* return the number of audio frames written by the audio dsp to DAC since
    309      * the output has exited standby
    310      */
    311     int (*get_render_position)(const struct audio_stream_out *stream,
    312                                uint32_t *dsp_frames);
    313 
    314     /**
    315      * get the local time at which the next write to the audio driver will be presented.
    316      * The units are microseconds, where the epoch is decided by the local audio HAL.
    317      */
    318     int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
    319                                     int64_t *timestamp);
    320 
    321     /**
    322      * set the callback function for notifying completion of non-blocking
    323      * write and drain.
    324      * Calling this function implies that all future write() and drain()
    325      * must be non-blocking and use the callback to signal completion.
    326      */
    327     int (*set_callback)(struct audio_stream_out *stream,
    328             stream_callback_t callback, void *cookie);
    329 
    330     /**
    331      * Notifies to the audio driver to stop playback however the queued buffers are
    332      * retained by the hardware. Useful for implementing pause/resume. Empty implementation
    333      * if not supported however should be implemented for hardware with non-trivial
    334      * latency. In the pause state audio hardware could still be using power. User may
    335      * consider calling suspend after a timeout.
    336      *
    337      * Implementation of this function is mandatory for offloaded playback.
    338      */
    339     int (*pause)(struct audio_stream_out* stream);
    340 
    341     /**
    342      * Notifies to the audio driver to resume playback following a pause.
    343      * Returns error if called without matching pause.
    344      *
    345      * Implementation of this function is mandatory for offloaded playback.
    346      */
    347     int (*resume)(struct audio_stream_out* stream);
    348 
    349     /**
    350      * Requests notification when data buffered by the driver/hardware has
    351      * been played. If set_callback() has previously been called to enable
    352      * non-blocking mode, the drain() must not block, instead it should return
    353      * quickly and completion of the drain is notified through the callback.
    354      * If set_callback() has not been called, the drain() must block until
    355      * completion.
    356      * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
    357      * data has been played.
    358      * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
    359      * data for the current track has played to allow time for the framework
    360      * to perform a gapless track switch.
    361      *
    362      * Drain must return immediately on stop() and flush() call
    363      *
    364      * Implementation of this function is mandatory for offloaded playback.
    365      */
    366     int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
    367 
    368     /**
    369      * Notifies to the audio driver to flush the queued data. Stream must already
    370      * be paused before calling flush().
    371      *
    372      * Implementation of this function is mandatory for offloaded playback.
    373      */
    374    int (*flush)(struct audio_stream_out* stream);
    375 
    376     /**
    377      * Return a recent count of the number of audio frames presented to an external observer.
    378      * This excludes frames which have been written but are still in the pipeline.
    379      * The count is not reset to zero when output enters standby.
    380      * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
    381      * The returned count is expected to be 'recent',
    382      * but does not need to be the most recent possible value.
    383      * However, the associated time should correspond to whatever count is returned.
    384      * Example:  assume that N+M frames have been presented, where M is a 'small' number.
    385      * Then it is permissible to return N instead of N+M,
    386      * and the timestamp should correspond to N rather than N+M.
    387      * The terms 'recent' and 'small' are not defined.
    388      * They reflect the quality of the implementation.
    389      *
    390      * 3.0 and higher only.
    391      */
    392     int (*get_presentation_position)(const struct audio_stream_out *stream,
    393                                uint64_t *frames, struct timespec *timestamp);
    394 
    395 };
    396 typedef struct audio_stream_out audio_stream_out_t;
    397 
    398 struct audio_stream_in {
    399     /**
    400      * Common methods of the audio stream in.  This *must* be the first member of audio_stream_in
    401      * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
    402      * where it's known the audio_stream references an audio_stream_in.
    403      */
    404     struct audio_stream common;
    405 
    406     /** set the input gain for the audio driver. This method is for
    407      *  for future use */
    408     int (*set_gain)(struct audio_stream_in *stream, float gain);
    409 
    410     /** Read audio buffer in from audio driver. Returns number of bytes read, or a
    411      *  negative status_t. If at least one frame was read prior to the error,
    412      *  read should return that byte count and then return an error in the subsequent call.
    413      */
    414     ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
    415                     size_t bytes);
    416 
    417     /**
    418      * Return the amount of input frames lost in the audio driver since the
    419      * last call of this function.
    420      * Audio driver is expected to reset the value to 0 and restart counting
    421      * upon returning the current value by this function call.
    422      * Such loss typically occurs when the user space process is blocked
    423      * longer than the capacity of audio driver buffers.
    424      *
    425      * Unit: the number of input audio frames
    426      */
    427     uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
    428 };
    429 typedef struct audio_stream_in audio_stream_in_t;
    430 
    431 /**
    432  * return the frame size (number of bytes per sample).
    433  *
    434  * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead.
    435  */
    436 __attribute__((__deprecated__))
    437 static inline size_t audio_stream_frame_size(const struct audio_stream *s)
    438 {
    439     size_t chan_samp_sz;
    440     audio_format_t format = s->get_format(s);
    441 
    442     if (audio_is_linear_pcm(format)) {
    443         chan_samp_sz = audio_bytes_per_sample(format);
    444         return popcount(s->get_channels(s)) * chan_samp_sz;
    445     }
    446 
    447     return sizeof(int8_t);
    448 }
    449 
    450 /**
    451  * return the frame size (number of bytes per sample) of an output stream.
    452  */
    453 static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s)
    454 {
    455     size_t chan_samp_sz;
    456     audio_format_t format = s->common.get_format(&s->common);
    457 
    458     if (audio_is_linear_pcm(format)) {
    459         chan_samp_sz = audio_bytes_per_sample(format);
    460         return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
    461     }
    462 
    463     return sizeof(int8_t);
    464 }
    465 
    466 /**
    467  * return the frame size (number of bytes per sample) of an input stream.
    468  */
    469 static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s)
    470 {
    471     size_t chan_samp_sz;
    472     audio_format_t format = s->common.get_format(&s->common);
    473 
    474     if (audio_is_linear_pcm(format)) {
    475         chan_samp_sz = audio_bytes_per_sample(format);
    476         return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
    477     }
    478 
    479     return sizeof(int8_t);
    480 }
    481 
    482 /**********************************************************************/
    483 
    484 /**
    485  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
    486  * and the fields of this data structure must begin with hw_module_t
    487  * followed by module specific information.
    488  */
    489 struct audio_module {
    490     struct hw_module_t common;
    491 };
    492 
    493 struct audio_hw_device {
    494     /**
    495      * Common methods of the audio device.  This *must* be the first member of audio_hw_device
    496      * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
    497      * where it's known the hw_device_t references an audio_hw_device.
    498      */
    499     struct hw_device_t common;
    500 
    501     /**
    502      * used by audio flinger to enumerate what devices are supported by
    503      * each audio_hw_device implementation.
    504      *
    505      * Return value is a bitmask of 1 or more values of audio_devices_t
    506      *
    507      * NOTE: audio HAL implementations starting with
    508      * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
    509      * All supported devices should be listed in audio_policy.conf
    510      * file and the audio policy manager must choose the appropriate
    511      * audio module based on information in this file.
    512      */
    513     uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
    514 
    515     /**
    516      * check to see if the audio hardware interface has been initialized.
    517      * returns 0 on success, -ENODEV on failure.
    518      */
    519     int (*init_check)(const struct audio_hw_device *dev);
    520 
    521     /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
    522     int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
    523 
    524     /**
    525      * set the audio volume for all audio activities other than voice call.
    526      * Range between 0.0 and 1.0. If any value other than 0 is returned,
    527      * the software mixer will emulate this capability.
    528      */
    529     int (*set_master_volume)(struct audio_hw_device *dev, float volume);
    530 
    531     /**
    532      * Get the current master volume value for the HAL, if the HAL supports
    533      * master volume control.  AudioFlinger will query this value from the
    534      * primary audio HAL when the service starts and use the value for setting
    535      * the initial master volume across all HALs.  HALs which do not support
    536      * this method may leave it set to NULL.
    537      */
    538     int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
    539 
    540     /**
    541      * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
    542      * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
    543      * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
    544      */
    545     int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
    546 
    547     /* mic mute */
    548     int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
    549     int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
    550 
    551     /* set/get global audio parameters */
    552     int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
    553 
    554     /*
    555      * Returns a pointer to a heap allocated string. The caller is responsible
    556      * for freeing the memory for it using free().
    557      */
    558     char * (*get_parameters)(const struct audio_hw_device *dev,
    559                              const char *keys);
    560 
    561     /* Returns audio input buffer size according to parameters passed or
    562      * 0 if one of the parameters is not supported.
    563      * See also get_buffer_size which is for a particular stream.
    564      */
    565     size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
    566                                     const struct audio_config *config);
    567 
    568     /** This method creates and opens the audio hardware output stream.
    569      * The "address" parameter qualifies the "devices" audio device type if needed.
    570      * The format format depends on the device type:
    571      * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
    572      * - USB devices use the ALSA card and device numbers in the form  "card=X;device=Y"
    573      * - Other devices may use a number or any other string.
    574      */
    575 
    576     int (*open_output_stream)(struct audio_hw_device *dev,
    577                               audio_io_handle_t handle,
    578                               audio_devices_t devices,
    579                               audio_output_flags_t flags,
    580                               struct audio_config *config,
    581                               struct audio_stream_out **stream_out,
    582                               const char *address);
    583 
    584     void (*close_output_stream)(struct audio_hw_device *dev,
    585                                 struct audio_stream_out* stream_out);
    586 
    587     /** This method creates and opens the audio hardware input stream */
    588     int (*open_input_stream)(struct audio_hw_device *dev,
    589                              audio_io_handle_t handle,
    590                              audio_devices_t devices,
    591                              struct audio_config *config,
    592                              struct audio_stream_in **stream_in,
    593                              audio_input_flags_t flags,
    594                              const char *address,
    595                              audio_source_t source);
    596 
    597     void (*close_input_stream)(struct audio_hw_device *dev,
    598                                struct audio_stream_in *stream_in);
    599 
    600     /** This method dumps the state of the audio hardware */
    601     int (*dump)(const struct audio_hw_device *dev, int fd);
    602 
    603     /**
    604      * set the audio mute status for all audio activities.  If any value other
    605      * than 0 is returned, the software mixer will emulate this capability.
    606      */
    607     int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
    608 
    609     /**
    610      * Get the current master mute status for the HAL, if the HAL supports
    611      * master mute control.  AudioFlinger will query this value from the primary
    612      * audio HAL when the service starts and use the value for setting the
    613      * initial master mute across all HALs.  HALs which do not support this
    614      * method may leave it set to NULL.
    615      */
    616     int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
    617 
    618     /**
    619      * Routing control
    620      */
    621 
    622     /* Creates an audio patch between several source and sink ports.
    623      * The handle is allocated by the HAL and should be unique for this
    624      * audio HAL module. */
    625     int (*create_audio_patch)(struct audio_hw_device *dev,
    626                                unsigned int num_sources,
    627                                const struct audio_port_config *sources,
    628                                unsigned int num_sinks,
    629                                const struct audio_port_config *sinks,
    630                                audio_patch_handle_t *handle);
    631 
    632     /* Release an audio patch */
    633     int (*release_audio_patch)(struct audio_hw_device *dev,
    634                                audio_patch_handle_t handle);
    635 
    636     /* Fills the list of supported attributes for a given audio port.
    637      * As input, "port" contains the information (type, role, address etc...)
    638      * needed by the HAL to identify the port.
    639      * As output, "port" contains possible attributes (sampling rates, formats,
    640      * channel masks, gain controllers...) for this port.
    641      */
    642     int (*get_audio_port)(struct audio_hw_device *dev,
    643                           struct audio_port *port);
    644 
    645     /* Set audio port configuration */
    646     int (*set_audio_port_config)(struct audio_hw_device *dev,
    647                          const struct audio_port_config *config);
    648 
    649 };
    650 typedef struct audio_hw_device audio_hw_device_t;
    651 
    652 /** convenience API for opening and closing a supported device */
    653 
    654 static inline int audio_hw_device_open(const struct hw_module_t* module,
    655                                        struct audio_hw_device** device)
    656 {
    657     return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
    658                                  (struct hw_device_t**)device);
    659 }
    660 
    661 static inline int audio_hw_device_close(struct audio_hw_device* device)
    662 {
    663     return device->common.close(&device->common);
    664 }
    665 
    666 
    667 __END_DECLS
    668 
    669 #endif  // ANDROID_AUDIO_INTERFACE_H
    670