gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libbase/curl_adapter.cpp libbas...


From: Tomas Groth
Subject: [Gnash-commit] gnash ChangeLog libbase/curl_adapter.cpp libbas...
Date: Sun, 04 Mar 2007 21:35:31 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Tomas Groth <tgc>       07/03/04 21:35:31

Modified files:
        .              : ChangeLog 
        libbase        : curl_adapter.cpp noseek_fd_adapter.cpp 
                         tu_file.cpp tu_file.h zlib_adapter.cpp 
        server/asobj   : NetConnection.cpp NetConnection.h NetStream.cpp 
                         NetStream.h NetStreamFfmpeg.cpp 
                         NetStreamFfmpeg.h NetStreamGst.cpp 
                         NetStreamGst.h 

Log message:
        * libbase/curl_adapter.cpp: Added support for getting the total size
          of file being downloaded (get_stream_size()), and the current cached 
          size (get_cur_stream_size()).
        * libbase/tu_file.{cpp,h}: Added get_size() and get_cur_size() which 
          uses get_stream_size() and get_cur_stream_size().
        * libbase/noseek_fd_adapter.cpp, libbase/zlib_adapter.cpp: Added dummy
          support for get_stream_size() and get_cur_stream_size()
        * server/asobj/NetConnection.{cpp,h}: Switched to use StreamProvider
        * server/asobj/NetStream.{cpp,h}, server/asobj/NetStreamFfmpeg.{cpp,h},
          server/asobj/NetStreamGst.{cpp,h}: Added support for the bytesLoaded 
          and bytesTotal property.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2532&r2=1.2533
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/curl_adapter.cpp?cvsroot=gnash&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/noseek_fd_adapter.cpp?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.cpp?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.h?cvsroot=gnash&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/zlib_adapter.cpp?cvsroot=gnash&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetConnection.cpp?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetConnection.h?cvsroot=gnash&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStream.cpp?cvsroot=gnash&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStream.h?cvsroot=gnash&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.h?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamGst.cpp?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamGst.h?cvsroot=gnash&r1=1.7&r2=1.8

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2532
retrieving revision 1.2533
diff -u -b -r1.2532 -r1.2533
--- ChangeLog   4 Mar 2007 02:22:00 -0000       1.2532
+++ ChangeLog   4 Mar 2007 21:35:30 -0000       1.2533
@@ -1,3 +1,17 @@
+2007-03-04 Tomas Groth Christensen <address@hidden>
+
+       * libbase/curl_adapter.cpp: Added support for getting the total size
+         of file being downloaded (get_stream_size()), and the current cached 
+         size (get_cur_stream_size()).
+       * libbase/tu_file.{cpp,h}: Added get_size() and get_cur_size() which 
+         uses get_stream_size() and get_cur_stream_size().
+       * libbase/noseek_fd_adapter.cpp, libbase/zlib_adapter.cpp: Added dummy
+         support for get_stream_size() and get_cur_stream_size()
+       * server/asobj/NetConnection.{cpp,h}: Switched to use StreamProvider
+       * server/asobj/NetStream.{cpp,h}, server/asobj/NetStreamFfmpeg.{cpp,h},
+         server/asobj/NetStreamGst.{cpp,h}: Added support for the bytesLoaded 
+         and bytesTotal property.
+
 2007-03-03 Sandro Santilli <address@hidden>
 
        * server/as_value.h: add ALLOW_C_FUNCTION_VALUES to prepare

Index: libbase/curl_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/curl_adapter.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- libbase/curl_adapter.cpp    25 Feb 2007 20:30:56 -0000      1.22
+++ libbase/curl_adapter.cpp    4 Mar 2007 21:35:31 -0000       1.23
@@ -16,7 +16,7 @@
 
 // 
 
-/* $Id: curl_adapter.cpp,v 1.22 2007/02/25 20:30:56 strk Exp $ */
+/* $Id: curl_adapter.cpp,v 1.23 2007/03/04 21:35:31 tgc Exp $ */
 
 #if defined(_WIN32) || defined(WIN32)
 #define snprintf _snprintf
@@ -125,6 +125,11 @@
        /// Put read pointer at eof
        bool seek_to_end();
 
+       /// Returns the size of the stream
+       long get_stream_size();
+
+       /// Returns the size of the cached part of the stream
+       long get_cur_stream_size();
 private:
 
        void init(const std::string& url);
@@ -152,6 +157,9 @@
        // Post data. Empty if no POST has been requested
        std::string _postdata;
 
+       // Current size of cached data
+       long _cached;
+
        // Attempt at filling the cache up to the given size.
        // Will call libcurl routines to fetch data.
        void fill_cache(off_t size);
@@ -222,6 +230,9 @@
                throw gnash::GnashException(errmsg);
        }
 
+       // Set the size of cached data
+       _cached = ftell(_cache);
+
        // reset position for next read
        fseek(_cache, curr_pos, SEEK_SET);
 
@@ -285,6 +296,8 @@
        _url = url;
        _running = 1;
 
+       _cached = -1;
+
        _handle = curl_easy_init();
        _mhandle = curl_multi_init();
 
@@ -499,6 +512,35 @@
 
 }
 
+/*public*/
+long
+CurlStreamFile::get_stream_size()
+{
+       double size;
+       curl_easy_getinfo(_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &size);
+
+       int ret = static_cast<long>(size);
+
+#ifdef GNASH_CURL_VERBOSE
+       fprintf(stderr, "get_stream_size() returning %ld\n", ret);
+#endif
+
+       return ret;
+
+}
+
+/*public*/
+long
+CurlStreamFile::get_cur_stream_size()
+{
+
+#ifdef GNASH_CURL_VERBOSE
+       fprintf(stderr, "get_cur_stream_size() returning %ld\n", _cached);
+#endif
+
+       return _cached;
+
+}
 /***********************************************************************
  *
  * Adapter calls
@@ -551,6 +593,22 @@
        return stream->tell();
 }
 
+static long
+get_stream_size(void* appdata)
+{
+       CurlStreamFile* stream = (CurlStreamFile*) appdata;
+       return stream->get_stream_size();
+
+}
+
+static long
+get_cur_stream_size(void* appdata)
+{
+       CurlStreamFile* stream = (CurlStreamFile*) appdata;
+       return stream->get_cur_stream_size();
+
+}
+
 static int
 close(void* appdata)
 {
@@ -593,6 +651,8 @@
                seek_to_end, // seek_to_end
                tell, // tell
                eof, // get eof
+               get_stream_size, // size of stream 
+               get_cur_stream_size, // current size of cached stream 
                close);
 }
 
@@ -623,6 +683,8 @@
                seek_to_end, // seek_to_end
                tell, // tell
                eof, // get eof
+               get_stream_size, // size of stream 
+               get_cur_stream_size, // current size of cached stream 
                close);
 }
 

Index: libbase/noseek_fd_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/noseek_fd_adapter.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- libbase/noseek_fd_adapter.cpp       4 Nov 2006 16:18:11 -0000       1.12
+++ libbase/noseek_fd_adapter.cpp       4 Mar 2007 21:35:31 -0000       1.13
@@ -16,7 +16,7 @@
 
 // 
 
-/* $Id: noseek_fd_adapter.cpp,v 1.12 2006/11/04 16:18:11 alexeev Exp $ */
+/* $Id: noseek_fd_adapter.cpp,v 1.13 2007/03/04 21:35:31 tgc Exp $ */
 
 #if defined(_WIN32) || defined(WIN32)
 #define snprintf _snprintf
@@ -489,6 +489,8 @@
                seek_to_end, // seek_to_end
                tell, // tell
                eof, // get eof
+               NULL, // get stream size
+               NULL, // get cur stream size
                close);
 }
 

Index: libbase/tu_file.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- libbase/tu_file.cpp 10 Feb 2007 17:54:06 -0000      1.11
+++ libbase/tu_file.cpp 4 Mar 2007 21:35:31 -0000       1.12
@@ -87,6 +87,21 @@
     }
 }
 
+static long
+std_get_stream_size_func(void *appdata)
+// Return -1 on failure, or the size
+{
+    assert(appdata);
+    int        org_pos = ftell((FILE*)appdata);
+
+       fseek((FILE*)appdata, 0, SEEK_END);
+       int ret = ftell((FILE*)appdata);
+
+       fseek((FILE*)appdata, org_pos, SEEK_SET);
+       return ret;
+}
+
+
 static int
 std_close_func(void *appdata)
 // Return 0 on success, or TU_FILE_CLOSE_ERROR on failure.
@@ -271,6 +286,18 @@
     return buf->m_position >= buf->m_.size();
 }
 
+static long
+mem_get_stream_size(void* appdata)
+// Return the file size, or -1 on failure.
+{
+    assert(appdata);
+    
+    filebuf* buf = (filebuf*) appdata;
+    assert(buf->is_valid());
+    
+    return buf->m_.size();
+}
+
 static int mem_close_func(void* appdata)
 // Return 0 on success, or TU_FILE_CLOSE_ERROR on failure.
 {
@@ -292,7 +319,7 @@
 // Create a file using the custom callbacks.
 tu_file::tu_file(void * appdata, read_func rf, write_func wf,
                 seek_func sf, seek_to_end_func ef, tell_func tf,
-                get_eof_func gef, close_func cf)
+                get_eof_func gef, get_stream_size_func gss, 
get_cur_stream_size_func gcss, close_func cf)
 {
     m_data = appdata;
     m_read = rf;
@@ -301,6 +328,8 @@
     m_seek_to_end = ef;
     m_tell = tf;
     m_get_eof = gef;
+    m_get_stream_size = gss;
+    m_get_cur_stream_size = gcss;
     m_close = cf;
     m_error = TU_FILE_NO_ERROR;
 }
@@ -317,6 +346,8 @@
     m_seek_to_end = std_seek_to_end_func;
     m_tell = std_tell_func;
     m_get_eof = std_get_eof_func;
+    m_get_stream_size = std_get_stream_size_func;
+    m_get_cur_stream_size = std_get_stream_size_func;
     m_close = autoclose ? std_close_func : NULL;
     m_error = TU_FILE_NO_ERROR;
 }
@@ -335,6 +366,8 @@
        m_seek_to_end = std_seek_to_end_func;
        m_tell = std_tell_func;
        m_get_eof = std_get_eof_func;
+    m_get_stream_size = std_get_stream_size_func;
+    m_get_cur_stream_size = std_get_stream_size_func;
        m_close = std_close_func;
        m_error = TU_FILE_NO_ERROR;
     } else {
@@ -344,6 +377,8 @@
        m_seek_to_end = NULL;
        m_tell = NULL;
        m_get_eof = NULL;
+    m_get_stream_size = NULL;
+    m_get_cur_stream_size = NULL;
        m_close = NULL;
        m_error = TU_FILE_OPEN_ERROR;
     }
@@ -360,6 +395,8 @@
     m_seek_to_end = mem_seek_to_end_func;
     m_tell = mem_tell_func;
     m_get_eof = mem_get_eof_func;
+    m_get_stream_size = mem_get_stream_size;
+    m_get_cur_stream_size = mem_get_stream_size;
     m_close = mem_close_func;
     m_error = TU_FILE_NO_ERROR;
 }
@@ -376,6 +413,8 @@
     m_seek_to_end = mem_seek_to_end_func;
     m_tell = mem_tell_func;
     m_get_eof = mem_get_eof_func;
+    m_get_stream_size = mem_get_stream_size;
+    m_get_cur_stream_size = mem_get_stream_size;
     m_close = mem_close_func;
     m_error = TU_FILE_NO_ERROR;
 }

Index: libbase/tu_file.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- libbase/tu_file.h   14 Sep 2006 23:54:22 -0000      1.9
+++ libbase/tu_file.h   4 Mar 2007 21:35:31 -0000       1.10
@@ -43,6 +43,8 @@
     typedef int (* seek_to_end_func)(void* appdata);
     typedef int (* tell_func)(void* appdata);
     typedef bool (* get_eof_func)(void* appdata);
+    typedef long (* get_stream_size_func)(void* appdata);
+    typedef long (* get_cur_stream_size_func)(void* appdata);
     typedef int (* close_func)(void* appdata);
     
     // The generic constructor; supply functions for the implementation.
@@ -54,6 +56,8 @@
        seek_to_end_func ef,
        tell_func tf,
        get_eof_func gef,
+       get_stream_size_func gss,
+       get_cur_stream_size_func gcss,
        close_func cf=NULL);
     
     // Make a file from an ordinary FILE*.
@@ -132,6 +136,11 @@
     
     int        get_error() { return m_error; }
     
+
+       // get the size of the stream
+       int get_size() { return m_get_stream_size(m_data); }
+       int get_cur_size() { return m_get_cur_stream_size(m_data); }
+
     // printf-style convenience function.
     int        printf(const char* fmt, ...);
     
@@ -183,6 +192,8 @@
     seek_to_end_func   m_seek_to_end;
     tell_func          m_tell;
     get_eof_func       m_get_eof;
+    get_stream_size_func       m_get_stream_size;
+    get_cur_stream_size_func   m_get_cur_stream_size;
     close_func         m_close;
     int                m_error;
 };

Index: libbase/zlib_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/zlib_adapter.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- libbase/zlib_adapter.cpp    16 Jan 2007 23:53:23 -0000      1.11
+++ libbase/zlib_adapter.cpp    4 Mar 2007 21:35:31 -0000       1.12
@@ -322,6 +322,8 @@
                                inflate_seek_to_end,
                                inflate_tell,
                                inflate_get_eof,
+                               NULL, // get stream size
+                               NULL, // get cur stream size
                                inflate_close)
                        );
        }

Index: server/asobj/NetConnection.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetConnection.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- server/asobj/NetConnection.cpp      4 Mar 2007 01:39:01 -0000       1.26
+++ server/asobj/NetConnection.cpp      4 Mar 2007 21:35:31 -0000       1.27
@@ -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: NetConnection.cpp,v 1.26 2007/03/04 01:39:01 strk Exp $ */
+/* $Id: NetConnection.cpp,v 1.27 2007/03/04 21:35:31 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -29,6 +29,7 @@
 #include "builtin_function.h"
 #include "movie_root.h"
 
+#include "StreamProvider.h"
 #include "URLAccessManager.h"
 #include "URL.h"
 
@@ -50,142 +51,17 @@
 /// system, using curl.
 
 
-// Ensure libcurl is initialized
-static void ensure_libcurl_initialized()
-{
-       static bool initialized=0;
-       if ( ! initialized ) {
-#ifdef USE_CURL
-
-               // TODO: handle an error here
-               curl_global_init(CURL_GLOBAL_ALL);
-#else
-               log_error("Network support disabled (libcurl disabled at 
compile-time)");
-#endif
-               initialized=1;
-       }
-}
-
-/*static private*/
-int
-NetConnection::progress_callback(void *clientp, double dltotal, 
-               double /*dlnow*/, double /*ultotal*/, double /*ulnow*/)
-{
-
-       NetConnection* stream = (NetConnection*)clientp;
-       stream->totalSize = dltotal;
-       /*if (stream->callback && stream->callback_cache >= dltotal) {
-               stream->netStreamObj->startPlayback();
-               stream->callback = false;
-       }*/
-       return 0;
-}
-
-/*static private*/
-size_t
-NetConnection::recv(void *buf, size_t  size,  size_t  nmemb, 
-       void *userp)
-{
-
-       NetConnection* stream = (NetConnection*)userp;
-       return stream->cache(buf, size*nmemb);
-}
-
-       
-/*private*/
-size_t
-NetConnection::cache(void *from, size_t sz)
-{
-       // take note of current position
-       long curr_pos = ftell(_cache);
-
-       // seek to the end
-       fseek(_cache, 0, SEEK_END);
-
-       size_t wrote = fwrite(from, 1, sz, _cache);
-       if ( wrote < 1 )
-       {
-               char errmsg[256];
-       
-               snprintf(errmsg, 255,
-                       "writing to cache file: requested " SIZET_FMT ", wrote 
" SIZET_FMT " (%s)",
-                       sz, wrote, strerror(errno));
-               fprintf(stderr, "%s\n", errmsg);
-               throw gnash::GnashException(errmsg);
-       }
-
-       // reset position for next read
-       fseek(_cache, curr_pos, SEEK_SET);
-
-       return wrote;
-}
-
-/*public*/
-size_t
-NetConnection::tell()
-{
-       long ret =  ftell(_cache);
-
-       return ret;
-
-}
-
-/*private*/
-void
-NetConnection::fill_cache(off_t size)
-{
-       struct stat statbuf;
-
-#ifdef USE_CURL
-       CURLMcode mcode;
-       while (_running)
-       {
-               do
-               {
-                       mcode=curl_multi_perform(_mhandle, &_running);
-               } while ( mcode == CURLM_CALL_MULTI_PERFORM );
-
-               if ( mcode != CURLM_OK )
-               {
-                       throw gnash::GnashException(curl_multi_strerror(mcode));
-               }
-
-               // we already have that much data
-               fstat(_cachefd, &statbuf);
-               if ( statbuf.st_size >= size ) 
-               {
-                       return;
-               }
-
-
-       }
-#endif
-}
-
 NetConnection::NetConnection()
        :
        as_object(getNetConnectionInterface()),
-       _cache(NULL),
-       _cachefd(0),
        _url(),
-#ifdef USE_CURL
-       _handle(NULL),
-       _mhandle(NULL),
-#endif
-       _running(false),
-       localFile(true),
-       netStreamObj(NULL),
-       totalSize(0)
+       _owner(NULL),
+       _stream(NULL)
 {
 }
 
 NetConnection::~NetConnection() {
-#ifdef USE_CURL
-       curl_multi_remove_handle(_mhandle, _handle);
-       curl_easy_cleanup(_handle);
-       curl_multi_cleanup(_mhandle);
-#endif
-       fclose(_cache);
+
 }
 
 /// Open a connection to stream FLV files.
@@ -197,134 +73,31 @@
 /// RTMP. Newer Flash movies have a parameter to connect which is a
 /// URL string like rtmp://foobar.com/videos/bar.flv
 /*public*/
-bool NetConnection::openConnection(const char* char_url, as_object* ns)
+bool NetConnection::openConnection(const char* char_url, as_object* owner)
 {
 
        // if already running there is no need to setup things again
-       if (_running) return true;
+       if (_stream) return true;
 
-       netStreamObj = ns;
+       _owner = owner;
        if (_url.size() > 0) {
                _url += "/";
        }
        _url += char_url;
-       _running = true;
-       _cache = NULL;
-
-       localFile = false;
-
 
        URL uri(_url, get_base_url());
 
        _url = uri.str().c_str();
 
        // Check if we're allowed to open url
-       if (URLAccessManager::allow(uri)) {
-
-               if (uri.protocol() == "file")
-               {
-                       localFile = true;
-               }
-
-       } else {
+       if (!URLAccessManager::allow(uri)) {
                log_warning("Gnash is not allowed to open this url.");
                return false;
        }
 
-       if (localFile) {
-               _cache = fopen(uri.path().c_str(), "rb");
-               if (_cache) {
-                       _cachefd = fileno(_cache);
-                       return true;
-               } else {
-                       log_warning("Gnash failed to open local file.");
-                       _cachefd = -1;
-                       return false;
-               }
-       }
-
-#ifdef USE_CURL
-       ensure_libcurl_initialized();
-
-       _handle = curl_easy_init();
-       _mhandle = curl_multi_init();
-
-       /// later on we might want to accept a filename
-       /// in the constructor
-       _cache = tmpfile();
-       if ( ! _cache ) {
-               throw gnash::GnashException("Could not create temporary cache 
file");
-       }
-       _cachefd = fileno(_cache);
-
-       CURLcode ccode;
-       CURLMcode mcode;
-
-       ccode = curl_easy_setopt(_handle, CURLOPT_USERAGENT, "Gnash-" VERSION);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-
-/* from libcurl-tutorial(3)
-When using multiple threads you should set the CURLOPT_NOSIGNAL  option
-to TRUE for all handles. Everything will work fine except that timeouts
-are not honored during the DNS lookup - which you can  work  around  by
-*/
-
-       ccode = curl_easy_setopt(_handle, CURLOPT_NOSIGNAL, true);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       // set url
-       ccode = curl_easy_setopt(_handle, CURLOPT_URL, _url.c_str());
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       // set write data and function
-       ccode = curl_easy_setopt(_handle, CURLOPT_WRITEDATA, this);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       ccode = curl_easy_setopt(_handle, CURLOPT_WRITEFUNCTION,
-               NetConnection::recv);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       ccode = curl_easy_setopt(_handle, CURLOPT_FOLLOWLOCATION, 1);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       // set progress callback and function
-       ccode = curl_easy_setopt(_handle, CURLOPT_PROGRESSFUNCTION, 
-               NetConnection::progress_callback);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       ccode = curl_easy_setopt(_handle, CURLOPT_PROGRESSDATA, this);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       ccode = curl_easy_setopt(_handle, CURLOPT_NOPROGRESS, false);
-       if ( ccode != CURLE_OK ) {
-               throw gnash::GnashException(curl_easy_strerror(ccode));
-       }
-
-       // CURLMcode ret = 
-       mcode = curl_multi_add_handle(_mhandle, _handle);
-       if ( mcode != CURLM_OK ) {
-               throw gnash::GnashException(curl_multi_strerror(mcode));
-       }
-       fill_cache(50000); // pre-cache 50 Kbytes
+       _stream = StreamProvider::getDefaultInstance().getStream(uri);
 
-#endif // defined USE_CURL
+       if (!_stream) return false;
 
        return true;
 }
@@ -342,38 +115,61 @@
 bool
 NetConnection::eof()
 {
-       bool ret = ( ! _running && feof(_cache) );
        
-       return ret;
+       if (!_stream) return false;
 
+       return _stream->get_eof();
 }
+
 /*public*/
 size_t
 NetConnection::read(void *dst, size_t bytes)
 {
-       if ( eof() ) return 0;
-
-       if (!localFile) fill_cache(tell()+bytes);
-
-       return fread(dst, 1, bytes, _cache);
+       if (!_stream) return 0;
 
+       return _stream->read_bytes(dst, bytes);
 }
 
 /*public*/
 bool
 NetConnection::seek(size_t pos)
 {
-       if (!localFile) fill_cache(pos);
+       if (!_stream) return false;
 
-       if ( fseek(_cache, pos, SEEK_SET) == -1 ) {
-               return false;
-       } else {
-               return true;
-       }
+       _stream->set_position(pos);
+
+       if (_stream->get_position() == pos)     return true;
+       else return false;
+}
+
+/*public*/
+size_t
+NetConnection::tell()
+{
+       if (!_stream) return 0;
+
+       return _stream->get_position();
+
+}
 
+/*public*/
+long
+NetConnection::getBytesLoaded()
+{
+       if (!_stream) return -1;
+
+       return _stream->get_cur_size();
 }
 
 
+/*public*/
+long
+NetConnection::getBytesTotal()
+{
+       if (!_stream) return -1;
+
+       return _stream->get_size();
+}
 
 
 // Wrapper around dynamic_cast to implement user warning.

Index: server/asobj/NetConnection.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetConnection.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- server/asobj/NetConnection.h        25 Feb 2007 16:31:48 -0000      1.18
+++ server/asobj/NetConnection.h        4 Mar 2007 21:35:31 -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: NetConnection.h,v 1.18 2007/02/25 16:31:48 strk Exp $ */
+/* $Id: NetConnection.h,v 1.19 2007/03/04 21:35:31 tgc Exp $ */
 
 #ifndef __NETCONNECTION_H__
 #define __NETCONNECTION_H__
@@ -23,9 +23,7 @@
 #include "config.h"
 #endif
 
-#ifdef HAVE_CURL_CURL_H
-#include <curl/curl.h>
-#endif
+#include "tu_file.h"
 
 #include <stdexcept>
 #include <cstdio>
@@ -54,7 +52,7 @@
        ~NetConnection();
 
        /// Opens the connection to char_url
-       bool openConnection(const char* char_url, as_object* ns);
+       bool openConnection(const char* char_url, as_object* owner);
 
        /// Put read pointer at given position
        bool seek(size_t pos);
@@ -71,61 +69,26 @@
        /// Report global position within the file
        size_t tell();
 
-       // Extend the URL to be used for playing
+       /// Extend the URL to be used for playing
        void addToURL(const char* url);
        
-private:
-       // Use this file to cache data
-       FILE* _cache;
-
-       // _cache file descriptor
-       int _cachefd;
-
-       // we keep a copy here to be sure the char*
-       // is alive for the whole CurlStreamFile lifetime
-       // TODO: don't really do this :)
-       std::string _url;
-
-#ifdef USE_CURL
-       // the libcurl easy handle
-       CURL *_handle;
-
-       // the libcurl multi handle
-       CURLM *_mhandle;
-#endif
+       ///     Returns the number of bytes cached
+       long getBytesLoaded();
 
-       // transfer in progress
-       int _running;
+       ///     Returns the total size of the file
+       long getBytesTotal();
 
-       // Attempt at filling the cache up to the given size.
-       // Will call libcurl routines to fetch data.
-       void fill_cache(off_t size);
 
-       // Append sz bytes to the cache
-       size_t cache(void *from, size_t sz);
-
-       void printInfo();
-
-       // Callback for libcurl, will be called
-       // by fill_cache() and will call cache() 
-       static size_t recv(void *buf, size_t  size, 
-               size_t  nmemb, void *userp);
-
-       // If the file is local
-       bool localFile;
-
-       // The NetStream object which handles the video playback
-       // Watch out for circular dependencies, see NetStream.h
-       as_object* netStreamObj;
-
-       // Total filesize
-       double totalSize;
+private:
 
-       // Callback for libcurl, will be used to detect total filesize
-       static int progress_callback(void *clientp, double dltotal, 
-               double dlnow, double ultotal, double ulnow);
+       /// the url of the file
+       std::string _url;
 
+       /// the as_object which owns the connection
+       as_object* _owner;
 
+       /// The file connection
+       tu_file* _stream;
 };
 
 void netconnection_class_init(as_object& global);

Index: server/asobj/NetStream.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStream.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- server/asobj/NetStream.cpp  4 Mar 2007 01:39:01 -0000       1.27
+++ server/asobj/NetStream.cpp  4 Mar 2007 21:35:31 -0000       1.28
@@ -15,7 +15,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: NetStream.cpp,v 1.27 2007/03/04 01:39:01 strk Exp $ */
+/* $Id: NetStream.cpp,v 1.28 2007/03/04 21:35:31 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -49,7 +49,6 @@
 NetStream::NetStream()
        :
        as_object(getNetStreamInterface()),
-       _parent(NULL),
        _netCon(NULL)
 {
 }
@@ -177,6 +176,44 @@
        }
 }
 
+// Both a getter and a (do-nothing) setter for bytesLoaded
+static void
+netstream_bytesloaded(const fn_call& fn)
+{
+
+       NetStream* ns = ensure_netstream(fn.this_ptr);
+
+       if ( fn.nargs == 0 )
+       {
+               fn.result->set_double(ns->bytesLoaded());
+       }
+       else
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+                       log_aserror("Tried to set read-only property 
NetStream.bytesLoaded");
+               );
+       }
+}
+
+// Both a getter and a (do-nothing) setter for bytesTotal
+static void
+netstream_bytestotal(const fn_call& fn)
+{
+
+       NetStream* ns = ensure_netstream(fn.this_ptr);
+
+       if ( fn.nargs == 0 )
+       {
+               fn.result->set_double(ns->bytesTotal());
+       }
+       else
+       {
+               IF_VERBOSE_ASCODING_ERRORS(
+                       log_aserror("Tried to set read-only property 
NetStream.bytesTotal");
+               );
+       }
+}
+
 void
 attachNetStreamInterface(as_object& o)
 {
@@ -195,6 +232,12 @@
     gettersetter = new builtin_function(&netstream_time, NULL);
     o.init_property("time", *gettersetter, *gettersetter);
 
+    gettersetter = new builtin_function(&netstream_bytesloaded, NULL);
+    o.init_property("bytesLoaded", *gettersetter, *gettersetter);
+
+    gettersetter = new builtin_function(&netstream_bytestotal, NULL);
+    o.init_property("bytesTotal", *gettersetter, *gettersetter);
+
 }
 
 static as_object*

Index: server/asobj/NetStream.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStream.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- server/asobj/NetStream.h    30 Jan 2007 12:49:03 -0000      1.20
+++ server/asobj/NetStream.h    4 Mar 2007 21:35:31 -0000       1.21
@@ -18,7 +18,7 @@
 //
 //
 
-/*  $Id: NetStream.h,v 1.20 2007/01/30 12:49:03 strk Exp $ */
+/*  $Id: NetStream.h,v 1.21 2007/03/04 21:35:31 tgc Exp $ */
 
 #ifndef __NETSTREAM_H__
 #define __NETSTREAM_H__
@@ -44,9 +44,6 @@
 
 protected:
 
-       // Watch out for circular dependencies, see NetStream.h
-       NetStream* _parent;
-
        NetConnection* _netCon;
 
 public:
@@ -76,11 +73,9 @@
 
        virtual int64_t time() { return 0; }
 
-       /// What is supposed to happens if ns is NULL ?
-       void set_parent(NetStream* ns)
-       {
-               _parent = ns;
-       }
+       virtual long bytesLoaded() { return 0; }
+
+       virtual long bytesTotal() { return 0; }
 
        virtual bool playing()
        {

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- server/asobj/NetStreamFfmpeg.cpp    1 Mar 2007 10:05:51 -0000       1.19
+++ server/asobj/NetStreamFfmpeg.cpp    4 Mar 2007 21:35:31 -0000       1.20
@@ -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.19 2007/03/01 10:05:51 tgc Exp $ */
+/* $Id: NetStreamFfmpeg.cpp,v 1.20 2007/03/04 21:35:31 tgc Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -75,11 +75,8 @@
 // called from avstreamer thread
 void NetStreamFfmpeg::set_status(const char* /*code*/)
 {
-       if (_parent)
-       {
                //m_netstream_object->init_member("onStatus_Code", code);
-               //push_video_event(m_netstream_object);
-       }
+       //push_video_event(this);
 }
 
 void NetStreamFfmpeg::pause(int mode)
@@ -245,8 +242,8 @@
        assert(nc);
 
        // Pass stuff from/to the NetConnection object.
-       assert(ns); // ns->_parent is ok being NULL
-       if ( !nc->openConnection(ns->url.c_str(), ns->_parent) ) {
+       assert(ns);
+       if ( !nc->openConnection(ns->url.c_str(), ns) ) {
                log_warning("Gnash could not open movie url: %s", 
ns->url.c_str());
                return;
        }
@@ -461,7 +458,7 @@
                        }
                        else
                        {
-                               delay = int((video_clock - clock)*1000000);
+                               delay = int((video_clock - clock)*10000000); 
                        }
 
                        // Don't hog the CPU.
@@ -759,6 +756,17 @@
        }
 }
 
+long
+NetStreamFfmpeg::bytesLoaded()
+{
+       return _netCon->getBytesLoaded();
+}
+
+long
+NetStreamFfmpeg::bytesTotal()
+{
+       return _netCon->getBytesTotal();
+}
 } // gnash namespcae
 
 #endif // USE_FFMPEG

Index: server/asobj/NetStreamFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- server/asobj/NetStreamFfmpeg.h      14 Feb 2007 20:41:48 -0000      1.12
+++ server/asobj/NetStreamFfmpeg.h      4 Mar 2007 21:35:31 -0000       1.13
@@ -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.12 2007/02/14 20:41:48 tgc Exp $ */
+/* $Id: NetStreamFfmpeg.h,v 1.13 2007/03/04 21:35:31 tgc Exp $ */
 
 #ifndef __NETSTREAMFFMPEG_H__
 #define __NETSTREAMFFMPEG_H__
@@ -142,6 +142,8 @@
        void set_status(const char* code);
        void setNetCon(as_object* nc);
        int64_t time();
+       long bytesLoaded();
+       long bytesTotal();
 
        // Used for ffmpeg data read and seek callbacks
        static int readPacket(void* opaque, uint8_t* buf, int buf_size);

Index: server/asobj/NetStreamGst.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamGst.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- server/asobj/NetStreamGst.cpp       14 Feb 2007 20:41:48 -0000      1.12
+++ server/asobj/NetStreamGst.cpp       4 Mar 2007 21:35:31 -0000       1.13
@@ -89,11 +89,8 @@
 // called from avstreamer thread
 void NetStreamGst::set_status(const char* /*code*/)
 {
-       if (_parent)
-       {
                //m_netstream_object->init_member("onStatus_Code", code);
-               //push_video_event(m_netstream_object);
-       }
+       //push_video_event(this);
 }
 
 void NetStreamGst::pause(int mode)
@@ -271,8 +268,8 @@
        assert(nc);
 
        // Pass stuff from/to the NetConnection object.
-       assert(ns); // ns->_parent being null seems ok
-       if ( !nc->openConnection(ns->url.c_str(), ns->_parent) ) {
+       assert(ns);
+       if ( !nc->openConnection(ns->url.c_str(), ns) ) {
                log_warning("Gnash could not open movie url: %s", 
ns->url.c_str());
                return;
        }
@@ -408,6 +405,18 @@
        }
 }
 
+long
+NetStreamGst::bytesLoaded()
+{
+       return _netCon->getBytesLoaded();
+}
+
+long
+NetStreamGst::bytesTotal()
+{
+       return _netCon->getBytesTotal();
+}
+
 // Gstreamer callback function
 int 
 NetStreamGst::readPacket(void* opaque, char* buf, int buf_size){

Index: server/asobj/NetStreamGst.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamGst.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- server/asobj/NetStreamGst.h 5 Feb 2007 22:22:32 -0000       1.7
+++ server/asobj/NetStreamGst.h 4 Mar 2007 21:35:31 -0000       1.8
@@ -48,6 +48,8 @@
        void set_status(const char* code);
        void setNetCon(as_object* nc);
        int64_t time();
+       long bytesLoaded();
+       long bytesTotal();
 
        // Used for gstreamer data read and seek callbacks
        static int readPacket(void* opaque, char* buf, int buf_size);




reply via email to

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