| 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>
49#include "CaptureFrameGrabber/CaptureFrameGrabber.h"
50
51 class WindowsMediaCapture
52{
53
54 public:
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;
79 void WindowsMediaCapture::showSettings(void);
80
81 private:
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
86 WindowsMediaCapture(WindowsMediaCapture&&) = delete;
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};
CaptureFrameGrabber.h
WindowsMediaCapture
Definition: WindowsMediaCapture.h:52
WindowsMediaCapture::deviceLocation
Windows::Devices::Enumeration::Panel deviceLocation() const
Definition: WindowsMediaCapture.cpp:531
WindowsMediaCapture::StartCapture
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
WindowsMediaCapture::StopCapture
void StopCapture()
Definition: WindowsMediaCapture.cpp:458
WindowsMediaCapture::deviceName
std::string deviceName() const
Definition: WindowsMediaCapture.cpp:536
WindowsMediaCapture::Capturing
bool Capturing() const
Definition: WindowsMediaCapture.cpp:341
WindowsMediaCapture::height
int height() const
Definition: WindowsMediaCapture.cpp:511
WindowsMediaCapture::showSettings
void showSettings(void)
Definition: WindowsMediaCapture.cpp:541
WindowsMediaCapture::Bpp
int Bpp() const
Definition: WindowsMediaCapture.cpp:516
WindowsMediaCapture::width
int width() const
Definition: WindowsMediaCapture.cpp:506
WindowsMediaCapture::setFlipV
void setFlipV(bool flag)
Definition: WindowsMediaCapture.cpp:526
WindowsMediaCapture::~WindowsMediaCapture
virtual ~WindowsMediaCapture(void)
Definition: WindowsMediaCapture.cpp:126
WindowsMediaCapture::WindowsMediaCapture
WindowsMediaCapture(void)
Definition: WindowsMediaCapture.cpp:117
WindowsMediaCapture::GetFrame
uint8_t * GetFrame()
Definition: WindowsMediaCapture.cpp:440
WindowsMediaCapture::flipV
bool flipV() const
Definition: WindowsMediaCapture.cpp:521