]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/sout/sout_widgets.cpp
Qt4: remove audio/video port from RTP streaming wizard
[vlc] / modules / gui / qt4 / components / sout / sout_widgets.cpp
1 /*****************************************************************************
2  * profile_selector.cpp : A small profile selector and editor
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
31 #include <QGroupBox>
32 #include <QGridLayout>
33 #include <QLabel>
34 #include <QLineEdit>
35 #include <QFileDialog>
36
37 SoutInputBox::SoutInputBox( QWidget *_parent, const QString& mrl ) : QGroupBox( _parent )
38 {
39     /**
40      * Source Block
41      **/
42     setTitle( qtr( "Source" ) );
43     QGridLayout *sourceLayout = new QGridLayout( this );
44
45     QLabel *sourceLabel = new QLabel( qtr( "Source:" ) );
46     sourceLayout->addWidget( sourceLabel, 0, 0 );
47
48     sourceLine = new QLineEdit;
49     sourceLine->setReadOnly( true );
50     sourceLine->setText( mrl );
51     sourceLabel->setBuddy( sourceLine );
52     sourceLayout->addWidget( sourceLine, 0, 1 );
53
54     QLabel *sourceTypeLabel = new QLabel( qtr( "Type:" ) );
55     sourceLayout->addWidget( sourceTypeLabel, 1, 0 );
56     sourceValueLabel = new QLabel;
57     sourceLayout->addWidget( sourceValueLabel, 1, 1 );
58
59     /* Line */
60     QFrame *line = new QFrame;
61     line->setFrameStyle( QFrame::HLine |QFrame::Sunken );
62     sourceLayout->addWidget( line, 2, 0, 1, -1 );
63 }
64
65 void SoutInputBox::setMRL( const QString& mrl )
66 {
67     sourceLine->setText( mrl );
68     QString type;
69     int i = mrl.indexOf( "://" );
70     if( i != -1 )
71     {
72         type = mrl.left( i );
73     }
74     else
75         type = qtr( "File/Directory" );
76     sourceValueLabel->setText( type );
77 }
78
79 #define CT( x ) connect( x, SIGNAL( textChanged( const QString& ) ), this, SIGNAL( mrlUpdated() ) );
80 #define CS( x ) connect( x, SIGNAL( valueChanged( int ) ), this, SIGNAL( mrlUpdated() ) );
81
82 /* FileDest Box */
83 FileDestBox::FileDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
84 {
85     QPushButton *fileSelectButton;
86     QGridLayout *layout = new QGridLayout( this );
87
88     QLabel *fileOutput = new QLabel(
89          qtr( "This module writes the transcoded stream to a file."), this );
90     layout->addWidget(fileOutput, 0, 0, 1, -1);
91
92     QLabel *fileLabel = new QLabel( qtr( "Filename"), this );
93     layout->addWidget(fileLabel, 1, 0, 1, 1);
94
95     fileEdit = new QLineEdit(this);
96     layout->addWidget(fileEdit, 1, 4, 1, 1);
97
98     fileSelectButton = new QPushButton( qtr( "Browse..." ), this );
99     QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
100     fileSelectButton->setSizePolicy(sizePolicy);
101
102     layout->addWidget(fileSelectButton, 1, 5, 1, 1);
103     CT( fileEdit );
104     BUTTONACT( fileSelectButton, fileBrowse() );
105 }
106
107 QString FileDestBox::getMRL( const QString& mux )
108 {
109     if( fileEdit->text().isEmpty() ) return "";
110
111     SoutMrl m;
112     m.begin( "std" );
113     m.option( "access", "file" );
114     if( !mux.isEmpty() )
115         m.option( "mux", mux ); //FIXME: alert if ext doesn't match
116     m.option( "dst", fileEdit->text() );
117     m.end();
118
119     return m.getMrl();
120 }
121
122 void FileDestBox::fileBrowse()
123 {
124     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
125             "", qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
126     fileEdit->setText( toNativeSeparators( fileName ) );
127     emit mrlUpdated();
128 }
129
130
131
132 HTTPDestBox::HTTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
133 {
134     QGridLayout *layout = new QGridLayout( this );
135
136     QLabel *httpOutput = new QLabel(
137         qtr( "This module outputs the transcoded stream to a network via HTTP."),
138         this );
139     layout->addWidget(httpOutput, 0, 0, 1, -1);
140
141     QLabel *HTTPLabel = new QLabel( qtr("Address"), this );
142     QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
143     layout->addWidget(HTTPLabel, 1, 0, 1, 1);
144     layout->addWidget(HTTPPortLabel, 2, 0, 1, 1);
145
146     HTTPEdit = new QLineEdit(this);
147     HTTPEdit->setText( "0.0.0.0" );
148
149     HTTPPort = new QSpinBox(this);
150     HTTPPort->setMaximumSize(QSize(90, 16777215));
151     HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
152     HTTPPort->setMinimum(1);
153     HTTPPort->setMaximum(65535);
154     HTTPPort->setValue(8080);
155
156     layout->addWidget(HTTPEdit, 1, 1, 1, 1);
157     layout->addWidget(HTTPPort, 2, 1, 1, 1);
158     CS( HTTPPort );
159     CT( HTTPEdit );
160 }
161
162 QString HTTPDestBox::getMRL( const QString& mux )
163 {
164     if( HTTPEdit->text().isEmpty() ) return "";
165
166     SoutMrl m;
167     m.begin( "std" );
168     m.option(  "access", "http" );
169     if( !mux.isEmpty() )
170         m.option( "mux", mux );
171     m.option( "dst", HTTPEdit->text(), HTTPPort->value() );
172     m.end();
173
174     return m.getMrl();
175 }
176
177 MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
178 {
179     QGridLayout *layout = new QGridLayout( this );
180
181     QLabel *mmshOutput = new QLabel(
182         qtr( "This module outputs the transcoded stream to a network "
183              " via the mms protocol." ), this );
184     layout->addWidget(mmshOutput, 0, 0, 1, -1);
185
186     QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
187     QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
188     layout->addWidget(MMSHLabel, 1, 0, 1, 1);
189     layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);
190
191     MMSHEdit = new QLineEdit(this);
192     MMSHEdit->setText( "0.0.0.0" );
193
194     MMSHPort = new QSpinBox(this);
195     MMSHPort->setMaximumSize(QSize(90, 16777215));
196     MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
197     MMSHPort->setMinimum(1);
198     MMSHPort->setMaximum(65535);
199     MMSHPort->setValue(8080);
200
201     layout->addWidget(MMSHEdit, 1, 1, 1, 1);
202     layout->addWidget(MMSHPort, 2, 1, 1, 1);
203     CS( MMSHPort );
204     CT( MMSHEdit );
205 }
206
207 QString MMSHDestBox::getMRL( const QString& mux )
208 {
209     if( MMSHEdit->text().isEmpty() ) return "";
210
211     SoutMrl m;
212     m.begin( "std" );
213     m.option(  "access", "mmsh" );
214     m.option( "mux", "asfh" );
215     m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
216     m.end();
217
218     return m.getMrl();
219 }
220
221
222 UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
223 {
224     QGridLayout *layout = new QGridLayout( this );
225
226     QLabel *udpOutput = new QLabel(
227         qtr( "This module outputs the transcoded stream to a network via UDP."),
228         this );
229     layout->addWidget(udpOutput, 0, 0, 1, -1);
230
231     QLabel *UDPLabel = new QLabel( qtr("Address"), this );
232     QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
233     layout->addWidget(UDPLabel, 1, 0, 1, 1);
234     layout->addWidget(UDPPortLabel, 2, 0, 1, 1);
235
236     UDPEdit = new QLineEdit(this);
237
238     UDPPort = new QSpinBox(this);
239     UDPPort->setMaximumSize(QSize(90, 16777215));
240     UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
241     UDPPort->setMinimum(1);
242     UDPPort->setMaximum(65535);
243     UDPPort->setValue(1234);
244
245     layout->addWidget(UDPEdit, 1, 1, 1, 1);
246     layout->addWidget(UDPPort, 2, 1, 1, 1);
247     CS( UDPPort );
248     CT( UDPEdit );
249 }
250
251 QString UDPDestBox::getMRL( const QString& mux )
252 {
253     if( UDPEdit->text().isEmpty() ) return "";
254
255     SoutMrl m;
256     m.begin( "std" );
257     m.option(  "access", "udp" );
258     if( !mux.isEmpty() )
259         m.option( "mux", mux );
260     m.option( "dst", UDPEdit->text(), UDPPort->value() );
261     m.end();
262
263     return m.getMrl();
264 }
265
266
267
268 RTPDestBox::RTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
269 {
270     QGridLayout *layout = new QGridLayout( this );
271
272     QLabel *rtpOutput = new QLabel(
273         qtr( "This module outputs the transcoded stream to a network via RTP."),
274         this );
275     layout->addWidget(rtpOutput, 0, 0, 1, -1);
276
277     QLabel *RTPLabel = new QLabel( qtr("Address"), this );
278     QLabel *RTPPortLabel = new QLabel( qtr("Base port"), this );
279     layout->addWidget(RTPLabel, 1, 0, 1, 1);
280     layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
281
282     RTPEdit = new QLineEdit(this);
283
284     RTPPort = new QSpinBox(this);
285     RTPPort->setMaximumSize(QSize(90, 16777215));
286     RTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
287     RTPPort->setMinimum(1);
288     RTPPort->setMaximum(65535);
289     RTPPort->setValue(5004);
290
291     layout->addWidget(RTPEdit, 1, 1, 1, 1);
292     layout->addWidget(RTPPort, 2, 1, 1, 1);
293
294     CS( RTPPort );
295     CT( RTPEdit );
296 }
297
298 QString RTPDestBox::getMRL( const QString& mux )
299 {
300     if( RTPEdit->text().isEmpty() ) return "";
301
302     SoutMrl m;
303     m.begin( "rtp" );
304     m.option( "dst", RTPEdit->text() );
305     m.option( "port", RTPPort->value() );
306     if( !mux.isEmpty() )
307         m.option( "mux", mux );
308     m.end();
309
310     return m.getMrl();
311 }
312
313
314 ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
315 {
316     QGridLayout *layout = new QGridLayout( this );
317
318     QLabel *iceOutput = new QLabel(
319         qtr( "This module outputs the transcoded stream to an Icecast server."),
320         this );
321     layout->addWidget(iceOutput, 0, 0, 1, -1);
322
323     QLabel *ICELabel = new QLabel( qtr("Address"), this );
324     QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
325     layout->addWidget(ICELabel, 1, 0, 1, 1);
326     layout->addWidget(ICEPortLabel, 2, 0, 1, 1);
327
328     ICEEdit = new QLineEdit(this);
329
330     ICEPort = new QSpinBox(this);
331     ICEPort->setMaximumSize(QSize(90, 16777215));
332     ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
333     ICEPort->setMinimum(1);
334     ICEPort->setMaximum(65535);
335     ICEPort->setValue(8000);
336
337     layout->addWidget(ICEEdit, 1, 1, 1, 1);
338     layout->addWidget(ICEPort, 2, 1, 1, 1);
339
340     QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
341     QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
342     ICEMountEdit = new QLineEdit( this );
343     ICEPassEdit = new QLineEdit( this );
344     layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
345     layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
346     layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
347     layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );
348
349     CS( ICEPort );
350     CT( ICEEdit );
351     CT( ICEMountEdit );
352     CT( ICEPassEdit );
353 }
354
355 #undef CS
356 #undef CT
357
358 QString ICEDestBox::getMRL( const QString& mux )
359 {
360     if( ICEEdit->text().isEmpty() ) return "";
361
362     SoutMrl m;
363     m.begin( "std" );
364     m.option( "access", "shout" );
365     m.option( "mux", "ogg" );
366
367     QString url = ICEPassEdit->text() + "@"
368         + ICEEdit->text()
369         + ":" + QString::number( ICEPort->value(), 10 )
370         + "/" + ICEMountEdit->text();
371
372     m.option( "dst", url );
373     m.end();
374     return m.getMrl();
375 }
376