DirectShow Developer Q & A

zhaozj2021-02-08  197

DirectShow Developer Q & A

What is IASYNCREADER? How to use it? What is CPULLPIN?

What is the difference between stopping, suspend, running these three status in DirectShow?

A typical graphic filter has several threads?

What is G_Templates to do? Why do I have to connect to it?

Why does the filter are unsuccessful?

How to play back the activity video stream or network video stream?

How to use DirectX Audio Plug-Ins in the program?

What is iasyncreader for and how can I use it? What is cpultpin?

Most streams in DirectShow use a requested push model. That is, you tell the upstream pin where it should start and stop, and it then delivers you that section of the stream in a sequence of samples delivered to your Receive method on its thread. This works fine for most playback scenarios, but there are some cases where it is not very efficient One such case is the AVI file format:. this is not really designed well for sequential playback, since the chunks you need are often in the wrong place. To Play THIS BACK Efficiently, You NEED To Be Able To Read More At Random in The File, Rather Than Just Parsing Chunks As The Arrive As You Would With MPEG for Example.

In order to extract the file reading parts of both the MPEG parser and the AVI parser into a common filter (so that for example it could be replaced by a URL filter) it was necessary to have an interface at this point that was efficient in both cases. This is the IAsyncReader interface. Using this interface, each sample is requested separately with a random access style. You can either have the requests fulfilled synchronously on your own thread (SyncRead) or queue them and collect the completed requests later (Request and Wait).

CPullPin provides the client code for this interface for a downstream pin, and really is designed to let the input pin look the same whether it uses IAsyncReader or the normal push-model IMemInputPin :: Receive. If you connect to an output pin that uses IMemInputPin :: Receive, the data will be sent to your Receive method. If you connect to an output pin that only supports IAsyncReader, then CPullPin provides the 'glue' that pulls data from the output pin and delivers it to your Receive method. It doesn 't really get any of the benefit of being able to read data from different positions in the stream. Accordingly you will not be surprised to learn that the mpeg parser uses CPullPin (in sync mode) whereas the AVI file parser uses the IAsyncReader interface in async mode, but using its own code to access discontiguous chunks independently.In sync mode, the async reader just reads the file. When you call IAsyncReader :: SyncReadAligned, it does an unbuffered ReadFile call and then returns. CPull Pin in this mode Just Has A Loop That Gets A Buffer, Calls The Sync-Read Method and The Calls The Sync-Read Method and The Calls The Sync - Receive Method To Get To your Pin.

In async mode you call Request to queue a request, which is passed to a worker thread within the async reader. At some point, you can then call WaitForNext to get a completed buffer back from the async reader. Win95 does not support overlapped i / O, AND hence i don't believed I / O in the Windows NT Case Either Even WHEN IS AVAILABLE.

CPullPin in async mode has a loop that queues a request and waits for a completed request, but always keeping one request queued. So in this case, the only difference between the two modes is that in async mode, the next request will be sent to the disk almost immediately, whereas in sync mode, the next request is not queued to the disk until your Receive method has completed (in most of the standard parsers, this is very quick) .So in a high bandwidth case where you need to queue the next request before completing the receive processing, you may want to consider async mode, but in other cases, you are ok in sync mode. If you want to receive data from many discontiguous parts of the file, you probably want to discard CPullPin entirely And Write Your Own Access Code, But for Most Streaming Cases, Sync Mode with cpultpin gives you what you want.

It's also worth noting that the DirectShow MPEG splitters use IAsyncReader methods to access parts of the file at pin-connection time: IMemInputPin would not provide data until the graph was running (see discussion below on live material)

What's The Difference Between Stopped, Paused and Running States in DirectShow?

In a DirectShow graph, there are three possible states: stopped, paused and running If a graph is stopped, filters hold a minimum set of resources and do not process data If the graph is running, filters hold a maximal set of resources and.. Data is processed and indeed.

If a graph is paused then data is processed but not rendered. Source filters will start (or continue) to push data into the graph and transform filters will process the data but the renderer will not draw or write the data. The transform filter will eventually block since its buffers are not being consumed by the renderer Thus a graph can be cued for rapid starting simply by leaving it in paused mode:. once some data arrives at the renderer, the rest of the graph will be blocked by the normal flow control mechanisms (GetBuffer or Receive will block) until the graph is run.Media types that can be rendered statically, such as video (where you can show a frozen frame) but not, for example, audio, are typically rendered in paused state. Repainting The Video Window Can Simply Be Achieved by Transitioning The Graph To Paused Mode And Back.

How Many THREADS Are The There in a Typical Filter GRAPH?

DirectShow filter graphs typically have one thread per stream segment - that is, one thread would be active on a source filter's output pin and would push data right through the transform filters and into the renderer The transform function and delivery downstream would normally occur on. this thread during the Receive call. A parser or other filter that has more than one output pin would typically have a new thread for each output pin (plus the source filter's thread on which it receives data). This can be done straightforwardly using a COutputQueue Class in Each Output Pin.

In Addition, There Will Typically Be a Filter Graph Manager Thread and the Application's Thread

What is g_templates and why won n't my application limited?

The DirectShow base class library strmbase.lib provides a COM class factory implementation to simplify the development of filters as COM objects This class factory uses the template implementation you provide:. Your filter code will supply the templates for objects in your DLL in the g_Templates array , with a count of entries in g_cTemplates If you are building a filter, you will need to supply this array and count.If, however, you are writing an application that uses the DirectShow base classes, you do not need to define this. - - You CAN set g_ctemplates to 0 and the g_templates will not be reference.

If your DLL is a COM dll that uses another class factory implementation (perhaps your dll is a ATL control) then you will be exporting DllGetClassFactory from your DLL. This is implemented in a number of places, including the ATL and MFC libraries as well as DirectShow's Library. Make Sure That The Correct Library IS Found First Otherwise Even if you define g_ctemplates you will not becomplate Any of your atl objects.

The Dll Registers Ok But The Wrong Module Is Registered for My Filters.

You need to make sure that your DLL starts at DllEntryPoint, defined in dllentry.cpp in the class library. Otherwise the class library's global variable g_hInst is not set to the correct module handle, and registration will go wrong.

How Can i Play Back MPEG STREAMS from Live Sources or the network?

You will need a source filter that introduces the mpeg data into the graph. You will probably also need an MPEG splitter (also called a parser) that works with live streams and you will also need a decompressor if you are using MPEG-2 (the MPEG FILTER Supplied with DirectShow Supports Only MPEG-1).

The DirectShow-supplied splitters for MPEG-1 and 2 do two tasks in addition to separating out the individual elementary streams:. They convert the embedded PTS times into DirectShow timestamps, and they create a media type including the sequence header Both of these involved searching around in the file at pin-connection time, which is clearly not possible for live sources.The best solution is to create a new splitter filter, based on the sample code in the DirectShow SDK (under mpegparse). Your source filter would supply data using the IMemInputPin transport rather than IAsyncReader (see the discussion of IAsyncReader above). The splitter filter would look for the first pts and first sequence header after any discontinuity, and would use these for the media type and as a base for timestamp conversion. A Default Media Type Would Be Needed At Connection Time, To BE Replaced by a Dynamical Deted Media Type When The First Sequence Header IS Detected.

How Can I Host DirectX Audio Plug-Ins in My Application?

The right way to do this, I believe, is to create a source and sink filter as part of your application and connect the plugin between them. When you call the source filter from your application, it delivers the data to the plugin (a DirectShow And The Processed Data Arrives At Your Sink Filter When Done, from Where it ing going to your application.

Construct the two filters as C objects by calling new (rather than registering them with class ids and calling CoCreateInstance) They still. That way, you can call public methods on the objects without needing to define a custom COM interface to get access to them. need to be COM objects of course (in particular, do not forget to initialise the refcount to 1 after creating them, and delete them by Release rather than delete) .The source filter is derived from CBaseFilter and has a single output pin derived from CBASEOUTPUTPIN. WHEN THE APP WANTS To Deliver Data, You Call GetdeliveryBuffer, Fill with Data, And The Output Pin.

The sink filter is also derived from CBaseFilter and has a single input pin based on CBaseInputPin. The data arrives at the Receive method of the input pin from where you can either call out to your app or wait for your app to collect it.

Note that the delivery of data from the plug-in to your sync filter is not necessarily tied to the delivery of data from your source into the plug-in. Most transforms (eg most of those written to the Sonic Foundry template) will do the transform synchronously: during your source filter's Deliver call, the data will be processed and delivered to the sink filter, but there is no guarantee that this is the case (or that, eg, the same size and count of buffers are used) A. simple approach used by some hosts is to only support 'synchronous' plug-ins: call Deliver with the data, then call the sink filter to pick up the processed data and if it has not arrived, complain that the plug-in is not supported. I do not like this idea because it is unnecessarily restrictive on design of transform filters (eg you could not do mpeg decode like that). A better idea is to have an async model where the sink filter calls back to your app When the data arrives.other things to worry about:

Negotiation of size and count of buffers used (separate on input to and output from transform) Instantiation of filter graph manager and building the three-filter graph Finding the right transform by enumeration using IFilterMapper2 from CLSID_FilterMapper2 Property pages using OleCreatePropertyFrame are modal, so you either mess about with separate threads for the property page or you have your own property frame to host the property pages. Storing the filter's property settings using IPersistStream and eg CreateStreamOnHGLOBAL. Timestamping the samples somehow in the source filter in case the transform uses this.

转载请注明原文地址:https://www.9cbs.com/read-2853.html

New Post(0)