]> git.sesse.net Git - vlc/blob - share/http/js/mosaic.js
Spelling fix, again.
[vlc] / share / http / js / mosaic.js
1 /*****************************************************************************
2  * mosaic.js: VLC media player web interface - Mosaic specific functions
3  *****************************************************************************
4  * Copyright (C) 2005-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /**********************************************************************
25  * 
26  *********************************************************************/
27
28 var mosaic_alpha    = 255;
29 var mosaic_height   = 0;
30 var mosaic_width    = 0;
31 var mosaic_align    = 5;
32 var mosaic_xoffset  = 0;
33 var mosaic_yoffset  = 0;
34 var mosaic_vborder  = 0;
35 var mosaic_hborder  = 0;
36 var mosaic_position = 1;
37 var mosaic_rows     = 0;
38 var mosaic_cols     = 0;
39 var mosaic_delay    = 0;
40
41 var cell_width  = 0;
42 var cell_height = 0;
43
44 var streams = Object;
45 var cells   = Object;
46
47 function mosaic_init()
48 {
49     document.getElementById( 'sout_extra' ).value = ",sfilter=mosaic";
50     mosaic_size_change();
51 }
52
53 function mosaic_size_change()
54 {
55     var x,y;
56
57     var bg_width    = check_and_replace_int( "bg_width", "400" );
58     var bg_height   = check_and_replace_int( "bg_height", "300" );
59
60     mosaic_height   = check_and_replace_int( "mosaic_height", "100" );
61     mosaic_width    = check_and_replace_int( "mosaic_width", "100" );
62     mosaic_xoffset  = check_and_replace_int( "mosaic_xoffset", "10" );
63     mosaic_yoffset  = check_and_replace_int( "mosaic_yoffset", "10" );
64     mosaic_vborder  = check_and_replace_int( "mosaic_vborder", "5" );
65     mosaic_hborder  = check_and_replace_int( "mosaic_hborder", "10" );
66     mosaic_rows     = check_and_replace_int( "mosaic_rows", "1" );
67     mosaic_cols     = check_and_replace_int( "mosaic_cols", "1" );
68     
69     cell_width  = Math.floor((mosaic_width-(mosaic_cols-1)*mosaic_hborder)/mosaic_cols);
70     cell_height = Math.floor((mosaic_height-(mosaic_rows-1)*mosaic_vborder)/mosaic_rows);
71     
72     var mlayout = document.getElementById( "mosaic_layout" );
73
74     /* TODO: keep 'common' cells when resizing */
75     while( mlayout.hasChildNodes() )
76         mlayout.removeChild( mlayout.firstChild );
77
78     mlayout.style.width = bg_width + "px";
79     mlayout.style.height = bg_height + "px";
80     if( mosaic_cols && mosaic_rows )
81     {
82         var mdt = document.createElement( 'div' );
83         mdt.setAttribute( 'id',    'mosaic_dt'  );
84         mdt.setAttribute( 'class', 'mosaic_tbl' );
85         
86         mdt.style.width  = mosaic_width   + "px";
87         mdt.style.height = mosaic_height  + "px";
88         mdt.style.top    = mosaic_yoffset + "px";
89         mdt.style.left   = mosaic_xoffset + "px";
90
91         var mtable = document.createElement( 'table' );
92         mtable.setAttribute( 'id', 'mosaic_table' );
93         mtable.style.top    = "-" + mosaic_vborder + "px";
94         mtable.style.left   = "-" + mosaic_hborder + "px";
95         mtable.style.width  = (1*mosaic_width +2*mosaic_hborder)  + "px";
96         mtable.style.height = (1*mosaic_height+2*mosaic_vborder) + "px";
97         mtable.style.borderSpacing = mosaic_hborder + "px " +
98                                      mosaic_vborder + "px";
99
100         for( y = 0; y < mosaic_rows; y++ )
101         {
102             var mrow = document.createElement( 'tr' );
103             for( x = 0; x < mosaic_cols; x++ )
104             {
105                 var mcell = document.createElement( 'td' );
106                 mcell.setAttribute( 'class', 'mosaic_itm' );
107                 mcell.style.width  = cell_width  + "px";
108                 mcell.style.height = cell_height + "px";
109                 
110                 var melt = document.createElement( 'input' );
111                 melt.setAttribute( 'type', 'button' );
112                 var id = x+'_'+y;
113                 melt.setAttribute( 'id', id );
114                 melt.setAttribute( 'onclick', 'mosaic_elt_choose(\''+id+'\');' );
115                 if( cells[id] )
116                     melt.setAttribute( 'value', cells[id] );
117                 else
118                     melt.setAttribute( 'value', '?' );
119                 melt.setAttribute( 'title', 'Click to choose stream' );
120                 
121                 mcell.appendChild( melt );
122                 mrow.appendChild( mcell );
123             }
124             mtable.appendChild( mrow );
125         }
126         mdt.appendChild( mtable );
127         mlayout.appendChild( mdt );
128     }
129     mosaic_code_update();
130 }
131
132 function mosaic_add_input()
133 {
134     streams[ addunderscores( value('mosaic_input_name') ) ] =
135         value('mosaic_input');
136
137     mosaic_feedback( addunderscores( value('mosaic_input_name') ) + " ( " + value('mosaic_input') + " ) added to input list.", true );
138
139     var mlist = document.getElementById( "mosaic_list_content" );
140     while( mlist.hasChildNodes() )
141         mlist.removeChild( mlist.firstChild );
142     
143     for( var name in streams )
144     {
145         var mrl = streams[name];
146         
147         var minput = document.createElement( 'a' );
148         minput.setAttribute( 'href', 'javascript:mosaic_elt_select(\''+name+'\');');
149         minput.setAttribute( 'id', name );
150         minput.setAttribute( 'value', mrl );
151         
152         var minputtxt = document.createTextNode( name );
153
154         minput.appendChild( minputtxt );
155         mlist.appendChild( minput );
156         mlist.appendChild( document.createTextNode( " ( "+mrl+" )" ) );
157         mlist.appendChild( document.createElement( 'br' ) );
158     }
159 }
160
161 function mosaic_elt_select( id )
162 {
163     hide( 'mosaic_list' );
164     var ml = document.getElementById( 'mosaic_list' ).value;
165     if( ml )
166     {
167         document.getElementById( ml ).value = id;
168         cells[ ml ] = id;
169         mosaic_code_update();
170     }
171 }
172
173 function mosaic_elt_choose( id )
174 {
175     document.getElementById( 'mosaic_list' ).value = id;
176     show( 'mosaic_list' );
177 }
178
179 function mosaic_code_update()
180 {
181
182     var code = document.getElementById( 'mosaic_code' );
183     code.value =
184 "##################################\n"+
185 "## HTTP interface mosaic wizard ##\n"+
186 "##################################\n"+
187 "\n"+
188 "# Comment the following line if you don't want to reset your VLM configuration\n"+
189 "del all\n"+
190 "\n"+
191 "# Background options\n"+
192 "new   bg broadcast enabled\n"+
193 "setup bg input     " + value( 'mosaic_bg_input' ) + "\n";
194     if( value( 'mosaic_output' ) )
195     {
196         code.value +=
197 "setup bg output    " + value( 'mosaic_output' )+ "\n";
198     }
199     var o = /.*transcode.*/;
200     if(! o.test( value( 'mosaic_output' ) ) )
201     {
202         code.value +=
203 "setup bg option    sub-filter=mosaic\n";
204     }
205     code.value+=
206 "\n"+
207 "# Mosaic options\n"+
208 "setup bg option mosaic-alpha="    + mosaic_alpha    + "\n"+
209 "setup bg option mosaic-height="   + mosaic_height   + "\n"+
210 "setup bg option mosaic-width="    + mosaic_width    + "\n"+
211 "setup bg option mosaic-align="    + mosaic_align    + "\n"+
212 "setup bg option mosaic-xoffset="  + mosaic_xoffset  + "\n"+
213 "setup bg option mosaic-yoffset="  + mosaic_yoffset  + "\n"+
214 "setup bg option mosaic-vborder="  + mosaic_vborder  + "\n"+
215 "setup bg option mosaic-hborder="  + mosaic_hborder  + "\n"+
216 "setup bg option mosaic-position=" + mosaic_position + "\n"+
217 "setup bg option mosaic-rows="     + mosaic_rows     + "\n"+
218 "setup bg option mosaic-cols="     + mosaic_cols     + "\n"+
219 "setup bg option mosaic-order=";
220     for( y = 0; y < mosaic_rows; y++ )
221     {
222         for( x = 0; x < mosaic_cols; x++ )
223         {
224             var id = x+'_'+y;
225             if( cells[id] )
226                 code.value += cells[id];
227             else
228                 code.value += '_';
229             if( y != mosaic_rows - 1 || x != mosaic_cols - 1 )
230                 code.value += ',';
231         }
232     }
233     code.value += "\n"+
234 "setup bg option mosaic-delay="    + mosaic_delay    + "\n"+
235 "setup bg option mosaic-keep-picture\n"+
236 "\n"+
237 "# Input options\n";
238     var x, y;
239     for( y = 0; y < mosaic_rows; y++ )
240     {
241         for( x = 0; x < mosaic_cols; x++ )
242         {
243             var id = x+'_'+y;
244             if( cells[id] )
245             {
246                 var s = cells[id];
247                 code.value +=
248 "new   " + s + " broadcast enabled\n"+
249 "setup " + s + " input     " + streams[s] + "\n"+
250 "setup " + s + " output #duplicate{dst=mosaic-bridge{id=" + s + ",width="+cell_width+",height="+cell_height+"},select=video,dst=bridge-out,select=audio}\n"+
251 "\n";
252             }
253         }
254     }
255     code.value +=
256 "# Launch everything\n"+
257 "control bg play\n";
258     for( y = 0; y < mosaic_rows; y++ )
259     {
260         for( x = 0; x < mosaic_cols; x++ )
261         {
262             var id = x+'_'+y;
263             if( cells[id] )
264             {
265                 var s = cells[id];
266                 code.value +=
267 "control " + s + " play\n";
268             }
269         }
270     }
271     code.value +=
272 "\n"+
273 "# end of mosaic batch\n";
274 }
275
276 function mosaic_batch( batch )
277 {
278     var i;
279     var commands = batch.split( '\n' );
280     for( i = 0; i < commands.length; i++ )
281     {
282         mosaic_cmd( commands[i] );
283     }
284 }
285
286 function mosaic_cmd( cmd )
287 {
288     loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_mosaic_cmd );
289 }
290
291 function parse_mosaic_cmd()
292 {
293     /* TODO */
294 }
295
296 function mosaic_stop()
297 {
298     var cmd;
299     cmd = "control bg stop\n";
300     var x,y;
301     for( y = 0; y < mosaic_rows; y++ )
302     {
303         for( x = 0; x < mosaic_cols; x++ )
304         {
305             var id = x+'_'+y;
306             if( cells[id] )
307             {
308                 var s = cells[id];
309                 cmd += "control " + s + " stop\n";
310             }
311         }
312     }
313     mosaic_batch( cmd );
314 }
315
316 function mosaic_feedback( msg, ok )
317 {
318     var f = document.getElementById( "mosaic_feedback" );
319     while( f.hasChildNodes() )
320         f.removeChild( f.firstChild );
321
322     f.style.fontWeight = "bold";
323     if( ok )
324         f.style.color = "#0f0";
325     else
326         f.style.color = "#f00";
327
328     var t = document.createTextNode( ( ok ? "Info: " : "Error: " ) + msg );
329     f.appendChild( t );
330
331 }