MYNT-EYE-S-SDK/src/internal/streams.h

94 lines
2.9 KiB
C
Raw Permalink 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-04-08 07:23:33 +03:00
#ifndef MYNTEYE_INTERNAL_STREAMS_H_ // NOLINT
#define MYNTEYE_INTERNAL_STREAMS_H_
#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>
2018-04-08 17:35:49 +03:00
#include <mutex>
2018-04-08 07:23:33 +03:00
#include <vector>
#include "mynteye/callbacks.h"
2018-04-08 07:23:33 +03:00
#include "mynteye/mynteye.h"
#include "mynteye/types.h"
MYNTEYE_BEGIN_NAMESPACE
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::vector<Stream> key_streams);
2018-04-08 07:23:33 +03:00
~Streams();
void ConfigStream(
const Capabilities &capability, const StreamRequest &request);
void PushStream(const Capabilities &capability, const void *data);
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 Stream &stream, const StreamRequest &request);
void AllocStreamData(
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
};
MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_INTERNAL_STREAMS_H_ NOLINT