[Jahshaka-cvs] openlibraries/src/openmedialib/plugins/avformat avformat_plugin.cpp, 1.39, 1.40
Status: Beta
Brought to you by:
jahshaka
From: Charles Y. <lil...@us...> - 2006-08-17 10:53:07
|
Update of /cvsroot/openlibraries/openlibraries/src/openmedialib/plugins/avformat In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2419 Modified Files: avformat_plugin.cpp Log Message: + Variable bitrate mp3 support, an experimental modification to provide the audio queue with the priority in seek placement and a small clean up relating to store inclusion Index: avformat_plugin.cpp =================================================================== RCS file: /cvsroot/openlibraries/openlibraries/src/openmedialib/plugins/avformat/avformat_plugin.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- avformat_plugin.cpp 15 Aug 2006 13:14:40 -0000 1.39 +++ avformat_plugin.cpp 17 Aug 2006 10:53:00 -0000 1.40 @@ -69,9 +69,6 @@ namespace olib { namespace openmedialib { namespace ml { -char filenameSrc[1024]; - - class ML_PLUGIN_DECLSPEC avformat_store : public store_type, public store_keyboard_feedback { @@ -158,8 +155,6 @@ exit(1); } - dump_format(oc, 0, filenameSrc, 1); - /* now that all the parameters are set, we can open the audio and video codecs and allocate the necessary encode buffers */ if (video_st) @@ -170,9 +165,9 @@ /* open the output file, if needed */ if (!(fmt->flags & AVFMT_NOFILE)) { - if (url_fopen(&oc->pb, filenameSrc, URL_WRONLY) < 0) + if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { - fprintf(stderr, "Could not open '%s'\n", filenameSrc); + fprintf(stderr, "Could not open '%s'\n", filename); exit(1); } } @@ -786,9 +781,6 @@ } if (video_outbuf) free(video_outbuf); - - //if (filenameSrc) - // free(filenameSrc); } @@ -939,15 +931,10 @@ , key_search_( false ) , audio_buf_used_( 0 ) , audio_buf_offset_( 0 ) + , seek_factor_( 1.0 ) + , seek_flag_( AVSEEK_FLAG_BACKWARD ) { - - - - // Ugly - looking to see if a dv1394 device has been specified - - - if ( resource.find( L"/dev/" ) == 0 && resource.find( L"1394/" ) != opl::wstring::npos ) format_ = av_find_input_format( "dv" ); @@ -999,9 +986,6 @@ // Analyse streams and set input values void populate( ) { - - - // Iterate through all the streams available for( int i = 0; i < context_->nb_streams; i++ ) { @@ -1018,21 +1002,6 @@ video_index_ = i; width_ = codec_context->width; height_ = codec_context->height; - - //WidthSrc = 128;//width_;//width_ * 2;//stores the w and h, to be used in the store class... - //HeightSrc = 128;//height_;//height_ * 2; - - - - //filenameSrc, context_->filename - int size=strlen(context_->filename); - //filenameSrc=(char *)malloc(sizeof(size)+1); - memset(filenameSrc,0,size+1); - sprintf(filenameSrc, "%s", context_->filename); - memcpy(&filenameSrc[size-3],"mpg",3);//name to be used in the store class - - - } break; case CODEC_TYPE_AUDIO: @@ -1072,12 +1041,33 @@ if ( has_video( ) ) open_video_codec( ); if ( has_audio( ) ) open_audio_codec( ); + int s = context_->duration / AV_TIME_BASE; + int us = context_->duration % AV_TIME_BASE; + // Set the duration if ( ( uint64_t )context_->duration != AV_NOPTS_VALUE ) - frames_ = int( ( input_type::fps( ) * ( double )context_->duration / ( double )AV_TIME_BASE ) - 2 ); + frames_ = int( ( input_type::fps( ) * ( double )context_->duration / ( double )AV_TIME_BASE ) ); else frames_ = 1 << 29; + // This is a nasty bit of code to provide support for variable bit rate mp3s + if ( uri_.find( L".mp3" ) != opl::wstring::npos ) + { + seek( frames_ - 1 ); + must_decode_ = false; + if ( seek_to_position( ) ) + { + av_init_packet( &pkt_ ); + int original = frames_; + if ( av_read_frame( context_, &pkt_ ) >= 0 ) + frames_ = int( av_q2d( get_audio_stream( )->time_base ) * pkt_.pts * input_type::fps( ) ) + 1; + seek_factor_ = double( original ) / double( frames_ ); + seek_flag_ = AVSEEK_FLAG_ANY; + } + seek( 0 ); + seek_to_position( ); + } + // 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... @@ -1142,7 +1132,7 @@ // Gets the timestamp of the requested frame inline int64_t get_time_stamp( ) { - int64_t timestamp = ( int64_t )( ( double )get_position( ) / input_type::fps( ) * AV_TIME_BASE ); + int64_t timestamp = ( int64_t )( ( ( double )get_position( ) * seek_factor_ / input_type::fps( ) ) * AV_TIME_BASE ); if ( ( uint64_t )context_->start_time != AV_NOPTS_VALUE ) timestamp += context_->start_time; return timestamp; @@ -1151,8 +1141,6 @@ // Seek to the requested frame inline bool seek_to_position( ) { - - int64_t offset = get_time_stamp( ); if ( must_decode_ ) { @@ -1161,18 +1149,12 @@ offset = 0; key_search_ = true; } - return av_seek_frame( context_, -1, offset, AVSEEK_FLAG_BACKWARD ) >= 0; + return av_seek_frame( context_, -1, offset, seek_flag_ ) >= 0; } // Decode the image - - - - - int decode_image( bool &got_picture ) { - AVCodecContext *codec_context = get_video_stream( )->codec; int ret = 0; @@ -1201,8 +1183,6 @@ else if ( must_decode_ ) avcodec_decode_video( codec_context, av_frame_, &got_dummy, pkt_.data, pkt_.size ); - - got_picture = got_pict != 0; // If we have just done a search, then we need to locate the first key frame @@ -1315,12 +1295,11 @@ double pts = 0; if ( ( uint64_t )pkt_.pts != AV_NOPTS_VALUE ) pts = av_q2d( get_audio_stream( )->time_base ) * pkt_.pts; - int found = int( pts * input_type::fps( ) + 0.5 ); + int found = int( pts * input_type::fps( ) ); if ( ( uint64_t )context_->start_time != AV_NOPTS_VALUE ) found -= int( context_->start_time * input_type::fps( ) / AV_TIME_BASE ); - // Get the audio info from the codec context int channels = codec_context->channels; int frequency = codec_context->sample_rate; @@ -1530,7 +1509,7 @@ if ( images_.size( ) > 0 ) valid = images_[ 0 ]->position( ); if ( audio_.size( ) > 0 ) - valid = audio_[ 0 ]->position( ) > valid ? audio_[ 0 ]->position( ) : valid; + valid = audio_[ 0 ]->position( ); if ( get_position( ) >= valid && get_position( ) < int( expected_ + 2 * fps( ) ) ) ; @@ -1639,6 +1618,8 @@ unsigned char audio_buf_[ ( AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 ) / 2 ]; int audio_buf_used_; int audio_buf_offset_; + double seek_factor_; + int seek_flag_; }; // @@ -1655,21 +1636,14 @@ result_type_ptr result = result_type_ptr( new avformat_input( resource ) ); if ( !result->is_valid( ) ) result = result_type_ptr( ); - - return result; } + //este es el metodo que hay que hacer mañana, para que se cree un store.... //virtual store_type_ptr store( const openpluginlib::wstring &resource, const frame_type_ptr &frame ) = 0; - - - - virtual store_type_ptr store( const opl::wstring &, const frame_type_ptr &frame ) { return store_type_ptr( avformat_store::get_instance( frame )); - - } }; @@ -1731,13 +1705,5 @@ { delete static_cast< plugin::avformat_plugin * >( plug ); } - - - - - - } - - |