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";
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 /* TODO: keep 'common' cells when resizing */
80 while( mlayout.hasChildNodes() )
81 mlayout.removeChild( mlayout.firstChild );
83 mlayout.style.width = bg_width + "px";
84 mlayout.style.height = bg_height + "px";
85 if( mosaic_cols && mosaic_rows )
87 var mdt = document.createElement( 'div' );
88 mdt.setAttribute( 'id', 'mosaic_dt' );
89 mdt.setAttribute( 'class', 'mosaic_tbl' );
91 mdt.style.width = mosaic_width + "px";
92 mdt.style.height = mosaic_height + "px";
93 mdt.style.top = mosaic_yoffset + "px";
94 mdt.style.left = mosaic_xoffset + "px";
96 var mtable = document.createElement( 'table' );
97 mtable.setAttribute( 'id', 'mosaic_table' );
98 mtable.style.top = "-" + mosaic_vborder + "px";
99 mtable.style.left = "-" + mosaic_hborder + "px";
100 mtable.style.width = (1*mosaic_width +2*mosaic_hborder) + "px";
101 mtable.style.height = (1*mosaic_height+2*mosaic_vborder) + "px";
102 mtable.style.borderSpacing = mosaic_hborder + "px " +
103 mosaic_vborder + "px";
105 for( y = 0; y < mosaic_rows; y++ )
107 var mrow = document.createElement( 'tr' );
108 for( x = 0; x < mosaic_cols; x++ )
110 var mcell = document.createElement( 'td' );
111 mcell.setAttribute( 'class', 'mosaic_itm' );
112 mcell.style.width = cell_width + "px";
113 mcell.style.height = cell_height + "px";
115 var melt = document.createElement( 'input' );
116 melt.setAttribute( 'type', 'button' );
118 melt.setAttribute( 'id', id );
119 melt.setAttribute( 'onclick', 'mosaic_elt_choose(\''+id+'\');' );
121 melt.setAttribute( 'value', cells[id] );
123 melt.setAttribute( 'value', '?' );
124 melt.setAttribute( 'title', 'Click to choose stream' );
126 mcell.appendChild( melt );
127 mrow.appendChild( mcell );
129 mtable.appendChild( mrow );
131 mdt.appendChild( mtable );
132 mlayout.appendChild( mdt );
134 mosaic_code_update();
137 function mosaic_add_input()
139 streams[ addunderscores( value('mosaic_input_name') ) ] =
140 value('mosaic_input');
142 mosaic_feedback( addunderscores( value('mosaic_input_name') ) + " ( " + value('mosaic_input') + " ) added to input list.", true );
144 var mlist = document.getElementById( "mosaic_list_content" );
145 while( mlist.hasChildNodes() )
146 mlist.removeChild( mlist.firstChild );
148 for( var name in streams )
150 var mrl = streams[name];
152 var minput = document.createElement( 'a' );
153 minput.setAttribute( 'href', 'javascript:mosaic_elt_select(\''+name+'\');');
154 minput.setAttribute( 'id', name );
155 minput.setAttribute( 'value', mrl );
157 var minputtxt = document.createTextNode( name );
159 minput.appendChild( minputtxt );
160 mlist.appendChild( minput );
161 mlist.appendChild( document.createTextNode( " ( "+mrl+" )" ) );
162 mlist.appendChild( document.createElement( 'br' ) );
166 function mosaic_elt_select( id )
168 hide( 'mosaic_list' );
169 var ml = document.getElementById( 'mosaic_list' ).value;
172 document.getElementById( ml ).value = id;
174 mosaic_code_update();
178 function mosaic_elt_choose( id )
180 document.getElementById( 'mosaic_list' ).value = id;
181 show( 'mosaic_list' );
184 function mosaic_code_update()
187 var code = document.getElementById( 'mosaic_code' );
189 "##################################\n"+
190 "## HTTP interface mosaic wizard ##\n"+
191 "##################################\n"+
193 "# Comment the following line if you don't want to reset your VLM configuration\n"+
196 "# Background options\n"+
197 "new bg broadcast enabled\n"+
198 "setup bg input " + value( 'mosaic_bg_input' ) + "\n";
199 if( value( 'mosaic_output' ) )
202 "setup bg output " + value( 'mosaic_output' )+ "\n";
204 var o = /.*transcode.*/;
205 if(! o.test( value( 'mosaic_output' ) ) )
208 "setup bg option sub-filter=mosaic\n";
212 "# Mosaic options\n"+
213 "setup bg option mosaic-alpha=" + mosaic_alpha + "\n"+
214 "setup bg option mosaic-height=" + mosaic_height + "\n"+
215 "setup bg option mosaic-width=" + mosaic_width + "\n"+
216 "setup bg option mosaic-align=" + mosaic_align + "\n"+
217 "setup bg option mosaic-xoffset=" + mosaic_xoffset + "\n"+
218 "setup bg option mosaic-yoffset=" + mosaic_yoffset + "\n"+
219 "setup bg option mosaic-vborder=" + mosaic_vborder + "\n"+
220 "setup bg option mosaic-hborder=" + mosaic_hborder + "\n"+
221 "setup bg option mosaic-position=" + mosaic_position + "\n"+
222 "setup bg option mosaic-rows=" + mosaic_rows + "\n"+
223 "setup bg option mosaic-cols=" + mosaic_cols + "\n"+
224 "setup bg option mosaic-order=";
225 for( y = 0; y < mosaic_rows; y++ )
227 for( x = 0; x < mosaic_cols; x++ )
231 code.value += cells[id];
234 if( y != mosaic_rows - 1 || x != mosaic_cols - 1 )
239 "setup bg option mosaic-delay=" + mosaic_delay + "\n"+
240 "setup bg option mosaic-keep-picture\n"+
244 for( y = 0; y < mosaic_rows; y++ )
246 for( x = 0; x < mosaic_cols; x++ )
253 "new " + s + " broadcast enabled\n"+
254 "setup " + s + " input " + streams[s] + "\n"+
255 "setup " + s + " output #duplicate{dst=mosaic-bridge{id=" + s + ",width="+cell_width+",height="+cell_height+"},select=video,dst=bridge-out,select=audio}\n"+
261 "# Launch everything\n"+
263 for( y = 0; y < mosaic_rows; y++ )
265 for( x = 0; x < mosaic_cols; x++ )
272 "control " + s + " play\n";
278 "# end of mosaic batch\n";
281 function mosaic_batch( batch )
284 var commands = batch.split( '\n' );
285 for( i = 0; i < commands.length; i++ )
287 mosaic_cmd( commands[i] );
291 function mosaic_cmd( cmd )
293 loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_mosaic_cmd );
296 function parse_mosaic_cmd()
301 function mosaic_stop()
304 cmd = "control bg stop\n";
306 for( y = 0; y < mosaic_rows; y++ )
308 for( x = 0; x < mosaic_cols; x++ )
314 cmd += "control " + s + " stop\n";
321 function mosaic_feedback( msg, ok )
323 var f = document.getElementById( "mosaic_feedback" );
324 while( f.hasChildNodes() )
325 f.removeChild( f.firstChild );
327 f.style.fontWeight = "bold";
329 f.style.color = "#0f0";
331 f.style.color = "#f00";
333 var t = document.createTextNode( ( ok ? "Info: " : "Error: " ) + msg );