2 * Copyright (C) 2007 Pekka Lampila <pekka.lampila@iki.fi>
3 * 2007 Benjamin Otte <otte@gnome.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
25 #include <libswfdec/swfdec.h>
28 main (int argc
, char **argv
)
30 GOptionContext
*context
;
35 cairo_surface_t
*surface
;
38 glong play_per_file
= 30;
39 glong max_per_file
= 60;
40 glong max_per_advance
= 10;
42 char **filenames
= NULL
;
43 const GOptionEntry entries
[] = {
45 "play-time", 'p', 0, G_OPTION_ARG_INT
, &play_per_file
,
46 "How many seconds will be played from each file (default 30)", NULL
49 "max-per-file", '\0', 0, G_OPTION_ARG_INT
, &max_per_file
,
50 "Maximum runtime in seconds allowed for each file (default 60)", NULL
53 "max-per-advance", '\0', 0, G_OPTION_ARG_INT
, &max_per_advance
,
54 "Maximum runtime in seconds allowed for each advance (default 10)", NULL
57 G_OPTION_REMAINING
, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY
, &filenames
,
58 NULL
, "<INPUT FILE> <OUTPUT FILE>"
68 // read command line params
69 context
= g_option_context_new ("Run a Flash file trying to crash Swfdec");
70 g_option_context_add_main_entries (context
, entries
, NULL
);
72 if (g_option_context_parse (context
, &argc
, &argv
, &err
) == FALSE
) {
73 g_printerr ("Couldn't parse command-line options: %s\n", err
->message
);
78 if (filenames
== NULL
|| g_strv_length (filenames
) < 1) {
79 g_printerr ("At least one input filename is required\n");
83 // make them milliseconds
84 play_per_file
*= 1000;
86 max_per_advance
*= 1000;
89 surface
= cairo_image_surface_create (CAIRO_FORMAT_ARGB32
, 1, 1);
90 cr
= cairo_create (surface
);
93 for (i
= 0; i
< g_strv_length (filenames
); i
++)
95 glong played
, advance
, elapsed
;
97 g_print ("Running: %s\n", filenames
[i
]);
100 timer
= g_timer_new ();
103 loader
= swfdec_file_loader_new (filenames
[i
]);
104 player
= swfdec_player_new (NULL
);
107 g_printerr ("Error loading %s: %s\n", filenames
[i
], loader
->error
);
108 g_object_unref (loader
);
112 swfdec_player_set_loader (player
, loader
);
114 // loop until we have played what we wanted, or timelimit is hit
117 while (played
< play_per_file
&&
118 !swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player
)))
120 elapsed
= (glong
)(g_timer_elapsed (timer
, NULL
) * 1000);
121 if (elapsed
>= max_per_file
)
123 swfdec_player_set_maximum_runtime (player
,
124 MIN (max_per_advance
, max_per_file
- elapsed
));
126 advance
= swfdec_player_get_next_event (player
);
129 swfdec_player_advance (player
, advance
);
131 swfdec_player_render (player
, cr
, 0, 0, 0, 0);
136 if (elapsed
>= max_per_file
||
137 swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player
))) {
138 g_print ("Aborted: %s\n", filenames
[i
]);
141 g_print ("Finished: %s\n", filenames
[i
]);
145 g_object_unref (player
);
146 g_timer_destroy (timer
);
150 cairo_surface_destroy (surface
);