Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetPinCapabilitiesAndConfigureSizeAndRate() does not release streamConfig #394

Closed
GoogleCodeExporter opened this issue Jun 25, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. use the sample Samples\Video\Player
2. use a real hardware camera, e.g.Basler ace USB3 (will not show up with avi / 
file accessing simulators). Should come up with many cameras as it is not 
Basler camera specific
3. run sample

What is the expected output? What do you see instead?

No live image is shown. After a call to  
GetPinCapabilitiesAndConfigureSizeAndRate() , the camera is exclusivliy locked, 
streamConfig internally holds a ref count to the filter subsystem and the 
camera cannot be opened again. (i guess the player first builds up a temporary 
graph to fetch camera capabilities)

What version of the product are you using?
svn trunk as of 12.1.2015



Please provide any additional information below.


The fix is easy:

just use
 Marshal.ReleaseComObject(streamConfigObject); 

<code>
at the end of GetPinCapabilitiesAndConfigureSizeAndRate(...), e.g.:

      // Configure specified pin and collect its capabilities if required
        private void GetPinCapabilitiesAndConfigureSizeAndRate( ICaptureGraphBuilder2 graphBuilder, IBaseFilter baseFilter,
            Guid pinCategory, VideoCapabilities resolutionToSet, ref VideoCapabilities[] capabilities )
        {
            object streamConfigObject;
            graphBuilder.FindInterface( pinCategory, MediaType.Video, baseFilter, typeof( IAMStreamConfig ).GUID, out streamConfigObject );

            if ( streamConfigObject != null )
            {
                IAMStreamConfig streamConfig = null;

                try
                {
                    streamConfig = (IAMStreamConfig) streamConfigObject;
                }
                catch ( InvalidCastException )
                {
                }

                if ( streamConfig != null )
                {
                    if ( capabilities == null )
                    {
                        try
                        {
                            // get all video capabilities
                            capabilities = AForge.Video.DirectShow.VideoCapabilities.FromStreamConfig( streamConfig );
                        }
                        catch
                        {
                        }
                    }

                    // check if it is required to change capture settings
                    if ( resolutionToSet != null )
                    {
                        SetResolution( streamConfig, resolutionToSet );
                    }
                }
                // release interface was missing here, Cameras could be left locked if not released 
                Marshal.ReleaseComObject(streamConfigObject);
             }

            // if failed resolving capabilities, then just create empty capabilities array,
            // so we don't try again
            if ( capabilities == null )
            {
                capabilities = new VideoCapabilities[0];
            }
        }

</code>


best regards,

Timm von der Mehden
Software Developer

Basler AG
An der Strusbek 60-62
22926 Ahrensburg
Germany
www.baslerweb.com

Original issue reported on code.google.com by vdMeh...@gmail.com on 13 Jan 2015 at 8:37

@GoogleCodeExporter
Copy link
Author

Fixed leak of "streamConfigObject" in 
VideoCaptureDevice.GetPinCapabilitiesAndConfigureSizeAndRate().

SVN revision on Google Project: 1733.
Git SHA-1 on GitHub: 50e95424cd5b5b185d5a77305c088b45cdd2f2d7

Original comment by andrew.k...@gmail.com on 28 Jan 2015 at 11:13

  • Changed state: Fixed
  • Added labels: Priority-Medium, Project-Video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant