magician-david / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Add support for microsoft lifecam (and potentially other webcams) - directshow wrapper #200

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Microsoft lifecam (and probably other webcams) don't accept changes to 
infoHeader.BmiHeader.Width or Height - they just get ignored:

http://social.msdn.microsoft.com/Forums/en/windowsdirectshowdevelopment/thread/6
ae459fe-3423-4f82-a41a-4fe51f639bd3

Need to pass in the correct AMMediaType instead of creating a new one. Propose 
changing the code in VideoCaptureDevice.cs to:

Line 561...

// get current format
                        streamConfig.GetFormat( out mediaType );

                        if ((desiredFrameSize.Width != 0) && (desiredFrameSize.Height != 0))
                        {
                            // get/set media type
                            int _numcaps = 0, _capsize = 0;
                            streamConfig.GetNumberOfCapabilities(out _numcaps, out _capsize);
                            Size _size = new Size(desiredFrameSize.Width, desiredFrameSize.Height);
                            AMMediaType _newmediatype = null;
                            VideoStreamConfigCaps caps = new VideoStreamConfigCaps();
                            bool _found = false;
                            for (int _i = 0; _i < _numcaps; _i++)
                            {
                                streamConfig.GetStreamCaps(_i, out _newmediatype, caps);
                                if (caps.InputSize == _size)
                                {
                                    _found = true;
                                    break;
                                }
                            }
                            if (_found)
                            {
                                mediaType.Dispose();
                                mediaType = _newmediatype;
                                //streamConfig.SetFormat(_newmediatype);
                            }

                        }

                        VideoInfoHeader infoHeader = (VideoInfoHeader) Marshal.PtrToStructure( mediaType.FormatPtr, typeof( VideoInfoHeader ) );

                        // change frame size if required
                        //if ( ( desiredFrameSize.Width != 0 ) && ( desiredFrameSize.Height != 0 ) )
                        //{
                        //    infoHeader.BmiHeader.Width = desiredFrameSize.Width;
                        //    infoHeader.BmiHeader.Height = desiredFrameSize.Height;
                        //}
                        // change frame rate if required
                        if ( desiredFrameRate != 0 )
                        {
                            infoHeader.AverageTimePerFrame = 10000000 / desiredFrameRate;
                        }

                        // copy the media structure back
                        Marshal.StructureToPtr( infoHeader, mediaType.FormatPtr, false );

                        // set the new format
                        streamConfig.SetFormat( mediaType );

                        mediaType.Dispose( );

- this works with lifecam and other webcams but isn't tested extensively...

Original issue reported on code.google.com by sean.p.t...@gmail.com on 17 Apr 2011 at 11:25

GoogleCodeExporter commented 8 years ago

Original comment by sean.p.t...@gmail.com on 18 Apr 2011 at 12:09

Attachments:

GoogleCodeExporter commented 8 years ago
Just uploaded my modified file with some code clean-up

Original comment by sean.p.t...@gmail.com on 18 Apr 2011 at 12:10

GoogleCodeExporter commented 8 years ago
Thank you for the update. Will take a look. Don't have MS life came though, but 
will see how others work.

Original comment by andrew.k...@gmail.com on 18 Apr 2011 at 8:17

GoogleCodeExporter commented 8 years ago
When desired video size is set, perform search of complete media type structure 
and set it as it is configured when enumerating capabilities.

Committed in revision 1439. Will be released in next version.

Original comment by andrew.k...@gmail.com on 30 Apr 2011 at 7:40

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 28 Jul 2011 at 9:47

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 10 Aug 2011 at 9:33