Is it possible to use an http url as your source location of a Source Filter in DirectShow .Net?

做~自己de王妃 提交于 2020-01-15 08:41:26

问题


I'm using the DirectShow.Net Library to create a filter graph that streams video by using an http address and the WM Asf Writer. Then on the webpage I'm able to use the object element to render the video feed in a Windows Media Player object. So now I'm curious if it is possible to read from that http address with some type of FilterSource. I have seen that some people use the AsyncReader as an IBaseFilter, and then casting it as an IFileSourceFilter and calling the load method and passing it a url for their network. But I haven't been able to successfully do this with a url of "http://localhost:8080". I'm guessing this is because it's not an actual "file source". I have tried using a AMMediaType with a majorType of MediaType.URLStream and subType of MediaSubType.Asf in the IFileSourceFilter Load method, but still no luck. If someone could help me figure this out I would figuratively kiss them, seeing that I have been working on this for some time now. Please oh please help me.

In my code I'm creating the FilterGraph and CaptureGraph accordingly. Then creating an AsyncReader instance and casting it as an IBaseFilter. Next I cast it as an IFileSourceFilter and call the Load method passing it the "http://localhost:8080" url. Then add it to the FilterGraph. Then I create the video render filter and add it, but when I try to call the RenderStream method of the CaptureGraphBuilder2 object it throws an "Unspecified Error" exception. Here is what I have for code...

            var fGraph = new FilterGraph() as IFilterGraph2;
            var cGraph = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
            cGraph.SetFiltergraph(fGraph);

            var tmp = new AsyncReader() as IBaseFilter;

            //  This is where I tried to load it with a media type.
            //media = new AMMediaType { majorType = MediaType.URLStream, subType = MediaSubType.Asf };
            //((IFileSourceFilter)tmp).Load(_streamingURL, media);
            //DsUtils.FreeAMMediaType(media);

            ((IFileSourceFilter)tmp).Load(_streamingURL, null);

            hr = fGraph.AddFilter(tmp, "SourceFilter");
            DsError.ThrowExceptionForHR(hr);

            var vRender = new VideoRenderer() as IBaseFilter;
            var aRender = new AudioRender() as IBaseFilter;

            hr = fGraph.AddFilter(vRender, "vRenderer");
            DsError.ThrowExceptionForHR(hr);

            hr = cGraph.RenderStream(null, MediaType.Video, tmp, null, vRender); //  This is where it throws an "Unspecified Error".
            DsError.ThrowExceptionForHR(hr);

            hr = fGraph.AddFilter(aRender, "aRenderer");
            DsError.ThrowExceptionForHR(hr);

            hr = cGraph.RenderStream(null, MediaType.Audio, tmp, null, aRender);
            DsError.ThrowExceptionForHR(hr);

            var mcx = fGraph as IMediaControl;
            hr = mcx.Run();
            DsError.ThrowExceptionForHR(hr);  

So if you have any advice for me I would greatly appreciate it. Thanks again for all your help.


回答1:


After some more research I was able to find some information that helped me solve my issue. Here's the graph the adds a source filter with a http url as it's source and then renders the stream to a video renderer filter and an audio render filter.

            var fGraph = new FilterGraph() as IFilterGraph2;
            var cGraph = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
            cGraph.SetFiltergraph(fGraph);

            IBaseFilter sourceFilter = null;

            hr = fGraph.AddSourceFilter(@"http://localhost:8080/tempStreaming.asf", "SourceFilter", out sourceFilter);
            DsError.ThrowExceptionForHR(hr);

            var vRender = new VideoRenderer() as IBaseFilter;
            var aRender = new AudioRender() as IBaseFilter;

            hr = fGraph.AddFilter(vRender, "vRenderer");
            DsError.ThrowExceptionForHR(hr);

            hr = cGraph.RenderStream(null, MediaType.Video, sourceFilter, null, vRender);
            DsError.ThrowExceptionForHR(hr);

            hr = fGraph.AddFilter(aRender, "aRenderer");
            DsError.ThrowExceptionForHR(hr);

            hr = cGraph.RenderStream(null, MediaType.Audio, sourceFilter, null, aRender);
            DsError.ThrowExceptionForHR(hr);

            var mcx = fGraph as IMediaControl;
            hr = mcx.Run();
            DsError.ThrowExceptionForHR(hr);

The tmpStreaming.asf file is created using an WM Asf Writer filter set up with a network sink. In case you need an example of how to do this it's in the WindowsMediaLib .Net Framework samples as the AsfNet project. Hope this helps if you come across same issue.



来源:https://stackoverflow.com/questions/7476252/is-it-possible-to-use-an-http-url-as-your-source-location-of-a-source-filter-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!