trikRuntime
trikV4l2VideoDevice.h
Go to the documentation of this file.
1 /* Copyright 2018 Ivan Tyulyandin and CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QObject>
18 #include <QSocketNotifier>
19 #include <QtCore/QString>
20 #include <QtCore/QVector>
21 #include <QtCore/QSocketNotifier>
22 #include <linux/videodev2.h>
23 
24 using convertFunctionPtr = QVector<uint8_t> (*)(const QVector<uint8_t> &realCameraShot, int height, int width);
25 
27 class TrikV4l2VideoDevice: QObject
28 {
29  Q_OBJECT
30 public:
31 
34  explicit TrikV4l2VideoDevice(const QString &inputFile);
35 
37 
39  const QVector<uint8_t> & makeShot();
40 
42  const QVector<uint8_t> & getFrame() const { return mFrame; }
43 
44 signals:
46  void dataReady();
47 
48 public slots:
51  void readFrameData(int fd);
52 
53 private:
54  void closeDevice();
55  void setFormat();
56  void openDevice();
57  int xioctl(unsigned long request, void *arg, const QString &possibleError);
58  void initMMAP();
59  void startCapturing();
60  int readFrame();
61  void stopCapturing();
62  void freeMMAP();
63 
64  int mFileDescriptor = -1;
65  const QString fileDevicePath;
66 
67  struct buffer {
68  uint8_t *start;
69  size_t length;
70  };
71  QVector<uint8_t> mFrame;
72  QVector<buffer> buffers;
73  v4l2_format mFormat {};
74  QSocketNotifier *mNotifier {}; // Has ownership
75  convertFunctionPtr mConvertFunc; // convert real camera shot to RGB888
76 };
77 
Class for working with a camera on a TRIK controller.
Definition: trikV4l2VideoDevice.h:27
const QVector< uint8_t > & getFrame() const
Get last frame.
Definition: trikV4l2VideoDevice.h:42
void dataReady()
Signal when photo was made.
void readFrameData(int fd)
Read data from v4l2 buffers.
Definition: trikV4l2VideoDevice.cpp:358
~TrikV4l2VideoDevice()
Definition: trikV4l2VideoDevice.cpp:134
const QVector< uint8_t > & makeShot()
Make photo using TRIK camera.
Definition: trikV4l2VideoDevice.cpp:260
QVector< uint8_t >(*)(const QVector< uint8_t > &realCameraShot, int height, int width) convertFunctionPtr
Definition: trikV4l2VideoDevice.h:24
TrikV4l2VideoDevice(const QString &inputFile)
TRIK v4l2 video device constructor.
Definition: trikV4l2VideoDevice.cpp:127