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 <swfdec/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>"
65 // catch asserts and don't spew debug output by default
66 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
| G_LOG_LEVEL_CRITICAL
| G_LOG_LEVEL_WARNING
);
67 g_setenv ("SWFDEC_DEBUG", "0", FALSE
);
72 // read command line params
73 context
= g_option_context_new ("Run a Flash file trying to crash Swfdec");
74 g_option_context_add_main_entries (context
, entries
, NULL
);
76 if (g_option_context_parse (context
, &argc
, &argv
, &err
) == FALSE
) {
77 g_printerr ("Couldn't parse command-line options: %s\n", err
->message
);
82 if (filenames
== NULL
|| g_strv_length (filenames
) < 1) {
83 g_printerr ("At least one input filename is required\n");
87 // make them milliseconds
88 play_per_file
*= 1000;
90 max_per_advance
*= 1000;
93 surface
= cairo_image_surface_create (CAIRO_FORMAT_ARGB32
, 1, 1);
94 cr
= cairo_create (surface
);
97 for (i
= 0; i
< g_strv_length (filenames
); i
++)
99 glong played
, advance
, elapsed
;
101 g_print ("Running: %s\n", filenames
[i
]);
104 timer
= g_timer_new ();
106 player
= swfdec_player_new (NULL
);
107 url
= swfdec_url_new_from_input (filenames
[i
]);
108 swfdec_player_set_url (player
, url
);
109 swfdec_url_free (url
);
111 // loop until we have played what we wanted, or timelimit is hit
114 while (played
< play_per_file
&&
115 !swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player
)))
117 elapsed
= (glong
)(g_timer_elapsed (timer
, NULL
) * 1000);
118 if (elapsed
>= max_per_file
)
120 swfdec_player_set_maximum_runtime (player
,
121 MIN (max_per_advance
, max_per_file
- elapsed
));
123 advance
= swfdec_player_get_next_event (player
);
126 played
+= swfdec_player_advance (player
, advance
);
128 swfdec_player_render (player
, cr
);
131 if (elapsed
>= max_per_file
||
132 swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player
))) {
133 g_print ("*** Aborted ***\n");
138 g_object_unref (player
);
139 g_timer_destroy (timer
);
143 cairo_surface_destroy (surface
);