I have my own RTSP Source Filter solution which is still under development but working with H.264/MPEG-4 video streams at the moment. My problem is at initialization stage. If I open graphedit and add RTSP source, decoder and video renderer filters one by one and connect their pins, everything works fine (RTSP Source URL is hardcoded at the moment). But if I try to save the graph and re-open the graph from saved file, the graph crashes. I think the reason is at my RTSP Source Filter’s initialization part. Since my filter doesn’t know anything about the streams at the beginning, it passes invalid parameters to the decoder. So, my questions are:
- How should I exactly handle the initialization process?
- When (which function in the code) should I exactly connect to the source and start transmission? Filter class constructor? Output pin class constructor?
OnThreadCreate? - Do we need to get some information like video width/height from streams or do we just need to pass the streams to decoder? What is the proper way of doing this? (I think some video renderers use width/height information from
VIDEOINFOHEADERstructure.) -
How should we decide our buffer size? In
GetMediaTypemethod, I set the sample size from bitmap info header like:pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
How should I set the parameters like biWidth, biHeight, biSize, biSizeImage etc.? I believe I need to set them with some default values at the beginning and then change them after receiving the streams but how?
All questions indicates to the same problem. What should I exactly do at the initialization process of my RTSP Source Filter?
!UPDATE!
I just noticed that when I load a saved graph, disconnecting and re-connecting the pins between decoder and video renderer solves the problem. I tried it with different video renderers (microsoft’s and some other custom video renderers). They all react similar. Some of them doesn’t crash but runs video with incorrect size/aspect ratio. Apparently, what makes graph crash or causes weird results is not my source filter but some invalid information passed to the video renderer. Since this situation doesn’t happen with other RTSP Source Filters, I still believe I’m doing something wrong, there is something missing.
What may cause this problem? Do I need to send some media information when graph starts running?
P.S: Graph crashes only when I run the graph. Just loading graph doesn’t cause a crash.
I concur with Wimmel, I haven’t considered it a problem if a filter does not support being loaded from a saved graph. Also as Roman stated, there are two issues, the crash, which you need to debug, and the implementation questions.
In answer to some of your questions:
How should I exactly handle the initialization process?
One approach is to implement the IFileSourceFilter interface. This method is called by both GraphEdit, Windows Media Player just after the filter is loaded and allows you to do the RTSP DESCRIBE to obtain your media session description. For media types that require a running stream you can also PLAY the stream, extract the media parameters such as width and height, and then setup your graph correctly. H264 relies on information in the sequence and picture parameters sets which are usually in the SDP. The IFileSourceFilter::Load method will be called by the DS framework before GetMediaType which means that your decoder should be fed the correct parameters.
Do we need to get some information like video width/height from streams or do we just need to pass the streams to decoder? What is the proper way of doing this? (I think some video renderers use width/height information from VIDEOINFOHEADER structure.)
How should we decide our buffer size? In GetMediaType method, I set the sample size from bitmap info header like…
Depends on the decoder: some decoders just require you to stream the media and then setup everything correctly, others may require that the width and height, etc be correctly configured. If you use the approach outlined above, it shouldn’t matter.
You can download our open source RTSP source filter at sourceforge.
It is not a commercial grade RTSP source filter and handles a couple of (mostly audio) media types, but it shows various aspects that might help you write your own. IIRC I started adding H.264 support to it, and basic tests using the live555 RTSP server were ok, but I had some issue with timestamping the H.264 stream though…
Also, I recommend using GraphStudio for the purpose of testing your RTSP source filter: if you implement the IFileSourceFilter interface, it allows you to enter URLs. It is very similar to GraphEdit, but personally I prefer it.