diff --git a/include/mynteye/types.h b/include/mynteye/types.h index ac8a459..b0961e7 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -101,7 +101,7 @@ enum class Info : std::uint8_t { /** Nominal baseline */ NOMINAL_BASELINE, /** Last guard */ - LAST, + LAST }; /** @@ -146,7 +146,7 @@ enum class Option : std::uint8_t { /** Erase chip */ ERASE_CHIP, /** Last guard */ - LAST, + LAST }; #define MYNTEYE_ENUM_HELPERS(TYPE) \ @@ -173,6 +173,43 @@ MYNTEYE_ENUM_HELPERS(Option) #undef MYNTEYE_ENUM_HELPERS +#define MYNTEYE_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 + +/** + * @ingroup enumerations + * @brief Formats define how each stream can be encoded. + */ +enum class Format : std::uint32_t { + /** YUV 4:2:2, 16 bits per pixel */ + YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'), + /** Last guard */ + LAST +}; + +#undef MYNTEYE_FOURCC + +const char *to_string(const Format &value); + +inline std::ostream &operator<<(std::ostream &os, const Format &value) { + return os << to_string(value); +} + +/** + * Stream request. + */ +struct MYNTEYE_API StreamRequest { + /** width in pixels */ + std::uint16_t width; + /** height in pixels */ + std::uint16_t height; + /** stream pixel format */ + Format format; + /** frames per second */ + std::uint16_t fps; +}; + /** * @defgroup calibration Intrinsics & Extrinsics * @brief Intrinsic and extrinsic properties. @@ -180,9 +217,9 @@ MYNTEYE_ENUM_HELPERS(Option) /** * @ingroup calibration - * Video stream intrinsics. + * Image intrinsics. */ -struct MYNTEYE_API Intrinsics { +struct MYNTEYE_API ImgIntrinsics { /** width of the image in pixels */ std::uint16_t width; /** height of the image in pixels */ @@ -232,13 +269,29 @@ struct MYNTEYE_API ImuIntrinsics { /** * @ingroup calibration - * Cross-stream extrinsics, represent how the different devices are connected. + * Extrinsics, represent how the different datas are connected. */ struct MYNTEYE_API Extrinsics { double rotation[3][3]; /**< rotation matrix */ double translation[3]; /**< translation vector */ }; +/** + * @ingroup calibration + * Image extrinsics. + */ +struct MYNTEYE_API ImgExtrinsics { + Extrinsics left_to_right; +}; + +/** + * @ingroup calibration + * IMU extrinsics. + */ +struct MYNTEYE_API ImuExtrinsics { + Extrinsics left_to_imu; +}; + /** * @defgroup datatypes Datatypes * @brief Public data types. diff --git a/samples/uvc/camera.cc b/samples/uvc/camera.cc index b123648..2bf8a0b 100644 --- a/samples/uvc/camera.cc +++ b/samples/uvc/camera.cc @@ -8,8 +8,7 @@ #include #include "mynteye/mynteye.h" - -#include "internal/types.h" +#include "mynteye/types.h" #include "uvc/uvc.h" #include "glog_init.h" // NOLINT diff --git a/src/device/device.cc b/src/device/device.cc index 335bc66..2d6e8b2 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -13,6 +13,7 @@ MYNTEYE_BEGIN_NAMESPACE Device::Device(const Model &model, std::shared_ptr device) : model_(model), device_(device) { VLOG(2) << __func__; + ReadDeviceInfo(); } Device::~Device() { @@ -79,4 +80,61 @@ std::string Device::GetInfo(const Info &info) const { } } +ImgIntrinsics Device::GetImgIntrinsics() const { + return img_intrinsics_; +} + +ImgExtrinsics Device::GetImgExtrinsics() const { + return img_extrinsics_; +} + +ImuIntrinsics Device::GetImuIntrinsics() const { + return imu_intrinsics_; +} + +ImuExtrinsics Device::GetImuExtrinsics() const { + return imu_extrinsics_; +} + +void Device::SetStreamCallback( + const Stream &stream, stream_callback_t callback) { + if (!Supports(stream)) { + LOG(WARNING) << "Unsupported stream: " << to_string(stream); + return; + } + if (callback) { + stream_callbacks_[stream] = callback; + } else { + stream_callbacks_.erase(stream); + } +} + +void Device::SetMotionCallback(motion_callback_t callback) { + motion_callback_ = callback; +} + +void Device::ReadDeviceInfo() { + // TODO(JohnZhao): Read device info +} + +void Device::WriteImgIntrinsics(const ImgIntrinsics &intrinsics) { + // TODO(JohnZhao): Write img intrinsics + UNUSED(intrinsics); +} + +void Device::WriteImgExtrinsics(const ImgExtrinsics &extrinsics) { + // TODO(JohnZhao): Write img extrinsics + UNUSED(extrinsics); +} + +void Device::WriteImuIntrinsics(const ImuIntrinsics &intrinsics) { + // TODO(JohnZhao): Write imu intrinsics + UNUSED(intrinsics); +} + +void Device::WriteImuExtrinsics(const ImuExtrinsics &extrinsics) { + // TODO(JohnZhao): Write imu extrinsics + UNUSED(extrinsics); +} + MYNTEYE_END_NAMESPACE diff --git a/src/device/device.h b/src/device/device.h index 153f77b..732a1b7 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -2,12 +2,15 @@ #define MYNTEYE_DEVICE_H_ #pragma once +#include #include #include #include "mynteye/mynteye.h" #include "mynteye/types.h" +#include "internal/callbacks.h" + MYNTEYE_BEGIN_NAMESPACE namespace uvc { @@ -20,12 +23,21 @@ struct DeviceInfo; class Device { public: + using stream_callback_t = device::StreamCallback; + using motion_callback_t = device::MotionCallback; + + using stream_callbacks_t = std::map; + Device(const Model &model, std::shared_ptr device); virtual ~Device(); static std::shared_ptr Create( const std::string &name, std::shared_ptr device); + Model GetModel() const { + return model_; + } + bool Supports(const Stream &stream) const; bool Supports(const Capabilities &capability) const; bool Supports(const Option &option) const; @@ -33,19 +45,46 @@ class Device { std::shared_ptr GetInfo() const; std::string GetInfo(const Info &info) const; - Model model() const { - return model_; - } + ImgIntrinsics GetImgIntrinsics() const; + ImgExtrinsics GetImgExtrinsics() const; + + ImuIntrinsics GetImuIntrinsics() const; + ImuExtrinsics GetImuExtrinsics() const; + + void SetStreamCallback(const Stream &stream, stream_callback_t callback); + void SetMotionCallback(motion_callback_t callback); protected: std::shared_ptr device() const { return device_; } + std::shared_ptr device_info() const { + return device_info_; + } + private: Model model_; std::shared_ptr device_; std::shared_ptr device_info_; + + ImgIntrinsics img_intrinsics_; + ImgExtrinsics img_extrinsics_; + ImuIntrinsics imu_intrinsics_; + ImuExtrinsics imu_extrinsics_; + + stream_callbacks_t stream_callbacks_; + motion_callback_t motion_callback_; + + void ReadDeviceInfo(); + + void WriteImgIntrinsics(const ImgIntrinsics &intrinsics); + void WriteImgExtrinsics(const ImgExtrinsics &extrinsics); + + void WriteImuIntrinsics(const ImuIntrinsics &intrinsics); + void WriteImuExtrinsics(const ImuExtrinsics &extrinsics); + + // friend DeviceWriter; }; MYNTEYE_END_NAMESPACE diff --git a/src/internal/callbacks.h b/src/internal/callbacks.h new file mode 100644 index 0000000..ec973f3 --- /dev/null +++ b/src/internal/callbacks.h @@ -0,0 +1,29 @@ +#ifndef MYNTEYE_INTERNAL_CALLBACKS_H_ // NOLINT +#define MYNTEYE_INTERNAL_CALLBACKS_H_ +#pragma once + +#include + +#include "mynteye/mynteye.h" +#include "mynteye/types.h" + +MYNTEYE_BEGIN_NAMESPACE + +namespace device { + +struct MYNTEYE_API StreamData { + ImgData img; +}; + +struct MYNTEYE_API MotionData { + ImuData imu; +}; + +using StreamCallback = std::function; +using MotionCallback = std::function; + +} // namespace device + +MYNTEYE_END_NAMESPACE + +#endif // MYNTEYE_INTERNAL_CALLBACKS_H_ NOLINT diff --git a/src/internal/types.h b/src/internal/types.h index 00da6f0..725d9a2 100644 --- a/src/internal/types.h +++ b/src/internal/types.h @@ -12,20 +12,6 @@ MYNTEYE_BEGIN_NAMESPACE -#define MYNTEYE_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 - -/** - * @ingroup enumerations - * @brief Formats define how each stream can be encoded. - */ -enum class Format : std::uint32_t { - YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'), -}; - -#undef MYNTEYE_FOURCC - #define MYNTEYE_PROPERTY(TYPE, NAME) \ public: \ void set_##NAME(TYPE NAME) { \ diff --git a/src/public/types.cc b/src/public/types.cc index 07220fd..9dbc97a 100644 --- a/src/public/types.cc +++ b/src/public/types.cc @@ -102,4 +102,16 @@ const char *to_string(const Option &value) { #undef CASE } +const char *to_string(const Format &value) { +#define CASE(X) \ + case Format::X: \ + return "Format::" #X; + switch (value) { + CASE(YUYV) + default: + return "Format::UNKNOWN"; + } +#undef CASE +} + MYNTEYE_END_NAMESPACE diff --git a/test/public/types_test.cc b/test/public/types_test.cc index bf38924..5369fa2 100644 --- a/test/public/types_test.cc +++ b/test/public/types_test.cc @@ -61,3 +61,7 @@ TEST(Option, VerifyToString) { to_string(Option::ZERO_DRIFT_CALIBRATION)); EXPECT_STREQ("Option::ERASE_CHIP", to_string(Option::ERASE_CHIP)); } + +TEST(Format, VerifyToString) { + EXPECT_STREQ("Format::YUYV", to_string(Format::YUYV)); +}