[Swfdec-commits] 3 commits - swfdec/swfdec_as_object.c swfdec/swfdec_as_object.h swfdec/swfdec_as_strings.c swfdec/swfdec_net_stream.c test/trace
Pekka Lampila
medar at kemper.freedesktop.org
Wed Jul 16 06:11:06 PDT 2008
swfdec/swfdec_as_object.c | 20 ++++----
swfdec/swfdec_as_object.h | 2
swfdec/swfdec_as_strings.c | 1
swfdec/swfdec_net_stream.c | 16 ++++++
test/trace/Makefile.am | 4 +
test/trace/system-onstatus-netstream.c | 61 +++++++++++++++++++++++++
test/trace/system-onstatus-netstream.swf |binary
test/trace/system-onstatus-netstream.swf.trace | 9 +++
8 files changed, 103 insertions(+), 10 deletions(-)
New commits:
commit 1e604260dcc746c8f35839cc3b283524944c73c0
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Jul 16 16:03:46 2008 +0300
Add a test for calling System.onStatus for NetStream errors
diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index e64034c..3118d36 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -3726,6 +3726,10 @@ EXTRA_DIST = \
system-capabilities-query-7.swf.trace \
system-capabilities-query-8.swf \
system-capabilities-query-8.swf.trace \
+ system-capabilities-query.as \
+ system-onstatus-netstream.c \
+ system-onstatus-netstream.swf \
+ system-onstatus-netstream.swf.trace \
targetpath.as \
targetpath-5.swf \
targetpath-5.swf.trace \
diff --git a/test/trace/system-onstatus-netstream.c b/test/trace/system-onstatus-netstream.c
new file mode 100644
index 0000000..08fd579
--- /dev/null
+++ b/test/trace/system-onstatus-netstream.c
@@ -0,0 +1,61 @@
+/* gcc `pkg-config --libs --cflags libming` system-onstatus-netstream.c -o system-onstatus-netstream && ./system-onstatus-netstream
+ */
+
+#include <ming.h>
+
+int
+main (int argc, char **argv)
+{
+ SWFMovie movie;
+ SWFVideoStream video;
+ SWFDisplayItem item;
+ SWFAction action;
+
+ if (Ming_init ())
+ return 1;
+ Ming_useSWFVersion (7);
+
+ movie = newSWFMovie();
+ SWFMovie_setRate (movie, 1);
+ SWFMovie_setDimension (movie, 200, 150);
+ video = newSWFVideoStream ();
+ SWFVideoStream_setDimension (video, 200, 150);
+ item = SWFMovie_add (movie, (SWFBlock) video);
+ SWFDisplayItem_setName (item, "video");
+ action = compileSWFActionCode (""
+ "trace (\"Test System.onStatus\");"
+ ""
+ "System.onStatus = function (info)"
+ "{"
+ " trace ('System.onStatus ' + info.code);"
+ " trace (arguments);"
+ " trace (arguments.caller);"
+ " trace (arguments.callee);"
+ " delete (ns.onStatus);"
+ ""
+ " ns.onStatus = function () {"
+ " trace ('ns.onStatus ' + info.code);"
+ " getURL ('fscommand:quit', '');"
+ " };"
+ ""
+ " trace (\"Calling play\");"
+ " ns.play (\"404.flv\");"
+ "};"
+ ""
+ "var nc = new NetConnection ();"
+ "nc.connect (null);"
+ "var ns = new NetStream (nc);"
+ "video.attachVideo (ns);"
+ "ns.setBufferTime (5);"
+ ""
+ "function get () { trace ('get'); return null; };"
+ "function set () { trace ('set: ' + arguments); };"
+ "ns.addProperty ('onStatus', get, set);"
+ ""
+ "trace (\"Calling play\");"
+ "ns.play (\"404.flv\");"
+ "");
+ SWFMovie_add (movie, (SWFBlock) action);
+ SWFMovie_save (movie, "system-onstatus-netstream.swf");
+ return 0;
+}
diff --git a/test/trace/system-onstatus-netstream.swf b/test/trace/system-onstatus-netstream.swf
new file mode 100644
index 0000000..e275357
Binary files /dev/null and b/test/trace/system-onstatus-netstream.swf differ
diff --git a/test/trace/system-onstatus-netstream.swf.trace b/test/trace/system-onstatus-netstream.swf.trace
new file mode 100644
index 0000000..cb1cdb7
--- /dev/null
+++ b/test/trace/system-onstatus-netstream.swf.trace
@@ -0,0 +1,9 @@
+Test System.onStatus
+Calling play
+get
+System.onStatus NetStream.Play.StreamNotFound
+[object Object]
+null
+[type Function]
+Calling play
+ns.onStatus NetStream.Play.StreamNotFound
commit 2b1d838047483422a2f3834c098c1a7351adca33
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Jul 16 15:56:24 2008 +0300
Call System.onStatus for error messages from NetStream if necessary
System.onStatus is only called if there is no onStatus function for the
NetStream instance in question
diff --git a/swfdec/swfdec_as_strings.c b/swfdec/swfdec_as_strings.c
index a5a41b0..c05441b 100644
--- a/swfdec/swfdec_as_strings.c
+++ b/swfdec/swfdec_as_strings.c
@@ -522,5 +522,6 @@ const char swfdec_as_strings[] =
SWFDEC_AS_CONSTANT_STRING ("decodedFrames")
SWFDEC_AS_CONSTANT_STRING ("liveDelay")
SWFDEC_AS_CONSTANT_STRING ("videoCodec")
+ SWFDEC_AS_CONSTANT_STRING ("System")
/* add more here */
;
diff --git a/swfdec/swfdec_net_stream.c b/swfdec/swfdec_net_stream.c
index 3687436..2970e43 100644
--- a/swfdec/swfdec_net_stream.c
+++ b/swfdec/swfdec_net_stream.c
@@ -58,7 +58,21 @@ swfdec_net_stream_onstatus (SwfdecNetStream *stream, const char *code, const cha
swfdec_as_object_set_variable (object, SWFDEC_AS_STR_level, &val);
SWFDEC_AS_VALUE_SET_OBJECT (&val, object);
- swfdec_as_object_call (SWFDEC_AS_OBJECT (stream), SWFDEC_AS_STR_onStatus, 1, &val, NULL);
+ if (!swfdec_as_object_call (SWFDEC_AS_OBJECT (stream),
+ SWFDEC_AS_STR_onStatus, 1, &val, NULL)) {
+ // if it's an error message and the stream object didn't have onStatus
+ // handler, call System.onStatus
+ if (level == SWFDEC_AS_STR_error) {
+ SwfdecAsValue system;
+
+ swfdec_as_object_get_variable (SWFDEC_AS_OBJECT
+ (stream)->context->global, SWFDEC_AS_STR_System, &system);
+ if (SWFDEC_AS_VALUE_IS_OBJECT (&system)) {
+ swfdec_as_object_call (SWFDEC_AS_VALUE_GET_OBJECT (&system),
+ SWFDEC_AS_STR_onStatus, 1, &val, NULL);
+ }
+ }
+ }
swfdec_sandbox_unuse (stream->sandbox);
}
commit 2f6de889db97010f50b187bf53fd1037ccb66b21
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Jul 16 15:48:25 2008 +0300
Add return value for swfdec_as_object_call: FALSE if no function found
This can be used to easily try calling another function, if the first one
wasn't found
diff --git a/swfdec/swfdec_as_object.c b/swfdec/swfdec_as_object.c
index b2dbb96..a590d5e 100644
--- a/swfdec/swfdec_as_object.c
+++ b/swfdec/swfdec_as_object.c
@@ -1229,31 +1229,35 @@ swfdec_as_object_run (SwfdecAsObject *object, SwfdecScript *script)
* <informalexample><programlisting>
* @return_value = @object. at name (@argv[0], ..., @argv[argc-1]);
* </programlisting></informalexample>
+ *
+ * Returns: %TRUE if @object had a function with the given name, %FALSE otherwise
**/
-void
+gboolean
swfdec_as_object_call (SwfdecAsObject *object, const char *name, guint argc,
SwfdecAsValue *argv, SwfdecAsValue *return_value)
{
SwfdecAsValue tmp;
SwfdecAsFunction *fun;
- g_return_if_fail (SWFDEC_IS_AS_OBJECT (object));
- g_return_if_fail (name != NULL);
- g_return_if_fail (argc == 0 || argv != NULL);
- g_return_if_fail (object->context->global != NULL); /* for SwfdecPlayer */
+ g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), TRUE);
+ g_return_val_if_fail (name != NULL, TRUE);
+ g_return_val_if_fail (argc == 0 || argv != NULL, TRUE);
+ g_return_val_if_fail (object->context->global != NULL, TRUE); /* for SwfdecPlayer */
if (return_value)
SWFDEC_AS_VALUE_SET_UNDEFINED (return_value);
swfdec_as_object_get_variable (object, name, &tmp);
if (!SWFDEC_AS_VALUE_IS_OBJECT (&tmp))
- return;
+ return FALSE;
fun = (SwfdecAsFunction *) SWFDEC_AS_VALUE_GET_OBJECT (&tmp);
if (!SWFDEC_IS_AS_FUNCTION (fun))
- return;
+ return FALSE;
swfdec_as_function_call (fun, object, argc, argv, return_value ? return_value : &tmp);
if (swfdec_as_context_is_aborted (object->context))
- return;
+ return TRUE;
swfdec_as_context_run (object->context);
+
+ return TRUE;
}
/**
diff --git a/swfdec/swfdec_as_object.h b/swfdec/swfdec_as_object.h
index cd84e5d..6394270 100644
--- a/swfdec/swfdec_as_object.h
+++ b/swfdec/swfdec_as_object.h
@@ -177,7 +177,7 @@ SwfdecAsFunction *swfdec_as_object_add_constructor
guint min_args,
SwfdecAsObject * prototype);
-void swfdec_as_object_call (SwfdecAsObject * object,
+gboolean swfdec_as_object_call (SwfdecAsObject * object,
const char * name,
guint argc,
SwfdecAsValue * argv,
More information about the Swfdec-commits
mailing list