2
* Copyright (C) 2007-2008 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_sound_object.h"
26
#include "swfdec_as_context.h"
27
#include "swfdec_as_internal.h"
28
#include "swfdec_as_native_function.h"
29
#include "swfdec_as_object.h"
30
#include "swfdec_as_strings.h"
31
#include "swfdec_debug.h"
32
#include "swfdec_internal.h"
33
#include "swfdec_player_internal.h"
34
#include "swfdec_resource.h"
35
#include "swfdec_sound.h"
37
/*** SwfdecSoundObject ***/
39
G_DEFINE_TYPE (SwfdecSoundObject, swfdec_sound_object, SWFDEC_TYPE_AS_OBJECT)
42
swfdec_sound_object_mark (SwfdecGcObject *object)
44
SwfdecSoundObject *sound = SWFDEC_SOUND_OBJECT (object);
46
if (sound->target != NULL)
47
swfdec_as_string_mark (sound->target);
49
SWFDEC_GC_OBJECT_CLASS (swfdec_sound_object_parent_class)->mark (object);
53
swfdec_sound_object_dispose (GObject *object)
55
SwfdecSoundObject *sound = SWFDEC_SOUND_OBJECT (object);
57
if (sound->provider) {
58
g_object_unref (sound->provider);
59
sound->provider = NULL;
62
G_OBJECT_CLASS (swfdec_sound_object_parent_class)->dispose (object);
66
swfdec_sound_object_class_init (SwfdecSoundObjectClass *klass)
68
GObjectClass *object_class = G_OBJECT_CLASS (klass);
69
SwfdecGcObjectClass *gc_class = SWFDEC_GC_OBJECT_CLASS (klass);
71
object_class->dispose = swfdec_sound_object_dispose;
73
gc_class->mark = swfdec_sound_object_mark;
77
swfdec_sound_object_init (SwfdecSoundObject *sound)
82
swfdec_sound_object_get_actor (SwfdecSoundObject *sound)
84
SwfdecPlayer *player = SWFDEC_PLAYER (swfdec_gc_object_get_context (sound));
87
movie = swfdec_player_get_movie_from_string (player,
88
sound->target ? sound->target : "");
89
if (!SWFDEC_IS_ACTOR (movie))
91
return SWFDEC_ACTOR (movie);
95
swfdec_sound_object_get_sound (SwfdecSoundObject *sound, const char *name)
97
SwfdecActor *actor = swfdec_sound_object_get_actor (sound);
102
return swfdec_resource_get_export (SWFDEC_MOVIE (actor)->resource, name);
107
static SwfdecSoundMatrix *
108
swfdec_sound_object_get_matrix (SwfdecSoundObject *sound)
110
if (sound->provider) {
111
SwfdecSoundMatrix *ret = swfdec_sound_provider_get_matrix (sound->provider);
116
if (sound->target == NULL) {
117
return &SWFDEC_PLAYER (swfdec_gc_object_get_context (sound))->priv->sound_matrix;
119
SwfdecActor *actor = swfdec_sound_object_get_actor (sound);
121
return &actor->sound_matrix;
126
SWFDEC_AS_NATIVE (500, 0, swfdec_sound_object_getPan)
128
swfdec_sound_object_getPan (SwfdecAsContext *cx, SwfdecAsObject *object,
129
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
131
SwfdecSoundObject *sound;
132
const SwfdecSoundMatrix *matrix;
134
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "");
136
matrix = swfdec_sound_object_get_matrix (sound);
140
SWFDEC_AS_VALUE_SET_INT (ret, swfdec_sound_matrix_get_pan (matrix));
143
SWFDEC_AS_NATIVE (500, 1, swfdec_sound_object_getTransform)
145
swfdec_sound_object_getTransform (SwfdecAsContext *cx, SwfdecAsObject *object,
146
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
148
SwfdecSoundObject *sound;
149
const SwfdecSoundMatrix *matrix;
153
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "");
155
matrix = swfdec_sound_object_get_matrix (sound);
159
obj = swfdec_as_object_new (cx);
161
SWFDEC_AS_VALUE_SET_INT (&val, matrix->ll);
162
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_ll, &val);
163
SWFDEC_AS_VALUE_SET_INT (&val, matrix->lr);
164
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_lr, &val);
165
SWFDEC_AS_VALUE_SET_INT (&val, matrix->rl);
166
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_rl, &val);
167
SWFDEC_AS_VALUE_SET_INT (&val, matrix->rr);
168
swfdec_as_object_set_variable (obj, SWFDEC_AS_STR_rr, &val);
170
SWFDEC_AS_VALUE_SET_OBJECT (ret, obj);
173
SWFDEC_AS_NATIVE (500, 2, swfdec_sound_object_getVolume)
175
swfdec_sound_object_getVolume (SwfdecAsContext *cx, SwfdecAsObject *object,
176
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
178
SwfdecSoundObject *sound;
179
const SwfdecSoundMatrix *matrix;
181
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "");
183
matrix = swfdec_sound_object_get_matrix (sound);
187
SWFDEC_AS_VALUE_SET_INT (ret, matrix->volume);
190
SWFDEC_AS_NATIVE (500, 3, swfdec_sound_object_setPan)
192
swfdec_sound_object_setPan (SwfdecAsContext *cx, SwfdecAsObject *object,
193
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
195
SwfdecSoundObject *sound;
196
SwfdecSoundMatrix *matrix;
199
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "i", &pan);
201
matrix = swfdec_sound_object_get_matrix (sound);
205
swfdec_sound_matrix_set_pan (matrix, pan);
208
SWFDEC_AS_NATIVE (500, 4, swfdec_sound_object_setTransform)
210
swfdec_sound_object_setTransform (SwfdecAsContext *cx, SwfdecAsObject *object,
211
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
213
SwfdecSoundObject *sound;
214
SwfdecSoundMatrix *matrix;
215
SwfdecAsObject *trans;
218
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "o", &trans);
220
matrix = swfdec_sound_object_get_matrix (sound);
225
val = swfdec_as_object_peek_variable (trans, SWFDEC_AS_STR_ll);
227
matrix->ll = swfdec_as_value_to_integer (cx, val);
228
} else if (swfdec_as_object_has_variable (trans, SWFDEC_AS_STR_ll) == trans) {
232
val = swfdec_as_object_peek_variable (trans, SWFDEC_AS_STR_lr);
234
matrix->lr = swfdec_as_value_to_integer (cx, val);
235
} else if (swfdec_as_object_has_variable (trans, SWFDEC_AS_STR_lr) == trans) {
239
val = swfdec_as_object_peek_variable (trans, SWFDEC_AS_STR_rr);
241
matrix->rr = swfdec_as_value_to_integer (cx, val);
242
} else if (swfdec_as_object_has_variable (trans, SWFDEC_AS_STR_rr) == trans) {
246
val = swfdec_as_object_peek_variable (trans, SWFDEC_AS_STR_rl);
248
matrix->rl = swfdec_as_value_to_integer (cx, val);
249
} else if (swfdec_as_object_has_variable (trans, SWFDEC_AS_STR_rl) == trans) {
254
SWFDEC_AS_NATIVE (500, 5, swfdec_sound_object_setVolume)
256
swfdec_sound_object_setVolume (SwfdecAsContext *cx, SwfdecAsObject *object,
257
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
259
SwfdecSoundObject *sound;
260
SwfdecSoundMatrix *matrix;
263
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "i", &volume);
265
matrix = swfdec_sound_object_get_matrix (sound);
269
matrix->volume = volume;
272
SWFDEC_AS_NATIVE (500, 9, swfdec_sound_object_getDuration)
274
swfdec_sound_object_getDuration (SwfdecAsContext *cx, SwfdecAsObject *object,
275
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
277
SWFDEC_STUB ("Sound.getDuration");
280
SWFDEC_AS_NATIVE (500, 10, swfdec_sound_object_setDuration)
282
swfdec_sound_object_setDuration (SwfdecAsContext *cx, SwfdecAsObject *object,
283
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
285
SWFDEC_STUB ("Sound.setDuration");
288
SWFDEC_AS_NATIVE (500, 11, swfdec_sound_object_getPosition)
290
swfdec_sound_object_getPosition (SwfdecAsContext *cx, SwfdecAsObject *object,
291
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
293
SWFDEC_STUB ("Sound.getPosition");
296
SWFDEC_AS_NATIVE (500, 12, swfdec_sound_object_setPosition)
298
swfdec_sound_object_setPosition (SwfdecAsContext *cx, SwfdecAsObject *object,
299
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
301
SWFDEC_STUB ("Sound.setPosition");
304
SWFDEC_AS_NATIVE (500, 13, swfdec_sound_object_loadSound)
306
swfdec_sound_object_loadSound (SwfdecAsContext *cx, SwfdecAsObject *object,
307
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
309
SwfdecSoundObject *sound;
314
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "sb", &url, &stream);
315
actor = swfdec_sound_object_get_actor (sound);
320
g_object_unref (sound->provider);
321
sound->provider = SWFDEC_SOUND_PROVIDER (swfdec_load_sound_new (object, url));
323
swfdec_sound_provider_start (sound->provider, actor, 0, 1);
326
SWFDEC_AS_NATIVE (500, 14, swfdec_sound_object_getBytesLoaded)
328
swfdec_sound_object_getBytesLoaded (SwfdecAsContext *cx, SwfdecAsObject *object,
329
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
331
SWFDEC_STUB ("Sound.getBytesLoaded");
334
SWFDEC_AS_NATIVE (500, 15, swfdec_sound_object_getBytesTotal)
336
swfdec_sound_object_getBytesTotal (SwfdecAsContext *cx, SwfdecAsObject *object,
337
guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
339
SWFDEC_STUB ("Sound.getBytesTotal");
342
SWFDEC_AS_NATIVE (500, 18, swfdec_sound_object_get_checkPolicyFile)
344
swfdec_sound_object_get_checkPolicyFile (SwfdecAsContext *cx,
345
SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
348
SWFDEC_STUB ("Sound.checkPolicyFile (get)");
351
SWFDEC_AS_NATIVE (500, 19, swfdec_sound_object_set_checkPolicyFile)
353
swfdec_sound_object_set_checkPolicyFile (SwfdecAsContext *cx,
354
SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
357
SWFDEC_STUB ("Sound.checkPolicyFile (set)");
360
SWFDEC_AS_NATIVE (500, 16, swfdec_sound_object_areSoundsInaccessible)
362
swfdec_sound_object_areSoundsInaccessible (SwfdecAsContext *cx,
363
SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
366
SWFDEC_STUB ("Sound.areSoundsInaccessible");
369
SWFDEC_AS_NATIVE (500, 7, swfdec_sound_object_attachSound)
371
swfdec_sound_object_attachSound (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
372
SwfdecAsValue *argv, SwfdecAsValue *ret)
374
SwfdecSoundObject *sound;
378
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "s", &name);
380
new = swfdec_sound_object_get_sound (sound, name);
383
g_object_unref (sound->provider);
384
sound->provider = g_object_ref (new);
388
SWFDEC_AS_NATIVE (500, 8, swfdec_sound_object_start)
390
swfdec_sound_object_start (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
391
SwfdecAsValue *argv, SwfdecAsValue *ret)
393
SwfdecSoundObject *sound;
398
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "|ni", &offset, &loops);
399
actor = swfdec_sound_object_get_actor (sound);
403
if (sound->provider == NULL) {
404
SWFDEC_INFO ("no sound attached when calling Sound.start()");
409
if (offset < 0 || !isfinite (offset))
412
swfdec_sound_provider_start (sound->provider, actor, offset * 44100, loops);
415
SWFDEC_AS_NATIVE (500, 6, swfdec_sound_object_stop)
417
swfdec_sound_object_stop (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
418
SwfdecAsValue *argv, SwfdecAsValue *ret)
420
SwfdecSoundObject *sound;
421
const char *name = NULL;
425
SWFDEC_AS_CHECK (SWFDEC_TYPE_SOUND_OBJECT, &sound, "|s", &name);
426
actor = swfdec_sound_object_get_actor (sound);
431
stopme = swfdec_sound_object_get_sound (sound, name);
434
if (sound->provider == NULL || SWFDEC_IS_SOUND (sound->provider))
435
swfdec_sound_provider_stop (SWFDEC_SOUND_PROVIDER (stopme), actor);
436
} else if (sound->provider) {
437
swfdec_sound_provider_stop (sound->provider, actor);
441
SWFDEC_AS_CONSTRUCTOR (500, 16, swfdec_sound_object_construct, swfdec_sound_object_get_type)
443
swfdec_sound_object_construct (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
444
SwfdecAsValue *argv, SwfdecAsValue *ret)
446
SwfdecSoundObject *sound;
447
SwfdecPlayer *player;
449
if (!swfdec_as_context_is_constructing (cx))
452
sound = SWFDEC_SOUND_OBJECT (object);
453
player = SWFDEC_PLAYER (cx);
455
if (argc == 0 || SWFDEC_AS_VALUE_IS_UNDEFINED (&argv[0])) {
456
sound->target = NULL;
458
sound->target = swfdec_as_value_to_string (cx, &argv[0]);