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