如何使用 DirectShow 从套接字/应用程序渲染字节数组?
我有一个申请。我将遇到一种情况,我将收到一大堆编码字节。我必须解码它们并渲染它。对于解码,我使用自定义解码器类。解码后,如何构造一个 DirectShow 图来接收来自解码器的输入数据?请就此提供一些指导/样本。
I have an application. I will have a situation, wherein I will receive a big array of encoded bytes. I have to decode them and render it. For decoding, I am using a custom decoder class. After the decode, how can I construct a DirectShow graph which will receive input data from the decoder? Please give some direction/samples on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 DirectShow SDK 中的 PushSource 示例。此示例向您展示如何创建可呈现的源过滤器。这一切都是为了正确设置过滤器的输出媒体类型,以便可以渲染图表的其余部分。该示例还向您展示了如何将媒体样本提供给媒体管道的其余部分。在你的情况下,你解码什么? PushSource 示例输出 RGB24 IIRC。
另外,听起来您在接收字节时在同一个过滤器中进行解码?通常,在 DirectShow 中,您将编写一个源过滤器,它能够从网络接收字节并以编码格式输出样本。然后,您可以将此过滤器连接到自定义解码器过滤器,然后该过滤器输出 RGB24 或 DirectShow 可以理解的某些原始媒体格式。类似地,对于音频,您可以输出 PCM。
编辑:
我使用了相同的方法(CSource、CSourceStream)。没错,DoBufferProcessingLoop 调用 FillBuffer。我的一般方法是使用生产者-消费者模式。网络读取线程用样本填充队列,并在重写的 DoBufferProcessingLoop 中检查队列是否有任何数据,如果有数据则调用 FillBuffer。您当然可以尝试其他方法,例如等待事件(帧可用性)。要查看我使用的方法,您可以在 http://sourceforge.net 下载示例 RTSP 源过滤器的源代码/projects/videoprocessing/ 看看是否适合您。我想说的最好的事情就是不断尝试并不断学习。
Have a look at the PushSource sample in the DirectShow SDK. This sample shows you how to create a source filter that can be rendered. It is all about setting the output media type of your filter correctly so that the rest of the graph can be rendered. The sample also shows you how to feed media samples to the rest of the media pipeline. In your case what do you decode to? The PushSource sample outputs RGB24 IIRC.
Also, it sounds like you're decoding in the same filter as your receiving the bytes in? Typically in DirectShow you would write a source filter that is able to receive bytes from the network and outputs samples in the encoded format. You would then connect this filter to a custom decoder filter, that then outputs either RGB24 or some raw media format that is understood by DirectShow. Similarly for audio, you could output say, PCM.
Edit:
I have used the same approach (CSource, CSourceStream). That is correct, the DoBufferProcessingLoop calls FillBuffer. My general approach has been to use the producer-consumer pattern. The networking-reading thread populates the queue with samples and in my overridden DoBufferProcessingLoop I check whether the queue has any data, calling FillBuffer if there is data. You can of course try other methods such as waiting on events (frame availibility). To see the approach I used you can download the source code of an example RTSP source filter at http://sourceforge.net/projects/videoprocessing/ and see if that suits you. Best thing I would say is to just try stuff and learn as you go along.