赞
踩
本文将介绍一些常用的音频调试方法,可以帮助发现和解决音频系统的问题,提高音频质量和性能。音频调试的方法有很多,不同的方法适用于不同的场景和目的。以及它们的优缺点和使用场景。这些方法都是基于命令行工具的,可以在adb shell中执行。这些工具可以让我们获取或修改音频系统的状态、设置、参数和功能,方便我们分析和诊断音频问题。
日志调试是一种通过查看系统或应用程序输出的日志信息来分析和诊断音频问题的方法。日志信息可以包含错误、警告、状态、事件等信息,反映了音频系统或应用程序的运行情况。日志调试的优点是简单易用,可以快速定位问题的来源和原因。日志调试的缺点是需要有足够的日志信息,而且日志信息可能不够详细或准确,需要结合其他信息进行分析。
这将输出设备上所有应用程序和服务的日志信息,可以根据需要查看或保存。也可以使用grep来过滤感兴趣的部分,比如:
adb logcat | grep Audio
这将只显示与Audio相关的日志信息。
也可以使用以下选项来控制日志输出的格式和级别:
adb logcat [options] [filterspecs]
其中[options]可以是以下之一:
-b <buffer>: 指定要显示或清除的缓冲区,可以是main, system, radio, events, crash等。
-c: 清除所有缓冲区。
-d: 将当前缓冲区转储到屏幕并退出。
-f <filename>: 将日志输出到指定文件中。
-g: 显示每个缓冲区的大小。
-n <count>: 设置循环缓冲区文件数。
-r <kbytes>: 设置每个缓冲区文件大小。
-s: 设置静默模式,只显示指定过滤器的日志。
-t <count>: 显示最近指定数量的日志行。
-v <format>: 设置输出格式,可以是brief, process, tag, thread, raw, time, threadtime, long等。
其中[filterspecs]可以是以下形式:
<tag>[:priority]
是日志标签,是日志级别,可以是以下之一:
V: Verbose
D: Debug
I: Info
W: Warn
E: Error
F: Fatal
S: Silent
如果想显示AudioService标签下级别为Error或更高的日志信息,可以输入以下命令:
adb logcat AudioService:E *:S
这将过滤掉其他标签和级别的日志信息。
命令行调试是一种通过执行一些特定的命令来获取或修改音频系统或应用程序的状态或设置的方法。命令行调试的优点是灵活强大,可以直接操作音频系统或应用程序的内部参数和功能。命令行调试的缺点是需要熟悉命令语法和参数,而且可能会影响音频系统或应用程序的正常运行。
要使用命令行调试,需要在adb shell中输入以下命令:
adb shell <command>
其中是想要执行的命令,可以是以下之一:
以下是一些命令行调试的示例:
dumpsys audio 是一个命令行工具,可以用来获取Android设备上的音频系统的状态信息,包括音频流的音量、音频策略、音频设备、音频焦点、音频策略等。这些信息可以帮助分析和诊断音频问题,比如音量异常、声音断续、声道不平衡等。
要使用dumpsys audio,需要在adb shell中输入以下命令:
adb shell dumpsys audio
这将输出一系列的信息,可以根据需要查看或保存。也可以使用grep来过滤感兴趣的部分,比如:
Audio event log: audio services lifecycle
07-14 13:44:45:720 AudioService()
Message handler (watch for unhandled messages):
Handler (com.android.server.audio.AudioService$AudioHandler) {6c25604} @ 13884091
Looper (AudioService, tid 92) {20c07ed}
(Total messages: 0, polling=true, quitting=false)
MediaFocusControl dump time: 下午5:35:33
Audio Focus stack entries (last is top of stack):
No external focus policy
Notify on duck: true
In ring or call: false
Audio event log: focus commands as seen by MediaFocusControl
Multi Audio Focus enabled :false
Stream volumes (device: index)
- STREAM_VOICE_CALL:
Muted: false
Muted Internally: false
Min: 1
Max: 5
streamVolume:3
Current: 40000000 (default): 3
Devices: hdmi
- STREAM_SYSTEM:
Muted: false
Muted Internally: false
Min: 0
Max: 7
streamVolume:5
Current: 40000000 (default): 5
Devices: hdmi
- STREAM_RING:
Muted: false
Muted Internally: false
Min: 0
Max: 7
streamVolume:5
Current: 40000000 (default): 5
Devices: speaker
- STREAM_MUSIC:
Muted: false
Muted Internally: false
Min: 0
Max: 15
streamVolume:5
Current: 4000000 (usb_headset): 3, 40000000 (default): 5
Devices: hdmi
- STREAM_ALARM:
Muted: false
Muted Internally: false
Min: 1
Max: 7
streamVolume:6
Current: 40000000 (default): 6
Devices: speaker
- STREAM_NOTIFICATION:
Muted: false
Muted Internally: false
Min: 0
Max: 7
streamVolume:5
Current: 40000000 (default): 5
Devices: hdmi
- STREAM_BLUETOOTH_SCO:
Muted: false
Muted Internally: false
Min: 0
Max: 15
streamVolume:7
Current: 40000000 (default): 7
Devices: hdmi
- STREAM_SYSTEM_ENFORCED:
Muted: false
Muted Internally: false
Min: 0
Max: 7
streamVolume:5
Current: 40000000 (default): 5
Devices: hdmi
- STREAM_DTMF:
Muted: false
Muted Internally: false
Min: 0
Max: 15
streamVolume:5
Current: 4000000 (usb_headset): 3, 40000000 (default): 5
Devices: hdmi
- STREAM_TTS:
Muted: false
Muted Internally: false
Min: 0
Max: 15
streamVolume:5
Current: 4000000 (usb_headset): 3, 40000000 (default): 5
Devices: speaker
- STREAM_ACCESSIBILITY:
Muted: false
Muted Internally: false
Min: 1
Max: 15
streamVolume:6
Current: 4000000 (usb_headset): 4, 40000000 (default): 6
Devices: hdmi
- STREAM_ASSISTANT:
Muted: false
Muted Internally: false
Min: 0
Max: 15
streamVolume:5
Current: 4000000 (usb_headset): 3, 40000000 (default): 5
Devices: hdmi
- mute affected streams = 0x6f
Volume Groups (device: index)
- VOLUME GROUP AUDIO_STREAM_ACCESSIBILITY:
Min: 1
Max: 15
Current: 40000000 (default): 6
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_ALARM:
Min: 1
Max: 7
Current: 40000000 (default): 6
Devices: speaker
- VOLUME GROUP AUDIO_STREAM_DTMF:
Min: 0
Max: 15
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_ENFORCED_AUDIBLE:
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_MUSIC:
Min: 0
Max: 15
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_NOTIFICATION:
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_REROUTING:
Min: 0
Max: 15
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_RING:
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: speaker
- VOLUME GROUP AUDIO_STREAM_SYSTEM:
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_VOICE_CALL:
Min: 1
Max: 5
Current: 40000000 (default): 3
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_ASSISTANT:
Min: 0
Max: 15
Current: 40000000 (default): 5
Devices: hdmi
- VOLUME GROUP AUDIO_STREAM_CALL_ASSISTANT:
Min: 0
Max: 15
Current: 40000000 (default): 5
Devices: hdmi
Ringer mode:
- mode (internal) = NORMAL
- mode (external) = NORMAL
- zen mode:ZEN_MODE_OFF
- ringer mode affected streams = 0xa6 (STREAM_SYSTEM,STREAM_RING,STREAM_NOTIFICATION,STREAM_SYSTEM_ENFORCED)
- ringer mode muted streams = 0x0
- delegate = ZenModeHelper
Audio routes:
mMainType=0x8
mBluetoothName=null
Other state:
mVolumeController=VolumeController(android.os.BinderProxy@7d7c622,mVisible=false)
mSafeMediaVolumeState=SAFE_MEDIA_VOLUME_ACTIVE
mSafeMediaVolumeIndex=100
mSafeUsbMediaVolumeIndex=30
mSafeUsbMediaVolumeDbfs=-37.0
sIndependentA11yVolume=false
mPendingVolumeCommand=null
mMusicActiveMs=0
mMcc=0
mCameraSoundForced=false
mHasVibrator=false
mVolumePolicy=VolumePolicy[volumeDownToEnterSilent=false,volumeUpToExitSilent=false,doNotDisturbWhenSilent=false,vibrateToSilentDebounce=400]
mAvrcpAbsVolSupported=false
mIsSingleVolume=false
mUseFixedVolume=false
mFixedVolumeDevices=0x1000,0x800,0x200000,0x40000,0x80000
mExtVolumeController=null
mHdmiCecSink=false
mHdmiAudioSystemClient=null
mHdmiPlaybackClient=null
mHdmiTvClient=null
mHdmiSystemAudioSupported=false
mHdmiCecVolumeControlEnabled=false
mIsCallScreeningModeSupported=false
mic mute FromSwitch=false FromRestrictions=false FromApi=false from system=false
Audio policies:
Audio event log: dynamic policy events (logged when command received by AudioService)
PlaybackActivityMonitor dump time: 下午5:35:33
playback listeners:
(S)com.android.server.audio.PlaybackActivityMonitor$PlayMonitorClient@589e8b3
players:
AudioPlaybackConfiguration piid:15 type:android.media.SoundPool u/pid:1000/587 state:idle attr:AudioAttributes: usage=USAGE_ASSISTANCE_SONIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x800 tags= bundle=null
AudioPlaybackConfiguration piid:23 type:android.media.SoundPool u/pid:10117/735 state:idle attr:AudioAttributes: usage=USAGE_ASSISTANCE_SONIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x800 tags= bundle=null
ducked players piids:
muted player piids:
banned uids:
Audio event log: playback activity as reported through PlayerBase
07-14 13:44:46:868 new player piid:15 uid/pid:1000/587 type:android.media.SoundPool attr:AudioAttributes: usage=USAGE_ASSISTANCE_SONIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x800 tags= bundle=null
07-14 13:44:48:662 new player piid:23 uid/pid:10117/735 type:android.media.SoundPool attr:AudioAttributes: usage=USAGE_ASSISTANCE_SONIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x800 tags= bundle=null
allowed capture policies:
RecordActivityMonitor dump time: 下午5:35:33
Audio event log: recording activity received by AudioService
AudioDeviceBroker:
Message handler (watch for unhandled messages):
Handler (com.android.server.audio.AudioDeviceBroker$BrokerHandler) {e10ce70} @ 13884101
Looper (AudioDeviceBroker, tid 93) {6ae35e9}
(Total messages: 0, polling=true, quitting=false)
Preferred devices for strategy:
Connected devices:
[DeviceInfo: type:0x400 (hdmi) name: addr: codec: 0]
APM Connected device (A2DP sink only):
mForcedUseForComm: FORCE_NONE
mForcedUseForCommExt: FORCE_NONE
mModeOwnerPid: 0
Speakerphone clients:
mBluetoothHeadset: null
mBluetoothHeadsetDevice: null
mScoAudioState: SCO_STATE_INACTIVE
mScoAudioMode: SCO_MODE_VIRTUAL_CALL
Sco clients:
mHearingAid: null
mA2dp: null
mAvrcpAbsVolSupported: false
SoundEffects:
Message handler (watch for unhandled messages):
Handler (com.android.server.audio.SoundEffectsHelper$SfxHandler) {7d0226e} @ 13884101
Looper (AS.SfxWorker, tid 91) {d305d0f}
(Total messages: 0, polling=true, quitting=false)
Default attenuation (dB): -6
Audio event log: Sound Effects Loading
07-14 13:44:46:867 effects loading started
07-14 13:44:47:900 effect Effect_Tick.ogg loaded
07-14 13:44:47:918 effect KeypressStandard.ogg loaded
07-14 13:44:47:986 effect KeypressSpacebar.ogg loaded
07-14 13:44:48:040 effect KeypressDelete.ogg loaded
07-14 13:44:48:078 effect KeypressReturn.ogg loaded
07-14 13:44:48:138 effect KeypressInvalid.ogg loaded
07-14 13:44:48:138 effects loading completed
Event logs:
Audio event log: phone state (logged after successful call to AudioSystem.setPhoneState(int, int))
Audio event log: wired/A2DP/hearing aid device connection
07-14 13:44:50:552 setWiredDeviceConnectionState( type:400 state:DEVICE_STATE_AVAILABLE addr: name:) from android
Audio event log: force use (logged before setForceUse() is executed)
07-14 13:44:45:739 setForceUse(FOR_SYSTEM, FORCE_NONE) due to AudioService ctor
07-14 13:44:45:746 setForceUse(FOR_ENCODED_SURROUND, FORCE_NONE) due to readPersistedSettings
07-14 13:44:45:747 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
07-14 13:44:45:814 setForceUse(FOR_VIBRATE_RINGING, FORCE_NONE) due to muteRingerModeStreams() from u/pid:1000/587
07-14 13:44:46:855 setForceUse(FOR_COMMUNICATION, FORCE_NONE) due to resetBluetoothSco
07-14 13:44:46:859 setForceUse(FOR_RECORD, FORCE_NONE) due to resetBluetoothSco
07-14 13:44:46:868 setForceUse(FOR_VIBRATE_RINGING, FORCE_NONE) due to muteRingerModeStreams() from u/pid:1000/587
07-14 13:44:49:856 setForceUse(FOR_COMMUNICATION, FORCE_NONE) due to resetBluetoothSco
07-14 13:44:49:857 setForceUse(FOR_VIBRATE_RINGING, FORCE_NONE) due to muteRingerModeStreams() from u/pid:1000/587
07-14 13:44:49:859 setForceUse(FOR_RECORD, FORCE_NONE) due to resetBluetoothSco
07-14 13:44:50:069 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
07-14 13:44:50:069 setForceUse(FOR_ENCODED_SURROUND, FORCE_NONE) due to readPersistedSettings
07-14 13:44:50:091 setForceUse(FOR_VIBRATE_RINGING, FORCE_NONE) due to muteRingerModeStreams() from u/pid:1000/587
07-14 13:44:50:216 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
07-14 13:44:50:225 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
07-14 13:44:50:562 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
07-14 13:44:50:721 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
07-14 13:44:50:723 setForceUse(FOR_DOCK, FORCE_ANALOG_DOCK) due to readDockAudioSettings
Audio event log: volume changes (logged when command received by AudioService)
Supported System Usages:
USAGE_CALL_ASSISTANT
这将只显示音频流的音量信息。
从输出结果中,我们可以看到一些有用的信息,例如:
通过dumpsys audio,我们可以快速地了解当前系统的音频状态和配置,方便我们定位和解决音频问题。
除了这些信息之外,dumpsys audio还可以显示以下内容:
service call audio 是一个命令行工具,可以用来调用Android设备上的音频服务的接口方法,比如设置音量、模式、焦点、设备等。这些方法定义在framework/base/media/java/android/media/IAudioService.aidl文件中,可以查看该文件来了解每个方法的参数和返回值。
编号 | 名称 | 范围 | 默认值 | 功能 |
---|---|---|---|---|
0 | STREAM_VOICE_CALL | 1~11 | 8 | 通话 |
1 | STREAM_SYSTEM | 0~15 | 10 | 铃声 |
2 | STREAM_RING | 0~15 | 10 | 铃声 |
3 | STREAM_MUSIC | 0~150 | 100 | 媒体 |
4 | STREAM_ALARM | 1~15 | 12 | 闹钟 |
5 | STREAM_NOTIFICATION | 0~15 | 10 | 闹钟 |
6 | STREAM_BLUETOOTH_SCO | 1~15 | 7 | 通话 |
7 | STREAM_SYSTEM_ENFORCED | 0~7 | 7 | 铃声 |
8 | STREAM_DTMF | 0~15 | 10 | 铃声 |
9 | STREAM_TTS | 0~15 | 10 | 媒体 |
10 | STREAM_ACCESSIBILITY | 0~15 | 10 | 媒体 |
11 | STREAM_ASSISTANT | 0~15 | 10 | 语音助手 |
adjustStreamVolume()方法所需要的音量操作<类型>
参数,可以在AudioManager.java中查看。整理如下:
值 | 名称 | 功能 |
---|---|---|
1 | ADJUST_RAISE | 增加音量 |
-1 | ADJUST_LOWER | 降低音量 |
0 | ADJUST_SAME | 显示音量,但不设置 |
-100 | ADJUST_MUTE | 静音 |
100 | ADJUST_UNMUTE | 取消静音 |
101 | ADJUST_TOGGLE_MUTE | 切换静音状态 |
要使用service call audio,需要在adb shell中输入以下命令:
adb shell service call audio <CODE> [i32 <INT>] ...
其中是<CODE>
方法的编号,从1开始,按照IAudioService.aidl文件中的顺序排列。[i32 ]是方法的参数,如果有多个参数,需要用空格分隔。参数的类型必须是整数,如果是其他类型,需要进行转换。例如,如果是字符串类型,需要用十六进制表示每个字符的ASCII码,并在前面加上0x。如果是布尔类型,需要用0或1表示。
以下是一些service call audio的示例:
以下是调用这些方法的示例:
rk3568_r:/data # service call audio 16 i32 1
adb shell service call audio 17 i32 <streamType>
# 结果表示返回了一个Parcel对象,其中包含了一个int值
Result: Parcel(00000000 00000005 '........')
adb shell service call audio 18 i32 <streamType>
将 <streamType> 替换为相应的音频流类型编号。
通过service call audio,我们可以直接调用音频服务中的方法,实现一些高级或者隐藏的功能,方便我们测试和验证音频特性。
提供的内容是IAudioService.aidl文件的内容,其中定义了音频服务的接口方法。可以根据该文件来选择想要调用的方法和参数。
除了setStreamVolume方法之外,IAudioService.aidl文件还定义了以下一些与音频相关的方法:
…等等 自己去看aidl文件。
settings是一种通过命令行来获取或修改Android设备上的系统或安全设置的工具。这些设置存储在SQLite数据库中(后面的版本好像是存到data/system/users/0/settings_*.xml里),分为三种类型:system, secure 和 global。每种类型有不同的访问权限和作用域。
要使用settings,需要在adb shell中输入以下命令:
255|rk3568_r:/data # settings
Settings provider (settings) commands:
help
Print this help text.
get [--user <USER_ID> | current] NAMESPACE KEY
Retrieve the current value of KEY.
put [--user <USER_ID> | current] NAMESPACE KEY VALUE [TAG] [default]
Change the contents of KEY to VALUE.
TAG to associate with the setting.
{default} to set as the default, case-insensitive only for global/secure namespace
delete [--user <USER_ID> | current] NAMESPACE KEY
Delete the entry for KEY.
reset [--user <USER_ID> | current] NAMESPACE {PACKAGE_NAME | RESET_MODE}
Reset the global/secure table for a package with mode.
RESET_MODE is one of {untrusted_defaults, untrusted_clear, trusted_defaults}, case-insensitive
list [--user <USER_ID> | current] NAMESPACE
Print all defined keys.
NAMESPACE is one of {system, secure, global}, case-insensitive
其中[NAMESPACE]是设置的类型,可以是system, secure 或 global。是设置的名称。是设置的值。[get|put|delete|list]是操作类型,分别表示获取、修改、删除或列出设置。
255|rk3568_r:/data # settings list system
accelerometer_rotation=0
alarm_alert=content://media/internal/audio/media/136?title=Oxygen&canonical=1
alarm_alert_set=1
dim_screen=1
dtmf_tone=1
dtmf_tone_type=0
end_button_behavior=2
haptic_feedback_enabled=1
hearing_aid=0
hide_rotation_lock_toggle_for_accessibility=0
lockscreen_sounds_enabled=1
mode_ringer_streams_affected=166
mute_streams_affected=111
notification_light_pulse=1
notification_sound=content://media/internal/audio/media/153?title=Pixie%20Dust&canonical=1
notification_sound_set=1
pointer_speed=0
radio.data.stall.recovery.action=0
ringtone=content://media/internal/audio/media/41?title=Flutey%20Phone&canonical=1
ringtone_set=1
screen_brightness=120
screen_brightness_float=0.46850395
screen_brightness_for_vr=86
screen_brightness_mode=0
screen_off_timeout=2147483647
screenshot_button_show=1
sound_effects_enabled=1
tty_mode=0
user_rotation=0
vibrate_when_ringing=0
volume_alarm=6
volume_bluetooth_sco=7
volume_music=5
volume_music_usb_headset=3
volume_notification=5
volume_ring=5
volume_system=7
volume_voice=4
rk3568_r:/data # settings put system volume_system 15
rk3568_r:/data # settings get system volume_system
15
提供的内容是一些settings的调试示例,其中包含了以下命令:
settings的调试方法可以帮助了解和修改设备上的一些重要的设置,比如音量、亮度、铃声等。
除了这些命令之外,settings还可以用来获取或修改以下一些与音频相关的设置:
frameworks$ vi base/media/java/android/media/IAudioService.aidl
这个文件定义了音频服务接口,用于描述音频服务接口的方法和数据类型。它允许客户端和服务器之间进行通信,允许其他应用通过 AIDL 调用音频服务的方法。
frameworks$ vi base/services/core/java/com/android/server/audio/AudioService.java
这个文件是 Android 系统中实际实现音频服务的类。它是音频服务的主要实现代码,负责处理音频的相关逻辑,如音量调整、音频路由、音频设备管理、音频焦点管理等。它是音频服务的核心部分,通过调用 AudioSystem.java 中定义的底层音频接口来实现功能。
frameworks$ vi base/media/java/android/media/AudioSystem.java
这个文件定义了系统级的音频接口,它提供了与底层音频系统交互的方法和常量。其中包括了音量调整、音频路由、音频设备管理等功能的实现。它提供了底层实现的API,供上层的Android应用和服务调用。
frameworks$ vi ./base/media/java/android/media/AudioManager.java
这个文件是 Android 系统中管理音频的类。它是一个高级API,为应用程序提供了访问和控制设备音频设置的方法。通过 AudioManager.java,应用程序可以获取当前音量、设置音量、请求音频焦点、注册音频事件监听器等。它作为一个接口层,调用 AudioService.java 的实现来提供音频管理功能给应用程序。
有啥问题 , 欢迎留言 ~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。