ARX  1.0
The next-generation open source augmented reality toolkit.
Loading...
Searching...
No Matches
WindowsMediaCapture.h
Go to the documentation of this file.
1/*
2 * WindowsMediaCapture.h
3 * artoolkitX
4 *
5 * This file is part of artoolkitX.
6 *
7 * artoolkitX is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * artoolkitX is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with artoolkitX. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * As a special exception, the copyright holders of this library give you
21 * permission to link this library with independent modules to produce an
22 * executable, regardless of the license terms of these independent modules, and to
23 * copy and distribute the resulting executable under terms of your choice,
24 * provided that you also meet, for each linked independent module, the terms and
25 * conditions of the license of that module. An independent module is a module
26 * which is neither derived from nor based on this library. If you modify this
27 * library, you may extend this exception to your version of the library, but you
28 * are not obligated to do so. If you do not wish to do so, delete this exception
29 * statement from your version.
30 *
31 * Copyright 2018 Realmax, Inc.
32 * Copyright 2015 Daqri, LLC.
33 * Copyright 2014-2015 ARToolworks, Inc.
34 *
35 * Author(s): Philip Lamb
36 *
37 */
38
39#pragma once
40
41#include <ARX/AR/config.h>
42
43#include <wrl/client.h>
44#include <agile.h>
45#include <string>
46#include <mutex>
47#include <condition_variable>
48#include <stdint.h>
50
52{
53
54public:
55 WindowsMediaCapture(void)/* : m_stopLockCondVar {}*/;
56 virtual ~WindowsMediaCapture(void);
57
58 // Setup/tear down functions
59 bool StartCapture(int width,
60 int height,
61 Platform::String^ pixelFormat = Windows::Media::MediaProperties::MediaEncodingSubtypes::Rgb24, // Raw formats: Rgb24, Rgb32, Nv12, Argb32, Bgra8, Yv12, Yuy2, Iyuv
62 int preferredDeviceIndex = 0,
63 Windows::Devices::Enumeration::Panel preferredLocation = Windows::Devices::Enumeration::Panel::Unknown,
64 void (*errorCallback)(void *) = NULL,
65 void *errorCallbackUserdata = NULL
66 );
67 bool Capturing() const; // Returns true if between StartCapture() and StopCapture().
68 uint8_t *GetFrame(); // Returns NULL if no new frame available, or pointer to frame buffer if new frame is available. Dimensions of buffer are width()*height()*Bpp(). If non-NULL buffer returned, then any previous non-NULL buffer is invalidated.
69 void StopCapture();
70
71 int width() const;
72 int height() const;
73 int Bpp() const;
74 bool flipV() const;
75 void setFlipV(bool flag);
76
77 Windows::Devices::Enumeration::Panel deviceLocation() const;
78 std::string deviceName() const;
80
81private:
82 //Disable Copy ctor and assignment
83 WindowsMediaCapture(const WindowsMediaCapture& other) = delete; // Copy constructor not implemented.
84 auto operator=(const WindowsMediaCapture& other) -> WindowsMediaCapture& = delete; // Copy assignment operator not implemented.
85 //Disable Move ctor and assignment
87 auto operator=(WindowsMediaCapture&&) -> WindowsMediaCapture& = delete;
88
89 bool initDevices();
90 void _GrabFrameAsync(Media::CaptureFrameGrabber^ frameGrabber);
91
92 bool m_started;
93 int m_width;
94 int m_height;
95 int m_Bpp;
96 bool m_flipV;
97 Platform::String^ m_pixelFormat;
98 Platform::Agile<Windows::Devices::Enumeration::DeviceInformationCollection> m_devices;
99 Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCapture;
100 int m_deviceIndex;
101 Windows::Devices::Enumeration::Panel m_deviceLocation;
102 std::string m_deviceName;
103 ::Media::CaptureFrameGrabber^ m_frameGrabber;
104 bool m_frameGrabberInited;
105 long m_frameCountIn;
106 long m_frameCountOut;
107 uint8_t *m_buf0;
108 uint8_t *m_buf1;
109 int m_bufNext;
110 std::mutex m_bufLock;
111 void (*m_errorCallback)(void *);
112 void *m_errorCallbackUserdata;
113 bool m_frameGrabberIsDone;
114 std::mutex m_stopLockMutex;
115 std::condition_variable m_stopLockCondVar;
116};
Definition: WindowsMediaCapture.h:52
Windows::Devices::Enumeration::Panel deviceLocation() const
Definition: WindowsMediaCapture.cpp:531
bool StartCapture(int width, int height, Platform::String^ pixelFormat=Windows::Media::MediaProperties::MediaEncodingSubtypes::Rgb24, int preferredDeviceIndex=0, Windows::Devices::Enumeration::Panel preferredLocation=Windows::Devices::Enumeration::Panel::Unknown, void(*errorCallback)(void *)=NULL, void *errorCallbackUserdata=NULL)
Definition: WindowsMediaCapture.cpp:151
void StopCapture()
Definition: WindowsMediaCapture.cpp:458
std::string deviceName() const
Definition: WindowsMediaCapture.cpp:536
bool Capturing() const
Definition: WindowsMediaCapture.cpp:341
int height() const
Definition: WindowsMediaCapture.cpp:511
void showSettings(void)
Definition: WindowsMediaCapture.cpp:541
int Bpp() const
Definition: WindowsMediaCapture.cpp:516
int width() const
Definition: WindowsMediaCapture.cpp:506
void setFlipV(bool flag)
Definition: WindowsMediaCapture.cpp:526
virtual ~WindowsMediaCapture(void)
Definition: WindowsMediaCapture.cpp:126
WindowsMediaCapture(void)
Definition: WindowsMediaCapture.cpp:117
uint8_t * GetFrame()
Definition: WindowsMediaCapture.cpp:440
bool flipV() const
Definition: WindowsMediaCapture.cpp:521