Skip to content

Commit 1976816

Browse files
author
Clement Champetier
committed
Transcoder: can use offset on rewrap
1 parent 469f4d8 commit 1976816

File tree

4 files changed

+50
-29
lines changed

4 files changed

+50
-29
lines changed

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 41 additions & 20 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(
@@ -325,7 +324,32 @@ void StreamTranscoder::preProcessCodecLatency()
325324

326325
bool StreamTranscoder::processFrame()
327326
{
328-
if( ! _currentDecoder )
327+
// Manage offset
328+
if( _offset > 0 )
329+
{
330+
bool endOfOffset = _outputStream->getStreamDuration() >= _offset;
331+
if( endOfOffset )
332+
{
333+
LOG_INFO( "End of offset" )
334+
335+
if( _inputDecoder )
336+
switchToInputDecoder();
337+
else
338+
_currentDecoder = NULL;
339+
_offset = 0;
340+
}
341+
else
342+
{
343+
// process generator
344+
if( _currentDecoder != _generator )
345+
{
346+
LOG_INFO( "Switch to generator to process offset" )
347+
switchToGeneratorDecoder();
348+
}
349+
}
350+
}
351+
352+
if( ! _inputDecoder )
329353
{
330354
return processRewrap();
331355
}
@@ -341,9 +365,17 @@ bool StreamTranscoder::processRewrap()
341365
{
342366
assert( _inputStream != NULL );
343367
assert( _outputStream != NULL );
344-
368+
assert( _inputDecoder == NULL );
369+
345370
LOG_DEBUG( "Rewrap a frame" )
346371

372+
// if switched to generator, process frame
373+
if( _currentDecoder == _generator )
374+
{
375+
return processTranscode();
376+
}
377+
378+
LOG_DEBUG( "read next packet" )
347379
CodedData data;
348380
if( ! _inputStream->readNextPacket( data ) )
349381
{
@@ -355,6 +387,7 @@ bool StreamTranscoder::processRewrap()
355387
return false;
356388
}
357389

390+
LOG_DEBUG( "wrap (" << data.getSize() << " bytes)" )
358391
IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
359392

360393
switch( wrappingStatus )
@@ -382,19 +415,7 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
382415

383416
LOG_DEBUG( "Transcode a frame" )
384417

385-
// check offset
386-
if( _offset )
387-
{
388-
bool endOfOffset = _outputStream->getStreamDuration() >= _offset;
389-
if( endOfOffset )
390-
{
391-
// switch to essence from input stream
392-
switchToInputDecoder();
393-
// reset offset
394-
_offset = 0;
395-
}
396-
}
397-
418+
LOG_DEBUG( "decode next frame" )
398419
bool decodingStatus = false;
399420
if( subStreamIndex == -1 )
400421
decodingStatus = _currentDecoder->decodeNextFrame( *_sourceBuffer );
@@ -425,8 +446,8 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
425446
}
426447

427448
LOG_DEBUG( "wrap (" << data.getSize() << " bytes)" )
428-
429449
IOutputStream::EWrappingStatus wrappingStatus = _outputStream->wrap( data );
450+
430451
switch( wrappingStatus )
431452
{
432453
case IOutputStream::eWrappingSuccess:

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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
4242
if( filename.length() == 0 )
4343
throw std::runtime_error( "Can't re-wrap a stream without filename indicated" );
4444

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

64-
addRewrapStream( filename, streamIndex );
64+
addRewrapStream( filename, streamIndex, offset );
6565
}
6666
// Transcode
6767
else
@@ -108,7 +108,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
108108
// Re-wrap
109109
if( subStreamIndex < 0 )
110110
{
111-
addRewrapStream( filename, streamIndex );
111+
addRewrapStream( filename, streamIndex, offset );
112112
}
113113
// Transcode (transparent for the user)
114114
else
@@ -139,7 +139,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
139139
// Re-wrap
140140
if( subStreamIndex < 0 )
141141
{
142-
addRewrapStream( filename, streamIndex );
142+
addRewrapStream( filename, streamIndex, offset );
143143
}
144144
// Transcode (transparent for the user)
145145
else
@@ -279,13 +279,13 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const si
279279
_outputDuration = outputDuration;
280280
}
281281

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

286286
InputFile* referenceFile = addInputFile( filename, streamIndex );
287287

288-
_streamTranscodersAllocated.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile ) );
288+
_streamTranscodersAllocated.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, offset ) );
289289
_streamTranscoders.push_back( _streamTranscodersAllocated.back() );
290290
}
291291

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)