opencv/modules
GregoryMorse aa3c36f545 Update cap_msmf.cpp
Add support for WinRT in the MF capture framework by removing the disallowed calls to enumerate devices and create a sample grabber sink and adding framework for the MediaCapture interface and a custom sink which interfaces with the sample grabber callback interface. The change requires discussion for making it completely functional as redundancy is required given that if the source is a video file, the old code pathways must be used. Otherwise all IMFMediaSession, IMFMediaSource, and IMFActivate code must use a MediaCapture code path and all sink code must use the CMediaSink custom sink.

Support for the custom sink is extended to non-WinRT not for compatibility as Windows Vista client is a minimum regardless, but because it offers more flexibility, could be faster and is able to be used as an optionally different code path during sink creation based on a future configuration parameter.

My discussion and proposal to finish this change:
 Devices are so easily enumerated through WinRT Windows.Devices namespace that wrapping the calls in a library is quite a chore for little benefit though to get the various modes and formats could still be a worthwhile project. For now conditional compilation to remove videodevices and any offending non-video file related activity in videodevice. In my opinion, this is a different , far less fundamental and important change which can possibly be done as a future project and also much more easily implemented in C++/CX.

ImageGrabber has the IMFSampleGrabberSinkCallback replaced with a base class (SharedSampleGrabber) which also be is base class for ImageGrabberRT. This change is necessary as the custom sink does not require a thread to pump events which is done through MediaCapture already. IMFSampleGrabberSinkCallback is the common element between both models and that piece can be shared. Initializing the new ImageGrabberRT is as simple as passing an already initialized MediaCapture object and any video format/encoding parameters.

The concurrency event is necessary to wait for completion and is the way the underlying, IAsyncAction wrappers in the task library work as well. Native WIN32 event objects would be an option if HAVE_CONCURRENCY is not defined. I could even imagine doing it with sleep/thread yield and InterlockedCompareExchange yet I am not enthusiastic about that approach either. Since there is a specific compiler HAVE_ for concurrency, I do not like pulling it in though I think for WinRT it is safe to say we will always have it available though should probably conditionally compile with the Interlocked option as WIN32 events would require HAVE_WIN32.

It looks like C++/CX cannot be used for the IMediaExtension sink (which should not be a problem) as using COM objects requires WRL and though deriving from IMediaExtension can be done, there is little purpose without COM. Objects from C++/CX can be swapped to interact with objects from native C++ as Inspectable* can reinterpret_cast to the ref object IInspectable^ and vice-versa. A solution to the COM class with C++/CX would be great so we could have dual support. Also without #define for every WRL object in use, the code will get quite muddy given that the */^ would need to be ifdef'd everywhere.

Update cap_msmf.cpp

Fixed bugs and completed the change.  I believe the new classes need to be moved to a header file as the file has become to large and more classes need to be added for handling all the asynchronous problems (one wrapping IAsyncAction in a task and another for making a task out of IAsyncAction).  Unfortunately, blocking on the UI thread is not an option in WinRT so a synchronous architecture is considered "illegal" by Microsoft's standards even if implementable (C++/CX ppltasks library throws errors if you try it).  Worse, either by design or a bug in the MF MediaCapture class with Custom Sinks causes a crash if stop/start previewing without reinitializing (spPreferredPreviewMediaType is fatally nulled).  After decompiling Windows.Media.dll, I worked around this in my own projects by using an activate-able custom sink ID which strangely assigns 1 to this pointer allowing it to be reinitialized in what can only be described as a hack by Microsoft.  This would add additional overhead to the project to implement especially for static libraries as it requires IDL/DLL exporting followed by manifest declaration.  Better to document that it is not supported.

Furthermore, an additional class for IMFAttributes should be implemented to make clean architecture for passing around attributes as opposed to directly calling non-COM interface calls on the objects and making use of SetProperties which would also be a set up for an object that uses the RuntimeClass activation ID.

The remaining changes are not difficult and will be complete soon along with debug tracing messages.

Update and rename cap_msmf.h to cap_msmf.hpp

Update cap_msmf.cpp

Successful test - samples are grabbed

Update ppltasks_winrt.h

Library updated and cleaned up with comments, marshaling, exceptions and linker settings
Fixed trailing whitespace

Support VS 2013 and consistency cleanup and C++/CX object creation fixed
2014-04-15 18:32:23 +08:00
..
androidcamera Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-01-27 15:28:14 +04:00
calib3d finalizing 2014-03-17 10:42:19 +04:00
contrib Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-11 17:20:01 +04:00
core Merge pull request #2486 from SpecLad:merge-2.4 2014-03-18 13:55:57 +04:00
cuda fix bug #3544: 2014-02-18 10:45:47 +04:00
cudaarithm Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-03 13:45:22 +04:00
cudabgsegm Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-12-03 17:35:21 +04:00
cudacodec Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-12-03 17:35:21 +04:00
cudafeatures2d Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-11 17:20:01 +04:00
cudafilters Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-12-03 17:35:21 +04:00
cudaimgproc Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-11 17:20:01 +04:00
cudalegacy Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-02-03 13:23:59 +04:00
cudaoptflow Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-02-17 15:24:05 +04:00
cudastereo Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-12-03 17:35:21 +04:00
cudawarping Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-12-03 17:35:21 +04:00
cudev Removed another usage of __func__, following #1763. 2013-11-11 17:02:50 +04:00
features2d Merge pull request #2480 from vpisarev:ocl_orb 2014-03-14 19:04:19 +04:00
flann Fixed getPolicy() method to make it thread-safe. 2014-03-14 13:50:33 +04:00
highgui Update cap_msmf.cpp 2014-04-15 18:32:23 +08:00
imgproc Merge pull request #2428 from alalek:ocl_copyMakeBorder_3channels 2014-03-17 13:10:34 +04:00
java Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-03 13:45:22 +04:00
legacy Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-03 13:45:22 +04:00
matlab Use CMAKE_CFG_INTDIR meta-variable to get the library output directory of the opencv_matlab. 2014-02-13 23:53:58 +08:00
ml fixed defects from coverity.com 2014-02-23 20:21:08 +04:00
nonfree nonfree perf tests 2014-03-13 22:35:08 +04:00
objdetect Removed workaround for Intel platform. 2014-03-14 14:18:52 +04:00
optim Merge pull request #1521 from nailbiter:optimCG 2013-10-29 16:14:32 +04:00
photo Merge pull request #2382 from ilya-lavrenov:tapi_nlmeans 2014-03-13 16:48:38 +04:00
python core/umat: usage flags (with proposals from PR #2195) 2014-02-14 15:40:16 +04:00
shape fixed defects from Xcode 2014-02-25 17:33:12 +04:00
softcascade deleted excess semicolons, commas 2014-01-18 01:31:33 +04:00
stitching TAPI: fix perf test for warpers 2014-02-20 13:09:06 +04:00
superres Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-02-25 15:02:24 +04:00
ts Merge pull request #2459 from ilya-lavrenov:tapi_experiments 2014-03-13 16:49:57 +04:00
video Merge pull request #2373 from mlyashko:optflow_dualtvl1 2014-03-11 16:00:22 +04:00
videostab Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-17 14:14:07 +04:00
viz Merge remote-tracking branch 'origin/2.4' into merge-2.4 2014-03-17 14:14:07 +04:00
world Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-11-11 16:55:36 +04:00
CMakeLists.txt Merge remote-tracking branch 'origin/2.4' into merge-2.4 2013-06-10 18:18:01 +04:00
refman.rst.in