audio.h 26 KB

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