sout.cpp 15 KB
Newer Older
zorglub's avatar
zorglub committed
1
/*****************************************************************************
2
 * sout.cpp : Stream output dialog ( old-style )
zorglub's avatar
zorglub committed
3
 ****************************************************************************
4
 * Copyright ( C ) 2006 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
 *          Jean-François Massol <jf.massol -at- gmail.com>
zorglub's avatar
zorglub committed
10
11
12
13
 *
 * 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
14
 * ( at your option ) any later version.
zorglub's avatar
zorglub committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 *
 * 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 "dialogs/sout.hpp"
#include "qt4.hpp"
#include <vlc_streaming.h>

30
31
#include <iostream>
#include <QString>
zorglub's avatar
zorglub committed
32
33
#include <QFileDialog>

34
35
SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
                     bool _transcode_only ) : QVLCDialog( parent,  _p_intf )
zorglub's avatar
zorglub committed
36
{
37
    setWindowTitle( qtr( "Stream output" ) );
38

39
40
    b_transcode_only = _transcode_only;

zorglub's avatar
zorglub committed
41
    /* UI stuff */
42
    ui.setupUi( this );
43

44
45
46
47
48
49
50
51
/* ADD HERE for new profiles */
#define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
    ADD_PROFILE( "Custom" , "Custom" )
    ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
    ADD_PROFILE( "XBox", "XBox" )
    ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
    ADD_PROFILE( "PSP", "PSP")
    ADD_PROFILE( "GSM", "GSM" )
52

53
#define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
54
55
56
57
58
59
60
61
62
63
64
65
66
    ADD_VCODEC( "MPEG-1", "mp1v" )
    ADD_VCODEC( "MPEG-2", "mp2v" )
    ADD_VCODEC( "MPEG-4", "mp4v" )
    ADD_VCODEC( "DIVX 1" , "DIV1" )
    ADD_VCODEC( "DIVX 2" , "DIV1" )
    ADD_VCODEC( "DIVX 3" , "DIV1" )
    ADD_VCODEC( "H-263", "H263" )
    ADD_VCODEC( "H-264", "h264" )
    ADD_VCODEC( "WMV1", "WMV1" )
    ADD_VCODEC( "WMV2" , "WMV2" )
    ADD_VCODEC( "M-JPEG", "MJPG" )
    ADD_VCODEC( "Theora", "theo" )

67
#define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
68
69
    ADD_ACODEC( "MPEG Audio", "mpga" )
    ADD_ACODEC( "MP3", "mp3" )
70
71
    ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
    ADD_ACODEC( "A52/AC-3", "a52" )
72
73
74
75
76
77
    ADD_ACODEC( "Vorbis", "vorb" )
    ADD_ACODEC( "Flac", "flac" )
    ADD_ACODEC( "Speex", "spx" )
    ADD_ACODEC( "WAV", "s16l" )
    ADD_ACODEC( "WMA", "wma" )

78
#define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
79
80
81
82
83
84
85
86
87
    ADD_SCALING( "0.25" )
    ADD_SCALING( "0.5" )
    ADD_SCALING( "0.75" )
    ADD_SCALING( "1" )
    ADD_SCALING( "1.25" )
    ADD_SCALING( "1.5" )
    ADD_SCALING( "1.75" )
    ADD_SCALING( "2" )

88
89
    ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n This is automatically generated "
                                                "when you change the above settings,\n but you can update it manually." ) ) ;
90
91

//     /* Connect everything to the updateMRL function */
92
 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
93
94
95
 #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
96
97
//     /* Output */
     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
98
99
100
     CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput );
     CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit );
     CS( HTTPPort ); CS( RTPPort ); CS( MMSHPort );
101
//     /* Transcode */
102
103
     CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
     CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
104
//     CB( sOverlay );
105
     CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
106
107
108
109
110
//     /* Mux */
     CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
     CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
//     /* Misc */
     CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
111
//
112
113
114
115
116
117
    CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
    CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse()  );
    CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
    CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
    CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
    CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
zorglub's avatar
zorglub committed
118

119
    okButton = new QPushButton( qtr( "&Stream" ) );
120
121
122
123
124
125
    QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );

    okButton->setDefault( true );
    ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
    ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );

126
127
    BUTTONACT( okButton, ok() );
    BUTTONACT( cancelButton, cancel() );
128

129
    if( b_transcode_only ) toggleSout();
zorglub's avatar
zorglub committed
130
131
}

132
133
134
135
136
QString SoutDialog::getMrl()
{
    return this->mrl;
}

zorglub's avatar
zorglub committed
137
void SoutDialog::fileBrowse()
138
139
{
    ui.tabWidget->setTabEnabled( 0,false );
140
141
142
    QString fileName = QFileDialog::getOpenFileName( this, qtr( "Save file" ), "",
        qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
    ui.fileEdit->setText( fileName );
zorglub's avatar
zorglub committed
143
144
145
    updateMRL();
}

146
void SoutDialog::setVTranscodeOptions( bool b_trans )
147
{
148
149
150
151
    ui.vCodecLabel->setEnabled( b_trans );
    ui.vCodecBox->setEnabled( b_trans );
    ui.vBitrateLabel->setEnabled( b_trans );
    ui.vBitrateSpin->setEnabled( b_trans );
152
    ui.vScaleLabel->setEnabled( b_trans );
153
    ui.vScaleBox->setEnabled( b_trans );
154
155
}

156
void SoutDialog::setATranscodeOptions( bool b_trans )
157
{
158
159
160
161
162
163
    ui.aCodecLabel->setEnabled( b_trans );
    ui.aCodecBox->setEnabled( b_trans );
    ui.aBitrateLabel->setEnabled( b_trans );
    ui.aBitrateSpin->setEnabled( b_trans );
    ui.aChannelsLabel->setEnabled( b_trans );
    ui.aChannelsSpin->setEnabled( b_trans );
164
165
}

166
void SoutDialog::setSTranscodeOptions( bool b_trans )
167
{
168
169
    ui.subsCodecBox->setEnabled( b_trans );
    ui.subsOverlay->setEnabled( b_trans );
170
171
}

172
void SoutDialog::setRawOptions( bool b_raw )
173
{
174
175
176
177
178
179
180
181
    if ( b_raw )
    {
        ui.tabWidget->setDisabled( true );
    }
    else
    {
        SoutDialog::setOptions();
    }
182
183
}

184
int indexFromItemData( QComboBox *aCombo, QString aString )
185
{
186
    for( int i=0; i < aCombo->count(); i++ )
187
    {
188
        if( aCombo->itemData( i ).toString() == aString ) return i;
189
    }
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    return -1;
}

void SoutDialog::setOptions()
{
    QString profileString = ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
    msg_Dbg( p_intf, "Profile Used: %s",  qta( profileString ));
    int index;

#define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
    { \
        ui.muxName ##Mux->setChecked( true ); \
        \
        ui.transcodeAudio->setChecked( hasAudio ); \
        index = indexFromItemData( ui.aCodecBox, vCodecName );  \
        if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
        \
        ui.transcodeVideo->setChecked( hasVideo ); \
        index = indexFromItemData( ui.aCodecBox, vCodecName );  \
        if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
210
    }
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

    /* ADD HERE the profiles you want and need */
    if( profileString == "IPod" ) setProfile( MP4, true, "mp4a", true, "mp4v" )
    else if( profileString == "XBox" ) setProfile( ASF, true, "wma", true, "WMV2" )

        /* If the profile is not a custom one, then disable the tabWidget */
        if ( profileString == "Custom" )
        {
            ui.tabWidget->setEnabled( true );
        }
        else
        {
            ui.tabWidget->setDisabled( true );
        }

    /* Update the MRL !! */
    updateMRL();
228
229
}

230
231
void SoutDialog::toggleSout()
{
232
    //Toggle all the streaming options.
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
233
234
235
236
237
    TOGGLEV( ui.HTTPOutput ) ; TOGGLEV( ui.RTPOutput ) ; TOGGLEV( ui.MMSHOutput ) ;
    TOGGLEV( ui.HTTPEdit ) ; TOGGLEV( ui.RTPEdit ) ; TOGGLEV( ui.MMSHEdit ) ;
    TOGGLEV( ui.HTTPLabel ) ; TOGGLEV( ui.RTPLabel ) ; TOGGLEV( ui.MMSHLabel ) ;
    TOGGLEV( ui.HTTPPortLabel ) ; TOGGLEV( ui.RTPPortLabel ) ; TOGGLEV( ui.MMSHPortLabel ) ;
    TOGGLEV( ui.HTTPPort ) ; TOGGLEV( ui.RTPPort ) ; TOGGLEV( ui.MMSHPort ) ;
238
239
240
241

    TOGGLEV( ui.sap ); TOGGLEV( ui.sapName );
    TOGGLEV( ui.sapGroup ); TOGGLEV( ui.sapGroupLabel );
    TOGGLEV( ui.ttlLabel ); TOGGLEV( ui.ttl );
242
243
244
245

    if( b_transcode_only ) okButton->setText( "&Save" );
    else okButton->setText( "&Stream" );

246
    updateGeometry();
247
248
}

zorglub's avatar
zorglub committed
249
250
void SoutDialog::ok()
{
zorglub's avatar
zorglub committed
251
252
    mrl = ui.mrlEdit->text();
    accept();
zorglub's avatar
zorglub committed
253
254
255
}
void SoutDialog::cancel()
{
zorglub's avatar
zorglub committed
256
257
    mrl = ui.mrlEdit->text();
    reject();
zorglub's avatar
zorglub committed
258
259
260
261
}

void SoutDialog::updateMRL()
{
262
263
    sout_gui_descr_t sout;
    memset( &sout, 0, sizeof( sout_gui_descr_t ) );
264
    int counter = 0;
265
266
267
268
269

    sout.b_local = ui.localOutput->isChecked();
    sout.b_file = ui.fileOutput->isChecked();
    sout.b_http = ui.HTTPOutput->isChecked();
    sout.b_mms = ui.MMSHOutput->isChecked();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
270
    sout.b_rtp = ui.RTPOutput->isChecked();
271
272
    sout.b_sap = ui.sap->isChecked();
    sout.b_all_es = ui.soutAll->isChecked();
273
274
275
    sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
    sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
    sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
276
277
278
    sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
    sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
    sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
279
    sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
280
281
    sout.i_http = ui.HTTPPort->value();
    sout.i_mms = ui.MMSHPort->value();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
282
    sout.i_rtp = ui.RTPPort->value();
283
284
285
286
    sout.i_ab = ui.aBitrateSpin->value();
    sout.i_vb = ui.vBitrateSpin->value();
    sout.i_channels = ui.aChannelsSpin->value();
    sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
287
288
289
    sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
    sout.psz_name = strdup( qtu( ui.sapName->text() ) );

290
291
292
293
294
295
296
297
298
299
#define COUNT() \
{ \
    if ( sout.b_local ) \
        counter += 1; \
    if ( sout.b_file ) \
        counter += 1; \
    if ( sout.b_http ) \
        counter += 1; \
    if ( sout.b_mms ) \
        counter += 1; \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
300
    if ( sout.b_rtp ) \
301
302
303
304
305
        counter += 1; \
}

COUNT()

306
#define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
307
308
309
310
311
312
313
314
315
316
    SMUX( PSMux, "ps" );
    SMUX( TSMux, "ts" );
    SMUX( MPEG1Mux, "mpeg" );
    SMUX( OggMux, "ogg" );
    SMUX( ASFMux, "asf" );
    SMUX( MP4Mux, "mp4" );
    SMUX( MOVMux, "mov" );
    SMUX( WAVMux, "wav" );
    SMUX( RAWMux, "raw" );
    SMUX( FLVMux, "flv" );
317
318
319
320

    bool trans = false;
    bool more = false;

321
    if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
322
    {
323
        if ( ui.transcodeVideo->isChecked() )
324
        {
325
326
327
328
329
330
            mrl = ":sout=#transcode{";
            mrl.append( "vcodec=" );
            mrl.append( sout.psz_vcodec );
            mrl.append( "," );
            mrl.append( "vb=" );
            mrl.append( QString::number( sout.i_vb,10 ) );
331
            mrl.append( "," );
332
333
334
            mrl.append( "scale=" );
            mrl.append( QString::number( sout.f_scale ) );
            trans = true;
335
        }
336
337

        if ( ui.transcodeAudio->isChecked() )
338
        {
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
            if ( trans )
            {
                mrl.append( "," );
            }
            else
            {
                mrl = ":sout=#transcode{";
            }
            mrl.append( "acodec=" );
            mrl.append( sout.psz_acodec );
            mrl.append( "," );
            mrl.append( "ab=" );
            mrl.append( QString::number( sout.i_ab,10 ) );
            mrl.append( "," );
            mrl.append( "channels=" );
            mrl.append( QString::number( sout.i_channels,10 ) );
            trans = true;
356
        }
357
        mrl.append( "}" );
358
    }
359

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
360
    if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_rtp )
361
362
363
364
    {

#define ISMORE() if ( more ) mrl.append( "," );

365
366
367
368
#define ATLEASTONE() \
        if ( counter > 1 ) \
        { \
            mrl.append( "dst=" ); \
369
        }
370
371
372
373
374
375

    if ( trans )
    {
        mrl.append( ":" );
    }
    else
376
377
378
379
        {
            mrl = ":sout=#";
        }

380
381
382
383
384
        if ( counter > 1 )
        {
            mrl.append( "duplicate{" );
        }

385
386
387
        if ( sout.b_local )
        {
            ISMORE();
388
389
            ATLEASTONE()
            mrl.append( "display" );
390
391
392
393
394
395
            more = true;
        }

        if ( sout.b_file )
        {
            ISMORE();
396
397
        ATLEASTONE()
            mrl.append( "std{access=file,mux=" );
398
399
400
401
402
403
404
405
406
407
            mrl.append( sout.psz_mux );
            mrl.append( ",dst=" );
            mrl.append( sout.psz_file );
            mrl.append( "}" );
            more = true;
        }

        if ( sout.b_http )
        {
            ISMORE();
408
409
            ATLEASTONE()
            mrl.append( "std{access=http,mux=" );
410
411
412
413
414
415
416
417
418
419
420
421
            mrl.append( sout.psz_mux );
            mrl.append( ",dst=" );
            mrl.append( sout.psz_http );
            mrl.append( ":" );
            mrl.append( QString::number( sout.i_http,10 ) );
            mrl.append( "}" );
            more = true;
        }

        if ( sout.b_mms )
        {
            ISMORE();
422
423
            ATLEASTONE()
            mrl.append( "std{access=mmsh,mux=" );
424
425
426
427
428
429
430
431
432
            mrl.append( sout.psz_mux );
            mrl.append( ",dst=" );
            mrl.append( sout.psz_mms );
            mrl.append( ":" );
            mrl.append( QString::number( sout.i_mms,10 ) );
            mrl.append( "}" );
            more = true;
        }

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
433
        if ( sout.b_rtp )
434
435
        {
            ISMORE();
436
            ATLEASTONE()
437
            mrl.append( "rtp{mux=" );
438
439
            mrl.append( sout.psz_mux );
            mrl.append( ",dst=" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
440
            mrl.append( sout.psz_rtp );
441
            mrl.append( ":" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
442
            mrl.append( QString::number( sout.i_rtp,10 ) );
443
444
445
446
447
448
449
450
451
452
453
454
455
456
            if ( sout.b_sap )
            {
                mrl.append( ",sap," );
                mrl.append( "group=\"" );
                mrl.append( sout.psz_group );
                mrl.append( "\"," );
                mrl.append( "name=\"" );
                mrl.append( sout.psz_name );
                mrl.append( "\"" );
            }
            mrl.append( "}" );
            more = true;
        }

457
        if ( counter > 1 )
458
459
460
461
462
463
        {
            mrl.append( "}" );
        }
    }

    if ( sout.b_all_es )
464
        mrl.append( ":sout-all" );
465
466
467
468

    ui.mrlEdit->setText( mrl );
    free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
    free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
469
    free( sout.psz_rtp ); free( sout.psz_mux );
470
    free( sout.psz_name ); free( sout.psz_group );
471
}