sout_widgets.cpp 13.9 KB
Newer Older
1
/*****************************************************************************
Pierre Ynard's avatar
Pierre Ynard committed
2
 * sout_widgets.cpp : Widgets for stream output destination boxes
3
 ****************************************************************************
4
5
6
 * Copyright (C) 2007-2009 the VideoLAN team
 * Copyright (C) 2007 Société des arts technologiques
 * Copyright (C) 2007 Savoir-faire Linux
7
8
9
 * $Id$
 *
 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
10
 *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "components/sout/sout_widgets.hpp"
28
29
#include "dialogs/sout.hpp"
#include "util/qt_dirs.hpp"
30
#include <vlc_intf_strings.h>
31
32
33
34
35

#include <QGroupBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
36
#include <QFileDialog>
37
#include <QUrl>
38

39
40
41
#define I_FILE_SLASH_DIR \
    I_DIR_OR_FOLDER( N_("File/Directory"), N_("File/Folder") )

42
SoutInputBox::SoutInputBox( QWidget *_parent, const QString& mrl ) : QGroupBox( _parent )
43
44
45
46
{
    /**
     * Source Block
     **/
47
48
    setTitle( qtr( "Source" ) );
    QGridLayout *sourceLayout = new QGridLayout( this );
49
50
51
52

    QLabel *sourceLabel = new QLabel( qtr( "Source:" ) );
    sourceLayout->addWidget( sourceLabel, 0, 0 );

53
    sourceLine = new QLineEdit;
54
    sourceLine->setReadOnly( true );
55
    sourceLine->setText( mrl );
56
57
58
59
60
    sourceLabel->setBuddy( sourceLine );
    sourceLayout->addWidget( sourceLine, 0, 1 );

    QLabel *sourceTypeLabel = new QLabel( qtr( "Type:" ) );
    sourceLayout->addWidget( sourceTypeLabel, 1, 0 );
61
    sourceValueLabel = new QLabel;
62
63
64
65
66
67
68
69
    sourceLayout->addWidget( sourceValueLabel, 1, 1 );

    /* Line */
    QFrame *line = new QFrame;
    line->setFrameStyle( QFrame::HLine |QFrame::Sunken );
    sourceLayout->addWidget( line, 2, 0, 1, -1 );
}

70
void SoutInputBox::setMRL( const QString& mrl )
71
{
72
    QUrl uri = QUrl::fromEncoded( mrl.toLatin1() );
73
74
75
    sourceLine->setText( uri.toString() );
    QString type = uri.scheme();
    if ( type.isEmpty() ) type = qtr( I_FILE_SLASH_DIR );
76
77
    sourceValueLabel->setText( type );
}
78

79
80
#define CT( x ) connect( x, SIGNAL(textChanged(QString)), this, SIGNAL(mrlUpdated()) );
#define CS( x ) connect( x, SIGNAL(valueChanged(int)), this, SIGNAL(mrlUpdated()) );
81
82

/* FileDest Box */
83
FileDestBox::FileDestBox( QWidget *_parent, intf_thread_t * _p_intf ) : VirtualDestBox( _parent )
84
{
85
86
    p_intf = _p_intf;

87
88
89
90
    QPushButton *fileSelectButton;
    QGridLayout *layout = new QGridLayout( this );

    QLabel *fileOutput = new QLabel(
91
         qtr( "This module writes the transcoded stream to a file."), this );
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    layout->addWidget(fileOutput, 0, 0, 1, -1);

    QLabel *fileLabel = new QLabel( qtr( "Filename"), this );
    layout->addWidget(fileLabel, 1, 0, 1, 1);

    fileEdit = new QLineEdit(this);
    layout->addWidget(fileEdit, 1, 4, 1, 1);

    fileSelectButton = new QPushButton( qtr( "Browse..." ), this );
    QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    fileSelectButton->setSizePolicy(sizePolicy);

    layout->addWidget(fileSelectButton, 1, 5, 1, 1);
    CT( fileEdit );
    BUTTONACT( fileSelectButton, fileBrowse() );
}

109
QString FileDestBox::getMRL( const QString& mux )
110
111
112
113
{
    if( fileEdit->text().isEmpty() ) return "";

    SoutMrl m;
114
115
    m.begin( "file" );
    QString outputfile = fileEdit->text();
116
    if( !mux.isEmpty() )
117
    {
118
        if( outputfile.contains( QRegExp("\\..{2,4}$")) &&
119
120
121
            !outputfile.endsWith(mux) )
        {
           /* Replace the extension according to muxer */
122
           outputfile.replace(QRegExp("\\..{2,4}$"),"."+mux);
123
124
125
126
127
128
        } else if (!outputfile.endsWith( mux ) )
        {
           m.option( "mux", mux );
        }
    }
    m.option( "dst", outputfile );
129
    m.option( "no-overwrite" );
130
131
132
133
134
135
136
137
    m.end();

    return m.getMrl();
}

void FileDestBox::fileBrowse()
{
    QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
138
            p_intf->p_sys->filepath, qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv *.webm)" ) );
139
140
141
142
143
144
145
146
147
148
149
    fileEdit->setText( toNativeSeparators( fileName ) );
    emit mrlUpdated();
}



HTTPDestBox::HTTPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
{
    QGridLayout *layout = new QGridLayout( this );

    QLabel *httpOutput = new QLabel(
150
151
        qtr( "This module outputs the transcoded stream to a network via HTTP."),
        this );
152
153
    layout->addWidget(httpOutput, 0, 0, 1, -1);

154
    QLabel *HTTPLabel = new QLabel( qtr("Path"), this );
155
    QLabel *HTTPPortLabel = new QLabel( qtr("Port"), this );
156
157
    layout->addWidget(HTTPLabel, 2, 0, 1, 1);
    layout->addWidget(HTTPPortLabel, 1, 0, 1, 1);
158
159

    HTTPEdit = new QLineEdit(this);
160
    HTTPEdit->setText( "/" );
161
162
163
164
165
166
167
168

    HTTPPort = new QSpinBox(this);
    HTTPPort->setMaximumSize(QSize(90, 16777215));
    HTTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    HTTPPort->setMinimum(1);
    HTTPPort->setMaximum(65535);
    HTTPPort->setValue(8080);

169
170
    layout->addWidget(HTTPEdit, 2, 1, 1, 1);
    layout->addWidget(HTTPPort, 1, 1, 1, 1);
171
172
173
174
    CS( HTTPPort );
    CT( HTTPEdit );
}

175
QString HTTPDestBox::getMRL( const QString& mux )
176
177
178
{
    if( HTTPEdit->text().isEmpty() ) return "";

179
180
181
182
183
184
185
    QString path = HTTPEdit->text();
    if( path[0] != '/' )
        path.prepend( qfu("/") );
    QString port;
    port.setNum( HTTPPort->value() );
    QString dst = ":" + port + path;

186
    SoutMrl m;
187
    m.begin( "http" );
188
189
190
191
192
193
194
195
196
197
    /* Path-extension is primary muxer to use if possible,
       otherwise check for mux-choise and see that it isn't mp4
       then fallback to flv*/
    if ( !path.contains(QRegExp("\\..{2,3}$") ) )
    {
        if( !mux.isEmpty() && mux.compare("mp4") )
           m.option( "mux", mux );
        else
           m.option( "mux", "ffmpeg{mux=flv}" );
    }
198
    m.option( "dst", dst );
199
200
201
202
203
204
205
206
207
208
    m.end();

    return m.getMrl();
}

MMSHDestBox::MMSHDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
{
    QGridLayout *layout = new QGridLayout( this );

    QLabel *mmshOutput = new QLabel(
209
        qtr( "This module outputs the transcoded stream to a network "
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
210
             "via the mms protocol." ), this );
211
212
213
214
215
216
217
218
    layout->addWidget(mmshOutput, 0, 0, 1, -1);

    QLabel *MMSHLabel = new QLabel( qtr("Address"), this );
    QLabel *MMSHPortLabel = new QLabel( qtr("Port"), this );
    layout->addWidget(MMSHLabel, 1, 0, 1, 1);
    layout->addWidget(MMSHPortLabel, 2, 0, 1, 1);

    MMSHEdit = new QLineEdit(this);
219
    MMSHEdit->setText( "0.0.0.0" );
220
221
222
223
224
225

    MMSHPort = new QSpinBox(this);
    MMSHPort->setMaximumSize(QSize(90, 16777215));
    MMSHPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    MMSHPort->setMinimum(1);
    MMSHPort->setMaximum(65535);
226
    MMSHPort->setValue(8080);
227
228
229
230
231
232
233

    layout->addWidget(MMSHEdit, 1, 1, 1, 1);
    layout->addWidget(MMSHPort, 2, 1, 1, 1);
    CS( MMSHPort );
    CT( MMSHEdit );
}

234
QString MMSHDestBox::getMRL( const QString& )
235
236
237
238
239
240
241
242
243
244
245
246
247
248
{
    if( MMSHEdit->text().isEmpty() ) return "";

    SoutMrl m;
    m.begin( "std" );
    m.option(  "access", "mmsh" );
    m.option( "mux", "asfh" );
    m.option( "dst", MMSHEdit->text(), MMSHPort->value() );
    m.end();

    return m.getMrl();
}


249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
RTSPDestBox::RTSPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
{
    QGridLayout *layout = new QGridLayout( this );

    QLabel *rtspOutput = new QLabel(
        qtr( "This module outputs the transcoded stream to a network via "
             "RTSP." ), this );
    layout->addWidget( rtspOutput, 0, 0, 1, -1 );

    QLabel *RTSPLabel = new QLabel( qtr("Path"), this );
    QLabel *RTSPPortLabel = new QLabel( qtr("Port"), this );
    layout->addWidget( RTSPLabel, 2, 0, 1, 1 );
    layout->addWidget( RTSPPortLabel, 1, 0, 1, 1 );

    RTSPEdit = new QLineEdit( this );
    RTSPEdit->setText( "/" );

    RTSPPort = new QSpinBox( this );
    RTSPPort->setMaximumSize( QSize( 90, 16777215 ) );
    RTSPPort->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
    RTSPPort->setMinimum( 1 );
    RTSPPort->setMaximum( 65535 );
271
    RTSPPort->setValue( 8554 );
272
273
274
275
276
277
278

    layout->addWidget( RTSPEdit, 2, 1, 1, 1 );
    layout->addWidget( RTSPPort, 1, 1, 1, 1 );
    CS( RTSPPort );
    CT( RTSPEdit );
}

279
QString RTSPDestBox::getMRL( const QString& )
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
{
    if( RTSPEdit->text().isEmpty() ) return "";

    QString path = RTSPEdit->text();
    if( path[0] != '/' )
        path.prepend( qfu("/") );
    QString port;
    port.setNum( RTSPPort->value() );
    QString sdp = "rtsp://:" + port + path;

    SoutMrl m;
    m.begin( "rtp" );
    m.option( "sdp", sdp );
    m.end();

    return m.getMrl();
}


299
300
301
302
303
UDPDestBox::UDPDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
{
    QGridLayout *layout = new QGridLayout( this );

    QLabel *udpOutput = new QLabel(
304
305
        qtr( "This module outputs the transcoded stream to a network via UDP."),
        this );
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
    layout->addWidget(udpOutput, 0, 0, 1, -1);

    QLabel *UDPLabel = new QLabel( qtr("Address"), this );
    QLabel *UDPPortLabel = new QLabel( qtr("Port"), this );
    layout->addWidget(UDPLabel, 1, 0, 1, 1);
    layout->addWidget(UDPPortLabel, 2, 0, 1, 1);

    UDPEdit = new QLineEdit(this);

    UDPPort = new QSpinBox(this);
    UDPPort->setMaximumSize(QSize(90, 16777215));
    UDPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    UDPPort->setMinimum(1);
    UDPPort->setMaximum(65535);
    UDPPort->setValue(1234);

    layout->addWidget(UDPEdit, 1, 1, 1, 1);
    layout->addWidget(UDPPort, 2, 1, 1, 1);
    CS( UDPPort );
    CT( UDPEdit );
}

328
QString UDPDestBox::getMRL( const QString& mux )
329
330
331
332
{
    if( UDPEdit->text().isEmpty() ) return "";

    SoutMrl m;
333
334
335
    m.begin( "udp" );
    /* udp output, ts-mux is really only reasonable one to use*/
    if( !mux.isEmpty() && !mux.compare("ts" ) )
336
337
338
339
340
341
342
343
344
        m.option( "mux", mux );
    m.option( "dst", UDPEdit->text(), UDPPort->value() );
    m.end();

    return m.getMrl();
}



345
RTPDestBox::RTPDestBox( QWidget *_parent, const char *_mux )
346
    : VirtualDestBox( _parent ), mux( qfu(_mux) )
347
348
349
350
{
    QGridLayout *layout = new QGridLayout( this );

    QLabel *rtpOutput = new QLabel(
351
352
        qtr( "This module outputs the transcoded stream to a network via RTP."),
        this );
353
354
355
356
    layout->addWidget(rtpOutput, 0, 0, 1, -1);

    QLabel *RTPLabel = new QLabel( qtr("Address"), this );
    RTPEdit = new QLineEdit(this);
357
358
    layout->addWidget(RTPLabel, 1, 0, 1, 1);
    layout->addWidget(RTPEdit, 1, 1, 1, 1);
359

360
    QLabel *RTPPortLabel = new QLabel( qtr("Base port"), this );
361
362
363
364
365
    RTPPort = new QSpinBox(this);
    RTPPort->setMaximumSize(QSize(90, 16777215));
    RTPPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    RTPPort->setMinimum(1);
    RTPPort->setMaximum(65535);
366
    RTPPort->setValue(5004);
367
    layout->addWidget(RTPPortLabel, 2, 0, 1, 1);
368
369
    layout->addWidget(RTPPort, 2, 1, 1, 1);

370
371
372
373
374
    QLabel *SAPNameLabel = new QLabel( qtr("Stream name"), this );
    SAPName = new QLineEdit(this);
    layout->addWidget(SAPNameLabel, 3, 0, 1, 1);
    layout->addWidget(SAPName, 3, 1, 1, 1);

375
    CT( RTPEdit );
376
377
    CS( RTPPort );
    CT( SAPName );
378
379
}

380
QString RTPDestBox::getMRL( const QString& )
381
{
382
383
384
385
    QString addr = RTPEdit->text();
    QString name = SAPName->text();

    if( addr.isEmpty() ) return qfu("");
386
387
388
389
390

    SoutMrl m;
    m.begin( "rtp" );
    m.option( "dst", RTPEdit->text() );
    m.option( "port", RTPPort->value() );
391
    /* mp4-mux ain't usable in rtp-output either */
392
393
394
395
396
397
398
    if( !mux.isEmpty() )
        m.option( "mux", mux );
    if( !name.isEmpty() )
    {
        m.option( "sap" );
        m.option( "name", name );
    }
399
400
401
402
403
404
405
406
407
408
409
    m.end();

    return m.getMrl();
}


ICEDestBox::ICEDestBox( QWidget *_parent ) : VirtualDestBox( _parent )
{
    QGridLayout *layout = new QGridLayout( this );

    QLabel *iceOutput = new QLabel(
410
411
        qtr( "This module outputs the transcoded stream to an Icecast server."),
        this );
412
413
414
415
416
417
418
419
420
421
422
423
424
425
    layout->addWidget(iceOutput, 0, 0, 1, -1);

    QLabel *ICELabel = new QLabel( qtr("Address"), this );
    QLabel *ICEPortLabel = new QLabel( qtr("Port"), this );
    layout->addWidget(ICELabel, 1, 0, 1, 1);
    layout->addWidget(ICEPortLabel, 2, 0, 1, 1);

    ICEEdit = new QLineEdit(this);

    ICEPort = new QSpinBox(this);
    ICEPort->setMaximumSize(QSize(90, 16777215));
    ICEPort->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    ICEPort->setMinimum(1);
    ICEPort->setMaximum(65535);
426
    ICEPort->setValue(8000);
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

    layout->addWidget(ICEEdit, 1, 1, 1, 1);
    layout->addWidget(ICEPort, 2, 1, 1, 1);

    QLabel *IcecastMountpointLabel = new QLabel( qtr( "Mount Point" ), this );
    QLabel *IcecastNameLabel = new QLabel( qtr( "Login:pass" ), this );
    ICEMountEdit = new QLineEdit( this );
    ICEPassEdit = new QLineEdit( this );
    layout->addWidget(IcecastMountpointLabel, 3, 0, 1, 1 );
    layout->addWidget(ICEMountEdit, 3, 1, 1, -1 );
    layout->addWidget(IcecastNameLabel, 4, 0, 1, 1 );
    layout->addWidget(ICEPassEdit, 4, 1, 1, -1 );

    CS( ICEPort );
    CT( ICEEdit );
    CT( ICEMountEdit );
    CT( ICEPassEdit );
}

ivoire's avatar
ivoire committed
446
447
448
#undef CS
#undef CT

449
QString ICEDestBox::getMRL( const QString& )
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
{
    if( ICEEdit->text().isEmpty() ) return "";

    SoutMrl m;
    m.begin( "std" );
    m.option( "access", "shout" );
    m.option( "mux", "ogg" );

    QString url = ICEPassEdit->text() + "@"
        + ICEEdit->text()
        + ":" + QString::number( ICEPort->value(), 10 )
        + "/" + ICEMountEdit->text();

    m.option( "dst", url );
    m.end();
    return m.getMrl();
}