directshowdirectshow.net

IMediaControl.Run() is successful still camera preview is black


By using Directshow.NET and c# I have developed an application which shows camera preview. Everything is working fine since 1 year but suddenly client complaint about black camera preview.

After some digging to issue I come to know that anti-virus program is blocking camera usages by my application. After adding my application in exclusion list of that anti-virus program makes application to work as like before.

In program I have properly thrown exception for HRESULT like below:

try
{
    //FilterGraph creation
    //CaptureGraphBuilder2 creation
    //AddSourceFilterForMoniker()
    //SampleGrabber configuration
    //VMR9 configuration

    hr = mediaControl.Run();
    DsError.ThrowExceptionForHR(hr);
}
catch(Exception ex)
{
    //logging part
}

Still there is nothing in log, even I debug that application on that particular machine but program executes successfully. So the question is, To avoid such issues how can I make sure that camera preview is actually started? Is there any way to check that stream is not blocked.


Solution

  • Black camera preview is not necessarily a symptom of a failure to run the graph. For example, whether this is your problem exactly or not, a filter graph esp. displaying IP camera feed might be put into running state and the video renderer would expect a frame to be received and processed respectively to the state it's display ready. However if an antivirus or a firewall blocks traffic, the video frame never reaches the renderer. The filter graph is running though and there is no failure or error.

    You normally want to request some statistics from filters in your filter graph, that prove there is payload processing happening. This might include:

    Once you see the data is being processed as the time goes, you know there is no unexpected locking happens.