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 var mlist = document.getElementById( "mosaic_list_content" );
138 while( mlist.hasChildNodes() )
139 mlist.removeChild( mlist.firstChild );
141 for( var name in streams )
143 var mrl = streams[name];
145 var minput = document.createElement( 'a' );
146 minput.setAttribute( 'href', 'javascript:mosaic_elt_select(\''+name+'\');');
147 minput.setAttribute( 'id', name );
148 minput.setAttribute( 'value', mrl );
149 minput.setAttribute( 'title', mrl );
151 var minputtxt = document.createTextNode( name );
153 minput.appendChild( minputtxt );
154 mlist.appendChild( minput );
155 mlist.appendChild( document.createElement( 'br' ) );
159 function mosaic_elt_select( id )
161 hide( 'mosaic_list' );
162 document.getElementById( document.getElementById( 'mosaic_list' ).value ).value = id;
163 cells[ document.getElementById( 'mosaic_list' ).value ] = id;
164 mosaic_code_update();
167 function mosaic_elt_choose( id )
169 document.getElementById( 'mosaic_list' ).value = id;
170 show( 'mosaic_list' );
173 function mosaic_code_update()
176 var code = document.getElementById( 'mosaic_code' );
178 "##################################\n"+
179 "## HTTP interface mosaic wizard ##\n"+
180 "##################################\n"+
182 "# Comment the following line if you don't want to reset you VLM configuration\n"+
185 "# Background options\n"+
186 "new bg broadcast enabled\n"+
187 "setup bg input " + value( 'mosaic_bg_input' ) + "\n";
188 if( value( 'mosaic_output' ) )
191 "setup bg output " + value( 'mosaic_output' )+ "\n";
193 var o = /.*transcode.*/;
194 if(! o.test( value( 'mosaic_output' ) ) )
197 "setup bg option sub-filter=mosaic\n";
201 "# Mosaic options\n"+
202 "setup bg option mosaic-alpha=" + mosaic_alpha + "\n"+
203 "setup bg option mosaic-height=" + mosaic_height + "\n"+
204 "setup bg option mosaic-width=" + mosaic_width + "\n"+
205 "setup bg option mosaic-align=" + mosaic_align + "\n"+
206 "setup bg option mosaic-xoffset=" + mosaic_xoffset + "\n"+
207 "setup bg option mosaic-yoffset=" + mosaic_yoffset + "\n"+
208 "setup bg option mosaic-vborder=" + mosaic_vborder + "\n"+
209 "setup bg option mosaic-hborder=" + mosaic_hborder + "\n"+
210 "setup bg option mosaic-position=" + mosaic_position + "\n"+
211 "setup bg option mosaic-rows=" + mosaic_rows + "\n"+
212 "setup bg option mosaic-cols=" + mosaic_cols + "\n"+
213 "setup bg option mosaic-order=";
214 for( y = 0; y < mosaic_rows; y++ )
216 for( x = 0; x < mosaic_cols; x++ )
220 code.value += cells[id];
223 if( y != mosaic_rows - 1 || x != mosaic_cols - 1 )
228 "setup bg option mosaic-delay=" + mosaic_delay + "\n"+
229 "setup bg option mosaic-keep-picture\n"+
233 for( y = 0; y < mosaic_rows; y++ )
235 for( x = 0; x < mosaic_cols; x++ )
242 "new " + s + " broadcast enabled\n"+
243 "setup " + s + " input " + streams[s] + "\n"+
244 "setup " + s + " output #duplicate{dst=mosaic-bridge{id=" + s + ",width="+cell_width+",height="+cell_height+"},select=video,dst=bridge-out,select=audio}\n"+
250 "# Launch everything\n"+
252 for( y = 0; y < mosaic_rows; y++ )
254 for( x = 0; x < mosaic_cols; x++ )
261 "control " + s + " play\n";
267 "# end of mosaic batch\n";
270 function mosaic_batch( batch )
273 var commands = batch.split( '\n' );
274 for( i = 0; i < commands.length; i++ )
276 mosaic_cmd( commands[i] );
280 function mosaic_cmd( cmd )
282 loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_mosaic_cmd );
285 function parse_mosaic_cmd()
290 function mosaic_stop()
293 cmd = "control bg stop\n";
295 for( y = 0; y < mosaic_rows; y++ )
297 for( x = 0; x < mosaic_cols; x++ )
303 cmd += "control " + s + " stop\n";