推荐阅读
Android10以上系统Audio音频遇到播放视频无声时的分析方法
干货|Android APP应用工程师转Framework工程师(仅此一篇够了)
定制版(绕过检测安全手机)
Android audio设备的定义
1.C++中audio设备的定义
(1).audio设备的定义在Android Froyo-2.2.3及之前是位于
/frameworks/base/include/media/AudioSystem.h
(2).audio设备的定义在Android ICS-4.0.3及之前是位于
/hardware/libhardware_legacy/include/hardware_legacy/AudioSystemLegacy.h
(3).audio设备的定义在Android JellyBean-4.2及之后是位于
/system/core/include/system/audio.h
(4).audio设备的定义在Android Marshmallow-6.0.0_r1及之后是位于
/system/media/audio/include/system/audio.h
(5).audio设备的定义在Android Oreo-8.0.0_r4及之后是位于
/system/media/audio/include/system/audio-base.h
/system/media/audio/include/system/audio-base-utils.h
http://aospxref.com/android-11.0.0_r21/xref/system/media/audio/include/system/audio-base.h
enum {
324 AUDIO_DEVICE_NONE = 0x0u,
325 AUDIO_DEVICE_BIT_IN = 0x80000000u,
326 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000u,
327
328 AUDIO_DEVICE_OUT_EARPIECE = 0x1u, //听筒
329 AUDIO_DEVICE_OUT_SPEAKER = 0x2u, //扬声器
330 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4u, //线控耳机,可以通过耳机控制远端播放、暂停、音量调节等功能的耳机
331 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8u, //普通耳机,只能听,不能操控播放
332 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10u, //单声道蓝牙耳机,十进制16
333 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20u, //车载免提蓝牙设备,十进制32
334 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40u, //立体声蓝牙耳机,十进制64
335 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80u, //十进制128
336 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100u, //十进制256
337 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200u, //十进制512
338 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400u, //十进制1024
339 AUDIO_DEVICE_OUT_HDMI = 0x400u, // OUT_AUX_DIGITAL
340 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800u,
341 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000u,
342 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000u,
343 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000u,
344 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000u,
345 AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000u,
346 AUDIO_DEVICE_OUT_LINE = 0x20000u,
347 AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000u,
348 AUDIO_DEVICE_OUT_SPDIF = 0x80000u,
349 AUDIO_DEVICE_OUT_FM = 0x100000u,
350 AUDIO_DEVICE_OUT_AUX_LINE = 0x200000u,
351 AUDIO_DEVICE_OUT_SPEAKER_SAFE = 0x400000u,
352 AUDIO_DEVICE_OUT_IP = 0x800000u,
353 AUDIO_DEVICE_OUT_BUS = 0x1000000u,
354 AUDIO_DEVICE_OUT_PROXY = 0x2000000u,
355 AUDIO_DEVICE_OUT_USB_HEADSET = 0x4000000u,
356 AUDIO_DEVICE_OUT_HEARING_AID = 0x8000000u,
357 AUDIO_DEVICE_OUT_ECHO_CANCELLER = 0x10000000u,
358 AUDIO_DEVICE_OUT_DEFAULT = 0x40000000u, // BIT_DEFAULT
359
360 AUDIO_DEVICE_IN_COMMUNICATION = 0x80000001u, // BIT_IN | 0x1
361 AUDIO_DEVICE_IN_AMBIENT = 0x80000002u, // BIT_IN | 0x2
362 AUDIO_DEVICE_IN_BUILTIN_MIC = 0x80000004u, // BIT_IN | 0x4
363 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000008u, // BIT_IN | 0x8
364 AUDIO_DEVICE_IN_WIRED_HEADSET = 0x80000010u, // BIT_IN | 0x10
365 AUDIO_DEVICE_IN_AUX_DIGITAL = 0x80000020u, // BIT_IN | 0x20
366 AUDIO_DEVICE_IN_HDMI = 0x80000020u, // IN_AUX_DIGITAL
367 AUDIO_DEVICE_IN_VOICE_CALL = 0x80000040u, // BIT_IN | 0x40
368 AUDIO_DEVICE_IN_TELEPHONY_RX = 0x80000040u, // IN_VOICE_CALL
369 AUDIO_DEVICE_IN_BACK_MIC = 0x80000080u, // BIT_IN | 0x80
370 AUDIO_DEVICE_IN_REMOTE_SUBMIX = 0x80000100u, // BIT_IN | 0x100
371 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = 0x80000200u, // BIT_IN | 0x200
372 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = 0x80000400u, // BIT_IN | 0x400
373 AUDIO_DEVICE_IN_USB_ACCESSORY = 0x80000800u, // BIT_IN | 0x800
374 AUDIO_DEVICE_IN_USB_DEVICE = 0x80001000u, // BIT_IN | 0x1000
375 AUDIO_DEVICE_IN_FM_TUNER = 0x80002000u, // BIT_IN | 0x2000
376 AUDIO_DEVICE_IN_TV_TUNER = 0x80004000u, // BIT_IN | 0x4000
377 AUDIO_DEVICE_IN_LINE = 0x80008000u, // BIT_IN | 0x8000
378 AUDIO_DEVICE_IN_SPDIF = 0x80010000u, // BIT_IN | 0x10000
379 AUDIO_DEVICE_IN_BLUETOOTH_A2DP = 0x80020000u, // BIT_IN | 0x20000
380 AUDIO_DEVICE_IN_LOOPBACK = 0x80040000u, // BIT_IN | 0x40000
381 AUDIO_DEVICE_IN_IP = 0x80080000u, // BIT_IN | 0x80000
382 AUDIO_DEVICE_IN_BUS = 0x80100000u, // BIT_IN | 0x100000
383 AUDIO_DEVICE_IN_PROXY = 0x81000000u, // BIT_IN | 0x1000000
384 AUDIO_DEVICE_IN_USB_HEADSET = 0x82000000u, // BIT_IN | 0x2000000
385 AUDIO_DEVICE_IN_BLUETOOTH_BLE = 0x84000000u, // BIT_IN | 0x4000000
386 AUDIO_DEVICE_IN_HDMI_ARC = 0x88000000u, // BIT_IN | 0x8000000
387 AUDIO_DEVICE_IN_ECHO_REFERENCE = 0x90000000u, // BIT_IN | 0x10000000
388 AUDIO_DEVICE_IN_DEFAULT = 0xC0000000u, // BIT_IN | BIT_DEFAULT
389 };
(6).audio设备的定义在Android 12.0.0_r3及之后是位于
/system/media/audio/include/system/audio-hal-enums.h
/system/media/audio/include/system/audio-base-utils.h
http://aospxref.com/android-12.0.0_r3/xref/system/media/audio/include/system/
2.Java中aduio设备的定义
audio设备的定义
/frameworks/base/media/java/android/media/AudioManager.java
/frameworks/base/media/java/android/media/AudioSystem.java
3.Android中实现系统声音录制(内置声源的录制方案)
Android中可以通过使用MediaRecorder.AudioSource.REMOTE_SUBMIX来实现系统声音的录制,这个属性只有系统应用能够使用;而且这个属性会截掉耳机和扬声器的声音,听不到Android设备中播放音乐或者视频时的声音;需要通过修改Android系统源码来解决!