@@ -19,6 +19,7 @@ Transcoder::Transcoder(IOutputFile& outputFile)
1919 , _profileLoader(true )
2020 , _eProcessMethod(eProcessMethodLongest)
2121 , _mainStreamIndex(0 )
22+ , _processedFrames(0 )
2223 , _outputDuration(0 )
2324{
2425}
@@ -159,27 +160,86 @@ void Transcoder::preProcessCodecLatency()
159160}
160161
161162bool Transcoder::processFrame ()
163+ {
164+ NoDisplayProgress progress;
165+ return processFrame (progress);
166+ }
167+
168+ bool Transcoder::processFrame (IProgress& progress)
162169{
163170 if (_streamTranscoders.size () == 0 )
164171 return false ;
165172
166173 // For each stream, process a frame
174+ bool result = true ;
167175 for (size_t streamIndex = 0 ; streamIndex < _streamTranscoders.size (); ++streamIndex)
168176 {
169- LOG_DEBUG (" Process stream " << streamIndex + 1 << " /" << _streamTranscoders.size ())
177+ if (!processFrame (progress, streamIndex))
178+ result = false ;
179+ }
180+ return result;
181+ }
170182
171- // if a stream failed to process
172- if (!_streamTranscoders.at (streamIndex)->processFrame ())
173- {
183+ bool Transcoder::processFrame (IProgress& progress, const size_t & streamIndex)
184+ {
185+ LOG_DEBUG (" Process stream " << streamIndex + 1 << " /" << _streamTranscoders.size ())
186+
187+ IOutputStream::EWrappingStatus status = _streamTranscoders.at (streamIndex)->processFrame ();
188+ switch (status)
189+ {
190+ case IOutputStream::eWrappingSuccess:
191+ if (streamIndex == 0 )
192+ _processedFrames++;
193+
194+ if (!continueProcess (progress))
195+ return false ;
196+ return true ;
197+
198+ case IOutputStream::eWrappingWaitingForData:
199+ // the wrapper needs more data to write the current packet
200+ if (streamIndex == 0 )
201+ _processedFrames++;
202+
203+ if (!continueProcess (progress))
204+ return false ;
205+
206+ return processFrame (progress, streamIndex);
207+
208+ case IOutputStream::eWrappingSkip:
209+ return true ;
210+
211+ case IOutputStream::eWrappingError:
212+ // if a stream failed to process
174213 LOG_WARN (" Failed to process the stream transcoder at index " << streamIndex)
175214
176215 // if this is the end of the main stream
177- if (streamIndex == _mainStreamIndex) {
216+ if (streamIndex == _mainStreamIndex)
178217 LOG_INFO (" End of process because the main stream at index " << _mainStreamIndex << " failed to process a new frame." )
179- return false ;
180- }
181- }
218+
219+ return false ;
182220 }
221+ }
222+
223+ bool Transcoder::continueProcess (IProgress& progress) {
224+ const float expectedOutputDuration = getExpectedOutputDuration ();
225+ const float progressDuration = getCurrentOutputDuration ();
226+
227+ // check if JobStatusCancel
228+ if (progress.progress ((progressDuration > expectedOutputDuration) ? expectedOutputDuration : progressDuration,
229+ expectedOutputDuration) == eJobStatusCancel)
230+ {
231+ LOG_INFO (" End of process because the job was canceled." )
232+ return false ;
233+ }
234+
235+ // check progressDuration
236+ if (_eProcessMethod == eProcessMethodBasedOnDuration && progressDuration >= expectedOutputDuration)
237+ {
238+ LOG_INFO (" End of process because the output program duration ("
239+ << progressDuration << " s) is equal or upper than " << expectedOutputDuration << " s." )
240+ return false ;
241+ }
242+
183243 return true ;
184244}
185245
@@ -205,36 +265,15 @@ ProcessStat Transcoder::process(IProgress& progress)
205265 const float expectedOutputDuration = getExpectedOutputDuration ();
206266 LOG_INFO (" The expected output duration of the program will be " << expectedOutputDuration << " s." )
207267
208- size_t frame = 0 ;
209268 bool frameProcessed = true ;
210269 while (frameProcessed)
211270 {
212- LOG_DEBUG (" Process frame " << frame)
213- frameProcessed = processFrame ();
214- ++frame;
215-
216- const float progressDuration = getCurrentOutputDuration ();
217-
218- // check if JobStatusCancel
219- if (progress.progress ((progressDuration > expectedOutputDuration) ? expectedOutputDuration : progressDuration,
220- expectedOutputDuration) == eJobStatusCancel)
221- {
222- LOG_INFO (" End of process because the job was canceled." )
223- break ;
224- }
225-
226- // check progressDuration
227- if (_eProcessMethod == eProcessMethodBasedOnDuration && progressDuration >= expectedOutputDuration)
228- {
229- LOG_INFO (" End of process because the output program duration ("
230- << progressDuration << " s) is equal or upper than " << expectedOutputDuration << " s." )
231- break ;
232- }
271+ LOG_INFO (" Process frame " << _processedFrames);
272+ frameProcessed = processFrame (progress);
233273 }
234274
235275 _outputFile.endWrap ();
236-
237- LOG_INFO (" End of process: " << ++frame << " frames processed" )
276+ LOG_INFO (" End of process: " << ++_processedFrames << " frames processed" )
238277
239278 LOG_INFO (" Get process statistics" )
240279 ProcessStat processStat;
0 commit comments