Skip to content

Commit da013d4

Browse files
author
Clement Champetier
committed
StreamTranscoder: check the next data buffers in case of audio frames
* If the buffer of filtered data is too small: reallocate it. * If the buffer of transformed data is too small: reallocate it.
1 parent 249bcfb commit da013d4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/AvTranscoder/data/decoded/AudioFrame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ void AudioFrame::allocateData()
103103
av_frame_set_channels(_frame, _desc._nbChannels);
104104
av_frame_set_channel_layout(_frame, av_get_default_channel_layout(_desc._nbChannels));
105105
_frame->format = _desc._sampleFormat;
106-
_frame->nb_samples = getDefaultNbSamples();
106+
if(_frame->nb_samples == 0)
107+
_frame->nb_samples = getDefaultNbSamples();
107108

108109
// Allocate data
109110
const int align = 0;

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,26 @@ bool StreamTranscoder::processTranscode()
547547
decodingStatus = decodingStatus && _currentDecoder->decodeNextFrame(*_decodedData.at(index));
548548
}
549549

550+
// check the next data buffers in case of audio frames
551+
if(_decodedData.at(0)->isAudioFrame())
552+
{
553+
const int nbInputSamplesPerChannel = _decodedData.at(0)->getAVFrame().nb_samples;
554+
if(nbInputSamplesPerChannel > _filteredData->getAVFrame().nb_samples)
555+
{
556+
LOG_WARN("The buffer of filtered data is too small: reallocate it.")
557+
_filteredData->freeData();
558+
_filteredData->getAVFrame().nb_samples = nbInputSamplesPerChannel;
559+
_filteredData->allocateData();
560+
}
561+
if(nbInputSamplesPerChannel > _transformedData->getAVFrame().nb_samples)
562+
{
563+
LOG_WARN("The buffer of transformed data is too small: reallocate it.")
564+
_transformedData->freeData();
565+
_transformedData->getAVFrame().nb_samples = nbInputSamplesPerChannel;
566+
_transformedData->allocateData();
567+
}
568+
}
569+
550570
// Transform
551571
CodedData data;
552572
if(decodingStatus)

0 commit comments

Comments
 (0)