]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/sout/sout_widgets.cpp
Qt4: check extensionlength 2-4 (ts to webm) on sout regexpt
[vlc] / modules / gui / qt4 / components / sout / sout_widgets.cpp
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$
8  *
9  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
10  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
11  *
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.
16  *
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.
21  *
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  *****************************************************************************/
26
27 #include "components/sout/sout_widgets.hpp"
28 #include "dialogs/sout.hpp"
29 #include "util/qt_dirs.hpp"
30 #include <vlc_intf_strings.h>
31
32 #include <QGroupBox>
33 #include <QGridLayout>
34 #include <QLabel>
35 #include <QLineEdit>
36 #include <QFileDialog>
37
38 #define I_FILE_SLASH_DIR \
39     I_DIR_OR_FOLDER( N_("File/Directory"), N_("File/Folder") )
40
41 SoutInputBox::SoutInputBox( QWidget *_parent, const QString& mrl ) : QGroupBox( _parent )
42 {
43     /**
44      * Source Block
45      **/
46     setTitle( qtr( "Source" ) );
47     QGridLayout *sourceLayout = new QGridLayout( this );
48
49     QLabel *sourceLabel = new QLabel( qtr( "Source:" ) );
50     sourceLayout->addWidget( sourceLabel, 0, 0 );
51
52     sourceLine = new QLineEdit;
53     sourceLine->setReadOnly( true );
54     sourceLine->setText( mrl );
55     sourceLabel->setBuddy( sourceLine );
56     sourceLayout->addWidget( sourceLine, 0, 1 );
57
58     QLabel *sourceTypeLabel = new QLabel( qtr( "Type:" ) );
59     sourceLayout->addWidget( sourceTypeLabel, 1, 0 );
60     sourceValueLabel = new QLabel;
61     sourceLayout->addWidget( sourceValueLabel, 1, 1 );
62
63     /* Line */
64     QFrame *line = new QFrame;
65     line->setFrameStyle( QFrame::HLine |QFrame::Sunken );
66     sourceLayout->addWidget( line, 2, 0, 1, -1 );
67 }
68
69 void SoutInputBox::setMRL( const QString& mrl )
70 {
71     sourceLine->setText( mrl );
72     QString type;
73     int i = mrl.indexOf( "://" );
74     if( i != -1 )
75     {
76         type = mrl.left( i );
77     }
78     else
79         type = qtr( I_FILE_SLASH_DIR );
80     sourceValueLabel->setText( type );
81 }
82
83 #define CT( x ) connect( x, SIGNAL( textChanged( const QString& ) ), this, SIGNAL( mrlUpdated() ) );
84 #define CS( x ) connect( x, SIGNAL( valueChanged( int ) ), this, SIGNAL( mrlUpdated() ) );
85
86 /* FileDest Box */
87 FileDestBox::FileDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
88 {
89     QPushButton *fileSelectButton;
90     QGridLayout *layout = new QGridLayout( this );
91
92     QLabel *fileOutput = new QLabel(
93          qtr( "This module writes the transcoded stream to a file."), this );
94     layout->addWidget(fileOutput, 0, 0, 1, -1);
95
96     QLabel *fileLabel = new QLabel( qtr( "Filename"), this );
97     layout->addWidget(fileLabel, 1, 0, 1, 1);
98
99     fileEdit = new QLineEdit(this);
100     layout->addWidget(fileEdit, 1, 4, 1, 1);
101
102     fileSelectButton = new QPushButton( qtr( "Browse..." ), this );
103     QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
104     fileSelectButton->setSizePolicy(sizePolicy);
105
106     layout->addWidget(fileSelectButton, 1, 5, 1, 1);
107     CT( fileEdit );
108     BUTTONACT( fileSelectButton, fileBrowse() );
109 }
110
111 QString FileDestBox::getMRL( const QString& mux )
112 {
113     if( fileEdit->text().isEmpty() ) return "";
114
115     SoutMrl m;
116     m.begin( "file" );
117     QString outputfile = fileEdit->text();
118     if( !mux.isEmpty() )
119     {
120         if( outputfile.contains( QRegExp("\\..{2,4}$")) &&
121             !outputfile.endsWith(mux) )
122         {
123            /* Replace the extension according to muxer */
124            outputfile.replace(QRegExp("\\..{2,4}$"),"."+mux);
125         } else if (!outputfile.endsWith( mux ) )
126         {
127            m.option( "mux", mux );
128         }
129     }
130     m.option( "dst", outputfile );
131     m.end();
132
133     return m.getMrl();
134 }
135
136 void FileDestBox::fileBrowse()
137 {
138     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
139             "", qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ) );
140     fileEdit->setText( toNativeSeparators( fileName ) );
141     emit mrlUpdated();
142 }
143
144
145
146 HTTPDestBox::HTTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
147 {
148     QGridLayout *layout = new QGridLayout( this );
149
150     QLabel *httpOutput = new QLabel(
151         qtr( "This module outputs the transcoded stream to a network via HTTP."),
152         this );
153     layout->addWidget(httpOutput, 0, 0, 1, -1);
154
155     QLabel *HTTPLabel = new QLabel( qtr("Path"), this );
156     QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
157     layout->addWidget(HTTPLabel, 2, 0, 1, 1);
158     layout->addWidget(HTTPPortLabel, 1, 0, 1, 1);
159
160     HTTPEdit = new QLineEdit(this);
161     HTTPEdit->setText( "/" );
162
163     HTTPPort = new QSpinBox(this);
164     HTTPPort->setMaximumSize(QSize(90, 16777215));
165     HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
166     HTTPPort->setMinimum(1);
167     HTTPPort->setMaximum(65535);
168     HTTPPort->setValue(8080);
169
170     layout->addWidget(HTTPEdit, 2, 1, 1, 1);
171     layout->addWidget(HTTPPort, 1, 1, 1, 1);
172     CS( HTTPPort );
173     CT( HTTPEdit );
174 }
175
176 QString HTTPDestBox::getMRL( const QString& mux )
177 {
178     if( HTTPEdit->text().isEmpty() ) return "";
179
180     QString path = HTTPEdit->text();
181     if( path[0] != '/' )
182         path.prepend( qfu("/") );
183     QString port;
184     port.setNum( HTTPPort->value() );
185     QString dst = ":" + port + path;
186
187     SoutMrl m;
188     m.begin( "http" );
189     /* Path-extension is primary muxer to use if possible,
190        otherwise check for mux-choise and see that it isn't mp4
191        then fallback to flv*/
192     if ( !path.contains(QRegExp("\\..{2,3}$") ) )
193     {
194         if( !mux.isEmpty() && mux.compare("mp4") )
195            m.option( "mux", mux );
196         else
197            m.option( "mux", "ffmpeg{mux=flv}" );
198     }
199     m.option( "dst", dst );
200     m.end();
201
202     return m.getMrl();
203 }
204
205 MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
206 {
207     QGridLayout *layout = new QGridLayout( this );
208
209     QLabel *mmshOutput = new QLabel(
210         qtr( "This module outputs the transcoded stream to a network "
211              " via the mms protocol." ), this );
212     layout->addWidget(mmshOutput, 0, 0, 1, -1);
213
214     QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
215     QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
216     layout->addWidget(MMSHLabel, 1, 0, 1, 1);
217     layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);
218
219     MMSHEdit = new QLineEdit(this);
220     MMSHEdit->setText( "0.0.0.0" );
221
222     MMSHPort = new QSpinBox(this);
223     MMSHPort->setMaximumSize(QSize(90, 16777215));
224     MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
225     MMSHPort->setMinimum(1);
226     MMSHPort->setMaximum(65535);
227     MMSHPort->setValue(8080);
228
229     layout->addWidget(MMSHEdit, 1, 1, 1, 1);
230     layout->addWidget(MMSHPort, 2, 1, 1, 1);
231     CS( MMSHPort );
232     CT( MMSHEdit );
233 }
234
235 QString MMSHDestBox::getMRL( const QString& mux )
236 {
237     if( MMSHEdit->text().isEmpty() ) return "";
238
239     SoutMrl m;
240     m.begin( "std" );
241     m.option(  "access", "mmsh" );
242     m.option( "mux", "asfh" );
243     m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
244     m.end();
245
246     return m.getMrl();
247 }
248
249
250 RTSPDestBox::RTSPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
251 {
252     QGridLayout *layout = new QGridLayout( this );
253
254     QLabel *rtspOutput = new QLabel(
255         qtr( "This module outputs the transcoded stream to a network via "
256              "RTSP." ), this );
257     layout->addWidget( rtspOutput, 0, 0, 1, -1 );
258
259     QLabel *RTSPLabel = new QLabel( qtr("Path"), this );
260     QLabel *RTSPPortLabel = new QLabel( qtr("Port"), this );
261     layout->addWidget( RTSPLabel, 2, 0, 1, 1 );
262     layout->addWidget( RTSPPortLabel, 1, 0, 1, 1 );
263
264     RTSPEdit = new QLineEdit( this );
265     RTSPEdit->setText( "/" );
266
267     RTSPPort = new QSpinBox( this );
268     RTSPPort->setMaximumSize( QSize( 90, 16777215 ) );
269     RTSPPort->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
270     RTSPPort->setMinimum( 1 );
271     RTSPPort->setMaximum( 65535 );
272     RTSPPort->setValue( 5544 );
273
274     layout->addWidget( RTSPEdit, 2, 1, 1, 1 );
275     layout->addWidget( RTSPPort, 1, 1, 1, 1 );
276     CS( RTSPPort );
277     CT( RTSPEdit );
278 }
279
280 QString RTSPDestBox::getMRL( const QString& mux )
281 {
282     if( RTSPEdit->text().isEmpty() ) return "";
283
284     QString path = RTSPEdit->text();
285     if( path[0] != '/' )
286         path.prepend( qfu("/") );
287     QString port;
288     port.setNum( RTSPPort->value() );
289     QString sdp = "rtsp://:" + port + path;
290
291     SoutMrl m;
292     m.begin( "rtp" );
293     m.option( "sdp", sdp );
294     m.end();
295
296     return m.getMrl();
297 }
298
299
300 UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
301 {
302     QGridLayout *layout = new QGridLayout( this );
303
304     QLabel *udpOutput = new QLabel(
305         qtr( "This module outputs the transcoded stream to a network via UDP."),
306         this );
307     layout->addWidget(udpOutput, 0, 0, 1, -1);
308
309     QLabel *UDPLabel = new QLabel( qtr("Address"), this );
310     QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
311     layout->addWidget(UDPLabel, 1, 0, 1, 1);
312     layout->addWidget(UDPPortLabel, 2, 0, 1, 1);
313
314     UDPEdit = new QLineEdit(this);
315
316     UDPPort = new QSpinBox(this);
317     UDPPort->setMaximumSize(QSize(90, 16777215));
318     UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
319     UDPPort->setMinimum(1);
320     UDPPort->setMaximum(65535);
321     UDPPort->setValue(1234);
322
323     layout->addWidget(UDPEdit, 1, 1, 1, 1);
324     layout->addWidget(UDPPort, 2, 1, 1, 1);
325     CS( UDPPort );
326     CT( UDPEdit );
327 }
328
329 QString UDPDestBox::getMRL( const QString& mux )
330 {
331     if( UDPEdit->text().isEmpty() ) return "";
332
333     SoutMrl m;
334     m.begin( "udp" );
335     /* udp output, ts-mux is really only reasonable one to use*/
336     if( !mux.isEmpty() && !mux.compare("ts" ) )
337         m.option( "mux", mux );
338     m.option( "dst", UDPEdit->text(), UDPPort->value() );
339     m.end();
340
341     return m.getMrl();
342 }
343
344
345
346 RTPDestBox::RTPDestBox( QWidget *_parent, const char *_mux )
347     : VirtualDestBox( _parent ), mux( _mux )
348 {
349     QGridLayout *layout = new QGridLayout( this );
350
351     QLabel *rtpOutput = new QLabel(
352         qtr( "This module outputs the transcoded stream to a network via RTP."),
353         this );
354     layout->addWidget(rtpOutput, 0, 0, 1, -1);
355
356     QLabel *RTPLabel = new QLabel( qtr("Address"), this );
357     QLabel *RTPPortLabel = new QLabel( qtr("Base port"), this );
358     layout->addWidget(RTPLabel, 1, 0, 1, 1);
359     layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
360
361     RTPEdit = new QLineEdit(this);
362
363     RTPPort = new QSpinBox(this);
364     RTPPort->setMaximumSize(QSize(90, 16777215));
365     RTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
366     RTPPort->setMinimum(1);
367     RTPPort->setMaximum(65535);
368     RTPPort->setValue(5004);
369
370     layout->addWidget(RTPEdit, 1, 1, 1, 1);
371     layout->addWidget(RTPPort, 2, 1, 1, 1);
372
373     CS( RTPPort );
374     CT( RTPEdit );
375 }
376
377 QString RTPDestBox::getMRL( const QString& )
378 {
379     if( RTPEdit->text().isEmpty() ) return "";
380
381     SoutMrl m;
382     m.begin( "rtp" );
383     m.option( "dst", RTPEdit->text() );
384     m.option( "port", RTPPort->value() );
385     /* mp4-mux ain't usable in rtp-output either */
386     if( mux != NULL )
387         m.option( "mux", qfu( mux ) );
388     m.end();
389
390     return m.getMrl();
391 }
392
393
394 ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
395 {
396     QGridLayout *layout = new QGridLayout( this );
397
398     QLabel *iceOutput = new QLabel(
399         qtr( "This module outputs the transcoded stream to an Icecast server."),
400         this );
401     layout->addWidget(iceOutput, 0, 0, 1, -1);
402
403     QLabel *ICELabel = new QLabel( qtr("Address"), this );
404     QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
405     layout->addWidget(ICELabel, 1, 0, 1, 1);
406     layout->addWidget(ICEPortLabel, 2, 0, 1, 1);
407
408     ICEEdit = new QLineEdit(this);
409
410     ICEPort = new QSpinBox(this);
411     ICEPort->setMaximumSize(QSize(90, 16777215));
412     ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
413     ICEPort->setMinimum(1);
414     ICEPort->setMaximum(65535);
415     ICEPort->setValue(8000);
416
417     layout->addWidget(ICEEdit, 1, 1, 1, 1);
418     layout->addWidget(ICEPort, 2, 1, 1, 1);
419
420     QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
421     QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
422     ICEMountEdit = new QLineEdit( this );
423     ICEPassEdit = new QLineEdit( this );
424     layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
425     layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
426     layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
427     layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );
428
429     CS( ICEPort );
430     CT( ICEEdit );
431     CT( ICEMountEdit );
432     CT( ICEPassEdit );
433 }
434
435 #undef CS
436 #undef CT
437
438 QString ICEDestBox::getMRL( const QString& mux )
439 {
440     if( ICEEdit->text().isEmpty() ) return "";
441
442     SoutMrl m;
443     m.begin( "std" );
444     m.option( "access", "shout" );
445     m.option( "mux", "ogg" );
446
447     QString url = ICEPassEdit->text() + "@"
448         + ICEEdit->text()
449         + ":" + QString::number( ICEPort->value(), 10 )
450         + "/" + ICEMountEdit->text();
451
452     m.option( "dst", url );
453     m.end();
454     return m.getMrl();
455 }
456