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