Skip to content

Commit e887b1d

Browse files
author
Clement Champetier
committed
AudioTransform: rename initFrames to updateOutputFrame
* The functions only update the output frame. * We update some attributes of the transform after this function (which is now const).
1 parent 9e57c8a commit e887b1d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/AvTranscoder/transform/AudioTransform.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,32 @@ bool AudioTransform::init( const Frame& srcFrame, const Frame& dstFrame )
6969
return true;
7070
}
7171

72-
void AudioTransform::initFrames( const Frame& srcFrame, Frame& dstFrame )
72+
void AudioTransform::updateOutputFrame( const size_t nbInputSamples, Frame& dstFrame ) const
7373
{
74-
const AudioFrame& src = static_cast<const AudioFrame&>( srcFrame );
7574
AudioFrame& dst = static_cast<AudioFrame&>( dstFrame );
7675

7776
// resize buffer of output frame
7877
const int dstSampleSize = av_get_bytes_per_sample( dst.desc().getSampleFormat() );
79-
const size_t bufferSizeNeeded = src.getNbSamples() * dst.desc().getChannels() * dstSampleSize;
78+
const size_t bufferSizeNeeded = nbInputSamples * dst.desc().getChannels() * dstSampleSize;
8079
if( bufferSizeNeeded > dstFrame.getSize() )
8180
dstFrame.resize( bufferSizeNeeded );
8281

8382
// set nbSamples of output frame
84-
dst.setNbSamples( src.getNbSamples() );
85-
86-
_nbSamplesOfPreviousFrame = src.getNbSamples();
83+
dst.setNbSamples( nbInputSamples );
8784
}
8885

8986
void AudioTransform::convert( const Frame& srcFrame, Frame& dstFrame )
9087
{
9188
if( ! _isInit )
9289
_isInit = init( srcFrame, dstFrame );
9390

91+
// if number of samples change from previous frame
9492
const AudioFrame& srcAudioFrame = static_cast<const AudioFrame&>( srcFrame );
9593
if( srcAudioFrame.getNbSamples() != _nbSamplesOfPreviousFrame )
96-
initFrames( srcFrame, dstFrame );
94+
{
95+
updateOutputFrame( srcAudioFrame.getNbSamples(), dstFrame );
96+
_nbSamplesOfPreviousFrame = srcAudioFrame.getNbSamples();
97+
}
9798

9899
const unsigned char* srcData = srcFrame.getData();
99100
unsigned char* dstData = dstFrame.getData();

src/AvTranscoder/transform/AudioTransform.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class AvExport AudioTransform : public ITransform
2828
private:
2929
bool init( const Frame& srcFrame, const Frame& dstFrame );
3030

31-
/// Resize output buffer if source has a different size from the last process
32-
void initFrames( const Frame& srcFrame, Frame& dstFrame );
31+
/// Update output buffer if source has a different size from the last process
32+
void updateOutputFrame( const size_t nbInputSamples, Frame& dstFrame ) const;
3333

3434
private:
3535
ResampleContext* _audioConvertContext;

0 commit comments

Comments
 (0)