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: Bastiaan Jacques
Subject: [Gnash-commit] gnash ChangeLog server/asobj/NetStreamFfmpeg.cp...
Date: Sun, 08 Apr 2007 15:23:44 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Bastiaan Jacques <bjacques>     07/04/08 15:23:43

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

Log message:
        Only use a single
        thread (rather than two extra threads) for decoding. Plug a
        memory leak (ByteIOCxt.buffer). Modularise some more code

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2814&r2=1.2815
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.h?cvsroot=gnash&r1=1.18&r2=1.19

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2814
retrieving revision 1.2815
diff -u -b -r1.2814 -r1.2815
--- ChangeLog   8 Apr 2007 14:32:10 -0000       1.2814
+++ ChangeLog   8 Apr 2007 15:23:43 -0000       1.2815
@@ -1,3 +1,10 @@
+2007-04-08 Bastiaan Jacques <address@hidden>
+
+       * server/asobj/NetStreamFfmpeg{.cpp, .h}: Only use a single
+       thread (rather than two extra threads) for decoding. Plug a
+       memory leak (ByteIOCxt.buffer). Modularise some more code.
+
+
 2007-04-08 Ann Barcomb <address@hidden>
 
        * devtools/testsuite/c_casts.t: added this test at Bastiaan's

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- server/asobj/NetStreamFfmpeg.cpp    7 Apr 2007 12:50:04 -0000       1.33
+++ server/asobj/NetStreamFfmpeg.cpp    8 Apr 2007 15:23:43 -0000       1.34
@@ -14,7 +14,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.cpp,v 1.33 2007/04/07 12:50:04 tgc Exp $ */
+/* $Id: NetStreamFfmpeg.cpp,v 1.34 2007/04/08 15:23:43 bjacques Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -31,6 +31,7 @@
 #include "NetConnection.h"
 #include "sound_handler.h"
 #include "action.h"
+#include <boost/scoped_array.hpp>
 
 #if defined(_WIN32) || defined(WIN32)
        #include <Windows.h>    // for sleep()
@@ -58,8 +59,7 @@
        m_Frame(NULL),
        m_Resample(NULL),
 
-       m_thread(NULL),
-       startThread(NULL),
+       _decodeThread(NULL),
 
        m_go(false),
        m_imageframe(NULL),
@@ -75,12 +75,14 @@
        m_start_onbuffer(false),
        m_env(NULL)
 {
+
+       ByteIOCxt.buffer = NULL;
 }
 
 NetStreamFfmpeg::~NetStreamFfmpeg()
 {
        close();
-       if (m_parser) delete m_parser;
+       delete m_parser;
 }
 
 void NetStreamFfmpeg::setEnvironment(as_environment* env)
@@ -116,12 +118,9 @@
                // terminate thread
                m_go = false;
 
-               startThread->join();
-               delete startThread;
-
                // wait till thread is complete before main continues
-               m_thread->join();
-               delete m_thread;
+               _decodeThread->join();
+               delete _decodeThread;
 
        }
 
@@ -167,6 +166,8 @@
                m_qaudio.pop();
        }
 
+       delete [] ByteIOCxt.buffer;
+
 }
 
 // ffmpeg callback function
@@ -242,19 +243,8 @@
        m_go = true;
        m_pause = true;
 
-       if (!m_parser && !m_FormatCtx) {
-               // To avoid blocking while connecting, we use a thread.
-               startThread = new 
boost::thread(boost::bind(NetStreamFfmpeg::startPlayback, this));
-
-       } else {
-               // We need to restart the audio
-               sound_handler* s = get_sound_handler();
-               if (s) s->attach_aux_streamer(audio_streamer, (void*) this);
-
-       }
-
        // This starts the decoding thread
-       m_thread = new boost::thread(boost::bind(NetStreamFfmpeg::av_streamer, 
this)); 
+       _decodeThread = new 
boost::thread(boost::bind(NetStreamFfmpeg::av_streamer, this)); 
 
        return 0;
 }
@@ -358,6 +348,31 @@
        return initContext(codec_id);
 }
 
+
+/// Probe the stream and try to figure out what the format is.
+//
+/// @param ns the netstream to use for reading
+/// @return a pointer to the AVInputFormat structure containing
+///         information about the input format, or NULL.
+static AVInputFormat*
+probeStream(NetStreamFfmpeg* ns)
+{
+       boost::scoped_array<uint8_t> buffer(new uint8_t[2048]);
+
+       // Probe the file to detect the format
+       AVProbeData probe_data;
+       probe_data.filename = "";
+       probe_data.buf = buffer.get();
+       probe_data.buf_size = 2048;
+
+       if (ns->readPacket(ns, probe_data.buf, probe_data.buf_size) < 1){
+               log_warning("Gnash could not read from movie url.");
+               return NULL;
+       }
+
+       return av_probe_input_format(&probe_data, 1);
+}
+
 void
 NetStreamFfmpeg::startPlayback(NetStreamFfmpeg* ns)
 {
@@ -429,26 +444,15 @@
        // This registers all available file formats and codecs 
        // with the library so they will be used automatically when
        // a file with the corresponding format/codec is opened
-
+       // XXX should we call avcodec_init() first?
        av_register_all();
 
-       // Open video file
-
-       // Probe the file to detect the format
-       AVProbeData probe_data, *pd = &probe_data;
-       pd->filename = "";
-       pd->buf = new uint8_t[2048];
-       pd->buf_size = 2048;
-
-       if (readPacket(ns, pd->buf, pd->buf_size) < 1){
-               log_warning("Gnash could not read from movie url: %s", 
ns->url.c_str());
-               delete[] pd->buf;
+       AVInputFormat* inputFmt = probeStream(ns);
+       if (!inputFmt) {
+               log_error("Couldn't determine stream input format from URL %s", 
ns->url.c_str());
                return;
        }
 
-       AVInputFormat* inputFmt = av_probe_input_format(pd, 1);
-       delete[] pd->buf;
-
        // After the format probe, reset to the beginning of the file.
        nc->seek(0);
 
@@ -575,11 +579,16 @@
 // decoder thread
 void NetStreamFfmpeg::av_streamer(NetStreamFfmpeg* ns)
 {
-       // Wait for startThread to finish.
-       // XXX if this method is to start right after startThread finishes, why 
is this
-       //     method not called directly by startThread, instead of having its 
own
-       //     execution thread?
-       ns->startThread->join();
+
+       if (!ns->m_parser && !ns->m_FormatCtx) {
+               startPlayback(ns);
+       } else {
+               // We need to restart the audio
+               sound_handler* s = get_sound_handler();
+               if (s) {
+                       s->attach_aux_streamer(audio_streamer, ns);
+               }
+       }
 
        // This should only happen if close() is called before setup is complete
        if (!ns->m_go) return;
@@ -784,7 +793,7 @@
                        int got = 0;
                        avcodec_decode_video(m_VCodecCtx, m_Frame, &got, 
packet.data, packet.size);
                        if (got) {
-                               uint8_t *buffer = NULL;
+                               boost::scoped_array<uint8_t> buffer;
 
                                int videoFrameFormat = 
gnash::render::videoFrameFormat();
                                if (m_imageframe == NULL) {
@@ -806,8 +815,8 @@
                                } else if (videoFrameFormat == render::RGB && 
m_VCodecCtx->pix_fmt != PIX_FMT_RGB24) {
                                        AVFrame* frameRGB = 
avcodec_alloc_frame();
                                        unsigned int numBytes = 
avpicture_get_size(PIX_FMT_RGB24, m_VCodecCtx->width, m_VCodecCtx->height);
-                                       buffer = new uint8_t[numBytes];
-                                       avpicture_fill((AVPicture *)frameRGB, 
buffer, PIX_FMT_RGB24, m_VCodecCtx->width, m_VCodecCtx->height);
+                                       buffer.reset(new uint8_t[numBytes]);
+                                       avpicture_fill((AVPicture *)frameRGB, 
buffer.get(), PIX_FMT_RGB24, m_VCodecCtx->width, m_VCodecCtx->height);
                                        img_convert((AVPicture*) frameRGB, 
PIX_FMT_RGB24, (AVPicture*) m_Frame, m_VCodecCtx->pix_fmt, m_VCodecCtx->width, 
m_VCodecCtx->height);
                                        av_free(m_Frame);
                                        m_Frame = frameRGB;
@@ -880,7 +889,6 @@
                                                }
                                        }
                                }
-                               delete [] buffer;
 
                                m_unqueued_data = m_qvideo.push(video) ? NULL : 
video;
                        }

Index: server/asobj/NetStreamFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- server/asobj/NetStreamFfmpeg.h      7 Apr 2007 11:55:50 -0000       1.18
+++ server/asobj/NetStreamFfmpeg.h      8 Apr 2007 15:23:43 -0000       1.19
@@ -14,7 +14,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.18 2007/04/07 11:55:50 tgc Exp $ */
+/* $Id: NetStreamFfmpeg.h,v 1.19 2007/04/08 15:23:43 bjacques Exp $ */
 
 #ifndef __NETSTREAMFFMPEG_H__
 #define __NETSTREAMFFMPEG_H__
@@ -207,8 +207,7 @@
        // Use for resampling audio
        ReSampleContext *m_Resample;
 
-       boost::thread *m_thread;
-       boost::thread *startThread;
+       boost::thread* _decodeThread;
        boost::mutex decoding_mutex;
        boost::mutex image_mutex;
 




reply via email to

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