gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libmedia/ffmpeg/MediaParserFfmp...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libmedia/ffmpeg/MediaParserFfmp...
Date: Wed, 04 Jun 2008 17:05:26 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/06/04 17:05:26

Modified files:
        .              : ChangeLog 
        libmedia/ffmpeg: MediaParserFfmpeg.cpp MediaParserFfmpeg.h 

Log message:
                * libmedia/ffmpeg/MediaParserFfmpeg.{cpp,h}: implement
                  getBufferLength; reduce chunk size for reads; modify
                  getBytesLoaded to be immune to seek backs; don't check
                  eof in the ffmpeg callback routine but just at the
                  end of each frame parsing.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6816&r2=1.6817
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/MediaParserFfmpeg.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/MediaParserFfmpeg.h?cvsroot=gnash&r1=1.3&r2=1.4

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6816
retrieving revision 1.6817
diff -u -b -r1.6816 -r1.6817
--- ChangeLog   4 Jun 2008 16:49:22 -0000       1.6816
+++ ChangeLog   4 Jun 2008 17:05:25 -0000       1.6817
@@ -1,5 +1,13 @@
 2008-06-04 Sandro Santilli <address@hidden>
 
+       * libmedia/ffmpeg/MediaParserFfmpeg.{cpp,h}: implement
+         getBufferLength; reduce chunk size for reads; modify
+         getBytesLoaded to be immune to seek backs; don't check
+         eof in the ffmpeg callback routine but just at the
+         end of each frame parsing.
+
+2008-06-04 Sandro Santilli <address@hidden>
+
        * libmedia/FLVParser.cpp (getBufferLength): don't rely
          on cursor to tell how much time the buffer contains;
          add notes about need to sort out a rationale for

Index: libmedia/ffmpeg/MediaParserFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/MediaParserFfmpeg.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libmedia/ffmpeg/MediaParserFfmpeg.cpp       4 Jun 2008 14:06:57 -0000       
1.3
+++ libmedia/ffmpeg/MediaParserFfmpeg.cpp       4 Jun 2008 17:05:26 -0000       
1.4
@@ -70,9 +70,6 @@
        size_t actuallyRead = _stream->read_bytes(probe_data.buf, 
probe_data.buf_size);
        _stream->set_position(0);
 
-       if ( actuallyRead > _lastParsedPosition ) // could probably be an 
assertion here (always true)
-               _lastParsedPosition = actuallyRead;
-
        if (actuallyRead < 1)
        {
                log_error(_("Gnash could not read from movie url"));
@@ -80,18 +77,34 @@
        }
 
        probe_data.buf_size = actuallyRead; // right ?
-       return av_probe_input_format(&probe_data, 1);
+       AVInputFormat* ret = av_probe_input_format(&probe_data, 1);
+       return ret;
 }
 
 boost::uint32_t
 MediaParserFfmpeg::getBufferLength()
 {
-       LOG_ONCE( log_unimpl("%s", __PRETTY_FUNCTION__) );
+       // TODO: figure wheter and why we should privilege
+       //       video frames over audio frames when both
+       //       are available
+       //       I belive the corrent behaviour here would
+       //       be using the smallest max-timestamp..
+
+       if (_videoStream && ! _videoFrames.empty())
+       {
+               return _videoFrames.back()->timestamp; 
+       }
+
+       if (_audioStream && ! _audioFrames.empty())
+       {
+               return _audioFrames.back()->timestamp; 
+       }
+
        return 0;
 }
 
 bool
-MediaParserFfmpeg::nextVideoFrameTimestamp(boost::uint64_t& ts)
+MediaParserFfmpeg::nextVideoFrameTimestamp(boost::uint64_t& /*ts*/)
 {
        LOG_ONCE( log_unimpl("%s", __PRETTY_FUNCTION__) );
        return false;
@@ -106,7 +119,7 @@
 }
 
 bool
-MediaParserFfmpeg::nextAudioFrameTimestamp(boost::uint64_t& ts)
+MediaParserFfmpeg::nextAudioFrameTimestamp(boost::uint64_t& /*ts*/)
 {
        LOG_ONCE( log_unimpl("%s", __PRETTY_FUNCTION__) );
        return false;
@@ -183,6 +196,11 @@
        // packet.dts is "decompression" timestamp
        // packet.pts is "presentation" timestamp
        // Dunno why we use dts, and don't understand the magic formula 
either...
+       //
+       // From ffmpeg dox:
+       //    pkt->pts can be AV_NOPTS_VALUE if the video format has B frames,
+       //    so it is better to rely on pkt->dts if you do not decompress the 
payload.
+       //
        boost::uint64_t timestamp = static_cast<boost::uint64_t>(packet.dts * 
as_double(_videoStream->time_base) * 1000.0); 
 
        // flags, for keyframe
@@ -216,19 +234,24 @@
        // packet.dts is "decompression" timestamp
        // packet.pts is "presentation" timestamp
        // Dunno why we use dts, and don't understand the magic formula 
either...
+       //
+       // From ffmpeg dox:
+       //    pkt->pts can be AV_NOPTS_VALUE if the video format has B frames,
+       //    so it is better to rely on pkt->dts if you do not decompress the 
payload.
+       //
        boost::uint64_t timestamp = static_cast<boost::uint64_t>(packet.dts * 
as_double(_audioStream->time_base) * 1000.0); 
 
        // Frame offset in input
        boost::int64_t offset = packet.pos;
        if ( offset < 0 )
        {
-               log_error("Unknown offset of audio frame, what to use here ?");
-               return false;
+               log_error("Unknown offset of audio frame, should we pretend we 
know ? or rely on ffmpeg seeking ? I guess the latter will do for a start.");
+               //return false;
        }
 
        AudioFrameInfo* info = new AudioFrameInfo;
        info->dataSize = packet.size;
-       info->dataPosition = offset;
+       info->dataPosition = offset > 0 ? (boost::uint64_t)offset : 0;
        info->timestamp = timestamp;
 
        _audioFrames.push_back(info); // takes ownership
@@ -239,13 +262,19 @@
 bool
 MediaParserFfmpeg::parseNextFrame()
 {
-       if ( _parsingComplete ) return false;
+       if ( _parsingComplete )
+       {
+               log_debug("MediaParserFfmpeg::parseNextFrame: parsing complete, 
nothing to do");
+               return false;
+       }
 
        assert(_formatCtx);
 
        AVPacket packet;
 
+       log_debug("av_read_frame call");
        int rc = av_read_frame(_formatCtx, &packet);
+       log_debug("av_read_frame returned %d", rc);
        if ( rc < 0 )
        {
                log_error(_("MediaParserFfmpeg::parseNextChunk: Problems 
parsing next frame"));
@@ -270,6 +299,14 @@
 
        av_free_packet(&packet);
 
+       // Check if EOF was reached
+       if ( _stream->get_eof() )
+       {
+               log_debug("MediaParserFfmpeg::parseNextFrame: at eof after 
av_read_frame");
+               _parsingComplete=true;
+       }
+
+
        return ret;
 
 }
@@ -287,7 +324,7 @@
 MediaParserFfmpeg::getBytesLoaded() const
 {
        //log_unimpl("%s", __PRETTY_FUNCTION__);
-       return _stream->get_position();
+       return _lastParsedPosition;
 }
 
 MediaParserFfmpeg::MediaParserFfmpeg(std::auto_ptr<tu_file> stream)
@@ -394,6 +431,7 @@
 int 
 MediaParserFfmpeg::readPacket(boost::uint8_t* buf, int buf_size)
 {
+       //GNASH_REPORT_FUNCTION;
 
        assert( _stream.get() );
        tu_file& in = *_stream;
@@ -404,9 +442,6 @@
        boost::uint64_t curPos = in.get_position();
        if ( curPos > _lastParsedPosition ) _lastParsedPosition = curPos;
 
-       // Check if EOF was reached
-       if ( in.get_eof() ) _parsingComplete=true;
-
        return ret;
 
 }
@@ -414,6 +449,7 @@
 offset_t 
 MediaParserFfmpeg::seekMedia(offset_t offset, int whence)
 {
+       //GNASH_REPORT_FUNCTION;
 
        assert(_stream.get());
        tu_file& in = *(_stream);

Index: libmedia/ffmpeg/MediaParserFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/MediaParserFfmpeg.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libmedia/ffmpeg/MediaParserFfmpeg.h 4 Jun 2008 14:06:57 -0000       1.3
+++ libmedia/ffmpeg/MediaParserFfmpeg.h 4 Jun 2008 17:05:26 -0000       1.4
@@ -219,7 +219,11 @@
        ByteIOContext ByteIOCxt;
 
        /// Size of the ByteIO context buffer
-       static const size_t byteIOBufferSize = 500000;
+       //
+       /// This seems to be the size of chunks read
+       /// by av_read_frame.
+       ///
+       static const size_t byteIOBufferSize = 1024; // 500000;
 
        boost::scoped_array<unsigned char> _byteIOBuffer;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]