1 /*****************************************************************************
2 * sout.cpp : Stream output dialog ( old-style )
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Jean-François Massol <jf.massol -at- gmail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #include "dialogs/sout.hpp"
28 #include <vlc_streaming.h>
32 #include <QFileDialog>
34 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
35 bool _transcode_only ) : QVLCDialog( parent, _p_intf )
37 setWindowTitle( qtr( "Stream output" ) );
39 b_transcode_only = _transcode_only;
44 /* ADD HERE for new profiles */
45 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
46 ADD_PROFILE( "Custom" , "Custom" )
47 ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
48 ADD_PROFILE( "XBox", "XBox" )
49 ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
50 ADD_PROFILE( "PSP", "PSP")
51 ADD_PROFILE( "GSM", "GSM" )
53 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
54 ADD_VCODEC( "MPEG-1", "mp1v" )
55 ADD_VCODEC( "MPEG-2", "mp2v" )
56 ADD_VCODEC( "MPEG-4", "mp4v" )
57 ADD_VCODEC( "DIVX 1" , "DIV1" )
58 ADD_VCODEC( "DIVX 2" , "DIV1" )
59 ADD_VCODEC( "DIVX 3" , "DIV1" )
60 ADD_VCODEC( "H-263", "H263" )
61 ADD_VCODEC( "H-264", "h264" )
62 ADD_VCODEC( "WMV1", "WMV1" )
63 ADD_VCODEC( "WMV2" , "WMV2" )
64 ADD_VCODEC( "M-JPEG", "MJPG" )
65 ADD_VCODEC( "Theora", "theo" )
67 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
68 ADD_ACODEC( "MPEG Audio", "mpga" )
69 ADD_ACODEC( "MP3", "mp3" )
70 ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
71 ADD_ACODEC( "A52/AC-3", "a52" )
72 ADD_ACODEC( "Vorbis", "vorb" )
73 ADD_ACODEC( "Flac", "flac" )
74 ADD_ACODEC( "Speex", "spx" )
75 ADD_ACODEC( "WAV", "s16l" )
76 ADD_ACODEC( "WMA", "wma" )
78 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
88 ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n This is automatically generated "
89 "when you change the above settings,\n but you can update it manually." ) ) ;
91 // /* Connect everything to the updateMRL function */
92 #define CB( x ) CONNECT( ui.x, clicked( bool ), this, updateMRL() );
93 #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
94 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
95 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
97 CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
98 CB( UDPOutput ); CB( MMSHOutput ); CB( rawInput );
99 CT( fileEdit ); CT( HTTPEdit ); CT( UDPEdit ); CT( MMSHEdit );
100 CS( HTTPPort ); CS( UDPPort ); CS( MMSHPort );
102 CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
103 CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
105 CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
107 CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
108 CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
110 CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
112 CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
113 CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse() );
114 CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
115 CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
116 CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
117 CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
119 okButton = new QPushButton( qtr( "&Stream" ) );
120 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
122 okButton->setDefault( true );
123 ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
124 ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
126 BUTTONACT( okButton, ok() );
127 BUTTONACT( cancelButton, cancel() );
129 if( b_transcode_only ) toggleSout();
132 void SoutDialog::fileBrowse()
134 ui.tabWidget->setTabEnabled( 0,false );
135 QString f = QFileDialog::getOpenFileName( this, qtr( "Save file" ), "", "" );
136 ui.fileEdit->setText( f );
140 void SoutDialog::setVTranscodeOptions( bool b_trans )
142 ui.vCodecLabel->setEnabled( b_trans );
143 ui.vCodecBox->setEnabled( b_trans );
144 ui.vBitrateLabel->setEnabled( b_trans );
145 ui.vBitrateSpin->setEnabled( b_trans );
146 ui.vScaleLabel->setEnabled( b_trans );
147 ui.vScaleBox->setEnabled( b_trans );
150 void SoutDialog::setATranscodeOptions( bool b_trans )
152 ui.aCodecLabel->setEnabled( b_trans );
153 ui.aCodecBox->setEnabled( b_trans );
154 ui.aBitrateLabel->setEnabled( b_trans );
155 ui.aBitrateSpin->setEnabled( b_trans );
156 ui.aChannelsLabel->setEnabled( b_trans );
157 ui.aChannelsSpin->setEnabled( b_trans );
160 void SoutDialog::setSTranscodeOptions( bool b_trans )
162 ui.subsCodecBox->setEnabled( b_trans );
163 ui.subsOverlay->setEnabled( b_trans );
166 void SoutDialog::setRawOptions( bool b_raw )
170 ui.tabWidget->setDisabled( true );
174 SoutDialog::setOptions();
178 int indexFromItemData( QComboBox *aCombo, QString aString )
180 for( int i=0; i < aCombo->count(); i++ )
182 if( aCombo->itemData( i ).toString() == aString ) return i;
187 void SoutDialog::setOptions()
189 QString profileString = ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
190 msg_Dbg( p_intf, "Profile Used: %s", qta( profileString ));
193 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
195 ui.muxName ##Mux->setChecked( true ); \
197 ui.transcodeAudio->setChecked( hasAudio ); \
198 index = indexFromItemData( ui.aCodecBox, vCodecName ); \
199 if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
201 ui.transcodeVideo->setChecked( hasVideo ); \
202 index = indexFromItemData( ui.aCodecBox, vCodecName ); \
203 if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
206 /* ADD HERE the profiles you want and need */
207 if( profileString == "IPod" ) setProfile( MP4, true, "mp4a", true, "mp4v" )
208 else if( profileString == "XBox" ) setProfile( ASF, true, "wma", true, "WMV2" )
210 /* If the profile is not a custom one, then disable the tabWidget */
211 if ( profileString == "Custom" )
213 ui.tabWidget->setEnabled( true );
217 ui.tabWidget->setDisabled( true );
220 /* Update the MRL !! */
224 void SoutDialog::toggleSout()
226 //Toggle all the streaming options.
228 if( ( x->isHidden() ) ) \
232 TGV( ui.HTTPOutput ) ; TGV( ui.UDPOutput ) ; TGV( ui.MMSHOutput ) ;
233 TGV( ui.HTTPEdit ) ; TGV( ui.UDPEdit ) ; TGV( ui.MMSHEdit ) ;
234 TGV( ui.HTTPLabel ) ; TGV( ui.UDPLabel ) ; TGV( ui.MMSHLabel ) ;
235 TGV( ui.HTTPPortLabel ) ; TGV( ui.UDPPortLabel ) ; TGV( ui.MMSHPortLabel ) ;
236 TGV( ui.HTTPPort ) ; TGV( ui.UDPPort ) ; TGV( ui.MMSHPort ) ;
238 TGV( ui.sap ); TGV( ui.sapName );
239 TGV( ui.sapGroup ); TGV( ui.sapGroupLabel );
240 TGV( ui.ttlLabel ); TGV( ui.ttl );
242 if( b_transcode_only ) okButton->setText( "&Save" );
243 else okButton->setText( "&Stream" );
248 void SoutDialog::ok()
250 mrl = ui.mrlEdit->text();
253 void SoutDialog::cancel()
255 mrl = ui.mrlEdit->text();
259 void SoutDialog::updateMRL()
261 sout_gui_descr_t sout;
262 memset( &sout, 0, sizeof( sout_gui_descr_t ) );
264 sout.b_local = ui.localOutput->isChecked();
265 sout.b_file = ui.fileOutput->isChecked();
266 sout.b_http = ui.HTTPOutput->isChecked();
267 sout.b_mms = ui.MMSHOutput->isChecked();
268 sout.b_udp = ui.UDPOutput->isChecked();
269 sout.b_sap = ui.sap->isChecked();
270 sout.b_all_es = ui.soutAll->isChecked();
271 sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
272 sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
273 sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
274 sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
275 sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
276 sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
277 sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
278 sout.i_http = ui.HTTPPort->value();
279 sout.i_mms = ui.MMSHPort->value();
280 sout.i_udp = ui.UDPPort->value();
281 sout.i_ab = ui.aBitrateSpin->value();
282 sout.i_vb = ui.vBitrateSpin->value();
283 sout.i_channels = ui.aChannelsSpin->value();
284 sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
285 sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
286 sout.psz_name = strdup( qtu( ui.sapName->text() ) );
288 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
291 SMUX( MPEG1Mux, "mpeg" );
292 SMUX( OggMux, "ogg" );
293 SMUX( ASFMux, "asf" );
294 SMUX( MP4Mux, "mp4" );
295 SMUX( MOVMux, "mov" );
296 SMUX( WAVMux, "wav" );
297 SMUX( RAWMux, "raw" );
298 SMUX( FLVMux, "flv" );
303 if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
305 if ( ui.transcodeVideo->isChecked() )
307 mrl = ":sout=#transcode{";
308 mrl.append( "vcodec=" );
309 mrl.append( sout.psz_vcodec );
312 mrl.append( QString::number( sout.i_vb,10 ) );
314 mrl.append( "scale=" );
315 mrl.append( QString::number( sout.f_scale ) );
319 if ( ui.transcodeAudio->isChecked() )
327 mrl = ":sout=#transcode{";
329 mrl.append( "acodec=" );
330 mrl.append( sout.psz_acodec );
333 mrl.append( QString::number( sout.i_ab,10 ) );
335 mrl.append( "channels=" );
336 mrl.append( QString::number( sout.i_channels,10 ) );
342 if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_udp )
345 #define ISMORE() if ( more ) mrl.append( "," );
349 mrl.append( ":duplicate{" );
359 mrl.append( "dst=display" );
366 mrl.append( "dst=std{access=file,mux=" );
367 mrl.append( sout.psz_mux );
368 mrl.append( ",dst=" );
369 mrl.append( sout.psz_file );
377 mrl.append( "dst=std{access=http,mux=" );
378 mrl.append( sout.psz_mux );
379 mrl.append( ",dst=" );
380 mrl.append( sout.psz_http );
382 mrl.append( QString::number( sout.i_http,10 ) );
390 mrl.append( "dst=std{access=mmsh,mux=" );
391 mrl.append( sout.psz_mux );
392 mrl.append( ",dst=" );
393 mrl.append( sout.psz_mms );
395 mrl.append( QString::number( sout.i_mms,10 ) );
403 mrl.append( "dst=std{access=udp,mux=" );
404 mrl.append( sout.psz_mux );
405 mrl.append( ",dst=" );
406 mrl.append( sout.psz_udp );
408 mrl.append( QString::number( sout.i_udp,10 ) );
411 mrl.append( ",sap," );
412 mrl.append( "group=\"" );
413 mrl.append( sout.psz_group );
415 mrl.append( "name=\"" );
416 mrl.append( sout.psz_name );
430 mrl.append( ":sout-all" );
432 ui.mrlEdit->setText( mrl );
433 free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
434 free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
435 free( sout.psz_udp ); free( sout.psz_mux );
436 free( sout.psz_name ); free( sout.psz_group );