Skip to content

Commit 406013b

Browse files
authored
Merge pull request #322 from avTranscoder/fix/stop_process_even_if_the_wrapper_expects_more_data
Fix: stop the process even if the wrapper expects more data
2 parents 8cc0912 + 30be155 commit 406013b

File tree

6 files changed

+107
-75
lines changed

6 files changed

+107
-75
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool OutputFile::beginWrap()
188188
IOutputStream::EWrappingStatus OutputFile::wrap(const CodedData& data, const size_t streamIndex)
189189
{
190190
if(!data.getSize())
191-
return IOutputStream::eWrappingSuccess;
191+
return IOutputStream::eWrappingSkip;
192192

193193
LOG_DEBUG("Wrap on stream " << streamIndex << " (" << data.getSize() << " bytes for frame "
194194
<< _frameCount.at(streamIndex) << ")")

src/AvTranscoder/stream/IOutputStream.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class AvExport IOutputStream
1616
**/
1717
enum EWrappingStatus
1818
{
19-
eWrappingSuccess = 0,
20-
eWrappingWaitingForData,
21-
eWrappingError,
19+
eWrappingSuccess = 0, ///< The wrapping succeeded
20+
eWrappingWaitingForData, ///< The wrapper expects more data to complete the writing process
21+
eWrappingSkip, ///< The wrapper receives empty data, so nothing is written
22+
eWrappingError, ///< An error occurred during the wrapping process
2223
};
2324

2425
virtual ~IOutputStream(){};

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ void StreamTranscoder::preProcessCodecLatency()
597597
_currentDecoder = NULL;
598598
}
599599

600-
bool StreamTranscoder::processFrame()
600+
IOutputStream::EWrappingStatus StreamTranscoder::processFrame()
601601
{
602602
std::string msg = "Current process case of the stream is a ";
603603
switch(getProcessCase())
@@ -677,7 +677,7 @@ bool StreamTranscoder::processFrame()
677677
return processTranscode();
678678
}
679679

680-
bool StreamTranscoder::processRewrap()
680+
IOutputStream::EWrappingStatus StreamTranscoder::processRewrap()
681681
{
682682
assert(_inputStreams.size() == 1);
683683
assert(_outputStream != NULL);
@@ -692,25 +692,13 @@ bool StreamTranscoder::processRewrap()
692692
switchToGeneratorDecoder();
693693
return processTranscode();
694694
}
695-
return false;
695+
return IOutputStream::eWrappingError;
696696
}
697697

698-
const IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap(data);
699-
switch(wrappingStatus)
700-
{
701-
case IOutputStream::eWrappingSuccess:
702-
return true;
703-
case IOutputStream::eWrappingWaitingForData:
704-
// the wrapper needs more data to write the current packet
705-
return processFrame();
706-
case IOutputStream::eWrappingError:
707-
return false;
708-
}
709-
710-
return true;
698+
return _outputStream->wrap(data);
711699
}
712700

713-
bool StreamTranscoder::processTranscode()
701+
IOutputStream::EWrappingStatus StreamTranscoder::processTranscode()
714702
{
715703
assert(_outputStream != NULL);
716704
assert(_currentDecoder != NULL);
@@ -840,25 +828,13 @@ bool StreamTranscoder::processTranscode()
840828
}
841829
return processTranscode();
842830
}
843-
return false;
831+
return IOutputStream::eWrappingError;
844832
}
845833
}
846834

847835
// Wrap
848836
LOG_DEBUG("wrap (" << data.getSize() << " bytes)")
849-
const IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap(data);
850-
switch(wrappingStatus)
851-
{
852-
case IOutputStream::eWrappingSuccess:
853-
return true;
854-
case IOutputStream::eWrappingWaitingForData:
855-
// the wrapper needs more data to write the current packet
856-
return processFrame();
857-
case IOutputStream::eWrappingError:
858-
return false;
859-
}
860-
861-
return true;
837+
return _outputStream->wrap(data);
862838
}
863839

864840
void StreamTranscoder::switchToGeneratorDecoder()

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class AvExport StreamTranscoder
6969
* @brief process a single frame for the current stream
7070
* @return the process status result
7171
*/
72-
bool processFrame();
72+
IOutputStream::EWrappingStatus processFrame();
7373

7474
//@{
7575
// Switch current decoder.
@@ -139,8 +139,8 @@ class AvExport StreamTranscoder
139139
void addDecoder(const InputStreamDesc& inputStreamDesc, IInputStream& inputStream);
140140
void addGenerator(const InputStreamDesc& inputStreamDesc, const ProfileLoader::Profile& profile);
141141

142-
bool processRewrap();
143-
bool processTranscode();
142+
IOutputStream::EWrappingStatus processRewrap();
143+
IOutputStream::EWrappingStatus processTranscode();
144144

145145
private:
146146
std::vector<InputStreamDesc> _inputStreamDesc; ///< Description of the data to extract from the input stream.

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

161162
bool 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;

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ class AvExport Transcoder
9595

9696
/**
9797
* @brief Process the next frame of all streams.
98+
* @param progress: choose a progress, or create your own in C++ or in bindings by inherit IProgress class.
9899
* @return if a frame was processed or not.
99100
*/
100-
bool processFrame();
101+
bool processFrame(IProgress& progress);
102+
bool processFrame(); ///< Call processFrame with no display of progression
101103

102104
/**
103105
* @brief Process all the streams, and ended the process depending on the transcode politic.
@@ -190,6 +192,19 @@ class AvExport Transcoder
190192
*/
191193
void manageSwitchToGenerator();
192194

195+
/**
196+
* @brief Process the next frame of the specified stream.
197+
* @return whether a frame was processed or not.
198+
*/
199+
bool processFrame(IProgress& progress, const size_t& streamIndex);
200+
201+
/**
202+
* @brief Check whether the process is canceled or not, and whether the process reached the ending condition.
203+
* @note The progress is updated in this function.
204+
* @return whether the process must continue or stop.
205+
*/
206+
bool continueProcess(IProgress& progress);
207+
193208
/**
194209
* @brief Fill the given ProcessStat to summarize the process.
195210
*/
@@ -205,10 +220,11 @@ class AvExport Transcoder
205220
ProfileLoader _profileLoader; ///< Objet to get existing profiles, and add new ones for the Transcoder.
206221

207222
EProcessMethod _eProcessMethod; ///< Processing policy
208-
size_t
209-
_mainStreamIndex; ///< Index of stream used to stop the process.
210-
float _outputDuration; ///< Duration of output media used to stop the process of transcode in case of
211-
/// eProcessMethodBasedOnDuration.
223+
224+
size_t _mainStreamIndex; ///< Index of stream used to stop the process.
225+
size_t _processedFrames; ///< Counter for the number of processed frames.
226+
227+
float _outputDuration; ///< Duration of output media used to stop the process of transcode in case of eProcessMethodBasedOnDuration.
212228
};
213229
}
214230

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy