[Jahshaka-cvs] SF.net SVN: openlibraries:[1479] trunk/src/openmedialib/plugins/avformat/ avformat_p
Status: Beta
Brought to you by:
jahshaka
From: <tim...@us...> - 2009-09-11 13:53:45
|
Revision: 1479 http://openlibraries.svn.sourceforge.net/openlibraries/?rev=1479&view=rev Author: timdewhirst Date: 2009-09-11 13:53:37 +0000 (Fri, 11 Sep 2009) Log Message: ----------- OML * avoid crash on loading files with no audio Modified Paths: -------------- trunk/src/openmedialib/plugins/avformat/avformat_plugin.cpp Modified: trunk/src/openmedialib/plugins/avformat/avformat_plugin.cpp =================================================================== --- trunk/src/openmedialib/plugins/avformat/avformat_plugin.cpp 2009-08-24 11:33:31 UTC (rev 1478) +++ trunk/src/openmedialib/plugins/avformat/avformat_plugin.cpp 2009-09-11 13:53:37 UTC (rev 1479) @@ -1446,7 +1446,7 @@ // Work around for inefficiencies on I frame only seeking // - this should be covered by the AVStream discard and need_parsing values // but they're either wrong or poorly documented... - if ( has_video( ) ) + if ( get_video_stream() ) { std::string codec( get_video_stream( )->codec->codec->name ); if ( codec == "mjpeg" ) @@ -1477,27 +1477,45 @@ // Returns the current video stream inline AVStream *get_video_stream( ) { - assert( context_ && context_->streams[ video_indexes_[ prop_video_index_.value< int >( ) ] ] ); - if ( prop_video_index_.value< int >( ) >= 0 && video_indexes_.size( ) > 0 ) - return context_->streams[ video_indexes_[ prop_video_index_.value< int >( ) ] ]; - else - return 0; + assert( context_ ); + + int prop_video_index = prop_video_index_.value< int >(); + if ( video_indexes_.size() == 0 || prop_video_index < 0 ) + return NULL; + + int video_index = video_indexes_[ prop_video_index ]; + if ( !context_->streams[ video_index ] ) + return NULL; + + return context_->streams[ video_indexes_[ video_index ] ]; } // Returns the current audio stream inline AVStream *get_audio_stream( ) { - assert( context_ && context_->streams[ audio_indexes_[ prop_audio_index_.value< int >( ) ] ] ); - if ( prop_audio_index_.value< int >( ) >= 0 && audio_indexes_.size( ) > 0 ) - return context_->streams[ audio_indexes_[ prop_audio_index_.value< int >( ) ] ]; - else - return 0; + assert( context_ ); + + int prop_audio_index = prop_audio_index_.value< int >(); + if ( audio_indexes_.size() == 0 || prop_audio_index < 0 ) + return NULL; + + int audio_index = audio_indexes_[ prop_audio_index ]; + if ( !context_->streams[ audio_index ] ) + return NULL; + + return context_->streams[ audio_index ]; } // Opens the video codec associated to the current stream void open_video_codec( ) { AVStream *stream = get_video_stream( ); + if ( !stream ) + { + WARNING_LOG << "failed to get_video_stream"; + return; + } + AVCodecContext *codec_context = stream->codec; video_codec_ = avcodec_find_decoder( codec_context->codec_id ); if ( video_codec_ == NULL || avcodec_open( codec_context, video_codec_ ) < 0 ) @@ -1515,6 +1533,12 @@ void open_audio_codec( ) { AVStream *stream = get_audio_stream( ); + if ( !stream ) + { + WARNING_LOG << "failed to get_audio_stream"; + return; + } + AVCodecContext *codec_context = stream->codec; audio_codec_ = avcodec_find_decoder( codec_context->codec_id ); if ( audio_codec_ == NULL || avcodec_open( codec_context, audio_codec_ ) < 0 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |