我可以使用异步转换编写 DirectShow 转换过滤器吗?
我有一个任务将第三方视频解码器库包装在直接显示转换过滤器中。
我相信这将是一个问题,因为当全帧准备就绪时,第 3 方库使用异步回调,即
// on main thread
lib->RegisterCallback(callback function)
lib->write(raw data bytes)
void callback(frame)
{
// here is your frame (on a worker thread)
}
当我查看纯虚拟 CTransformFilter.Transform 函数时,它期望转换是同步的。现在我可以对其进行设置,以便它阻止在回调中设置的事件,但是如果进入 Transform 函数的数据不足以生成完整的新帧,会发生什么情况?我会让这个函数陷入僵局。
我唯一的选择是返回库开发人员并要求同步解码器吗?
我刚刚查看了 CTransformFilter Receive 函数。这就是所谓的(重写的)变换函数。然后,它调用 m_pOutput->m_pInputPin->Receive(pOutSample) 来向前传递样本。我可以在回调中从工作线程调用此 Receive 函数,还是必须将所有内容保留在同一线程上?
谢谢
I have a task to wrap a 3rd party video decoder library in a direct show transform filter.
I believe this is going to be a problem as the 3rd party library uses an asynchronous callback when a full frame is ready i.e.
// on main thread
lib->RegisterCallback(callback function)
lib->write(raw data bytes)
void callback(frame)
{
// here is your frame (on a worker thread)
}
When I look at the pure virtual CTransformFilter.Transform function it expects the transform to be synchronous. Now I could set this up so it blocks on a event that is Set in the callback but what happens if the data coming in to the Transform function is not sufficient to generate a full new frame? I would deadlock the function.
Is my only option to go back to the library developer and ask for a synchronous decoder?
I've just been looking at the CTransformFilter Receive function. This is what calls the (overridden) Transform function. It then calls m_pOutput->m_pInputPin->Receive(pOutSample) to pass the sample onwards. Can I call this Receive function from the worker thread in the callback or do I have to keep everything on the same thread?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你仍然可以实现你想要的。请注意,过滤器不需要在同一线程上和/或在接收输入媒体样本的调用中输出媒体样本。然而,
CTransformFilter
是在考虑到这一假设的情况下进行的。因此,基本上您的直接选择是:
CTransformFilter
退一步,并使用其继承的祖先来实现从 [工作线程] 回调调用Transform
函数中 的输出媒体样本传递对于异步完成(如果内部库仍然为 1 个输入帧解码 1 个输出帧,则有意义)并赶上然后交付输出;您还必须在那里等待暂停请求并中止等待,以免阻止执行You can still achieve what you want. Note that a filter is not required to output a media sample on the same thread and/or within the call it receives an input media sample.
CTransformFilter
is however made with this assumption in mind.So basically your straightforward choices are:
CTransformFilter
and use its ancestor to inherit from to implement output media sample delivery from [a worker thread's] callback callTransform
function for asynchronous completion (makes sense if the inner library still decodes 1 output frame for 1 input frame) and catch up then delivering the output; you will also have to wait for pause requests there and abort your wait in order to not block the execution