Skip to content

Commit 28dc5fe

Browse files
author
Valentin Noel
committed
StreamTranscoder: store the index of the first non-null input stream
Instead of using the getFirstInputStreamIndex() private method.
1 parent 4d4ca1e commit 28dc5fe

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ StreamTranscoder::StreamTranscoder(IInputStream& inputStream, IOutputFile& outpu
3333
, _outputEncoder(NULL)
3434
, _transform(NULL)
3535
, _filterGraph(NULL)
36+
, _firstInputStreamIndex(0)
3637
, _offset(offset)
3738
, _needToSwitchToGenerator(false)
3839
{
@@ -140,6 +141,7 @@ StreamTranscoder::StreamTranscoder(const std::vector<InputStreamDesc>& inputStre
140141
, _outputEncoder(NULL)
141142
, _transform(NULL)
142143
, _filterGraph(NULL)
144+
, _firstInputStreamIndex(std::numeric_limits<size_t>::max())
143145
, _offset(offset)
144146
, _needToSwitchToGenerator(false)
145147
{
@@ -152,17 +154,19 @@ StreamTranscoder::StreamTranscoder(const std::vector<InputStreamDesc>& inputStre
152154
LOG_INFO("add decoder for input stream " << index);
153155
addDecoder(_inputStreamDesc.at(index), *_inputStreams.at(index));
154156
nbOutputChannels += _inputStreamDesc.at(index)._channelIndexArray.size();
157+
if(_firstInputStreamIndex == std::numeric_limits<size_t>::max())
158+
_firstInputStreamIndex = index;
155159
}
156160
else
157161
{
158162
LOG_INFO("add generator for empty input " << index);
159163
addGenerator(_inputStreamDesc.at(index), profile);
164+
nbOutputChannels++;
160165
}
161166
}
162167

163-
const size_t firstInputStreamIndex = getFirstInputStreamIndex();
164-
IInputStream& inputStream = *_inputStreams.at(firstInputStreamIndex);
165-
const InputStreamDesc& inputStreamDesc = inputStreamsDesc.at(firstInputStreamIndex);
168+
IInputStream& inputStream = *_inputStreams.at(_firstInputStreamIndex);
169+
const InputStreamDesc& inputStreamDesc = inputStreamsDesc.at(_firstInputStreamIndex);
166170

167171
// create a transcode case
168172
switch(inputStream.getProperties().getStreamType())
@@ -239,16 +243,6 @@ StreamTranscoder::StreamTranscoder(const std::vector<InputStreamDesc>& inputStre
239243
setOffset(offset);
240244
}
241245

242-
size_t StreamTranscoder::getFirstInputStreamIndex()
243-
{
244-
for(size_t index = 0; index < _inputStreams.size(); ++index)
245-
{
246-
if(_inputStreams.at(index) != NULL)
247-
return index;
248-
}
249-
throw std::runtime_error("Cannot handle only null input streams");
250-
}
251-
252246
void StreamTranscoder::addDecoder(const InputStreamDesc& inputStreamDesc, IInputStream& inputStream)
253247
{
254248
// create a transcode case
@@ -358,6 +352,7 @@ StreamTranscoder::StreamTranscoder(IOutputFile& outputFile, const ProfileLoader:
358352
, _outputEncoder(NULL)
359353
, _transform(NULL)
360354
, _filterGraph(NULL)
355+
, _firstInputStreamIndex(0)
361356
, _offset(0)
362357
, _needToSwitchToGenerator(false)
363358
{
@@ -617,10 +612,9 @@ bool StreamTranscoder::processTranscode()
617612
}
618613

619614
// check the next data buffers in case of audio frames
620-
const size_t firstInputStreamIndex = getFirstInputStreamIndex();
621-
if(_decodedData.at(firstInputStreamIndex)->isAudioFrame())
615+
if(_decodedData.at(_firstInputStreamIndex)->isAudioFrame())
622616
{
623-
const int nbInputSamplesPerChannel = _decodedData.at(firstInputStreamIndex)->getAVFrame().nb_samples;
617+
const int nbInputSamplesPerChannel = _decodedData.at(_firstInputStreamIndex)->getAVFrame().nb_samples;
624618

625619
// Reallocate output frame
626620
if(nbInputSamplesPerChannel > _filteredData->getAVFrame().nb_samples)

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ class AvExport StreamTranscoder
130130
bool processRewrap();
131131
bool processTranscode();
132132

133-
size_t getFirstInputStreamIndex();
134-
135133
private:
136134
std::vector<InputStreamDesc> _inputStreamDesc; ///< Description of the data to extract from the input stream.
137135
std::vector<IInputStream*> _inputStreams; ///< List of input stream to read next packet (has link, no ownership)
@@ -150,6 +148,8 @@ class AvExport StreamTranscoder
150148

151149
FilterGraph* _filterGraph; ///< Filter graph (has ownership)
152150

151+
size_t _firstInputStreamIndex; ///< Index of the first non-null input stream.
152+
153153
float _offset; ///< Offset, in seconds, at the beginning of the StreamTranscoder.
154154

155155
bool _needToSwitchToGenerator; ///< Set if need to switch to a generator during the process (because, of other streams

0 commit comments

Comments
 (0)