ios - AudioToolbox ExtAudioFileSeek(_:_:) does not directly set the desired frame position
问题描述
I am working on an iOS MPEG-DASH player and I have an issue with seeking feature.
ExtAudioFileSeek(::) documentation said
Sets the file’s read position to the specified sample frame number. A subsequent call to the ExtAudioFileRead(::_:) function returns samples from precisely this location, even if it is located in the middle of a packet.
Unfortunately, the AudioToolbox.AudioFile_ReadProc
loop does not seek straight to the right frame and goes trough all file segments, requesting 16 and 27682 bytes packages.
It takes a lot of time (especially for long tracks) and force to download all intermediate segments (that should not be required)
This also cause the app to crash when long tracks with high sound quality are being played.
Here my log trace. I converted frame index to "mega" for more readability.
[PlayerEngine] - Trying to seek at 16.870537 %
[AudioSource] - Pausing AudioOutputUnit
[AudioSource] - AudioOutputUnit successfully stopped
[AudioOutputUnit] - Trying to seek at frame 31.006805M
[AudioOutputUnit] - Successfully sought at frame 31.006805M
[AudioInputUnit] - Audio frames have been flushed
[AudioInputUnit] - Seek to frame 31.006806M pending
[AudioConverter] - Converted frame buffer has been flush
[AudioSource] - Resuming AudioOutputUnit
[AudioSource] - AudioOutputUnit successfully resumed
[PlayerEngine] - Successfully sought at 16.870537 %
[AudioInputUnit] - Seeking to frame 31.006805M
[CoreAudioDecoder] - Trying to seek at frame 31.006805M
[CoreAudioDecoder] - Seek on frame 31.006806M done successfully
[CoreAudioDecoder] - AudioToolbox.AudioFile_ReadProc : inClientData, inPosition:1.315635M, requestCount:16
(...)
[CoreAudioDecoder] - AudioToolbox.AudioFile_ReadProc : inClientData, inPosition:1.331687M, requestCount:27682
Is it a bug on AudioToolBox or is there a way to fix it ?
Thanks a lot !
解决方案
凉爽的!
由于您提到读取回调,我假设您不仅使用ExtAudioFile
API,还使用AudioFile
API,例如ExtAudioFileWrapAudioFileID(AudioFileInitializeWithCallbacks(...))
压缩的音频格式并不总是在帧和文件偏移之间具有简单的映射,因此您看到的幼稚行为可能是由于这些 API 之一(AudioFile
?)可以理解的是不知道这种映射。
尝试在或包装的音频文件上设置kExtAudioFileProperty_PacketTable
属性。前者可能更有意义。我不知道整个数据包表信息是否从一开始就可供您使用,或者是否会随着时间的推移而显示给您,也不知道 API 将如何对您多次设置这些属性做出反应。ExtAudioFile
kAudioFilePropertyPacketTableInfo
祝你好运!
推荐阅读
- dataframe - 如何将列名和列数据类型都传递给 toDF() 函数
- powershell - 参数验证
- python - 为什么 multiprocessing.Process 与内部函数一起使用,但 multiprocessing.Pool 不使用?
- angular - 如何使用 Angular 在 Firebase 中使用 WHERE 函数?
- javascript - 将javascript变量保存到服务器中的文本文件
- html - 在导航栏中切换页面时文本更改
- c# - MethodBase.Invoke 与 Convert.ChangeType 对象结果
- java - java - 如何在Java中的对象模型类中创建字符串字段列表?
- c# - asp.net mvc 站点中的 ArrayPool 缓存和过期
- java - 返回数学表达式时从java中的递归方法返回值