Imediaeventex Reprint _graph

Source: Internet
Author: User
Tags case statement

How Event Notification Works

While a DirectShow application is running, events can occur within the filter graph. For example, a filter might encounter a streaming error. Filters alert the Filter Graph Manager by sending events, which consist of the event code and two event parameters. The event code indicates the type of event, and the event parameters supply additional information. The meaning of the parameters depends on the event code. For a complete list of event codes, the event Notification codes.

DirectShow an event occurs inside the filter graph while the application is running. For example, filter will encounter a stream error. The filter Graph Manager is alerted by an event consisting of an event code and two event parameters. The event code defines the type of the event, and the event arguments provide additional information. It means that the parameter depends on the event code.

Some events are handled silently by the Filter Graph Manager, without the application being. The other events are placed in a queue for the application. Depending on the application, there are various events, might need to handle. This article focuses on three events that are very common:

Some events are handled by the Filter Graph Manager and do not notify the application. Other events are placed in the application's queue. Some events must depend on the application for processing. This article focuses on three most versatile times:

· The Ec_complete event indicates that playback has completed normally.

· Ec_complete event flag Playback complete.

· The Ec_userabort event indicates that the user has interrupted playback. Video Renderers Send this event if the user closes the "video window."

· Ec_userabort Event flag user interrupts playback. If the user closes the video window, the video renderer sends this event.

· The Ec_errorabort event indicates that a error has caused playback to halt.

· The EC_ERRORABORT flag playback caused an error and stopped.

Using Event Notification

An application can instruct the "Filter Graph Manager to send a" Windows message to a designated window whenever a new event Occurs. This is enables the application to respond inside the window ' s message loop. The define the message that would be sent to the application window. Applications can use message numbers in the range from Wm_app through 0xBFFF as private messages:

Once a new event arises, the application can command the Filter Graph Manager to send a Windows message to the specified window. This enables the application to respond within the Windows message loop. First, define the messages that will be sent to the application window. Applications can use values between Wm_app and 0xBFFF as private messages.

#define WM_GRAPHNOTIFY Wm_app + 1

Next, Query the Filter Graph Manager for the "Imediaeventex interface and Call" Imediaeventex::setnotifywindow method:

Next, request the Imediaeventex interface to the Filter Graph Manager and Invoke the Imediaeventex::setnotifywindow method:

Imediaeventex *g_pevent = NULL;

G_pgraph->queryinterface (Iid_imediaeventex, void * * *) &g_pevent);

G_pevent->setnotifywindow ((Oahwnd) G_hwnd, wm_graphnotify, 0);

This method designates the specified window (G_hwnd) as the recipient of the. Call the "method" after you create the filter graph, but before running the graph.

This function assigns a specified window as the recipient of the message. Call this function before you run graph after you create the filter graph.

Wm_graphnotify is a ordinary Windows message. Whenever the Filter Graph Manager puts a new event on the event queue, it posts a wm_graphnotify message to the designated application window. The message ' s LParam parameter are equal to the third parameter in Setnotifywindow. This parameter enables your to send instance data with the message. The window message ' s WParam parameter is always zero.

Wm_graphnotify is an ordinary Windows message. When Filter Graph Manager puts a new event in the queue, it sends a WM_GRAPHNOTIFY message to the specified application window. The LParam parameter of the message equals the third parameter of the Setnotifywindow. This parameter allows you to send the instance data along with the message. The WParam parameter for Windows messages is always 0.

In your application ' s WindowProc function, add a case statement for the wm_graphnotify message:

In the application's message handler function, add a case statement:

Case Wm_graphnotify:

Handlegraphevent ();

Break

In the event handler function, call the "Imediaevent::getevent method" to retrieve events from the queue:

In the event handler function, call the Imediaevent::getevent function to get the event from the queue.

void Handlegraphevent ()

{

Disregard if we don ' t have an imediaeventex pointer.

if (g_pevent = NULL)

{

Return

}

Get all the events

Long Evcode;

Long_ptr param1, param2;

HRESULT hr;

while (SUCCEEDED (G_pevent->getevent (&evcode, &param1, &param2, 0))

{

G_pevent->freeeventparams (Evcode, param1, param2);

Switch (Evcode)

{

Case Ec_complete://Fall through.

Case Ec_userabort://Fall through.

Case Ec_errorabort:

CleanUp ();

PostQuitMessage (0);

Return

}

}

}

The GetEvent method retrieves the event code and the two event parameters. The fourth GetEvent parameter specifies the length of the ' time ' for ' an event, in milliseconds. Because the application calls this method in response to a wm_graphnotify message, the event is already queued. Therefore, we set the time-out value to zero.

The GetEvent function obtains the event code and two event arguments. The fourth parameter of the GetEvent function specifies the length of the wait event, in milliseconds. The event is already in the queue because the application calls this method when it responds to the wm_graphnotify message. Therefore, you can set the timeout time to 0.

Event notification and the message loop are both asynchronous, so the queue might hold more than one event by the R application responds to the message. Also, the Filter Graph Manager can remove certain events from the queue, if they become invalid. Therefore, you should call GetEvent until it returns a failure code, indicating the "queue is empty."

Both the event notification and the message loop are asynchronous, so there may be multiple events in the queue when the application responds to the message. The Filter Graph Manager also removes invalid events. Therefore, you should call GetEvent until the failure code is returned, and the flag queue is empty.

In this example, the application responds to Ec_complete, Ec_userabort, and ec_errorabort by invoking the Application-defi Ned CleanUp function, which causes the application to quit gracefully. The example ignores the two event parameters. After you retrieve a event, call Imediaevent::freeeventparams to any free associated with the event parameters.

In this example, the application responds to Ec_complete, Ec_userabort, ec_errorabort by referencing the CLEANUP function defined by the program, which causes the program to quit softly. This example ignores the two parameters of the event. After you get the event, call the Imediaevent::freeeventparams function to release the resource associated with the event parameter.

Note This ec_complete event does not cause the filter graph to stop. The application can either stop or pause the graph. If you stop the graph, filters to release any they are holding. If you are pause the graph, filters continue to hold. Also, when a video renderer pauses, it displays a static image of the most recent frame.

The Ec_complete event does not cause the filter graph to stop. The application can stop or pause graph. If graph is stopped, filter releases some of his resources. If it is paused, filter will not release these resources. When a video renderer is paused, it displays the most recent static picture.

Before the Imediaeventex pointer, cancel event notification by calling Setnotifywindow with a NULL window hand Le

The Setnotifywindow cancellation event notification is invoked before the Imediaeventex pointer is released, and the argument is a NULL window handle.

Disable event Notification before releasing the graph.

G_pevent->setnotifywindow (NULL, 0, 0);

G_pevent->release ();

G_pevent = NULL;

In the Wm_graphnotify message handler, check the Imediaeventex pointer before calling GetEvent:

In Wm_graphnotify message processing, check the Imediaeventex pointer before calling GetEvent.

if (g_pevent = NULL) return;

This prevents a possible error so can occur if the application receives the event notification after releasing the point Er.

If the application has released the pointer after it has been notified of the event, this can prevent errors as much as possible.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.