MYNT-EYE-S-SDK/include/mynteye/device/device.h

406 lines
9.9 KiB
C
Raw Normal View History

2018-05-10 09:46:34 +03:00
// Copyright 2018 Slightech Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2018-10-27 16:24:04 +03:00
#ifndef MYNTEYE_DEVICE_DEVICE_H_
#define MYNTEYE_DEVICE_DEVICE_H_
2018-04-04 05:50:27 +03:00
#pragma once
2019-10-17 08:48:37 +03:00
#include <sys/types.h>
// undef major & minor for 18.04 gcc
#undef major
#undef minor
2018-04-06 04:12:09 +03:00
#include <map>
2018-04-04 05:50:27 +03:00
#include <memory>
2018-06-01 11:50:15 +03:00
#include <mutex>
2018-04-04 05:50:27 +03:00
#include <string>
2018-04-08 07:23:33 +03:00
#include <vector>
2018-04-04 05:50:27 +03:00
#include "mynteye/mynteye.h"
2018-10-27 16:24:04 +03:00
#include "mynteye/device/callbacks.h"
#include "mynteye/device/types.h"
2018-04-04 05:50:27 +03:00
MYNTEYE_BEGIN_NAMESPACE
namespace uvc {
struct device;
} // namespace uvc
2018-04-21 10:45:33 +03:00
namespace tools {
class DeviceWriter;
} // namespace tools
2018-04-04 10:52:10 +03:00
struct DeviceInfo;
2018-04-26 09:44:47 +03:00
class API;
2018-04-09 17:24:34 +03:00
class Channels;
class ChannelsAdapter;
2018-04-12 06:48:09 +03:00
class Motions;
2018-04-08 07:23:33 +03:00
class Streams;
class StreamsAdapter;
2018-04-08 07:23:33 +03:00
2018-05-31 10:39:42 +03:00
template <class Data>
class AsyncCallback;
2018-05-16 05:31:31 +03:00
/**
* The Device class to communicate with MYNT® EYE device.
*/
2018-04-23 18:11:11 +03:00
class MYNTEYE_API Device {
2018-04-04 05:50:27 +03:00
public:
2018-05-16 05:31:31 +03:00
/** The device::StreamData callback. */
2018-04-06 04:12:09 +03:00
using stream_callback_t = device::StreamCallback;
2018-05-16 05:31:31 +03:00
/** The device::MotionData callback. */
2018-04-06 04:12:09 +03:00
using motion_callback_t = device::MotionCallback;
using stream_callbacks_t = std::map<Stream, stream_callback_t>;
2018-05-31 10:39:42 +03:00
using stream_async_callback_t = AsyncCallback<device::StreamData>;
using motion_async_callback_t = AsyncCallback<device::MotionData>;
using stream_async_callback_ptr_t = std::shared_ptr<stream_async_callback_t>;
using motion_async_callback_ptr_t = std::shared_ptr<motion_async_callback_t>;
using img_params_t = device::img_params_t;
using img_params_map_t = std::map<Resolution, img_params_t>;
using imu_params_t = device::imu_params_t;
protected:
Device(const Model &model,
const std::shared_ptr<uvc::device> &device,
const std::shared_ptr<StreamsAdapter> &streams_adapter,
const std::shared_ptr<ChannelsAdapter> &channels_adapter);
public:
2018-04-04 05:50:27 +03:00
virtual ~Device();
2018-05-16 05:31:31 +03:00
/**
* Create the Device instance.
* @param name the device name.
* @param device the device from uvc.
* @return the Device instance.
*/
2018-04-04 05:50:27 +03:00
static std::shared_ptr<Device> Create(
const std::string &name, std::shared_ptr<uvc::device> device);
2018-05-16 05:31:31 +03:00
/**
* Get the model.
*/
2018-04-06 04:12:09 +03:00
Model GetModel() const {
return model_;
}
2018-05-16 05:31:31 +03:00
/**
* Supports the stream or not.
*/
2018-04-04 10:52:10 +03:00
bool Supports(const Stream &stream) const;
2018-05-16 05:31:31 +03:00
/**
* Supports the capability or not.
*/
2018-04-04 10:52:10 +03:00
bool Supports(const Capabilities &capability) const;
2018-05-16 05:31:31 +03:00
/**
* Supports the option or not.
*/
2018-04-04 10:52:10 +03:00
bool Supports(const Option &option) const;
2018-05-16 05:31:31 +03:00
/**
* Supports the addon or not.
*/
bool Supports(const AddOns &addon) const;
2018-05-16 05:31:31 +03:00
/**
* Get all stream requests of the capability.
*/
2018-04-08 07:23:33 +03:00
const std::vector<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;
2018-05-16 05:31:31 +03:00
/**
* Config the stream request to the capability.
*/
2018-04-08 07:23:33 +03:00
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;
2018-04-08 07:23:33 +03:00
2018-05-16 05:31:31 +03:00
/**
* Get the device info.
*/
2018-04-04 10:52:10 +03:00
std::shared_ptr<DeviceInfo> GetInfo() const;
2018-05-16 05:31:31 +03:00
/**
* Get the device info of a field.
*/
2018-04-04 10:52:10 +03:00
std::string GetInfo(const Info &info) const;
2018-05-16 05:31:31 +03:00
/**
* Get the intrinsics of stream.
*/
std::shared_ptr<IntrinsicsBase> GetIntrinsics(const Stream &stream) const;
2018-05-16 05:31:31 +03:00
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
2018-05-16 05:31:31 +03:00
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics() const;
2018-05-16 05:31:31 +03:00
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from) const;
2018-04-06 04:12:09 +03:00
2018-06-12 10:58:13 +03:00
/**
* Get the intrinsics of stream.
*/
std::shared_ptr<IntrinsicsBase> GetIntrinsics(
const Stream &stream, bool *ok) const;
2018-06-12 10:58:13 +03:00
/**
* Get the extrinsics from one stream to another.
*/
Extrinsics GetExtrinsics(
const Stream &from, const Stream &to, bool *ok) const;
/**
* Get the intrinsics of motion.
*/
MotionIntrinsics GetMotionIntrinsics(bool *ok) const;
/**
* Get the extrinsics from one stream to motion.
*/
Extrinsics GetMotionExtrinsics(const Stream &from, bool *ok) const;
2018-05-16 05:31:31 +03:00
/**
* Set the intrinsics of stream.
*/
void SetIntrinsics(const Stream &stream,
const std::shared_ptr<IntrinsicsBase> &in);
2018-05-16 05:31:31 +03:00
/**
* Set the extrinsics from one stream to another.
*/
void SetExtrinsics(
const Stream &from, const Stream &to, const Extrinsics &ex);
2018-05-16 05:31:31 +03:00
/**
* Set the intrinsics of motion.
*/
void SetMotionIntrinsics(const MotionIntrinsics &in);
2018-05-16 05:31:31 +03:00
/**
* Set the extrinsics from one stream to motion.
*/
void SetMotionExtrinsics(const Stream &from, const Extrinsics &ex);
2018-04-06 04:12:09 +03:00
2018-05-16 05:31:31 +03:00
/**
* Log all option infos.
*/
2018-04-10 11:00:38 +03:00
void LogOptionInfos() const;
2018-05-16 05:31:31 +03:00
/**
* Get the option info.
*/
2018-04-09 19:26:22 +03:00
OptionInfo GetOptionInfo(const Option &option) const;
2018-04-10 11:00:38 +03:00
2018-05-16 05:31:31 +03:00
/**
* Get the option value.
*/
2018-04-09 19:26:22 +03:00
std::int32_t GetOptionValue(const Option &option) const;
2018-05-16 05:31:31 +03:00
/**
* Set the option value.
*/
2018-04-09 19:26:22 +03:00
void SetOptionValue(const Option &option, std::int32_t value);
/**
* Set the option value.
*/
bool SetOptionValue(const Option &option, std::uint64_t value);
2018-04-10 11:00:38 +03:00
2018-05-16 05:31:31 +03:00
/**
* Run the option action.
*/
2018-04-10 11:00:38 +03:00
bool RunOptionAction(const Option &option) const;
2018-04-09 19:26:22 +03:00
2018-05-16 05:31:31 +03:00
/**
* Set the callback of stream.
*/
2018-05-31 10:39:42 +03:00
void SetStreamCallback(
const Stream &stream, stream_callback_t callback, bool async = false);
2018-05-16 05:31:31 +03:00
/**
* Set the callback of motion.
*/
2018-05-31 10:39:42 +03:00
void SetMotionCallback(motion_callback_t callback, bool async = false);
2018-04-04 10:52:10 +03:00
2018-05-16 05:31:31 +03:00
/**
* Has the callback of stream.
*/
2018-04-08 17:35:49 +03:00
bool HasStreamCallback(const Stream &stream) const;
2018-05-16 05:31:31 +03:00
/**
* Has the callback of motion.
*/
2018-04-08 17:35:49 +03:00
bool HasMotionCallback() const;
2018-05-16 05:31:31 +03:00
/**
* Start capturing the source.
*/
2018-04-07 04:36:41 +03:00
virtual void Start(const Source &source);
2018-05-16 05:31:31 +03:00
/**
* Stop capturing the source.
*/
2018-04-07 04:36:41 +03:00
virtual void Stop(const Source &source);
2018-05-16 05:31:31 +03:00
/**
* Wait the streams are ready.
*/
2018-04-08 17:35:49 +03:00
void WaitForStreams();
/**
* Get the latest data of stream.
*/
device::StreamData GetStreamData(const Stream &stream);
/**
* @deprecated Replaced by GetStreamData(const Stream &stream)
*/
device::StreamData GetLatestStreamData(const Stream &stream);
2018-05-16 05:31:31 +03:00
/**
* Get the datas of stream.
* @note default cache 4 datas at most.
*/
2018-04-08 17:35:49 +03:00
std::vector<device::StreamData> GetStreamDatas(const Stream &stream);
2019-02-21 16:19:52 +02:00
/**
* Disable cache motion datas.
*/
void DisableMotionDatas();
2018-05-16 05:31:31 +03:00
/**
* Enable cache motion datas.
*/
2018-11-01 14:42:44 +02:00
void EnableMotionDatas();
/**
* Enable motion datas timestamp correspondence.
*/
void EnableImuCorrespondence(bool is_enable);
2018-11-01 14:42:44 +02:00
/**
* Enable cache motion datas.
*/
void EnableMotionDatas(std::size_t max_size);
2018-05-16 05:31:31 +03:00
/**
* Get the motion datas.
*/
2018-04-12 06:48:09 +03:00
std::vector<device::MotionData> GetMotionDatas();
2019-03-15 13:46:20 +02:00
/** Enable process mode, e.g. imu assembly, temp_drift */
void EnableProcessMode(const ProcessMode& mode);
/** Enable process mode, e.g. imu assembly, temp_drift */
void EnableProcessMode(const std::int32_t& mode);
bool CheckImageParams();
2018-04-04 10:52:10 +03:00
protected:
std::shared_ptr<uvc::device> device() const {
return device_;
}
std::shared_ptr<Streams> streams() const {
return streams_;
}
std::shared_ptr<Channels> channels() const {
return channels_;
}
std::shared_ptr<Motions> motions() const {
return motions_;
}
2018-04-07 04:36:41 +03:00
virtual void StartVideoStreaming();
virtual void StopVideoStreaming();
virtual void StartMotionTracking();
virtual void StopMotionTracking();
virtual void OnStereoStreamUpdate();
virtual Capabilities GetKeyStreamCapability() const = 0;
2018-04-08 17:35:49 +03:00
img_params_map_t GetImgParams() const {
return all_img_params_;
}
imu_params_t GetImuParams() const {
return imu_params_;
}
2018-04-08 07:23:33 +03:00
bool video_streaming_;
bool motion_tracking_;
2018-04-04 05:50:27 +03:00
private:
2018-04-04 10:52:10 +03:00
Model model_;
std::shared_ptr<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_;
2018-04-06 04:12:09 +03:00
img_params_map_t all_img_params_;
imu_params_t imu_params_;
std::map<Stream, std::shared_ptr<IntrinsicsBase>> 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_;
2018-04-06 04:12:09 +03:00
stream_callbacks_t stream_callbacks_;
motion_callback_t motion_callback_;
2018-05-31 10:39:42 +03:00
std::map<Stream, stream_async_callback_ptr_t> stream_async_callbacks_;
motion_async_callback_ptr_t motion_async_callback_;
2018-04-08 07:23:33 +03:00
std::shared_ptr<Streams> streams_;
std::map<Capabilities, StreamRequest> stream_config_requests_;
2018-06-01 11:50:15 +03:00
std::mutex mtx_streams_;
2018-04-09 17:24:34 +03:00
std::shared_ptr<Channels> channels_;
2018-04-12 06:48:09 +03:00
std::shared_ptr<Motions> motions_;
2018-04-13 16:55:32 +03:00
void ReadAllInfos();
void UpdateStreamIntrinsics(
const Capabilities &capability, const StreamRequest &request);
2018-09-14 15:00:28 +03:00
2018-05-31 10:39:42 +03:00
void CallbackPushedStreamData(const Stream &stream);
void CallbackMotionData(const device::MotionData &data);
bool GetFiles(
DeviceInfo *info, img_params_map_t *img_params, imu_params_t *imu_params);
bool SetFiles(
DeviceInfo *info, img_params_map_t *img_params, imu_params_t *imu_params);
bool is_default_intrinsics_;
2018-04-26 09:44:47 +03:00
friend API;
2018-04-21 10:45:33 +03:00
friend tools::DeviceWriter;
2018-04-04 05:50:27 +03:00
};
MYNTEYE_END_NAMESPACE
2018-10-27 16:24:04 +03:00
#endif // MYNTEYE_DEVICE_DEVICE_H_