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