Skip to content

Commit 3ed4962

Browse files
committed
Merge pull request #167 from cchampet/dev_ManageOffsetOnRewrap
Manage offset on rewrap
2 parents 32d99fd + 9cfa8f8 commit 3ed4962

File tree

5 files changed

+55
-31
lines changed

5 files changed

+55
-31
lines changed

src/AvTranscoder/decoder/AudioGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ bool AudioGenerator::decodeNextFrame( Frame& frameBuffer )
7070

7171
bool AudioGenerator::decodeNextFrame( Frame& frameBuffer, const size_t subStreamIndex )
7272
{
73-
return false;
73+
return decodeNextFrame( frameBuffer );
7474
}
7575

7676
}

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace avtranscoder
2222

2323
StreamTranscoder::StreamTranscoder(
2424
IInputStream& inputStream,
25-
IOutputFile& outputFile
25+
IOutputFile& outputFile,
26+
const double offset
2627
)
2728
: _inputStream( &inputStream )
2829
, _outputStream( NULL )
@@ -34,7 +35,7 @@ StreamTranscoder::StreamTranscoder(
3435
, _outputEncoder( NULL )
3536
, _transform( NULL )
3637
, _subStreamIndex( -1 )
37-
, _offset( 0 )
38+
, _offset( offset )
3839
, _canSwitchToGenerator( false )
3940
{
4041
// create a re-wrapping case
@@ -213,8 +214,6 @@ StreamTranscoder::StreamTranscoder(
213214
break;
214215
}
215216
}
216-
if( offset )
217-
switchToGeneratorDecoder();
218217
}
219218

220219
StreamTranscoder::StreamTranscoder(
@@ -327,6 +326,31 @@ void StreamTranscoder::preProcessCodecLatency()
327326

328327
bool StreamTranscoder::processFrame()
329328
{
329+
// Manage offset
330+
if( _offset > 0 )
331+
{
332+
bool endOfOffset = _outputStream->getStreamDuration() >= _offset;
333+
if( endOfOffset )
334+
{
335+
LOG_INFO( "End of offset" )
336+
337+
if( _inputDecoder )
338+
switchToInputDecoder();
339+
else
340+
_currentDecoder = NULL;
341+
_offset = 0;
342+
}
343+
else
344+
{
345+
// process generator
346+
if( _currentDecoder != _generator )
347+
{
348+
LOG_INFO( "Switch to generator to process offset" )
349+
switchToGeneratorDecoder();
350+
}
351+
}
352+
}
353+
330354
if( isRewrapCase() )
331355
return processRewrap();
332356

@@ -337,9 +361,17 @@ bool StreamTranscoder::processRewrap()
337361
{
338362
assert( _inputStream != NULL );
339363
assert( _outputStream != NULL );
340-
364+
assert( _inputDecoder == NULL );
365+
341366
LOG_DEBUG( "Rewrap a frame" )
342367

368+
// if switched to generator, process frame
369+
if( _currentDecoder == _generator )
370+
{
371+
return processTranscode();
372+
}
373+
374+
LOG_DEBUG( "read next packet" )
343375
CodedData data;
344376
if( ! _inputStream->readNextPacket( data ) )
345377
{
@@ -351,6 +383,7 @@ bool StreamTranscoder::processRewrap()
351383
return false;
352384
}
353385

386+
LOG_DEBUG( "wrap (" << data.getSize() << " bytes)" )
354387
IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
355388

356389
switch( wrappingStatus )
@@ -378,19 +411,7 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
378411

379412
LOG_DEBUG( "Transcode a frame" )
380413

381-
// check offset
382-
if( _offset )
383-
{
384-
bool endOfOffset = _outputStream->getStreamDuration() >= _offset;
385-
if( endOfOffset )
386-
{
387-
// switch to essence from input stream
388-
switchToInputDecoder();
389-
// reset offset
390-
_offset = 0;
391-
}
392-
}
393-
414+
LOG_DEBUG( "decode next frame" )
394415
bool decodingStatus = false;
395416
if( subStreamIndex < 0 )
396417
decodingStatus = _currentDecoder->decodeNextFrame( *_sourceBuffer );
@@ -421,8 +442,8 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
421442
}
422443

423444
LOG_DEBUG( "wrap (" << data.getSize() << " bytes)" )
424-
425445
IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
446+
426447
switch( wrappingStatus )
427448
{
428449
case IOutputStream::eWrappingSuccess:
@@ -439,12 +460,16 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
439460

440461
void StreamTranscoder::switchToGeneratorDecoder()
441462
{
463+
LOG_INFO( "Switch to generator decoder" )
464+
442465
_currentDecoder = _generator;
443466
assert( _currentDecoder != NULL );
444467
}
445468

446469
void StreamTranscoder::switchToInputDecoder()
447470
{
471+
LOG_INFO( "Switch to input decoder" )
472+
448473
_currentDecoder = _inputDecoder;
449474
assert( _currentDecoder != NULL );
450475
}

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AvExport StreamTranscoder
2929
* @brief rewrap stream
3030
* @note offset feature when rewrap a stream is not supported
3131
**/
32-
StreamTranscoder( IInputStream& inputStream, IOutputFile& outputFile );
32+
StreamTranscoder( IInputStream& inputStream, IOutputFile& outputFile, const double offset = 0 );
3333

3434
/**
3535
* @brief transcode stream

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
4141
if( filename.length() == 0 )
4242
throw std::runtime_error( "Can't re-wrap a stream without filename indicated" );
4343

44-
addRewrapStream( filename, streamIndex );
44+
addRewrapStream( filename, streamIndex, offset );
4545
}
4646
// Transcode
4747
else
@@ -60,7 +60,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
6060
if( filename.length() == 0 )
6161
throw std::runtime_error( "Can't re-wrap a stream without filename indicated" );
6262

63-
addRewrapStream( filename, streamIndex );
63+
addRewrapStream( filename, streamIndex, offset );
6464
}
6565
// Transcode
6666
else
@@ -107,7 +107,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
107107
// Re-wrap
108108
if( subStreamIndex < 0 )
109109
{
110-
addRewrapStream( filename, streamIndex );
110+
addRewrapStream( filename, streamIndex, offset );
111111
}
112112
// Transcode (transparent for the user)
113113
else
@@ -138,7 +138,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
138138
// Re-wrap
139139
if( subStreamIndex < 0 )
140140
{
141-
addRewrapStream( filename, streamIndex );
141+
addRewrapStream( filename, streamIndex, offset );
142142
}
143143
// Transcode (transparent for the user)
144144
else
@@ -198,7 +198,6 @@ void Transcoder::preProcessCodecLatency()
198198
{
199199
for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex )
200200
{
201-
std::stringstream os;
202201
LOG_DEBUG( "Init stream " << streamIndex )
203202
_streamTranscoders.at( streamIndex )->preProcessCodecLatency();
204203
}
@@ -243,8 +242,8 @@ void Transcoder::process( IProgress& progress )
243242
preProcessCodecLatency();
244243

245244
double outputDuration = getOutputDuration();
245+
LOG_DEBUG( "Output duration of the process will be " << outputDuration )
246246

247-
std::stringstream os;
248247
size_t frame = 0;
249248
bool frameProcessed = true;
250249
while( frameProcessed )
@@ -278,13 +277,13 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const si
278277
_outputDuration = outputDuration;
279278
}
280279

281-
void Transcoder::addRewrapStream( const std::string& filename, const size_t streamIndex )
280+
void Transcoder::addRewrapStream( const std::string& filename, const size_t streamIndex, const double offset )
282281
{
283-
LOG_INFO( "Add rewrap stream from file '" << filename << "' / index=" << streamIndex )
282+
LOG_INFO( "Add rewrap stream from file '" << filename << "' / index=" << streamIndex << " / offset=" << offset << "s" )
284283

285284
InputFile* referenceFile = addInputFile( filename, streamIndex );
286285

287-
_streamTranscodersAllocated.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile ) );
286+
_streamTranscodersAllocated.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, offset ) );
288287
_streamTranscoders.push_back( _streamTranscodersAllocated.back() );
289288
}
290289

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class AvExport Transcoder
148148
void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0, const double outputDuration = 0 );
149149

150150
private:
151-
void addRewrapStream( const std::string& filename, const size_t streamIndex );
151+
void addRewrapStream( const std::string& filename, const size_t streamIndex, const double offset );
152152

153153
void addTranscodeStream( const std::string& filename, const size_t streamIndex, const int subStreamIndex, const double offset );
154154
void addTranscodeStream( const std::string& filename, const size_t streamIndex, const int subStreamIndex, const ProfileLoader::Profile& profile, const double offset = 0 );

0 commit comments

Comments
 (0)