]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/sout.cpp
String updates from tonsofpcs
[vlc] / modules / gui / qt4 / dialogs / sout.cpp
index 0087709e0a0e4df94ba8d26edca5877101033b07..d83431229871f67c21ded3c6602cbba88d9a368c 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * sout.cpp : Stream output dialog ( old-style )
  ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2007-2008 the VideoLAN team
  * Copyright (C) 2007 Société des arts technologiques
  * Copyright (C) 2007 Savoir-faire Linux
  *
@@ -26,6 +26,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -63,6 +64,8 @@ struct sout_gui_descr_t
     int32_t i_http;     /*< http port number */
     int32_t i_mms;      /*< mms port number */
     int32_t i_rtp;      /*< rtp port number */
+    int32_t i_rtp_audio;      /*< rtp port number */
+    int32_t i_rtp_video;      /*< rtp port number */
     int32_t i_udp;      /*< udp port number */
     int32_t i_icecast;  /*< icecast port number */
 
@@ -82,6 +85,7 @@ struct sout_gui_descr_t
     /* Misc */
     bool b_sap;   /*< send SAP announcement */
     bool b_all_es;/*< send all elementary streams from source stream */
+    bool b_sout_keep;
     char *psz_group;    /*< SAP Group name */
     char *psz_name;     /*< SAP name */
     int32_t i_ttl;      /*< Time To Live (TTL) for network traversal */
@@ -91,36 +95,114 @@ struct sout_gui_descr_t
     struct streaming_account_t sa_icecast;  /*< Icecast account information */
 };
 
+class SoutMrl
+{
+public:
+    SoutMrl( const QString head = "")
+    {
+        mrl = head;
+        b_first = true;
+        b_has_bracket = false;
+    }
+
+    QString getMrl()
+    {
+        return mrl;
+    }
+
+    void begin( QString module )
+    {
+        if( !b_first )
+            mrl += ":";
+        b_first = false;
+
+        mrl += module;
+        b_has_bracket = false;
+    }
+    void end()
+    {
+        if( b_has_bracket )
+            mrl += "}";
+    }
+    void option( const QString option, const QString value = "" )
+    {
+        if( !b_has_bracket )
+            mrl += "{";
+        else
+            mrl += ",";
+        b_has_bracket = true;
+
+        mrl += option;
+
+        if( !value.isEmpty() )
+        {
+            char *psz = config_StringEscape( qta(value) );
+            if( psz )
+            {
+                QString v = QString( psz );
+
+                mrl += "=\"" + v + "\"";
+
+                free( psz );
+            }
+        }
+    }
+    void option( const QString name, const int i_value, const int i_precision = 10 )
+    {
+        option( name, QString::number( i_value, i_precision ) );
+    }
+    void option( const QString name, const double f_value )
+    {
+        option( name, QString::number( f_value ) );
+    }
+
+    void option( const QString name, const QString base, const int i_value, const int i_precision = 10 )
+    {
+        option( name, base + ":" + QString::number( i_value, i_precision ) );
+    }
+
+private:
+    QString mrl;
+    bool b_has_bracket;
+    bool b_first;
+};
+
 SoutDialog* SoutDialog::instance = NULL;
 
 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
                      bool _transcode_only ) : QVLCDialog( parent,  _p_intf )
 {
-    setWindowTitle( qtr( "Stream output" ) );
+    setWindowTitle( qtr( "Stream Output" ) );
 
     b_transcode_only = _transcode_only;
 
     /* UI stuff */
     ui.setupUi( this );
 
-    ui.UDPEdit->hide(); ui.UDPLabel->hide();
-    ui.UDPPort->hide(); ui.UDPPortLabel->hide();
+    changeUDPandRTPmess( false );
+
 /* ADD HERE for new profiles */
 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
     ADD_PROFILE( "Custom" , "Custom" )
+    ADD_PROFILE( "Ogg / Theora", "theora" )
+    ADD_PROFILE( "Ogg / Vorbis", "vorbis" )
+    ADD_PROFILE( "MPEG-2", "mpeg2" )
+    ADD_PROFILE( "MP3", "mp3" )
+    ADD_PROFILE( "MPEG-4 audio AAC", "aac" )
+    ADD_PROFILE( "MPEG-4 / DivX", "mp4" )
+    ADD_PROFILE( "H264", "h264" )
     ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
     ADD_PROFILE( "XBox", "XBox" )
     ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
     ADD_PROFILE( "PSP", "PSP")
-    ADD_PROFILE( "GSM", "GSM" )
 
 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
     ADD_VCODEC( "MPEG-1", "mp1v" )
     ADD_VCODEC( "MPEG-2", "mp2v" )
     ADD_VCODEC( "MPEG-4", "mp4v" )
     ADD_VCODEC( "DIVX 1" , "DIV1" )
-    ADD_VCODEC( "DIVX 2" , "DIV1" )
-    ADD_VCODEC( "DIVX 3" , "DIV1" )
+    ADD_VCODEC( "DIVX 2" , "DIV2" )
+    ADD_VCODEC( "DIVX 3" , "DIV3" )
     ADD_VCODEC( "H-263", "H263" )
     ADD_VCODEC( "H-264", "h264" )
     ADD_VCODEC( "WMV1", "WMV1" )
@@ -140,45 +222,50 @@ SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
     ADD_ACODEC( "WMA", "wma" )
 
 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
+    ADD_SCALING( "1" )
     ADD_SCALING( "0.25" )
     ADD_SCALING( "0.5" )
     ADD_SCALING( "0.75" )
-    ADD_SCALING( "1" )
     ADD_SCALING( "1.25" )
     ADD_SCALING( "1.5" )
     ADD_SCALING( "1.75" )
     ADD_SCALING( "2" )
 
-    ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n This is automatically generated "
-                                                "when you change the above settings,\n but you can update it manually." ) ) ;
+    ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
+                "This is automatically generated "
+                 "when you change the above settings,\n"
+                 "but you can change it manually." ) ) ;
 
 //     /* Connect everything to the updateMRL function */
  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
-//     /* Output */
+    /* Output */
     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
     CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
     CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
     CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
-    CS( HTTPPort ); CS( RTPPort ); CS( MMSHPort ); CS( UDPPort );
-//     /* Transcode */
+    CS( HTTPPort ); CS( RTPPort ); CS( RTPPort2 ); CS( MMSHPort ); CS( UDPPort );
+    /* Transcode */
     CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
     CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
-//     CB( sOverlay );
+    /*   CB( sOverlay ); */
     CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
-//     /* Mux */
+    /* Mux */
     CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
     CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
-//     /* Misc */
-    CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
-//
+    /* Misc */
+    CB( soutAll ); CB( soutKeep );  CS( ttl ); CT( sapName ); CT( sapGroup );
+
     CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
     CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse()  );
-    CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
-    CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
-    CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
+    CONNECT( ui.transcodeVideo, toggled( bool ),
+            this, setVTranscodeOptions( bool ) );
+    CONNECT( ui.transcodeAudio, toggled( bool ),
+            this, setATranscodeOptions( bool ) );
+    CONNECT( ui.transcodeSubs, toggled( bool ),
+            this, setSTranscodeOptions( bool ) );
     CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
 
     okButton = new QPushButton( qtr( "&Stream" ) );
@@ -191,13 +278,15 @@ SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
     BUTTONACT( okButton, ok() );
     BUTTONACT( cancelButton, cancel() );
 
+    CONNECT( ui.UDPOutput, toggled( bool ), this, changeUDPandRTPmess( bool ) );
+    CONNECT( ui.RTPOutput, clicked(bool), this, RTPtoggled( bool ) );
+
     if( b_transcode_only ) toggleSout();
 }
 
 void SoutDialog::fileBrowse()
 {
-    ui.tabWidget->setTabEnabled( 0,false );
-    QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
+    QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ), "",
         qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
     ui.fileEdit->setText( fileName );
     updateMRL();
@@ -231,19 +320,24 @@ void SoutDialog::setSTranscodeOptions( bool b_trans )
 
 void SoutDialog::setRawOptions( bool b_raw )
 {
+    ui.localOutput->setEnabled( !b_raw );
+    ui.HTTPOutput->setEnabled( !b_raw );
+    ui.MMSHOutput->setEnabled( !b_raw );
+    ui.UDPOutput->setEnabled( !b_raw );
+    ui.RTPOutput->setEnabled( !b_raw );
+    ui.IcecastOutput->setEnabled( !b_raw );
+    ui.UDPRTPLabel->setEnabled( !b_raw );
+
     if( b_raw )
-    {
         ui.tabWidget->setDisabled( true );
-    }
     else
-    {
-        SoutDialog::setOptions();
-    }
+        setOptions();
 }
 
 void SoutDialog::setOptions()
 {
-    QString profileString = ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
+    QString profileString =
+        ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
     msg_Dbg( p_intf, "Profile Used: %s",  qta( profileString ));
     int index;
 
@@ -252,28 +346,32 @@ void SoutDialog::setOptions()
         ui.muxName ##Mux->setChecked( true ); \
         \
         ui.transcodeAudio->setChecked( hasAudio ); \
-        index = ui.aCodecBox->findText( vCodecName );  \
+        index = ui.aCodecBox->findData( aCodecName );  \
         if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
         \
         ui.transcodeVideo->setChecked( hasVideo ); \
-        index = ui.aCodecBox->findText( vCodecName );  \
+        index = ui.vCodecBox->findData( vCodecName );  \
         if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
     }
 
     /* ADD HERE the profiles you want and need */
-    /* FIXME */
-    if( profileString == "IPod" ) setProfile( MP4, true, "mp4a", true, "mp4v" )
-    else if( profileString == "XBox" ) setProfile( ASF, true, "wma", true, "WMV2" )
+    if( profileString == "IPod" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
+    else if( profileString == "theora" ) setProfile( Ogg, true, "theo", true, "vorb" )
+    else if( profileString == "vorbis" ) setProfile( Ogg, false, "", true, "vorb" )
+    else if( profileString == "mpeg2" ) setProfile( TS, true, "mp2v", true, "mpga" )
+    else if( profileString == "mp3" ) setProfile( RAW, false, "", true, "mp3" )
+    else if( profileString == "aac" ) setProfile( MP4, false, "", true, "mp4a" )
+    else if( profileString == "mp4" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
+    else if( profileString == "h264" ) setProfile( TS, true, "h264", true, "mp4a" )
+    else if( profileString == "XBox" ) setProfile( ASF, true, "WMV2", true, "wma" )
+    else if( profileString == "Windows" ) setProfile( ASF, true, "WMV2", true, "wma" )
+    else if( profileString == "PSP" ) setProfile( Ogg, true, "DIV3", true, "vorb" )
 
         /* If the profile is not a custom one, then disable the tabWidget */
         if ( profileString == "Custom" )
-        {
             ui.tabWidget->setEnabled( true );
-        }
         else
-        {
             ui.tabWidget->setDisabled( true );
-        }
 
     /* Update the MRL !! */
     updateMRL();
@@ -282,20 +380,70 @@ void SoutDialog::setOptions()
 void SoutDialog::toggleSout()
 {
     //Toggle all the streaming options.
-    TOGGLEV( ui.HTTPOutput ) ; TOGGLEV( ui.RTPOutput ) ; TOGGLEV( ui.MMSHOutput ) ; TOGGLEV( ui.UDPOutput ) ;
-    TOGGLEV( ui.HTTPEdit ) ; TOGGLEV( ui.RTPEdit ) ; TOGGLEV( ui.MMSHEdit ) ; TOGGLEV( ui.UDPEdit ) ;
-    TOGGLEV( ui.HTTPLabel ) ; TOGGLEV( ui.RTPLabel ) ; TOGGLEV( ui.MMSHLabel ) ; TOGGLEV( ui.UDPLabel ) ;
-    TOGGLEV( ui.HTTPPortLabel ) ; TOGGLEV( ui.RTPPortLabel ) ; TOGGLEV( ui.MMSHPortLabel ) ; TOGGLEV( ui.UDPPortLabel )
-    TOGGLEV( ui.HTTPPort ) ; TOGGLEV( ui.RTPPort ) ; TOGGLEV( ui.MMSHPort ) ; TOGGLEV( ui.UDPPort ) ;
-
-    TOGGLEV( ui.sap ); TOGGLEV( ui.sapName );
-    TOGGLEV( ui.sapGroup ); TOGGLEV( ui.sapGroupLabel );
-    TOGGLEV( ui.ttlLabel ); TOGGLEV( ui.ttl );
+#define HIDEORSHOW(x) if( b_transcode_only ) x->hide(); else x->show();
+    HIDEORSHOW( ui.HTTPOutput ) ; HIDEORSHOW( ui.RTPOutput ) ; HIDEORSHOW( ui.MMSHOutput ) ; HIDEORSHOW( ui.UDPOutput ) ;
+    HIDEORSHOW( ui.HTTPEdit ) ; HIDEORSHOW( ui.RTPEdit ) ; HIDEORSHOW( ui.MMSHEdit ) ; HIDEORSHOW( ui.UDPEdit ) ;
+    HIDEORSHOW( ui.HTTPLabel ) ; HIDEORSHOW( ui.RTPLabel ) ; HIDEORSHOW( ui.MMSHLabel ) ; HIDEORSHOW( ui.UDPLabel ) ;
+    HIDEORSHOW( ui.HTTPPortLabel ) ; HIDEORSHOW( ui.RTPPortLabel ) ; HIDEORSHOW( ui.MMSHPortLabel ) ; HIDEORSHOW( ui.UDPPortLabel )
+    HIDEORSHOW( ui.HTTPPort ) ; HIDEORSHOW( ui.RTPPort ) ; HIDEORSHOW( ui.MMSHPort ) ; HIDEORSHOW( ui.UDPPort ) ; HIDEORSHOW( ui.RTPPortLabel2 ); HIDEORSHOW( ui.RTPPort2 ); HIDEORSHOW( ui.UDPRTPLabel )
+
+    HIDEORSHOW( ui.sap ); HIDEORSHOW( ui.sapName );
+    HIDEORSHOW( ui.sapGroup ); HIDEORSHOW( ui.sapGroupLabel );
+    HIDEORSHOW( ui.ttlLabel ); HIDEORSHOW( ui.ttl );
+    HIDEORSHOW( ui.soutKeep );
+
+    HIDEORSHOW( ui.IcecastOutput ); HIDEORSHOW( ui.IcecastEdit );
+    HIDEORSHOW( ui.IcecastNamePassEdit ); HIDEORSHOW( ui.IcecastMountpointEdit );
+    HIDEORSHOW( ui.IcecastPort ); HIDEORSHOW( ui.IcecastLabel );
+    HIDEORSHOW( ui.IcecastPortLabel );
+    HIDEORSHOW( ui.IcecastMountpointLabel ); HIDEORSHOW( ui.IcecastNameLabel );
+#undef HIDEORSHOW
 
     if( b_transcode_only ) okButton->setText( "&Save" );
     else okButton->setText( "&Stream" );
 
-    updateGeometry();
+    setMinimumHeight( 500 );
+    resize( width(), sizeHint().height() );
+}
+
+void SoutDialog::changeUDPandRTPmess( bool b_udp )
+{
+    ui.RTPEdit->setVisible( !b_udp );
+    ui.RTPLabel->setVisible( !b_udp );
+    ui.RTPPort->setVisible( !b_udp );
+    ui.RTPPortLabel->setVisible( !b_udp );
+    ui.UDPEdit->setVisible( b_udp );
+    ui.UDPLabel->setVisible( b_udp );
+    ui.UDPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Audio Port:" ) );
+    ui.RTPPort2->setVisible( !b_udp );
+    ui.RTPPortLabel2->setVisible( !b_udp );
+}
+
+void SoutDialog::RTPtoggled( bool b_en )
+{
+    if( !b_en )
+    {
+        if( ui.RTPPort->value() == ui.UDPPort->value() )
+        {
+            ui.UDPPort->setValue( ui.UDPPort->value() + 1 );
+        }
+
+        while( ui.RTPPort2->value() == ui.UDPPort->value() ||
+                ui.RTPPort2->value() == ui.RTPPort->value() )
+        {
+            ui.RTPPort2->setValue( ui.RTPPort2->value() + 1 );
+        }
+    }
+    ui.sap->setEnabled( b_en );
+    ui.RTPLabel->setEnabled( b_en );
+    ui.RTPEdit->setEnabled( b_en );
+    ui.UDPOutput->setEnabled( b_en );
+    ui.UDPRTPLabel->setEnabled( b_en );
+    ui.UDPEdit->setEnabled( b_en );
+    ui.UDPPort->setEnabled( b_en );
+    ui.UDPPortLabel->setEnabled( b_en );
+    ui.RTPPort2->setEnabled( b_en );
+    ui.RTPPortLabel2->setEnabled( b_en );
 }
 
 void SoutDialog::ok()
@@ -303,9 +451,10 @@ void SoutDialog::ok()
     mrl = ui.mrlEdit->text();
     accept();
 }
+
 void SoutDialog::cancel()
 {
-    mrl = ui.mrlEdit->text();
+    mrl.clear();
     reject();
 }
 
@@ -322,8 +471,10 @@ void SoutDialog::updateMRL()
     sout.b_icecast = ui.IcecastOutput->isChecked();
     sout.b_rtp = ui.RTPOutput->isChecked();
     sout.b_udp = ui.UDPOutput->isChecked();
+    sout.b_dump = ui.rawInput->isChecked();
     sout.b_sap = ui.sap->isChecked();
     sout.b_all_es = ui.soutAll->isChecked();
+    sout.b_sout_keep = ui.soutKeep->isChecked();
     sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
     sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
     sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
@@ -339,7 +490,8 @@ void SoutDialog::updateMRL()
     sout.i_http = ui.HTTPPort->value();
     sout.i_mms = ui.MMSHPort->value();
     sout.i_rtp = ui.RTPPort->value();
-    sout.i_udp = ui.UDPPort->value();
+    sout.i_rtp_audio = sout.i_udp = ui.UDPPort->value();
+    sout.i_rtp_video = ui.RTPPort2->value();
     sout.i_icecast = ui.IcecastPort->value();
     sout.i_ab = ui.aBitrateSpin->value();
     sout.i_vb = ui.vBitrateSpin->value();
@@ -372,173 +524,181 @@ void SoutDialog::updateMRL()
     bool trans = false;
     bool more = false;
 
-    if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
+    SoutMrl smrl( ":sout=#" );
+
+    if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked()
+         && !ui.rawInput->isChecked() /*demuxdump speciality*/ )
     {
+        smrl.begin( "transcode" );
+
         if ( ui.transcodeVideo->isChecked() )
         {
-            mrl = ":sout=#transcode{";
-            mrl.append( "vcodec=" );
-            mrl.append( sout.psz_vcodec );
-            mrl.append( "," );
-            mrl.append( "vb=" );
-            mrl.append( QString::number( sout.i_vb,10 ) );
-            mrl.append( "," );
-            mrl.append( "scale=" );
-            mrl.append( QString::number( sout.f_scale ) );
+            smrl.option( "vcodec", sout.psz_vcodec );
+            smrl.option( "vb", sout.i_vb );
+            smrl.option( "scale", sout.f_scale );
             trans = true;
         }
 
         if ( ui.transcodeAudio->isChecked() )
         {
-            if ( trans )
-            {
-                mrl.append( "," );
-            }
-            else
-            {
-                mrl = ":sout=#transcode{";
-            }
-            mrl.append( "acodec=" );
-            mrl.append( sout.psz_acodec );
-            mrl.append( "," );
-            mrl.append( "ab=" );
-            mrl.append( QString::number( sout.i_ab,10 ) );
-            mrl.append( "," );
-            mrl.append( "channels=" );
-            mrl.append( QString::number( sout.i_channels,10 ) );
+            smrl.option( "acodec", sout.psz_acodec );
+            smrl.option( "ab", sout.i_ab );
+            smrl.option( "channels", sout.i_channels );
             trans = true;
         }
-        mrl.append( "}" );
+
+        smrl.end();
+
+        mrl = smrl.getMrl();
     }
 
-    if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_rtp || sout.b_udp )
+    /* Special case for demuxdump */
+    if ( sout.b_file && sout.b_dump )
     {
+        mrl = ":demux=dump :demuxdump-file=";
+        mrl.append( sout.psz_file );
+    }
+    else
 
-#define ISMORE() if ( more ) mrl.append( "," );
-#define ATLEASTONE() if ( counter ) mrl.append( "dst=" );
-
-#define CHECKMUX() \
-       if( sout.psz_mux ) \
-       {                  \
-         mrl.append( ",mux=");\
-         mrl.append( sout.psz_mux ); \
-       }
 
-        if ( trans )
-        {
-            mrl.append( ":" );
-        }
-        else
-        {
-            mrl = ":sout=#";
-        }
+    /* Protocol output */
+    if ( sout.b_local || sout.b_file || sout.b_http ||
+         sout.b_mms || sout.b_rtp || sout.b_udp || sout.b_icecast )
+    {
+        if( counter > 1 )
+            smrl.begin( "duplicate" );
 
-        if ( counter )
-        {
-            mrl.append( "duplicate{" );
-        }
+#define ADD(m) do { if( counter > 1 ) { \
+                smrl.option( "dst", m.getMrl() ); \
+            } else { \
+                smrl.begin( m.getMrl() ); \
+                smrl.end(); \
+            } } while(0)
 
         if ( sout.b_local )
         {
-            ISMORE();
-            ATLEASTONE()
-                mrl.append( "display" );
+            SoutMrl m;
+            m.begin( "display" );
+            m.end();
+
+            ADD( m );
             more = true;
         }
 
         if ( sout.b_file )
         {
-            ISMORE();
-            ATLEASTONE()
-                mrl.append( "std{access=file" );
-            CHECKMUX();
-            mrl.append( ",dst=" );
-            mrl.append( sout.psz_file );
-            mrl.append( "}" );
+            SoutMrl m;
+
+            m.begin( "std" );
+            m.option( "access", "file" );
+            if( sout.psz_mux )
+                m.option( "mux", sout.psz_mux );
+            m.option( "dst", sout.psz_file );
+            m.end();
+
+            ADD( m );
             more = true;
         }
 
         if ( sout.b_http )
         {
-            ISMORE();
-            ATLEASTONE()
-                mrl.append( "std{access=http" );
-            CHECKMUX();
-            mrl.append( ",dst=" );
-            mrl.append( sout.psz_http );
-            mrl.append( ":" );
-            mrl.append( QString::number( sout.i_http,10 ) );
-            mrl.append( "}" );
+            SoutMrl m;
+
+            m.begin( "std" );
+            m.option(  "access", "http" );
+            if( sout.psz_mux )
+                m.option( "mux", sout.psz_mux );
+            m.option( "dst", sout.psz_http, sout.i_http );
+            m.end();
+
+            ADD( m );
             more = true;
         }
 
         if ( sout.b_mms )
         {
-            ISMORE();
-            ATLEASTONE()
-                mrl.append( "std{access=mmsh" );
-            CHECKMUX();
-            mrl.append( ",dst=" );
-            mrl.append( sout.psz_mms );
-            mrl.append( ":" );
-            mrl.append( QString::number( sout.i_mms,10 ) );
-            mrl.append( "}" );
+            SoutMrl m;
+
+            m.begin( "std" );
+            m.option(  "access", "mmsh" );
+            m.option( "mux", "asfh" );
+            m.option( "dst", sout.psz_mms, sout.i_mms );
+            m.end();
+
+            ADD( m );
             more = true;
         }
 
         if ( sout.b_rtp )
         {
-            ISMORE();
-            ATLEASTONE()
-                mrl.append( "rtp{" );
-            CHECKMUX();
-            mrl.append( ",dst=" );
-            mrl.append( sout.psz_rtp );
-            mrl.append( ":" );
-            mrl.append( QString::number( sout.i_rtp,10 ) );
-            mrl.append( "}" );
-            more = true;
-        }
+            SoutMrl m;
+            if ( sout.b_udp )
+            {
+                m.begin( "std" );
+                m.option(  "access", "udp" );
+                if( sout.psz_mux )
+                    m.option( "mux", sout.psz_mux );
+                m.option( "dst", sout.psz_udp, sout.i_udp );
+            }
+            else
+            {
+                m.begin( "rtp" );
+
+                if( sout.psz_rtp && *sout.psz_rtp )
+                    m.option( "dst", sout.psz_rtp );
+                if( sout.psz_mux )
+                    m.option( "mux", sout.psz_mux );
+
+                m.option( "port", sout.i_rtp );
+                if( !sout.psz_mux || strncmp( sout.psz_mux, "ts", 2 ) )
+                {
+                    m.option( "port-audio", sout.i_rtp_audio );
+                    m.option( "port-video", sout.i_rtp_video );
+                }
+            }
 
-        if ( sout.b_udp )
-        {
-            ISMORE();
-            ATLEASTONE()
-            mrl.append( "std{access=udp" );
-            CHECKMUX();
-            mrl.append( ",dst=" );
-            mrl.append( sout.psz_udp );
-            mrl.append( ":" );
-            mrl.append( QString::number( sout.i_udp,10 ) );
+            /* SAP */
             if ( sout.b_sap )
             {
-                mrl.append( ",sap," );
-                mrl.append( "group=\"" );
-                mrl.append( sout.psz_group );
-                mrl.append( "\"," );
-                mrl.append( "name=\"" );
-                mrl.append( sout.psz_name );
-                mrl.append( "\"" );
+                m.option( "sap" );
+                m.option( "group", sout.psz_group );
+                m.option( "name", sout.psz_name );
             }
-            mrl.append( "}" );
+
+            m.end();
+            ADD( m );
             more = true;
         }
 
         if( sout.b_icecast )
         {
-            // TODO
+            SoutMrl m;
+            QString url;
+
+            url = QString(sout.sa_icecast.psz_username) + "@" + sout.psz_icecast + ":" +
+                  QString::number( sout.i_icecast, 10 ) + "/" + sout.psz_icecast_mountpoint;
+
+            m.begin( "std" );
+            m.option( "access", "shout" );
+            m.option( "mux", "ogg" );
+            m.option( "dst", url );
+            m.end();
+
+            ADD( m );
+            more = true;
         }
 
         if ( counter )
-        {
-            mrl.append( "}" );
-        }
-    }
+            smrl.end();
 
-#undef CHECKMUX
+        mrl = smrl.getMrl();
+    }
 
     if ( sout.b_all_es )
-        mrl.append( ":sout-all" );
+        mrl.append( " :sout-all" );
+
+    if ( sout.b_sout_keep )
+        mrl.append( " :sout-keep" );
 
     ui.mrlEdit->setText( mrl );
     free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );