refactor(*): change stream request and params interfaces

This commit is contained in:
John Zhao
2018-12-20 17:10:18 +08:00
parent 098b307260
commit d2a32e0ec1
37 changed files with 491 additions and 375 deletions

View File

@@ -28,6 +28,8 @@
MYNTEYE_BEGIN_NAMESPACE
struct DeviceInfo;
class Device;
class Synthetic;
@@ -93,25 +95,6 @@ class MYNTEYE_API API {
explicit API(std::shared_ptr<Device> device);
virtual ~API();
/**
* Create the API instance.
* @return the API instance.
* @note This will call device::select() to select a device.
*/
static std::shared_ptr<API> Create(Resolution res);
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(
std::shared_ptr<Device> device, Resolution res);
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(std::shared_ptr<Device> device);
/**
* Create the API instance.
* @param argc the arg count.
@@ -130,7 +113,7 @@ class MYNTEYE_API API {
* @note This will init glog with args.
*/
static std::shared_ptr<API> Create(
int argc, char *argv[], std::shared_ptr<Device> device);
int argc, char *argv[], const std::shared_ptr<Device> &device);
/**
* Get the model.
@@ -155,9 +138,10 @@ class MYNTEYE_API API {
bool Supports(const AddOns &addon) const;
/**
* set the stream request.
* Log all stream requests and prompt user to select one.
*/
void SetStreamRequest(const Format &format, const FrameRate &rate);
StreamRequest SelectStreamRequest(bool *ok) const;
/**
* Get all stream requests of the capability.
*/
@@ -168,7 +152,28 @@ class MYNTEYE_API API {
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the config stream requests of the capability.
*/
const StreamRequest &GetStreamRequest(const Capabilities &capability) const;
/**
* Get all stream requests of the key stream capability.
*/
const std::vector<StreamRequest> &GetStreamRequests() const;
/**
* Config the stream request to the key stream capability.
*/
void ConfigStreamRequest(const StreamRequest &request);
/**
* Get the config stream requests of the key stream capability.
*/
const StreamRequest &GetStreamRequest() const;
/**
* Get the device info.
*/
std::shared_ptr<DeviceInfo> GetInfo() const;
/**
* Get the device info.
*/
@@ -214,11 +219,6 @@ class MYNTEYE_API API {
*/
bool RunOptionAction(const Option &option) const;
/**
* Init device resolution.
*/
void InitResolution(const Resolution &res);
/**
* Set the callback of stream.
*/

View File

@@ -32,8 +32,8 @@ namespace device {
typedef struct ImgParams {
bool ok;
std::map<Resolution, Intrinsics> in_left_map;
std::map<Resolution, Intrinsics> in_right_map;
Intrinsics in_left;
Intrinsics in_right;
Extrinsics ex_right_to_left;
} img_params_t;

View File

@@ -104,14 +104,7 @@ class MYNTEYE_API Device {
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
/**
* Init device resolution.
*/
void InitResolution(const Resolution &res);
/**
* set the stream request.
*/
void SetStreamRequest(const Format &format, const FrameRate &rate);
/**
* Get all stream requests of the capability.
*/
@@ -122,6 +115,23 @@ class MYNTEYE_API Device {
*/
void ConfigStreamRequest(
const Capabilities &capability, const StreamRequest &request);
/**
* Get the config stream requests of the capability.
*/
const StreamRequest &GetStreamRequest(const Capabilities &capability) const;
/**
* Get all stream requests of the key stream capability.
*/
const std::vector<StreamRequest> &GetStreamRequests() const;
/**
* Config the stream request to the key stream capability.
*/
void ConfigStreamRequest(const StreamRequest &request);
/**
* Get the config stream requests of the key stream capability.
*/
const StreamRequest &GetStreamRequest() const;
/**
* Get the device info.
@@ -241,15 +251,15 @@ class MYNTEYE_API Device {
*/
void WaitForStreams();
/**
* Get the latest data of stream.
*/
device::StreamData GetStreamData(const Stream &stream);
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
std::vector<device::StreamData> GetStreamDatas(const Stream &stream);
/**
* Get the latest data of stream.
*/
device::StreamData GetLatestStreamData(const Stream &stream);
/**
* Enable cache motion datas.
@@ -263,10 +273,6 @@ class MYNTEYE_API Device {
* Get the motion datas.
*/
std::vector<device::MotionData> GetMotionDatas();
/**
* Get the device img params
*/
img_params_t GetImgParams();
protected:
std::shared_ptr<uvc::device> device() const {
@@ -285,8 +291,6 @@ class MYNTEYE_API Device {
return motions_;
}
const StreamRequest &GetStreamRequest(const Capabilities &capability);
virtual void StartVideoStreaming();
virtual void StopVideoStreaming();
@@ -295,25 +299,33 @@ class MYNTEYE_API Device {
virtual void OnStereoStreamUpdate();
virtual Capabilities GetKeyStreamCapability() const = 0;
virtual std::vector<Stream> GetKeyStreams() const = 0;
std::map<Resolution, device::img_params_t> GetImgParams() const {
return all_img_params_;
}
device::imu_params_t GetImuParams() const {
return imu_params_;
}
bool video_streaming_;
bool motion_tracking_;
private:
Model model_;
Resolution res_ = Resolution::RES_752x480;
StreamRequest request_;
std::shared_ptr<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_;
std::map<Resolution, device::img_params_t> all_img_params_;
device::imu_params_t imu_params_;
std::map<Stream, Intrinsics> stream_intrinsics_;
std::map<Stream, std::map<Stream, Extrinsics>> stream_from_extrinsics_;
std::shared_ptr<MotionIntrinsics> motion_intrinsics_;
std::map<Stream, Extrinsics> motion_from_extrinsics_;
img_params_t img_params_;
stream_callbacks_t stream_callbacks_;
motion_callback_t motion_callback_;
@@ -331,8 +343,8 @@ class MYNTEYE_API Device {
std::shared_ptr<Motions> motions_;
void ReadAllInfos();
void ConfigIntrinsics(const Resolution &res);
void UpdateStreamIntrinsics(
const Capabilities &capability, const StreamRequest &request);
void CallbackPushedStreamData(const Stream &stream);
void CallbackMotionData(const device::MotionData &data);

View File

@@ -19,6 +19,7 @@
#include <string>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
@@ -39,6 +40,16 @@ namespace device {
*/
MYNTEYE_API std::shared_ptr<Device> select();
/**
* @ingroup utils
*
* List stream requests and prompt user to select one.
*
* @return the selected request.
*/
MYNTEYE_API MYNTEYE_NAMESPACE::StreamRequest select_request(
const std::shared_ptr<Device> &device, bool *ok);
} // namespace device
namespace utils {
@@ -58,14 +69,14 @@ MYNTEYE_API float get_real_exposure_time(
/**
* @ingroup utils
*
*
* Get sdk root dir.
*/
MYNTEYE_API std::string get_sdk_root_dir();
/**
* @ingroup utils
*
*
* Get sdk install dir.
*/
MYNTEYE_API std::string get_sdk_install_dir();

View File

@@ -37,6 +37,8 @@ MYNTEYE_BEGIN_NAMESPACE
enum class Model : std::uint8_t {
/** Standard */
STANDARD,
/** Standard 2 */
STANDARD2,
/** Last guard */
LAST
};
@@ -74,10 +76,10 @@ enum class Stream : std::uint8_t {
enum class Capabilities : std::uint8_t {
/** Provides stereo stream */
STEREO,
/** Provide stereo color stream */
STEREO_COLOR,
/** Provides color stream */
COLOR,
/** Provide stereo color stream */
STEREO_COLOR,
/** Provides depth stream */
DEPTH,
/** Provides point cloud stream */
@@ -143,6 +145,7 @@ enum class Option : std::uint8_t {
* range: [0,255], default: 127
*/
CONTRAST,
/**
* Image frame rate, must set IMU_FREQUENCY together
*
@@ -155,6 +158,7 @@ enum class Option : std::uint8_t {
* values: {100,200,250,333,500}, default: 200
*/
IMU_FREQUENCY,
/**
* Exposure mode
*
@@ -174,12 +178,19 @@ enum class Option : std::uint8_t {
* range: [0,1000], default: 333
*/
MAX_EXPOSURE_TIME,
/**
* min exposure time, valid if auto-exposure
*
* range: [0,1000], default: 0
*/
MIN_EXPOSURE_TIME,
/**
* Desired brightness, valid if auto-exposure
*
* range: [1,255], default: 122
*/
DESIRED_BRIGHTNESS,
/**
* IR control
*
@@ -193,16 +204,7 @@ enum class Option : std::uint8_t {
* 1: 12-bit
*/
HDR_MODE,
/** Zero drift calibration */
ZERO_DRIFT_CALIBRATION,
/** Erase chip */
ERASE_CHIP,
/**
* min exposure time, valid if auto-exposure
*
* range: [0,1000], default: 0
*/
MIN_EXPOSURE_TIME,
/**
* The range of accelerometer
*
@@ -227,6 +229,12 @@ enum class Option : std::uint8_t {
* values: {23,64}, default: 64
*/
GYROSCOPE_LOW_PASS_FILTER,
/** Zero drift calibration */
ZERO_DRIFT_CALIBRATION,
/** Erase chip */
ERASE_CHIP,
/** Last guard */
LAST
};
@@ -259,40 +267,6 @@ enum class AddOns : std::uint8_t {
LAST
};
/**
* @ingroup enumerations
* @brief Camera supported resolution.
*/
enum class Resolution : std::uint8_t {
/** 752x480 */
RES_752x480,
/** 1280x400 */
RES_1280x400,
/** 2560x800 */
RES_2560x800,
/** Last guard */
LAST
};
/**
* @ingroup enumerations
* @brief Camera supported frame rate.
*/
enum class FrameRate : std::uint8_t {
/** 10 fps */
RATE_10_FPS = 10,
/** 20 fps */
RATE_20_FPS = 20,
/** 20 fps */
RATE_25_FPS = 25,
/** 30 fps */
RATE_30_FPS = 30,
/** 60 fps */
RATE_60_FPS = 60,
/** Last guard */
LAST
};
#define MYNTEYE_ENUM_HELPERS(TYPE) \
MYNTEYE_API const char *to_string(const TYPE &value); \
inline bool is_valid(const TYPE &value) { \
@@ -316,8 +290,6 @@ MYNTEYE_ENUM_HELPERS(Info)
MYNTEYE_ENUM_HELPERS(Option)
MYNTEYE_ENUM_HELPERS(Source)
MYNTEYE_ENUM_HELPERS(AddOns)
MYNTEYE_ENUM_HELPERS(Resolution)
MYNTEYE_ENUM_HELPERS(FrameRate)
#undef MYNTEYE_ENUM_HELPERS
@@ -350,6 +322,26 @@ inline std::ostream &operator<<(std::ostream &os, const Format &value) {
MYNTEYE_API std::size_t bytes_per_pixel(const Format &value);
/**
* Resolution.
*/
struct MYNTEYE_API Resolution {
/** Width */
std::uint16_t width;
/** Height */
std::uint16_t height;
bool operator==(const Resolution &other) const {
return width == other.width && height == other.height;
}
bool operator!=(const Resolution &other) const {
return !(*this == other);
}
bool operator<(const Resolution &other) const {
return (width * height) < (other.width * other.height);
}
};
/**
* Stream request.
*/
@@ -370,25 +362,10 @@ struct MYNTEYE_API StreamRequest {
std::uint16_t fps)
: width(width), height(height), format(format), fps(fps) {}
StreamRequest(Resolution res, Format format, FrameRate rate)
: format(format) {
fps = static_cast<uint16_t>(rate);
StreamRequest(const Resolution &res, Format format, std::uint16_t fps)
: width(res.width), height(res.height), format(format), fps(fps) {}
switch (res) {
case Resolution::RES_752x480:
width = 480, height = 752;
break;
case Resolution::RES_1280x400:
width = 1280, height = 400;
break;
case Resolution::RES_2560x800:
width = 2560, height = 800;
break;
default:
width = 480, height = 752;
break;
}
}
Resolution GetResolution() const { return {width, height}; }
bool operator==(const StreamRequest &other) const {
return width == other.width && height == other.height &&