1 // Video support with XAML
2 
3 // Copyright (c) Microsoft Open Technologies, Inc.
4 // All rights reserved.
5 //
6 // (3 - clause BSD License)
7 //
8 // Redistribution and use in source and binary forms, with or without modification, are permitted provided that
9 // the following conditions are met:
10 //
11 // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
12 // following disclaimer.
13 // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14 // following disclaimer in the documentation and/or other materials provided with the distribution.
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or
16 // promote products derived from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 // PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
22 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
26 
27 #pragma once
28 
29 #include "cap_winrt/CaptureFrameGrabber.hpp"
30 
31 #include <mutex>
32 #include <memory>
33 
34 class Video {
35 public:
36 
37     // non-blocking
38     bool initGrabber(int device, int w, int h);
39     void closeGrabber();
40     bool isStarted();
41 
42     // singleton
43     static Video &getInstance();
44 
45     void CopyOutput();
46 
47 private:
48     // singleton
49     Video();
50 
51     void _GrabFrameAsync(::Media::CaptureFrameGrabber^ frameGrabber);
52 
53     bool listDevices();
54 
55     Platform::Agile<Windows::Media::Capture::MediaCapture> m_capture;
56     Platform::Agile<Windows::Devices::Enumeration::DeviceInformationCollection> m_devices;
57 
58     ::Media::CaptureFrameGrabber^ m_frameGrabber;
59 
60     bool listDevicesTask();
61 
62     bool					bChooseDevice;
63     bool 					bVerbose;
64     bool                    bFlipImageX;
65     //std::atomic<bool>       bGrabberInited;
66     int						m_deviceID;
67     int						attemptFramerate;
68     std::atomic<bool>       bIsFrameNew;
69     std::atomic<bool>       bGrabberInited;
70     std::atomic<bool>       bGrabberInitInProgress;
71     unsigned int			width, height;
72     int                     bytesPerPixel;
73 
74 };