]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Fix typos and stupid code errors to make profiles work.
[vlc] / modules / gui / qt4 / dialogs / sout.cpp
1 /*****************************************************************************
2  * sout.cpp : Stream output dialog ( old-style )
3  ****************************************************************************
4  * Copyright (C) 2007-2008 the VideoLAN team
5  * Copyright (C) 2007 Société des arts technologiques
6  * Copyright (C) 2007 Savoir-faire Linux
7  *
8  * $Id$
9  *
10  * Authors: Clément Stenac <zorglub@videolan.org>
11  *          Jean-Baptiste Kempf <jb@videolan.org>
12  *          Jean-François Massol <jf.massol -at- gmail.com>
13  *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * ( at your option ) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
28  *****************************************************************************/
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include "dialogs/sout.hpp"
35
36 #include <QString>
37 #include <QFileDialog>
38
39 struct streaming_account_t
40 {
41     char *psz_username; /*< username of account */
42     char *psz_password; /*< password of account */
43 };
44
45 struct sout_gui_descr_t
46 {
47     /* Access types */
48     bool b_local;   /*< local access module */
49     bool b_file;    /*< file access module */
50     bool b_http;    /*< http access module */
51     bool b_mms;     /*< mms access module */
52     bool b_rtp;     /*< rtp access module */
53     bool b_udp;     /*< udp access module */
54     bool b_dump;    /*< dump access module */
55     bool b_icecast; /*< icecast access module */
56
57     char *psz_file;     /*< filename */
58     char *psz_http;     /*< HTTP servername or ipaddress */
59     char *psz_mms;      /*< MMS servername or ipaddress */
60     char *psz_rtp;      /*< RTP servername or ipaddress */
61     char *psz_udp;      /*< UDP servername or ipaddress */
62     char *psz_icecast;  /*< Icecast servername or ipaddress*/
63
64     int32_t i_http;     /*< http port number */
65     int32_t i_mms;      /*< mms port number */
66     int32_t i_rtp;      /*< rtp port number */
67     int32_t i_rtp_audio;      /*< rtp port number */
68     int32_t i_rtp_video;      /*< rtp port number */
69     int32_t i_udp;      /*< udp port number */
70     int32_t i_icecast;  /*< icecast port number */
71
72     /* Mux */
73     char *psz_mux;      /*< name of muxer to use in streaming */
74
75     /* Transcode */
76     bool b_soverlay; /*< enable burning overlay in the video */
77     char *psz_vcodec;   /*< video codec to use in transcoding */
78     char *psz_acodec;   /*< audio codec to use in transcoding */
79     char *psz_scodec;   /*< subtitle codec to use in transcoding */
80     int32_t i_vb;       /*< video bitrate to use in transcoding */
81     int32_t i_ab;       /*< audio bitrate to use in transcoding */
82     int32_t i_channels; /*< number of audio channels to use in transcoding */
83     float f_scale;      /*< scaling factor to use in transcoding */
84
85     /* Misc */
86     bool b_sap;   /*< send SAP announcement */
87     bool b_all_es;/*< send all elementary streams from source stream */
88     char *psz_group;    /*< SAP Group name */
89     char *psz_name;     /*< SAP name */
90     int32_t i_ttl;      /*< Time To Live (TTL) for network traversal */
91
92     /* Icecast */
93     char *psz_icecast_mountpoint;/*< path to Icecast mountpoint */
94     struct streaming_account_t sa_icecast;  /*< Icecast account information */
95 };
96
97 SoutDialog* SoutDialog::instance = NULL;
98
99 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
100                      bool _transcode_only ) : QVLCDialog( parent,  _p_intf )
101 {
102     setWindowTitle( qtr( "Stream Output" ) );
103
104     b_transcode_only = _transcode_only;
105
106     /* UI stuff */
107     ui.setupUi( this );
108
109     changeUDPandRTPmess( false );
110
111 /* ADD HERE for new profiles */
112 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
113     ADD_PROFILE( "Custom" , "Custom" )
114     ADD_PROFILE( "Ogg / Theora", "theora" )
115     ADD_PROFILE( "Ogg / Vorbis", "vorbis" )
116     ADD_PROFILE( "MPEG-2", "mpeg2" )
117     ADD_PROFILE( "MP3", "mp3" )
118     ADD_PROFILE( "MPEG-4 audio AAC", "aac" )
119     ADD_PROFILE( "MPEG-4 / DivX", "mp4" )
120     ADD_PROFILE( "H264", "h264" )
121     ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
122     ADD_PROFILE( "XBox", "XBox" )
123     ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
124     ADD_PROFILE( "PSP", "PSP")
125
126 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
127     ADD_VCODEC( "MPEG-1", "mp1v" )
128     ADD_VCODEC( "MPEG-2", "mp2v" )
129     ADD_VCODEC( "MPEG-4", "mp4v" )
130     ADD_VCODEC( "DIVX 1" , "DIV1" )
131     ADD_VCODEC( "DIVX 2" , "DIV2" )
132     ADD_VCODEC( "DIVX 3" , "DIV3" )
133     ADD_VCODEC( "H-263", "H263" )
134     ADD_VCODEC( "H-264", "h264" )
135     ADD_VCODEC( "WMV1", "WMV1" )
136     ADD_VCODEC( "WMV2" , "WMV2" )
137     ADD_VCODEC( "M-JPEG", "MJPG" )
138     ADD_VCODEC( "Theora", "theo" )
139
140 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
141     ADD_ACODEC( "MPEG Audio", "mpga" )
142     ADD_ACODEC( "MP3", "mp3" )
143     ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
144     ADD_ACODEC( "A52/AC-3", "a52" )
145     ADD_ACODEC( "Vorbis", "vorb" )
146     ADD_ACODEC( "Flac", "flac" )
147     ADD_ACODEC( "Speex", "spx" )
148     ADD_ACODEC( "WAV", "s16l" )
149     ADD_ACODEC( "WMA", "wma" )
150
151 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
152     ADD_SCALING( "0.25" )
153     ADD_SCALING( "0.5" )
154     ADD_SCALING( "0.75" )
155     ADD_SCALING( "1" )
156     ADD_SCALING( "1.25" )
157     ADD_SCALING( "1.5" )
158     ADD_SCALING( "1.75" )
159     ADD_SCALING( "2" )
160
161     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
162                 "This is automatically generated "
163                  "when you change the above settings,\n"
164                  "but you can update it manually." ) ) ;
165
166 //     /* Connect everything to the updateMRL function */
167  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
168  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
169  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
170  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
171     /* Output */
172     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
173     CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
174     CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
175     CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
176     CS( HTTPPort ); CS( RTPPort ); CS( RTPPort2 ); CS( MMSHPort ); CS( UDPPort );
177     /* Transcode */
178     CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
179     CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
180     /*   CB( sOverlay ); */
181     CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
182     /* Mux */
183     CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
184     CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
185     /* Misc */
186     CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
187
188     CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
189     CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse()  );
190     CONNECT( ui.transcodeVideo, toggled( bool ),
191             this, setVTranscodeOptions( bool ) );
192     CONNECT( ui.transcodeAudio, toggled( bool ),
193             this, setATranscodeOptions( bool ) );
194     CONNECT( ui.transcodeSubs, toggled( bool ),
195             this, setSTranscodeOptions( bool ) );
196     CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
197
198     okButton = new QPushButton( qtr( "&Stream" ) );
199     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
200
201     okButton->setDefault( true );
202     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
203     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
204
205     BUTTONACT( okButton, ok() );
206     BUTTONACT( cancelButton, cancel() );
207
208     CONNECT( ui.UDPOutput, toggled( bool ), this, changeUDPandRTPmess( bool ) );
209     CONNECT( ui.RTPOutput, clicked(bool), this, RTPtoggled( bool ) );
210
211     if( b_transcode_only ) toggleSout();
212 }
213
214 void SoutDialog::fileBrowse()
215 {
216     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
217         qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
218     ui.fileEdit->setText( fileName );
219     updateMRL();
220 }
221
222 void SoutDialog::setVTranscodeOptions( bool b_trans )
223 {
224     ui.vCodecLabel->setEnabled( b_trans );
225     ui.vCodecBox->setEnabled( b_trans );
226     ui.vBitrateLabel->setEnabled( b_trans );
227     ui.vBitrateSpin->setEnabled( b_trans );
228     ui.vScaleLabel->setEnabled( b_trans );
229     ui.vScaleBox->setEnabled( b_trans );
230 }
231
232 void SoutDialog::setATranscodeOptions( bool b_trans )
233 {
234     ui.aCodecLabel->setEnabled( b_trans );
235     ui.aCodecBox->setEnabled( b_trans );
236     ui.aBitrateLabel->setEnabled( b_trans );
237     ui.aBitrateSpin->setEnabled( b_trans );
238     ui.aChannelsLabel->setEnabled( b_trans );
239     ui.aChannelsSpin->setEnabled( b_trans );
240 }
241
242 void SoutDialog::setSTranscodeOptions( bool b_trans )
243 {
244     ui.subsCodecBox->setEnabled( b_trans );
245     ui.subsOverlay->setEnabled( b_trans );
246 }
247
248 void SoutDialog::setRawOptions( bool b_raw )
249 {
250     ui.localOutput->setEnabled( !b_raw );
251     ui.HTTPOutput->setEnabled( !b_raw );
252     ui.MMSHOutput->setEnabled( !b_raw );
253     ui.UDPOutput->setEnabled( !b_raw );
254     ui.RTPOutput->setEnabled( !b_raw );
255     ui.IcecastOutput->setEnabled( !b_raw );
256     ui.UDPRTPLabel->setEnabled( !b_raw );
257
258     if( b_raw )
259         ui.tabWidget->setDisabled( true );
260     else
261         setOptions();
262 }
263
264 void SoutDialog::setOptions()
265 {
266     QString profileString =
267         ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
268     msg_Dbg( p_intf, "Profile Used: %s",  qta( profileString ));
269     int index;
270
271 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
272     { \
273         ui.muxName ##Mux->setChecked( true ); \
274         \
275         ui.transcodeAudio->setChecked( hasAudio ); \
276         index = ui.aCodecBox->findData( aCodecName );  \
277         if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
278         \
279         ui.transcodeVideo->setChecked( hasVideo ); \
280         index = ui.vCodecBox->findData( vCodecName );  \
281         if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
282     }
283
284     /* ADD HERE the profiles you want and need */
285     if( profileString == "IPod" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
286     else if( profileString == "theora" ) setProfile( Ogg, true, "theo", true, "vorb" )
287     else if( profileString == "vorbis" ) setProfile( Ogg, false, "", true, "vorb" )
288     else if( profileString == "mpeg2" ) setProfile( TS, true, "mp2v", true, "mpga" )
289     else if( profileString == "mp3" ) setProfile( RAW, false, "", true, "mp3" )
290     else if( profileString == "aac" ) setProfile( MP4, false, "", true, "mp4a" )
291     else if( profileString == "mp4" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
292     else if( profileString == "h264" ) setProfile( TS, true, "h264", true, "mp4a" )
293     else if( profileString == "XBox" ) setProfile( ASF, true, "WMV2", true, "wma" )
294     else if( profileString == "Windows" ) setProfile( ASF, true, "WMV2", true, "wma" )
295     else if( profileString == "PSP" ) setProfile( Ogg, true, "DIV3", true, "vorb" )
296
297         /* If the profile is not a custom one, then disable the tabWidget */
298         if ( profileString == "Custom" )
299             ui.tabWidget->setEnabled( true );
300         else
301             ui.tabWidget->setDisabled( true );
302
303     /* Update the MRL !! */
304     updateMRL();
305 }
306
307 void SoutDialog::toggleSout()
308 {
309     //Toggle all the streaming options.
310 #define HIDEORSHOW(x) if( b_transcode_only ) x->hide(); else x->show();
311     HIDEORSHOW( ui.HTTPOutput ) ; HIDEORSHOW( ui.RTPOutput ) ; HIDEORSHOW( ui.MMSHOutput ) ; HIDEORSHOW( ui.UDPOutput ) ;
312     HIDEORSHOW( ui.HTTPEdit ) ; HIDEORSHOW( ui.RTPEdit ) ; HIDEORSHOW( ui.MMSHEdit ) ; HIDEORSHOW( ui.UDPEdit ) ;
313     HIDEORSHOW( ui.HTTPLabel ) ; HIDEORSHOW( ui.RTPLabel ) ; HIDEORSHOW( ui.MMSHLabel ) ; HIDEORSHOW( ui.UDPLabel ) ;
314     HIDEORSHOW( ui.HTTPPortLabel ) ; HIDEORSHOW( ui.RTPPortLabel ) ; HIDEORSHOW( ui.MMSHPortLabel ) ; HIDEORSHOW( ui.UDPPortLabel )
315     HIDEORSHOW( ui.HTTPPort ) ; HIDEORSHOW( ui.RTPPort ) ; HIDEORSHOW( ui.MMSHPort ) ; HIDEORSHOW( ui.UDPPort ) ; HIDEORSHOW( ui.RTPPortLabel2 ); HIDEORSHOW( ui.RTPPort2 ); HIDEORSHOW( ui.UDPRTPLabel )
316
317     HIDEORSHOW( ui.sap ); HIDEORSHOW( ui.sapName );
318     HIDEORSHOW( ui.sapGroup ); HIDEORSHOW( ui.sapGroupLabel );
319     HIDEORSHOW( ui.ttlLabel ); HIDEORSHOW( ui.ttl );
320
321     HIDEORSHOW( ui.IcecastOutput ); HIDEORSHOW( ui.IcecastEdit );
322     HIDEORSHOW( ui.IcecastNamePassEdit ); HIDEORSHOW( ui.IcecastMountpointEdit );
323     HIDEORSHOW( ui.IcecastPort ); HIDEORSHOW( ui.IcecastLabel );
324     HIDEORSHOW( ui.IcecastPortLabel );
325     HIDEORSHOW( ui.IcecastMountpointLabel ); HIDEORSHOW( ui.IcecastNameLabel );
326 #undef HIDEORSHOW
327
328     if( b_transcode_only ) okButton->setText( "&Save" );
329     else okButton->setText( "&Stream" );
330
331     setMinimumHeight( 500 );
332     resize( width(), sizeHint().height() );
333 }
334
335 void SoutDialog::changeUDPandRTPmess( bool b_udp )
336 {
337     ui.RTPEdit->setVisible( !b_udp );
338     ui.RTPLabel->setVisible( !b_udp );
339     ui.RTPPort->setVisible( !b_udp );
340     ui.RTPPortLabel->setVisible( !b_udp );
341     ui.UDPEdit->setVisible( b_udp );
342     ui.UDPLabel->setVisible( b_udp );
343     ui.UDPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Audio Port:" ) );
344     ui.RTPPort2->setVisible( !b_udp );
345     ui.RTPPortLabel2->setVisible( !b_udp );
346 }
347
348 void SoutDialog::RTPtoggled( bool b_en )
349 {
350     if( !b_en )
351     {
352         if( ui.RTPPort->value() == ui.UDPPort->value() )
353         {
354             ui.UDPPort->setValue( ui.UDPPort->value() + 1 );
355         }
356
357         while( ui.RTPPort2->value() == ui.UDPPort->value() ||
358                 ui.RTPPort2->value() == ui.RTPPort->value() )
359         {
360             ui.RTPPort2->setValue( ui.RTPPort2->value() + 1 );
361         }
362     }
363     ui.sap->setEnabled( b_en );
364     ui.RTPLabel->setEnabled( b_en );
365     ui.RTPEdit->setEnabled( b_en );
366     ui.UDPOutput->setEnabled( b_en );
367     ui.UDPEdit->setEnabled( b_en );
368     ui.UDPPort->setEnabled( b_en );
369     ui.UDPPortLabel->setEnabled( b_en );
370     ui.RTPPort2->setEnabled( b_en );
371     ui.RTPPortLabel2->setEnabled( b_en );
372 }
373
374 void SoutDialog::ok()
375 {
376     mrl = ui.mrlEdit->text();
377     accept();
378 }
379
380 void SoutDialog::cancel()
381 {
382     mrl.clear();
383     reject();
384 }
385
386 void SoutDialog::updateMRL()
387 {
388     sout_gui_descr_t sout;
389     memset( &sout, 0, sizeof( sout_gui_descr_t ) );
390     unsigned int counter = 0;
391
392     sout.b_local = ui.localOutput->isChecked();
393     sout.b_file = ui.fileOutput->isChecked();
394     sout.b_http = ui.HTTPOutput->isChecked();
395     sout.b_mms = ui.MMSHOutput->isChecked();
396     sout.b_icecast = ui.IcecastOutput->isChecked();
397     sout.b_rtp = ui.RTPOutput->isChecked();
398     sout.b_udp = ui.UDPOutput->isChecked();
399     sout.b_dump = ui.rawInput->isChecked();
400     sout.b_sap = ui.sap->isChecked();
401     sout.b_all_es = ui.soutAll->isChecked();
402     sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
403     sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
404     sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
405     sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
406     sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
407     sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
408     sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
409     sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
410     sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
411     sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
412     sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
413     sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
414     sout.i_http = ui.HTTPPort->value();
415     sout.i_mms = ui.MMSHPort->value();
416     sout.i_rtp = ui.RTPPort->value();
417     sout.i_rtp_audio = sout.i_udp = ui.UDPPort->value();
418     sout.i_rtp_video = ui.RTPPort2->value();
419     sout.i_icecast = ui.IcecastPort->value();
420     sout.i_ab = ui.aBitrateSpin->value();
421     sout.i_vb = ui.vBitrateSpin->value();
422     sout.i_channels = ui.aChannelsSpin->value();
423     sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
424     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
425     sout.psz_name = strdup( qtu( ui.sapName->text() ) );
426
427     if ( sout.b_local ) counter++ ;
428     if ( sout.b_file ) counter++ ;
429     if ( sout.b_http ) counter++ ;
430     if ( sout.b_mms ) counter++ ;
431     if ( sout.b_rtp ) counter++ ;
432     if ( sout.b_udp ) counter ++;
433     if ( sout.b_icecast ) counter ++;
434
435 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
436     SMUX( PSMux, "ps" );
437     SMUX( TSMux, "ts" );
438     SMUX( MPEG1Mux, "mpeg" );
439     SMUX( OggMux, "ogg" );
440     SMUX( ASFMux, "asf" );
441     SMUX( MP4Mux, "mp4" );
442     SMUX( MOVMux, "mov" );
443     SMUX( WAVMux, "wav" );
444     SMUX( RAWMux, "raw" );
445     SMUX( FLVMux, "flv" );
446     SMUX( MKVMux, "mkv" );
447
448     bool trans = false;
449     bool more = false;
450
451     if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked()
452          && !ui.rawInput->isChecked() /*demuxdump speciality*/ )
453     {
454         if ( ui.transcodeVideo->isChecked() )
455         {
456             mrl = ":sout=#transcode{";
457             mrl.append( "vcodec=" );
458             mrl.append( sout.psz_vcodec );
459             mrl.append( "," );
460             mrl.append( "vb=" );
461             mrl.append( QString::number( sout.i_vb,10 ) );
462             mrl.append( "," );
463             mrl.append( "scale=" );
464             mrl.append( QString::number( sout.f_scale ) );
465             trans = true;
466         }
467
468         if ( ui.transcodeAudio->isChecked() )
469         {
470             if ( trans )
471             {
472                 mrl.append( "," );
473             }
474             else
475             {
476                 mrl = ":sout=#transcode{";
477             }
478             mrl.append( "acodec=" );
479             mrl.append( sout.psz_acodec );
480             mrl.append( "," );
481             mrl.append( "ab=" );
482             mrl.append( QString::number( sout.i_ab,10 ) );
483             mrl.append( "," );
484             mrl.append( "channels=" );
485             mrl.append( QString::number( sout.i_channels,10 ) );
486             trans = true;
487         }
488         mrl.append( "}" );
489     }
490
491     /* Special case for demuxdump */
492     if ( sout.b_file && sout.b_dump )
493     {
494         mrl = ":demux=dump :demuxdump-file=";
495         mrl.append( sout.psz_file );
496     }
497     else
498
499
500     /* Protocol output */
501     if ( sout.b_local || sout.b_file || sout.b_http ||
502          sout.b_mms || sout.b_rtp || sout.b_udp || sout.b_icecast )
503     {
504
505 #define ISMORE() if ( more ) mrl.append( "," )
506 #define ATLEASTONE() if ( counter ) mrl.append( "dst=" )
507
508 #define CHECKMUX() \
509        if( sout.psz_mux ) \
510        {                  \
511          mrl.append( ",mux=");\
512          mrl.append( sout.psz_mux ); \
513        }
514
515         if ( trans )
516             mrl.append( ":" );
517         else
518             mrl = ":sout=#";
519
520         if ( counter )
521             mrl.append( "duplicate{" );
522
523         if ( sout.b_local )
524         {
525             ISMORE();
526             ATLEASTONE();
527             mrl.append( "display" );
528             more = true;
529         }
530
531         if ( sout.b_file )
532         {
533             ISMORE();
534             ATLEASTONE();
535             mrl.append( "std{access=file" );
536             CHECKMUX();
537             mrl.append( ",dst=" );
538             mrl.append( sout.psz_file );
539             mrl.append( "}" );
540             more = true;
541         }
542
543         if ( sout.b_http )
544         {
545             ISMORE();
546             ATLEASTONE();
547             mrl.append( "std{access=http" );
548             CHECKMUX();
549             mrl.append( ",dst=" );
550             mrl.append( sout.psz_http );
551             mrl.append( ":" );
552             mrl.append( QString::number( sout.i_http,10 ) );
553             mrl.append( "}" );
554             more = true;
555         }
556
557         if ( sout.b_mms )
558         {
559             ISMORE();
560             ATLEASTONE();
561             mrl.append( "std{access=mmsh" );
562             CHECKMUX();
563             mrl.append( ",dst=" );
564             mrl.append( sout.psz_mms );
565             mrl.append( ":" );
566             mrl.append( QString::number( sout.i_mms,10 ) );
567             mrl.append( "}" );
568             more = true;
569         }
570
571         if ( sout.b_rtp )
572         {
573             ISMORE();
574             ATLEASTONE();
575             if ( sout.b_udp )
576             {
577                 mrl.append( "std{access=udp" );
578                 CHECKMUX();
579                 mrl.append( ",dst=" );
580                 mrl.append( sout.psz_udp );
581                 mrl.append( ":" );
582                 mrl.append( QString::number( sout.i_udp,10 ) );
583             }
584             else
585             {
586                 mrl.append( "rtp{" );
587                 mrl.append( "dst=" );
588                 mrl.append( sout.psz_rtp );
589                 CHECKMUX();
590                 mrl.append( ",port=" );
591                 mrl.append( QString::number( sout.i_rtp,10 ) );
592                 if( !sout.psz_mux || strncmp( sout.psz_mux, "ts", 2 ) )
593                 {
594                     mrl.append( ",port-audio=" );
595                     mrl.append( QString::number( sout.i_rtp_audio, 10 ) );
596                     mrl.append( ",port-video=" );
597                     mrl.append( QString::number( sout.i_rtp_video, 10 ) );
598                 }
599             }
600
601             /* SAP */
602             if ( sout.b_sap )
603             {
604                 mrl.append( ",sap," );
605                 mrl.append( "group=\"" );
606                 mrl.append( sout.psz_group );
607                 mrl.append( "\"," );
608                 mrl.append( "name=\"" );
609                 mrl.append( sout.psz_name );
610                 mrl.append( "\"" );
611             }
612
613             mrl.append( "}" );
614             more = true;
615         }
616
617         if( sout.b_icecast )
618         {
619             ISMORE();
620             ATLEASTONE();
621             mrl.append( "std{access=shout,mux=ogg" );
622             mrl.append( ",dst=" );
623             mrl.append( sout.sa_icecast.psz_username );
624             mrl.append( "@" );
625             mrl.append( sout.psz_icecast );
626             mrl.append( ":" );
627             mrl.append( QString::number( sout.i_icecast, 10 ) );
628             mrl.append( "/" );
629             mrl.append( sout.psz_icecast_mountpoint );
630             mrl.append( "}" );
631             more = true;
632         }
633
634         if ( counter )
635         {
636             mrl.append( "}" );
637         }
638     }
639
640 #undef CHECKMUX
641
642     if ( sout.b_all_es )
643         mrl.append( ":sout-all" );
644
645     ui.mrlEdit->setText( mrl );
646     free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
647     free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
648     free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
649     free( sout.psz_name ); free( sout.psz_group );
650     free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
651     free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );
652 }