[Swfdec-commits] 14 commits - configure.ac swfdec/.gitignore swfdec-gtk/swfdec_gtk_loader.c swfdec-gtk/swfdec_playback_alsa.c swfdec/Makefile.am swfdec/swfdec_asnative.h swfdec/swfdec_as_string.c swfdec/swfdec_audio.c swfdec/swfdec_audio_load.c swfdec/swfdec_audio_load.h swfdec/swfdec_audio_stream.c swfdec/swfdec_audio_stream.h swfdec/swfdec_audio_swf_stream.c swfdec/swfdec.h swfdec/swfdec_loader.h swfdec/swfdec_load_sound.c swfdec/swfdec_load_sound.h swfdec/swfdec_net_stream_as.c swfdec/swfdec_net_stream.c swfdec/swfdec_net_stream.h swfdec/swfdec_player_as.c swfdec/swfdec_player_internal.h swfdec/swfdec_policy_file.c swfdec/swfdec_policy_file.h swfdec/swfdec_sandbox.h swfdec/swfdec_sound_object.c swfdec/swfdec_sound_object.h swfdec/swfdec_types.h test/trace vivified/code

Benjamin Otte company at kemper.freedesktop.org
Sun Jun 15 05:28:58 PDT 2008


 configure.ac                                     |    3 
 swfdec-gtk/swfdec_gtk_loader.c                   |    6 
 swfdec-gtk/swfdec_playback_alsa.c                |   10 
 swfdec/.gitignore                                |    2 
 swfdec/Makefile.am                               |   13 
 swfdec/swfdec.h                                  |    1 
 swfdec/swfdec_as_string.c                        |   10 
 swfdec/swfdec_asnative.h                         |   32 ++
 swfdec/swfdec_audio.c                            |   12 
 swfdec/swfdec_audio_load.c                       |   93 ++++++
 swfdec/swfdec_audio_load.h                       |   58 +++
 swfdec/swfdec_audio_stream.c                     |   27 +
 swfdec/swfdec_audio_stream.h                     |    1 
 swfdec/swfdec_audio_swf_stream.c                 |   19 -
 swfdec/swfdec_load_sound.c                       |  356 +++++++++++++++++++++++
 swfdec/swfdec_load_sound.h                       |   63 ++++
 swfdec/swfdec_loader.h                           |    2 
 swfdec/swfdec_net_stream.c                       |   52 ---
 swfdec/swfdec_net_stream.h                       |    1 
 swfdec/swfdec_net_stream_as.c                    |    2 
 swfdec/swfdec_player_as.c                        |    4 
 swfdec/swfdec_player_internal.h                  |    5 
 swfdec/swfdec_policy_file.c                      |   57 +++
 swfdec/swfdec_policy_file.h                      |    2 
 swfdec/swfdec_sandbox.h                          |    3 
 swfdec/swfdec_sound_object.c                     |   17 +
 swfdec/swfdec_sound_object.h                     |    4 
 swfdec/swfdec_types.h                            |    1 
 test/trace/Makefile.am                           |    9 
 test/trace/String-split-count-values-5.swf       |binary
 test/trace/String-split-count-values-5.swf.trace |  133 ++++++++
 test/trace/String-split-count-values-6.swf       |binary
 test/trace/String-split-count-values-6.swf.trace |  134 ++++++++
 test/trace/String-split-count-values-7.swf       |binary
 test/trace/String-split-count-values-7.swf.trace |  134 ++++++++
 test/trace/String-split-count-values-8.swf       |binary
 test/trace/String-split-count-values-8.swf.trace |  134 ++++++++
 test/trace/String-split-count-values.as          |   11 
 vivified/code/vivi_code_function_call.c          |    4 
 39 files changed, 1319 insertions(+), 96 deletions(-)

New commits:
commit 260038b28e98aa5bf9a29335a57e8218f92a2406
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 21:46:04 2008 +0200

    add test for recent fix

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 00226b2..587e6f0 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -3305,6 +3305,15 @@ EXTRA_DIST = \
 	string-split-6.swf.trace \
 	string-split-7.swf \
 	string-split-7.swf.trace \
+	String-split-count-values-5.swf \
+	String-split-count-values-5.swf.trace \
+	String-split-count-values-6.swf \
+	String-split-count-values-6.swf.trace \
+	String-split-count-values-7.swf \
+	String-split-count-values-7.swf.trace \
+	String-split-count-values-8.swf \
+	String-split-count-values-8.swf.trace \
+	String-split-count-values.as \
 	string-split-empty.as \
 	string-split-empty-5.swf \
 	string-split-empty-5.swf.trace \
diff --git a/test/trace/String-split-count-values-5.swf b/test/trace/String-split-count-values-5.swf
new file mode 100644
index 0000000..6375c6d
Binary files /dev/null and b/test/trace/String-split-count-values-5.swf differ
diff --git a/test/trace/String-split-count-values-5.swf.trace b/test/trace/String-split-count-values-5.swf.trace
new file mode 100644
index 0000000..214a170
--- /dev/null
+++ b/test/trace/String-split-count-values-5.swf.trace
@@ -0,0 +1,133 @@
+valueOf called
+toString called
+toString called with 
+valueOf called with 
+0: valueOf!
+1: valueOf!
+2: valueOf!
+3: valueOf!
+4: valueOf!
+5: valueOf!
+6: valueOf!
+7: valueOf!
+8: valueOf!
+9: valueOf!
+10: valueOf!
+11: valueOf!
+12: valueOf!
+13: valueOf!
+14: valueOf!
+15: valueOf!
+16: valueOf!
+17: valueOf!
+18: valueOf!
+19: valueOf!
+20: valueOf!
+21: valueOf!
+22: valueOf!
+22: toString!
+23: valueOf!
+23: toString!
+24: valueOf!
+24: toString!
+25: valueOf!
+26: valueOf!
+26: toString!
+27: valueOf!
+27: toString!
+28: valueOf!
+28: toString!
+29: valueOf!
+29: toString!
+(0)  (undefined) - 12345
+(1) null (null) - 
+(2) true (boolean) - 12345
+(3) false (boolean) - 
+(4) 0 (number) - 
+(5) 1 (number) - 12345
+(6) 0.5 (number) - 
+(7) -1 (number) - 
+(8) -0.5 (number) - 
+(9) Infinity (number) - 
+(10) -Infinity (number) - 
+(11) NaN (number) - 
+(12)  (string) - 
+(13) 0 (string) - 
+(14) -0 (string) - 
+(15) 0.0 (string) - 
+(16) 1 (string) - 12345
+(17) Hello World! (string) - 
+(18) true (string) - 
+(19) _level0 (string) - 
+(20) äöü (string) - 
+(21) _level0 (movieclip) - 
+(22) [object Object] (object) - 
+(23) 1035840244000 (object) - 12345
+(24)  (object) - 
+(25)  (undefined) - 12345
+valueOf called
+(26) [type Object] (object) - 
+(27) [type Object] (object) - 
+valueOf called with 
+(28) [object Object] (object) - 
+(29)  (object) - 
+0: valueOf!
+(30)  (object) - 
+1: valueOf!
+(31) null (object) - 
+2: valueOf!
+(32) true (object) - 12345
+3: valueOf!
+(33) false (object) - 
+4: valueOf!
+(34) 0 (object) - 
+5: valueOf!
+(35) 1 (object) - 12345
+6: valueOf!
+(36) 0.5 (object) - 
+7: valueOf!
+(37) -1 (object) - 
+8: valueOf!
+(38) -0.5 (object) - 
+9: valueOf!
+(39) Infinity (object) - 
+10: valueOf!
+(40) -Infinity (object) - 
+11: valueOf!
+(41) NaN (object) - 
+12: valueOf!
+(42)  (object) - 
+13: valueOf!
+(43) 0 (object) - 
+14: valueOf!
+(44) -0 (object) - 
+15: valueOf!
+(45) 0.0 (object) - 
+16: valueOf!
+(46) 1 (object) - 12345
+17: valueOf!
+(47) Hello World! (object) - 
+18: valueOf!
+(48) true (object) - 
+19: valueOf!
+(49) _level0 (object) - 
+20: valueOf!
+(50) äöü (object) - 
+21: valueOf!
+(51) _level0 (object) - 
+22: valueOf!
+(52) [type Object] (object) - 
+23: valueOf!
+(53) [type Object] (object) - 
+24: valueOf!
+(54) [type Object] (object) - 
+25: valueOf!
+(55)  (object) - 
+26: valueOf!
+(56) [type Object] (object) - 
+27: valueOf!
+(57) [type Object] (object) - 
+28: valueOf!
+(58) [type Object] (object) - 
+29: valueOf!
+(59) [type Object] (object) - 
diff --git a/test/trace/String-split-count-values-6.swf b/test/trace/String-split-count-values-6.swf
new file mode 100644
index 0000000..cac9d41
Binary files /dev/null and b/test/trace/String-split-count-values-6.swf differ
diff --git a/test/trace/String-split-count-values-6.swf.trace b/test/trace/String-split-count-values-6.swf.trace
new file mode 100644
index 0000000..57ca73f
--- /dev/null
+++ b/test/trace/String-split-count-values-6.swf.trace
@@ -0,0 +1,134 @@
+valueOf called
+toString called
+toString called with 
+valueOf called with 
+0: valueOf!
+1: valueOf!
+2: valueOf!
+3: valueOf!
+4: valueOf!
+5: valueOf!
+6: valueOf!
+7: valueOf!
+8: valueOf!
+9: valueOf!
+10: valueOf!
+11: valueOf!
+12: valueOf!
+13: valueOf!
+14: valueOf!
+15: valueOf!
+16: valueOf!
+17: valueOf!
+18: valueOf!
+19: valueOf!
+20: valueOf!
+21: valueOf!
+22: valueOf!
+22: toString!
+23: valueOf!
+23: toString!
+24: valueOf!
+24: toString!
+25: valueOf!
+25: toString!
+26: valueOf!
+26: toString!
+27: valueOf!
+27: toString!
+28: valueOf!
+28: toString!
+29: valueOf!
+29: toString!
+(0)  (undefined) - 1,45
+(1) null (null) - 
+(2) true (boolean) - 1
+(3) false (boolean) - 
+(4) 0 (number) - 
+(5) 1 (number) - 1
+(6) 0.5 (number) - 
+(7) -1 (number) - 
+(8) -0.5 (number) - 
+(9) Infinity (number) - 
+(10) -Infinity (number) - 
+(11) NaN (number) - 
+(12)  (string) - 
+(13) 0 (string) - 
+(14) -0 (string) - 
+(15) 0.0 (string) - 
+(16) 1 (string) - 1
+(17) Hello World! (string) - 
+(18) true (string) - 
+(19) _level0 (string) - 
+(20) äöü (string) - 
+(21) _level0 (movieclip) - 
+(22) [object Object] (object) - 
+(23) Mon Oct 28 21:24:04 GMT+0000 2002 (object) - 1,45
+(24)  (object) - 
+(25) [type Function] (function) - 
+valueOf called
+(26) [type Object] (object) - 
+(27) [type Object] (object) - 
+valueOf called with 
+(28) [object Object] (object) - 
+(29)  (object) - 
+0: valueOf!
+(30)  (object) - 
+1: valueOf!
+(31) null (object) - 
+2: valueOf!
+(32) true (object) - 1
+3: valueOf!
+(33) false (object) - 
+4: valueOf!
+(34) 0 (object) - 
+5: valueOf!
+(35) 1 (object) - 1
+6: valueOf!
+(36) 0.5 (object) - 
+7: valueOf!
+(37) -1 (object) - 
+8: valueOf!
+(38) -0.5 (object) - 
+9: valueOf!
+(39) Infinity (object) - 
+10: valueOf!
+(40) -Infinity (object) - 
+11: valueOf!
+(41) NaN (object) - 
+12: valueOf!
+(42)  (object) - 
+13: valueOf!
+(43) 0 (object) - 
+14: valueOf!
+(44) -0 (object) - 
+15: valueOf!
+(45) 0.0 (object) - 
+16: valueOf!
+(46) 1 (object) - 1
+17: valueOf!
+(47) Hello World! (object) - 
+18: valueOf!
+(48) true (object) - 
+19: valueOf!
+(49) _level0 (object) - 
+20: valueOf!
+(50) äöü (object) - 
+21: valueOf!
+(51) _level0 (object) - 
+22: valueOf!
+(52) [type Object] (object) - 
+23: valueOf!
+(53) [type Object] (object) - 
+24: valueOf!
+(54) [type Object] (object) - 
+25: valueOf!
+(55) [type Object] (object) - 
+26: valueOf!
+(56) [type Object] (object) - 
+27: valueOf!
+(57) [type Object] (object) - 
+28: valueOf!
+(58) [type Object] (object) - 
+29: valueOf!
+(59) [type Object] (object) - 
diff --git a/test/trace/String-split-count-values-7.swf b/test/trace/String-split-count-values-7.swf
new file mode 100644
index 0000000..55c2f50
Binary files /dev/null and b/test/trace/String-split-count-values-7.swf differ
diff --git a/test/trace/String-split-count-values-7.swf.trace b/test/trace/String-split-count-values-7.swf.trace
new file mode 100644
index 0000000..bbbae34
--- /dev/null
+++ b/test/trace/String-split-count-values-7.swf.trace
@@ -0,0 +1,134 @@
+valueOf called
+toString called
+toString called with 
+valueOf called with 
+0: valueOf!
+1: valueOf!
+2: valueOf!
+3: valueOf!
+4: valueOf!
+5: valueOf!
+6: valueOf!
+7: valueOf!
+8: valueOf!
+9: valueOf!
+10: valueOf!
+11: valueOf!
+12: valueOf!
+13: valueOf!
+14: valueOf!
+15: valueOf!
+16: valueOf!
+17: valueOf!
+18: valueOf!
+19: valueOf!
+20: valueOf!
+21: valueOf!
+22: valueOf!
+22: toString!
+23: valueOf!
+23: toString!
+24: valueOf!
+24: toString!
+25: valueOf!
+25: toString!
+26: valueOf!
+26: toString!
+27: valueOf!
+27: toString!
+28: valueOf!
+28: toString!
+29: valueOf!
+29: toString!
+(0) undefined (undefined) - 1,45
+(1) null (null) - 
+(2) true (boolean) - 1
+(3) false (boolean) - 
+(4) 0 (number) - 
+(5) 1 (number) - 1
+(6) 0.5 (number) - 
+(7) -1 (number) - 
+(8) -0.5 (number) - 
+(9) Infinity (number) - 
+(10) -Infinity (number) - 
+(11) NaN (number) - 
+(12)  (string) - 
+(13) 0 (string) - 
+(14) -0 (string) - 
+(15) 0.0 (string) - 
+(16) 1 (string) - 1
+(17) Hello World! (string) - 
+(18) true (string) - 
+(19) _level0 (string) - 
+(20) äöü (string) - 
+(21) _level0 (movieclip) - 
+(22) [object Object] (object) - 
+(23) Mon Oct 28 21:24:04 GMT+0000 2002 (object) - 1,45
+(24)  (object) - 
+(25) [type Function] (function) - 
+valueOf called
+(26) [type Object] (object) - 
+(27) [type Object] (object) - 
+valueOf called with 
+(28) [object Object] (object) - 
+(29) undefined (object) - 
+0: valueOf!
+(30) undefined (object) - 
+1: valueOf!
+(31) null (object) - 
+2: valueOf!
+(32) true (object) - 1
+3: valueOf!
+(33) false (object) - 
+4: valueOf!
+(34) 0 (object) - 
+5: valueOf!
+(35) 1 (object) - 1
+6: valueOf!
+(36) 0.5 (object) - 
+7: valueOf!
+(37) -1 (object) - 
+8: valueOf!
+(38) -0.5 (object) - 
+9: valueOf!
+(39) Infinity (object) - 
+10: valueOf!
+(40) -Infinity (object) - 
+11: valueOf!
+(41) NaN (object) - 
+12: valueOf!
+(42)  (object) - 
+13: valueOf!
+(43) 0 (object) - 
+14: valueOf!
+(44) -0 (object) - 
+15: valueOf!
+(45) 0.0 (object) - 
+16: valueOf!
+(46) 1 (object) - 1
+17: valueOf!
+(47) Hello World! (object) - 
+18: valueOf!
+(48) true (object) - 
+19: valueOf!
+(49) _level0 (object) - 
+20: valueOf!
+(50) äöü (object) - 
+21: valueOf!
+(51) _level0 (object) - 
+22: valueOf!
+(52) [type Object] (object) - 
+23: valueOf!
+(53) [type Object] (object) - 
+24: valueOf!
+(54) [type Object] (object) - 
+25: valueOf!
+(55) [type Object] (object) - 
+26: valueOf!
+(56) [type Object] (object) - 
+27: valueOf!
+(57) [type Object] (object) - 
+28: valueOf!
+(58) [type Object] (object) - 
+29: valueOf!
+(59) [type Object] (object) - 
diff --git a/test/trace/String-split-count-values-8.swf b/test/trace/String-split-count-values-8.swf
new file mode 100644
index 0000000..91ea844
Binary files /dev/null and b/test/trace/String-split-count-values-8.swf differ
diff --git a/test/trace/String-split-count-values-8.swf.trace b/test/trace/String-split-count-values-8.swf.trace
new file mode 100644
index 0000000..bbbae34
--- /dev/null
+++ b/test/trace/String-split-count-values-8.swf.trace
@@ -0,0 +1,134 @@
+valueOf called
+toString called
+toString called with 
+valueOf called with 
+0: valueOf!
+1: valueOf!
+2: valueOf!
+3: valueOf!
+4: valueOf!
+5: valueOf!
+6: valueOf!
+7: valueOf!
+8: valueOf!
+9: valueOf!
+10: valueOf!
+11: valueOf!
+12: valueOf!
+13: valueOf!
+14: valueOf!
+15: valueOf!
+16: valueOf!
+17: valueOf!
+18: valueOf!
+19: valueOf!
+20: valueOf!
+21: valueOf!
+22: valueOf!
+22: toString!
+23: valueOf!
+23: toString!
+24: valueOf!
+24: toString!
+25: valueOf!
+25: toString!
+26: valueOf!
+26: toString!
+27: valueOf!
+27: toString!
+28: valueOf!
+28: toString!
+29: valueOf!
+29: toString!
+(0) undefined (undefined) - 1,45
+(1) null (null) - 
+(2) true (boolean) - 1
+(3) false (boolean) - 
+(4) 0 (number) - 
+(5) 1 (number) - 1
+(6) 0.5 (number) - 
+(7) -1 (number) - 
+(8) -0.5 (number) - 
+(9) Infinity (number) - 
+(10) -Infinity (number) - 
+(11) NaN (number) - 
+(12)  (string) - 
+(13) 0 (string) - 
+(14) -0 (string) - 
+(15) 0.0 (string) - 
+(16) 1 (string) - 1
+(17) Hello World! (string) - 
+(18) true (string) - 
+(19) _level0 (string) - 
+(20) äöü (string) - 
+(21) _level0 (movieclip) - 
+(22) [object Object] (object) - 
+(23) Mon Oct 28 21:24:04 GMT+0000 2002 (object) - 1,45
+(24)  (object) - 
+(25) [type Function] (function) - 
+valueOf called
+(26) [type Object] (object) - 
+(27) [type Object] (object) - 
+valueOf called with 
+(28) [object Object] (object) - 
+(29) undefined (object) - 
+0: valueOf!
+(30) undefined (object) - 
+1: valueOf!
+(31) null (object) - 
+2: valueOf!
+(32) true (object) - 1
+3: valueOf!
+(33) false (object) - 
+4: valueOf!
+(34) 0 (object) - 
+5: valueOf!
+(35) 1 (object) - 1
+6: valueOf!
+(36) 0.5 (object) - 
+7: valueOf!
+(37) -1 (object) - 
+8: valueOf!
+(38) -0.5 (object) - 
+9: valueOf!
+(39) Infinity (object) - 
+10: valueOf!
+(40) -Infinity (object) - 
+11: valueOf!
+(41) NaN (object) - 
+12: valueOf!
+(42)  (object) - 
+13: valueOf!
+(43) 0 (object) - 
+14: valueOf!
+(44) -0 (object) - 
+15: valueOf!
+(45) 0.0 (object) - 
+16: valueOf!
+(46) 1 (object) - 1
+17: valueOf!
+(47) Hello World! (object) - 
+18: valueOf!
+(48) true (object) - 
+19: valueOf!
+(49) _level0 (object) - 
+20: valueOf!
+(50) äöü (object) - 
+21: valueOf!
+(51) _level0 (object) - 
+22: valueOf!
+(52) [type Object] (object) - 
+23: valueOf!
+(53) [type Object] (object) - 
+24: valueOf!
+(54) [type Object] (object) - 
+25: valueOf!
+(55) [type Object] (object) - 
+26: valueOf!
+(56) [type Object] (object) - 
+27: valueOf!
+(57) [type Object] (object) - 
+28: valueOf!
+(58) [type Object] (object) - 
+29: valueOf!
+(59) [type Object] (object) - 
diff --git a/test/trace/String-split-count-values.as b/test/trace/String-split-count-values.as
new file mode 100644
index 0000000..f15ac2d
--- /dev/null
+++ b/test/trace/String-split-count-values.as
@@ -0,0 +1,11 @@
+// makeswf -v 7 -s 200x150 -r 1 -o String-split-count-values.swf String-split-count-values.as
+
+#include "values.as"
+
+s = "12345";
+
+for (i = 0; i < values.length; i++) {
+  trace (names[i] + " - " + s.split ("23", values[i]));
+};
+
+getURL ("fscommand:quit", "");
commit 85d56338542df488af47674ea102cb1ab225225e
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 21:43:51 2008 +0200

    fix String.split(x, undefined) to return the proper value

diff --git a/swfdec/swfdec_as_string.c b/swfdec/swfdec_as_string.c
index 3468e37..16c5d6d 100644
--- a/swfdec/swfdec_as_string.c
+++ b/swfdec/swfdec_as_string.c
@@ -370,7 +370,7 @@ swfdec_as_string_split_5 (SwfdecAsContext *cx, SwfdecAsObject *object,
     swfdec_as_array_push (arr, &val);
     return;
   }
-  if (argc > 1) {
+  if (argc > 1 && !SWFDEC_AS_VALUE_IS_UNDEFINED (&argv[1])) {
     swfdec_as_value_to_string (cx, &argv[0]);
     count = swfdec_as_value_to_integer (cx, &argv[1]);
   } else {
@@ -392,8 +392,7 @@ swfdec_as_string_split_5 (SwfdecAsContext *cx, SwfdecAsObject *object,
     }
     SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, g_strndup (str, end - str)));
     swfdec_as_array_push (arr, &val);
-    if (count)
-      count--;
+    count--;
     str = end + 1;
   }
 }
@@ -428,7 +427,7 @@ swfdec_as_string_split_6 (SwfdecAsContext *cx, SwfdecAsObject *object,
     swfdec_as_array_push (arr, &val);
     return;
   }
-  if (argc > 1)
+  if (argc > 1 && !SWFDEC_AS_VALUE_IS_UNDEFINED (&argv[1]))
     count = swfdec_as_value_to_integer (cx, &argv[1]);
   else
     count = G_MAXINT;
@@ -451,8 +450,7 @@ swfdec_as_string_split_6 (SwfdecAsContext *cx, SwfdecAsObject *object,
     }
     SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, g_strndup (str, end - str)));
     swfdec_as_array_push (arr, &val);
-    if (count)
-      count--;
+    count--;
     str = end + len;
   }
 }
commit 7aff0246ace6fc420c42fddbfb27cebe13e5cd5c
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 20:46:47 2008 +0200

    fix argument order

diff --git a/vivified/code/vivi_code_function_call.c b/vivified/code/vivi_code_function_call.c
index 5f93d29..2c7b6e7 100644
--- a/vivified/code/vivi_code_function_call.c
+++ b/vivified/code/vivi_code_function_call.c
@@ -139,11 +139,11 @@ vivi_code_function_call_compile_value (ViviCodeValue *value,
   vivi_code_compiler_compile_value (compiler, count);
   g_object_unref (count);
 
-  vivi_code_compiler_compile_value (compiler, call->name);
-
   if (call->value)
     vivi_code_compiler_compile_value (compiler, call->value);
 
+  vivi_code_compiler_compile_value (compiler, call->name);
+
   if (call->construct) {
     if (call->value) {
       code = vivi_code_asm_new_method_new ();
commit 92b2d2f15dc237c5f830250994363fc61f048336
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 14:03:24 2008 +0200

    implement Sound.loadSound()

diff --git a/swfdec/Makefile.am b/swfdec/Makefile.am
index 7d39e60..a4ea245 100644
--- a/swfdec/Makefile.am
+++ b/swfdec/Makefile.am
@@ -38,6 +38,7 @@ libswfdec_source_files = \
 	swfdec_audio_decoder_uncompressed.c \
 	$(CODEC_FILES) \
 	swfdec_audio_event.c \
+	swfdec_audio_load.c \
 	swfdec_audio_flv.c \
 	swfdec_audio_stream.c \
 	swfdec_audio_swf_stream.c \
@@ -93,6 +94,7 @@ libswfdec_source_files = \
 	swfdec_key_as.c \
 	swfdec_load_object.c \
 	swfdec_load_object_as.c \
+	swfdec_load_sound.c \
 	swfdec_loader.c \
 	swfdec_loadvars_as.c \
 	swfdec_local_connection.c \
@@ -237,6 +239,7 @@ noinst_HEADERS = \
 	swfdec_audio_decoder_uncompressed.h \
 	swfdec_audio_event.h \
 	swfdec_audio_flv.h \
+	swfdec_audio_load.h \
 	swfdec_audio_stream.h \
 	swfdec_audio_swf_stream.h \
 	swfdec_bits.h \
@@ -271,6 +274,7 @@ noinst_HEADERS = \
 	swfdec_internal.h \
 	swfdec_interval.h \
 	swfdec_load_object.h \
+	swfdec_load_sound.h \
 	swfdec_loader_internal.h \
 	swfdec_marshal.h \
 	swfdec_morph_movie.h \
diff --git a/swfdec/swfdec_audio_load.c b/swfdec/swfdec_audio_load.c
new file mode 100644
index 0000000..d63da2d
--- /dev/null
+++ b/swfdec/swfdec_audio_load.c
@@ -0,0 +1,93 @@
+/* Swfdec
+ * Copyright (C) 2008 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 <string.h>
+#include "swfdec_audio_load.h"
+#include "swfdec_debug.h"
+#include "swfdec_sprite.h"
+#include "swfdec_tag.h"
+
+
+G_DEFINE_TYPE (SwfdecAudioLoad, swfdec_audio_load, SWFDEC_TYPE_AUDIO_STREAM)
+
+static void
+swfdec_audio_load_dispose (GObject *object)
+{
+  SwfdecAudioLoad *stream = SWFDEC_AUDIO_LOAD (object);
+
+  if (stream->load != NULL) {
+    g_object_unref (stream->load);
+    stream->load = NULL;
+  }
+
+  G_OBJECT_CLASS (swfdec_audio_load_parent_class)->dispose (object);
+}
+
+static SwfdecBuffer *
+swfdec_audio_load_pull (SwfdecAudioStream *audio)
+{
+  SwfdecAudioLoad *stream = SWFDEC_AUDIO_LOAD (audio);
+
+  if (stream->frame >= stream->load->frames->len) {
+    if (stream->load->stream == NULL)
+      swfdec_audio_stream_done (audio);
+    return NULL;
+  }
+
+  return swfdec_buffer_ref (g_ptr_array_index (stream->load->frames, stream->frame++));
+}
+
+static void
+swfdec_audio_load_class_init (SwfdecAudioLoadClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecAudioStreamClass *stream_class = SWFDEC_AUDIO_STREAM_CLASS (klass);
+
+  object_class->dispose = swfdec_audio_load_dispose;
+
+  stream_class->pull = swfdec_audio_load_pull;
+}
+
+static void
+swfdec_audio_load_init (SwfdecAudioLoad *stream)
+{
+}
+
+SwfdecAudio *
+swfdec_audio_load_new (SwfdecPlayer *player, SwfdecLoadSound *load)
+{
+  SwfdecAudioLoad *stream;
+
+  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), NULL);
+  g_return_val_if_fail (SWFDEC_IS_LOAD_SOUND (load), NULL);
+
+  stream = g_object_new (SWFDEC_TYPE_AUDIO_LOAD, NULL);
+  stream->load = g_object_ref (load);
+  swfdec_audio_stream_use_decoder (SWFDEC_AUDIO_STREAM (stream), 
+      SWFDEC_AUDIO_CODEC_MP3, swfdec_audio_format_new (44100, TRUE, 2));
+  
+  swfdec_audio_add (SWFDEC_AUDIO (stream), player);
+
+  return SWFDEC_AUDIO (stream);
+}
+
diff --git a/swfdec/swfdec_audio_load.h b/swfdec/swfdec_audio_load.h
new file mode 100644
index 0000000..56bf5be
--- /dev/null
+++ b/swfdec/swfdec_audio_load.h
@@ -0,0 +1,58 @@
+/* Swfdec
+ * Copyright (C) 2008 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
+ */
+
+#ifndef _SWFDEC_AUDIO_LOAD_H_
+#define _SWFDEC_AUDIO_LOAD_H_
+
+#include <swfdec/swfdec_audio_stream.h>
+#include <swfdec/swfdec_load_sound.h>
+
+G_BEGIN_DECLS
+
+typedef struct _SwfdecAudioLoad SwfdecAudioLoad;
+typedef struct _SwfdecAudioLoadClass SwfdecAudioLoadClass;
+
+#define SWFDEC_TYPE_AUDIO_LOAD                    (swfdec_audio_load_get_type())
+#define SWFDEC_IS_AUDIO_LOAD(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_AUDIO_LOAD))
+#define SWFDEC_IS_AUDIO_LOAD_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_AUDIO_LOAD))
+#define SWFDEC_AUDIO_LOAD(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_AUDIO_LOAD, SwfdecAudioLoad))
+#define SWFDEC_AUDIO_LOAD_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_AUDIO_LOAD, SwfdecAudioLoadClass))
+#define SWFDEC_AUDIO_LOAD_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_AUDIO_LOAD, SwfdecAudioLoadClass))
+
+struct _SwfdecAudioLoad
+{
+  SwfdecAudioStream	stream;
+
+  SwfdecLoadSound *	load;			/* sound we play back */
+  guint			frame;			/* next frame to push */
+};
+
+struct _SwfdecAudioLoadClass
+{
+  SwfdecAudioStreamClass stream_class;
+};
+
+GType		swfdec_audio_load_get_type	(void);
+
+SwfdecAudio *	swfdec_audio_load_new		(SwfdecPlayer *		player,
+						 SwfdecLoadSound *	load);
+
+
+G_END_DECLS
+#endif
diff --git a/swfdec/swfdec_load_sound.c b/swfdec/swfdec_load_sound.c
new file mode 100644
index 0000000..6369232
--- /dev/null
+++ b/swfdec/swfdec_load_sound.c
@@ -0,0 +1,356 @@
+/* Swfdec
+ * Copyright (C) 2003, 2008 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_load_sound.h"
+#include "swfdec_as_strings.h"
+#include "swfdec_audio_decoder.h"
+#include "swfdec_bits.h"
+#include "swfdec_buffer.h"
+#include "swfdec_debug.h"
+#include "swfdec_loader_internal.h"
+#include "swfdec_player_internal.h"
+#include "swfdec_sandbox.h"
+#include "swfdec_stream_target.h"
+
+/*** SWFDEC_STREAM_TARGET ***/
+
+static SwfdecPlayer *
+swfdec_load_sound_stream_target_get_player (SwfdecStreamTarget *target)
+{
+  return SWFDEC_PLAYER (SWFDEC_LOAD_SOUND (target)->target->context);
+}
+
+static gboolean
+swfdec_load_sound_mp3_parse_id3v2 (SwfdecLoadSound *sound, SwfdecBufferQueue *queue)
+{
+  SwfdecBuffer *buffer;
+  SwfdecBits bits;
+  guint size;
+  gboolean footer;
+
+  buffer = swfdec_buffer_queue_peek (queue, 10);
+  if (buffer == NULL)
+    return FALSE;
+  swfdec_bits_init (&bits, buffer);
+  if (swfdec_bits_get_u8 (&bits) != 'I' ||
+      swfdec_bits_get_u8 (&bits) != 'D' ||
+      swfdec_bits_get_u8 (&bits) != '3')
+    goto error;
+  /* version = */ swfdec_bits_get_u16 (&bits);
+  /* flags = */ swfdec_bits_getbits (&bits, 3);
+  footer = swfdec_bits_getbit (&bits);
+  /* reserved = */ swfdec_bits_getbits (&bits, 4);
+  size = swfdec_bits_get_bu32 (&bits);
+  if (size & 0x80808080)
+    goto error;
+  size = ((size & 0xFF000000) >> 3) |
+    ((size & 0xFF0000) >> 2) |
+    ((size & 0xFF00) >> 1) | (size & 0xFF);
+  swfdec_buffer_unref (buffer);
+
+  buffer = swfdec_buffer_queue_pull (queue, 10 + size + (footer ? 10 : 0));
+  if (buffer == NULL)
+    return FALSE;
+  SWFDEC_FIXME ("implement ID3v2 parsing");
+  SWFDEC_LOG ("%u bytes ID3v2", buffer->length);
+  swfdec_buffer_unref (buffer);
+  return TRUE;
+
+error:
+  swfdec_buffer_unref (buffer);
+  swfdec_buffer_queue_flush (queue, 1);
+  return TRUE;
+}
+
+static gboolean
+swfdec_load_sound_mp3_parse_id3v1 (SwfdecLoadSound *sound, SwfdecBufferQueue *queue)
+{
+  SwfdecBuffer *buffer;
+  
+  buffer = swfdec_buffer_queue_pull (queue, 128);
+  if (buffer == NULL)
+    return FALSE;
+
+  if (buffer->data[0] != 'T' ||
+      buffer->data[1] != 'A' ||
+      buffer->data[2] != 'G') {
+    swfdec_buffer_unref (buffer);
+    swfdec_buffer_queue_flush (queue, 1);
+    return TRUE;
+  }
+  SWFDEC_FIXME ("implement ID3v1 parsing");
+  swfdec_buffer_unref (buffer);
+  return TRUE;
+}
+
+static gboolean
+swfdec_load_sound_mp3_parse_frame (SwfdecLoadSound *sound, SwfdecBufferQueue *queue)
+{
+  static const guint mp3types_bitrates[2][3][16] = { 
+    { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, },
+      {0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384, },
+      {0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, }},
+    { {0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256, },
+      {0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160, },
+      {0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160, }}
+  };
+  static const guint mp3types_freqs[3][3] = { 
+    { 11025, 12000,  8000 },
+    { 22050, 24000, 16000 },
+    { 44100, 48000, 32000 }
+  };
+
+  SwfdecBuffer *buffer;
+  SwfdecBits bits;
+  guint version, layer, bitrate, samplerate, length, channels;
+
+  buffer = swfdec_buffer_queue_peek (queue, 4);
+  if (buffer == NULL)
+    return FALSE;
+
+  swfdec_bits_init (&bits, buffer);
+  if (swfdec_bits_getbits (&bits, 11) != 0x7FF)
+    goto error;
+
+  version = swfdec_bits_getbits (&bits, 2);
+  if (version == 1)
+    goto error;
+  layer = 4 - swfdec_bits_getbits (&bits, 2);
+  if (layer == 4)
+    goto error;
+  /* has_crc = */ swfdec_bits_getbit (&bits);
+  bitrate = swfdec_bits_getbits (&bits, 4);
+  if (bitrate == 0 || bitrate == 15) {
+    if (bitrate == 0) {
+      SWFDEC_FIXME ("need to support free frame length?");
+    }
+    goto error;
+  }
+  samplerate = swfdec_bits_getbits (&bits, 2);
+  if (samplerate == 3)
+    goto error;
+  length = swfdec_bits_getbits (&bits, 1);
+  /* unused = */ swfdec_bits_getbits (&bits, 1);
+  channels = swfdec_bits_getbits (&bits, 2) == 3 ? 1 : 2;
+
+  samplerate = mp3types_freqs[version > 0 ? version - 1 : 0][samplerate];
+  bitrate = mp3types_bitrates[version == 3 ? 0 : 1][layer - 1][bitrate];
+  if (layer == 1) {
+    length = ((12000 * bitrate / samplerate) + length) * 4;
+  } else {
+    length += ((layer == 3 && version != 3) ? 72000 : 144000) 
+      * bitrate / samplerate;
+  }
+  swfdec_buffer_unref (buffer);
+
+  SWFDEC_LOG ("adding %u bytes mp3 frame", length);
+  buffer = swfdec_buffer_queue_pull (queue, length);
+  if (buffer == NULL)
+    return FALSE;
+
+  g_ptr_array_add (sound->frames, buffer);
+  return TRUE;
+
+error:
+  swfdec_buffer_unref (buffer);
+  swfdec_buffer_queue_flush (queue, 1);
+  return TRUE;
+}
+
+static gboolean
+swfdec_load_sound_stream_target_parse (SwfdecStreamTarget *target,
+    SwfdecStream *stream)
+{
+  SwfdecLoadSound *sound = SWFDEC_LOAD_SOUND (target);
+  SwfdecBufferQueue *queue;
+  SwfdecBuffer *buffer;
+  guint i;
+  gboolean go_on = TRUE;
+
+  /* decode MP3 into frames, ID3 tags and crap */
+  queue = swfdec_stream_get_queue (stream);
+  do {
+    /* sync */
+    buffer = swfdec_buffer_queue_peek_buffer (queue);
+    if (buffer == NULL)
+      break;
+    for (i = 0; i < buffer->length; i++) {
+      if (buffer->data[i] == 'I' || buffer->data[i] == 'T' || buffer->data[i] == 0xFF)
+	break;
+    }
+    if (i) {
+      SWFDEC_LOG ("sync: flushing %u bytes", i);
+    }
+    swfdec_buffer_queue_flush (queue, i);
+    if (i == buffer->length) {
+      swfdec_buffer_unref (buffer);
+      continue;
+    }
+    /* parse data */
+    switch (buffer->data[i]) {
+      case 'I':
+	/* ID3v2 */
+	go_on = swfdec_load_sound_mp3_parse_id3v2 (sound, queue);
+	break;
+      case 'T':
+	/* ID3v1 */
+	go_on = swfdec_load_sound_mp3_parse_id3v1 (sound, queue);
+	break;
+      case 0xFF:
+	/* MP3 frame */
+	go_on = swfdec_load_sound_mp3_parse_frame (sound, queue);
+	break;
+      default:
+	/* skip - and yes, the continue refers to the for loop */
+	continue;
+    }
+    swfdec_buffer_unref (buffer);
+  } while (go_on);
+  return FALSE;
+}
+
+static void
+swfdec_load_sound_stream_target_error (SwfdecStreamTarget *target,
+    SwfdecStream *stream)
+{
+  SwfdecLoadSound *sound = SWFDEC_LOAD_SOUND (target);
+  SwfdecAsValue val;
+
+  SWFDEC_AS_VALUE_SET_BOOLEAN (&val, FALSE);
+  swfdec_sandbox_use (sound->sandbox);
+  swfdec_as_object_call (sound->target, SWFDEC_AS_STR_onLoad, 1, &val, NULL);
+  swfdec_sandbox_unuse (sound->sandbox);
+
+  swfdec_stream_set_target (stream, NULL);
+  g_object_unref (stream);
+  sound->stream = NULL;
+}
+
+static void
+swfdec_load_sound_stream_target_close (SwfdecStreamTarget *target,
+    SwfdecStream *stream)
+{
+  SwfdecLoadSound *sound = SWFDEC_LOAD_SOUND (target);
+  SwfdecAsValue val;
+
+  swfdec_stream_set_target (stream, NULL);
+  g_object_unref (stream);
+  sound->stream = NULL;
+
+  SWFDEC_AS_VALUE_SET_BOOLEAN (&val, TRUE);
+  swfdec_sandbox_use (sound->sandbox);
+  swfdec_as_object_call (sound->target, SWFDEC_AS_STR_onLoad, 1, &val, NULL);
+  swfdec_sandbox_unuse (sound->sandbox);
+}
+
+static void
+swfdec_load_sound_stream_target_init (SwfdecStreamTargetInterface *iface)
+{
+  iface->get_player = swfdec_load_sound_stream_target_get_player;
+  iface->parse = swfdec_load_sound_stream_target_parse;
+  iface->close = swfdec_load_sound_stream_target_close;
+  iface->error = swfdec_load_sound_stream_target_error;
+}
+
+/*** SWFDEC_LOAD_SOUND ***/
+
+G_DEFINE_TYPE_WITH_CODE (SwfdecLoadSound, swfdec_load_sound, G_TYPE_OBJECT,
+    G_IMPLEMENT_INTERFACE (SWFDEC_TYPE_STREAM_TARGET, swfdec_load_sound_stream_target_init))
+
+static void
+swfdec_load_sound_dispose (GObject *object)
+{
+  SwfdecLoadSound *sound = SWFDEC_LOAD_SOUND (object);
+
+  g_ptr_array_foreach (sound->frames, (GFunc) swfdec_buffer_unref, NULL);
+  g_ptr_array_free (sound->frames, TRUE);
+  if (sound->stream) {
+    swfdec_stream_set_target (sound->stream, NULL);
+    g_object_unref (sound->stream);
+    sound->stream = NULL;
+  }
+  g_free (sound->url);
+
+  G_OBJECT_CLASS (swfdec_load_sound_parent_class)->dispose (object);
+}
+
+static void
+swfdec_load_sound_class_init (SwfdecLoadSoundClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = swfdec_load_sound_dispose;
+}
+
+static void
+swfdec_load_sound_init (SwfdecLoadSound *sound)
+{
+  sound->frames = g_ptr_array_new ();
+}
+
+static void
+swfdec_load_sound_load (SwfdecPlayer *player, gboolean allow, gpointer data)
+{
+  SwfdecLoadSound *sound = data;
+
+  if (!allow) {
+    SwfdecAsValue val;
+
+    SWFDEC_WARNING ("SECURITY: no access to %s from Sound.loadSound",
+	sound->url);
+    SWFDEC_AS_VALUE_SET_BOOLEAN (&val, FALSE);
+    return;
+  }
+
+  sound->stream = SWFDEC_STREAM (swfdec_player_load (player, sound->url, NULL));
+  swfdec_stream_set_target (sound->stream, SWFDEC_STREAM_TARGET (sound));
+}
+
+SwfdecLoadSound *
+swfdec_load_sound_new (SwfdecAsObject *target, const char *url)
+{
+  SwfdecLoadSound *sound;
+  char *missing;
+
+  g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (target), NULL);
+  g_return_val_if_fail (url != NULL, NULL);
+
+  sound = g_object_new (SWFDEC_TYPE_LOAD_SOUND, NULL);
+  sound->target = target;
+  sound->sandbox = SWFDEC_SANDBOX (target->context->global);
+  sound->url = g_strdup (url);
+  swfdec_player_load_default (SWFDEC_PLAYER (target->context), url, 
+      swfdec_load_sound_load, sound);
+  /* tell missing plugins stuff we want MP3 */
+  missing = NULL;
+  swfdec_audio_decoder_prepare (SWFDEC_AUDIO_CODEC_MP3, 
+      swfdec_audio_format_new (44100, 2, TRUE), &missing);
+  if (missing) {
+    swfdec_player_add_missing_plugin (SWFDEC_PLAYER (target->context),
+	missing);
+    g_free (missing);
+  }
+
+  return sound;
+}
+
diff --git a/swfdec/swfdec_load_sound.h b/swfdec/swfdec_load_sound.h
new file mode 100644
index 0000000..f5e7e97
--- /dev/null
+++ b/swfdec/swfdec_load_sound.h
@@ -0,0 +1,63 @@
+/* Swfdec
+ * Copyright (C) 2008 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
+ */
+
+#ifndef _SWFDEC_LOAD_SOUND_H_
+#define _SWFDEC_LOAD_SOUND_H_
+
+#include <swfdec/swfdec_as_object.h>
+#include <swfdec/swfdec_stream.h>
+#include <swfdec/swfdec_types.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct _SwfdecLoadSound SwfdecLoadSound;
+typedef struct _SwfdecLoadSoundClass SwfdecLoadSoundClass;
+
+#define SWFDEC_TYPE_LOAD_SOUND                    (swfdec_load_sound_get_type())
+#define SWFDEC_IS_LOAD_SOUND(obj)                 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_LOAD_SOUND))
+#define SWFDEC_IS_LOAD_SOUND_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_LOAD_SOUND))
+#define SWFDEC_LOAD_SOUND(obj)                    (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_LOAD_SOUND, SwfdecLoadSound))
+#define SWFDEC_LOAD_SOUND_CLASS(klass)            (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_LOAD_SOUND, SwfdecLoadSoundClass))
+#define SWFDEC_LOAD_SOUND_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_LOAD_SOUND, SwfdecLoadSoundClass))
+
+struct _SwfdecLoadSound
+{
+  GObject		object;
+
+  SwfdecAsObject *	target;		/* target using us that we emit events on, a SwfdecSoundObject */
+  SwfdecSandbox *	sandbox;	/* sandbox we use for emission of events */
+  char *		url;		/* URL we are loading - FIXME: make the security stuff hand us a loader */
+  SwfdecStream *	stream;		/* stream we're parsing or NULL when done parsing */
+  GPtrArray *		frames;		/* buffers pointing to the frames of this file */
+};
+
+struct _SwfdecLoadSoundClass
+{
+  GObjectClass    	object_class;
+};
+
+GType			swfdec_load_sound_get_type	(void);
+
+SwfdecLoadSound *	swfdec_load_sound_new		(SwfdecAsObject *	target,
+							 const char *		url);
+
+
+G_END_DECLS
+#endif
diff --git a/swfdec/swfdec_sound_object.c b/swfdec/swfdec_sound_object.c
index b689c61..2f0fd45 100644
--- a/swfdec/swfdec_sound_object.c
+++ b/swfdec/swfdec_sound_object.c
@@ -29,6 +29,7 @@
 #include "swfdec_as_object.h"
 #include "swfdec_as_strings.h"
 #include "swfdec_audio_event.h"
+#include "swfdec_audio_load.h"
 #include "swfdec_debug.h"
 #include "swfdec_internal.h"
 #include "swfdec_player_internal.h"
@@ -58,6 +59,10 @@ swfdec_sound_object_dispose (GObject *object)
     g_object_unref (sound->attached);
     sound->attached = NULL;
   }
+  if (sound->load) {
+    g_object_unref (sound->load);
+    sound->load = NULL;
+  }
 
   G_OBJECT_CLASS (swfdec_sound_object_parent_class)->dispose (object);
 }
@@ -285,7 +290,17 @@ void
 swfdec_sound_object_loadSound (SwfdecAsContext *cx, SwfdecAsObject *object,
     guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
 {
-  SWFDEC_STUB ("Sound.loadSound");
+  SwfdecSoundObject *sound;
+  const char *url;
+  gboolean stream;
+
+  SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "sb", &url, &stream);
+
+  if (sound->load)
+    g_object_unref (sound->load);
+  sound->load = swfdec_load_sound_new (object, url);
+  if (stream)
+    sound->audio = swfdec_audio_load_new (SWFDEC_PLAYER (cx), sound->load);
 }
 
 SWFDEC_AS_NATIVE (500, 14, swfdec_sound_object_getBytesLoaded)
diff --git a/swfdec/swfdec_sound_object.h b/swfdec/swfdec_sound_object.h
index ec057b6..c053057 100644
--- a/swfdec/swfdec_sound_object.h
+++ b/swfdec/swfdec_sound_object.h
@@ -20,6 +20,8 @@
 #ifndef _SWFDEC_SOUND_OBJECT_H_
 #define _SWFDEC_SOUND_OBJECT_H_
 
+#include <swfdec/swfdec_audio.h>
+#include <swfdec/swfdec_load_sound.h>
 #include <swfdec/swfdec_movie.h>
 
 G_BEGIN_DECLS
@@ -41,6 +43,8 @@ struct _SwfdecSoundObject {
   SwfdecMovie *		target;		/* target movie or NULL on constructing error */
   gboolean		global;		/* TRUE if handling global sound */
   SwfdecSound *		attached;	/* sound that was attached */
+  SwfdecLoadSound *	load;		/* sound that is/was loaded using loadSound */
+  SwfdecAudio *		audio;		/* audio stream we started */
 };
 
 struct _SwfdecSoundObjectClass {
commit 9d283a4cd7e31ee9cf99839db483455adf5bb60d
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 14:02:59 2008 +0200

    don't remove audio when buffering and no audio was available

diff --git a/swfdec/swfdec_audio_stream.c b/swfdec/swfdec_audio_stream.c
index acdef91..62bff62 100644
--- a/swfdec/swfdec_audio_stream.c
+++ b/swfdec/swfdec_audio_stream.c
@@ -120,24 +120,25 @@ swfdec_audio_stream_render (SwfdecAudio *audio, gint16* dest,
   return rendered - start;
 }
 
-static void
+static gboolean
 swfdec_audio_stream_check_buffering (SwfdecAudioStream *stream)
 {
   SwfdecAudioStreamClass *klass;
   SwfdecBuffer *buffer;
 
-  if (!stream->buffering)
-    return;
+  if (!stream->buffering || stream->done)
+    return FALSE;
 
-  klass = SWFDEC_AUDIO_STREAM_CLASS (stream);
+  klass = SWFDEC_AUDIO_STREAM_GET_CLASS (stream);
   buffer = klass->pull (stream);
   if (buffer == NULL)
-    return;
+    return FALSE;
 
   swfdec_audio_decoder_push (stream->decoder, buffer);
   swfdec_buffer_unref (buffer);
   stream->buffering = FALSE;
   g_signal_emit_by_name (stream, "new-data");
+  return stream->queue_size == 0;
 }
 
 static gsize
@@ -147,7 +148,8 @@ swfdec_audio_stream_iterate (SwfdecAudio *audio, gsize remove)
   SwfdecBuffer *buffer;
   gsize samples, cur_samples;
 
-  swfdec_audio_stream_check_buffering (stream);
+  if (swfdec_audio_stream_check_buffering (stream))
+    return G_MAXUINT;
   swfdec_audio_stream_require (stream, remove);
   samples = MIN (remove, stream->queue_size);
 
commit 732a5412513384ccc3fbee03bd16a33e17531359
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 10:52:32 2008 +0200

    remove -Wlogical-op from warning flags
    
    gcc emits lots of useless warnings there, see the added comment.

diff --git a/configure.ac b/configure.ac
index ca54cec..588089f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,8 @@ AC_CONFIG_MACRO_DIR([m4])
 dnl decide on error flags
 dnl if we support them, we set them unconditionally
 dnl FIXME: I want this but stupid headers don't let me: -Wshadow
-AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wmissing-noreturn -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-enum -Wswitch-default -Winit-self -Wmissing-include-dirs -Wundef -Waddress -Wlogical-op -Waggregate-return -Wmissing-format-attribute -Wno-multichar -Wnested-externs")
+dnl FIXME: readd -Wlogical-op when http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36513 is solved
+AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wmissing-noreturn -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Winline -Wformat-nonliteral -Wformat-security -Wswitch-enum -Wswitch-default -Winit-self -Wmissing-include-dirs -Wundef -Waddress -Waggregate-return -Wmissing-format-attribute -Wno-multichar -Wnested-externs")
 dnl if we're in nano >= 1, add -Werror if supported
 if test x$SWFDEC_CVS = xyes ; then
   AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Werror")
commit 7875841e5ba9a53ce70b18d2625174c05c13e803
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 10:52:11 2008 +0200

    implement new-data signal

diff --git a/swfdec-gtk/swfdec_playback_alsa.c b/swfdec-gtk/swfdec_playback_alsa.c
index 84cf7e1..f4711e9 100644
--- a/swfdec-gtk/swfdec_playback_alsa.c
+++ b/swfdec-gtk/swfdec_playback_alsa.c
@@ -259,6 +259,12 @@ swfdec_playback_stream_changed (SwfdecAudio *audio, Stream *stream)
 }
 
 static void
+swfdec_playback_stream_new_data (SwfdecAudio *audio, Stream *stream)
+{
+  swfdec_playback_stream_install_handlers (stream);
+}
+
+static void
 swfdec_playback_stream_open (SwfdecPlayback *sound, SwfdecAudio *audio)
 {
   Stream *stream;
@@ -325,6 +331,8 @@ swfdec_playback_stream_open (SwfdecPlayback *sound, SwfdecAudio *audio)
   sound->streams = g_list_prepend (sound->streams, stream);
   g_signal_connect (stream->audio, "changed", 
       G_CALLBACK (swfdec_playback_stream_changed), stream);
+  g_signal_connect (stream->audio, "new-data", 
+      G_CALLBACK (swfdec_playback_stream_new_data), stream);
   swfdec_playback_stream_start (stream);
   return;
 
@@ -341,6 +349,8 @@ swfdec_playback_stream_close (Stream *stream)
   stream->sound->streams = g_list_remove (stream->sound->streams, stream);
   g_signal_handlers_disconnect_by_func (stream->audio, 
       swfdec_playback_stream_changed, stream);
+  g_signal_handlers_disconnect_by_func (stream->audio, 
+      swfdec_playback_stream_new_data, stream);
   g_object_unref (stream->audio);
   g_free (stream);
 }
commit 840c59b5b1c7ce65599dd65bc5f1e47788ad1c01
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 10:51:25 2008 +0200

    allow buffering of audio streams and emit "new-data" signal when new data arrives

diff --git a/swfdec/swfdec_audio.c b/swfdec/swfdec_audio.c
index 6a7b1b2..b74d05f 100644
--- a/swfdec/swfdec_audio.c
+++ b/swfdec/swfdec_audio.c
@@ -60,6 +60,7 @@ G_DEFINE_ABSTRACT_TYPE (SwfdecAudio, swfdec_audio, G_TYPE_OBJECT)
 
 enum {
   CHANGED,
+  NEW_DATA,
   LAST_SIGNAL
 };
 
@@ -92,6 +93,17 @@ swfdec_audio_class_init (SwfdecAudioClass *klass)
   signals[CHANGED] = g_signal_new ("changed", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
       G_TYPE_NONE, 0);
+  /**
+   * SwfdecAudio::new-data:
+   * @audio: the #SwfdecAudio affected
+   *
+   * This signal is emitted whenever new data was loaded into @audio. You want
+   * to listen to this signal when swfdec_audio_render() previously returned 
+   * less samples than you wanted to render.
+   */
+  signals[NEW_DATA] = g_signal_new ("new-data", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
+      G_TYPE_NONE, 0);
 
   object_class->dispose = swfdec_audio_dispose;
 }
diff --git a/swfdec/swfdec_audio_stream.c b/swfdec/swfdec_audio_stream.c
index b69174b..acdef91 100644
--- a/swfdec/swfdec_audio_stream.c
+++ b/swfdec/swfdec_audio_stream.c
@@ -68,8 +68,10 @@ swfdec_audio_stream_require (SwfdecAudioStream *stream, guint n_samples)
     }
     /* otherwise get a new buffer from the decoder */
     buffer = klass->pull (stream);
-    if (buffer == NULL)
+    if (buffer == NULL) {
+      stream->buffering = TRUE;
       break;
+    }
     swfdec_audio_decoder_push (stream->decoder, buffer);
     swfdec_buffer_unref (buffer);
   }
@@ -118,6 +120,26 @@ swfdec_audio_stream_render (SwfdecAudio *audio, gint16* dest,
   return rendered - start;
 }
 
+static void
+swfdec_audio_stream_check_buffering (SwfdecAudioStream *stream)
+{
+  SwfdecAudioStreamClass *klass;
+  SwfdecBuffer *buffer;
+
+  if (!stream->buffering)
+    return;
+
+  klass = SWFDEC_AUDIO_STREAM_CLASS (stream);
+  buffer = klass->pull (stream);
+  if (buffer == NULL)
+    return;
+
+  swfdec_audio_decoder_push (stream->decoder, buffer);
+  swfdec_buffer_unref (buffer);
+  stream->buffering = FALSE;
+  g_signal_emit_by_name (stream, "new-data");
+}
+
 static gsize
 swfdec_audio_stream_iterate (SwfdecAudio *audio, gsize remove)
 {
@@ -125,6 +147,7 @@ swfdec_audio_stream_iterate (SwfdecAudio *audio, gsize remove)
   SwfdecBuffer *buffer;
   gsize samples, cur_samples;
 
+  swfdec_audio_stream_check_buffering (stream);
   swfdec_audio_stream_require (stream, remove);
   samples = MIN (remove, stream->queue_size);
 
diff --git a/swfdec/swfdec_audio_stream.h b/swfdec/swfdec_audio_stream.h
index 824d477..92d2984 100644
--- a/swfdec/swfdec_audio_stream.h
+++ b/swfdec/swfdec_audio_stream.h
@@ -45,6 +45,7 @@ struct _SwfdecAudioStream
   GQueue *		queue;		/* all the samples we've decoded so far */
   gsize			queue_size;	/* size of queue in samples */
   gboolean		done;		/* no more data will arrive */
+  gboolean		buffering;	/* pull vfunc returned NULL */
 };
 
 struct _SwfdecAudioStreamClass
commit 3dc519878fc24ad568ecd94f1426bd296bd891d9
Author: Benjamin Otte <otte at gnome.org>
Date:   Fri Jun 13 10:16:50 2008 +0200

    remove debugging code
    
    Everybody knows how I debug by now, if you consider how much code I've
    scattered everywhere...

diff --git a/swfdec/swfdec_audio_swf_stream.c b/swfdec/swfdec_audio_swf_stream.c
index eec2e5c..9a38753 100644
--- a/swfdec/swfdec_audio_swf_stream.c
+++ b/swfdec/swfdec_audio_swf_stream.c
@@ -159,24 +159,6 @@ swfdec_audio_swf_stream_init (SwfdecAudioSwfStream *stream)
 {
 }
 
-static void
-check (SwfdecAudio *audio)
-{
-  guint length = 20000;
-  gint16 *data = g_new (gint16, 2 * length);
-  gint16 *compare = g_new (gint16, 2 * length);
-  guint i;
-
-  swfdec_audio_render (audio, compare, 0, length);
-  for (i = 1; i < length; i++) {
-    swfdec_audio_render (audio, data, i, length - i);
-    g_assert (memcmp (data, compare + 2 * i, (length - i) * 4) == 0);
-  }
-
-  g_free (data);
-  g_free (compare);
-}
-
 SwfdecAudio *
 swfdec_audio_swf_stream_new (SwfdecPlayer *player, SwfdecSprite *sprite,
     guint id)
@@ -210,7 +192,6 @@ swfdec_audio_swf_stream_new (SwfdecPlayer *player, SwfdecSprite *sprite,
 
 found:
   swfdec_audio_add (SWFDEC_AUDIO (stream), player);
-  check (SWFDEC_AUDIO (stream));
   return SWFDEC_AUDIO (stream);
 }
 
commit b30bf3f7ee637ad113e726d26722c1235f15674b
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 12 21:27:27 2008 +0200

    include swfdec_as_array.h

diff --git a/swfdec/swfdec.h b/swfdec/swfdec.h
index 2dec954..cc3ea1f 100644
--- a/swfdec/swfdec.h
+++ b/swfdec/swfdec.h
@@ -22,6 +22,7 @@
 #ifndef __SWFDEC_H__
 #define __SWFDEC_H__
 
+#include <swfdec/swfdec_as_array.h>
 #include <swfdec/swfdec_as_context.h>
 #include <swfdec/swfdec_as_debugger.h>
 #include <swfdec/swfdec_as_frame.h>
commit 431c0250eaf5b26c506da4d0f3983e1f4ecaeb52
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 12 21:26:39 2008 +0200

    put the native function table into its own source file
    
    Avoids duplicate declarations with the next change

diff --git a/swfdec/.gitignore b/swfdec/.gitignore
index 9f923f0..bf881cd 100644
--- a/swfdec/.gitignore
+++ b/swfdec/.gitignore
@@ -12,7 +12,7 @@ Makefile.in
 *.loT
 
 swfdec_as_strings.h
-swfdec_asnative.h
+swfdec_asnative.c
 swfdec_enums.[ch]
 swfdec_marshal.[ch]
 
diff --git a/swfdec/Makefile.am b/swfdec/Makefile.am
index 8b78fdf..7d39e60 100644
--- a/swfdec/Makefile.am
+++ b/swfdec/Makefile.am
@@ -168,6 +168,7 @@ libswfdec_source_files = \
 
 libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES = \
   	$(libswfdec_source_files) \
+	swfdec_asnative.c \
 	swfdec_enums.c \
 	swfdec_marshal.c
 
@@ -321,7 +322,7 @@ EXTRA_DIST = \
 	swfdec_marshal.list
 
 BUILT_SOURCES = \
-	swfdec_asnative.h \
+	swfdec_asnative.c \
 	swfdec_as_strings.h \
 	swfdec_enums.c \
 	swfdec_enums.h \
@@ -331,7 +332,7 @@ BUILT_SOURCES = \
 CLEANFILES = \
 	$(BUILT_SOURCES)
 
-swfdec_asnative.h: $(libswfdec_source_files)
+swfdec_asnative.c: $(libswfdec_source_files)
 	(cd $(srcdir) \
 	  && echo "#include \"swfdec_as_types.h\"" \
 	  && echo "#define SWFDEC_AS_NATIVE(x,y,func) void func (SwfdecAsContext *cx, \\" \
@@ -343,7 +344,7 @@ swfdec_asnative.h: $(libswfdec_source_files)
 	  && echo "#undef SWFDEC_AS_NATIVE" \
 	  && echo "#define SWFDEC_AS_NATIVE(x,y,func) SWFDEC_AS_CONSTRUCTOR(x,y,func,NULL)" \
 	  && echo "#define SWFDEC_AS_CONSTRUCTOR(x,y,func,type) { x, y, func, G_STRINGIFY (func), type }," \
-	  && echo "static const struct { guint x, y; SwfdecAsNative func; const char *name; GType (* get_type) (void); } native_funcs[] = {" \
+	  && echo "const struct { guint x, y; SwfdecAsNative func; const char *name; GType (* get_type) (void); } native_funcs[] = {" \
 	  && grep -he "^SWFDEC_AS_CONSTRUCTOR" $(libswfdec_source_files) \
 	  && grep -he "^SWFDEC_AS_NATIVE" $(libswfdec_source_files) \
 	  && echo "  { 0, 0, NULL }" \
@@ -351,7 +352,7 @@ swfdec_asnative.h: $(libswfdec_source_files)
 	  && echo "#undef SWFDEC_AS_CONSTRUCTOR" \
 	  && echo "#undef SWFDEC_AS_NATIVE" \
 	 ) >> xgen-san \
-	&& (cmp -s xgen-san swfdec_asnative.h || cp xgen-san swfdec_asnative.h) \
+	&& (cmp -s xgen-san swfdec_asnative.c || cp xgen-san swfdec_asnative.c) \
 	&& rm -f xgen-san
 
 swfdec_marshal.h: swfdec_marshal.list Makefile
diff --git a/swfdec/swfdec_asnative.h b/swfdec/swfdec_asnative.h
new file mode 100644
index 0000000..3ca29ff
--- /dev/null
+++ b/swfdec/swfdec_asnative.h
@@ -0,0 +1,32 @@
+/* Swfdec
+ * Copyright (C) 2008 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
+ */
+
+#ifndef _SWFDEC_ASNATIVE_H_
+#define _SWFDEC_ASNATIVE_H_
+
+#include <swfdec/swfdec_as_native_function.h>
+
+extern const struct { 
+  guint x, y; 
+  SwfdecAsNative func; 
+  const char *name; 
+  GType (* get_type) (void); 
+} native_funcs[];
+
+#endif
diff --git a/swfdec/swfdec_player_as.c b/swfdec/swfdec_player_as.c
index d4d8dd5..de9744a 100644
--- a/swfdec/swfdec_player_as.c
+++ b/swfdec/swfdec_player_as.c
@@ -35,10 +35,6 @@
 #include "swfdec_interval.h"
 #include "swfdec_as_frame_internal.h"
 
-/* FIXME: to avoid duplicate definitions */
-#undef SWFDEC_AS_NATIVE
-#define SWFDEC_AS_NATIVE(x, y, func)
-
 /*** INTERVALS ***/
 
 static void
commit 02a24ed1590922db8e961d61ba4a76c715748bb4
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 12 18:13:16 2008 +0200

    add swfdec_player_load_default() function that does proper security checks

diff --git a/swfdec/swfdec_net_stream.c b/swfdec/swfdec_net_stream.c
index 6d6896f..70fdbb3 100644
--- a/swfdec/swfdec_net_stream.c
+++ b/swfdec/swfdec_net_stream.c
@@ -570,14 +570,13 @@ swfdec_net_stream_load (SwfdecPlayer *player, gboolean allowed, gpointer streamp
 }
 
 void
-swfdec_net_stream_set_url (SwfdecNetStream *stream, SwfdecSandbox *sandbox, const char *url_string)
+swfdec_net_stream_set_url (SwfdecNetStream *stream, const char *url_string)
 {
   SwfdecPlayer *player;
   SwfdecAsContext *cx;
-  SwfdecURL *url;
 
   g_return_if_fail (SWFDEC_IS_NET_STREAM (stream));
-  g_return_if_fail (SWFDEC_IS_SANDBOX (sandbox));
+  g_return_if_fail (url_string != NULL);
 
   cx = SWFDEC_AS_OBJECT (stream)->context;
   player = SWFDEC_PLAYER (cx);
@@ -588,52 +587,9 @@ swfdec_net_stream_set_url (SwfdecNetStream *stream, SwfdecSandbox *sandbox, cons
     return;
   }
   stream->requested_url = g_strdup (url_string);
-  stream->sandbox = sandbox;
-#if 0
-  if (swfdec_url_path_is_relative (url_string)) {
-    swfdec_net_stream_load (player, TRUE, stream);
-    return;
-  }
-#endif
-  url = swfdec_player_create_url (player, url_string);
-  if (url == NULL) {
-    swfdec_net_stream_load (player, FALSE, stream);
-    return;
-  }
-  if (swfdec_url_is_local (url)) {
-    swfdec_net_stream_load (player, 
-	sandbox->type == SWFDEC_SANDBOX_LOCAL_TRUSTED ||
-	sandbox->type == SWFDEC_SANDBOX_LOCAL_FILE, stream);
-  } else {
-    switch (sandbox->type) {
-      case SWFDEC_SANDBOX_REMOTE:
-	if (swfdec_url_host_equal(url, sandbox->url)) {
-	  swfdec_net_stream_load (player, TRUE, stream);
-	  break;
-	}
-	/* fall through */
-      case SWFDEC_SANDBOX_LOCAL_NETWORK:
-      case SWFDEC_SANDBOX_LOCAL_TRUSTED:
-	{
-	  SwfdecURL *load_url = swfdec_url_new_components (
-	      swfdec_url_get_protocol (url), swfdec_url_get_host (url), 
-	      swfdec_url_get_port (url), "crossdomain.xml", NULL);
-	  swfdec_player_allow_or_load (player, url, load_url,
-	    swfdec_net_stream_load, stream);
-	  swfdec_url_free (load_url);
-	}
-	break;
-      case SWFDEC_SANDBOX_LOCAL_FILE:
-	swfdec_net_stream_load (player, FALSE, stream);
-	break;
-      case SWFDEC_SANDBOX_NONE:
-      default:
-	g_assert_not_reached ();
-	break;
-    }
-  }
+  stream->sandbox = SWFDEC_SANDBOX (SWFDEC_AS_CONTEXT (player)->global);
 
-  swfdec_url_free (url);
+  swfdec_player_load_default (player, url_string, swfdec_net_stream_load, stream);
 }
 
 void
diff --git a/swfdec/swfdec_net_stream.h b/swfdec/swfdec_net_stream.h
index e8414de..2f7783d 100644
--- a/swfdec/swfdec_net_stream.h
+++ b/swfdec/swfdec_net_stream.h
@@ -81,7 +81,6 @@ GType			swfdec_net_stream_get_type	(void);
 SwfdecNetStream *	swfdec_net_stream_new		(SwfdecNetConnection *	conn);
 
 void			swfdec_net_stream_set_url	(SwfdecNetStream *	stream,
-							 SwfdecSandbox *	sandbox,
 							 const char *		url);
 void			swfdec_net_stream_set_loader	(SwfdecNetStream *	stream,
 							 SwfdecLoader *		loader);
diff --git a/swfdec/swfdec_net_stream_as.c b/swfdec/swfdec_net_stream_as.c
index 93b889a..4eebd18 100644
--- a/swfdec/swfdec_net_stream_as.c
+++ b/swfdec/swfdec_net_stream_as.c
@@ -51,7 +51,7 @@ swfdec_net_stream_play (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, Sw
   const char *url;
 
   url = swfdec_as_value_to_string (cx, &argv[0]);
-  swfdec_net_stream_set_url (stream, SWFDEC_SANDBOX (cx->global), url);
+  swfdec_net_stream_set_url (stream, url);
   swfdec_net_stream_set_playing (stream, TRUE);
 }
 
diff --git a/swfdec/swfdec_player_internal.h b/swfdec/swfdec_player_internal.h
index 70bdbb8..d51c5e1 100644
--- a/swfdec/swfdec_player_internal.h
+++ b/swfdec/swfdec_player_internal.h
@@ -279,6 +279,11 @@ void	      	swfdec_player_allow_or_load	(SwfdecPlayer *		player,
 						 const SwfdecURL *	load_url,
 						 SwfdecPolicyFunc	func,
 						 gpointer		data);
+void	      	swfdec_player_load_default	(SwfdecPlayer *		player,
+						 const char *		url_string,
+						 SwfdecPolicyFunc	func,
+						 gpointer		data);
+
 /* in swfdec_as_interpret.c */
 SwfdecMovie *	swfdec_player_get_movie_from_value 
 						(SwfdecPlayer *		player,
diff --git a/swfdec/swfdec_policy_file.c b/swfdec/swfdec_policy_file.c
index 9a2471d..084202d 100644
--- a/swfdec/swfdec_policy_file.c
+++ b/swfdec/swfdec_policy_file.c
@@ -1,5 +1,5 @@
 /* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ * Copyright (C) 2007-2008 Benjamin Otte <otte at gnome.org>
  *               2007 Pekka Lampila <pekka.lampila at iki.fi>
  *
  * This library is free software; you can redistribute it and/or
@@ -31,6 +31,7 @@
 #include "swfdec_internal.h"
 #include "swfdec_loader_internal.h"
 #include "swfdec_player_internal.h"
+#include "swfdec_sandbox.h"
 #include "swfdec_xml.h"
 #include "swfdec_xml_node.h"
 
@@ -358,3 +359,57 @@ swfdec_player_allow_or_load (SwfdecPlayer *player, const SwfdecURL *url,
   file->requests = g_slist_append (file->requests, request);
 }
 
+void
+swfdec_player_load_default (SwfdecPlayer *player, const char *url_string,
+    SwfdecPolicyFunc func, gpointer data)
+{
+  SwfdecSandbox *sandbox;
+  SwfdecURL *url;
+
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+  g_return_if_fail (url_string != NULL);
+  g_return_if_fail (func);
+
+  sandbox = SWFDEC_SANDBOX (SWFDEC_AS_CONTEXT (player)->global);
+  g_assert (sandbox);
+
+  url = swfdec_player_create_url (player, url_string);
+  if (url == NULL) {
+    func (player, FALSE, data);
+    return;
+  }
+  if (swfdec_url_is_local (url)) {
+    func (player, 
+	sandbox->type == SWFDEC_SANDBOX_LOCAL_TRUSTED ||
+	sandbox->type == SWFDEC_SANDBOX_LOCAL_FILE, data);
+  } else {
+    switch (sandbox->type) {
+      case SWFDEC_SANDBOX_REMOTE:
+	if (swfdec_url_host_equal(url, sandbox->url)) {
+	  func (player, TRUE, data);
+	  break;
+	}
+	/* fall through */
+      case SWFDEC_SANDBOX_LOCAL_NETWORK:
+      case SWFDEC_SANDBOX_LOCAL_TRUSTED:
+	{
+	  SwfdecURL *load_url = swfdec_url_new_components (
+	      swfdec_url_get_protocol (url), swfdec_url_get_host (url), 
+	      swfdec_url_get_port (url), "crossdomain.xml", NULL);
+	  swfdec_player_allow_or_load (player, url, load_url, func, data);
+	  swfdec_url_free (load_url);
+	}
+	break;
+      case SWFDEC_SANDBOX_LOCAL_FILE:
+	func (player, FALSE, data);
+	break;
+      case SWFDEC_SANDBOX_NONE:
+      default:
+	g_assert_not_reached ();
+	break;
+    }
+  }
+
+  swfdec_url_free (url);
+}
+
diff --git a/swfdec/swfdec_policy_file.h b/swfdec/swfdec_policy_file.h
index 337e236..74c3b5b 100644
--- a/swfdec/swfdec_policy_file.h
+++ b/swfdec/swfdec_policy_file.h
@@ -1,5 +1,5 @@
 /* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ * Copyright (C) 2007-2008 Benjamin Otte <otte at gnome.org>
  *               2007 Pekka Lampila <pekka.lampila at iki.fi>
  *
  * This library is free software; you can redistribute it and/or
commit 546c8b94608260deb70c95af63935550db817022
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 12 18:01:37 2008 +0200

    put sandbox definition into swfdec_types.h

diff --git a/swfdec/swfdec_sandbox.h b/swfdec/swfdec_sandbox.h
index fa5baca..f9332ea 100644
--- a/swfdec/swfdec_sandbox.h
+++ b/swfdec/swfdec_sandbox.h
@@ -23,10 +23,11 @@
 #include <swfdec/swfdec_as_object.h>
 #include <swfdec/swfdec_url.h>
 #include <swfdec/swfdec_player.h>
+#include <swfdec/swfdec_types.h>
 
 G_BEGIN_DECLS
 
-typedef struct _SwfdecSandbox SwfdecSandbox;
+//typedef struct _SwfdecSandbox SwfdecSandbox;
 typedef struct _SwfdecSandboxClass SwfdecSandboxClass;
 
 typedef enum {
diff --git a/swfdec/swfdec_types.h b/swfdec/swfdec_types.h
index 1beb94b..8b8848b 100644
--- a/swfdec/swfdec_types.h
+++ b/swfdec/swfdec_types.h
@@ -50,6 +50,7 @@ typedef struct _SwfdecShapeVec SwfdecShapeVec;
 typedef struct _SwfdecRect SwfdecRect;
 typedef struct _SwfdecResource SwfdecResource;
 typedef struct _SwfdecRootSprite SwfdecRootSprite;
+typedef struct _SwfdecSandbox SwfdecSandbox;
 typedef struct _SwfdecScriptable SwfdecScriptable;
 typedef struct _SwfdecSound SwfdecSound;
 typedef struct _SwfdecSoundChunk SwfdecSoundChunk;
commit ab164d28c797351b8c94fd4f09c070d97eb1fbb5
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Jun 12 09:52:22 2008 +0200

    rename header_count to n_headers
    
    I've made it a style decision back in the days to use n_foos instead of
    foo_count everywhere. Would be nice if you would do so, too. Otherwise
    I'll fix it. :)

diff --git a/swfdec-gtk/swfdec_gtk_loader.c b/swfdec-gtk/swfdec_gtk_loader.c
index b3b0f1f..a4214e7 100644
--- a/swfdec-gtk/swfdec_gtk_loader.c
+++ b/swfdec-gtk/swfdec_gtk_loader.c
@@ -133,7 +133,7 @@ swfdec_gtk_loader_dispose (GObject *object)
 
 static void
 swfdec_gtk_loader_load (SwfdecLoader *loader, SwfdecPlayer *player, 
-    const char *url_string, SwfdecBuffer *buffer, guint header_count,
+    const char *url_string, SwfdecBuffer *buffer, guint n_headers,
     const char **header_names, const char **header_values)
 {
   SwfdecURL *url;
@@ -152,7 +152,7 @@ swfdec_gtk_loader_load (SwfdecLoader *loader, SwfdecPlayer *player,
   if (!swfdec_url_has_protocol (url, "http") &&
       !swfdec_url_has_protocol (url, "https")) {
     SWFDEC_LOADER_CLASS (swfdec_gtk_loader_parent_class)->load (loader, player,
-	url_string, buffer, header_count, header_names, header_values);
+	url_string, buffer, n_headers, header_names, header_values);
   } else {
     SwfdecGtkLoader *gtk = SWFDEC_GTK_LOADER (loader);
     SwfdecGtkLoaderClass *klass = SWFDEC_GTK_LOADER_GET_CLASS (gtk);
@@ -161,7 +161,7 @@ swfdec_gtk_loader_load (SwfdecLoader *loader, SwfdecPlayer *player,
 	swfdec_url_get_url (url));
     soup_message_set_flags (gtk->message, SOUP_MESSAGE_OVERWRITE_CHUNKS);
 
-    for (i = 0; i < header_count; i++) {
+    for (i = 0; i < n_headers; i++) {
       soup_message_headers_append (gtk->message->request_headers,
 	  header_names[i], header_values[i]);
     }
diff --git a/swfdec/swfdec_loader.h b/swfdec/swfdec_loader.h
index b0e1b5e..d5e4cd2 100644
--- a/swfdec/swfdec_loader.h
+++ b/swfdec/swfdec_loader.h
@@ -68,7 +68,7 @@ struct _SwfdecLoaderClass
 					 SwfdecPlayer *			player,
 					 const char *			url,
 					 SwfdecBuffer *			buffer,
-					 guint				header_count,
+					 guint				n_headers,
 					 const char **			header_names,
 					 const char **			header_values);
 };


More information about the Swfdec-commits mailing list