Skip to content

G-API: Basic frame drop functionality#19731

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
rgarnov:rg/basic_frame_drop
Mar 24, 2021
Merged

G-API: Basic frame drop functionality#19731
opencv-pushbot merged 1 commit intoopencv:masterfrom
rgarnov:rg/basic_frame_drop

Conversation

@rgarnov
Copy link
Copy Markdown
Contributor

@rgarnov rgarnov commented Mar 16, 2021

Summary

This PR brings cv::gapi::streaming::sync_policy enum which allows to control input streaming sources synchronization when passed as compile arg. Currently possible values are dont_sync and drop. If dont_sync or nothing is passed, framework will behave as previously. If drop is passed, framework will run the whole graph only on inputs which timestamps are equal, dropping all inappropriate frames. Need to note that const (non-video) sources are not taken into account when comparing timestamps since their output is always the same.

Changes overview

For each input our streaming executor creates an Emitter which is responsible for pulling data from the source. There is 1:1 correspondence between emitters and GComputation inputs. For const sources ConstEmitter-s are created, for video sources - VideoEmitter-s. For each emitter framework creates a thread which simply pulls data from the according source and pushes this data further to all its readers (islands). There are queues placed between emitters and their readers to maintain pipelining, so emitter simply pushes to according queues while islands are popping from these queues.

To add input timestamp synchronization to this picture a new Synchronizer entity was introduced. If synchronization is required, it adds additional layer of queues between emitters which need to be synchronized and their readers. A synchronization thread is created to pull data from emitter queues and compare their timestamps, dropping some data till it gets all input data from all emitters having the same timestamp value. After that this synchronized data is pushed further to the islands and the actual calculations are launched.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Build configuration

Xforce_builders_only=linux,docs
force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.1.0:20.04
build_image:Custom Win=openvino-2021.1.0
build_image:Custom Mac=openvino-2021.2.0

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@rgarnov rgarnov force-pushed the rg/basic_frame_drop branch 2 times, most recently from 6a0af23 to b2c8950 Compare March 16, 2021 09:07
@alalek
Copy link
Copy Markdown
Member

alalek commented Mar 16, 2021

BTW, python tests with OpenVINO are failed/crashed due to this issue: #19719

@rgarnov rgarnov force-pushed the rg/basic_frame_drop branch from b2c8950 to 48b0a07 Compare March 16, 2021 11:23
@rgarnov rgarnov force-pushed the rg/basic_frame_drop branch 2 times, most recently from 371a580 to b180d8d Compare March 17, 2021 13:19
@dmatveev dmatveev self-assigned this Mar 18, 2021
@dmatveev dmatveev added this to the 4.5.2 milestone Mar 18, 2021
Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks quite good!

}
// Iterate through all input queues, pop GRunArg's and compare timestamps.
// Continue pulling from queues whose timestamps is smaller.
// Finish when all timestamps are equal.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the equality strict or in some range? Is it configurable at this point? Is it open to become configurable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently equality is strict, it can be relaxed if needed. And yes, we can give a user possibility to customize it. But what to customize is questionable, it can be just some range for timestamps to be considered synchronized, or maybe it should be some interface which gives the ability to manually interact with the queues to implement more sophisticated synchronization logic. I think it's better to do it separately when we'll better know supposed use cases

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it won't work for the case with two USB cameras (at the prototype stage). There is no guarantee frames will have equal timestamps..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align with @OrestChura on his stereo tool PoC

std::vector<ade::NodeHandle> m_synchronized_emitters;
std::vector<stream::SyncQueue> m_sync_queues;

std::vector<stream::Q*> newSyncQueue() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it return a vector of a single element?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was done this way to conform with reader_queues signature and not to compilicate outQueues() call with std::vector<Q*> creation

@rgarnov rgarnov force-pushed the rg/basic_frame_drop branch from b180d8d to 716bdd5 Compare March 19, 2021 11:30
@rgarnov
Copy link
Copy Markdown
Contributor Author

rgarnov commented Mar 19, 2021

@dmatveev @smirnov-alexey updated

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please proceed with the merge

@opencv-pushbot opencv-pushbot merged commit 24002a5 into opencv:master Mar 24, 2021
@alalek alalek mentioned this pull request Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants