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

View File

@ -10,6 +10,8 @@
#include <mutex>
#include "mynteye/mynteye.h"
#include "internal/types.h"
#include "uvc/uvc.h"
struct glog_init {
@ -66,13 +68,14 @@ int main(int argc, char *argv[]) {
size_t n = mynteye_devices.size();
LOG_IF(FATAL, n <= 0) << "No MYNT EYE devices :(";
LOG(INFO) << "MYNT EYE devices: ";
for (size_t i = 0; i < n; i++) {
auto device = mynteye_devices[i];
auto name = uvc::get_video_name(*device);
auto vid = uvc::get_vendor_id(*device);
auto pid = uvc::get_product_id(*device);
LOG(INFO) << "index: " << i << ", name: " << name << ", vid: " << vid
<< ", pid: " << pid;
LOG(INFO) << " index: " << i << ", name: " << name << ", vid: 0x"
<< std::hex << vid << ", pid: 0x" << std::hex << pid;
}
std::shared_ptr<uvc::device> device = nullptr;
@ -101,7 +104,7 @@ int main(int argc, char *argv[]) {
const auto frame_empty = [&frames]() { return frames.empty(); };
uvc::set_device_mode(
*device, 752, 480, 0, 25,
*device, 752, 480, static_cast<int>(Format::YUYV), 25,
[&mtx, &cv, &frames, &frame_ready](const void *data) {
// reinterpret_cast<const std::uint8_t *>(data);
std::unique_lock<std::mutex> lock(mtx);

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