diff --git a/samples/uvc/camera.cc b/samples/uvc/camera.cc index 64dea2b..f5be80f 100644 --- a/samples/uvc/camera.cc +++ b/samples/uvc/camera.cc @@ -10,6 +10,8 @@ #include #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 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(Format::YUYV), 25, [&mtx, &cv, &frames, &frame_ready](const void *data) { // reinterpret_cast(data); std::unique_lock lock(mtx); diff --git a/src/internal/types.h b/src/internal/types.h new file mode 100644 index 0000000..8e1db19 --- /dev/null +++ b/src/internal/types.h @@ -0,0 +1,25 @@ +#ifndef MYNTEYE_INTERNAL_TYPES_H_ // NOLINT +#define MYNTEYE_INTERNAL_TYPES_H_ +#pragma once + +#include + +#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 diff --git a/src/types.h b/src/types.h deleted file mode 100644 index cb98bc2..0000000 --- a/src/types.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MYNTEYE_TYPES_H_ // NOLINT -#define MYNTEYE_TYPES_H_ -#pragma once - -#include "mynteye/mynteye.h" - -MYNTEYE_BEGIN_NAMESPACE - -template -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(&le_value)[i] = - reinterpret_cast(&be_value)[sizeof(T) - i - 1]; - } - return le_value; - } -}; - -MYNTEYE_END_NAMESPACE - -#endif // MYNTEYE_TYPES_H_ NOLINT diff --git a/src/uvc/uvc-v4l2.cc b/src/uvc/uvc-v4l2.cc index 11c6035..d8d96a2 100644 --- a/src/uvc/uvc-v4l2.cc +++ b/src/uvc/uvc-v4l2.cc @@ -19,8 +19,6 @@ #include #include -#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 &)fourcc, fps, callback); + device.set_format(width, height, fourcc, fps, callback); } void start_streaming(device &device, int /*num_transfer_bufs*/) { // NOLINT diff --git a/src/uvc/uvc.h b/src/uvc/uvc.h index d30b615..992e77d 100644 --- a/src/uvc/uvc.h +++ b/src/uvc/uvc.h @@ -47,7 +47,7 @@ void set_control( typedef std::function 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