Skip to content

Commit f04f47b

Browse files
committed
Merge pull request #63 from cchampet/fix_formatContextCloseInput
Fix FormatContext close input
2 parents bde8526 + 4da5603 commit f04f47b

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace avtranscoder
1010
FormatContext::FormatContext( const std::string& filename, int req_flags )
1111
: _avFormatContext( NULL )
1212
, _options()
13-
, _isOpen( true )
13+
, _isOpen( false )
1414
{
1515
int ret = avformat_open_input( &_avFormatContext, filename.c_str(), NULL, NULL );
1616
if( ret < 0 )
@@ -23,6 +23,7 @@ FormatContext::FormatContext( const std::string& filename, int req_flags )
2323
msg += err;
2424
throw std::ios_base::failure( msg );
2525
}
26+
_isOpen = true;
2627
loadOptions( _options, _avFormatContext, req_flags );
2728
}
2829

@@ -39,7 +40,7 @@ FormatContext::~FormatContext()
3940
{
4041
if( ! _avFormatContext )
4142
return;
42-
43+
4344
if( _isOpen )
4445
avformat_close_input( &_avFormatContext );
4546
else
@@ -52,7 +53,6 @@ void FormatContext::findStreamInfo( AVDictionary** options )
5253
int err = avformat_find_stream_info( _avFormatContext, options );
5354
if( err < 0 )
5455
{
55-
avformat_close_input( &_avFormatContext );
5656
throw std::ios_base::failure( "unable to find stream informations" );
5757
}
5858
}
@@ -65,7 +65,6 @@ void FormatContext::openRessource( const std::string& url, int flags )
6565
int err = avio_open2( &_avFormatContext->pb, url.c_str(), flags, NULL, NULL );
6666
if( err < 0 )
6767
{
68-
avformat_close_input( &_avFormatContext );
6968
throw std::ios_base::failure( "error when opening output format" );
7069
}
7170
}
@@ -78,7 +77,6 @@ void FormatContext::closeRessource()
7877
int err = avio_close( _avFormatContext->pb );
7978
if( err < 0 )
8079
{
81-
avformat_close_input( &_avFormatContext );
8280
throw std::ios_base::failure( "error when close output format" );
8381
}
8482
}

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class AvExport FormatContext
8686
private:
8787
AVFormatContext* _avFormatContext; ///< Has ownership
8888
OptionMap _options;
89-
const bool _isOpen; ///< Is the AVFormatContext open (in constructor with a filename)
89+
bool _isOpen; ///< Is the AVFormatContext open (in constructor with a filename)
9090
};
9191

9292
}

0 commit comments

Comments
 (0)