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>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * ( at your option ) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "dialogs/sout.hpp"
26 #include <vlc_streaming.h>
30 #include <QFileDialog>
32 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
33 bool _transcode_only ) : QVLCDialog( parent, _p_intf )
35 setWindowTitle( qtr( "Stream output" ) );
40 #define ADD_PROFILE( name ) ui.profileBox->addItem( name );
41 ADD_PROFILE( "Custom" )
44 ADD_PROFILE( "Windows" )
48 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
49 ADD_VCODEC( "MPEG-1", "mp1v" )
50 ADD_VCODEC( "MPEG-2", "mp2v" )
51 ADD_VCODEC( "MPEG-4", "mp4v" )
52 ADD_VCODEC( "DIVX 1" , "DIV1" )
53 ADD_VCODEC( "DIVX 2" , "DIV1" )
54 ADD_VCODEC( "DIVX 3" , "DIV1" )
55 ADD_VCODEC( "H-263", "H263" )
56 ADD_VCODEC( "H-264", "h264" )
57 ADD_VCODEC( "WMV1", "WMV1" )
58 ADD_VCODEC( "WMV2" , "WMV2" )
59 ADD_VCODEC( "M-JPEG", "MJPG" )
60 ADD_VCODEC( "Theora", "theo" )
62 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
63 ADD_ACODEC( "MPEG Audio", "mpga" )
64 ADD_ACODEC( "MP3", "mp3" )
65 ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
66 ADD_ACODEC( "A52/AC-3", "a52" )
67 ADD_ACODEC( "Vorbis", "vorb" )
68 ADD_ACODEC( "Flac", "flac" )
69 ADD_ACODEC( "Speex", "spx" )
70 ADD_ACODEC( "WAV", "s16l" )
71 ADD_ACODEC( "WMA", "wma" )
73 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
83 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." ) ) ;
85 // /* Connect everything to the updateMRL function */
86 #define CB( x ) CONNECT( ui.x, clicked( bool ), this, updateMRL() );
87 #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
88 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
89 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
91 CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
92 CB( UDPOutput ); CB( MMSHOutput ); CB( rawInput );
93 CT( fileEdit ); CT( HTTPEdit ); CT( UDPEdit ); CT( MMSHEdit );
94 CS( HTTPPort ); CS( UDPPort ); CS( MMSHPort );
96 CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
97 CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
99 CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
101 CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
102 CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
104 CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
106 CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
107 CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse() );
108 CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
109 CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
110 CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
111 CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
113 QPushButton *okButton = new QPushButton( qtr( "&Stream" ) );
114 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
116 okButton->setDefault( true );
117 ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
118 ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
120 BUTTONACT( okButton, ok() );
121 BUTTONACT( cancelButton, cancel() );
123 if( _transcode_only ) toggleSout();
126 void SoutDialog::fileBrowse()
127 {ui.tabWidget->setTabEnabled( 0,false );
128 QString f = QFileDialog::getOpenFileName( this, qtr( "Save file" ), "", "" );
129 ui.fileEdit->setText( f );
133 void SoutDialog::setVTranscodeOptions( bool b_trans )
135 ui.vCodecLabel->setEnabled( b_trans );
136 ui.vCodecBox->setEnabled( b_trans );
137 ui.vBitrateLabel->setEnabled( b_trans );
138 ui.vBitrateSpin->setEnabled( b_trans );
139 ui.vScaleLabel->setEnabled( b_trans );
140 ui.vScaleBox->setEnabled( b_trans );
143 void SoutDialog::setATranscodeOptions( bool b_trans )
145 ui.aCodecLabel->setEnabled( b_trans );
146 ui.aCodecBox->setEnabled( b_trans );
147 ui.aBitrateLabel->setEnabled( b_trans );
148 ui.aBitrateSpin->setEnabled( b_trans );
149 ui.aChannelsLabel->setEnabled( b_trans );
150 ui.aChannelsSpin->setEnabled( b_trans );
153 void SoutDialog::setSTranscodeOptions( bool b_trans )
155 ui.subsCodecBox->setEnabled( b_trans );
156 ui.subsOverlay->setEnabled( b_trans );
159 void SoutDialog::setRawOptions( bool b_raw )
163 ui.tabWidget->setDisabled( true );
167 SoutDialog::setOptions();
171 void SoutDialog::setOptions()
173 /* The test is currently done with a QString, it could be done with the index, it'd depend how translation works */
174 if ( ui.profileBox->currentText() == "Custom" )
176 ui.tabWidget->setEnabled( true );
180 ui.tabWidget->setDisabled( true );
184 void SoutDialog::toggleSout()
187 if( ( x->isHidden() ) ) \
191 TGV( ui.HTTPOutput ) ; TGV( ui.UDPOutput ) ; TGV( ui.MMSHOutput ) ;
192 TGV( ui.HTTPEdit ) ; TGV( ui.UDPEdit ) ; TGV( ui.MMSHEdit ) ;
193 TGV( ui.HTTPLabel ) ; TGV( ui.UDPLabel ) ; TGV( ui.MMSHLabel ) ;
194 TGV( ui.HTTPPortLabel ) ; TGV( ui.UDPPortLabel ) ; TGV( ui.MMSHPortLabel ) ;
195 TGV( ui.HTTPPort ) ; TGV( ui.UDPPort ) ; TGV( ui.MMSHPort ) ;
199 void SoutDialog::ok()
201 mrl = ui.mrlEdit->text();
204 void SoutDialog::cancel()
206 mrl = ui.mrlEdit->text();
210 void SoutDialog::updateMRL()
212 sout_gui_descr_t sout;
213 memset( &sout, 0, sizeof( sout_gui_descr_t ) );
215 sout.b_local = ui.localOutput->isChecked();
216 sout.b_file = ui.fileOutput->isChecked();
217 sout.b_http = ui.HTTPOutput->isChecked();
218 sout.b_mms = ui.MMSHOutput->isChecked();
219 sout.b_udp = ui.UDPOutput->isChecked();
220 sout.b_sap = ui.sap->isChecked();
221 sout.b_all_es = ui.soutAll->isChecked();
222 sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
223 sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
224 sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
225 sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
226 sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
227 sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
228 sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
229 sout.i_http = ui.HTTPPort->value();
230 sout.i_mms = ui.MMSHPort->value();
231 sout.i_udp = ui.UDPPort->value();
232 sout.i_ab = ui.aBitrateSpin->value();
233 sout.i_vb = ui.vBitrateSpin->value();
234 sout.i_channels = ui.aChannelsSpin->value();
235 sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
236 sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
237 sout.psz_name = strdup( qtu( ui.sapName->text() ) );
239 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
242 SMUX( MPEG1Mux, "mpeg" );
243 SMUX( OggMux, "ogg" );
244 SMUX( ASFMux, "asf" );
245 SMUX( MP4Mux, "mp4" );
246 SMUX( MOVMux, "mov" );
247 SMUX( WAVMux, "wav" );
248 SMUX( RAWMux, "raw" );
249 SMUX( FLVMux, "flv" );
254 if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
256 if ( ui.transcodeVideo->isChecked() )
258 mrl = ":sout=#transcode{";
259 mrl.append( "vcodec=" );
260 mrl.append( sout.psz_vcodec );
263 mrl.append( QString::number( sout.i_vb,10 ) );
265 mrl.append( "scale=" );
266 mrl.append( QString::number( sout.f_scale ) );
270 if ( ui.transcodeAudio->isChecked() )
278 mrl = ":sout=#transcode{";
280 mrl.append( "acodec=" );
281 mrl.append( sout.psz_acodec );
284 mrl.append( QString::number( sout.i_ab,10 ) );
286 mrl.append( "channels=" );
287 mrl.append( QString::number( sout.i_channels,10 ) );
293 if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_udp )
296 #define ISMORE() if ( more ) mrl.append( "," );
300 mrl.append( ":duplicate{" );
310 mrl.append( "dst=display" );
317 mrl.append( "dst=std{access=file,mux=" );
318 mrl.append( sout.psz_mux );
319 mrl.append( ",dst=" );
320 mrl.append( sout.psz_file );
328 mrl.append( "dst=std{access=http,mux=" );
329 mrl.append( sout.psz_mux );
330 mrl.append( ",dst=" );
331 mrl.append( sout.psz_http );
333 mrl.append( QString::number( sout.i_http,10 ) );
341 mrl.append( "dst=std{access=mmsh,mux=" );
342 mrl.append( sout.psz_mux );
343 mrl.append( ",dst=" );
344 mrl.append( sout.psz_mms );
346 mrl.append( QString::number( sout.i_mms,10 ) );
354 mrl.append( "dst=std{access=udp,mux=" );
355 mrl.append( sout.psz_mux );
356 mrl.append( ",dst=" );
357 mrl.append( sout.psz_udp );
359 mrl.append( QString::number( sout.i_udp,10 ) );
362 mrl.append( ",sap," );
363 mrl.append( "group=\"" );
364 mrl.append( sout.psz_group );
366 mrl.append( "name=\"" );
367 mrl.append( sout.psz_name );
381 mrl.append( ":sout-all" );
384 ui.mrlEdit->setText( mrl );
385 free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
386 free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
387 free( sout.psz_udp ); free( sout.psz_mux );
388 free( sout.psz_name ); free( sout.psz_group );
391 // void SoutDialog::updateMRL()
393 // sout_gui_descr_t pd;
394 // memset( &pd, 0, sizeof( sout_gui_descr_t ) );
397 // pd.b_dump = ui.rawInput->isChecked();
398 // if( pd.b_dump ) goto end;
400 // pd.b_local = ui.localOutput->isChecked();
401 // pd.b_file = ui.fileOutput->isChecked();
402 // pd.b_http = ui.HTTPOutput->isChecked();
403 // pd.b_mms = ui.MMSHOutput->isChecked();
404 // pd.b_udp = ui.UDPOutput->isChecked();
406 // pd.psz_file = ui.fileOutput->isChecked() ?
407 // strdup( qtu( ui.fileEdit->text() ) ): NULL;
408 // pd.psz_http = ui.HTTPOutput->isChecked() ?
409 // strdup( qtu( ui.HTTPEdit->text() ) ) : NULL;
410 // pd.psz_mms = ui.MMSHOutput->isChecked() ?
411 // strdup( qtu( ui.MMSHEdit->text() ) ): NULL;
412 // pd.psz_udp = ui.UDPOutput->isChecked() ?
413 // strdup( qtu( ui.UDPEdit->text() ) ): NULL;
415 // pd.i_http = ui.HTTPPort->value();
416 // pd.i_mms = ui.MMSHPort->value();
417 // pd.i_udp = ui.UDPPort->value();
420 // #define SMUX( x, txt ) if( ui.x##Mux->isChecked() ) pd.psz_mux = strdup( txt );
423 // SMUX( MPEG1, "mpeg" );
424 // SMUX( Ogg, "ogg" );
425 // SMUX( ASF, "asf" );
426 // SMUX( MP4, "mp4" );
427 // SMUX( MOV, "mov" );
428 // SMUX( WAV, "wav" );
429 // SMUX( RAW, "raw" );
430 // SMUX( FLV, "flv" );
435 // // pd.b_soverlay = ui.sOverlay->isChecked();
436 // // pd.i_vb = ui.vBitrate->value();
437 // // pd.i_ab = ui.aBitrate->value();
438 // // pd.i_channels = ui.aChannels->value();
439 // // pd.f_scale = atof( qta( ui.vScale->currentText() ) );
441 // // pd.psz_vcodec = ui.transcodeVideo->isChecked() ?
442 // // strdup( qtu( ui.vCodec->itemData(
443 // // ui.vCodec->currentIndex() ). toString() ) ) : NULL;
444 // // pd.psz_acodec = ui.transcodeAudio->isChecked() ?
445 // // strdup( qtu( ui.aCodec->itemData(
446 // // ui.aCodec->currentIndex() ).toString() ) ) : NULL;
447 // // pd.psz_scodec = ui.transcodeSubs->isChecked() ?
448 // // strdup( qtu( ui.sCodec->itemData(
449 // // ui.sCodec->currentIndex() ).toString() ) ) : NULL;
450 // // pd.b_sap = ui.sap->isChecked();
451 // // pd.b_all_es = ui.soutAll->isChecked();
452 // // pd.psz_name = qtu( ui.sapName->text() );
453 // // pd.psz_group = qtu( ui.sapGroup->text() );
454 // // pd.i_ttl = ui.ttl->value() ;
456 // sout_chain_t* p_chain = streaming_ChainNew();
457 // streaming_GuiDescToChain( VLC_OBJECT( p_intf ), p_chain, &pd );
458 // char *psz_mrl = streaming_ChainToPsz( p_chain );
460 // ui.mrlEdit->setText( qfu( strdup( psz_mrl ) ) );
461 // free( pd.psz_acodec ); free( pd.psz_vcodec ); free( pd.psz_scodec );
462 // free( pd.psz_file );free( pd.psz_http ); free( pd.psz_mms );
463 // free( pd.psz_udp ); free( pd.psz_mux );