ARX  1.2.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 <string>
47#include <pthread.h>
48
54class ARX_EXTERN ARVideoSource {
55
56private:
57
58 typedef enum {
59 DEVICE_CLOSED,
60 DEVICE_OPEN,
61 DEVICE_GETTING_READY,
62 DEVICE_RUNNING
63 } DeviceState;
64
65 DeviceState deviceState;
66
67 AR2VideoParamT *m_vid;
68 bool m_noCpara;
69 char* cameraParam;
70 char* cameraParamBuffer;
71 size_t cameraParamBufferLen;
72 ARParamLT *cparamLT;
73 ARParam cparamAdjusted;
74
75 char* videoConfiguration;
76
77 int videoWidth;
78 int videoHeight;
79
80 AR_PIXEL_FORMAT pixelFormat;
81
82 int m_captureFrameWaitCount;
83
84 AR2VideoBufferT *m_frameBuffer;
85
86 AR2VideoTimestampT m_getFrameTextureTime;
87
88 int m_error;
89 void setError(int error);
90
91 pthread_rwlock_t m_frameBufferLock;
92
93 static void openCallback(void *userData);
94 bool open2();
95 static void open2CparamCallback(const ARParam *cparam_p, void *userdata);
96 bool open3(const ARParam *cparam_p);
97
98public:
99
101
103
104 int getError();
105
110 bool isOpen() const;
111
116 bool isRunning() const;
117
126 void configure(const char* vconf, bool noCpara, const char* cparaName, const char* cparaBuff, size_t cparaBuffLen);
127
133
134 struct Size {
135 int width;
137 };
138
139 enum class ScalingMode {
140 SCALE_MODE_STRETCH,
141 SCALE_MODE_FIT,
142 SCALE_MODE_FILL,
143 SCALE_MODE_1_TO_1
144 };
145
146 static const std::string ScalingModeName(const ScalingMode scalingMode)
147 {
148 switch (scalingMode) {
149 case ScalingMode::SCALE_MODE_STRETCH: return "stretch";
150 case ScalingMode::SCALE_MODE_FIT: return "fit";
151 case ScalingMode::SCALE_MODE_FILL: return "fill";
152 case ScalingMode::SCALE_MODE_1_TO_1: return "1 to 1";
153 default: return "";
154 }
155 }
156
160 ARParam* getCameraParametersForViewportSizeAndFittingMode(const Size viewportSize, const ScalingMode scalingMode);
161
166 int getVideoWidth() const;
167
172 int getVideoHeight() const;
173
178 AR_PIXEL_FORMAT getPixelFormat() const;
179
184 bool open();
185
190 bool close();
191
199 bool captureFrame();
200
218 AR2VideoBufferT* checkoutFrameIfNewerThan(const AR2VideoTimestampT time);
219
226 void checkinFrame(void);
227
235 AR2VideoParamT *getAR2VideoParam(void);
236
242 bool getFrameTextureRGBA32(uint32_t *buffer);
243
244 int videoPushInit(int width, int height, const char *pixelFormat, int cameraIndex, int cameraPosition);
245 int videoPush(ARUint8 *buf0p, int buf0Size, int buf0PixelStride, int buf0RowStride,
246 ARUint8 *buf1p, int buf1Size, int buf1PixelStride, int buf1RowStride,
247 ARUint8 *buf2p, int buf2Size, int buf2PixelStride, int buf2RowStride,
248 ARUint8 *buf3p, int buf3Size, int buf3PixelStride, int buf3RowStride,
249 PFN_VIDEOPUSHRELEASECALLBACK releaseCallback, void *releaseCallbackUserdata);
250 int videoPushFinal(void);
251
252};
253
254#endif // !VIDEOSOURCE_H
void(CALL_CONV *) PFN_VIDEOPUSHRELEASECALLBACK(void *releaseCallbackUserdata)
Definition Platform.h:105
artoolkitX core routines.
unsigned char ARUint8
Definition ar.h:92
ScalingMode
Definition ARVideoSource.h:139
@ SCALE_MODE_STRETCH
Definition ARVideoSource.h:140
@ SCALE_MODE_FIT
Definition ARVideoSource.h:141
@ SCALE_MODE_FILL
Definition ARVideoSource.h:142
@ SCALE_MODE_1_TO_1
Definition ARVideoSource.h:143
static const std::string ScalingModeName(const ScalingMode scalingMode)
Definition ARVideoSource.h:146
int getError()
Definition ARVideoSource.cpp:355
bool isOpen() const
Returns true if the video source is open.
Definition ARVideoSource.cpp:364
ARVideoSource()
Definition ARVideoSource.cpp:61
ARParamLT * getCameraParameters() const
Returns the camera parameters for the video source.
Definition ARVideoSource.cpp:374
void configure(const char *vconf, bool noCpara, const char *cparaName, const char *cparaBuff, size_t cparaBuffLen)
Sets initial parameters which will be used when the video source is opened.
Definition ARVideoSource.cpp:104
bool isRunning() const
Returns true if the video source is open and ready to be queried.
Definition ARVideoSource.cpp:369
A structure which carries information about a video frame retrieved by the video library.
Definition ar.h:148
Definition video.h:321
A structure to hold a timestamp in seconds and microseconds, with arbitrary epoch.
Definition ar.h:139
Structure holding camera parameters, including image size, projection matrix and lens distortion para...
Definition param.h:99
Structure holding camera parameters, in lookup table form.
Definition param.h:151
Definition ARVideoSource.h:134
int width
Definition ARVideoSource.h:135
int height
Definition ARVideoSource.h:136