Merge pull request #20298 from mpashchenkov:mp/python-desync
[platform/upstream/opencv.git] / modules / gapi / src / compiler / gstreaming.cpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2019 Intel Corporation
6
7
8 #include "precomp.hpp"
9
10 #include <ade/graph.hpp>
11 #include <ade/util/zip_range.hpp>   // util::indexed
12
13 #include <opencv2/gapi/gproto.hpp> // can_describe
14 #include <opencv2/gapi/gcompiled.hpp>
15
16 #include "compiler/gstreaming_priv.hpp"
17 #include "backends/common/gbackend.hpp"
18
19 // GStreamingCompiled private implementation ///////////////////////////////////
20 void cv::GStreamingCompiled::Priv::setup(const GMetaArgs &_metaArgs,
21                                          const GMetaArgs &_outMetas,
22                                          std::unique_ptr<cv::gimpl::GStreamingExecutor> &&_pE)
23 {
24     m_metas    = _metaArgs;
25     m_outMetas = _outMetas;
26     m_exec     = std::move(_pE);
27 }
28
29 void cv::GStreamingCompiled::Priv::setup(std::unique_ptr<cv::gimpl::GStreamingExecutor> &&_pE)
30 {
31     m_exec = std::move(_pE);
32 }
33
34 bool cv::GStreamingCompiled::Priv::isEmpty() const
35 {
36     return !m_exec;
37 }
38
39 const cv::GMetaArgs& cv::GStreamingCompiled::Priv::metas() const
40 {
41     return m_metas;
42 }
43
44 const cv::GMetaArgs& cv::GStreamingCompiled::Priv::outMetas() const
45 {
46     return m_outMetas;
47 }
48
49 // FIXME: What is the reason in having Priv here if Priv actually dispatches
50 // everything to the underlying executable?? May be this executable may become
51 // the G*Compiled's priv?
52 void cv::GStreamingCompiled::Priv::setSource(cv::GRunArgs &&args)
53 {
54     if (!m_metas.empty() && !can_describe(m_metas, args))
55     {
56         util::throw_error(std::logic_error("This object was compiled "
57                                            "for different metadata!"));
58     }
59     GAPI_Assert(m_exec != nullptr);
60     m_exec->setSource(std::move(args));
61 }
62
63 void cv::GStreamingCompiled::Priv::start()
64 {
65     m_exec->start();
66 }
67
68 bool cv::GStreamingCompiled::Priv::pull(cv::GRunArgsP &&outs)
69 {
70     return m_exec->pull(std::move(outs));
71 }
72
73 bool cv::GStreamingCompiled::Priv::pull(cv::GOptRunArgsP &&outs)
74 {
75     return m_exec->pull(std::move(outs));
76 }
77
78 std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>> cv::GStreamingCompiled::Priv::pull()
79 {
80     return m_exec->pull();
81 }
82
83 bool cv::GStreamingCompiled::Priv::try_pull(cv::GRunArgsP &&outs)
84 {
85     return m_exec->try_pull(std::move(outs));
86 }
87
88 void cv::GStreamingCompiled::Priv::stop()
89 {
90     m_exec->stop();
91 }
92
93 bool cv::GStreamingCompiled::Priv::running() const
94 {
95     return m_exec->running();
96 }
97
98 // GStreamingCompiled public implementation ////////////////////////////////////
99 cv::GStreamingCompiled::GStreamingCompiled()
100     : m_priv(new Priv())
101 {
102 }
103
104 // NB: This overload is called from python code
105 void cv::GStreamingCompiled::setSource(const cv::detail::ExtractArgsCallback& callback)
106 {
107     setSource(callback(m_priv->inInfo()));
108 }
109
110 void cv::GStreamingCompiled::setSource(GRunArgs &&ins)
111 {
112     // FIXME: verify these input parameters according to the graph input meta
113     m_priv->setSource(std::move(ins));
114 }
115
116 void cv::GStreamingCompiled::setSource(const cv::gapi::wip::IStreamSource::Ptr &s)
117 {
118     setSource(cv::gin(s));
119 }
120
121 void cv::GStreamingCompiled::start()
122 {
123     m_priv->start();
124 }
125
126 bool cv::GStreamingCompiled::pull(cv::GRunArgsP &&outs)
127 {
128     return m_priv->pull(std::move(outs));
129 }
130
131 std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>> cv::GStreamingCompiled::pull()
132 {
133     return m_priv->pull();
134 }
135
136 bool cv::GStreamingCompiled::pull(cv::GOptRunArgsP &&outs)
137 {
138     return m_priv->pull(std::move(outs));
139 }
140
141 bool cv::GStreamingCompiled::try_pull(cv::GRunArgsP &&outs)
142 {
143     return m_priv->try_pull(std::move(outs));
144 }
145
146 void cv::GStreamingCompiled::stop()
147 {
148     m_priv->stop();
149 }
150
151 bool cv::GStreamingCompiled::running() const
152 {
153     return m_priv->running();
154 }
155
156 cv::GStreamingCompiled::operator bool() const
157 {
158     return !m_priv->isEmpty();
159 }
160
161 const cv::GMetaArgs& cv::GStreamingCompiled::metas() const
162 {
163     return m_priv->metas();
164 }
165
166 const cv::GMetaArgs& cv::GStreamingCompiled::outMetas() const
167 {
168     return m_priv->outMetas();
169 }
170
171 cv::GStreamingCompiled::Priv& cv::GStreamingCompiled::priv()
172 {
173     return *m_priv;
174 }