2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
25 #include "swfdec_as_internal.h"
26 #include "swfdec_as_string.h"
27 #include "swfdec_as_strings.h"
28 #include "swfdec_audio_decoder.h"
29 #include "swfdec_debug.h"
30 #include "swfdec_player_internal.h"
32 SWFDEC_AS_NATIVE (1066, 0, swfdec_system_setClipboard
)
34 swfdec_system_setClipboard (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
35 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
37 SWFDEC_STUB ("System.setClipboard (static)");
40 SWFDEC_AS_NATIVE (2107, 0, swfdec_system_showSettings
)
42 swfdec_system_showSettings (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
43 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
45 SWFDEC_STUB ("System.showSettings (static)");
48 SWFDEC_AS_NATIVE (2107, 1, swfdec_system_get_exactSettings
)
50 swfdec_system_get_exactSettings (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
51 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
53 SWFDEC_STUB ("System.exactSettings (static, get)");
56 SWFDEC_AS_NATIVE (2107, 2, swfdec_system_set_exactSettings
)
58 swfdec_system_set_exactSettings (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
59 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
61 SWFDEC_STUB ("System.exactSettings (static, set)");
64 SWFDEC_AS_NATIVE (2107, 3, swfdec_system_get_useCodepage
)
66 swfdec_system_get_useCodepage (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
67 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
69 SWFDEC_STUB ("System.useCodepage (static, get)");
72 SWFDEC_AS_NATIVE (2107, 4, swfdec_system_set_useCodepage
)
74 swfdec_system_set_useCodepage (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
75 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*ret
)
77 SWFDEC_STUB ("System.useCodepage (static, set)");
81 swfdec_system_has_audio (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
83 /* FIXME: allow setting this? */
84 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, TRUE
);
88 swfdec_system_has_streaming_audio (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
90 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, TRUE
);
94 swfdec_system_has_streaming_video (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
96 /* FIXME: check if video decoders got compiled in? */
97 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, TRUE
);
101 swfdec_system_has_embedded_video (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
103 /* FIXME: what's this? */
104 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, TRUE
);
108 swfdec_system_has_mp3 (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
110 gboolean result
= swfdec_audio_decoder_prepare (SWFDEC_AUDIO_CODEC_MP3
,
111 swfdec_audio_format_new (44100, 2, TRUE
), NULL
);
113 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, result
);
117 swfdec_system_has_audio_encoder (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
119 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
123 swfdec_system_has_video_encoder (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
125 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
129 swfdec_system_has_accessibility (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
131 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
135 swfdec_system_has_printing (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
137 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
141 swfdec_system_has_screen_broadcast (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
143 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
147 swfdec_system_has_screen_playback (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
149 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
153 swfdec_system_is_debugger (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
155 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, player
->priv
->system
->debugger
);
159 swfdec_system_version (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
161 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_get_string (
162 SWFDEC_AS_CONTEXT (player
), player
->priv
->system
->version
));
166 swfdec_system_manufacturer (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
168 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_get_string (
169 SWFDEC_AS_CONTEXT (player
), player
->priv
->system
->manufacturer
));
173 swfdec_system_screen_width (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
175 SWFDEC_AS_VALUE_SET_INT (ret
, player
->priv
->system
->screen_width
);
179 swfdec_system_screen_height (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
181 SWFDEC_AS_VALUE_SET_INT (ret
, player
->priv
->system
->screen_height
);
185 swfdec_system_screen_dpi (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
187 SWFDEC_AS_VALUE_SET_INT (ret
, player
->priv
->system
->dpi
);
191 swfdec_system_screen_color (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
193 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_get_string (
194 SWFDEC_AS_CONTEXT (player
), player
->priv
->system
->color_mode
));
198 swfdec_system_screen_par (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
200 SWFDEC_AS_VALUE_SET_NUMBER (ret
, player
->priv
->system
->par
);
204 swfdec_system_os (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
206 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_get_string (
207 SWFDEC_AS_CONTEXT (player
), player
->priv
->system
->os
));
211 swfdec_system_language (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
213 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_get_string (
214 SWFDEC_AS_CONTEXT (player
), player
->priv
->system
->language
));
218 swfdec_system_has_ime (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
220 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
224 swfdec_system_player_type (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
226 SWFDEC_AS_VALUE_SET_STRING (ret
, swfdec_as_context_get_string (
227 SWFDEC_AS_CONTEXT (player
), player
->priv
->system
->player_type
));
231 swfdec_system_av_disabled (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
233 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
237 swfdec_system_local_file_disabled (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
239 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
243 swfdec_system_windowless_disabled (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
245 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
249 swfdec_system_has_tls (SwfdecPlayer
*player
, SwfdecAsValue
*ret
)
251 SWFDEC_AS_VALUE_SET_BOOLEAN (ret
, FALSE
);
254 /* NB: ordered for the query string order */
257 const char * server_string
;
258 void (* get
) (SwfdecPlayer
*player
, SwfdecAsValue
*ret
);
260 { SWFDEC_AS_STR_hasAudio
, "A", swfdec_system_has_audio
},
261 { SWFDEC_AS_STR_hasStreamingAudio
, "SA", swfdec_system_has_streaming_audio
},
262 { SWFDEC_AS_STR_hasStreamingVideo
, "SV", swfdec_system_has_streaming_video
},
263 { SWFDEC_AS_STR_hasEmbeddedVideo
, "EV", swfdec_system_has_embedded_video
},
264 { SWFDEC_AS_STR_hasMP3
, "MP3", swfdec_system_has_mp3
},
265 { SWFDEC_AS_STR_hasAudioEncoder
, "AE", swfdec_system_has_audio_encoder
},
266 { SWFDEC_AS_STR_hasVideoEncoder
, "VE", swfdec_system_has_video_encoder
},
267 { SWFDEC_AS_STR_hasAccessibility
, "ACC", swfdec_system_has_accessibility
},
268 { SWFDEC_AS_STR_hasPrinting
, "PR", swfdec_system_has_printing
},
269 { SWFDEC_AS_STR_hasScreenPlayback
, "SP", swfdec_system_has_screen_playback
},
270 { SWFDEC_AS_STR_hasScreenBroadcast
, "SB", swfdec_system_has_screen_broadcast
},
271 { SWFDEC_AS_STR_isDebugger
, "DEB", swfdec_system_is_debugger
},
272 { SWFDEC_AS_STR_version
, "V", swfdec_system_version
},
273 { SWFDEC_AS_STR_manufacturer
, NULL
, swfdec_system_manufacturer
},
274 { SWFDEC_AS_STR_screenResolutionX
, "R", swfdec_system_screen_width
},
275 { SWFDEC_AS_STR_screenResolutionY
, NULL
, swfdec_system_screen_height
},
276 { SWFDEC_AS_STR_screenDPI
, "DP", swfdec_system_screen_dpi
},
277 { SWFDEC_AS_STR_screenColor
, "COL", swfdec_system_screen_color
},
278 { SWFDEC_AS_STR_pixelAspectRatio
, NULL
, swfdec_system_screen_par
},
279 { SWFDEC_AS_STR_os
, "OS", swfdec_system_os
},
280 { SWFDEC_AS_STR_language
, "L", swfdec_system_language
},
281 { SWFDEC_AS_STR_hasIME
, "IME", swfdec_system_has_ime
},
282 { SWFDEC_AS_STR_playerType
, "PT", swfdec_system_player_type
},
283 { SWFDEC_AS_STR_avHardwareDisable
, "AVD", swfdec_system_av_disabled
},
284 { SWFDEC_AS_STR_localFileReadDisable
, "LFD", swfdec_system_local_file_disabled
},
285 { SWFDEC_AS_STR_windowlessDisable
, "WD", swfdec_system_windowless_disabled
},
286 { SWFDEC_AS_STR_hasTLS
, "TLS", swfdec_system_has_tls
},
289 SWFDEC_AS_NATIVE (11, 0, swfdec_system_query
)
291 swfdec_system_query (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
292 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*retval
)
294 SwfdecPlayer
*player
= SWFDEC_PLAYER (cx
);
299 if (object
== NULL
) {
300 SWFDEC_WARNING ("no this object in Query()");
304 server
= g_string_new ("");
305 for (i
= 0; i
< G_N_ELEMENTS (queries
); i
++) {
306 queries
[i
].get (player
, &val
);
307 swfdec_as_object_set_variable (object
, queries
[i
].name
, &val
);
308 if (queries
[i
].name
== SWFDEC_AS_STR_screenResolutionY
) {
309 g_string_append_printf (server
, "x%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val
));
310 } else if (queries
[i
].name
== SWFDEC_AS_STR_pixelAspectRatio
) {
312 g_ascii_formatd (buffer
, sizeof (buffer
), "%.1f",
313 SWFDEC_AS_VALUE_GET_NUMBER (&val
));
314 g_string_append (server
, "&AR=");
315 g_string_append (server
, buffer
);
316 } else if (queries
[i
].name
== SWFDEC_AS_STR_manufacturer
) {
317 char *s
= swfdec_as_string_escape (cx
, player
->priv
->system
->server_manufacturer
);
318 g_string_append_printf (server
, "&M=%s", s
);
321 g_assert (queries
[i
].server_string
);
323 g_string_append_c (server
, '&');
324 g_string_append (server
, queries
[i
].server_string
);
325 g_string_append_c (server
, '=');
326 if (SWFDEC_AS_VALUE_IS_BOOLEAN (&val
)) {
327 g_string_append_c (server
, SWFDEC_AS_VALUE_GET_BOOLEAN (&val
) ? 't' : 'f');
328 } else if (SWFDEC_AS_VALUE_IS_NUMBER (&val
)) {
329 g_string_append_printf (server
, "%d", (int) SWFDEC_AS_VALUE_GET_NUMBER (&val
));
330 } else if (SWFDEC_AS_VALUE_IS_STRING (&val
)) {
331 char *s
= swfdec_as_string_escape (cx
, SWFDEC_AS_VALUE_GET_STRING (&val
));
332 g_string_append (server
, s
);
335 g_assert_not_reached ();
339 SWFDEC_AS_VALUE_SET_STRING (&val
, swfdec_as_context_give_string (cx
, g_string_free (server
, FALSE
)));
340 swfdec_as_object_set_variable (object
, SWFDEC_AS_STR_serverString
, &val
);