@@ -147,28 +147,64 @@ size_t FilterGraph::getMinInputFrameSize(const std::vector<IFrame*>& inputs)
147
147
return minFrameSize;
148
148
}
149
149
150
+ bool FilterGraph::areInputFrameSizeEqual (const std::vector<IFrame*>& inputs)
151
+ {
152
+ if (!inputs.size () || inputs.size () == 1 )
153
+ return true ;
154
+
155
+ const int frameSize = inputs.at (0 )->getDataSize ();
156
+ for (size_t index = 1 ; index < inputs.size (); ++index)
157
+ {
158
+ if (frameSize != inputs.at (index)->getDataSize ())
159
+ return false ;
160
+ }
161
+ return true ;
162
+ }
163
+
164
+ bool FilterGraph::areFrameBuffersEmpty ()
165
+ {
166
+ if (!_inputFramesBuffer.size ())
167
+ return true ;
168
+
169
+ for (std::vector<FrameBuffer>::iterator it = _inputFramesBuffer.begin (); it != _inputFramesBuffer.end (); ++it)
170
+ {
171
+ if (!it->isEmpty ())
172
+ return false ;
173
+ }
174
+ return true ;
175
+ }
176
+
150
177
void FilterGraph::process (const std::vector<IFrame*>& inputs, IFrame& output)
151
178
{
152
- // init filter graph
179
+ // Init the filter graph
153
180
if (!_isInit)
154
181
init (inputs, output);
155
182
156
- // setup input frames
183
+ // Check whether we can bypass the input buffers
184
+ const bool bypassBuffers = areInputFrameSizeEqual (inputs) && areFrameBuffersEmpty ();
185
+ size_t minInputFrameSize = 0 ;
157
186
158
- // Fill the frame buffer with inputs
159
- for (size_t index = 0 ; index < inputs.size (); ++index)
187
+ if (!bypassBuffers)
160
188
{
161
- _inputFramesBuffer.at (index).addFrame (inputs.at (index));
189
+ // Fill the frame buffer with inputs
190
+ for (size_t index = 0 ; index < inputs.size (); ++index)
191
+ _inputFramesBuffer.at (index).addFrame (inputs.at (index));
192
+
193
+ // Get the minimum input frames size
194
+ minInputFrameSize = getMinInputFrameSize (inputs);
162
195
}
163
196
164
- // Get the minimum input frames size
165
- const size_t minInputFrameSize = getMinInputFrameSize (inputs);
166
197
167
198
// Setup input frames into the filter graph
168
199
for (size_t index = 0 ; index < inputs.size (); ++index)
169
200
{
170
- IFrame* inputBufferedFrame = _inputFramesBuffer.at (index).getFrame (minInputFrameSize);
171
- const int ret = av_buffersrc_add_frame_flags (_filters.at (index)->getAVFilterContext (), &inputBufferedFrame->getAVFrame (), AV_BUFFERSRC_FLAG_PUSH);
201
+ IFrame* inputFrame = NULL ;
202
+ if (bypassBuffers)
203
+ inputFrame = inputs.at (index);
204
+ else
205
+ inputFrame = _inputFramesBuffer.at (index).getFrame (minInputFrameSize);
206
+
207
+ const int ret = av_buffersrc_add_frame_flags (_filters.at (index)->getAVFilterContext (), &inputFrame->getAVFrame (), AV_BUFFERSRC_FLAG_PUSH);
172
208
173
209
if (ret < 0 )
174
210
{
0 commit comments