[Swfdec] Branch 'as' - libswfdec/swfdec_as_strings.c libswfdec/swfdec_net_stream_as.c libswfdec/swfdec_net_stream.c

Benjamin Otte company at kemper.freedesktop.org
Wed Jun 27 06:44:27 PDT 2007


 libswfdec/swfdec_as_strings.c    |    3 +
 libswfdec/swfdec_net_stream.c    |   44 ++++++++++++++++++++++++
 libswfdec/swfdec_net_stream_as.c |   70 ---------------------------------------
 3 files changed, 47 insertions(+), 70 deletions(-)

New commits:
diff-tree 281da9b83e68a6d82c61d603b7cc3c735d3e66e9 (from ffe888d4c04af436959d7279bc4e5a8fae6d0acf)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 27 15:40:20 2007 +0200

    reimplement the NetStream properties
    
    Youtube now works again

diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 8fe5c1b..7a846f5 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -218,6 +218,9 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("Video")
   SWFDEC_AS_CONSTANT_STRING ("attachVideo")
   SWFDEC_AS_CONSTANT_STRING ("clear")
+  SWFDEC_AS_CONSTANT_STRING ("time")
+  SWFDEC_AS_CONSTANT_STRING ("bytesLoaded")
+  SWFDEC_AS_CONSTANT_STRING ("bytesTotal")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_net_stream.c b/libswfdec/swfdec_net_stream.c
index 0aeab9d..0635921 100644
--- a/libswfdec/swfdec_net_stream.c
+++ b/libswfdec/swfdec_net_stream.c
@@ -327,6 +327,49 @@ swfdec_net_stream_dispose (GObject *obje
   G_OBJECT_CLASS (swfdec_net_stream_parent_class)->dispose (object);
 }
 
+static gboolean
+swfdec_net_stream_get_variable (SwfdecAsObject *object, const char *variable,
+    SwfdecAsValue *val, guint *flags)
+{
+  SwfdecNetStream *stream;
+
+  if (SWFDEC_AS_OBJECT_CLASS (swfdec_net_stream_parent_class)->get (object, variable, val, flags))
+    return TRUE;
+
+  stream = SWFDEC_NET_STREAM (object);
+  /* FIXME: need case insensitive comparisons? */
+  if (variable == SWFDEC_AS_STR_time) {
+    guint msecs;
+    if (stream->flvdecoder == NULL ||
+	!swfdec_flv_decoder_get_video_info (stream->flvdecoder, &msecs, NULL)) {
+      SWFDEC_AS_VALUE_SET_INT (val, 0);
+    } else {
+      if (msecs >= stream->current_time)
+	msecs = 0;
+      else 
+	msecs = stream->current_time - msecs;
+    }
+    SWFDEC_AS_VALUE_SET_NUMBER (val, msecs / 1000.);
+    *flags = 0;
+    return TRUE;
+  } else if (variable == SWFDEC_AS_STR_bytesLoaded) {
+    if (stream->loader == NULL)
+      SWFDEC_AS_VALUE_SET_INT (val, 0);
+    else
+      SWFDEC_AS_VALUE_SET_INT (val, swfdec_loader_get_loaded (stream->loader));
+    *flags = 0;
+    return TRUE;
+  } else if (variable == SWFDEC_AS_STR_bytesTotal) {
+    guint bytes = swfdec_loader_get_size (stream->loader);
+    if (bytes == 0)
+      bytes = swfdec_loader_get_loaded (stream->loader);
+    SWFDEC_AS_VALUE_SET_INT (val, bytes);
+    *flags = 0;
+    return TRUE;
+  }
+  return FALSE;
+}
+
 static void
 swfdec_net_stream_mark (SwfdecAsObject *object)
 {
@@ -345,6 +388,7 @@ swfdec_net_stream_class_init (SwfdecNetS
 
   object_class->dispose = swfdec_net_stream_dispose;
 
+  asobject_class->get = swfdec_net_stream_get_variable;
   asobject_class->mark = swfdec_net_stream_mark;
 }
 
diff --git a/libswfdec/swfdec_net_stream_as.c b/libswfdec/swfdec_net_stream_as.c
index 6496c68..69dd38c 100644
--- a/libswfdec/swfdec_net_stream_as.c
+++ b/libswfdec/swfdec_net_stream_as.c
@@ -74,76 +74,6 @@ swfdec_net_stream_do_seek (SwfdecAsConte
   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)
 {


More information about the Swfdec mailing list