| ARX 1.0 The next-generation open source augmented reality toolkit.

Loading...
Searching...
No Matches
ARVideoSource.h
Go to the documentation of this file.
1/*
2 * ARVideoSource.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-2016 Daqri, LLC.
33 * Copyright 2010-2015 ARToolworks, Inc.
34 *
35 */
36
37#ifndef VIDEOSOURCE_H
38#define VIDEOSOURCE_H
39
40#include <ARX/Platform.h>
41
42#include <ARX/AR/ar.h>
43#include <ARX/ARVideo/video.h>
44
45#include <mutex>
46#include <pthread.h>
47
53 class ARX_EXTERN ARVideoSource {
54
55 private:
56
57 typedef enum {
58 DEVICE_CLOSED,
59 DEVICE_OPEN,
60 DEVICE_GETTING_READY,
61 DEVICE_RUNNING
62 } DeviceState;
63
64 DeviceState deviceState;
65
66 AR2VideoParamT *m_vid;
67 bool m_noCpara;
68 char* cameraParam;
69 char* cameraParamBuffer;
70 size_t cameraParamBufferLen;
71 ARParamLT *cparamLT;
72 ARParam cparamAdjusted;
73
74 char* videoConfiguration;
75
76 int videoWidth;
77 int videoHeight;
78
79 AR_PIXEL_FORMAT pixelFormat;
80
81 int m_captureFrameWaitCount;
82
83 AR2VideoBufferT *m_frameBuffer;
84
85 AR2VideoTimestampT m_getFrameTextureTime;
86
87 int m_error;
88 void setError(int error);
89
90 pthread_rwlock_t m_frameBufferLock;
91
92 static void openCallback(void *userData);
93 bool open2();
94 static void open2CparamCallback(const ARParam *cparam_p, void *userdata);
95 bool open3(const ARParam *cparam_p);
96
97 public:
98
99 ARVideoSource();
100
101 ~ARVideoSource();
102
103 int getError();
104
109 bool isOpen() const;
110
115 bool isRunning() const;
116
125 void configure(const char* vconf, bool noCpara, const char* cparaName, const char* cparaBuff, size_t cparaBuffLen);
126
131 ARParamLT* getCameraParameters() const;
132
133 struct Size {
134 int width;
135 int height;
136 };
137
138 enum class ScalingMode {
139 SCALE_MODE_STRETCH,
140 SCALE_MODE_FIT,
141 SCALE_MODE_FILL,
142 SCALE_MODE_1_TO_1
143 };
144
145 static const std::string ScalingModeName(const ScalingMode scalingMode)
146 {
147 switch (scalingMode) {
148 case ScalingMode::SCALE_MODE_STRETCH: return "stretch";
149 case ScalingMode::SCALE_MODE_FIT: return "fit";
150 case ScalingMode::SCALE_MODE_FILL: return "fill";
151 case ScalingMode::SCALE_MODE_1_TO_1: return "1 to 1";
152 default: return "";
153 }
154 }
155
159 ARParam* getCameraParametersForViewportSizeAndFittingMode(const Size viewportSize, const ScalingMode scalingMode);
160
165 int getVideoWidth() const;
166
171 int getVideoHeight() const;
172
177 AR_PIXEL_FORMAT getPixelFormat() const;
178
183 bool open();
184
189 bool close();
190
198 bool captureFrame();
199
217 AR2VideoBufferT* checkoutFrameIfNewerThan(const AR2VideoTimestampT time);
218
225 void checkinFrame(void);
226
234 AR2VideoParamT *getAR2VideoParam(void);
235
241 bool getFrameTextureRGBA32(uint32_t *buffer);
242
243 int videoPushInit(int width, int height, const char *pixelFormat, int cameraIndex, int cameraPosition);
244 int videoPush(ARUint8 *buf0p, int buf0Size, int buf0PixelStride, int buf0RowStride,
245 ARUint8 *buf1p, int buf1Size, int buf1PixelStride, int buf1RowStride,
246 ARUint8 *buf2p, int buf2Size, int buf2PixelStride, int buf2RowStride,
247 ARUint8 *buf3p, int buf3Size, int buf3PixelStride, int buf3RowStride);
248 int videoPushFinal(void);
249
250};
251
252#endif // !VIDEOSOURCE_H
Platform.h
ar.h
artoolkitX core routines.
ARUint8
unsigned char ARUint8
Definition: ar.h:92
ARVideoSource
A video source provides video frames to the artoolkitX tracking module.
Definition: ARVideoSource.h:53
ARVideoSource::ScalingMode
ScalingMode
Definition: ARVideoSource.h:138
ARVideoSource::ScalingModeName
static const std::string ScalingModeName(const ScalingMode scalingMode)
Definition: ARVideoSource.h:145
AR2VideoBufferT
A structure which carries information about a video frame retrieved by the video library.
Definition: ar.h:148
AR2VideoParamT
Definition: video.h:320
AR2VideoTimestampT
A structure to hold a timestamp in seconds and microseconds, with arbitrary epoch.
Definition: ar.h:139
ARParam
Structure holding camera parameters, including image size, projection matrix and lens distortion para...
Definition: param.h:99
ARParamLT
Structure holding camera parameters, in lookup table form.
Definition: param.h:151
ARVideoSource::Size
Definition: ARVideoSource.h:133
ARVideoSource::Size::width
int width
Definition: ARVideoSource.h:134
ARVideoSource::Size::height
int height
Definition: ARVideoSource.h:135
video.h