MYNT-EYE-S-SDK/src/mynteye/device/streams.h

111 lines
3.3 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_STREAMS_H_
#define MYNTEYE_DEVICE_STREAMS_H_
2018-04-08 07:23:33 +03:00
#pragma once
2018-04-08 17:35:49 +03:00
#include <condition_variable>
#include <functional>
2018-04-08 07:23:33 +03:00
#include <map>
#include <memory>
2018-04-08 17:35:49 +03:00
#include <mutex>
2018-04-08 07:23:33 +03:00
#include <vector>
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
2018-10-27 16:24:04 +03:00
#include "mynteye/device/callbacks.h"
2018-04-08 07:23:33 +03:00
MYNTEYE_BEGIN_NAMESPACE
class StreamsAdapter;
2018-04-08 07:23:33 +03:00
class Streams {
public:
using frame_t = device::Frame;
using stream_data_t = device::StreamData;
using stream_datas_t = std::vector<stream_data_t>;
2018-04-09 04:24:08 +03:00
using unpack_img_data_t = std::function<bool(
2018-04-10 11:19:28 +03:00
const void *data, const StreamRequest &request, ImgData *img)>;
2018-04-09 04:24:08 +03:00
using unpack_img_pixels_t = std::function<bool(
2018-04-10 11:19:28 +03:00
const void *data, const StreamRequest &request, frame_t *frame)>;
2018-04-08 17:35:49 +03:00
explicit Streams(const std::shared_ptr<StreamsAdapter> &adapter);
2018-04-08 07:23:33 +03:00
~Streams();
void ConfigStream(
const Capabilities &capability, const StreamRequest &request);
2018-05-31 05:20:48 +03:00
bool PushStream(const Capabilities &capability, const void *data);
2018-04-08 07:23:33 +03:00
2018-04-08 17:35:49 +03:00
void WaitForStreams();
2018-04-08 07:23:33 +03:00
2018-04-12 04:54:54 +03:00
void ConfigStreamLimits(const Stream &stream, std::size_t max_data_size);
std::size_t GetStreamDataMaxSize(const Stream &stream) const;
2018-04-08 17:35:49 +03:00
stream_datas_t GetStreamDatas(const Stream &stream);
stream_data_t GetLatestStreamData(const Stream &stream);
2018-04-11 12:08:24 +03:00
const stream_datas_t &stream_datas(const Stream &stream);
2018-04-08 07:23:33 +03:00
private:
bool IsStreamCapability(const Capabilities &capability) const;
bool HasStreamConfigRequest(const Capabilities &capability) const;
const StreamRequest &GetStreamConfigRequest(
const Capabilities &capability) const;
bool HasStreamDatas(const Stream &stream) const;
2018-04-08 17:35:49 +03:00
void AllocStreamData(const Capabilities &capability,
const Stream &stream, const StreamRequest &request);
void AllocStreamData(const Capabilities &capability,
2018-04-08 17:35:49 +03:00
const Stream &stream, const StreamRequest &request, const Format &format);
2018-04-11 12:08:24 +03:00
void DiscardStreamData(const Stream &stream);
2018-04-08 17:35:49 +03:00
bool HasKeyStreamDatas() const;
std::vector<Stream> key_streams_;
2018-04-08 07:23:33 +03:00
std::vector<Capabilities> stream_capabilities_;
std::map<Capabilities, StreamRequest> stream_config_requests_;
2018-04-08 17:35:49 +03:00
std::map<Stream, unpack_img_data_t> unpack_img_data_map_;
std::map<Stream, unpack_img_pixels_t> unpack_img_pixels_map_;
2018-04-12 04:54:54 +03:00
std::map<Stream, std::size_t> stream_limits_map_;
2018-04-08 07:23:33 +03:00
std::map<Stream, stream_datas_t> stream_datas_map_;
2018-04-08 17:35:49 +03:00
std::mutex mtx_;
std::condition_variable cv_;
2018-04-08 07:23:33 +03:00
};
class StreamsAdapter {
public:
virtual ~StreamsAdapter() {}
virtual std::vector<Stream> GetKeyStreams() = 0;
virtual std::vector<Capabilities> GetStreamCapabilities() = 0;
virtual std::map<Stream, Streams::unpack_img_data_t>
GetUnpackImgDataMap() = 0;
virtual std::map<Stream, Streams::unpack_img_pixels_t>
GetUnpackImgPixelsMap() = 0;
};
2018-04-08 07:23:33 +03:00
MYNTEYE_END_NAMESPACE
2018-10-27 16:24:04 +03:00
#endif // MYNTEYE_DEVICE_STREAMS_H_