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
|
|
|
|
|
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-04-04 10:52:10 +03:00
|
|
|
#include "mynteye/types.h"
|
2018-10-27 16:24:04 +03:00
|
|
|
#include "mynteye/device/callbacks.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;
|
2018-04-12 06:48:09 +03:00
|
|
|
class Motions;
|
2018-04-08 07:23:33 +03:00
|
|
|
class Streams;
|
2018-12-20 18:23:42 +02:00
|
|
|
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>;
|
|
|
|
|
2018-11-27 08:50:12 +02:00
|
|
|
using img_params_t = device::img_params_t;
|
|
|
|
using imu_params_t = device::imu_params_t;
|
|
|
|
|
2018-04-04 10:52:10 +03:00
|
|
|
Device(const Model &model, std::shared_ptr<uvc::device> device);
|
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.
|
|
|
|
*/
|
2018-05-04 10:57:12 +03:00
|
|
|
bool Supports(const AddOns &addon) const;
|
2018-12-20 11:10:18 +02:00
|
|
|
|
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);
|
2018-12-20 11:10:18 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
Intrinsics GetIntrinsics(const Stream &stream) const;
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Get the extrinsics from one stream to another.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
Extrinsics GetExtrinsics(const Stream &from, const Stream &to) const;
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Get the intrinsics of motion.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
MotionIntrinsics GetMotionIntrinsics() const;
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Get the extrinsics from one stream to motion.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
Intrinsics GetIntrinsics(const Stream &stream, bool *ok) const;
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
void SetIntrinsics(const Stream &stream, const Intrinsics &in);
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Set the extrinsics from one stream to another.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
void SetExtrinsics(
|
|
|
|
const Stream &from, const Stream &to, const Extrinsics &ex);
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Set the intrinsics of motion.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
void SetMotionIntrinsics(const MotionIntrinsics &in);
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Set the extrinsics from one stream to motion.
|
|
|
|
*/
|
2018-04-19 17:44:40 +03:00
|
|
|
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);
|
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();
|
|
|
|
|
2018-12-20 11:10:18 +02:00
|
|
|
/**
|
|
|
|
* Get the latest data of stream.
|
|
|
|
*/
|
|
|
|
device::StreamData GetStreamData(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);
|
|
|
|
|
2018-05-16 05:31:31 +03:00
|
|
|
/**
|
|
|
|
* Enable cache motion datas.
|
|
|
|
*/
|
2018-11-01 14:42:44 +02:00
|
|
|
void EnableMotionDatas();
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2018-04-04 10:52:10 +03:00
|
|
|
protected:
|
|
|
|
std::shared_ptr<uvc::device> device() const {
|
|
|
|
return device_;
|
|
|
|
}
|
|
|
|
|
2018-06-07 06:19:58 +03:00
|
|
|
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();
|
|
|
|
|
2018-06-07 06:19:58 +03:00
|
|
|
virtual void OnStereoStreamUpdate();
|
|
|
|
|
2018-12-20 11:10:18 +02:00
|
|
|
virtual Capabilities GetKeyStreamCapability() const = 0;
|
2018-12-20 18:23:42 +02:00
|
|
|
virtual std::shared_ptr<StreamsAdapter> CreateStreamsAdapter() const = 0;
|
2018-04-08 17:35:49 +03:00
|
|
|
|
2018-12-20 11:10:18 +02:00
|
|
|
std::map<Resolution, device::img_params_t> GetImgParams() const {
|
|
|
|
return all_img_params_;
|
|
|
|
}
|
|
|
|
device::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
|
|
|
|
2018-12-20 11:10:18 +02:00
|
|
|
std::map<Resolution, device::img_params_t> all_img_params_;
|
|
|
|
device::imu_params_t imu_params_;
|
|
|
|
|
2018-04-19 17:44:40 +03:00
|
|
|
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_;
|
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();
|
2018-12-20 11:10:18 +02:00
|
|
|
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);
|
|
|
|
|
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_
|