gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/asobj/NetStream.cpp serv...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/asobj/NetStream.cpp serv...
Date: Fri, 04 May 2007 15:21:00 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/05/04 15:21:00

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

Log message:
                * server/asobj/: NetStream.{cpp,h},
                  NetStreamFfmpeg.cpp, NetStreamGst.cpp:
                  Use an enum for status codes, avoid notifying multiple
                  times the same status.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3091&r2=1.3092
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStream.cpp?cvsroot=gnash&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStream.h?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamGst.cpp?cvsroot=gnash&r1=1.26&r2=1.27

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3091
retrieving revision 1.3092
diff -u -b -r1.3091 -r1.3092
--- ChangeLog   4 May 2007 13:30:21 -0000       1.3091
+++ ChangeLog   4 May 2007 15:20:59 -0000       1.3092
@@ -1,5 +1,12 @@
 2007-05-03 Sandro Santilli <address@hidden>
 
+       * server/asobj/: NetStream.{cpp,h},
+         NetStreamFfmpeg.cpp, NetStreamGst.cpp:
+         Use an enum for status codes, avoid notifying multiple
+         times the same status.
+
+2007-05-03 Sandro Santilli <address@hidden>
+
        * gui/gui.cpp: Add RENDER_ONE_FRAME_EVERY macro to skip
          rendering of a given fraction of movie frames (for debugging).
        * server/video_stream_instance.cpp (display): call

Index: server/asobj/NetStream.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStream.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- server/asobj/NetStream.cpp  1 May 2007 20:33:27 -0000       1.38
+++ server/asobj/NetStream.cpp  4 May 2007 15:21:00 -0000       1.39
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: NetStream.cpp,v 1.38 2007/05/01 20:33:27 strk Exp $ */
+/* $Id: NetStream.cpp,v 1.39 2007/05/04 15:21:00 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -54,7 +54,8 @@
        :
        as_object(getNetStreamInterface()),
        _netCon(NULL),
-       m_env(NULL)
+       m_env(NULL),
+       _lastStatus(invalidStatus)
 {
 }
 
@@ -254,55 +255,97 @@
 void
 NetStream::processStatusNotifications()
 {
+       // Get an exclusive lock so any notification from loader thread will 
wait
        boost::mutex::scoped_lock lock(statusMutex);
 
-       // TODO: check for System.onStatus too !
-       size_t size = m_status_messages.size();
+       // No queued statuses to notify ...
+       if ( _statusQueue.empty() ) return;
+
+       // TODO: check for System.onStatus too ! use a private 
getStatusHandler() method for this.
        as_value status;
-       if (size && get_member("onStatus", &status) && status.is_function())
+       if ( get_member("onStatus", &status) && status.is_function())
        {
-               log_debug("Processing %d status notifications", size);
+               log_debug("Processing %d status notifications", 
_statusQueue.size());
 
-               for (size_t i = 0; i < size; ++i)
+               for (StatusQueue::iterator it=_statusQueue.begin(), 
itE=_statusQueue.end(); it!=itE; ++it)
                {
-                       log_debug(" Invoking onStatus(%s)", 
m_status_messages[i].c_str());
+                       StatusCode code = *it; 
 
-                       // TODO: optimize by reusing the same as_object ?
-                       boost::intrusive_ptr<as_object> o = new as_object();
-                       o->init_member("code", as_value(m_status_messages[i]), 
1);
+                       log_debug(" Invoking onStatus(%s)", 
getStatusCodeInfo(code).first);
 
-                       if (m_status_messages[i].find("StreamNotFound") == 
string::npos && m_status_messages[i].find("InvalidTime") == string::npos)
-                       {
-                               o->init_member("level", as_value("status"), 
as_prop_flags::dontDelete|as_prop_flags::dontEnum);
-                       }
-                       else
-                       {
-                               o->init_member("level", as_value("error"), 
as_prop_flags::dontDelete|as_prop_flags::dontEnum);
-                       }
+                       // TODO: optimize by reusing the same as_object ?
+                       boost::intrusive_ptr<as_object> o = 
getStatusObject(code);
 
                        m_env->push_val(as_value(o.get()));
                        call_method(status, m_env, this, 1, 
m_env->get_top_index() );
                }
+
        }
 
-       m_status_messages.clear();
+       _statusQueue.clear();
+
 }
 
 void
-NetStream::setStatus(const std::string& status)
+NetStream::setStatus(StatusCode status)
 {
-       // TODO: make thread safe !! protect by a mutex, and use the mutex from 
status invoker
+       // status unchanged
+       if ( _lastStatus == status) return;
+
+       // Get a lock to avoid messing with statuses while processing them
        boost::mutex::scoped_lock lock(statusMutex);
 
-       if (m_status_messages.size() && m_status_messages.back() == status)
+       _lastStatus = status;
+       _statusQueue.push_back(status);
+}
+
+std::pair<const char*, const char*>
+NetStream::getStatusCodeInfo(StatusCode code)
+{
+       switch (code)
        {
-               // status unchanged
-               return;
-       }
 
-       m_status_messages.push_back(status);
+               case bufferEmpty:
+                       return make_pair("NetStream.Buffer.Empty", "status");
+
+               case bufferFull:
+                       return make_pair("NetStream.Buffer.Full", "status");
+
+               case bufferFlush:
+                       return make_pair("NetStream.Buffer.Flush", "status");
+
+               case playStart:
+                       return make_pair("NetStream.Play.Start", "status");
+
+               case playStop:
+                       return make_pair("NetStream.Play.Stop", "status");
+
+               case seekNotify:
+                       return make_pair("NetStream.Seek.Notify", "status");
+
+               case streamNotFound:
+                       return make_pair("NetStream.Play.StreamNotFound", 
"error");
+
+               case invalidTime:
+                       return make_pair("NetStream.Seek.InvalidTime", "error");
+
+               default:
+                       return make_pair("","");
+       }
 }
 
+boost::intrusive_ptr<as_object>
+NetStream::getStatusObject(StatusCode code)
+{
+       // code, level
+       std::pair<const char*, const char*> info = getStatusCodeInfo(code);
+
+       boost::intrusive_ptr<as_object> o = new as_object();
+       o->init_member("code",  info.first,  1);
+       o->init_member("level", info.second, 
as_prop_flags::dontDelete|as_prop_flags::dontEnum);
+
+       return o;
+}
 
 
 } // end of gnash namespace

Index: server/asobj/NetStream.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStream.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- server/asobj/NetStream.h    1 May 2007 20:33:27 -0000       1.27
+++ server/asobj/NetStream.h    4 May 2007 15:21:00 -0000       1.28
@@ -18,7 +18,7 @@
 //
 //
 
-/*  $Id: NetStream.h,v 1.27 2007/05/01 20:33:27 strk Exp $ */
+/*  $Id: NetStream.h,v 1.28 2007/05/04 15:21:00 strk Exp $ */
 
 #ifndef __NETSTREAM_H__
 #define __NETSTREAM_H__
@@ -47,13 +47,38 @@
 
 protected:
 
-       boost::intrusive_ptr<NetConnection> _netCon;
+       /// Status codes used for notifications
+       enum StatusCode {
 
-       // List of status messages to be processed
-       std::vector<std::string> m_status_messages;
+               // Internal status, not a valid ActionScript value
+               invalidStatus,
 
-       /// Mutex protecting m_status_messages
-       boost::mutex statusMutex;
+               /// NetStream.Buffer.Empty (level: status)
+               bufferEmpty,
+
+               /// NetStream.Buffer.Full (level: status)
+               bufferFull,
+
+               /// NetStream.Buffer.Flush (level: status)
+               bufferFlush,
+
+               /// NetStream.Play.Start (level: status)
+               playStart,
+
+               /// NetStream.Play.Stop  (level: status)
+               playStop,
+
+               /// NetStream.Seek.Notify  (level: status)
+               seekNotify,
+
+               /// NetStream.Play.StreamNotFound (level: error)
+               streamNotFound,
+
+               /// NetStream.Seek.InvalidTime (level: error)
+               invalidTime
+       };
+
+       boost::intrusive_ptr<NetConnection> _netCon;
 
        /// Set stream status.
        //
@@ -71,16 +96,12 @@
        ///  - NetStream.Play.StreamNotFound
        ///  - NetStream.Seek.InvalidTime
        ///
-       /// TODO: use an enum !
-       ///
-       void setStatus(const std::string& /*code*/);
+       void setStatus(StatusCode code);
 
        /// \brief
        /// Call any onStatus event handler passing it
-       /// any queued status change, see m_status_messages
+       /// any queued status change, see _statusQueue
        //
-       /// TODO: move up to NetStream ?
-       ///
        void processStatusNotifications();
 
        // The actionscript enviroment for the AS callbacks
@@ -129,6 +150,31 @@
                assert(env);
                m_env = env;
        }
+
+private:
+
+       typedef std::vector<StatusCode> StatusQueue;
+
+       /// List of status messages to be processed
+       StatusQueue _statusQueue;
+
+       /// Mutex protecting _statusQueue
+       boost::mutex statusMutex;
+
+       /// Last status code (to avoid consecutively notifying the same event)
+       StatusCode _lastStatus;
+
+       /// Get 'status' (first) and 'level' (second) strings for given status 
code
+       //
+       /// The two members of the pair are ensured to be not-NULL
+       /// Any invalid code, out of bound or explicitly invalid (invalidCode) 
+       /// returns two empty C strings.
+       ///
+       std::pair<const char*, const char*> getStatusCodeInfo(StatusCode code);
+
+       /// Return a newly allocated information object for the given status
+       boost::intrusive_ptr<as_object> getStatusObject(StatusCode code);
+
 };
 
 

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- server/asobj/NetStreamFfmpeg.cpp    4 May 2007 12:00:51 -0000       1.41
+++ server/asobj/NetStreamFfmpeg.cpp    4 May 2007 15:21:00 -0000       1.42
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: NetStreamFfmpeg.cpp,v 1.41 2007/05/04 12:00:51 bjacques Exp $ */
+/* $Id: NetStreamFfmpeg.cpp,v 1.42 2007/05/04 15:21:00 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -367,7 +367,7 @@
        assert(ns);
        if ( !nc->openConnection(ns->url.c_str(), ns) ) {
                log_error(_("Gnash could not open movie: %s"), ns->url.c_str());
-               ns->setStatus("NetStream.Buffer.StreamNotFound");
+               ns->setStatus(streamNotFound);
                return;
        }
 
@@ -376,7 +376,7 @@
        // Check if the file is a FLV, in which case we use our own parser
        char head[4] = {0, 0, 0, 0};
        if (nc->read(head, 3) < 3) {
-               ns->setStatus("NetStream.Buffer.StreamNotFound");
+               ns->setStatus(streamNotFound);
                return;
        }
        nc->seek(0);
@@ -384,7 +384,7 @@
                ns->m_isFLV = true;
                ns->m_parser = new FLVParser();
                if (!nc->connectParser(ns->m_parser)) {
-                       ns->setStatus("NetStream.Buffer.StreamNotFound");
+                       ns->setStatus(streamNotFound);
                        log_error(_("Gnash could not open FLV movie: %s"), 
ns->url.c_str());
                        delete ns->m_parser;
                        return;
@@ -449,7 +449,7 @@
        // Open the stream. the 4th argument is the filename, which we ignore.
        if(av_open_input_stream(&ns->m_FormatCtx, &ns->ByteIOCxt, "", inputFmt, 
NULL) < 0){
                log_error(_("Couldn't open file '%s' for decoding"), 
ns->url.c_str());
-               ns->setStatus("NetStream.Play.StreamNotFound");
+               ns->setStatus(streamNotFound);
                return;
        }
 
@@ -604,7 +604,7 @@
        // This should only happen if close() is called before setup is complete
        if (!ns->m_go) return;
 
-       ns->setStatus("NetStream.Play.Start");
+       ns->setStatus(playStart);
 
        raw_videodata_t* video = NULL;
 
@@ -671,7 +671,7 @@
                }
        }
        ns->m_go = false;
-       ns->setStatus("NetStream.Play.Stop");
+       ns->setStatus(playStop);
 
 }
 
@@ -744,7 +744,7 @@
                                // We pause and load and buffer a second before 
continuing.
                                m_pause = true;
                                m_bufferTime = 
static_cast<uint32_t>(m_video_clock) * 1000 + 1000;
-                               setStatus("NetStream.Buffer.Empty");
+                               setStatus(bufferEmpty);
                                m_start_onbuffer = true;
                        }
                        return false;
@@ -1035,7 +1035,7 @@
 {
        // Check if we should start the playback when a certain amount is 
buffered
        if (m_go && m_pause && m_start_onbuffer && m_parser && 
m_parser->isTimeLoaded(m_bufferTime)) {
-               setStatus("NetStream.Buffer.Full");
+               setStatus(bufferFull);
                m_pause = false;
                m_start_onbuffer = false;
        }

Index: server/asobj/NetStreamGst.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamGst.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- server/asobj/NetStreamGst.cpp       2 May 2007 07:34:35 -0000       1.26
+++ server/asobj/NetStreamGst.cpp       4 May 2007 15:21:00 -0000       1.27
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: NetStreamGst.cpp,v 1.26 2007/05/02 07:34:35 strk Exp $ */
+/* $Id: NetStreamGst.cpp,v 1.27 2007/05/04 15:21:00 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -283,7 +283,7 @@
 
        FLVFrame* frame = ns->m_parser->nextAudioFrame();
        if (!frame) {
-               ns->setStatus("NetStream.Buffer.Empty");
+               ns->setStatus(bufferEmpty);
                ns->m_pausePlayback = true;
                return;
        }
@@ -305,7 +305,7 @@
 
        FLVFrame* frame = ns->m_parser->nextVideoFrame();
        if (!frame) {
-               ns->setStatus("NetStream.Buffer.Empty");
+               ns->setStatus(bufferEmpty);
                ns->m_pausePlayback = true;
                return;
        }
@@ -327,7 +327,7 @@
        // Pass stuff from/to the NetConnection object.
        assert(ns);
        if ( !nc->openConnection(ns->url.c_str(), ns) ) {
-               ns->setStatus("NetStream.Play.StreamNotFound");
+               ns->setStatus(streamNotFound);
                log_debug(_("Gnash could not open movie: %s"), ns->url.c_str());
                return;
        }
@@ -336,7 +336,7 @@
 
        uint8_t head[3];
        if (nc->read(head, 3) < 3) {
-               ns->setStatus("NetStream.Buffer.StreamNotFound");
+               ns->setStatus(streamNotFound);
                return;
        }
        nc->seek(0);
@@ -344,7 +344,7 @@
                ns->m_isFLV = true;
                ns->m_parser = new FLVParser();
                if (!nc->connectParser(ns->m_parser)) {
-                       ns->setStatus("NetStream.Play.StreamNotFound");
+                       ns->setStatus(streamNotFound);
                        log_debug(_("Gnash could not open movie: %s"), 
ns->url.c_str());
                        return;
                        
@@ -591,7 +591,7 @@
                ns->m_start_onbuffer = true;
        }
 
-       ns->setStatus("NetStream.Play.Start");
+       ns->setStatus(playStart);
        return;
 }
 
@@ -627,7 +627,7 @@
                        GST_SEEK_TYPE_SET, GST_SECOND * 
static_cast<long>(newpos),
                        GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
                        log_error("Gstreamer seek failed");
-                       setStatus("NetStream.Seek.InvalidTime");
+                       setStatus(invalidTime);
                        return;
                }*/
        } else {
@@ -635,11 +635,11 @@
                        GST_SEEK_TYPE_SET, GST_SECOND * static_cast<long>(pos),
                        GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
                        log_error("Gstreamer seek failed");
-                       setStatus("NetStream.Seek.InvalidTime");
+                       setStatus(invalidTime);
                        return;
                }
        }
-       setStatus("NetStream.Seek.Notify");
+       setStatus(seekNotify);
 }
 
 void
@@ -654,7 +654,7 @@
 {
        // Check if we should start the playback when a certain amount is 
buffered
        if (m_isFLV && m_pause && m_go && m_start_onbuffer && m_parser && 
m_parser->isTimeLoaded(m_bufferTime)) {
-               setStatus("NetStream.Buffer.Full");
+               setStatus(bufferFull);
                m_pause = false;
                gst_element_set_state (GST_ELEMENT (pipeline), 
GST_STATE_PLAYING);
        }
@@ -665,7 +665,7 @@
                m_pausePlayback = false;
 
                if (_netCon->loadCompleted()) {
-                       setStatus("NetStream.Play.Stop");
+                       setStatus(playStop);
                        gst_element_set_state (GST_ELEMENT (pipeline), 
GST_STATE_NULL);
                        m_go = false;
                } else {




reply via email to

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