qt: Fix Icecast mrl generation
[vlc.git] / modules / gui / qt / components / sout / sout_widgets.cpp
blob19b54f55a7fe323a832efe28182c29d36fdf649c
1 /*****************************************************************************
2 * sout_widgets.cpp : Widgets for stream output destination boxes
3 ****************************************************************************
4 * Copyright (C) 2007-2009 the VideoLAN team
5 * Copyright (C) 2007 Société des arts technologiques
6 * Copyright (C) 2007 Savoir-faire Linux
7 * $Id$
9 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
10 * Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #include "components/sout/sout_widgets.hpp"
28 #include "dialogs/sout.hpp"
29 #include "util/qt_dirs.hpp"
30 #include <vlc_intf_strings.h>
32 #include <QGroupBox>
33 #include <QGridLayout>
34 #include <QLabel>
35 #include <QLineEdit>
36 #include <QFileDialog>
37 #include <QUrl>
39 #define I_FILE_SLASH_DIR \
40 I_DIR_OR_FOLDER( N_("File/Directory"), N_("File/Folder") )
42 SoutInputBox::SoutInputBox( QWidget *_parent, const QString& mrl ) : QGroupBox( _parent )
44 /**
45 * Source Block
46 **/
47 setTitle( qtr( "Source" ) );
48 QGridLayout *sourceLayout = new QGridLayout( this );
50 QLabel *sourceLabel = new QLabel( qtr( "Source:" ) );
51 sourceLayout->addWidget( sourceLabel, 0, 0 );
53 sourceLine = new QLineEdit;
54 sourceLine->setReadOnly( true );
55 sourceLine->setText( mrl );
56 sourceLabel->setBuddy( sourceLine );
57 sourceLayout->addWidget( sourceLine, 0, 1 );
59 QLabel *sourceTypeLabel = new QLabel( qtr( "Type:" ) );
60 sourceLayout->addWidget( sourceTypeLabel, 1, 0 );
61 sourceValueLabel = new QLabel;
62 sourceLayout->addWidget( sourceValueLabel, 1, 1 );
64 /* Line */
65 QFrame *line = new QFrame;
66 line->setFrameStyle( QFrame::HLine |QFrame::Sunken );
67 sourceLayout->addWidget( line, 2, 0, 1, -1 );
70 void SoutInputBox::setMRL( const QString& mrl )
72 QUrl uri( mrl );
73 QString type = uri.scheme();
75 if( !uri.isValid() &&
76 !mrl.startsWith("http") &&
77 !mrl.startsWith("ftp") &&
78 !mrl.startsWith("/") )
80 int pos = mrl.indexOf("://");
81 if( pos != -1 )
83 sourceValueLabel->setText( mrl.left( pos ) );
84 sourceLine->setText( mrl );
87 else if ( type == "window" )
89 /* QUrl mangles X11 Window identifiers so use the raw mrl */
90 sourceLine->setText( mrl );
92 else
94 sourceLine->setText(
95 toNativeSeparators(uri.toDisplayString(
96 QUrl::RemovePassword | QUrl::PreferLocalFile | QUrl::NormalizePathSegments
97 )));
98 if ( type.isEmpty() ) type = qtr( I_FILE_SLASH_DIR );
99 sourceValueLabel->setText( type );
103 #define CT( x ) connect( x, SIGNAL(textChanged(QString)), this, SIGNAL(mrlUpdated()) );
104 #define CS( x ) connect( x, SIGNAL(valueChanged(int)), this, SIGNAL(mrlUpdated()) );
106 VirtualDestBox::VirtualDestBox( QWidget *_parent ) : QWidget( _parent )
108 label = new QLabel( this );
109 label->setWordWrap( true );
110 layout = new QGridLayout( this );
111 layout->addWidget( label, 0, 0, 1, -1);
114 VirtualDestBox::~VirtualDestBox()
116 delete label;
117 delete layout;
120 /* FileDest Box */
121 FileDestBox::FileDestBox( QWidget *_parent, intf_thread_t * _p_intf ) : VirtualDestBox( _parent )
123 p_intf = _p_intf;
125 QPushButton *fileSelectButton;
127 label->setText( qtr( "This module writes the transcoded stream to a file.") );
129 QLabel *fileLabel = new QLabel( qtr( "Filename"), this );
130 layout->addWidget(fileLabel, 1, 0, 1, 1);
132 fileEdit = new QLineEdit(this);
133 layout->addWidget(fileEdit, 1, 4, 1, 1);
135 fileSelectButton = new QPushButton( qtr( "Browse..." ), this );
136 QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
137 fileSelectButton->setSizePolicy(sizePolicy);
139 layout->addWidget(fileSelectButton, 1, 5, 1, 1);
140 CT( fileEdit );
141 BUTTONACT( fileSelectButton, fileBrowse() );
144 QString FileDestBox::getMRL( const QString& mux )
146 if( fileEdit->text().isEmpty() ) return "";
148 SoutMrl m;
149 m.begin( "file" );
150 QString outputfile = fileEdit->text();
151 if( !mux.isEmpty() )
153 if( outputfile.contains( QRegExp("\\..{2,4}$")) &&
154 !outputfile.endsWith(mux) )
156 /* Replace the extension according to muxer */
157 outputfile.replace(QRegExp("\\..{2,4}$"),"."+mux);
158 } else if (!outputfile.endsWith( mux ) )
160 m.option( "mux", mux );
163 m.option( "dst", outputfile );
164 m.option( "no-overwrite" );
165 m.end();
167 return m.getMrl();
170 void FileDestBox::fileBrowse()
172 QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
173 p_intf->p_sys->filepath, qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ) );
174 fileEdit->setText( toNativeSeparators( fileName ) );
175 emit mrlUpdated();
180 HTTPDestBox::HTTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
182 label->setText( qtr( "This module outputs the transcoded stream to a network via HTTP.") );
184 QLabel *HTTPLabel = new QLabel( qtr("Path"), this );
185 QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
186 layout->addWidget(HTTPLabel, 2, 0, 1, 1);
187 layout->addWidget(HTTPPortLabel, 1, 0, 1, 1);
189 HTTPEdit = new QLineEdit(this);
190 HTTPEdit->setText( "/" );
192 HTTPPort = new QSpinBox(this);
193 HTTPPort->setMaximumSize(QSize(90, 16777215));
194 HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
195 HTTPPort->setMinimum(1);
196 HTTPPort->setMaximum(65535);
197 HTTPPort->setValue(8080);
199 layout->addWidget(HTTPEdit, 2, 1, 1, 1);
200 layout->addWidget(HTTPPort, 1, 1, 1, 1);
201 CS( HTTPPort );
202 CT( HTTPEdit );
205 QString HTTPDestBox::getMRL( const QString& mux )
207 if( HTTPEdit->text().isEmpty() ) return "";
209 QString path = HTTPEdit->text();
210 if( path[0] != '/' )
211 path.prepend( qfu("/") );
212 QString port;
213 port.setNum( HTTPPort->value() );
214 QString dst = ":" + port + path;
216 SoutMrl m;
217 m.begin( "http" );
218 /* Path-extension is primary muxer to use if possible,
219 otherwise check for mux-choise and see that it isn't mp4
220 then fallback to flv*/
221 if ( !path.contains(QRegExp("\\..{2,3}$") ) )
223 if( !mux.isEmpty() && mux.compare("mp4") )
224 m.option( "mux", mux );
225 else
226 m.option( "mux", "ffmpeg{mux=flv}" );
228 m.option( "dst", dst );
229 m.end();
231 return m.getMrl();
234 MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
236 label->setText( qtr( "This module outputs the transcoded stream to a network "
237 "via the mms protocol." ) );
239 QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
240 QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
241 layout->addWidget(MMSHLabel, 1, 0, 1, 1);
242 layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);
244 MMSHEdit = new QLineEdit(this);
245 MMSHEdit->setText( "0.0.0.0" );
247 MMSHPort = new QSpinBox(this);
248 MMSHPort->setMaximumSize(QSize(90, 16777215));
249 MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
250 MMSHPort->setMinimum(1);
251 MMSHPort->setMaximum(65535);
252 MMSHPort->setValue(8080);
254 layout->addWidget(MMSHEdit, 1, 1, 1, 1);
255 layout->addWidget(MMSHPort, 2, 1, 1, 1);
256 CS( MMSHPort );
257 CT( MMSHEdit );
260 QString MMSHDestBox::getMRL( const QString& )
262 if( MMSHEdit->text().isEmpty() ) return "";
264 SoutMrl m;
265 m.begin( "std" );
266 m.option( "access", "mmsh" );
267 m.option( "mux", "asfh" );
268 m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
269 m.end();
271 return m.getMrl();
275 RTSPDestBox::RTSPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
277 label->setText(
278 qtr( "This module outputs the transcoded stream to a network via RTSP." ) );
280 QLabel *RTSPLabel = new QLabel( qtr("Path"), this );
281 QLabel *RTSPPortLabel = new QLabel( qtr("Port"), this );
282 layout->addWidget( RTSPLabel, 2, 0, 1, 1 );
283 layout->addWidget( RTSPPortLabel, 1, 0, 1, 1 );
285 RTSPEdit = new QLineEdit( this );
286 RTSPEdit->setText( "/" );
288 RTSPPort = new QSpinBox( this );
289 RTSPPort->setMaximumSize( QSize( 90, 16777215 ) );
290 RTSPPort->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
291 RTSPPort->setMinimum( 1 );
292 RTSPPort->setMaximum( 65535 );
293 RTSPPort->setValue( 8554 );
295 layout->addWidget( RTSPEdit, 2, 1, 1, 1 );
296 layout->addWidget( RTSPPort, 1, 1, 1, 1 );
297 CS( RTSPPort );
298 CT( RTSPEdit );
301 QString RTSPDestBox::getMRL( const QString& )
303 if( RTSPEdit->text().isEmpty() ) return "";
305 QString path = RTSPEdit->text();
306 if( path[0] != '/' )
307 path.prepend( qfu("/") );
308 QString port;
309 port.setNum( RTSPPort->value() );
310 QString sdp = "rtsp://:" + port + path;
312 SoutMrl m;
313 m.begin( "rtp" );
314 m.option( "sdp", sdp );
315 m.end();
317 return m.getMrl();
321 UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
323 label->setText(
324 qtr( "This module outputs the transcoded stream to a network via UDP.") );
326 QLabel *UDPLabel = new QLabel( qtr("Address"), this );
327 QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
328 layout->addWidget(UDPLabel, 1, 0, 1, 1);
329 layout->addWidget(UDPPortLabel, 2, 0, 1, 1);
331 UDPEdit = new QLineEdit(this);
333 UDPPort = new QSpinBox(this);
334 UDPPort->setMaximumSize(QSize(90, 16777215));
335 UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
336 UDPPort->setMinimum(1);
337 UDPPort->setMaximum(65535);
338 UDPPort->setValue(1234);
340 layout->addWidget(UDPEdit, 1, 1, 1, 1);
341 layout->addWidget(UDPPort, 2, 1, 1, 1);
342 CS( UDPPort );
343 CT( UDPEdit );
346 QString UDPDestBox::getMRL( const QString& mux )
348 if( UDPEdit->text().isEmpty() ) return "";
350 SoutMrl m;
351 m.begin( "udp" );
352 /* udp output, ts-mux is really only reasonable one to use*/
353 if( !mux.isEmpty() && !mux.compare("ts" ) )
354 m.option( "mux", mux );
355 m.option( "dst", UDPEdit->text(), UDPPort->value() );
356 m.end();
358 return m.getMrl();
363 RTPDestBox::RTPDestBox( QWidget *_parent, const char *_mux )
364 : VirtualDestBox( _parent ), mux( qfu(_mux) )
366 label->setText( qtr( "This module outputs the transcoded stream to a network via RTP.") );
368 QLabel *RTPLabel = new QLabel( qtr("Address"), this );
369 RTPEdit = new QLineEdit(this);
370 layout->addWidget(RTPLabel, 1, 0, 1, 1);
371 layout->addWidget(RTPEdit, 1, 1, 1, 1);
373 QLabel *RTPPortLabel = new QLabel( qtr("Base port"), this );
374 RTPPort = new QSpinBox(this);
375 RTPPort->setMaximumSize(QSize(90, 16777215));
376 RTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
377 RTPPort->setMinimum(1);
378 RTPPort->setMaximum(65535);
379 RTPPort->setValue(5004);
380 layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
381 layout->addWidget(RTPPort, 2, 1, 1, 1);
383 QLabel *SAPNameLabel = new QLabel( qtr("Stream name"), this );
384 SAPName = new QLineEdit(this);
385 layout->addWidget(SAPNameLabel, 3, 0, 1, 1);
386 layout->addWidget(SAPName, 3, 1, 1, 1);
388 CT( RTPEdit );
389 CS( RTPPort );
390 CT( SAPName );
393 QString RTPDestBox::getMRL( const QString& )
395 QString addr = RTPEdit->text();
396 QString name = SAPName->text();
398 if( addr.isEmpty() ) return qfu("");
400 SoutMrl m;
401 m.begin( "rtp" );
402 m.option( "dst", RTPEdit->text() );
403 m.option( "port", RTPPort->value() );
404 /* mp4-mux ain't usable in rtp-output either */
405 if( !mux.isEmpty() )
406 m.option( "mux", mux );
407 if( !name.isEmpty() )
409 m.option( "sap" );
410 m.option( "name", name );
412 m.end();
414 return m.getMrl();
418 ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
420 label->setText(
421 qtr( "This module outputs the transcoded stream to an Icecast server.") );
423 QLabel *ICELabel = new QLabel( qtr("Address"), this );
424 QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
425 layout->addWidget(ICELabel, 1, 0, 1, 1);
426 layout->addWidget(ICEPortLabel, 2, 0, 1, 1);
428 ICEEdit = new QLineEdit(this);
430 ICEPort = new QSpinBox(this);
431 ICEPort->setMaximumSize(QSize(90, 16777215));
432 ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
433 ICEPort->setMinimum(1);
434 ICEPort->setMaximum(65535);
435 ICEPort->setValue(8000);
437 layout->addWidget(ICEEdit, 1, 1, 1, 1);
438 layout->addWidget(ICEPort, 2, 1, 1, 1);
440 QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
441 QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
442 ICEMountEdit = new QLineEdit( this );
443 ICEPassEdit = new QLineEdit( this );
444 layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
445 layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
446 layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
447 layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );
449 CS( ICEPort );
450 CT( ICEEdit );
451 CT( ICEMountEdit );
452 CT( ICEPassEdit );
455 #undef CS
456 #undef CT
458 QString ICEDestBox::getMRL( const QString& )
460 if( ICEEdit->text().isEmpty() ) return "";
462 SoutMrl m;
463 m.begin( "std" );
464 m.option( "access", "shout" );
465 m.option( "mux", "ogg" );
467 QString url = "//" + ICEPassEdit->text() + "@"
468 + ICEEdit->text()
469 + ":" + QString::number( ICEPort->value(), 10 )
470 + "/" + ICEMountEdit->text();
472 m.option( "dst", url );
473 m.end();
474 return m.getMrl();