[Swfdec] 6 commits - doc/Makefile.am doc/swfdec-sections.txt libswfdec-gtk/swfdec_gtk_player.c libswfdec/swfdec_as_context.c libswfdec/swfdec_as_context.h libswfdec/swfdec_as_internal.h libswfdec/swfdec_player.c libswfdec/swfdec_player.h libswfdec/swfdec_player_internal.h

Benjamin Otte company at kemper.freedesktop.org
Mon Oct 22 02:01:04 PDT 2007


 doc/Makefile.am                    |    2 -
 doc/swfdec-sections.txt            |    2 +
 libswfdec-gtk/swfdec_gtk_player.c  |    3 +
 libswfdec/swfdec_as_context.c      |   31 +++++++++++++++
 libswfdec/swfdec_as_context.h      |    2 +
 libswfdec/swfdec_as_internal.h     |    1 
 libswfdec/swfdec_player.c          |   74 ++++++++++++++++++++++++++++++++++++-
 libswfdec/swfdec_player.h          |    5 ++
 libswfdec/swfdec_player_internal.h |    2 +
 9 files changed, 119 insertions(+), 3 deletions(-)

New commits:
commit 4fc6b0380faaf8f309d3c06a7bfb6f947d0f65f0
Merge: 6b0c5c2... a2bb0d9...
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 11:00:50 2007 +0200

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec/swfdec

commit 6b0c5c201736b69a65111c9614e547f6abd6723a
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 10:57:15 2007 +0200

    implement max-runtime and make it really work

diff --git a/libswfdec-gtk/swfdec_gtk_player.c b/libswfdec-gtk/swfdec_gtk_player.c
index 55db10a..60e7ded 100644
--- a/libswfdec-gtk/swfdec_gtk_player.c
+++ b/libswfdec-gtk/swfdec_gtk_player.c
@@ -174,7 +174,7 @@ swfdec_gtk_player_new (SwfdecAsDebugger *debugger)
 
   swfdec_init ();
   player = g_object_new (SWFDEC_TYPE_GTK_PLAYER, "debugger", debugger, 
-      "max-runtime", 10 * 1000, NULL);
+      "max-runtime", (gulong) 10 * 1000, NULL);
 
   return player;
 }
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 3ed0d5a..749ee31 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1219,6 +1219,7 @@ swfdec_player_lock_soft (SwfdecPlayer *player)
   g_assert (swfdec_rectangle_is_empty (&player->invalid_extents));
 
   g_object_freeze_notify (G_OBJECT (player));
+  g_timer_start (player->runtime);
   SWFDEC_DEBUG ("LOCKED");
 }
 
@@ -1239,6 +1240,7 @@ swfdec_player_unlock_soft (SwfdecPlayer *player)
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
 
   SWFDEC_DEBUG ("UNLOCK");
+  g_timer_stop (player->runtime);
   swfdec_player_update_mouse_cursor (player);
   g_object_thaw_notify (G_OBJECT (player));
   swfdec_player_emit_signals (player);
@@ -1307,7 +1309,7 @@ swfdec_player_check_continue (SwfdecAsContext *context)
 
   if (player->max_runtime == 0)
     return TRUE;
-  return g_timer_elapsed (player->runtime, NULL) * 1000 > player->max_runtime;
+  return g_timer_elapsed (player->runtime, NULL) * 1000 <= player->max_runtime;
 }
 
 static void
@@ -2499,7 +2501,9 @@ swfdec_player_get_maximum_runtime (SwfdecPlayer *player)
  * a later point in time. However, your application may become unresponsive and
  * your users annoyed if they cannot interact with it for too long. To give a 
  * reference point, the Adobe Flash player usually sets this value to 10 
- * seconds.
+ * seconds. Note that this time determines the maximum time calling 
+ * swfdec_player_advance() may take, even if it is called with a large value.
+ * Also note that this setting is ignored when running inside a debugger.
  **/
 void
 swfdec_player_set_maximum_runtime (SwfdecPlayer *player, gulong msecs)
commit cda0f0a3da0c3ba15f51ec57872c5bd69cb88085
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 00:03:29 2007 +0200

    Set the max runtime in the gtk player to 10 seconds.

diff --git a/libswfdec-gtk/swfdec_gtk_player.c b/libswfdec-gtk/swfdec_gtk_player.c
index 485f708..55db10a 100644
--- a/libswfdec-gtk/swfdec_gtk_player.c
+++ b/libswfdec-gtk/swfdec_gtk_player.c
@@ -173,7 +173,8 @@ swfdec_gtk_player_new (SwfdecAsDebugger *debugger)
   SwfdecPlayer *player;
 
   swfdec_init ();
-  player = g_object_new (SWFDEC_TYPE_GTK_PLAYER, "debugger", debugger, NULL);
+  player = g_object_new (SWFDEC_TYPE_GTK_PLAYER, "debugger", debugger, 
+      "max-runtime", 10 * 1000, NULL);
 
   return player;
 }
commit e97010394013386d4ca909312499a96fbcb3c39c
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 00:02:43 2007 +0200

    add max-runtime property and getter/setter functions
    
    This sets the maximum time a player may run before aborting.
    It's not used yet.

diff --git a/doc/swfdec-sections.txt b/doc/swfdec-sections.txt
index b3b4425..e423b7a 100644
--- a/doc/swfdec-sections.txt
+++ b/doc/swfdec-sections.txt
@@ -97,6 +97,8 @@ swfdec_player_key_press
 swfdec_player_key_release
 swfdec_player_render_audio
 swfdec_player_get_audio
+swfdec_player_get_maximum_runtime
+swfdec_player_set_maximum_runtime
 <SUBSECTION Standard>
 SwfdecPlayerClass
 SWFDEC_PLAYER
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index a726b3b..3ed0d5a 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -546,7 +546,8 @@ enum {
   PROP_HEIGHT,
   PROP_ALIGNMENT,
   PROP_SCALE,
-  PROP_SYSTEM
+  PROP_SYSTEM,
+  PROP_MAX_RUNTIME
 };
 
 G_DEFINE_TYPE (SwfdecPlayer, swfdec_player, SWFDEC_TYPE_AS_CONTEXT)
@@ -642,6 +643,9 @@ swfdec_player_get_property (GObject *object, guint param_id, GValue *value,
     case PROP_SYSTEM:
       g_value_set_object (value, player->system);
       break;
+    case PROP_MAX_RUNTIME:
+      g_value_set_ulong (value, player->max_runtime);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -751,6 +755,9 @@ swfdec_player_set_property (GObject *object, guint param_id, const GValue *value
 	player->system = swfdec_system_new ();
       }
       break;
+    case PROP_MAX_RUNTIME:
+      swfdec_player_set_maximum_runtime (player, g_value_get_ulong (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -811,6 +818,10 @@ swfdec_player_dispose (GObject *object)
   }
   g_array_free (player->invalidations, TRUE);
   player->invalidations = NULL;
+  if (player->runtime) {
+    g_timer_destroy (player->runtime);
+    player->runtime = NULL;
+  }
 }
 
 static void
@@ -1289,6 +1300,16 @@ swfdec_player_get_time (SwfdecAsContext *context, GTimeVal *tv)
   g_time_val_add (tv, SWFDEC_TICKS_TO_MSECS (SWFDEC_PLAYER (context)->time) * 1000);
 }
 
+static gboolean
+swfdec_player_check_continue (SwfdecAsContext *context)
+{
+  SwfdecPlayer *player = SWFDEC_PLAYER (context);
+
+  if (player->max_runtime == 0)
+    return TRUE;
+  return g_timer_elapsed (player->runtime, NULL) * 1000 > player->max_runtime;
+}
+
 static void
 swfdec_player_class_init (SwfdecPlayerClass *klass)
 {
@@ -1329,6 +1350,9 @@ swfdec_player_class_init (SwfdecPlayerClass *klass)
   g_object_class_install_property (object_class, PROP_SCALE,
       g_param_spec_object ("system", "system", "object holding system information",
 	  SWFDEC_TYPE_SYSTEM, G_PARAM_READWRITE));
+  g_object_class_install_property (object_class, PROP_MAX_RUNTIME,
+      g_param_spec_ulong ("max-runtime", "maximum runtime", "maximum time in msecs scripts may run in the player before aborting",
+	  0, G_MAXULONG, 0, G_PARAM_READWRITE));
 
   /**
    * SwfdecPlayer::invalidate:
@@ -1471,6 +1495,7 @@ swfdec_player_class_init (SwfdecPlayerClass *klass)
 
   context_class->mark = swfdec_player_mark;
   context_class->get_time = swfdec_player_get_time;
+  context_class->check_continue = swfdec_player_check_continue;
 
   klass->advance = swfdec_player_do_advance;
   klass->handle_key = swfdec_player_do_handle_key;
@@ -1488,6 +1513,7 @@ swfdec_player_init (SwfdecPlayer *player)
   player->cache = swfdec_cache_new (50 * 1024 * 1024); /* 100 MB */
   player->bgcolor = SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF);
 
+  player->runtime = g_timer_new ();
   player->invalidations = g_array_new (FALSE, FALSE, sizeof (SwfdecRectangle));
   player->mouse_visible = TRUE;
   player->mouse_cursor = SWFDEC_MOUSE_CURSOR_NORMAL;
@@ -2434,6 +2460,8 @@ swfdec_player_set_alignment (SwfdecPlayer *player, SwfdecAlignment align)
 void
 swfdec_player_set_align_flags (SwfdecPlayer *player, guint flags)
 {
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
   if (flags != player->align_flags) {
     player->align_flags = flags;
     swfdec_player_update_scale (player);
@@ -2441,3 +2469,43 @@ swfdec_player_set_align_flags (SwfdecPlayer *player, guint flags)
   }
 }
 
+/**
+ * swfdec_player_get_maximum_runtime:
+ * @player: a #SwfdecPlayer
+ *
+ * Queries the given @player for how long scripts may run. see 
+ * swfdec_player_set_maximum_runtime() for a longer discussion of this value.
+ *
+ * Returns: the maximum time in milliseconds that scripts are allowed to run or
+ *          0 for infinite.
+ **/
+gulong
+swfdec_player_get_maximum_runtime (SwfdecPlayer *player)
+{
+  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), 0);
+
+  return player->max_runtime;
+}
+
+/**
+ * swfdec_player_set_maximum_runtime:
+ * @player: a #SwfdecPlayer
+ * @msecs: time in milliseconds that scripts are allowed to run or 0 for 
+ *         infinite
+ *
+ * Sets the time that the player may use to let internal scripts run. If the 
+ * Flash file that is currently played back does not manage to complete its 
+ * scripts in the given time, it is aborted. You cannot continue the scripts at
+ * a later point in time. However, your application may become unresponsive and
+ * your users annoyed if they cannot interact with it for too long. To give a 
+ * reference point, the Adobe Flash player usually sets this value to 10 
+ * seconds.
+ **/
+void
+swfdec_player_set_maximum_runtime (SwfdecPlayer *player, gulong msecs)
+{
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
+  player->max_runtime = msecs;
+  g_object_notify (G_OBJECT (player), "max-runtime");
+}
diff --git a/libswfdec/swfdec_player.h b/libswfdec/swfdec_player.h
index 357bb54..6a0bb2b 100644
--- a/libswfdec/swfdec_player.h
+++ b/libswfdec/swfdec_player.h
@@ -99,6 +99,11 @@ void		swfdec_player_set_scale_mode	(SwfdecPlayer *		player,
 SwfdecAlignment	swfdec_player_get_alignment	(SwfdecPlayer *		player);
 void		swfdec_player_set_alignment	(SwfdecPlayer *		player,
 						 SwfdecAlignment	align);
+gulong		swfdec_player_get_maximum_runtime
+						(SwfdecPlayer *	player);
+void		swfdec_player_set_maximum_runtime 
+						(SwfdecPlayer *	player,
+						 gulong		msecs);
 					 
 void		swfdec_player_render		(SwfdecPlayer *	player,
 						 cairo_t *	cr,
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index 483d487..301587c 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -116,6 +116,8 @@ struct _SwfdecPlayer
   GList *		timeouts;	      	/* list of events, sorted by timestamp */
   guint			tick;			/* next tick */
   SwfdecTimeout		iterate_timeout;      	/* callback for iterating */
+  GTimer *		runtime;		/* for checking how long we've been running */
+  gulong		max_runtime;		/* maximum number of seconds the player may run */
   /* iterating */
   GList *		movies;			/* list of all moveis that want to be iterated */
   SwfdecRingBuffer *	actions;		/* all actions we've queued up so far */
commit 427256b6ab471f447034232e2883ec8ff35b2a08
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Oct 22 00:00:32 2007 +0200

    it's called swfdec_resource.h these days

diff --git a/doc/Makefile.am b/doc/Makefile.am
index 68cc5ac..5f441f8 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -112,6 +112,7 @@ IGNORE_HFILES= \
 	swfdec_pattern.h \
 	swfdec_player_internal.h \
 	swfdec_rect.h \
+	swfdec_resource.h \
 	swfdec_ringbuffer.h \
 	swfdec_root_movie.h \
 	swfdec_root_sprite.h \
@@ -128,7 +129,6 @@ IGNORE_HFILES= \
 	swfdec_stroke.h \
 	swfdec_style_sheet.h \
 	swfdec_swf_decoder.h \
-	swfdec_swf_instance.h \
 	swfdec_tag.h \
 	swfdec_text.h \
 	swfdec_text_format.h \
commit 0c67e418df972f4329e69f05c7556a0654ed8c64
Author: Benjamin Otte <otte at gnome.org>
Date:   Sun Oct 21 23:37:50 2007 +0200

    add framework for doing runtime checks

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index dd276fc..07eb2fd 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -732,6 +732,8 @@ swfdec_as_context_run (SwfdecAsContext *context)
   context->last_frame = context->frame->next;
   original_version = context->version;
 start:
+  if (!swfdec_as_context_check_continue (context))
+    goto error;
   /* setup data */
   frame = context->frame;
   if (frame == context->last_frame)
@@ -892,6 +894,10 @@ start:
       frame->pc = pc = nextpc;
       check_block = TRUE;
     } else {
+      if (frame->pc < pc &&
+	  !swfdec_as_context_check_continue (context)) {
+	goto error;
+      }
       pc = frame->pc;
       check_block = FALSE;
     }
@@ -1339,3 +1345,28 @@ swfdec_as_context_startup (SwfdecAsContext *context, guint version)
     context->state = SWFDEC_AS_CONTEXT_RUNNING;
 }
 
+/**
+ * swfdec_as_context_check_continue:
+ * @context: the context that might be running too long
+ *
+ * Checks if the context has been running too long. If it has, it gets aborted.
+ *
+ * Returns: %TRUE if this player aborted.
+ **/
+gboolean
+swfdec_as_context_check_continue (SwfdecAsContext *context)
+{
+  SwfdecAsContextClass *klass;
+
+  g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), TRUE);
+
+  klass = SWFDEC_AS_CONTEXT_GET_CLASS (context);
+  if (klass->check_continue == NULL)
+    return TRUE;
+  if (!klass->check_continue (context)) {
+    swfdec_as_context_abort (context, "Runtime exceeded");
+    return FALSE;
+  }
+  return TRUE;
+}
+
diff --git a/libswfdec/swfdec_as_context.h b/libswfdec/swfdec_as_context.h
index e04b3e0..73feae4 100644
--- a/libswfdec/swfdec_as_context.h
+++ b/libswfdec/swfdec_as_context.h
@@ -88,6 +88,8 @@ struct _SwfdecAsContextClass {
   /* overwrite if you want to report a different time than gettimeofday */
   void			(* get_time)		(SwfdecAsContext *      context,
 						 GTimeVal *		tv);
+  /* overwrite if you want to abort on infinite loops */
+  gboolean		(* check_continue)	(SwfdecAsContext *	context);
 };
 
 GType		swfdec_as_context_get_type	(void);
diff --git a/libswfdec/swfdec_as_internal.h b/libswfdec/swfdec_as_internal.h
index ee49ef2..98cb9ee 100644
--- a/libswfdec/swfdec_as_internal.h
+++ b/libswfdec/swfdec_as_internal.h
@@ -41,6 +41,7 @@ void		swfdec_as_function_init_context (SwfdecAsContext *	context,
 						 guint			version);
 
 /* swfdec_as_context.c */
+gboolean	swfdec_as_context_check_continue (SwfdecAsContext *	context);
 void		swfdec_as_context_run_init_script (SwfdecAsContext *	context,
 						 const guint8 *		data,
 						 gsize			length,


More information about the Swfdec mailing list