audio.h 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. /* SPDX-License-Identifier: Apache-2.0 */
  2. /*
  3. * Copyright (C) 2011 The Android Open Source Project
  4. *
  5. */
  6. #ifndef ANDROID_AUDIO_CORE_H
  7. #define ANDROID_AUDIO_CORE_H
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. #include <stdio.h>
  11. #include <sys/cdefs.h>
  12. #include <sys/types.h>
  13. __BEGIN_DECLS
  14. #define popcount __builtin_popcount
  15. /* The enums were moved here mostly from
  16. * frameworks/base/include/media/AudioSystem.h
  17. */
  18. /* device address used to refer to the standard remote submix */
  19. #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0"
  20. /* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */
  21. typedef int audio_io_handle_t;
  22. #define AUDIO_IO_HANDLE_NONE 0
  23. /* Audio stream types */
  24. typedef enum {
  25. /* These values must kept in sync with
  26. * frameworks/base/media/java/android/media/AudioSystem.java
  27. */
  28. AUDIO_STREAM_DEFAULT = -1,
  29. AUDIO_STREAM_MIN = 0,
  30. AUDIO_STREAM_VOICE_CALL = 0,
  31. AUDIO_STREAM_SYSTEM = 1,
  32. AUDIO_STREAM_RING = 2,
  33. AUDIO_STREAM_MUSIC = 3,
  34. AUDIO_STREAM_ALARM = 4,
  35. AUDIO_STREAM_NOTIFICATION = 5,
  36. AUDIO_STREAM_BLUETOOTH_SCO = 6,
  37. AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user
  38. * and must be routed to speaker
  39. */
  40. AUDIO_STREAM_DTMF = 8,
  41. AUDIO_STREAM_TTS = 9,
  42. AUDIO_STREAM_CNT,
  43. AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1,
  44. } audio_stream_type_t;
  45. /* Do not change these values without updating their counterparts
  46. * in frameworks/base/media/java/android/media/AudioAttributes.java
  47. */
  48. typedef enum {
  49. AUDIO_CONTENT_TYPE_UNKNOWN = 0,
  50. AUDIO_CONTENT_TYPE_SPEECH = 1,
  51. AUDIO_CONTENT_TYPE_MUSIC = 2,
  52. AUDIO_CONTENT_TYPE_MOVIE = 3,
  53. AUDIO_CONTENT_TYPE_SONIFICATION = 4,
  54. AUDIO_CONTENT_TYPE_CNT,
  55. AUDIO_CONTENT_TYPE_MAX = AUDIO_CONTENT_TYPE_CNT - 1,
  56. } audio_content_type_t;
  57. /* Do not change these values without updating their counterparts
  58. * in frameworks/base/media/java/android/media/AudioAttributes.java
  59. */
  60. typedef enum {
  61. AUDIO_USAGE_UNKNOWN = 0,
  62. AUDIO_USAGE_MEDIA = 1,
  63. AUDIO_USAGE_VOICE_COMMUNICATION = 2,
  64. AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
  65. AUDIO_USAGE_ALARM = 4,
  66. AUDIO_USAGE_NOTIFICATION = 5,
  67. AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE = 6,
  68. AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7,
  69. AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8,
  70. AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9,
  71. AUDIO_USAGE_NOTIFICATION_EVENT = 10,
  72. AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
  73. AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
  74. AUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
  75. AUDIO_USAGE_GAME = 14,
  76. AUDIO_USAGE_CNT,
  77. AUDIO_USAGE_MAX = AUDIO_USAGE_CNT - 1,
  78. } audio_usage_t;
  79. typedef uint32_t audio_flags_mask_t;
  80. /* Do not change these values without updating their counterparts
  81. * in frameworks/base/media/java/android/media/AudioAttributes.java
  82. */
  83. enum {
  84. AUDIO_FLAG_AUDIBILITY_ENFORCED = 0x1,
  85. AUDIO_FLAG_SECURE = 0x2,
  86. AUDIO_FLAG_SCO = 0x4,
  87. AUDIO_FLAG_BEACON = 0x8,
  88. AUDIO_FLAG_HW_AV_SYNC = 0x10,
  89. AUDIO_FLAG_HW_HOTWORD = 0x20,
  90. };
  91. /* Do not change these values without updating their counterparts
  92. * in frameworks/base/media/java/android/media/MediaRecorder.java,
  93. * frameworks/av/services/audiopolicy/AudioPolicyService.cpp,
  94. * and system/media/audio_effects/include/audio_effects/audio_effects_conf.h!
  95. */
  96. typedef enum {
  97. AUDIO_SOURCE_DEFAULT = 0,
  98. AUDIO_SOURCE_MIC = 1,
  99. AUDIO_SOURCE_VOICE_UPLINK = 2,
  100. AUDIO_SOURCE_VOICE_DOWNLINK = 3,
  101. AUDIO_SOURCE_VOICE_CALL = 4,
  102. AUDIO_SOURCE_CAMCORDER = 5,
  103. AUDIO_SOURCE_VOICE_RECOGNITION = 6,
  104. AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
  105. AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */
  106. /* An example of remote presentation is Wifi Display */
  107. /* where a dongle attached to a TV can be used to */
  108. /* play the mix captured by this audio source. */
  109. AUDIO_SOURCE_CNT,
  110. AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1,
  111. AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for
  112. for background software hotword detection.
  113. Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION.
  114. Used only internally to the framework. Not exposed
  115. at the audio HAL. */
  116. } audio_source_t;
  117. /* Audio attributes */
  118. #define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256
  119. typedef struct {
  120. audio_content_type_t content_type;
  121. audio_usage_t usage;
  122. audio_source_t source;
  123. audio_flags_mask_t flags;
  124. char tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
  125. } audio_attributes_t;
  126. /* special audio session values
  127. * (XXX: should this be living in the audio effects land?)
  128. */
  129. typedef enum {
  130. /* session for effects attached to a particular output stream
  131. * (value must be less than 0)
  132. */
  133. AUDIO_SESSION_OUTPUT_STAGE = -1,
  134. /* session for effects applied to output mix. These effects can
  135. * be moved by audio policy manager to another output stream
  136. * (value must be 0)
  137. */
  138. AUDIO_SESSION_OUTPUT_MIX = 0,
  139. /* application does not specify an explicit session ID to be used,
  140. * and requests a new session ID to be allocated
  141. * TODO use unique values for AUDIO_SESSION_OUTPUT_MIX and AUDIO_SESSION_ALLOCATE,
  142. * after all uses have been updated from 0 to the appropriate symbol, and have been tested.
  143. */
  144. AUDIO_SESSION_ALLOCATE = 0,
  145. } audio_session_t;
  146. /* a unique ID allocated by AudioFlinger for use as a audio_io_handle_t or audio_session_t */
  147. typedef int audio_unique_id_t;
  148. #define AUDIO_UNIQUE_ID_ALLOCATE AUDIO_SESSION_ALLOCATE
  149. /* Audio sub formats (see enum audio_format). */
  150. /* PCM sub formats */
  151. typedef enum {
  152. /* All of these are in native byte order */
  153. AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
  154. AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
  155. AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */
  156. AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */
  157. AUDIO_FORMAT_PCM_SUB_FLOAT = 0x5, /* PCM single-precision floating point */
  158. AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED = 0x6, /* PCM signed .23 fixed point packed in 3 bytes */
  159. } audio_format_pcm_sub_fmt_t;
  160. /* The audio_format_*_sub_fmt_t declarations are not currently used */
  161. /* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
  162. * frame header to specify bit rate, stereo mode, version...
  163. */
  164. typedef enum {
  165. AUDIO_FORMAT_MP3_SUB_NONE = 0x0,
  166. } audio_format_mp3_sub_fmt_t;
  167. /* AMR NB/WB sub format field definition: specify frame block interleaving,
  168. * bandwidth efficient or octet aligned, encoding mode for recording...
  169. */
  170. typedef enum {
  171. AUDIO_FORMAT_AMR_SUB_NONE = 0x0,
  172. } audio_format_amr_sub_fmt_t;
  173. /* AAC sub format field definition: specify profile or bitrate for recording... */
  174. typedef enum {
  175. AUDIO_FORMAT_AAC_SUB_MAIN = 0x1,
  176. AUDIO_FORMAT_AAC_SUB_LC = 0x2,
  177. AUDIO_FORMAT_AAC_SUB_SSR = 0x4,
  178. AUDIO_FORMAT_AAC_SUB_LTP = 0x8,
  179. AUDIO_FORMAT_AAC_SUB_HE_V1 = 0x10,
  180. AUDIO_FORMAT_AAC_SUB_SCALABLE = 0x20,
  181. AUDIO_FORMAT_AAC_SUB_ERLC = 0x40,
  182. AUDIO_FORMAT_AAC_SUB_LD = 0x80,
  183. AUDIO_FORMAT_AAC_SUB_HE_V2 = 0x100,
  184. AUDIO_FORMAT_AAC_SUB_ELD = 0x200,
  185. } audio_format_aac_sub_fmt_t;
  186. /* VORBIS sub format field definition: specify quality for recording... */
  187. typedef enum {
  188. AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0,
  189. } audio_format_vorbis_sub_fmt_t;
  190. /* Audio format consists of a main format field (upper 8 bits) and a sub format
  191. * field (lower 24 bits).
  192. *
  193. * The main format indicates the main codec type. The sub format field
  194. * indicates options and parameters for each format. The sub format is mainly
  195. * used for record to indicate for instance the requested bitrate or profile.
  196. * It can also be used for certain formats to give informations not present in
  197. * the encoded audio stream (e.g. octet alignement for AMR).
  198. */
  199. typedef enum {
  200. AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL,
  201. AUDIO_FORMAT_DEFAULT = 0,
  202. AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */
  203. AUDIO_FORMAT_MP3 = 0x01000000UL,
  204. AUDIO_FORMAT_AMR_NB = 0x02000000UL,
  205. AUDIO_FORMAT_AMR_WB = 0x03000000UL,
  206. AUDIO_FORMAT_AAC = 0x04000000UL,
  207. AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V1*/
  208. AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V2*/
  209. AUDIO_FORMAT_VORBIS = 0x07000000UL,
  210. AUDIO_FORMAT_OPUS = 0x08000000UL,
  211. AUDIO_FORMAT_AC3 = 0x09000000UL,
  212. AUDIO_FORMAT_E_AC3 = 0x0A000000UL,
  213. AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL,
  214. AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL,
  215. /* Aliases */
  216. /* note != AudioFormat.ENCODING_PCM_16BIT */
  217. AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM |
  218. AUDIO_FORMAT_PCM_SUB_16_BIT),
  219. /* note != AudioFormat.ENCODING_PCM_8BIT */
  220. AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
  221. AUDIO_FORMAT_PCM_SUB_8_BIT),
  222. AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM |
  223. AUDIO_FORMAT_PCM_SUB_32_BIT),
  224. AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM |
  225. AUDIO_FORMAT_PCM_SUB_8_24_BIT),
  226. AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM |
  227. AUDIO_FORMAT_PCM_SUB_FLOAT),
  228. AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM |
  229. AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED),
  230. AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC |
  231. AUDIO_FORMAT_AAC_SUB_MAIN),
  232. AUDIO_FORMAT_AAC_LC = (AUDIO_FORMAT_AAC |
  233. AUDIO_FORMAT_AAC_SUB_LC),
  234. AUDIO_FORMAT_AAC_SSR = (AUDIO_FORMAT_AAC |
  235. AUDIO_FORMAT_AAC_SUB_SSR),
  236. AUDIO_FORMAT_AAC_LTP = (AUDIO_FORMAT_AAC |
  237. AUDIO_FORMAT_AAC_SUB_LTP),
  238. AUDIO_FORMAT_AAC_HE_V1 = (AUDIO_FORMAT_AAC |
  239. AUDIO_FORMAT_AAC_SUB_HE_V1),
  240. AUDIO_FORMAT_AAC_SCALABLE = (AUDIO_FORMAT_AAC |
  241. AUDIO_FORMAT_AAC_SUB_SCALABLE),
  242. AUDIO_FORMAT_AAC_ERLC = (AUDIO_FORMAT_AAC |
  243. AUDIO_FORMAT_AAC_SUB_ERLC),
  244. AUDIO_FORMAT_AAC_LD = (AUDIO_FORMAT_AAC |
  245. AUDIO_FORMAT_AAC_SUB_LD),
  246. AUDIO_FORMAT_AAC_HE_V2 = (AUDIO_FORMAT_AAC |
  247. AUDIO_FORMAT_AAC_SUB_HE_V2),
  248. AUDIO_FORMAT_AAC_ELD = (AUDIO_FORMAT_AAC |
  249. AUDIO_FORMAT_AAC_SUB_ELD),
  250. } audio_format_t;
  251. /* For the channel mask for position assignment representation */
  252. enum {
  253. /* These can be a complete audio_channel_mask_t. */
  254. AUDIO_CHANNEL_NONE = 0x0,
  255. AUDIO_CHANNEL_INVALID = 0xC0000000,
  256. /* These can be the bits portion of an audio_channel_mask_t
  257. * with representation AUDIO_CHANNEL_REPRESENTATION_POSITION.
  258. * Using these bits as a complete audio_channel_mask_t is deprecated.
  259. */
  260. /* output channels */
  261. AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1,
  262. AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2,
  263. AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4,
  264. AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8,
  265. AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10,
  266. AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20,
  267. AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40,
  268. AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
  269. AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100,
  270. AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200,
  271. AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400,
  272. AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800,
  273. AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000,
  274. AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000,
  275. AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000,
  276. AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000,
  277. AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000,
  278. AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000,
  279. /* TODO: should these be considered complete channel masks, or only bits? */
  280. AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT,
  281. AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  282. AUDIO_CHANNEL_OUT_FRONT_RIGHT),
  283. AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  284. AUDIO_CHANNEL_OUT_FRONT_RIGHT |
  285. AUDIO_CHANNEL_OUT_BACK_LEFT |
  286. AUDIO_CHANNEL_OUT_BACK_RIGHT),
  287. AUDIO_CHANNEL_OUT_QUAD_BACK = AUDIO_CHANNEL_OUT_QUAD,
  288. /* like AUDIO_CHANNEL_OUT_QUAD_BACK with *_SIDE_* instead of *_BACK_* */
  289. AUDIO_CHANNEL_OUT_QUAD_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  290. AUDIO_CHANNEL_OUT_FRONT_RIGHT |
  291. AUDIO_CHANNEL_OUT_SIDE_LEFT |
  292. AUDIO_CHANNEL_OUT_SIDE_RIGHT),
  293. AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  294. AUDIO_CHANNEL_OUT_FRONT_RIGHT |
  295. AUDIO_CHANNEL_OUT_FRONT_CENTER |
  296. AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
  297. AUDIO_CHANNEL_OUT_BACK_LEFT |
  298. AUDIO_CHANNEL_OUT_BACK_RIGHT),
  299. AUDIO_CHANNEL_OUT_5POINT1_BACK = AUDIO_CHANNEL_OUT_5POINT1,
  300. /* like AUDIO_CHANNEL_OUT_5POINT1_BACK with *_SIDE_* instead of *_BACK_* */
  301. AUDIO_CHANNEL_OUT_5POINT1_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  302. AUDIO_CHANNEL_OUT_FRONT_RIGHT |
  303. AUDIO_CHANNEL_OUT_FRONT_CENTER |
  304. AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
  305. AUDIO_CHANNEL_OUT_SIDE_LEFT |
  306. AUDIO_CHANNEL_OUT_SIDE_RIGHT),
  307. // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
  308. AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  309. AUDIO_CHANNEL_OUT_FRONT_RIGHT |
  310. AUDIO_CHANNEL_OUT_FRONT_CENTER |
  311. AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
  312. AUDIO_CHANNEL_OUT_BACK_LEFT |
  313. AUDIO_CHANNEL_OUT_BACK_RIGHT |
  314. AUDIO_CHANNEL_OUT_SIDE_LEFT |
  315. AUDIO_CHANNEL_OUT_SIDE_RIGHT),
  316. AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
  317. AUDIO_CHANNEL_OUT_FRONT_RIGHT |
  318. AUDIO_CHANNEL_OUT_FRONT_CENTER |
  319. AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
  320. AUDIO_CHANNEL_OUT_BACK_LEFT |
  321. AUDIO_CHANNEL_OUT_BACK_RIGHT |
  322. AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
  323. AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
  324. AUDIO_CHANNEL_OUT_BACK_CENTER|
  325. AUDIO_CHANNEL_OUT_SIDE_LEFT|
  326. AUDIO_CHANNEL_OUT_SIDE_RIGHT|
  327. AUDIO_CHANNEL_OUT_TOP_CENTER|
  328. AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT|
  329. AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER|
  330. AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT|
  331. AUDIO_CHANNEL_OUT_TOP_BACK_LEFT|
  332. AUDIO_CHANNEL_OUT_TOP_BACK_CENTER|
  333. AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT),
  334. /* These are bits only, not complete values */
  335. /* input channels */
  336. AUDIO_CHANNEL_IN_LEFT = 0x4,
  337. AUDIO_CHANNEL_IN_RIGHT = 0x8,
  338. AUDIO_CHANNEL_IN_FRONT = 0x10,
  339. AUDIO_CHANNEL_IN_BACK = 0x20,
  340. AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40,
  341. AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
  342. AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
  343. AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200,
  344. AUDIO_CHANNEL_IN_PRESSURE = 0x400,
  345. AUDIO_CHANNEL_IN_X_AXIS = 0x800,
  346. AUDIO_CHANNEL_IN_Y_AXIS = 0x1000,
  347. AUDIO_CHANNEL_IN_Z_AXIS = 0x2000,
  348. AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000,
  349. AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000,
  350. /* TODO: should these be considered complete channel masks, or only bits, or deprecated? */
  351. AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT,
  352. AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
  353. AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK),
  354. AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT |
  355. AUDIO_CHANNEL_IN_RIGHT |
  356. AUDIO_CHANNEL_IN_FRONT |
  357. AUDIO_CHANNEL_IN_BACK|
  358. AUDIO_CHANNEL_IN_LEFT_PROCESSED |
  359. AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
  360. AUDIO_CHANNEL_IN_FRONT_PROCESSED |
  361. AUDIO_CHANNEL_IN_BACK_PROCESSED|
  362. AUDIO_CHANNEL_IN_PRESSURE |
  363. AUDIO_CHANNEL_IN_X_AXIS |
  364. AUDIO_CHANNEL_IN_Y_AXIS |
  365. AUDIO_CHANNEL_IN_Z_AXIS |
  366. AUDIO_CHANNEL_IN_VOICE_UPLINK |
  367. AUDIO_CHANNEL_IN_VOICE_DNLINK),
  368. };
  369. /* A channel mask per se only defines the presence or absence of a channel, not the order.
  370. * But see AUDIO_INTERLEAVE_* below for the platform convention of order.
  371. *
  372. * audio_channel_mask_t is an opaque type and its internal layout should not
  373. * be assumed as it may change in the future.
  374. * Instead, always use the functions declared in this header to examine.
  375. *
  376. * These are the current representations:
  377. *
  378. * AUDIO_CHANNEL_REPRESENTATION_POSITION
  379. * is a channel mask representation for position assignment.
  380. * Each low-order bit corresponds to the spatial position of a transducer (output),
  381. * or interpretation of channel (input).
  382. * The user of a channel mask needs to know the context of whether it is for output or input.
  383. * The constants AUDIO_CHANNEL_OUT_* or AUDIO_CHANNEL_IN_* apply to the bits portion.
  384. * It is not permitted for no bits to be set.
  385. *
  386. * AUDIO_CHANNEL_REPRESENTATION_INDEX
  387. * is a channel mask representation for index assignment.
  388. * Each low-order bit corresponds to a selected channel.
  389. * There is no platform interpretation of the various bits.
  390. * There is no concept of output or input.
  391. * It is not permitted for no bits to be set.
  392. *
  393. * All other representations are reserved for future use.
  394. *
  395. * Warning: current representation distinguishes between input and output, but this will not the be
  396. * case in future revisions of the platform. Wherever there is an ambiguity between input and output
  397. * that is currently resolved by checking the channel mask, the implementer should look for ways to
  398. * fix it with additional information outside of the mask.
  399. */
  400. typedef uint32_t audio_channel_mask_t;
  401. /* Maximum number of channels for all representations */
  402. #define AUDIO_CHANNEL_COUNT_MAX 30
  403. /* log(2) of maximum number of representations, not part of public API */
  404. #define AUDIO_CHANNEL_REPRESENTATION_LOG2 2
  405. /* Representations */
  406. typedef enum {
  407. AUDIO_CHANNEL_REPRESENTATION_POSITION = 0, // must be zero for compatibility
  408. // 1 is reserved for future use
  409. AUDIO_CHANNEL_REPRESENTATION_INDEX = 2,
  410. // 3 is reserved for future use
  411. } audio_channel_representation_t;
  412. /* The return value is undefined if the channel mask is invalid. */
  413. static inline uint32_t audio_channel_mask_get_bits(audio_channel_mask_t channel)
  414. {
  415. return channel & ((1 << AUDIO_CHANNEL_COUNT_MAX) - 1);
  416. }
  417. /* The return value is undefined if the channel mask is invalid. */
  418. static inline audio_channel_representation_t audio_channel_mask_get_representation(
  419. audio_channel_mask_t channel)
  420. {
  421. // The right shift should be sufficient, but also "and" for safety in case mask is not 32 bits
  422. return (audio_channel_representation_t)
  423. ((channel >> AUDIO_CHANNEL_COUNT_MAX) & ((1 << AUDIO_CHANNEL_REPRESENTATION_LOG2) - 1));
  424. }
  425. /* Returns true if the channel mask is valid,
  426. * or returns false for AUDIO_CHANNEL_NONE, AUDIO_CHANNEL_INVALID, and other invalid values.
  427. * This function is unable to determine whether a channel mask for position assignment
  428. * is invalid because an output mask has an invalid output bit set,
  429. * or because an input mask has an invalid input bit set.
  430. * All other APIs that take a channel mask assume that it is valid.
  431. */
  432. static inline bool audio_channel_mask_is_valid(audio_channel_mask_t channel)
  433. {
  434. uint32_t bits = audio_channel_mask_get_bits(channel);
  435. audio_channel_representation_t representation = audio_channel_mask_get_representation(channel);
  436. switch (representation) {
  437. case AUDIO_CHANNEL_REPRESENTATION_POSITION:
  438. case AUDIO_CHANNEL_REPRESENTATION_INDEX:
  439. break;
  440. default:
  441. bits = 0;
  442. break;
  443. }
  444. return bits != 0;
  445. }
  446. /* Not part of public API */
  447. static inline audio_channel_mask_t audio_channel_mask_from_representation_and_bits(
  448. audio_channel_representation_t representation, uint32_t bits)
  449. {
  450. return (audio_channel_mask_t) ((representation << AUDIO_CHANNEL_COUNT_MAX) | bits);
  451. }
  452. /* Expresses the convention when stereo audio samples are stored interleaved
  453. * in an array. This should improve readability by allowing code to use
  454. * symbolic indices instead of hard-coded [0] and [1].
  455. *
  456. * For multi-channel beyond stereo, the platform convention is that channels
  457. * are interleaved in order from least significant channel mask bit
  458. * to most significant channel mask bit, with unused bits skipped.
  459. * Any exceptions to this convention will be noted at the appropriate API.
  460. */
  461. enum {
  462. AUDIO_INTERLEAVE_LEFT = 0,
  463. AUDIO_INTERLEAVE_RIGHT = 1,
  464. };
  465. typedef enum {
  466. AUDIO_MODE_INVALID = -2,
  467. AUDIO_MODE_CURRENT = -1,
  468. AUDIO_MODE_NORMAL = 0,
  469. AUDIO_MODE_RINGTONE = 1,
  470. AUDIO_MODE_IN_CALL = 2,
  471. AUDIO_MODE_IN_COMMUNICATION = 3,
  472. AUDIO_MODE_CNT,
  473. AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1,
  474. } audio_mode_t;
  475. /* This enum is deprecated */
  476. typedef enum {
  477. AUDIO_IN_ACOUSTICS_NONE = 0,
  478. AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
  479. AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
  480. AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
  481. AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
  482. AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
  483. AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
  484. } audio_in_acoustics_t;
  485. enum {
  486. AUDIO_DEVICE_NONE = 0x0,
  487. /* reserved bits */
  488. AUDIO_DEVICE_BIT_IN = 0x80000000,
  489. AUDIO_DEVICE_BIT_DEFAULT = 0x40000000,
  490. /* output devices */
  491. AUDIO_DEVICE_OUT_EARPIECE = 0x1,
  492. AUDIO_DEVICE_OUT_SPEAKER = 0x2,
  493. AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
  494. AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
  495. AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10,
  496. AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
  497. AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
  498. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
  499. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
  500. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
  501. AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400,
  502. AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT_AUX_DIGITAL,
  503. /* uses an analog connection (multiplexed over the USB connector pins for instance) */
  504. AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
  505. AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
  506. /* USB accessory mode: your Android device is a USB device and the dock is a USB host */
  507. AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000,
  508. /* USB host mode: your Android device is a USB host and the dock is a USB device */
  509. AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000,
  510. AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000,
  511. /* Telephony voice TX path */
  512. AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000,
  513. /* Analog jack with line impedance detected */
  514. AUDIO_DEVICE_OUT_LINE = 0x20000,
  515. /* HDMI Audio Return Channel */
  516. AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000,
  517. /* S/PDIF out */
  518. AUDIO_DEVICE_OUT_SPDIF = 0x80000,
  519. /* FM transmitter out */
  520. AUDIO_DEVICE_OUT_FM = 0x100000,
  521. /* Line out for av devices */
  522. AUDIO_DEVICE_OUT_AUX_LINE = 0x200000,
  523. /* limited-output speaker device for acoustic safety */
  524. AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000,
  525. AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT,
  526. AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE |
  527. AUDIO_DEVICE_OUT_SPEAKER |
  528. AUDIO_DEVICE_OUT_WIRED_HEADSET |
  529. AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
  530. AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
  531. AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
  532. AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
  533. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
  534. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
  535. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
  536. AUDIO_DEVICE_OUT_HDMI |
  537. AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
  538. AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
  539. AUDIO_DEVICE_OUT_USB_ACCESSORY |
  540. AUDIO_DEVICE_OUT_USB_DEVICE |
  541. AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
  542. AUDIO_DEVICE_OUT_TELEPHONY_TX |
  543. AUDIO_DEVICE_OUT_LINE |
  544. AUDIO_DEVICE_OUT_HDMI_ARC |
  545. AUDIO_DEVICE_OUT_SPDIF |
  546. AUDIO_DEVICE_OUT_FM |
  547. AUDIO_DEVICE_OUT_AUX_LINE |
  548. AUDIO_DEVICE_OUT_SPEAKER_SAFE |
  549. AUDIO_DEVICE_OUT_DEFAULT),
  550. AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
  551. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
  552. AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
  553. AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
  554. AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
  555. AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
  556. AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY |
  557. AUDIO_DEVICE_OUT_USB_DEVICE),
  558. /* input devices */
  559. AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1,
  560. AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2,
  561. AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4,
  562. AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8,
  563. AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10,
  564. AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20,
  565. AUDIO_DEVICE_IN_HDMI = AUDIO_DEVICE_IN_AUX_DIGITAL,
  566. /* Telephony voice RX path */
  567. AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40,
  568. AUDIO_DEVICE_IN_TELEPHONY_RX = AUDIO_DEVICE_IN_VOICE_CALL,
  569. AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80,
  570. AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100,
  571. AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200,
  572. AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400,
  573. AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800,
  574. AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000,
  575. /* FM tuner input */
  576. AUDIO_DEVICE_IN_FM_TUNER = AUDIO_DEVICE_BIT_IN | 0x2000,
  577. /* TV tuner input */
  578. AUDIO_DEVICE_IN_TV_TUNER = AUDIO_DEVICE_BIT_IN | 0x4000,
  579. /* Analog jack with line impedance detected */
  580. AUDIO_DEVICE_IN_LINE = AUDIO_DEVICE_BIT_IN | 0x8000,
  581. /* S/PDIF in */
  582. AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000,
  583. AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000,
  584. AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000,
  585. AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT,
  586. AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION |
  587. AUDIO_DEVICE_IN_AMBIENT |
  588. AUDIO_DEVICE_IN_BUILTIN_MIC |
  589. AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
  590. AUDIO_DEVICE_IN_WIRED_HEADSET |
  591. AUDIO_DEVICE_IN_HDMI |
  592. AUDIO_DEVICE_IN_TELEPHONY_RX |
  593. AUDIO_DEVICE_IN_BACK_MIC |
  594. AUDIO_DEVICE_IN_REMOTE_SUBMIX |
  595. AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET |
  596. AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET |
  597. AUDIO_DEVICE_IN_USB_ACCESSORY |
  598. AUDIO_DEVICE_IN_USB_DEVICE |
  599. AUDIO_DEVICE_IN_FM_TUNER |
  600. AUDIO_DEVICE_IN_TV_TUNER |
  601. AUDIO_DEVICE_IN_LINE |
  602. AUDIO_DEVICE_IN_SPDIF |
  603. AUDIO_DEVICE_IN_BLUETOOTH_A2DP |
  604. AUDIO_DEVICE_IN_LOOPBACK |
  605. AUDIO_DEVICE_IN_DEFAULT),
  606. AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
  607. AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY |
  608. AUDIO_DEVICE_IN_USB_DEVICE),
  609. };
  610. typedef uint32_t audio_devices_t;
  611. /* the audio output flags serve two purposes:
  612. * - when an AudioTrack is created they indicate a "wish" to be connected to an
  613. * output stream with attributes corresponding to the specified flags
  614. * - when present in an output profile descriptor listed for a particular audio
  615. * hardware module, they indicate that an output stream can be opened that
  616. * supports the attributes indicated by the flags.
  617. * the audio policy manager will try to match the flags in the request
  618. * (when getOuput() is called) to an available output stream.
  619. */
  620. typedef enum {
  621. AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes
  622. AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track
  623. // to one output stream: no software mixer
  624. AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of
  625. // the device. It is unique and must be
  626. // present. It is opened by default and
  627. // receives routing, audio mode and volume
  628. // controls related to voice calls.
  629. AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks",
  630. // defined elsewhere
  631. AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers
  632. AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed
  633. // streams to hardware codec
  634. AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20, // use non-blocking write
  635. AUDIO_OUTPUT_FLAG_HW_AV_SYNC = 0x40 // output uses a hardware A/V synchronization source
  636. } audio_output_flags_t;
  637. /* The audio input flags are analogous to audio output flags.
  638. * Currently they are used only when an AudioRecord is created,
  639. * to indicate a preference to be connected to an input stream with
  640. * attributes corresponding to the specified flags.
  641. */
  642. typedef enum {
  643. AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes
  644. AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks"
  645. AUDIO_INPUT_FLAG_HW_HOTWORD = 0x2, // prefer an input that captures from hw hotword source
  646. } audio_input_flags_t;
  647. /* Additional information about compressed streams offloaded to
  648. * hardware playback
  649. * The version and size fields must be initialized by the caller by using
  650. * one of the constants defined here.
  651. */
  652. typedef struct {
  653. uint16_t version; // version of the info structure
  654. uint16_t size; // total size of the structure including version and size
  655. uint32_t sample_rate; // sample rate in Hz
  656. audio_channel_mask_t channel_mask; // channel mask
  657. audio_format_t format; // audio format
  658. audio_stream_type_t stream_type; // stream type
  659. uint32_t bit_rate; // bit rate in bits per second
  660. int64_t duration_us; // duration in microseconds, -1 if unknown
  661. bool has_video; // true if stream is tied to a video stream
  662. bool is_streaming; // true if streaming, false if local playback
  663. } audio_offload_info_t;
  664. #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \
  665. ((((maj) & 0xff) << 8) | ((min) & 0xff))
  666. #define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1)
  667. #define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1
  668. static const audio_offload_info_t AUDIO_INFO_INITIALIZER = {
  669. version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
  670. size: sizeof(audio_offload_info_t),
  671. sample_rate: 0,
  672. channel_mask: 0,
  673. format: AUDIO_FORMAT_DEFAULT,
  674. stream_type: AUDIO_STREAM_VOICE_CALL,
  675. bit_rate: 0,
  676. duration_us: 0,
  677. has_video: false,
  678. is_streaming: false
  679. };
  680. /* common audio stream configuration parameters
  681. * You should memset() the entire structure to zero before use to
  682. * ensure forward compatibility
  683. */
  684. struct audio_config {
  685. uint32_t sample_rate;
  686. audio_channel_mask_t channel_mask;
  687. audio_format_t format;
  688. audio_offload_info_t offload_info;
  689. size_t frame_count;
  690. };
  691. typedef struct audio_config audio_config_t;
  692. static const audio_config_t AUDIO_CONFIG_INITIALIZER = {
  693. sample_rate: 0,
  694. channel_mask: AUDIO_CHANNEL_NONE,
  695. format: AUDIO_FORMAT_DEFAULT,
  696. offload_info: {
  697. version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
  698. size: sizeof(audio_offload_info_t),
  699. sample_rate: 0,
  700. channel_mask: 0,
  701. format: AUDIO_FORMAT_DEFAULT,
  702. stream_type: AUDIO_STREAM_VOICE_CALL,
  703. bit_rate: 0,
  704. duration_us: 0,
  705. has_video: false,
  706. is_streaming: false
  707. },
  708. frame_count: 0,
  709. };
  710. /* audio hw module handle functions or structures referencing a module */
  711. typedef int audio_module_handle_t;
  712. /******************************
  713. * Volume control
  714. *****************************/
  715. /* If the audio hardware supports gain control on some audio paths,
  716. * the platform can expose them in the audio_policy.conf file. The audio HAL
  717. * will then implement gain control functions that will use the following data
  718. * structures. */
  719. /* Type of gain control exposed by an audio port */
  720. #define AUDIO_GAIN_MODE_JOINT 0x1 /* supports joint channel gain control */
  721. #define AUDIO_GAIN_MODE_CHANNELS 0x2 /* supports separate channel gain control */
  722. #define AUDIO_GAIN_MODE_RAMP 0x4 /* supports gain ramps */
  723. typedef uint32_t audio_gain_mode_t;
  724. /* An audio_gain struct is a representation of a gain stage.
  725. * A gain stage is always attached to an audio port. */
  726. struct audio_gain {
  727. audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */
  728. audio_channel_mask_t channel_mask; /* channels which gain an be controlled.
  729. N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */
  730. int min_value; /* minimum gain value in millibels */
  731. int max_value; /* maximum gain value in millibels */
  732. int default_value; /* default gain value in millibels */
  733. unsigned int step_value; /* gain step in millibels */
  734. unsigned int min_ramp_ms; /* minimum ramp duration in ms */
  735. unsigned int max_ramp_ms; /* maximum ramp duration in ms */
  736. };
  737. /* The gain configuration structure is used to get or set the gain values of a
  738. * given port */
  739. struct audio_gain_config {
  740. int index; /* index of the corresponding audio_gain in the
  741. audio_port gains[] table */
  742. audio_gain_mode_t mode; /* mode requested for this command */
  743. audio_channel_mask_t channel_mask; /* channels which gain value follows.
  744. N/A in joint mode */
  745. int values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels
  746. for each channel ordered from LSb to MSb in
  747. channel mask. The number of values is 1 in joint
  748. mode or popcount(channel_mask) */
  749. unsigned int ramp_duration_ms; /* ramp duration in ms */
  750. };
  751. /******************************
  752. * Routing control
  753. *****************************/
  754. /* Types defined here are used to describe an audio source or sink at internal
  755. * framework interfaces (audio policy, patch panel) or at the audio HAL.
  756. * Sink and sources are grouped in a concept of “audio port” representing an
  757. * audio end point at the edge of the system managed by the module exposing
  758. * the interface. */
  759. /* Audio port role: either source or sink */
  760. typedef enum {
  761. AUDIO_PORT_ROLE_NONE,
  762. AUDIO_PORT_ROLE_SOURCE,
  763. AUDIO_PORT_ROLE_SINK,
  764. } audio_port_role_t;
  765. /* Audio port type indicates if it is a session (e.g AudioTrack),
  766. * a mix (e.g PlaybackThread output) or a physical device
  767. * (e.g AUDIO_DEVICE_OUT_SPEAKER) */
  768. typedef enum {
  769. AUDIO_PORT_TYPE_NONE,
  770. AUDIO_PORT_TYPE_DEVICE,
  771. AUDIO_PORT_TYPE_MIX,
  772. AUDIO_PORT_TYPE_SESSION,
  773. } audio_port_type_t;
  774. /* Each port has a unique ID or handle allocated by policy manager */
  775. typedef int audio_port_handle_t;
  776. #define AUDIO_PORT_HANDLE_NONE 0
  777. /* maximum audio device address length */
  778. #define AUDIO_DEVICE_MAX_ADDRESS_LEN 32
  779. /* extension for audio port configuration structure when the audio port is a
  780. * hardware device */
  781. struct audio_port_config_device_ext {
  782. audio_module_handle_t hw_module; /* module the device is attached to */
  783. audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
  784. char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */
  785. };
  786. /* extension for audio port configuration structure when the audio port is a
  787. * sub mix */
  788. struct audio_port_config_mix_ext {
  789. audio_module_handle_t hw_module; /* module the stream is attached to */
  790. audio_io_handle_t handle; /* I/O handle of the input/output stream */
  791. union {
  792. //TODO: change use case for output streams: use strategy and mixer attributes
  793. audio_stream_type_t stream;
  794. audio_source_t source;
  795. } usecase;
  796. };
  797. /* extension for audio port configuration structure when the audio port is an
  798. * audio session */
  799. struct audio_port_config_session_ext {
  800. audio_session_t session; /* audio session */
  801. };
  802. /* Flags indicating which fields are to be considered in struct audio_port_config */
  803. #define AUDIO_PORT_CONFIG_SAMPLE_RATE 0x1
  804. #define AUDIO_PORT_CONFIG_CHANNEL_MASK 0x2
  805. #define AUDIO_PORT_CONFIG_FORMAT 0x4
  806. #define AUDIO_PORT_CONFIG_GAIN 0x8
  807. #define AUDIO_PORT_CONFIG_ALL (AUDIO_PORT_CONFIG_SAMPLE_RATE | \
  808. AUDIO_PORT_CONFIG_CHANNEL_MASK | \
  809. AUDIO_PORT_CONFIG_FORMAT | \
  810. AUDIO_PORT_CONFIG_GAIN)
  811. /* audio port configuration structure used to specify a particular configuration of
  812. * an audio port */
  813. struct audio_port_config {
  814. audio_port_handle_t id; /* port unique ID */
  815. audio_port_role_t role; /* sink or source */
  816. audio_port_type_t type; /* device, mix ... */
  817. unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */
  818. unsigned int sample_rate; /* sampling rate in Hz */
  819. audio_channel_mask_t channel_mask; /* channel mask if applicable */
  820. audio_format_t format; /* format if applicable */
  821. struct audio_gain_config gain; /* gain to apply if applicable */
  822. union {
  823. struct audio_port_config_device_ext device; /* device specific info */
  824. struct audio_port_config_mix_ext mix; /* mix specific info */
  825. struct audio_port_config_session_ext session; /* session specific info */
  826. } ext;
  827. };
  828. /* max number of sampling rates in audio port */
  829. #define AUDIO_PORT_MAX_SAMPLING_RATES 16
  830. /* max number of channel masks in audio port */
  831. #define AUDIO_PORT_MAX_CHANNEL_MASKS 16
  832. /* max number of audio formats in audio port */
  833. #define AUDIO_PORT_MAX_FORMATS 16
  834. /* max number of gain controls in audio port */
  835. #define AUDIO_PORT_MAX_GAINS 16
  836. /* extension for audio port structure when the audio port is a hardware device */
  837. struct audio_port_device_ext {
  838. audio_module_handle_t hw_module; /* module the device is attached to */
  839. audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
  840. char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
  841. };
  842. /* Latency class of the audio mix */
  843. typedef enum {
  844. AUDIO_LATENCY_LOW,
  845. AUDIO_LATENCY_NORMAL,
  846. } audio_mix_latency_class_t;
  847. /* extension for audio port structure when the audio port is a sub mix */
  848. struct audio_port_mix_ext {
  849. audio_module_handle_t hw_module; /* module the stream is attached to */
  850. audio_io_handle_t handle; /* I/O handle of the input.output stream */
  851. audio_mix_latency_class_t latency_class; /* latency class */
  852. // other attributes: routing strategies
  853. };
  854. /* extension for audio port structure when the audio port is an audio session */
  855. struct audio_port_session_ext {
  856. audio_session_t session; /* audio session */
  857. };
  858. struct audio_port {
  859. audio_port_handle_t id; /* port unique ID */
  860. audio_port_role_t role; /* sink or source */
  861. audio_port_type_t type; /* device, mix ... */
  862. unsigned int num_sample_rates; /* number of sampling rates in following array */
  863. unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES];
  864. unsigned int num_channel_masks; /* number of channel masks in following array */
  865. audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS];
  866. unsigned int num_formats; /* number of formats in following array */
  867. audio_format_t formats[AUDIO_PORT_MAX_FORMATS];
  868. unsigned int num_gains; /* number of gains in following array */
  869. struct audio_gain gains[AUDIO_PORT_MAX_GAINS];
  870. struct audio_port_config active_config; /* current audio port configuration */
  871. union {
  872. struct audio_port_device_ext device;
  873. struct audio_port_mix_ext mix;
  874. struct audio_port_session_ext session;
  875. } ext;
  876. };
  877. /* An audio patch represents a connection between one or more source ports and
  878. * one or more sink ports. Patches are connected and disconnected by audio policy manager or by
  879. * applications via framework APIs.
  880. * Each patch is identified by a handle at the interface used to create that patch. For instance,
  881. * when a patch is created by the audio HAL, the HAL allocates and returns a handle.
  882. * This handle is unique to a given audio HAL hardware module.
  883. * But the same patch receives another system wide unique handle allocated by the framework.
  884. * This unique handle is used for all transactions inside the framework.
  885. */
  886. typedef int audio_patch_handle_t;
  887. #define AUDIO_PATCH_HANDLE_NONE 0
  888. #define AUDIO_PATCH_PORTS_MAX 16
  889. struct audio_patch {
  890. audio_patch_handle_t id; /* patch unique ID */
  891. unsigned int num_sources; /* number of sources in following array */
  892. struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
  893. unsigned int num_sinks; /* number of sinks in following array */
  894. struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
  895. };
  896. /* a HW synchronization source returned by the audio HAL */
  897. typedef uint32_t audio_hw_sync_t;
  898. /* an invalid HW synchronization source indicating an error */
  899. #define AUDIO_HW_SYNC_INVALID 0
  900. static inline bool audio_is_output_device(audio_devices_t device)
  901. {
  902. if (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
  903. (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
  904. return true;
  905. else
  906. return false;
  907. }
  908. static inline bool audio_is_input_device(audio_devices_t device)
  909. {
  910. if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
  911. device &= ~AUDIO_DEVICE_BIT_IN;
  912. if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
  913. return true;
  914. }
  915. return false;
  916. }
  917. static inline bool audio_is_output_devices(audio_devices_t device)
  918. {
  919. return (device & AUDIO_DEVICE_BIT_IN) == 0;
  920. }
  921. static inline bool audio_is_a2dp_in_device(audio_devices_t device)
  922. {
  923. if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
  924. device &= ~AUDIO_DEVICE_BIT_IN;
  925. if ((popcount(device) == 1) && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP))
  926. return true;
  927. }
  928. return false;
  929. }
  930. static inline bool audio_is_a2dp_out_device(audio_devices_t device)
  931. {
  932. if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
  933. return true;
  934. else
  935. return false;
  936. }
  937. // Deprecated - use audio_is_a2dp_out_device() instead
  938. static inline bool audio_is_a2dp_device(audio_devices_t device)
  939. {
  940. return audio_is_a2dp_out_device(device);
  941. }
  942. static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
  943. {
  944. if ((device & AUDIO_DEVICE_BIT_IN) == 0) {
  945. if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0))
  946. return true;
  947. } else {
  948. device &= ~AUDIO_DEVICE_BIT_IN;
  949. if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0))
  950. return true;
  951. }
  952. return false;
  953. }
  954. static inline bool audio_is_usb_out_device(audio_devices_t device)
  955. {
  956. return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB));
  957. }
  958. static inline bool audio_is_usb_in_device(audio_devices_t device)
  959. {
  960. if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
  961. device &= ~AUDIO_DEVICE_BIT_IN;
  962. if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0)
  963. return true;
  964. }
  965. return false;
  966. }
  967. /* OBSOLETE - use audio_is_usb_out_device() instead. */
  968. static inline bool audio_is_usb_device(audio_devices_t device)
  969. {
  970. return audio_is_usb_out_device(device);
  971. }
  972. static inline bool audio_is_remote_submix_device(audio_devices_t device)
  973. {
  974. if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX
  975. || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX)
  976. return true;
  977. else
  978. return false;
  979. }
  980. /* Returns true if:
  981. * representation is valid, and
  982. * there is at least one channel bit set which _could_ correspond to an input channel, and
  983. * there are no channel bits set which could _not_ correspond to an input channel.
  984. * Otherwise returns false.
  985. */
  986. static inline bool audio_is_input_channel(audio_channel_mask_t channel)
  987. {
  988. uint32_t bits = audio_channel_mask_get_bits(channel);
  989. switch (audio_channel_mask_get_representation(channel)) {
  990. case AUDIO_CHANNEL_REPRESENTATION_POSITION:
  991. if (bits & ~AUDIO_CHANNEL_IN_ALL) {
  992. bits = 0;
  993. }
  994. // fall through
  995. case AUDIO_CHANNEL_REPRESENTATION_INDEX:
  996. return bits != 0;
  997. default:
  998. return false;
  999. }
  1000. }
  1001. /* Returns true if:
  1002. * representation is valid, and
  1003. * there is at least one channel bit set which _could_ correspond to an output channel, and
  1004. * there are no channel bits set which could _not_ correspond to an output channel.
  1005. * Otherwise returns false.
  1006. */
  1007. static inline bool audio_is_output_channel(audio_channel_mask_t channel)
  1008. {
  1009. uint32_t bits = audio_channel_mask_get_bits(channel);
  1010. switch (audio_channel_mask_get_representation(channel)) {
  1011. case AUDIO_CHANNEL_REPRESENTATION_POSITION:
  1012. if (bits & ~AUDIO_CHANNEL_OUT_ALL) {
  1013. bits = 0;
  1014. }
  1015. // fall through
  1016. case AUDIO_CHANNEL_REPRESENTATION_INDEX:
  1017. return bits != 0;
  1018. default:
  1019. return false;
  1020. }
  1021. }
  1022. /* Returns the number of channels from an input channel mask,
  1023. * used in the context of audio input or recording.
  1024. * If a channel bit is set which could _not_ correspond to an input channel,
  1025. * it is excluded from the count.
  1026. * Returns zero if the representation is invalid.
  1027. */
  1028. static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
  1029. {
  1030. uint32_t bits = audio_channel_mask_get_bits(channel);
  1031. switch (audio_channel_mask_get_representation(channel)) {
  1032. case AUDIO_CHANNEL_REPRESENTATION_POSITION:
  1033. // TODO: We can now merge with from_out_mask and remove anding
  1034. bits &= AUDIO_CHANNEL_IN_ALL;
  1035. // fall through
  1036. case AUDIO_CHANNEL_REPRESENTATION_INDEX:
  1037. return popcount(bits);
  1038. default:
  1039. return 0;
  1040. }
  1041. }
  1042. /* Returns the number of channels from an output channel mask,
  1043. * used in the context of audio output or playback.
  1044. * If a channel bit is set which could _not_ correspond to an output channel,
  1045. * it is excluded from the count.
  1046. * Returns zero if the representation is invalid.
  1047. */
  1048. static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
  1049. {
  1050. uint32_t bits = audio_channel_mask_get_bits(channel);
  1051. switch (audio_channel_mask_get_representation(channel)) {
  1052. case AUDIO_CHANNEL_REPRESENTATION_POSITION:
  1053. // TODO: We can now merge with from_in_mask and remove anding
  1054. bits &= AUDIO_CHANNEL_OUT_ALL;
  1055. // fall through
  1056. case AUDIO_CHANNEL_REPRESENTATION_INDEX:
  1057. return popcount(bits);
  1058. default:
  1059. return 0;
  1060. }
  1061. }
  1062. /* Derive an output channel mask for position assignment from a channel count.
  1063. * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
  1064. * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
  1065. * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
  1066. * for continuity with stereo.
  1067. * Returns the matching channel mask,
  1068. * or AUDIO_CHANNEL_NONE if the channel count is zero,
  1069. * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
  1070. * configurations for which a default output channel mask is defined.
  1071. */
  1072. static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
  1073. {
  1074. uint32_t bits;
  1075. switch (channel_count) {
  1076. case 0:
  1077. return AUDIO_CHANNEL_NONE;
  1078. case 1:
  1079. bits = AUDIO_CHANNEL_OUT_MONO;
  1080. break;
  1081. case 2:
  1082. bits = AUDIO_CHANNEL_OUT_STEREO;
  1083. break;
  1084. case 3:
  1085. bits = AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER;
  1086. break;
  1087. case 4: // 4.0
  1088. bits = AUDIO_CHANNEL_OUT_QUAD;
  1089. break;
  1090. case 5: // 5.0
  1091. bits = AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER;
  1092. break;
  1093. case 6: // 5.1
  1094. bits = AUDIO_CHANNEL_OUT_5POINT1;
  1095. break;
  1096. case 7: // 6.1
  1097. bits = AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER;
  1098. break;
  1099. case 8:
  1100. bits = AUDIO_CHANNEL_OUT_7POINT1;
  1101. break;
  1102. default:
  1103. return AUDIO_CHANNEL_INVALID;
  1104. }
  1105. return audio_channel_mask_from_representation_and_bits(
  1106. AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
  1107. }
  1108. /* Derive an input channel mask for position assignment from a channel count.
  1109. * Currently handles only mono and stereo.
  1110. * Returns the matching channel mask,
  1111. * or AUDIO_CHANNEL_NONE if the channel count is zero,
  1112. * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
  1113. * configurations for which a default input channel mask is defined.
  1114. */
  1115. static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
  1116. {
  1117. uint32_t bits;
  1118. switch (channel_count) {
  1119. case 0:
  1120. return AUDIO_CHANNEL_NONE;
  1121. case 1:
  1122. bits = AUDIO_CHANNEL_IN_MONO;
  1123. break;
  1124. case 2:
  1125. bits = AUDIO_CHANNEL_IN_STEREO;
  1126. break;
  1127. default:
  1128. return AUDIO_CHANNEL_INVALID;
  1129. }
  1130. return audio_channel_mask_from_representation_and_bits(
  1131. AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
  1132. }
  1133. /* Derive a channel mask for index assignment from a channel count.
  1134. * Returns the matching channel mask,
  1135. * or AUDIO_CHANNEL_NONE if the channel count is zero,
  1136. * or AUDIO_CHANNEL_INVALID if the channel count exceeds AUDIO_CHANNEL_COUNT_MAX.
  1137. */
  1138. static inline audio_channel_mask_t audio_channel_mask_for_index_assignment_from_count(
  1139. uint32_t channel_count)
  1140. {
  1141. uint32_t bits;
  1142. if (channel_count == 0) {
  1143. return AUDIO_CHANNEL_NONE;
  1144. }
  1145. if (channel_count > AUDIO_CHANNEL_COUNT_MAX) {
  1146. return AUDIO_CHANNEL_INVALID;
  1147. }
  1148. bits = (1 << channel_count) - 1;
  1149. return audio_channel_mask_from_representation_and_bits(
  1150. AUDIO_CHANNEL_REPRESENTATION_INDEX, bits);
  1151. }
  1152. static inline bool audio_is_valid_format(audio_format_t format)
  1153. {
  1154. switch (format & AUDIO_FORMAT_MAIN_MASK) {
  1155. case AUDIO_FORMAT_PCM:
  1156. switch (format) {
  1157. case AUDIO_FORMAT_PCM_16_BIT:
  1158. case AUDIO_FORMAT_PCM_8_BIT:
  1159. case AUDIO_FORMAT_PCM_32_BIT:
  1160. case AUDIO_FORMAT_PCM_8_24_BIT:
  1161. case AUDIO_FORMAT_PCM_FLOAT:
  1162. case AUDIO_FORMAT_PCM_24_BIT_PACKED:
  1163. return true;
  1164. case AUDIO_FORMAT_INVALID:
  1165. case AUDIO_FORMAT_DEFAULT:
  1166. case AUDIO_FORMAT_MP3:
  1167. case AUDIO_FORMAT_AMR_NB:
  1168. case AUDIO_FORMAT_AMR_WB:
  1169. case AUDIO_FORMAT_AAC:
  1170. case AUDIO_FORMAT_HE_AAC_V1:
  1171. case AUDIO_FORMAT_HE_AAC_V2:
  1172. case AUDIO_FORMAT_VORBIS:
  1173. case AUDIO_FORMAT_OPUS:
  1174. case AUDIO_FORMAT_AC3:
  1175. case AUDIO_FORMAT_E_AC3:
  1176. case AUDIO_FORMAT_MAIN_MASK:
  1177. case AUDIO_FORMAT_SUB_MASK:
  1178. case AUDIO_FORMAT_AAC_MAIN:
  1179. case AUDIO_FORMAT_AAC_LC:
  1180. case AUDIO_FORMAT_AAC_SSR:
  1181. case AUDIO_FORMAT_AAC_LTP:
  1182. case AUDIO_FORMAT_AAC_HE_V1:
  1183. case AUDIO_FORMAT_AAC_SCALABLE:
  1184. case AUDIO_FORMAT_AAC_ERLC:
  1185. case AUDIO_FORMAT_AAC_LD:
  1186. case AUDIO_FORMAT_AAC_HE_V2:
  1187. case AUDIO_FORMAT_AAC_ELD:
  1188. default:
  1189. return false;
  1190. }
  1191. /* not reached */
  1192. case AUDIO_FORMAT_MP3:
  1193. case AUDIO_FORMAT_AMR_NB:
  1194. case AUDIO_FORMAT_AMR_WB:
  1195. case AUDIO_FORMAT_AAC:
  1196. case AUDIO_FORMAT_HE_AAC_V1:
  1197. case AUDIO_FORMAT_HE_AAC_V2:
  1198. case AUDIO_FORMAT_VORBIS:
  1199. case AUDIO_FORMAT_OPUS:
  1200. case AUDIO_FORMAT_AC3:
  1201. case AUDIO_FORMAT_E_AC3:
  1202. return true;
  1203. default:
  1204. return false;
  1205. }
  1206. }
  1207. static inline bool audio_is_linear_pcm(audio_format_t format)
  1208. {
  1209. return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM);
  1210. }
  1211. static inline size_t audio_bytes_per_sample(audio_format_t format)
  1212. {
  1213. size_t size = 0;
  1214. switch (format) {
  1215. case AUDIO_FORMAT_PCM_32_BIT:
  1216. case AUDIO_FORMAT_PCM_8_24_BIT:
  1217. size = sizeof(int32_t);
  1218. break;
  1219. case AUDIO_FORMAT_PCM_24_BIT_PACKED:
  1220. size = sizeof(uint8_t) * 3;
  1221. break;
  1222. case AUDIO_FORMAT_PCM_16_BIT:
  1223. size = sizeof(int16_t);
  1224. break;
  1225. case AUDIO_FORMAT_PCM_8_BIT:
  1226. size = sizeof(uint8_t);
  1227. break;
  1228. case AUDIO_FORMAT_PCM_FLOAT:
  1229. size = sizeof(float);
  1230. break;
  1231. case AUDIO_FORMAT_INVALID:
  1232. case AUDIO_FORMAT_DEFAULT:
  1233. case AUDIO_FORMAT_MP3:
  1234. case AUDIO_FORMAT_AMR_NB:
  1235. case AUDIO_FORMAT_AMR_WB:
  1236. case AUDIO_FORMAT_AAC:
  1237. case AUDIO_FORMAT_HE_AAC_V1:
  1238. case AUDIO_FORMAT_HE_AAC_V2:
  1239. case AUDIO_FORMAT_VORBIS:
  1240. case AUDIO_FORMAT_OPUS:
  1241. case AUDIO_FORMAT_AC3:
  1242. case AUDIO_FORMAT_E_AC3:
  1243. case AUDIO_FORMAT_MAIN_MASK:
  1244. case AUDIO_FORMAT_SUB_MASK:
  1245. case AUDIO_FORMAT_AAC_MAIN:
  1246. case AUDIO_FORMAT_AAC_LC:
  1247. case AUDIO_FORMAT_AAC_SSR:
  1248. case AUDIO_FORMAT_AAC_LTP:
  1249. case AUDIO_FORMAT_AAC_HE_V1:
  1250. case AUDIO_FORMAT_AAC_SCALABLE:
  1251. case AUDIO_FORMAT_AAC_ERLC:
  1252. case AUDIO_FORMAT_AAC_LD:
  1253. case AUDIO_FORMAT_AAC_HE_V2:
  1254. case AUDIO_FORMAT_AAC_ELD:
  1255. default:
  1256. break;
  1257. }
  1258. return size;
  1259. }
  1260. /* converts device address to string sent to audio HAL via set_parameters */
  1261. #if 0 /* never used error */
  1262. static char *audio_device_address_to_parameter(audio_devices_t device, const char *address)
  1263. {
  1264. const size_t kSize = AUDIO_DEVICE_MAX_ADDRESS_LEN + sizeof("a2dp_sink_address=");
  1265. char param[kSize];
  1266. if (device & AUDIO_DEVICE_OUT_ALL_A2DP)
  1267. snprintf(param, kSize, "%s=%s", "a2dp_sink_address", address);
  1268. else if (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
  1269. snprintf(param, kSize, "%s=%s", "mix", address);
  1270. else
  1271. snprintf(param, kSize, "%s", address);
  1272. return strdup(param);
  1273. }
  1274. #endif
  1275. __END_DECLS
  1276. #endif // ANDROID_AUDIO_CORE_H