1 /*****************************************************************************
2 * mosaic.js: VLC media player web interface - Mosaic specific functions
3 *****************************************************************************
4 * Copyright (C) 2005-2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
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.
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.
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 *****************************************************************************/
24 /**********************************************************************
26 *********************************************************************/
28 var mosaic_alpha = 255;
29 var mosaic_height = 0;
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;
44 var streams = Object();
47 function mosaic_init()
49 document.getElementById( 'sout_transcode_extra' ).value = ",sfilter=mosaic}:bridge-in{offset=100";
52 /* Force usage of transcode in sout */
53 document.getElementById( 'sout_vcodec_s' ).checked = 'checked';
54 disable( 'sout_vcodec_s' );
58 function mosaic_size_change()
62 var bg_width = check_and_replace_int( "bg_width", "400" );
63 var bg_height = check_and_replace_int( "bg_height", "300" );
65 mosaic_height = check_and_replace_int( "mosaic_height", "100" );
66 mosaic_width = check_and_replace_int( "mosaic_width", "100" );
67 mosaic_xoffset = check_and_replace_int( "mosaic_xoffset", "10" );
68 mosaic_yoffset = check_and_replace_int( "mosaic_yoffset", "10" );
69 mosaic_vborder = check_and_replace_int( "mosaic_vborder", "5" );
70 mosaic_hborder = check_and_replace_int( "mosaic_hborder", "10" );
71 mosaic_rows = check_and_replace_int( "mosaic_rows", "1" );
72 mosaic_cols = check_and_replace_int( "mosaic_cols", "1" );
74 cell_width = Math.floor((mosaic_width-(mosaic_cols-1)*mosaic_hborder)/mosaic_cols);
75 cell_height = Math.floor((mosaic_height-(mosaic_rows-1)*mosaic_vborder)/mosaic_rows);
77 var mlayout = document.getElementById( "mosaic_layout" );
79 while( mlayout.hasChildNodes() )
80 mlayout.removeChild( mlayout.firstChild );
82 mlayout.style.width = bg_width + "px";
83 mlayout.style.height = bg_height + "px";
84 if( mosaic_cols && mosaic_rows )
86 var mdt = document.createElement( 'div' );
87 mdt.setAttribute( 'id', 'mosaic_dt' );
88 setclass( mdt, 'mosaic_tbl' );
90 mdt.style.width = mosaic_width + "px";
91 mdt.style.height = mosaic_height + "px";
92 mdt.style.top = mosaic_yoffset + "px";
93 mdt.style.left = mosaic_xoffset + "px";
95 var mtable = document.createElement( 'table' );
96 mtable.setAttribute( 'id', 'mosaic_table' );
97 mtable.style.top = "-" + mosaic_vborder + "px";
98 mtable.style.left = "-" + mosaic_hborder + "px";
99 mtable.style.width = (1*mosaic_width +2*mosaic_hborder) + "px";
100 mtable.style.height = (1*mosaic_height+2*mosaic_vborder) + "px";
101 mtable.style.borderSpacing = mosaic_hborder + "px " +
102 mosaic_vborder + "px";
104 var mtbody = document.createElement( 'tbody' );
106 for( y = 0; y < mosaic_rows; y++ )
108 var mrow = document.createElement( 'tr' );
109 for( x = 0; x < mosaic_cols; x++ )
111 var mcell = document.createElement( 'td' );
112 setclass( mcell, 'mosaic_itm' );
113 mcell.style.width = cell_width + "px";
114 mcell.style.height = cell_height + "px";
117 var melt = create_button( cells[id] ? cells[id] : '?', 'mosaic_elt_choose(\"'+id+'\");' );
118 melt.setAttribute( 'id', id );
119 melt.setAttribute( 'title', 'Click to choose stream' );
121 mcell.appendChild( melt );
122 mrow.appendChild( mcell );
124 mtbody.appendChild( mrow );
126 mtable.appendChild( mtbody );
127 mdt.appendChild( mtable );
128 mlayout.appendChild( mdt );
130 mosaic_code_update();
133 function mosaic_add_input()
135 streams[ addunderscores( value('mosaic_input_name') ) ] =
136 value('mosaic_input');
138 mosaic_feedback( addunderscores( value('mosaic_input_name') ) + " ( " + value('mosaic_input') + " ) added to input list.", true );
140 var mlist = document.getElementById( "mosaic_list_content" );
141 while( mlist.hasChildNodes() )
142 mlist.removeChild( mlist.firstChild );
144 for( var name in streams )
146 var mrl = streams[name];
148 var minput = document.createElement( 'a' );
149 minput.setAttribute( 'href', 'javascript:mosaic_elt_select(\''+name+'\');');
150 minput.setAttribute( 'id', name );
151 minput.setAttribute( 'value', mrl );
153 var minputtxt = document.createTextNode( name );
155 minput.appendChild( minputtxt );
156 mlist.appendChild( minput );
157 mlist.appendChild( document.createTextNode( " ( "+mrl+" )" ) );
158 mlist.appendChild( document.createElement( 'br' ) );
162 function mosaic_elt_select( id )
164 hide( 'mosaic_list' );
165 var ml = document.getElementById( 'mosaic_list' ).value;
168 document.getElementById( ml ).value = id;
170 mosaic_code_update();
174 function mosaic_elt_choose( id )
176 document.getElementById( 'mosaic_list' ).value = id;
177 show( 'mosaic_list' );
180 function mosaic_code_update()
183 var code = document.getElementById( 'mosaic_code' );
185 "##################################\n"+
186 "## HTTP interface mosaic wizard ##\n"+
187 "##################################\n"+
189 "# Comment the following line if you don't want to reset your VLM configuration\n"+
192 "# Background options\n"+
193 "new bg broadcast enabled\n"+
194 "setup bg input " + sanitize_input( value( 'mosaic_bg_input' ) ) + "\n";
195 if( value( 'mosaic_output' ) )
198 "setup bg output " + value( 'mosaic_output' )+ "\n";
200 var o = /.*transcode.*/;
201 if(! o.test( value( 'mosaic_output' ) ) )
204 "setup bg option sub-filter=mosaic\n"+
205 "setup bg output #bridge-in{offset=100}:display\n";
209 "# Mosaic options\n"+
210 "setup bg option mosaic-alpha=" + mosaic_alpha + "\n"+
211 "setup bg option mosaic-height=" + mosaic_height + "\n"+
212 "setup bg option mosaic-width=" + mosaic_width + "\n"+
213 "setup bg option mosaic-align=" + mosaic_align + "\n"+
214 "setup bg option mosaic-xoffset=" + mosaic_xoffset + "\n"+
215 "setup bg option mosaic-yoffset=" + mosaic_yoffset + "\n"+
216 "setup bg option mosaic-vborder=" + mosaic_vborder + "\n"+
217 "setup bg option mosaic-hborder=" + mosaic_hborder + "\n"+
218 "setup bg option mosaic-position=" + mosaic_position + "\n"+
219 "setup bg option mosaic-rows=" + mosaic_rows + "\n"+
220 "setup bg option mosaic-cols=" + mosaic_cols + "\n"+
221 "setup bg option mosaic-order=";
222 for( y = 0; y < mosaic_rows; y++ )
224 for( x = 0; x < mosaic_cols; x++ )
228 code.value += cells[id];
231 if( y != mosaic_rows - 1 || x != mosaic_cols - 1 )
236 "setup bg option mosaic-delay=" + mosaic_delay + "\n"+
237 "setup bg option mosaic-keep-picture\n"+
241 for( y = 0; y < mosaic_rows; y++ )
243 for( x = 0; x < mosaic_cols; x++ )
250 "new " + s + " broadcast enabled\n"+
251 "setup " + s + " input " + sanitize_input( streams[s] ) + "\n"+
252 "setup " + s + " output #duplicate{dst=mosaic-bridge{id=" + s + ",width="+cell_width+",height="+cell_height+"},select=video,dst=bridge-out{id="+(y*mosaic_cols+x)+"},select=audio}\n"+
258 "# Launch everything\n"+
260 for( y = 0; y < mosaic_rows; y++ )
262 for( x = 0; x < mosaic_cols; x++ )
269 "control " + s + " play\n";
275 "# end of mosaic batch\n";
278 function mosaic_batch( batch )
281 var commands = batch.split( '\n' );
282 for( i = 0; i < commands.length; i++ )
284 mosaic_cmd( commands[i] );
288 function mosaic_cmd( cmd )
290 loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_mosaic_cmd );
293 function parse_mosaic_cmd()
298 function mosaic_stop()
301 cmd = "control bg stop\n";
303 for( y = 0; y < mosaic_rows; y++ )
305 for( x = 0; x < mosaic_cols; x++ )
311 cmd += "control " + s + " stop\n";
318 function mosaic_feedback( msg, ok )
320 var f = document.getElementById( "mosaic_feedback" );
321 while( f.hasChildNodes() )
322 f.removeChild( f.firstChild );
324 f.style.fontWeight = "bold";
326 f.style.color = "#0f0";
328 f.style.color = "#f00";
330 var t = document.createTextNode( ( ok ? "Info: " : "Error: " ) + msg );