调试音频Audio之Tee sink部分

背景:

整个音频流程中,首先是各个app的AudioTrack的数据,传入AudioFlinger,由AudioFlinger进行了混音后,再送入Hal,kernel等。
在这里插入图片描述

但是对于用户来说声音最后是否正常,异常的判断就只能靠听到输出的喇叭声音,上面有好几个流程阶段,没办法准确定位到声音问题是发送在哪个阶段,所以为了调试音频数据方便,google官方就在AudioFlinger加入了Tee Sink相关dump。
具体的使用可以看官方的文档,非常详细:
https://source.android.google.cn/docs/core/audio/debugging
Audio debugging

This article describes some tips and tricks for debugging Android audio.
Tee sink

The “tee sink” is an AudioFlinger debugging feature, available in custom builds only, for retaining a short fragment of recent audio for later analysis. This permits comparison between what was actually played or recorded vs. what was expected.

For privacy the tee sink is disabled by default, at both compile-time and run-time. To use the tee sink, you will need to enable it by re-compiling, and also by setting a property. Be sure to disable this feature after you are done debugging; the tee sink should not be left enabled in production builds.

The instructions in this section are for Android 7.x and higher. For Android 5.x and 6.x, replace /data/misc/audioserver with /data/misc/media. Additionally, you must use a userdebug or eng build. If you use a userdebug build, then disable verity with:

adb root && adb disable-verity && adb reboot
翻译主要部分:上面表达只能在debug机器使用tee sink,正常手机是不可以的

Compile-time setup
如何开启tee sink,步骤如下所示,主要就是#define TEE_SINK.

cd frameworks/av/services/audioflinger
Edit Configuration.h.
Uncomment #define TEE_SINK.
Re-build libaudioflinger.so.
adb root
adb remount
Push or sync the new libaudioflinger.so to the device's /system/lib.

Run-time setup
adb shell getprop | grep ro.debuggable
Confirm that the output is: [ro.debuggable]: [1]
adb shell
ls -ld /data/misc/audioserver

Confirm that the output is:

drwx------ media media … media

If the directory does not exist, create it as follows:

mkdir /data/misc/audioserver
chown media:media /data/misc/audioserver

echo af.tee=# > /data/local.prop
Where the af.tee value is a number described below.
chmod 644 /data/local.prop
reboot

Values for af.tee property

The value of af.tee is a number between 0 and 7, expressing the sum of several bits, one per feature. See the code at AudioFlinger::AudioFlinger() in AudioFlinger.cpp for an explanation of each bit, but briefly:

1 = input
2 = FastMixer output
4 = per-track AudioRecord and AudioTrack

There is no bit for deep buffer or normal mixer yet, but you can get similar results using “4.”

**上面就是介绍了两个部分:
1.确定是否有 /data/misc/audioserver目录,这个目录来获取相关AudioFlinger里面的音频输出目录 2.确定是否有 af.tee property,prop值主要有1,2,4,具体值含义可以frameworks/av/services/audioflinger/NBAIO_Tee.h查看
**
在这里插入图片描述
上面都配置确定好了以后,既可以启动相关的dump目录来获取数据,主要的命令就是
adb shell dumpsys media.audio_flinger,执行完成后既可以去 /data/misc/audioserver/目录获取相关的wav文件

Test and acquire data

Run your audio test.
adb shell dumpsys media.audio_flinger
Look for a line in dumpsys output such as this:
tee copied to /data/misc/audioserver/20131010101147_2.wav
This is a PCM .wav file.
Then adb pull any /data/misc/audioserver/*.wav files of interest; note that track-specific dump filenames do not appear in the dumpsys output, but are still saved to /data/misc/audioserver upon track closure.
Review the dump files for privacy concerns before sharing with others.

各个wav文件的含义可以去这个文件frameworks/av/services/audioflinger/NBAIO_Tee.cpp查看

在这里插入图片描述

Suggestions

Try these ideas for more useful results:

Disable touch sounds and key clicks to reduce interruptions in test output.
Maximize all volumes.
Disable apps that make sound or record from microphone, if they are not of interest to your test.
Track-specific dumps are only saved when the track is closed; you may need to force close an app in order to dump its track-specific data
Do the dumpsys immediately after test; there is a limited amount of recording space available.
To make sure you don't lose your dump files, upload them to your host periodically. Only a limited number of dump files are preserved; older dumps are removed after that limit is reached.

Restore

As noted above, the tee sink feature should not be left enabled. Restore your build and device as follows:

Revert the source code changes to Configuration.h.
Re-build libaudioflinger.so.
Push or sync the restored libaudioflinger.so to the device's /system/lib.
adb shell
rm /data/local.prop
rm /data/misc/audioserver/*.wav
reboot

更多framework实战干货,请关注下面“千里马学框架”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值