Skip to content

Commit 96bf6fe

Browse files
author
Valentin Noel
committed
Transcoding: fix the audio output frame size problem when variable audio frame size in input
1 parent c1caf53 commit 96bf6fe

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/AvTranscoder/transform/AudioTransform.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace avtranscoder
3232

3333
AudioTransform::AudioTransform()
3434
: _audioConvertContext( NULL )
35+
, _previousProcessedAudioFrameSize( 0 )
3536
, _isInit ( false )
3637
{
3738
}
@@ -64,11 +65,24 @@ bool AudioTransform::init( const Frame& srcFrame, const Frame& dstFrame )
6465
return true;
6566
}
6667

68+
bool AudioTransform::initFrames( const Frame& srcFrame, Frame& dstFrame )
69+
{
70+
const AudioFrame& src = static_cast<const AudioFrame&>( srcFrame );
71+
const AudioFrame& dst = static_cast<const AudioFrame&>( dstFrame );
72+
73+
int dstSampleSize = av_get_bytes_per_sample( dst.desc().getAVSampleFormat() );
74+
dstFrame.getBuffer().resize( src.getNbSamples() * dstSampleSize );
75+
return true;
76+
}
77+
6778
void AudioTransform::convert( const Frame& srcFrame, Frame& dstFrame )
6879
{
6980
if( ! _isInit )
7081
_isInit = init( srcFrame, dstFrame );
7182

83+
if( srcFrame.getSize() != _previousProcessedAudioFrameSize )
84+
initFrames( srcFrame, dstFrame );
85+
7286
const unsigned char* srcData = srcFrame.getPtr();
7387
unsigned char* dstData = dstFrame.getPtr();
7488

@@ -89,6 +103,7 @@ void AudioTransform::convert( const Frame& srcFrame, Frame& dstFrame )
89103
if( dstFrame.getSize() != nbOutputSamples )
90104
dstFrame.getBuffer().resize( nbOutputSamples, 0 );
91105
static_cast<AudioFrame&>( dstFrame ).setNbSamples( static_cast<const AudioFrame&>( srcFrame ).getNbSamples() );
106+
_previousProcessedAudioFrameSize = srcFrame.getSize();
92107
}
93108

94109
}

src/AvTranscoder/transform/AudioTransform.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ class AvExport AudioTransform : public ITransform
2626

2727
private:
2828
bool init( const Frame& srcFrame, const Frame& dstFrame );
29+
bool initFrames( const Frame& srcFrame, Frame& dstFrame );
2930

3031
ResampleContext* _audioConvertContext;
32+
33+
size_t _previousProcessedAudioFrameSize;
3134

3235
bool _isInit;
3336
};

0 commit comments

Comments
 (0)