Skip to content

Commit d0a0c5e

Browse files
committed
Merge pull request #34 from cchampet/improve_InputFile_getStream
InputFile: catch out_of_range exception if getStream at a wrong index
2 parents da3b290 + 2d06ade commit d0a0c5e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,18 @@ AVMediaType InputFile::getStreamType( size_t index )
142142

143143
AvInputStream& InputFile::getStream( size_t index )
144144
{
145-
return *_inputStreams.at( index );
145+
try
146+
{
147+
return *_inputStreams.at( index );
148+
}
149+
catch( const std::out_of_range& e )
150+
{
151+
std::stringstream msg;
152+
msg << getFilename();
153+
msg << " has no stream at index ";
154+
msg << index;
155+
throw std::runtime_error( msg.str() );
156+
}
146157
}
147158

148159
bool InputFile::readNextPacket( CodedData& data, const size_t streamIndex )
@@ -196,12 +207,12 @@ void InputFile::seekAtFrame( const size_t frame )
196207

197208
void InputFile::activateStream( const size_t streamIndex, bool activate )
198209
{
199-
_inputStreams.at( streamIndex )->activate( activate );
210+
getStream( streamIndex ).activate( activate );
200211
}
201212

202213
bool InputFile::isStreamActivated( const size_t streamIndex )
203214
{
204-
return _inputStreams.at( streamIndex )->isActivated();
215+
return getStream( streamIndex ).isActivated();
205216
}
206217

207218
void InputFile::setProfile( const ProfileLoader::Profile& profile )

0 commit comments

Comments
 (0)