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;
47 function mosaic_init()
49 document.getElementById( 'sout_extra' ).value = ",sfilter=mosaic";
53 function mosaic_size_change()
57 var bg_width = check_and_replace_int( "bg_width", "400" );
58 var bg_height = check_and_replace_int( "bg_height", "300" );
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" );
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);
72 var mlayout = document.getElementById( "mosaic_layout" );
74 /* TODO: keep 'common' cells when resizing */
75 while( mlayout.hasChildNodes() )
76 mlayout.removeChild( mlayout.firstChild );
78 mlayout.style.width = bg_width + "px";
79 mlayout.style.height = bg_height + "px";
80 if( mosaic_cols && mosaic_rows )
82 var mdt = document.createElement( 'div' );
83 mdt.setAttribute( 'id', 'mosaic_dt' );
84 mdt.setAttribute( 'class', 'mosaic_tbl' );
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";
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";
100 for( y = 0; y < mosaic_rows; y++ )
102 var mrow = document.createElement( 'tr' );
103 for( x = 0; x < mosaic_cols; x++ )
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";
110 var melt = document.createElement( 'input' );
111 melt.setAttribute( 'type', 'button' );
113 melt.setAttribute( 'id', id );
114 melt.setAttribute( 'onclick', 'mosaic_elt_choose(\''+id+'\');' );
116 melt.setAttribute( 'value', cells[id] );
118 melt.setAttribute( 'value', '?' );
119 melt.setAttribute( 'title', 'Click to choose stream' );
121 mcell.appendChild( melt );
122 mrow.appendChild( mcell );
124 mtable.appendChild( mrow );
126 mdt.appendChild( mtable );
127 mlayout.appendChild( mdt );
129 mosaic_code_update();
132 function mosaic_add_input()
134 streams[ addunderscores( value('mosaic_input_name') ) ] =
135 value('mosaic_input');
137 mosaic_feedback( addunderscores( value('mosaic_input_name') ) + " ( " + value('mosaic_input') + " ) added to input list.", true );
139 var mlist = document.getElementById( "mosaic_list_content" );
140 while( mlist.hasChildNodes() )
141 mlist.removeChild( mlist.firstChild );
143 for( var name in streams )
145 var mrl = streams[name];
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 );
152 var minputtxt = document.createTextNode( name );
154 minput.appendChild( minputtxt );
155 mlist.appendChild( minput );
156 mlist.appendChild( document.createTextNode( " ( "+mrl+" )" ) );
157 mlist.appendChild( document.createElement( 'br' ) );
161 function mosaic_elt_select( id )
163 hide( 'mosaic_list' );
164 var ml = document.getElementById( 'mosaic_list' ).value;
167 document.getElementById( ml ).value = id;
169 mosaic_code_update();
173 function mosaic_elt_choose( id )
175 document.getElementById( 'mosaic_list' ).value = id;
176 show( 'mosaic_list' );
179 function mosaic_code_update()
182 var code = document.getElementById( 'mosaic_code' );
184 "##################################\n"+
185 "## HTTP interface mosaic wizard ##\n"+
186 "##################################\n"+
188 "# Comment the following line if you don't want to reset you VLM configuration\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' ) )
197 "setup bg output " + value( 'mosaic_output' )+ "\n";
199 var o = /.*transcode.*/;
200 if(! o.test( value( 'mosaic_output' ) ) )
203 "setup bg option sub-filter=mosaic\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++ )
222 for( x = 0; x < mosaic_cols; x++ )
226 code.value += cells[id];
229 if( y != mosaic_rows - 1 || x != mosaic_cols - 1 )
234 "setup bg option mosaic-delay=" + mosaic_delay + "\n"+
235 "setup bg option mosaic-keep-picture\n"+
239 for( y = 0; y < mosaic_rows; y++ )
241 for( x = 0; x < mosaic_cols; x++ )
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"+
256 "# Launch everything\n"+
258 for( y = 0; y < mosaic_rows; y++ )
260 for( x = 0; x < mosaic_cols; x++ )
267 "control " + s + " play\n";
273 "# end of mosaic batch\n";
276 function mosaic_batch( batch )
279 var commands = batch.split( '\n' );
280 for( i = 0; i < commands.length; i++ )
282 mosaic_cmd( commands[i] );
286 function mosaic_cmd( cmd )
288 loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_mosaic_cmd );
291 function parse_mosaic_cmd()
296 function mosaic_stop()
299 cmd = "control bg stop\n";
301 for( y = 0; y < mosaic_rows; y++ )
303 for( x = 0; x < mosaic_cols; x++ )
309 cmd += "control " + s + " stop\n";
316 function mosaic_feedback( msg, ok )
318 var f = document.getElementById( "mosaic_feedback" );
319 while( f.hasChildNodes() )
320 f.removeChild( f.firstChild );
322 f.style.fontWeight = "bold";
324 f.style.color = "#0f0";
326 f.style.color = "#f00";
328 var t = document.createTextNode( ( ok ? "Info: " : "Error: " ) + msg );