Add internal types

This commit is contained in:
John Zhao
2018-03-31 15:54:37 +08:00
parent 2df1ab635a
commit a5bdeaf41f
5 changed files with 35 additions and 37 deletions

25
src/internal/types.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef MYNTEYE_INTERNAL_TYPES_H_ // NOLINT
#define MYNTEYE_INTERNAL_TYPES_H_
#pragma once
#include <cstdint>
#include "mynteye/mynteye.h"
#define FOURCC(a, b, c, d) \
((std::uint32_t)(a) | ((std::uint32_t)(b) << 8) | \
((std::uint32_t)(c) << 16) | ((std::uint32_t)(d) << 24)) // NOLINT
MYNTEYE_BEGIN_NAMESPACE
/**
* @ingroup enumerations
* @brief Formats define how each stream can be encoded.
*/
enum class Format : std::uint32_t {
YUYV = FOURCC('Y', 'U', 'Y', 'V'),
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_INTERNAL_TYPES_H_ NOLINT

View File

@@ -1,26 +0,0 @@
#ifndef MYNTEYE_TYPES_H_ // NOLINT
#define MYNTEYE_TYPES_H_
#pragma once
#include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
template <class T>
class big_endian {
T be_value;
public:
operator T() const { // convert to T from big to little endian
T le_value = 0;
for (unsigned int i = 0; i < sizeof(T); ++i) {
reinterpret_cast<char *>(&le_value)[i] =
reinterpret_cast<const char *>(&be_value)[sizeof(T) - i - 1];
}
return le_value;
}
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_TYPES_H_ NOLINT

View File

@@ -19,8 +19,6 @@
#include <string>
#include <thread>
#include "types.h" // NOLINT
MYNTEYE_BEGIN_NAMESPACE
namespace uvc {
@@ -231,8 +229,7 @@ struct device {
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = width;
fmt.fmt.pix.height = height;
// fmt.fmt.pix.pixelformat = format;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.pixelformat = format;
fmt.fmt.pix.field = V4L2_FIELD_NONE;
// fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
if (xioctl(fd, VIDIOC_S_FMT, &fmt) < 0)
@@ -451,10 +448,9 @@ void set_control(
}
void set_device_mode(
device &device, int width, int height, uint32_t fourcc, int fps, // NOLINT
device &device, int width, int height, int fourcc, int fps, // NOLINT
video_channel_callback callback) {
device.set_format(
width, height, (const big_endian<int> &)fourcc, fps, callback);
device.set_format(width, height, fourcc, fps, callback);
}
void start_streaming(device &device, int /*num_transfer_bufs*/) { // NOLINT

View File

@@ -47,7 +47,7 @@ void set_control(
typedef std::function<void(const void *frame)> video_channel_callback;
void set_device_mode(
device &device, int width, int height, uint32_t fourcc, int fps, // NOLINT
device &device, int width, int height, int fourcc, int fps, // NOLINT
video_channel_callback callback);
void start_streaming(device &device, int num_transfer_bufs); // NOLINT
void stop_streaming(device &device); // NOLINT