WM_GRAPHNOTIFY, is it instance specific to it's filtergraph

1

We have an application which uses directshow with two filtergraphs to implement seamless video playback. each "panel" is initialized with a filtergraph using new QuartzTypeLib.FilgraphManager()and later assigned to WndProc using MediaEventEx.SetNotifyWindow to the same window but with a different LParam (panel ID 0 or 1)

Documentation states that WM_GRAPHNOTIFY is sent when there are new events, but there could be more than one event in the queue, or the queue may be empty. Additionally WM_GRAPHNOTIFY is not sent once per event, but could be sent once if there are one or more events in queue.

Since I am using the same window for notifications from both filtergraphs, can I be sure that i get events from both queues if they occur simultaneously, or do I need to parse both queues on each WM_GRAPHNOTIFY message or can I safely process the queue from lParam?

Below is a very stripped version of my code.

private const int WM_APP = 0x8000;
private const int WM_GRAPHNOTIFY = WM_APP + 1;
private const int EC_COMPLETE = 0x01;
private const int EC_USERABORT = 0x02;
private const int EC_ERRORABORT = 0x03;

void InitializePanels()
{
    for (int panel = 0; panel <= 1; panel++)
    {
        PlaybackPanels[panel].FilterGraph = new QuartzTypeLib.FilgraphManager();
        PlaybackPanels[panel].MediaEventEx = PlaybackPanels[(panel].FilterGraph as IMediaEventEx;
        PlaybackPanels[panel].MediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, panel);
        PlaybackPanels[panel].MediaControl = PlaybackPanels[panel].FilterGraph as IMediaControl;
        // Additional code to load media files here...
        PlaybackPanels[panel].MediaControl.Pause();
    }
    PlaybackPanels[0].MediaControl.Run();
}

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_GRAPHNOTIFY)
    {
        int lEventCode;
        int lParam1, lParam2;

        int playerPanelID = m.LParam.ToInt32();

        int _while = 0;
        while (_while < 100)
        {
            try
            {

                PlaybackPanels[playerPanelID].MediaEventEx.GetEvent(out lEventCode, out lParam1, out lParam2, 0);
                PlaybackPanels[playerPanelID].MediaEventEx.FreeEventParams(lEventCode, lParam1, lParam2);
                if (lEventCode == EC_COMPLETE)
                {
                    int nextPanel = 1 - playerPanelID;
                    PlaybackPanels[nextPanel].MediaControl.Run();
                }
                else if (lEventCode == EC_USERABORT || lEventCode == EC_ERRORABORT)
                {
                    /// Handle error...
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {

                // REMARKS: When the window receives the message, it should call the IMediaEvent::GetEvent method to retrieve the event. 
                //          Events are asynchronous, so the queue might contain several events (or none). 
                //          Call GetEvent repeatedly, until it returns an error code.

                if ((uint)ex.ErrorCode == 0x80004004) //Operation Aborted (E_ABORT)
                {

                    // We are done processing the event queue. *Resume event loop*
                    break;

                }
                else
                {
                    throw;
                }
            }

            _while++;
        }
    }

    base.WndProc(ref m);
}
c#
directshow
asked on Stack Overflow May 8, 2018 by ulvesked

1 Answer

0

The graphs issue notifications on new event availability, so there is no collision or problem otherwise that multiple graphs send the same window message. Already unrelated, there is no problem either if handing a message you GetEvent both graphs including not the one which issued a notification in first place.

Also another way to distinguish between the senders is to send WM_GRAPHNOTIFY + 0 and WM_GRAPHNOTIFY + 1 and handle respectively. You can have more identification information, the LPARAM and also message offset.

answered on Stack Overflow May 8, 2018 by Roman R. • edited May 8, 2018 by Roman R.

User contributions licensed under CC BY-SA 3.0