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
24 #include "swfdec_net_stream.h"
25 #include "swfdec_as_context.h"
26 #include "swfdec_as_native_function.h"
27 #include "swfdec_as_strings.h"
28 #include "swfdec_debug.h"
29 #include "swfdec_internal.h"
30 #include "swfdec_player_internal.h"
33 swfdec_net_stream_close (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
, guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
35 SwfdecNetStream
*stream
= SWFDEC_NET_STREAM (obj
);
37 swfdec_net_stream_set_loader (stream
, NULL
);
38 swfdec_net_stream_set_playing (stream
, TRUE
);
42 swfdec_net_stream_play (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
, guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
44 SwfdecNetStream
*stream
= SWFDEC_NET_STREAM (obj
);
47 url
= swfdec_as_value_to_string (cx
, &argv
[0]);
48 swfdec_net_stream_set_url (stream
, url
);
49 swfdec_net_stream_set_playing (stream
, TRUE
);
53 swfdec_net_stream_pause (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
, guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
55 SwfdecNetStream
*stream
= SWFDEC_NET_STREAM (obj
);
59 playing
= !swfdec_net_stream_get_playing (stream
);
61 playing
= !swfdec_as_value_to_boolean (cx
, &argv
[0]);
63 SWFDEC_LOG ("%s stream %p", playing
? "playing" : "pausing", stream
);
64 swfdec_net_stream_set_playing (stream
, playing
);
68 swfdec_net_stream_setBufferTime (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
, guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
70 SwfdecNetStream
*stream
= SWFDEC_NET_STREAM (obj
);
73 d
= swfdec_as_value_to_number (cx
, &argv
[0]);
74 swfdec_net_stream_set_buffer_time (stream
, d
);
78 swfdec_net_stream_do_seek (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
, guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
80 SwfdecNetStream
*stream
= SWFDEC_NET_STREAM (obj
);
83 d
= swfdec_as_value_to_number (cx
, &argv
[0]);
84 swfdec_net_stream_seek (stream
, d
);
88 swfdec_net_stream_construct (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
, guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
90 SwfdecNetStream
*stream
= SWFDEC_NET_STREAM (obj
);
91 SwfdecNetConnection
*conn
;
93 if (!swfdec_as_context_is_constructing (cx
)) {
94 SWFDEC_FIXME ("What do we do if not constructing?");
97 if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv
[0]) ||
98 !SWFDEC_IS_NET_CONNECTION ((conn
= (SwfdecNetConnection
*) SWFDEC_AS_VALUE_GET_OBJECT (&argv
[0])))) {
99 SWFDEC_WARNING ("no connection passed to NetStream ()");
106 swfdec_net_stream_init_context (SwfdecPlayer
*player
, guint version
)
108 SwfdecAsContext
*context
;
109 SwfdecAsObject
*stream
, *proto
;
112 g_return_if_fail (SWFDEC_IS_PLAYER (player
));
114 context
= SWFDEC_AS_CONTEXT (player
);
115 proto
= swfdec_as_object_new_empty (context
);
118 stream
= SWFDEC_AS_OBJECT (swfdec_as_object_add_constructor (context
->global
,
119 SWFDEC_AS_STR_NetStream
, SWFDEC_TYPE_NET_STREAM
, SWFDEC_TYPE_NET_STREAM
,
120 swfdec_net_stream_construct
, 1, proto
));
123 /* set the right properties on the NetStream.prototype object */
124 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_pause
, SWFDEC_TYPE_NET_STREAM
,
125 swfdec_net_stream_pause
, 0);
126 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_play
, SWFDEC_TYPE_NET_STREAM
,
127 swfdec_net_stream_play
, 1);
128 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_close
, SWFDEC_TYPE_NET_STREAM
,
129 swfdec_net_stream_close
, 0);
130 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_seek
, SWFDEC_TYPE_NET_STREAM
,
131 swfdec_net_stream_do_seek
, 1);
132 swfdec_as_object_add_function (proto
, SWFDEC_AS_STR_setBufferTime
, SWFDEC_TYPE_NET_STREAM
,
133 swfdec_net_stream_setBufferTime
, 1);
134 SWFDEC_AS_VALUE_SET_OBJECT (&val
, stream
);
135 swfdec_as_object_set_variable_and_flags (proto
, SWFDEC_AS_STR_constructor
,
136 &val
, SWFDEC_AS_VARIABLE_HIDDEN
| SWFDEC_AS_VARIABLE_PERMANENT
);
137 SWFDEC_AS_VALUE_SET_OBJECT (&val
, context
->Object_prototype
);
138 swfdec_as_object_set_variable_and_flags (proto
, SWFDEC_AS_STR___proto__
, &val
,
139 SWFDEC_AS_VARIABLE_HIDDEN
| SWFDEC_AS_VARIABLE_PERMANENT
);