]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Implemented sout string escaping in QT.
[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 class SoutMrl
98 {
99 public:
100     SoutMrl( const QString head = "")
101     {
102         mrl = head;
103         b_first = true;
104         b_has_bracket = false;
105     }
106
107     QString getMrl()
108     {
109         return mrl;
110     }
111
112     void begin( QString module )
113     {
114         if( !b_first )
115             mrl += ":";
116         b_first = false;
117
118         mrl += module;
119         b_has_bracket = false;
120     }
121     void end()
122     {
123         if( b_has_bracket )
124             mrl += "}";
125     }
126     void option( const QString option, const QString value = "" )
127     {
128         if( !b_has_bracket )
129             mrl += "{";
130         else
131             mrl += ",";
132         b_has_bracket = true;
133
134         mrl += option;
135
136         if( !value.isEmpty() )
137         {
138             char *psz = config_StringEscape( qta(value) );
139             if( psz )
140             {
141                 QString v = QString( psz );
142
143                 mrl += "=\"" + v + "\"";
144
145                 free( psz );
146             }
147         }
148     }
149     void option( const QString name, const int i_value, const int i_precision = 10 )
150     {
151         option( name, QString::number( i_value, i_precision ) );
152     }
153     void option( const QString name, const double f_value )
154     {
155         option( name, QString::number( f_value ) );
156     }
157
158     void option( const QString name, const QString base, const int i_value, const int i_precision = 10 )
159     {
160         option( name, base + ":" + QString::number( i_value, i_precision ) );
161     }
162
163 private:
164     QString mrl;
165     bool b_has_bracket;
166     bool b_first;
167 };
168
169 SoutDialog* SoutDialog::instance = NULL;
170
171 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
172                      bool _transcode_only ) : QVLCDialog( parent,  _p_intf )
173 {
174     setWindowTitle( qtr( "Stream Output" ) );
175
176     b_transcode_only = _transcode_only;
177
178     /* UI stuff */
179     ui.setupUi( this );
180
181     changeUDPandRTPmess( false );
182
183 /* ADD HERE for new profiles */
184 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
185     ADD_PROFILE( "Custom" , "Custom" )
186     ADD_PROFILE( "Ogg / Theora", "theora" )
187     ADD_PROFILE( "Ogg / Vorbis", "vorbis" )
188     ADD_PROFILE( "MPEG-2", "mpeg2" )
189     ADD_PROFILE( "MP3", "mp3" )
190     ADD_PROFILE( "MPEG-4 audio AAC", "aac" )
191     ADD_PROFILE( "MPEG-4 / DivX", "mp4" )
192     ADD_PROFILE( "H264", "h264" )
193     ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
194     ADD_PROFILE( "XBox", "XBox" )
195     ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
196     ADD_PROFILE( "PSP", "PSP")
197
198 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
199     ADD_VCODEC( "MPEG-1", "mp1v" )
200     ADD_VCODEC( "MPEG-2", "mp2v" )
201     ADD_VCODEC( "MPEG-4", "mp4v" )
202     ADD_VCODEC( "DIVX 1" , "DIV1" )
203     ADD_VCODEC( "DIVX 2" , "DIV2" )
204     ADD_VCODEC( "DIVX 3" , "DIV3" )
205     ADD_VCODEC( "H-263", "H263" )
206     ADD_VCODEC( "H-264", "h264" )
207     ADD_VCODEC( "WMV1", "WMV1" )
208     ADD_VCODEC( "WMV2" , "WMV2" )
209     ADD_VCODEC( "M-JPEG", "MJPG" )
210     ADD_VCODEC( "Theora", "theo" )
211
212 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
213     ADD_ACODEC( "MPEG Audio", "mpga" )
214     ADD_ACODEC( "MP3", "mp3" )
215     ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
216     ADD_ACODEC( "A52/AC-3", "a52" )
217     ADD_ACODEC( "Vorbis", "vorb" )
218     ADD_ACODEC( "Flac", "flac" )
219     ADD_ACODEC( "Speex", "spx" )
220     ADD_ACODEC( "WAV", "s16l" )
221     ADD_ACODEC( "WMA", "wma" )
222
223 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
224     ADD_SCALING( "0.25" )
225     ADD_SCALING( "0.5" )
226     ADD_SCALING( "0.75" )
227     ADD_SCALING( "1" )
228     ADD_SCALING( "1.25" )
229     ADD_SCALING( "1.5" )
230     ADD_SCALING( "1.75" )
231     ADD_SCALING( "2" )
232
233     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
234                 "This is automatically generated "
235                  "when you change the above settings,\n"
236                  "but you can update it manually." ) ) ;
237
238 //     /* Connect everything to the updateMRL function */
239  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
240  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
241  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
242  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
243     /* Output */
244     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
245     CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
246     CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
247     CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
248     CS( HTTPPort ); CS( RTPPort ); CS( RTPPort2 ); CS( MMSHPort ); CS( UDPPort );
249     /* Transcode */
250     CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
251     CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
252     /*   CB( sOverlay ); */
253     CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
254     /* Mux */
255     CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
256     CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
257     /* Misc */
258     CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
259
260     CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
261     CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse()  );
262     CONNECT( ui.transcodeVideo, toggled( bool ),
263             this, setVTranscodeOptions( bool ) );
264     CONNECT( ui.transcodeAudio, toggled( bool ),
265             this, setATranscodeOptions( bool ) );
266     CONNECT( ui.transcodeSubs, toggled( bool ),
267             this, setSTranscodeOptions( bool ) );
268     CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
269
270     okButton = new QPushButton( qtr( "&Stream" ) );
271     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
272
273     okButton->setDefault( true );
274     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
275     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
276
277     BUTTONACT( okButton, ok() );
278     BUTTONACT( cancelButton, cancel() );
279
280     CONNECT( ui.UDPOutput, toggled( bool ), this, changeUDPandRTPmess( bool ) );
281     CONNECT( ui.RTPOutput, clicked(bool), this, RTPtoggled( bool ) );
282
283     if( b_transcode_only ) toggleSout();
284 }
285
286 void SoutDialog::fileBrowse()
287 {
288     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
289         qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
290     ui.fileEdit->setText( fileName );
291     updateMRL();
292 }
293
294 void SoutDialog::setVTranscodeOptions( bool b_trans )
295 {
296     ui.vCodecLabel->setEnabled( b_trans );
297     ui.vCodecBox->setEnabled( b_trans );
298     ui.vBitrateLabel->setEnabled( b_trans );
299     ui.vBitrateSpin->setEnabled( b_trans );
300     ui.vScaleLabel->setEnabled( b_trans );
301     ui.vScaleBox->setEnabled( b_trans );
302 }
303
304 void SoutDialog::setATranscodeOptions( bool b_trans )
305 {
306     ui.aCodecLabel->setEnabled( b_trans );
307     ui.aCodecBox->setEnabled( b_trans );
308     ui.aBitrateLabel->setEnabled( b_trans );
309     ui.aBitrateSpin->setEnabled( b_trans );
310     ui.aChannelsLabel->setEnabled( b_trans );
311     ui.aChannelsSpin->setEnabled( b_trans );
312 }
313
314 void SoutDialog::setSTranscodeOptions( bool b_trans )
315 {
316     ui.subsCodecBox->setEnabled( b_trans );
317     ui.subsOverlay->setEnabled( b_trans );
318 }
319
320 void SoutDialog::setRawOptions( bool b_raw )
321 {
322     ui.localOutput->setEnabled( !b_raw );
323     ui.HTTPOutput->setEnabled( !b_raw );
324     ui.MMSHOutput->setEnabled( !b_raw );
325     ui.UDPOutput->setEnabled( !b_raw );
326     ui.RTPOutput->setEnabled( !b_raw );
327     ui.IcecastOutput->setEnabled( !b_raw );
328     ui.UDPRTPLabel->setEnabled( !b_raw );
329
330     if( b_raw )
331         ui.tabWidget->setDisabled( true );
332     else
333         setOptions();
334 }
335
336 void SoutDialog::setOptions()
337 {
338     QString profileString =
339         ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
340     msg_Dbg( p_intf, "Profile Used: %s",  qta( profileString ));
341     int index;
342
343 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
344     { \
345         ui.muxName ##Mux->setChecked( true ); \
346         \
347         ui.transcodeAudio->setChecked( hasAudio ); \
348         index = ui.aCodecBox->findData( aCodecName );  \
349         if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
350         \
351         ui.transcodeVideo->setChecked( hasVideo ); \
352         index = ui.vCodecBox->findData( vCodecName );  \
353         if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
354     }
355
356     /* ADD HERE the profiles you want and need */
357     if( profileString == "IPod" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
358     else if( profileString == "theora" ) setProfile( Ogg, true, "theo", true, "vorb" )
359     else if( profileString == "vorbis" ) setProfile( Ogg, false, "", true, "vorb" )
360     else if( profileString == "mpeg2" ) setProfile( TS, true, "mp2v", true, "mpga" )
361     else if( profileString == "mp3" ) setProfile( RAW, false, "", true, "mp3" )
362     else if( profileString == "aac" ) setProfile( MP4, false, "", true, "mp4a" )
363     else if( profileString == "mp4" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
364     else if( profileString == "h264" ) setProfile( TS, true, "h264", true, "mp4a" )
365     else if( profileString == "XBox" ) setProfile( ASF, true, "WMV2", true, "wma" )
366     else if( profileString == "Windows" ) setProfile( ASF, true, "WMV2", true, "wma" )
367     else if( profileString == "PSP" ) setProfile( Ogg, true, "DIV3", true, "vorb" )
368
369         /* If the profile is not a custom one, then disable the tabWidget */
370         if ( profileString == "Custom" )
371             ui.tabWidget->setEnabled( true );
372         else
373             ui.tabWidget->setDisabled( true );
374
375     /* Update the MRL !! */
376     updateMRL();
377 }
378
379 void SoutDialog::toggleSout()
380 {
381     //Toggle all the streaming options.
382 #define HIDEORSHOW(x) if( b_transcode_only ) x->hide(); else x->show();
383     HIDEORSHOW( ui.HTTPOutput ) ; HIDEORSHOW( ui.RTPOutput ) ; HIDEORSHOW( ui.MMSHOutput ) ; HIDEORSHOW( ui.UDPOutput ) ;
384     HIDEORSHOW( ui.HTTPEdit ) ; HIDEORSHOW( ui.RTPEdit ) ; HIDEORSHOW( ui.MMSHEdit ) ; HIDEORSHOW( ui.UDPEdit ) ;
385     HIDEORSHOW( ui.HTTPLabel ) ; HIDEORSHOW( ui.RTPLabel ) ; HIDEORSHOW( ui.MMSHLabel ) ; HIDEORSHOW( ui.UDPLabel ) ;
386     HIDEORSHOW( ui.HTTPPortLabel ) ; HIDEORSHOW( ui.RTPPortLabel ) ; HIDEORSHOW( ui.MMSHPortLabel ) ; HIDEORSHOW( ui.UDPPortLabel )
387     HIDEORSHOW( ui.HTTPPort ) ; HIDEORSHOW( ui.RTPPort ) ; HIDEORSHOW( ui.MMSHPort ) ; HIDEORSHOW( ui.UDPPort ) ; HIDEORSHOW( ui.RTPPortLabel2 ); HIDEORSHOW( ui.RTPPort2 ); HIDEORSHOW( ui.UDPRTPLabel )
388
389     HIDEORSHOW( ui.sap ); HIDEORSHOW( ui.sapName );
390     HIDEORSHOW( ui.sapGroup ); HIDEORSHOW( ui.sapGroupLabel );
391     HIDEORSHOW( ui.ttlLabel ); HIDEORSHOW( ui.ttl );
392
393     HIDEORSHOW( ui.IcecastOutput ); HIDEORSHOW( ui.IcecastEdit );
394     HIDEORSHOW( ui.IcecastNamePassEdit ); HIDEORSHOW( ui.IcecastMountpointEdit );
395     HIDEORSHOW( ui.IcecastPort ); HIDEORSHOW( ui.IcecastLabel );
396     HIDEORSHOW( ui.IcecastPortLabel );
397     HIDEORSHOW( ui.IcecastMountpointLabel ); HIDEORSHOW( ui.IcecastNameLabel );
398 #undef HIDEORSHOW
399
400     if( b_transcode_only ) okButton->setText( "&Save" );
401     else okButton->setText( "&Stream" );
402
403     setMinimumHeight( 500 );
404     resize( width(), sizeHint().height() );
405 }
406
407 void SoutDialog::changeUDPandRTPmess( bool b_udp )
408 {
409     ui.RTPEdit->setVisible( !b_udp );
410     ui.RTPLabel->setVisible( !b_udp );
411     ui.RTPPort->setVisible( !b_udp );
412     ui.RTPPortLabel->setVisible( !b_udp );
413     ui.UDPEdit->setVisible( b_udp );
414     ui.UDPLabel->setVisible( b_udp );
415     ui.UDPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Audio Port:" ) );
416     ui.RTPPort2->setVisible( !b_udp );
417     ui.RTPPortLabel2->setVisible( !b_udp );
418 }
419
420 void SoutDialog::RTPtoggled( bool b_en )
421 {
422     if( !b_en )
423     {
424         if( ui.RTPPort->value() == ui.UDPPort->value() )
425         {
426             ui.UDPPort->setValue( ui.UDPPort->value() + 1 );
427         }
428
429         while( ui.RTPPort2->value() == ui.UDPPort->value() ||
430                 ui.RTPPort2->value() == ui.RTPPort->value() )
431         {
432             ui.RTPPort2->setValue( ui.RTPPort2->value() + 1 );
433         }
434     }
435     ui.sap->setEnabled( b_en );
436     ui.RTPLabel->setEnabled( b_en );
437     ui.RTPEdit->setEnabled( b_en );
438     ui.UDPOutput->setEnabled( b_en );
439     ui.UDPEdit->setEnabled( b_en );
440     ui.UDPPort->setEnabled( b_en );
441     ui.UDPPortLabel->setEnabled( b_en );
442     ui.RTPPort2->setEnabled( b_en );
443     ui.RTPPortLabel2->setEnabled( b_en );
444 }
445
446 void SoutDialog::ok()
447 {
448     mrl = ui.mrlEdit->text();
449     accept();
450 }
451
452 void SoutDialog::cancel()
453 {
454     mrl.clear();
455     reject();
456 }
457
458 void SoutDialog::updateMRL()
459 {
460     sout_gui_descr_t sout;
461     memset( &sout, 0, sizeof( sout_gui_descr_t ) );
462     unsigned int counter = 0;
463
464     sout.b_local = ui.localOutput->isChecked();
465     sout.b_file = ui.fileOutput->isChecked();
466     sout.b_http = ui.HTTPOutput->isChecked();
467     sout.b_mms = ui.MMSHOutput->isChecked();
468     sout.b_icecast = ui.IcecastOutput->isChecked();
469     sout.b_rtp = ui.RTPOutput->isChecked();
470     sout.b_udp = ui.UDPOutput->isChecked();
471     sout.b_dump = ui.rawInput->isChecked();
472     sout.b_sap = ui.sap->isChecked();
473     sout.b_all_es = ui.soutAll->isChecked();
474     sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
475     sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
476     sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
477     sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
478     sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
479     sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
480     sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
481     sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
482     sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
483     sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
484     sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
485     sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
486     sout.i_http = ui.HTTPPort->value();
487     sout.i_mms = ui.MMSHPort->value();
488     sout.i_rtp = ui.RTPPort->value();
489     sout.i_rtp_audio = sout.i_udp = ui.UDPPort->value();
490     sout.i_rtp_video = ui.RTPPort2->value();
491     sout.i_icecast = ui.IcecastPort->value();
492     sout.i_ab = ui.aBitrateSpin->value();
493     sout.i_vb = ui.vBitrateSpin->value();
494     sout.i_channels = ui.aChannelsSpin->value();
495     sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
496     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
497     sout.psz_name = strdup( qtu( ui.sapName->text() ) );
498
499     if ( sout.b_local ) counter++ ;
500     if ( sout.b_file ) counter++ ;
501     if ( sout.b_http ) counter++ ;
502     if ( sout.b_mms ) counter++ ;
503     if ( sout.b_rtp ) counter++ ;
504     if ( sout.b_udp ) counter ++;
505     if ( sout.b_icecast ) counter ++;
506
507 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
508     SMUX( PSMux, "ps" );
509     SMUX( TSMux, "ts" );
510     SMUX( MPEG1Mux, "mpeg" );
511     SMUX( OggMux, "ogg" );
512     SMUX( ASFMux, "asf" );
513     SMUX( MP4Mux, "mp4" );
514     SMUX( MOVMux, "mov" );
515     SMUX( WAVMux, "wav" );
516     SMUX( RAWMux, "raw" );
517     SMUX( FLVMux, "flv" );
518     SMUX( MKVMux, "mkv" );
519
520     bool trans = false;
521     bool more = false;
522
523     SoutMrl smrl( ":sout=#" );
524
525     if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked()
526          && !ui.rawInput->isChecked() /*demuxdump speciality*/ )
527     {
528         smrl.begin( "transcode" );
529
530         if ( ui.transcodeVideo->isChecked() )
531         {
532             smrl.option( "vcodec", sout.psz_vcodec );
533             smrl.option( "vb", sout.i_vb );
534             smrl.option( "scale", sout.f_scale );
535             trans = true;
536         }
537
538         if ( ui.transcodeAudio->isChecked() )
539         {
540             smrl.option( "acodec", sout.psz_acodec );
541             smrl.option( "ab", sout.i_ab );
542             smrl.option( "channels", sout.i_channels );
543             trans = true;
544         }
545
546         smrl.end();
547
548         mrl = smrl.getMrl();
549     }
550
551     /* Special case for demuxdump */
552     if ( sout.b_file && sout.b_dump )
553     {
554         mrl = ":demux=dump :demuxdump-file=";
555         mrl.append( sout.psz_file );
556     }
557     else
558
559
560     /* Protocol output */
561     if ( sout.b_local || sout.b_file || sout.b_http ||
562          sout.b_mms || sout.b_rtp || sout.b_udp || sout.b_icecast )
563     {
564         if( counter > 1 )
565             smrl.begin( "duplicate" );
566
567 #define ADD(m) do { if( counter > 1 ) { \
568                 smrl.option( "dst", m.getMrl() ); \
569             } else { \
570                 smrl.begin( m.getMrl() ); \
571                 smrl.end(); \
572             } } while(0)
573
574         if ( sout.b_local )
575         {
576             SoutMrl m;
577             m.begin( "display" );
578             m.end();
579
580             ADD( m );
581             more = true;
582         }
583
584         if ( sout.b_file )
585         {
586             SoutMrl m;
587
588             m.begin( "std" );
589             m.option( "access", "file" );
590             if( sout.psz_mux )
591                 m.option( "mux", sout.psz_mux );
592             m.option( "dst", sout.psz_file );
593             m.end();
594
595             ADD( m );
596             more = true;
597         }
598
599         if ( sout.b_http )
600         {
601             SoutMrl m;
602
603             m.begin( "std" );
604             m.option(  "access", "http" );
605             if( sout.psz_mux )
606                 m.option( "mux", sout.psz_mux );
607             m.option( "dst", sout.psz_http, sout.i_http );
608             m.end();
609
610             ADD( m );
611             more = true;
612         }
613
614         if ( sout.b_mms )
615         {
616             SoutMrl m;
617
618             m.begin( "std" );
619             m.option(  "access", "mmsh" );
620             m.option( "mux", "asfh" );
621             m.option( "dst", sout.psz_mms, sout.i_mms );
622             m.end();
623
624             ADD( m );
625             more = true;
626         }
627
628         if ( sout.b_rtp )
629         {
630             SoutMrl m;
631             if ( sout.b_udp )
632             {
633                 m.begin( "std" );
634                 m.option(  "access", "udp" );
635                 if( sout.psz_mux )
636                     m.option( "mux", sout.psz_mux );
637                 m.option( "dst", sout.psz_udp, sout.i_udp );
638             }
639             else
640             {
641                 m.begin( "rtp" );
642
643                 if( sout.psz_rtp && *sout.psz_rtp )
644                     m.option( "dst", sout.psz_rtp );
645                 if( sout.psz_mux )
646                     m.option( "mux", sout.psz_mux );
647
648                 m.option( "port", sout.i_rtp );
649                 if( !sout.psz_mux || strncmp( sout.psz_mux, "ts", 2 ) )
650                 {
651                     m.option( "port-audio", sout.i_rtp_audio );
652                     m.option( "port-video", sout.i_rtp_video );
653                 }
654             }
655
656             /* SAP */
657             if ( sout.b_sap )
658             {
659                 m.option( "sap" );
660                 m.option( "group", sout.psz_group );
661                 m.option( "name", sout.psz_name );
662             }
663
664             m.end();
665             ADD( m );
666             more = true;
667         }
668
669         if( sout.b_icecast )
670         {
671             SoutMrl m;
672             QString url;
673
674             url = QString(sout.sa_icecast.psz_username) + "@" + sout.psz_icecast + ":" +
675                   QString::number( sout.i_icecast, 10 ) + "/" + sout.psz_icecast_mountpoint;
676
677             m.begin( "std" );
678             m.option( "access", "shout" );
679             m.option( "mux", "ogg" );
680             m.option( "dst", url );
681             m.end();
682
683             ADD( m );
684             more = true;
685         }
686
687         if ( counter )
688             smrl.end();
689
690         mrl = smrl.getMrl();
691     }
692
693     if ( sout.b_all_es )
694         mrl.append( " :sout-all" );
695
696     ui.mrlEdit->setText( mrl );
697     free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
698     free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
699     free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
700     free( sout.psz_name ); free( sout.psz_group );
701     free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
702     free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );
703 }