mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #24178 from dmatveev:dm/streaming_queue
G-API: Introduce a Queue Source #24178 - Added a new IStreamSource class: in fact, a wrapper over a concurrent queue; - Added minimal example on how it can be used; - Extended IStreamSource with optional "halt" interface to break the blocking calls in the emitter threads when required to stop. - Introduced a QueueInput class which allows to pass the whole graph's input vector at once. In fact it is a thin wrapper atop of individual Queue Sources. There is a hidden trap found with our type system as described in https://github.com/orgs/g-api-org/discussions/2 While it works even in this form, it should be addressed somewhere in the 5.0 timeframe. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -41,6 +41,10 @@ using namespace cv::gimpl::stream;
|
||||
class VideoEmitter final: public cv::gimpl::GIslandEmitter {
|
||||
cv::gapi::wip::IStreamSource::Ptr src;
|
||||
|
||||
virtual void halt() override {
|
||||
src->halt();
|
||||
}
|
||||
|
||||
virtual bool pull(cv::GRunArg &arg) override {
|
||||
// FIXME: probably we can maintain a pool of (then) pre-allocated
|
||||
// buffers to avoid runtime allocations.
|
||||
@@ -62,6 +66,10 @@ public:
|
||||
class ConstEmitter final: public cv::gimpl::GIslandEmitter {
|
||||
cv::GRunArg m_arg;
|
||||
|
||||
virtual void halt() override {
|
||||
// Not used here, but in fact can be used.
|
||||
}
|
||||
|
||||
virtual bool pull(cv::GRunArg &arg) override {
|
||||
arg = const_cast<const cv::GRunArg&>(m_arg); // FIXME: variant workaround
|
||||
return true;
|
||||
@@ -1918,6 +1926,11 @@ void cv::gimpl::GStreamingExecutor::stop()
|
||||
for (auto &q : m_emitter_queues) {
|
||||
q.push(stream::Cmd{stream::Stop{}});
|
||||
}
|
||||
// Also kindly ask emitter object to halt to break the blocking src->pull()
|
||||
// loop
|
||||
for (auto &nh : m_emitters) {
|
||||
m_gim.metadata(nh).get<Emitter>().object->halt();
|
||||
}
|
||||
|
||||
// Pull messages from the final queue to ensure completion
|
||||
Cmd cmd;
|
||||
|
||||
Reference in New Issue
Block a user