* G-API-NG/Streaming: Introduced a Streaming API Now a GComputation can be compiled in a special "streaming" way and then "played" on a video stream. Currently only VideoCapture is supported as an input source. * G-API-NG/Streaming: added threading & real streaming * G-API-NG/Streaming: Added tests & docs on Copy kernel - Added very simple pipeline tests, not all data types are covered yet (in fact, only GMat is tested now); - Started testing non-OCV backends in the streaming mode; - Added required fixes to Fluid backend, likely it works OK now; - Added required fixes to OCL backend, and now it is likely broken - Also added a UMat-based (OCL) version of Copy kernel * G-API-NG/Streaming: Added own concurrent queue class - Used only if TBB is not available * G-API-NG/Streaming: Fixing various issues - Added missing header to CMakeLists.txt - Fixed various CI issues and warnings * G-API-NG/Streaming: Fixed a compile-time GScalar queue deadlock - GStreamingExecutor blindly created island's input queues for compile-time (value-initialized) GScalars which didn't have any producers, making island actor threads wait there forever * G-API-NG/Streaming: Dropped own version of Copy kernel One was added into master already * G-API-NG/Streaming: Addressed GArray<T> review comments - Added tests on mov() - Removed unnecessary changes in garray.hpp * G-API-NG/Streaming: Added Doxygen comments to new public APIs Also fixed some other comments in the code * G-API-NG/Streaming: Removed debug info, added some comments & renamed vars * G-API-NG/Streaming: Fixed own-vs-cv abstraction leak - Now every island is triggered with own:: (instead of cv::) data objects as inputs; - Changes in Fluid backend required to support cv::Mat/Scalar were reverted; * G-API-NG/Streaming: use holds_alternative<> instead of index/index_of test - Also fixed regression test comments - Also added metadata check comments for GStreamingCompiled * G-API-NG/Streaming: Made start()/stop() more robust - Fixed various possible deadlocks - Unified the shutdown code - Added more tests covering different corner cases on start/stop * G-API-NG/Streaming: Finally fixed Windows crashes In fact the problem hasn't been Windows-only. Island thread popped data from queues without preserving the Cmd objects and without taking the ownership over data acquired so when islands started to process the data, this data may be already freed. Linux version worked only by occasion. * G-API-NG/Streaming: Fixed (I hope so) Windows warnings * G-API-NG/Streaming: fixed typos in internal comments - Also added some more explanation on Streaming/OpenCL status * G-API-NG/Streaming: Added more unit tests on streaming - Various start()/stop()/setSource() call flow combinations * G-API-NG/Streaming: Added tests on own concurrent bounded queue * G-API-NG/Streaming: Added more tests on various data types, + more - Vector/Scalar passed as input; - Vector/Scalar passed in-between islands; - Some more assertions; - Also fixed a deadlock problem when inputs are mixed (1 constant, 1 stream) * G-API-NG/Streaming: Added tests on output data types handling - Vector - Scalar * G-API-NG/Streaming: Fixed test issues with IE + Windows warnings * G-API-NG/Streaming: Decoupled G-API from videoio - Now the core G-API doesn't use a cv::VideoCapture directly, it comes in via an abstract interface; - Polished a little bit the setSource()/start()/stop() semantics, now setSource() is mandatory before ANY call to start(). * G-API-NG/Streaming: Fix STANDALONE build (errors brought by render)
130 lines
3.6 KiB
C++
130 lines
3.6 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
//
|
|
// Copyright (C) 2019 Intel Corporation
|
|
|
|
#ifndef OPENCV_GAPI_EXECUTOR_CONC_QUEUE_HPP
|
|
#define OPENCV_GAPI_EXECUTOR_CONC_QUEUE_HPP
|
|
|
|
#include <queue>
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
|
|
#include <opencv2/gapi/own/assert.hpp>
|
|
|
|
namespace cv {
|
|
namespace gapi {
|
|
namespace own {
|
|
|
|
// This class implements a bare minimum interface of TBB's
|
|
// concurrent_bounded_queue with only std:: stuff to make streaming
|
|
// API work without TBB.
|
|
//
|
|
// Highly inefficient, please use it as a last resort if TBB is not
|
|
// available in the build.
|
|
template<class T>
|
|
class concurrent_bounded_queue {
|
|
std::queue<T> m_data;
|
|
std::size_t m_capacity;
|
|
|
|
std::mutex m_mutex;
|
|
std::condition_variable m_cond_empty;
|
|
std::condition_variable m_cond_full;
|
|
|
|
void unsafe_pop(T &t);
|
|
|
|
public:
|
|
concurrent_bounded_queue() : m_capacity(0) {}
|
|
concurrent_bounded_queue(const concurrent_bounded_queue<T> &cc)
|
|
: m_data(cc.m_data), m_capacity(cc.m_capacity) {
|
|
// FIXME: what to do with all that locks, etc?
|
|
}
|
|
concurrent_bounded_queue(concurrent_bounded_queue<T> &&cc)
|
|
: m_data(std::move(cc.m_data)), m_capacity(cc.m_capacity) {
|
|
// FIXME: what to do with all that locks, etc?
|
|
}
|
|
|
|
// FIXME: && versions
|
|
void push(const T &t);
|
|
void pop(T &t);
|
|
bool try_pop(T &t);
|
|
|
|
void set_capacity(std::size_t capacity);
|
|
|
|
// Not thread-safe - as in TBB
|
|
void clear();
|
|
};
|
|
|
|
// Internal: do shared pop things assuming the lock is already there
|
|
template<typename T>
|
|
void concurrent_bounded_queue<T>::unsafe_pop(T &t) {
|
|
GAPI_Assert(!m_data.empty());
|
|
t = m_data.front();
|
|
m_data.pop();
|
|
}
|
|
|
|
// Push an element to the queue. Blocking if there's no space left
|
|
template<typename T>
|
|
void concurrent_bounded_queue<T>::push(const T& t) {
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
if (m_capacity && m_capacity == m_data.size()) {
|
|
// if there is a limit and it is reached, wait
|
|
m_cond_full.wait(lock, [&](){return m_capacity > m_data.size();});
|
|
GAPI_Assert(m_capacity > m_data.size());
|
|
}
|
|
m_data.push(t);
|
|
lock.unlock();
|
|
m_cond_empty.notify_one();
|
|
}
|
|
|
|
// Pop an element from the queue. Blocking if there's no items
|
|
template<typename T>
|
|
void concurrent_bounded_queue<T>::pop(T &t) {
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
if (m_data.empty()) {
|
|
// if there is no data, wait
|
|
m_cond_empty.wait(lock, [&](){return !m_data.empty();});
|
|
}
|
|
unsafe_pop(t);
|
|
lock.unlock();
|
|
m_cond_full.notify_one();
|
|
}
|
|
|
|
// Try pop an element from the queue. Returns false if queue is empty
|
|
template<typename T>
|
|
bool concurrent_bounded_queue<T>::try_pop(T &t) {
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
if (m_data.empty()) {
|
|
// if there is no data, return
|
|
return false;
|
|
}
|
|
unsafe_pop(t);
|
|
lock.unlock();
|
|
m_cond_full.notify_one();
|
|
return true;
|
|
}
|
|
|
|
// Specify the upper limit to the queue. Assumed to be called after
|
|
// queue construction but before any real use, any other case is UB
|
|
template<typename T>
|
|
void concurrent_bounded_queue<T>::set_capacity(std::size_t capacity) {
|
|
GAPI_Assert(m_data.empty());
|
|
GAPI_Assert(m_capacity == 0u);
|
|
GAPI_Assert(capacity != 0u);
|
|
m_capacity = capacity;
|
|
}
|
|
|
|
// Clear the queue. Similar to the TBB version, this method is not
|
|
// thread-safe.
|
|
template<typename T>
|
|
void concurrent_bounded_queue<T>::clear()
|
|
{
|
|
m_data = std::queue<T>{};
|
|
}
|
|
|
|
}}} // namespace cv::gapi::own
|
|
|
|
#endif // OPENCV_GAPI_EXECUTOR_CONC_QUEUE_HPP
|