How to properly dispose Haali Video Rendere

NelDigital
2013-08-29
2013-08-30
  • NelDigital
    NelDigital
    2013-08-29

    Greetings.

    I'm using directshow.net in my application to play video files and trying to use Haali Video Renderer which is working great untill I'm trying to dispose a graph and close video window. It's often freezes and I have no way to close it other than kill application through Task Manager. I'm not getting any Exceptions and it's not freezing all the time only approximately 50% of times when I'm trying to close application.

    And I see no such behavior with any other renderer. At the moment I'm forced to use VMR9 instead but experience I'm having with it is less than satisfying.

    I tried to google any info about this Issue with Haali Video Renderer bur found nothing. This leads me to the though that I'm doing something wrong when I'm trying to dispose the graph.

    Does anyone have any experience of working with Haali Video Renderer? How should I dispose it properly?

    This is an example of how I'm trying to dispose the graph.

    protected void Dispose()
    {
    if (_videoWin != null)
    {
    _videoWin.put_Visible(OABool.False);
    _videoWin.put_Owner(IntPtr.Zero);
    }
    if (_haali != null)
    {
    _haali.Stop();
    var dealoc = _haali as IMemAllocator; // added this after I noticed freezes but it didn't help
    dealoc.Decommit();
    }

            // Stop sending event messages
            if (_mediaEvent != null)
            {
                _mediaEvent.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                _mediaEvent = null;
            }
    
            if (_mediaControl != null)
            {
                _mediaControl.Stop();
                _mediaControl = null;
            }
    
            FilterGraphTools.DisconnectAllPins(_graph);
            FilterGraphTools.RemoveAllFilters(_graph);
    
            if (_graph != null)
            {                
                Marshal.ReleaseComObject(_graph);
                _graph = null;
                GC.Collect();
            }
    
            _playState = PlaybackState.Closed;
            m_seekCaps = 0;
            _mediaSeek = null;
        }
    
     
    Last edit: NelDigital 2013-08-29
  • snarfle
    snarfle
    2013-08-30

    Eric and I disagree about how to tear down graphs. He likes using those FilterGraphTools to tear down the graph.

    My belief is that it isn't necessary to do this (see https://sourceforge.net/p/directshownet/discussion/460697/thread/9a961ed4). It's slow, inefficient and redundant. If you have been releasing your interfaces as you go, typically all you've got left at shutdown that you haven't released is the FilterGraph (plus the QIs like IMediaControl, etc). You should be able to just stop the graph and release the FilterGraph object (ie remove put_Visible, put_Owner, _haali.Stop, dealoc.Decommit, SetNotifyWindow, DisconnectAllPins & RemoveAllFilters). In fact, doing some of these while the graph is running (like you do) seems like a bad idea.

    I don't have a Haali, so I can't experiment to see what you are seeing. If trimming this down doesn't resolve your problem, I might experiment with pausing the graph, using GetState to make sure it's paused, then stopping it and make sure it's stopped before shutting down (see http://msdn.microsoft.com/en-us/library/windows/desktop/dd390178%28v=vs.85%29.aspx), but this seems like a stretch.

    I'd also make sure you have the latest RemoveAllFilters. At one point there was a leak of the IEnumFilters.

    Lastly, make sure you are only using DsRot for debugging. Leaving this in has been known to cause bad things to happen.