gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/asobj/NetStreamFfmpeg.cp...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/asobj/NetStreamFfmpeg.cp...
Date: Mon, 26 Nov 2007 21:53:01 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/11/26 21:53:01

Modified files:
        .              : ChangeLog 
        server/asobj   : NetStreamFfmpeg.cpp NetStreamFfmpeg.h 

Log message:
        more AVPacket wrapping work.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4972&r2=1.4973
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.97&r2=1.98
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.h?cvsroot=gnash&r1=1.50&r2=1.51

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4972
retrieving revision 1.4973
diff -u -b -r1.4972 -r1.4973
--- ChangeLog   26 Nov 2007 20:43:46 -0000      1.4972
+++ ChangeLog   26 Nov 2007 21:53:00 -0000      1.4973
@@ -1,5 +1,9 @@
 2007-11-26 Sandro Santilli <address@hidden>
 
+       * server/asobj/NetStreamFfmpeg.{cpp,h}: more AVPacket wrapping work.
+
+2007-11-26 Sandro Santilli <address@hidden>
+
        * server/as_value.{cpp,h}: add is_sprite() and a way to get the sprite
          value w/out re-evaluating path.
        * server/sprite_instance.cpp (get_path_element): don't re-evaluate

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -b -r1.97 -r1.98
--- server/asobj/NetStreamFfmpeg.cpp    26 Nov 2007 20:11:05 -0000      1.97
+++ server/asobj/NetStreamFfmpeg.cpp    26 Nov 2007 21:53:00 -0000      1.98
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: NetStreamFfmpeg.cpp,v 1.97 2007/11/26 20:11:05 bwy Exp $ */
+/* $Id: NetStreamFfmpeg.cpp,v 1.98 2007/11/26 21:53:00 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -720,8 +720,6 @@
 
 bool NetStreamFfmpeg::decodeFLVFrame()
 {
-       PktPointer packet;
-
        FLVFrame* frame = NULL;
        if (m_qvideo.size() < m_qaudio.size() && m_VCodecCtx) {
                frame = m_parser->nextVideoFrame();
@@ -745,6 +743,8 @@
                return false;
        }
 
+       AvPkt packet;
+       // TODO: move this logic in AvPkt itself  ?
        packet->destruct = avpacket_destruct;
        packet->size = frame->dataSize;
        packet->data = frame->data;
@@ -753,15 +753,15 @@
 
        if (frame->tag == 9) {
                packet->stream_index = 0;
-               return decodeVideo(packet.get());
+               return decodeVideo(packet);
        } else {
                packet->stream_index = 1;
-               return decodeAudio(packet.get());
+               return decodeAudio(packet);
        }
 
 }
 
-bool NetStreamFfmpeg::decodeAudio(AVPacket* packet)
+bool NetStreamFfmpeg::decodeAudio(AvPkt& packet)
 {
        if (!m_ACodecCtx) return false;
 
@@ -829,13 +829,14 @@
        return true;
 }
 
-bool NetStreamFfmpeg::decodeVideo(AVPacket* packet)
+bool NetStreamFfmpeg::decodeVideo(AvPkt& packet)
 {
        if (!m_VCodecCtx) return false;
 
        int got = 0;
        avcodec_decode_video(m_VCodecCtx, m_Frame, &got, packet->data, 
packet->size);
-       if (got) {
+       if (got)
+       {
                boost::scoped_array<uint8_t> buffer;
 
                if (m_imageframe == NULL) {
@@ -969,13 +970,7 @@
                return true;
        }
 
-       // CHECKME: I'm not sure it's safe to call av_free_packet
-       //          on a statically allocated AVPacket.
-       //          Also, heap-allocating and storing in an auto_ptr
-       //          would make this function body simpler.
-       //
-       PktPointer packet;
-       //std::auto_ptr<AVPacket> packet(new AVPacket);
+       AvPkt packet;
        
        int rc = av_read_frame(m_FormatCtx, packet.get());
 
@@ -983,7 +978,8 @@
        {
                if (packet->stream_index == m_audio_index && 
get_sound_handler())
                {
-                       if (!decodeAudio(packet.get())) {
+                       if (!decodeAudio(packet))
+                       {
                                log_error(_("Problems decoding audio frame"));
                                return false;
                        }
@@ -991,7 +987,8 @@
                else
                if (packet->stream_index == m_video_index)
                {
-                       if (!decodeVideo(packet.get())) {
+                       if (!decodeVideo(packet))
+                       {
                                log_error(_("Problems decoding video frame"));
                                return false;
                        }
@@ -1013,13 +1010,16 @@
        double timebase = 0;
 
        // Seek to new position
-       if (m_isFLV) {
+       if (m_isFLV)
+       {
                if (m_parser.get()) {
                        newpos = m_parser->seek(pos);
                } else {
                        newpos = 0;
                }
-       } else if (m_FormatCtx) {
+       }
+       else if (m_FormatCtx)
+       {
 
                AVStream* videostream = m_FormatCtx->streams[m_video_index];
                timebase = static_cast<double>(videostream->time_base.num / 
videostream->time_base.den);
@@ -1029,19 +1029,25 @@
                        log_error(_("%s: seeking failed"), __FUNCTION__);
                        return;
                }
-       } else {
+       }
+       else
+       {
+               // TODO: should we log_debug ??
                return;
        }
 
        // This is kindof hackish and ugly :-(
-       if (newpos == 0) {
+       if (newpos == 0)
+       {
                m_last_video_timestamp = 0;
                m_last_audio_timestamp = 0;
                m_current_timestamp = 0;
 
                m_start_clock = tu_timer::get_ticks();
 
-       } else if (m_isFLV) {
+       }
+       else if (m_isFLV)
+       {
 
                if (m_VCodecCtx) m_start_clock += m_last_video_timestamp - 
newpos;
                else m_start_clock += m_last_audio_timestamp - newpos;
@@ -1049,21 +1055,22 @@
                if (m_ACodecCtx) m_last_audio_timestamp = newpos;
                if (m_VCodecCtx) m_last_video_timestamp = newpos;
                m_current_timestamp = newpos;
-       } else {
-               PktPointer packet;
-               //av_init_packet(&Packet);
+       }
+       else
+       {
+               AvPkt packet;
                double newtime = 0;
-               while (newtime == 0) {
-                       if ( av_read_frame(m_FormatCtx, packet.get()) < 0) {
-                               av_seek_frame(m_FormatCtx, -1, 
0,AVSEEK_FLAG_BACKWARD);
-                               //av_free_packet(&Packet);
+               while (newtime == 0)
+               {
+                       if ( av_read_frame(m_FormatCtx, packet.get()) < 0)
+                       {
+                               av_seek_frame(m_FormatCtx, -1, 0, 
AVSEEK_FLAG_BACKWARD);
                                return;
                        }
 
                        newtime = timebase * 
(double)m_FormatCtx->streams[m_video_index]->cur_dts;
                }
 
-               //av_free_packet(&Packet);
                av_seek_frame(m_FormatCtx, m_video_index, newpos, 0);
                uint32_t newtime_ms = static_cast<int32_t>(newtime / 1000.0);
                m_start_clock += m_last_audio_timestamp - newtime_ms;
@@ -1074,17 +1081,8 @@
        }
        
        // Flush the queues
-       while (m_qvideo.size() > 0)
-       {
-               delete m_qvideo.front();
-               m_qvideo.pop();
-       }
-
-       while (m_qaudio.size() > 0)
-       {
-               delete m_qaudio.front();
-               m_qaudio.pop();
-       }
+       m_qvideo.clear();
+       m_qaudio.clear();
 
 }
 

Index: server/asobj/NetStreamFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- server/asobj/NetStreamFfmpeg.h      26 Nov 2007 20:33:49 -0000      1.50
+++ server/asobj/NetStreamFfmpeg.h      26 Nov 2007 21:53:00 -0000      1.51
@@ -15,7 +15,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-/* $Id: NetStreamFfmpeg.h,v 1.50 2007/11/26 20:33:49 bwy Exp $ */
+/* $Id: NetStreamFfmpeg.h,v 1.51 2007/11/26 21:53:00 strk Exp $ */
 
 #ifndef __NETSTREAMFFMPEG_H__
 #define __NETSTREAMFFMPEG_H__
@@ -93,8 +93,14 @@
        // Destroy all elements of the queue. Locks.
        ~multithread_queue()
                {
+               clear();
+       }
+
+       // Destroy all elements of the queue. Locks.
+       void clear();
+       {
                        boost::mutex::scoped_lock lock(_mutex);
-                       while (m_queue.size() > 0)
+               while (!m_queue.empty())
                        {
                                T x = m_queue.front();
                                m_queue.pop();
@@ -147,7 +153,7 @@
                {
                        boost::mutex::scoped_lock lock(_mutex);
                        T member = NULL;
-                       if (m_queue.size() > 0)
+               if (!m_queue.empty())
                        {
                                member = m_queue.front();
                        }
@@ -162,13 +168,13 @@
                void pop()
                {
                        boost::mutex::scoped_lock lock(_mutex);
-                       if (m_queue.size() > 0)
+               if (!m_queue.empty())
                        {
                                m_queue.pop();
                        }
                }
 
-       private:
+private:
 
                // Mutex used for locking
                boost::mutex _mutex;
@@ -280,39 +286,44 @@
 
 private:
 
-       /// A smart pointer class that creates AVPackets used in decodeVideo()
-       /// and decodeAudio() and frees them when no longer needed.
+       /// A C++ wrapper around ffmpeg's AVPacket structure
+       //
+       /// Used in decodeVideo() and decodeAudio(). 
        /// Use PktPointer.get (as with auto_ptr) to access.
-       class PktPointer
+       ///
+       class AvPkt
        {
        public:
        
-               /// Constructs an auto_ptr containing a heap-allocated (is that
-               /// the best idea?) AVPacket and initializes the usual data 
fields
-               PktPointer () : pktptr(new AVPacket) {
-                       av_init_packet(pktptr.get());
+               /// Constructs and initialize an AVPacket 
+               AvPkt ()
+               {
+                       av_init_packet(&_pkt);
                }
                
-               /// Destructor automatically frees the AVPacket when it goes out
-               /// of scope.
-               ~PktPointer () {
-                       av_free_packet(pktptr.get());
+               /// Properly deinitialize the owned AVPacket 
+               ~AvPkt ()
+               {
+                       av_free_packet(&_pkt);
                }
 
-               /// @ return AVPacket* pointed to by auto_ptr.
-               AVPacket* get () {
-                       return pktptr.get();
+               /// @ return AVPacket* owned by this instance
+               AVPacket* get ()
+               {
+                       return &_pkt;
+       
                }
                
-               // @ return pointers to AVPacket* members in
-               //          auto_ptr
-               AVPacket* operator-> () {
-                       return pktptr.get();
+               /// @ return AVPacket* owned by this instance
+               AVPacket* operator-> ()
+               {
+                       return &_pkt;
                }
+
        private:
-               std::auto_ptr<AVPacket> pktptr;
-               PktPointer(const PktPointer&);
-               PktPointer operator= (const PktPointer&);
+               AVPacket _pkt;
+               AvPkt(const AvPkt&);
+               AvPkt& operator= (const AvPkt&);
        };
 
        // Setups the playback
@@ -366,10 +377,10 @@
        bool decodeFLVFrame();
 
        // Used to decode a video frame and push it on the videoqueue
-       bool decodeVideo(AVPacket* packet);
+       bool decodeVideo(AvPkt& packet);
 
        // Used to decode a audio frame and push it on the audioqueue
-       bool decodeAudio(AVPacket* packet);
+       bool decodeAudio(AvPkt& packet);
 
        // Used to calculate a decimal value from a ffmpeg fraction
        inline double as_double(AVRational time)




reply via email to

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