你如何发布MTAudioProcessingTap? [英] How do you release an MTAudioProcessingTap?

查看:198
本文介绍了你如何发布MTAudioProcessingTap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MTAudioProcessingTap的头文件说它的初始化和准备回调将通过无准备和最终化回调来平衡。但是,在 Apple的示例中,这些回调永远不会被调用(我添加了记录到他们,所以我可以检查)。该头文件表示在取消分配对象时将调用它们。

The header file for MTAudioProcessingTap says that its initialization and prepare callbacks will be balanced by unprepare and finalize callbacks. However, in Apple's example, these callbacks never get called (I added logging to them to so I could check). The header file says they will be called when the object is deallocated.

在Apple的示例中,Tap被传递到audioMixInputParameters中的retain参数,该参数被传递到音频中混合,它不再可公开访问:

In Apple's example, the Tap is passed into a retain parameter in audioMixInputParameters, which are passed into the audio mix, where it is no longer publicly accessible:

MTAudioProcessingTapRef audioProcessingTap;
if (noErr == MTAudioProcessingTapCreate(kCFAllocatorDefault, &callbacks, kMTAudioProcessingTapCreationFlag_PreEffects, &audioProcessingTap))
{
    audioMixInputParameters.audioTapProcessor = audioProcessingTap;

    CFRelease(audioProcessingTap);

    audioMix.inputParameters = @[audioMixInputParameters];

    _audioMix = audioMix;
}

我希望AudioMix负责以自己的dealloc方法发布它,以及释放相关PlayerItem时发布的AudioMix。

I would expect AudioMix therefore to be responsible for releasing it in its own dealloc method, and for AudioMix to be released when the associated PlayerItem is released.

Apple的例子使用的AVPlayer只播放一个项目,所以也许它不需要释放任何东西直。但在我的情况下,我正在使用AVQueuePlayer,所以我不断传递新的AVPlayerItems。我认为它正在泄漏我为每个玩家项目创建的Taps(以及相关的音频单元),即使玩家物品被取消分配。

Apple's example uses an AVPlayer that only ever plays one item, so maybe it has no need to deallocate anything directly. But in my case, I'm using an AVQueuePlayer so I keep passing it new AVPlayerItems. I think it's leaking the Taps that I'm creating for each player item (along with associated audio units), even though the player items get deallocated.

什么是正确的方式当我完成相关的玩家项目时,要取消分配MTAudioProcessingTap并获得无准备和最终确定的回调?

What's the proper way to deallocate the MTAudioProcessingTap and get its unprepare and finalize callbacks to fire when I'm done with its associated player item?

更新:我发现它实际上仍然可以通过音频混合访问,但是像这样释放它不会触发无准备和最终的回调:

Update: I found that it actually is still accessible through the audio mix, but releasing it like this doesn't trigger the unprepare and finalize callbacks:

((AVMutableAudioMixInputParameters *)audioMix.inputParameters[0]).audioTapProcessor = nil;

这两者都不是:

MTAudioProcessingTapRef audioProcessingTap = ((AVMutableAudioMixInputParameters *)audioMix.inputParameters[0]).audioTapProcessor;
CFRelease(audioProcessingTap);


推荐答案

我遇到了同样的问题。为了使它工作,我不得不重置播放器项目的 audioMix ,即Apple的示例项目中的点击处理器( MYAudioTapProcessor )并手动释放 MTAudioProcessingTapRef

I had the same problem. To make it work, I had to reset the player item's audioMix, the tap processor (MYAudioTapProcessor in Apple's sample project) and manually release the MTAudioProcessingTapRef:

MTAudioProcessingTapRef tap = ((AVMutableAudioMixInputParameters *)_audioTapProcessor.audioMix.inputParameters[0]).audioTapProcessor;
_player.currentItem.audioMix = nil;
_audioTapProcessor = nil;
CFRelease(tap);

这会导致调用 finalize 回调。

编辑:好像 CFRelease 必填项,见评论。

Seems like the CFRelease is not required, see comments.

这篇关于你如何发布MTAudioProcessingTap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆