]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/sout/sout_widgets.cpp
Qt4: update avcodec-hw prefs
[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(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.option( "no-overwrite" );
132     m.end();
133
134     return m.getMrl();
135 }
136
137 void FileDestBox::fileBrowse()
138 {
139     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
140             "", qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ) );
141     fileEdit->setText( toNativeSeparators( fileName ) );
142     emit mrlUpdated();
143 }
144
145
146
147 HTTPDestBox::HTTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
148 {
149     QGridLayout *layout = new QGridLayout( this );
150
151     QLabel *httpOutput = new QLabel(
152         qtr( "This module outputs the transcoded stream to a network via HTTP."),
153         this );
154     layout->addWidget(httpOutput, 0, 0, 1, -1);
155
156     QLabel *HTTPLabel = new QLabel( qtr("Path"), this );
157     QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
158     layout->addWidget(HTTPLabel, 2, 0, 1, 1);
159     layout->addWidget(HTTPPortLabel, 1, 0, 1, 1);
160
161     HTTPEdit = new QLineEdit(this);
162     HTTPEdit->setText( "/" );
163
164     HTTPPort = new QSpinBox(this);
165     HTTPPort->setMaximumSize(QSize(90, 16777215));
166     HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
167     HTTPPort->setMinimum(1);
168     HTTPPort->setMaximum(65535);
169     HTTPPort->setValue(8080);
170
171     layout->addWidget(HTTPEdit, 2, 1, 1, 1);
172     layout->addWidget(HTTPPort, 1, 1, 1, 1);
173     CS( HTTPPort );
174     CT( HTTPEdit );
175 }
176
177 QString HTTPDestBox::getMRL( const QString& mux )
178 {
179     if( HTTPEdit->text().isEmpty() ) return "";
180
181     QString path = HTTPEdit->text();
182     if( path[0] != '/' )
183         path.prepend( qfu("/") );
184     QString port;
185     port.setNum( HTTPPort->value() );
186     QString dst = ":" + port + path;
187
188     SoutMrl m;
189     m.begin( "http" );
190     /* Path-extension is primary muxer to use if possible,
191        otherwise check for mux-choise and see that it isn't mp4
192        then fallback to flv*/
193     if ( !path.contains(QRegExp("\\..{2,3}$") ) )
194     {
195         if( !mux.isEmpty() && mux.compare("mp4") )
196            m.option( "mux", mux );
197         else
198            m.option( "mux", "ffmpeg{mux=flv}" );
199     }
200     m.option( "dst", dst );
201     m.end();
202
203     return m.getMrl();
204 }
205
206 MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
207 {
208     QGridLayout *layout = new QGridLayout( this );
209
210     QLabel *mmshOutput = new QLabel(
211         qtr( "This module outputs the transcoded stream to a network "
212              "via the mms protocol." ), this );
213     layout->addWidget(mmshOutput, 0, 0, 1, -1);
214
215     QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
216     QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
217     layout->addWidget(MMSHLabel, 1, 0, 1, 1);
218     layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);
219
220     MMSHEdit = new QLineEdit(this);
221     MMSHEdit->setText( "0.0.0.0" );
222
223     MMSHPort = new QSpinBox(this);
224     MMSHPort->setMaximumSize(QSize(90, 16777215));
225     MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
226     MMSHPort->setMinimum(1);
227     MMSHPort->setMaximum(65535);
228     MMSHPort->setValue(8080);
229
230     layout->addWidget(MMSHEdit, 1, 1, 1, 1);
231     layout->addWidget(MMSHPort, 2, 1, 1, 1);
232     CS( MMSHPort );
233     CT( MMSHEdit );
234 }
235
236 QString MMSHDestBox::getMRL( const QString& )
237 {
238     if( MMSHEdit->text().isEmpty() ) return "";
239
240     SoutMrl m;
241     m.begin( "std" );
242     m.option(  "access", "mmsh" );
243     m.option( "mux", "asfh" );
244     m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
245     m.end();
246
247     return m.getMrl();
248 }
249
250
251 RTSPDestBox::RTSPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
252 {
253     QGridLayout *layout = new QGridLayout( this );
254
255     QLabel *rtspOutput = new QLabel(
256         qtr( "This module outputs the transcoded stream to a network via "
257              "RTSP." ), this );
258     layout->addWidget( rtspOutput, 0, 0, 1, -1 );
259
260     QLabel *RTSPLabel = new QLabel( qtr("Path"), this );
261     QLabel *RTSPPortLabel = new QLabel( qtr("Port"), this );
262     layout->addWidget( RTSPLabel, 2, 0, 1, 1 );
263     layout->addWidget( RTSPPortLabel, 1, 0, 1, 1 );
264
265     RTSPEdit = new QLineEdit( this );
266     RTSPEdit->setText( "/" );
267
268     RTSPPort = new QSpinBox( this );
269     RTSPPort->setMaximumSize( QSize( 90, 16777215 ) );
270     RTSPPort->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
271     RTSPPort->setMinimum( 1 );
272     RTSPPort->setMaximum( 65535 );
273     RTSPPort->setValue( 8554 );
274
275     layout->addWidget( RTSPEdit, 2, 1, 1, 1 );
276     layout->addWidget( RTSPPort, 1, 1, 1, 1 );
277     CS( RTSPPort );
278     CT( RTSPEdit );
279 }
280
281 QString RTSPDestBox::getMRL( const QString& )
282 {
283     if( RTSPEdit->text().isEmpty() ) return "";
284
285     QString path = RTSPEdit->text();
286     if( path[0] != '/' )
287         path.prepend( qfu("/") );
288     QString port;
289     port.setNum( RTSPPort->value() );
290     QString sdp = "rtsp://:" + port + path;
291
292     SoutMrl m;
293     m.begin( "rtp" );
294     m.option( "sdp", sdp );
295     m.end();
296
297     return m.getMrl();
298 }
299
300
301 UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
302 {
303     QGridLayout *layout = new QGridLayout( this );
304
305     QLabel *udpOutput = new QLabel(
306         qtr( "This module outputs the transcoded stream to a network via UDP."),
307         this );
308     layout->addWidget(udpOutput, 0, 0, 1, -1);
309
310     QLabel *UDPLabel = new QLabel( qtr("Address"), this );
311     QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
312     layout->addWidget(UDPLabel, 1, 0, 1, 1);
313     layout->addWidget(UDPPortLabel, 2, 0, 1, 1);
314
315     UDPEdit = new QLineEdit(this);
316
317     UDPPort = new QSpinBox(this);
318     UDPPort->setMaximumSize(QSize(90, 16777215));
319     UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
320     UDPPort->setMinimum(1);
321     UDPPort->setMaximum(65535);
322     UDPPort->setValue(1234);
323
324     layout->addWidget(UDPEdit, 1, 1, 1, 1);
325     layout->addWidget(UDPPort, 2, 1, 1, 1);
326     CS( UDPPort );
327     CT( UDPEdit );
328 }
329
330 QString UDPDestBox::getMRL( const QString& mux )
331 {
332     if( UDPEdit->text().isEmpty() ) return "";
333
334     SoutMrl m;
335     m.begin( "udp" );
336     /* udp output, ts-mux is really only reasonable one to use*/
337     if( !mux.isEmpty() && !mux.compare("ts" ) )
338         m.option( "mux", mux );
339     m.option( "dst", UDPEdit->text(), UDPPort->value() );
340     m.end();
341
342     return m.getMrl();
343 }
344
345
346
347 RTPDestBox::RTPDestBox( QWidget *_parent, const char *_mux )
348     : VirtualDestBox( _parent ), mux( qfu(_mux) )
349 {
350     QGridLayout *layout = new QGridLayout( this );
351
352     QLabel *rtpOutput = new QLabel(
353         qtr( "This module outputs the transcoded stream to a network via RTP."),
354         this );
355     layout->addWidget(rtpOutput, 0, 0, 1, -1);
356
357     QLabel *RTPLabel = new QLabel( qtr("Address"), this );
358     RTPEdit = new QLineEdit(this);
359     layout->addWidget(RTPLabel, 1, 0, 1, 1);
360     layout->addWidget(RTPEdit, 1, 1, 1, 1);
361
362     QLabel *RTPPortLabel = new QLabel( qtr("Base port"), this );
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     layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
370     layout->addWidget(RTPPort, 2, 1, 1, 1);
371
372     QLabel *SAPNameLabel = new QLabel( qtr("Stream name"), this );
373     SAPName = new QLineEdit(this);
374     layout->addWidget(SAPNameLabel, 3, 0, 1, 1);
375     layout->addWidget(SAPName, 3, 1, 1, 1);
376
377     CT( RTPEdit );
378     CS( RTPPort );
379     CT( SAPName );
380 }
381
382 QString RTPDestBox::getMRL( const QString& )
383 {
384     QString addr = RTPEdit->text();
385     QString name = SAPName->text();
386
387     if( addr.isEmpty() ) return qfu("");
388
389     SoutMrl m;
390     m.begin( "rtp" );
391     m.option( "dst", RTPEdit->text() );
392     m.option( "port", RTPPort->value() );
393     /* mp4-mux ain't usable in rtp-output either */
394     if( !mux.isEmpty() )
395         m.option( "mux", mux );
396     if( !name.isEmpty() )
397     {
398         m.option( "sap" );
399         m.option( "name", name );
400     }
401     m.end();
402
403     return m.getMrl();
404 }
405
406
407 ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
408 {
409     QGridLayout *layout = new QGridLayout( this );
410
411     QLabel *iceOutput = new QLabel(
412         qtr( "This module outputs the transcoded stream to an Icecast server."),
413         this );
414     layout->addWidget(iceOutput, 0, 0, 1, -1);
415
416     QLabel *ICELabel = new QLabel( qtr("Address"), this );
417     QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
418     layout->addWidget(ICELabel, 1, 0, 1, 1);
419     layout->addWidget(ICEPortLabel, 2, 0, 1, 1);
420
421     ICEEdit = new QLineEdit(this);
422
423     ICEPort = new QSpinBox(this);
424     ICEPort->setMaximumSize(QSize(90, 16777215));
425     ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
426     ICEPort->setMinimum(1);
427     ICEPort->setMaximum(65535);
428     ICEPort->setValue(8000);
429
430     layout->addWidget(ICEEdit, 1, 1, 1, 1);
431     layout->addWidget(ICEPort, 2, 1, 1, 1);
432
433     QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
434     QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
435     ICEMountEdit = new QLineEdit( this );
436     ICEPassEdit = new QLineEdit( this );
437     layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
438     layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
439     layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
440     layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );
441
442     CS( ICEPort );
443     CT( ICEEdit );
444     CT( ICEMountEdit );
445     CT( ICEPassEdit );
446 }
447
448 #undef CS
449 #undef CT
450
451 QString ICEDestBox::getMRL( const QString& )
452 {
453     if( ICEEdit->text().isEmpty() ) return "";
454
455     SoutMrl m;
456     m.begin( "std" );
457     m.option( "access", "shout" );
458     m.option( "mux", "ogg" );
459
460     QString url = ICEPassEdit->text() + "@"
461         + ICEEdit->text()
462         + ":" + QString::number( ICEPort->value(), 10 )
463         + "/" + ICEMountEdit->text();
464
465     m.option( "dst", url );
466     m.end();
467     return m.getMrl();
468 }
469