[Swfdec] Branch 'as' - 5 commits - libswfdec/Makefile.am libswfdec/swfdec_as_strings.c libswfdec/swfdec_js_net_stream.c libswfdec/swfdec_movie.c libswfdec/swfdec_net_connection.c libswfdec/swfdec_net_stream_as.c libswfdec/swfdec_net_stream.c libswfdec/swfdec_net_stream.h libswfdec/swfdec_player.c libswfdec/swfdec_player_internal.h test/trace

Benjamin Otte company at kemper.freedesktop.org
Thu Jun 21 13:50:23 PDT 2007


 libswfdec/Makefile.am              |    2 
 libswfdec/swfdec_as_strings.c      |    4 
 libswfdec/swfdec_js_net_stream.c   |  221 -------------------------------------
 libswfdec/swfdec_movie.c           |    2 
 libswfdec/swfdec_net_connection.c  |    2 
 libswfdec/swfdec_net_stream.c      |   25 ++--
 libswfdec/swfdec_net_stream.h      |    4 
 libswfdec/swfdec_net_stream_as.c   |  196 ++++++++++++++++++++++++++++++++
 libswfdec/swfdec_player.c          |   39 ++++--
 libswfdec/swfdec_player_internal.h |    2 
 test/trace/object-math-6.swf.trace |    2 
 11 files changed, 243 insertions(+), 256 deletions(-)

New commits:
diff-tree 0e96b023aba5b5548d22679a5fdffcc0ebce13e5 (from 64bfbc52868b3de1e7c3f655e1fc773d1feb36cb)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 21 22:49:59 2007 +0200

    fix trace output to be in line with Flash player 9
    
    something returns Infinity and not NaN in Flash player 7.
    You get it when running Number.valueOf(), but I'm not sure exactly who's at fault.

diff --git a/test/trace/object-math-6.swf.trace b/test/trace/object-math-6.swf.trace
index 87fc74d..c6fd440 100755
--- a/test/trace/object-math-6.swf.trace
+++ b/test/trace/object-math-6.swf.trace
@@ -11,7 +11,7 @@ NaN
 NaN
 0
 0
-Infinity
+NaN
 NaN
 0
 Infinity
diff-tree 64bfbc52868b3de1e7c3f655e1fc773d1feb36cb (from a12c0352c566f6fbef879e5a9f768c404a93d79f)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 21 22:48:09 2007 +0200

    don't set properties on values that can be NULL

diff --git a/libswfdec/swfdec_net_connection.c b/libswfdec/swfdec_net_connection.c
index 47c9d0d..d6df7d1 100644
--- a/libswfdec/swfdec_net_connection.c
+++ b/libswfdec/swfdec_net_connection.c
@@ -139,9 +139,9 @@ swfdec_net_connection_init_context (Swfd
   context = SWFDEC_AS_CONTEXT (player);
   conn = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
       SWFDEC_AS_STR_NetConnection, SWFDEC_TYPE_NET_CONNECTION, NULL, 0));
-  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (conn), SWFDEC_TYPE_NET_CONNECTION);
   if (!conn)
     return;
+  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (conn), SWFDEC_TYPE_NET_CONNECTION);
   proto = swfdec_as_object_new (context);
   /* set the right properties on the NetConnection object */
   SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
diff-tree a12c0352c566f6fbef879e5a9f768c404a93d79f (from 55515a23b84c9c71944c47d6e63b1b0066e53ead)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 21 22:47:51 2007 +0200

    port NetStream

diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am
index f1bb40c..a28e906 100644
--- a/libswfdec/Makefile.am
+++ b/libswfdec/Makefile.am
@@ -24,7 +24,6 @@ foofiles = \
 	swfdec_js_global.c \
 	swfdec_js_mouse.c \
 	swfdec_js_movie.c \
-	swfdec_js_net_stream.c \
 	swfdec_js_sound.c \
 	swfdec_js_video.c \
 	swfdec_js_xml.c
@@ -91,6 +90,7 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_movie_asprops.c \
 	swfdec_net_connection.c \
 	swfdec_net_stream.c \
+	swfdec_net_stream_as.c \
 	swfdec_pattern.c \
 	swfdec_player.c \
 	swfdec_player_as.c \
diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index c063aed..326b858 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -209,6 +209,10 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("connect")
   SWFDEC_AS_CONSTANT_STRING ("createEmptyMovieClip")
   SWFDEC_AS_CONSTANT_STRING ("split")
+  SWFDEC_AS_CONSTANT_STRING ("NetStream")
+  SWFDEC_AS_CONSTANT_STRING ("pause")
+  SWFDEC_AS_CONSTANT_STRING ("seek")
+  SWFDEC_AS_CONSTANT_STRING ("setBufferTime")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_js_net_stream.c b/libswfdec/swfdec_js_net_stream.c
deleted file mode 100644
index 873f673..0000000
--- a/libswfdec/swfdec_js_net_stream.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "swfdec_net_stream.h"
-#include "swfdec_debug.h"
-#include "swfdec_js.h"
-#include "swfdec_player_internal.h"
-
-static JSBool
-swfdec_js_net_stream_play (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecNetStream *stream;
-  const char *url;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-  url = swfdec_js_to_string (cx, argv[0]);
-  if (url == NULL)
-    return JS_FALSE;
-  swfdec_net_stream_set_url (stream, url);
-  swfdec_net_stream_set_playing (stream, TRUE);
-  return JS_TRUE;
-}
-
-static JSBool
-swfdec_js_net_stream_pause (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecNetStream *stream;
-  gboolean playing;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-  if (argc == 0) {
-    playing = !swfdec_net_stream_get_playing (stream);
-  } else {
-    JSBool b;
-    if (!JS_ValueToBoolean (cx, argv[0], &b))
-      return JS_FALSE;
-    playing = !b;
-  }
-  SWFDEC_LOG ("%s stream %p", playing ? "playing" : "pausing", stream);
-  swfdec_net_stream_set_playing (stream, playing);
-  return JS_TRUE;
-}
-
-static JSBool
-swfdec_js_net_stream_set_buffer_time (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecNetStream *stream;
-  double d;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-  if (!JS_ValueToNumber (cx, argv[0], &d))
-    return JS_FALSE;
-  swfdec_net_stream_set_buffer_time (stream, d);
-  return JS_TRUE;
-}
-
-static JSBool
-swfdec_js_net_stream_seek (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecNetStream *stream;
-  double d;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-  if (!JS_ValueToNumber (cx, argv[0], &d))
-    return JS_FALSE;
-  swfdec_net_stream_seek (stream, d);
-  return JS_TRUE;
-}
-
-static JSFunctionSpec net_stream_methods[] = {
-  { "pause",		swfdec_js_net_stream_pause,		0, 0, 0 },
-  { "play",		swfdec_js_net_stream_play,		1, 0, 0 },
-  { "seek",		swfdec_js_net_stream_seek,		1, 0, 0 },
-  { "setBufferTime",  	swfdec_js_net_stream_set_buffer_time,	1, 0, 0 },
-  { NULL }
-};
-
-static JSBool
-swfdec_js_net_stream_time (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
-{
-  SwfdecNetStream *stream;
-  guint msecs;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-
-  if (stream->flvdecoder == NULL ||
-      !swfdec_flv_decoder_get_video_info (stream->flvdecoder, &msecs, NULL)) {
-    *vp = INT_TO_JSVAL (0);
-    return JS_TRUE;
-  }
-  if (msecs >= stream->current_time)
-    msecs = 0;
-  else
-    msecs = stream->current_time - msecs;
-
-  return JS_NewNumberValue (cx, msecs / 1000., vp);
-}
-
-static JSBool
-swfdec_js_net_stream_bytes_loaded (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
-{
-  SwfdecNetStream *stream;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-
-  if (stream->loader == NULL) {
-    *vp = INT_TO_JSVAL (0);
-    return JS_TRUE;
-  }
-
-  return JS_NewNumberValue (cx, swfdec_loader_get_loaded (stream->loader), vp);
-}
-
-static JSBool
-swfdec_js_net_stream_bytes_total (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
-{
-  SwfdecNetStream *stream;
-  gulong bytes;
-
-  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
-  if (stream == NULL)
-    return JS_TRUE;
-
-  if (stream->loader == NULL) {
-    *vp = INT_TO_JSVAL (0);
-    return JS_TRUE;
-  }
-  bytes = swfdec_loader_get_size (stream->loader);
-  if (bytes == 0)
-    bytes = swfdec_loader_get_loaded (stream->loader);
-
-  return JS_NewNumberValue (cx, bytes, vp);
-}
-
-static JSPropertySpec net_stream_props[] = {
-  { "bytesLoaded",	-1,	JSPROP_PERMANENT|JSPROP_READONLY,	swfdec_js_net_stream_bytes_loaded,	NULL },
-  { "bytesTotal",	-1,	JSPROP_PERMANENT|JSPROP_READONLY,	swfdec_js_net_stream_bytes_total,	NULL },
-  { "time",		-1,	JSPROP_PERMANENT|JSPROP_READONLY,	swfdec_js_net_stream_time,		NULL },
-  { NULL }
-};
-
-static void
-swfdec_js_net_stream_finalize (JSContext *cx, JSObject *obj)
-{
-  SwfdecNetStream *stream;
-
-  stream = JS_GetPrivate (cx, obj);
-  if (stream) {
-    SWFDEC_SCRIPTABLE (stream)->jsobj = NULL;
-    g_object_unref (stream);
-  }
-}
-
-const JSClass net_stream_class = {
-    "NetStream", JSCLASS_HAS_PRIVATE,
-    JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
-    JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_net_stream_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-static JSBool
-swfdec_js_net_stream_new (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecNetStream *stream;
-  SwfdecConnection *conn;
-  
-  conn = swfdec_scriptable_from_jsval (cx, argv[0], SWFDEC_TYPE_CONNECTION);
-  if (conn == NULL) {
-    SWFDEC_WARNING ("no connection passed to NetStream ()");
-    *rval = JSVAL_VOID;
-    return JS_TRUE;
-  }
-  stream = swfdec_net_stream_new (JS_GetContextPrivate (cx), conn);
-
-  JS_SetPrivate (cx, obj, stream);
-  SWFDEC_SCRIPTABLE (stream)->jsobj = obj;
-
-  *rval = OBJECT_TO_JSVAL (obj);
-  return JS_TRUE;
-}
-
-void
-swfdec_js_add_net_stream (SwfdecPlayer *player)
-{
-  JS_InitClass (player->jscx, player->jsobj, NULL,
-      &net_stream_class, swfdec_js_net_stream_new, 0, net_stream_props, net_stream_methods,
-      NULL, NULL);
-}
-
diff --git a/libswfdec/swfdec_net_stream.c b/libswfdec/swfdec_net_stream.c
index 1a64f4c..0aeab9d 100644
--- a/libswfdec/swfdec_net_stream.c
+++ b/libswfdec/swfdec_net_stream.c
@@ -131,7 +131,7 @@ swfdec_net_stream_timeout (SwfdecTimeout
     SWFDEC_LOG ("readding timeout");
     stream->timeout.timestamp += SWFDEC_MSECS_TO_TICKS (stream->next_time - stream->current_time);
     stream->timeout.callback = swfdec_net_stream_timeout;
-    swfdec_player_add_timeout (stream->player, &stream->timeout);
+    swfdec_player_add_timeout (SWFDEC_PLAYER (SWFDEC_AS_OBJECT (stream)->context), &stream->timeout);
   } else {
     if (stream->audio) {
       /* FIXME: just unref and let it take care of removing itself? */
@@ -146,6 +146,7 @@ swfdec_net_stream_timeout (SwfdecTimeout
 static void
 swfdec_net_stream_update_playing (SwfdecNetStream *stream)
 {
+  SwfdecPlayer *player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (stream)->context);
   gboolean should_play;
     
   should_play = stream->playing; /* checks user-set play/pause */
@@ -155,12 +156,12 @@ swfdec_net_stream_update_playing (Swfdec
   if (should_play && stream->timeout.callback == NULL) {
     SWFDEC_DEBUG ("starting playback");
     stream->timeout.callback = swfdec_net_stream_timeout;
-    stream->timeout.timestamp = stream->player->time + SWFDEC_MSECS_TO_TICKS (stream->next_time - stream->current_time);
-    swfdec_player_add_timeout (stream->player, &stream->timeout);
+    stream->timeout.timestamp = player->time + SWFDEC_MSECS_TO_TICKS (stream->next_time - stream->current_time);
+    swfdec_player_add_timeout (player, &stream->timeout);
     if (stream->flvdecoder->audio) {
       g_assert (stream->audio == NULL);
       SWFDEC_LOG ("starting audio");
-      stream->audio = swfdec_audio_flv_new (stream->player, 
+      stream->audio = swfdec_audio_flv_new (player, 
 	  stream->flvdecoder, stream->current_time);
     } else {
       SWFDEC_LOG ("no audio");
@@ -172,7 +173,7 @@ swfdec_net_stream_update_playing (Swfdec
       g_object_unref (stream->audio);
       stream->audio = NULL;
     }
-    swfdec_player_remove_timeout (stream->player, &stream->timeout);
+    swfdec_player_remove_timeout (player, &stream->timeout);
     stream->timeout.callback = NULL;
     SWFDEC_DEBUG ("stopping playback");
   }
@@ -183,7 +184,7 @@ swfdec_net_stream_update_playing (Swfdec
 static SwfdecPlayer *
 swfdec_net_stream_loader_target_get_player (SwfdecLoaderTarget *target)
 {
-  return SWFDEC_NET_STREAM (target)->player;
+  return SWFDEC_PLAYER (SWFDEC_AS_OBJECT (target)->context);
 }
 
 static void
@@ -207,7 +208,7 @@ swfdec_net_stream_loader_target_parse (S
   if (stream->flvdecoder == NULL) {
     /* FIXME: add mp3 support */
     stream->flvdecoder = g_object_new (SWFDEC_TYPE_FLV_DECODER, NULL);
-    SWFDEC_DECODER (stream->flvdecoder)->player = stream->player;
+    SWFDEC_DECODER (stream->flvdecoder)->player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (stream)->context);
     SWFDEC_DECODER (stream->flvdecoder)->queue = loader->queue;
     swfdec_net_stream_onstatus (stream, SWFDEC_AS_STR_NetStream_Play_Start,
 	SWFDEC_AS_STR_status);
@@ -223,7 +224,7 @@ swfdec_net_stream_loader_target_parse (S
 	break;
       case SWFDEC_STATUS_INIT:
 	/* HACK for native flv playback */
-	swfdec_player_initialize (stream->player, 7,
+	swfdec_player_initialize (SWFDEC_PLAYER (SWFDEC_AS_OBJECT (stream)->context), 7,
 	    SWFDEC_DECODER (stream->flvdecoder)->rate, 
 	    SWFDEC_DECODER (stream->flvdecoder)->width, 
 	    SWFDEC_DECODER (stream->flvdecoder)->height);
@@ -321,8 +322,6 @@ swfdec_net_stream_dispose (GObject *obje
     stream->decoder = NULL;
   }
   swfdec_net_stream_set_loader (stream, NULL);
-  g_object_unref (stream->conn);
-  stream->conn = NULL;
   g_assert (stream->movies == NULL);
 
   G_OBJECT_CLASS (swfdec_net_stream_parent_class)->dispose (object);
@@ -359,7 +358,7 @@ swfdec_net_stream_init (SwfdecNetStream 
 }
 
 SwfdecNetStream *
-swfdec_net_stream_new (SwfdecPlayer *player, SwfdecNetConnection *conn)
+swfdec_net_stream_new (SwfdecNetConnection *conn)
 {
   SwfdecAsContext *context;
   SwfdecNetStream *stream;
@@ -385,7 +384,7 @@ swfdec_net_stream_set_url (SwfdecNetStre
   g_return_if_fail (url != NULL);
 
   /* FIXME: use the connection once connections are implemented */
-  loader = swfdec_player_load (stream->player, url);
+  loader = swfdec_player_load (SWFDEC_PLAYER (SWFDEC_AS_OBJECT (stream)->context), url);
   swfdec_net_stream_set_loader (stream, loader);
   g_object_unref (loader);
 }
@@ -482,7 +481,7 @@ swfdec_net_stream_seek (SwfdecNetStream 
     SWFDEC_WARNING ("FIXME: restarting audio after seek");
     swfdec_audio_remove (stream->audio);
     g_object_unref (stream->audio);
-    stream->audio = swfdec_audio_flv_new (stream->player, 
+    stream->audio = swfdec_audio_flv_new (SWFDEC_PLAYER (SWFDEC_AS_OBJECT (stream)->context), 
 	stream->flvdecoder, stream->current_time);
   }
 }
diff --git a/libswfdec/swfdec_net_stream.h b/libswfdec/swfdec_net_stream.h
index 984d897..5f805ad 100644
--- a/libswfdec/swfdec_net_stream.h
+++ b/libswfdec/swfdec_net_stream.h
@@ -44,7 +44,6 @@ struct _SwfdecNetStream
 {
   SwfdecAsObject	object;
 
-  SwfdecPlayer *	player;		/* the player we play in */
   SwfdecNetConnection *	conn;		/* connection used for opening streams */
   SwfdecLoader *	loader;		/* input stream */
   SwfdecFlvDecoder *	flvdecoder;	/* flv decoder */
@@ -76,8 +75,7 @@ struct _SwfdecNetStreamClass
 
 GType			swfdec_net_stream_get_type	(void);
 
-SwfdecNetStream *	swfdec_net_stream_new		(SwfdecPlayer *		player,
-							 SwfdecNetConnection *	conn);
+SwfdecNetStream *	swfdec_net_stream_new		(SwfdecNetConnection *	conn);
 
 void			swfdec_net_stream_set_url	(SwfdecNetStream *	stream,
 							 const char *		url);
diff --git a/libswfdec/swfdec_net_stream_as.c b/libswfdec/swfdec_net_stream_as.c
new file mode 100644
index 0000000..6496c68
--- /dev/null
+++ b/libswfdec/swfdec_net_stream_as.c
@@ -0,0 +1,196 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "swfdec_net_stream.h"
+#include "swfdec_as_context.h"
+#include "swfdec_as_frame.h"
+#include "swfdec_as_native_function.h"
+#include "swfdec_debug.h"
+#include "swfdec_player_internal.h"
+
+static void
+swfdec_net_stream_play (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecNetStream *stream = SWFDEC_NET_STREAM (obj);
+  const char *url;
+
+  url = swfdec_as_value_to_string (cx, &argv[0]);
+  swfdec_net_stream_set_url (stream, url);
+  swfdec_net_stream_set_playing (stream, TRUE);
+}
+
+static void
+swfdec_net_stream_pause (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecNetStream *stream = SWFDEC_NET_STREAM (obj);
+  gboolean playing;
+
+  if (argc == 0) {
+    playing = !swfdec_net_stream_get_playing (stream);
+  } else {
+    playing = !swfdec_as_value_to_boolean (cx, &argv[0]);
+  }
+  SWFDEC_LOG ("%s stream %p", playing ? "playing" : "pausing", stream);
+  swfdec_net_stream_set_playing (stream, playing);
+}
+
+static void
+swfdec_net_stream_setBufferTime (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecNetStream *stream = SWFDEC_NET_STREAM (obj);
+  double d;
+
+  d = swfdec_as_value_to_number (cx, &argv[0]);
+  swfdec_net_stream_set_buffer_time (stream, d);
+}
+
+static void
+swfdec_net_stream_do_seek (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecNetStream *stream = SWFDEC_NET_STREAM (obj);
+  double d;
+
+  d = swfdec_as_value_to_number (cx, &argv[0]);
+  swfdec_net_stream_seek (stream, d);
+}
+
+#if 0
+static void
+swfdec_net_stream_time (SwfdecAsContext *cx, SwfdecAsObject *obj, SwfdecAsValue id, SwfdecAsValue *vp)
+{
+  SwfdecNetStream *stream;
+  guint msecs;
+
+  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
+  if (stream == NULL)
+    return JS_TRUE;
+
+  if (stream->flvdecoder == NULL ||
+      !swfdec_flv_decoder_get_video_info (stream->flvdecoder, &msecs, NULL)) {
+    *vp = INT_TO_JSVAL (0);
+    return JS_TRUE;
+  }
+  if (msecs >= stream->current_time)
+    msecs = 0;
+  else
+    msecs = stream->current_time - msecs;
+
+  return JS_NewNumberValue (cx, msecs / 1000., vp);
+}
+
+static void
+swfdec_net_stream_bytes_loaded (SwfdecAsContext *cx, SwfdecAsObject *obj, SwfdecAsValue id, SwfdecAsValue *vp)
+{
+  SwfdecNetStream *stream;
+
+  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
+  if (stream == NULL)
+    return JS_TRUE;
+
+  if (stream->loader == NULL) {
+    *vp = INT_TO_JSVAL (0);
+    return JS_TRUE;
+  }
+
+  return JS_NewNumberValue (cx, swfdec_loader_get_loaded (stream->loader), vp);
+}
+
+static void
+swfdec_net_stream_bytes_total (SwfdecAsContext *cx, SwfdecAsObject *obj, SwfdecAsValue id, SwfdecAsValue *vp)
+{
+  SwfdecNetStream *stream;
+  gulong bytes;
+
+  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
+  if (stream == NULL)
+    return JS_TRUE;
+
+  if (stream->loader == NULL) {
+    *vp = INT_TO_JSVAL (0);
+    return JS_TRUE;
+  }
+  bytes = swfdec_loader_get_size (stream->loader);
+  if (bytes == 0)
+    bytes = swfdec_loader_get_loaded (stream->loader);
+
+  return JS_NewNumberValue (cx, bytes, vp);
+}
+
+static JSPropertySpec net_stream_props[] = {
+  { "bytesLoaded",	-1,	JSPROP_PERMANENT|JSPROP_READONLY,	swfdec_net_stream_bytes_loaded,	NULL },
+  { "bytesTotal",	-1,	JSPROP_PERMANENT|JSPROP_READONLY,	swfdec_net_stream_bytes_total,	NULL },
+  { "time",		-1,	JSPROP_PERMANENT|JSPROP_READONLY,	swfdec_net_stream_time,		NULL },
+  { NULL }
+};
+#endif
+
+static void
+swfdec_net_stream_construct (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecNetStream *stream = SWFDEC_NET_STREAM (obj);
+  SwfdecNetConnection *conn;
+  
+  if (!cx->frame->construct) {
+    SWFDEC_FIXME ("What do we do if not constructing?");
+    return;
+  }
+  if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv[0]) || 
+      !SWFDEC_IS_NET_CONNECTION ((conn = (SwfdecNetConnection *) SWFDEC_AS_VALUE_GET_OBJECT (&argv[0])))) {
+    SWFDEC_WARNING ("no connection passed to NetStream ()");
+    return;
+  }
+  stream->conn = conn;
+}
+
+void
+swfdec_net_stream_init_context (SwfdecPlayer *player, guint version)
+{
+  SwfdecAsContext *context;
+  SwfdecAsObject *stream, *proto;
+  SwfdecAsValue val;
+
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
+  context = SWFDEC_AS_CONTEXT (player);
+  stream = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
+      SWFDEC_AS_STR_NetStream, SWFDEC_TYPE_NET_STREAM, swfdec_net_stream_construct, 1));
+  if (stream == NULL)
+    return;
+  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (stream), SWFDEC_TYPE_NET_STREAM);
+  proto = swfdec_as_object_new (context);
+  /* set the right properties on the NetStream object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
+  swfdec_as_object_set_variable (stream, SWFDEC_AS_STR_prototype, &val);
+  /* set the right properties on the NetStream.prototype object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, stream);
+  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_pause, SWFDEC_TYPE_NET_STREAM,
+      swfdec_net_stream_pause, 0);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_play, SWFDEC_TYPE_NET_STREAM,
+      swfdec_net_stream_play, 1);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_seek, SWFDEC_TYPE_NET_STREAM,
+      swfdec_net_stream_do_seek, 1);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_setBufferTime, SWFDEC_TYPE_NET_STREAM,
+      swfdec_net_stream_setBufferTime, 1);
+}
+
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index fe4f415..a83a5e1 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1068,6 +1068,7 @@ extern void swfdec_player_init_global (S
 extern void swfdec_mouse_init_context (SwfdecPlayer *player, guint version);
 extern void swfdec_movie_color_init_context (SwfdecPlayer *player, guint version);
 extern void swfdec_net_connection_init_context (SwfdecPlayer *player, guint version);
+extern void swfdec_net_stream_init_context (SwfdecPlayer *player, guint version);
 extern void swfdec_sprite_movie_init_context (SwfdecPlayer *player, guint version);
 /**
  * swfdec_player_initialize:
@@ -1102,6 +1103,7 @@ swfdec_player_initialize (SwfdecPlayer *
     swfdec_sprite_movie_init_context (player, version);
     swfdec_movie_color_init_context (player, version);
     swfdec_net_connection_init_context (player, version);
+    swfdec_net_stream_init_context (player, version);
     if (context->state == SWFDEC_AS_CONTEXT_NEW) {
       context->state = SWFDEC_AS_CONTEXT_RUNNING;
       swfdec_as_object_set_constructor (player->roots->data, player->MovieClip, FALSE);
diff-tree 55515a23b84c9c71944c47d6e63b1b0066e53ead (from fa2a28a1388c0f22d19d59db99d292a4e911cae5)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 21 18:44:58 2007 +0200

    run __constructor__, not constructor
    
    I bet this is not the correct fix either, someone should write a test that
    resets the constructor on init.

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 1b09906..51d0bbd 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -370,7 +370,7 @@ swfdec_movie_run_construct (SwfdecMovie 
   player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context);
   g_queue_remove (player->construct_queue, movie);
   swfdec_movie_execute_script (movie, SWFDEC_EVENT_CONSTRUCT);
-  swfdec_as_object_call (SWFDEC_AS_OBJECT (movie), SWFDEC_AS_STR_constructor, 0, NULL, NULL);
+  swfdec_as_object_call (SWFDEC_AS_OBJECT (movie), SWFDEC_AS_STR___constructor__, 0, NULL, NULL);
 }
 
 void
diff-tree fa2a28a1388c0f22d19d59db99d292a4e911cae5 (from 6004dbe9fe5d1b4cc6859c704bec72900d43c300)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 21 17:27:48 2007 +0200

    fix mouse drag coordinate computation

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 8aaebbc..fe4f415 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -437,7 +437,6 @@ swfdec_player_update_mouse_cursor (Swfde
 static void
 swfdec_player_update_drag_movie (SwfdecPlayer *player)
 {
-  double mouse_x, mouse_y;
   double x, y;
   SwfdecMovie *movie;
 
@@ -446,23 +445,23 @@ swfdec_player_update_drag_movie (SwfdecP
 
   movie = player->mouse_drag;
   g_assert (movie->cache_state == SWFDEC_MOVIE_UP_TO_DATE);
-  mouse_x = player->mouse_x;
-  mouse_y = player->mouse_y;
-  swfdec_movie_global_to_local (movie->parent, &mouse_x, &mouse_y);
-  mouse_x = CLAMP (mouse_x, player->mouse_drag_rect.x0, player->mouse_drag_rect.x1);
-  mouse_y = CLAMP (mouse_y, player->mouse_drag_rect.y0, player->mouse_drag_rect.y1);
-  SWFDEC_LOG ("mouse is at %g %g, orighinally (%g %g)", mouse_x, mouse_y, player->mouse_x, player->mouse_y);
+  x = player->mouse_x;
+  y = player->mouse_y;
+  if (movie->parent)
+    swfdec_movie_global_to_local (movie->parent, &x, &y);
   if (player->mouse_drag_center) {
-    x = (movie->extents.x1 + movie->extents.x0) / 2;
-    y = (movie->extents.y1 + movie->extents.y0) / 2;
+    x -= (movie->extents.x1 - movie->extents.x0) / 2;
+    y -= (movie->extents.y1 - movie->extents.y0) / 2;
   } else {
-    x = 0;
-    y = 0;
+    x -= player->mouse_drag_x;
+    y -= player->mouse_drag_y;
   }
-  SWFDEC_LOG ("center is at %g %g, mouse is at %g %g", x, y, mouse_x, mouse_y);
-  if (mouse_x - x != movie->matrix.x0 || mouse_y -y != movie->matrix.y0) {
-    movie->matrix.x0 += mouse_x - x;
-    movie->matrix.y0 += mouse_y - y;
+  x = CLAMP (x, player->mouse_drag_rect.x0, player->mouse_drag_rect.x1);
+  y = CLAMP (y, player->mouse_drag_rect.y0, player->mouse_drag_rect.y1);
+  SWFDEC_LOG ("mouse is at %g %g, orighinally (%g %g)", x, y, player->mouse_x, player->mouse_y);
+  if (x != movie->matrix.x0 || y != movie->matrix.y0) {
+    movie->matrix.x0 = x;
+    movie->matrix.y0 = y;
     swfdec_movie_queue_update (movie, SWFDEC_MOVIE_INVALID_MATRIX);
   }
 }
@@ -488,6 +487,14 @@ swfdec_player_set_drag_movie (SwfdecPlay
   /* FIXME: need to do anything with old drag? */
   player->mouse_drag = drag;
   player->mouse_drag_center = center;
+  if (drag && !center) {
+    player->mouse_drag_x = player->mouse_x;
+    player->mouse_drag_y = player->mouse_y;
+    if (drag->parent)
+      swfdec_movie_global_to_local (drag->parent, &player->mouse_drag_x, &player->mouse_drag_y);
+    player->mouse_drag_x -= drag->matrix.x0;
+    player->mouse_drag_y -= drag->matrix.y0;
+  }
   if (rect) {
     player->mouse_drag_rect = *rect;
   } else {
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index a9cb62a..6ef00b3 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -73,6 +73,8 @@ struct _SwfdecPlayer
   SwfdecMovie *		mouse_drag;		/* current movie activated by startDrag */
   gboolean		mouse_drag_center;	/* TRUE to use center of movie at mouse, FALSE for movie's (0,0) */
   SwfdecRect		mouse_drag_rect;	/* clipping rectangle for movements */
+  double		mouse_drag_x;		/* offset of mouse in x direction */
+  double		mouse_drag_y;		/* offset of mouse in y direction */
 
   /* audio */
   GList *		audio;		 	/* list of playing SwfdecAudio */


More information about the Swfdec mailing list