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
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>
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.
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.
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 *****************************************************************************/
34 #include "dialogs/sout.hpp"
37 #include <QFileDialog>
39 struct streaming_account_t
41 char *psz_username; /*< username of account */
42 char *psz_password; /*< password of account */
45 struct sout_gui_descr_t
48 bool b_local; /*< local access module */
49 bool b_file; /*< file access module */
50 bool b_http; /*< http access module */
51 bool b_mms; /*< mms access module */
52 bool b_rtp; /*< rtp access module */
53 bool b_udp; /*< udp access module */
54 bool b_dump; /*< dump access module */
55 bool b_icecast; /*< icecast access module */
57 char *psz_file; /*< filename */
58 char *psz_http; /*< HTTP servername or ipaddress */
59 char *psz_mms; /*< MMS servername or ipaddress */
60 char *psz_rtp; /*< RTP servername or ipaddress */
61 char *psz_udp; /*< UDP servername or ipaddress */
62 char *psz_icecast; /*< Icecast servername or ipaddress*/
64 int32_t i_http; /*< http port number */
65 int32_t i_mms; /*< mms port number */
66 int32_t i_rtp; /*< rtp port number */
67 int32_t i_udp; /*< udp port number */
68 int32_t i_icecast; /*< icecast port number */
71 char *psz_mux; /*< name of muxer to use in streaming */
74 bool b_soverlay; /*< enable burning overlay in the video */
75 char *psz_vcodec; /*< video codec to use in transcoding */
76 char *psz_acodec; /*< audio codec to use in transcoding */
77 char *psz_scodec; /*< subtitle codec to use in transcoding */
78 int32_t i_vb; /*< video bitrate to use in transcoding */
79 int32_t i_ab; /*< audio bitrate to use in transcoding */
80 int32_t i_channels; /*< number of audio channels to use in transcoding */
81 float f_scale; /*< scaling factor to use in transcoding */
84 bool b_sap; /*< send SAP announcement */
85 bool b_all_es;/*< send all elementary streams from source stream */
86 char *psz_group; /*< SAP Group name */
87 char *psz_name; /*< SAP name */
88 int32_t i_ttl; /*< Time To Live (TTL) for network traversal */
91 char *psz_icecast_mountpoint;/*< path to Icecast mountpoint */
92 struct streaming_account_t sa_icecast; /*< Icecast account information */
95 SoutDialog* SoutDialog::instance = NULL;
97 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
98 bool _transcode_only ) : QVLCDialog( parent, _p_intf )
100 setWindowTitle( qtr( "Stream Output" ) );
102 b_transcode_only = _transcode_only;
107 changeUDPandRTPmess( false );
109 /* ADD HERE for new profiles */
110 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
111 ADD_PROFILE( "Custom" , "Custom" )
112 ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
113 ADD_PROFILE( "XBox", "XBox" )
114 ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
115 ADD_PROFILE( "PSP", "PSP")
116 ADD_PROFILE( "GSM", "GSM" )
118 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
119 ADD_VCODEC( "MPEG-1", "mp1v" )
120 ADD_VCODEC( "MPEG-2", "mp2v" )
121 ADD_VCODEC( "MPEG-4", "mp4v" )
122 ADD_VCODEC( "DIVX 1" , "DIV1" )
123 ADD_VCODEC( "DIVX 2" , "DIV2" )
124 ADD_VCODEC( "DIVX 3" , "DIV3" )
125 ADD_VCODEC( "H-263", "H263" )
126 ADD_VCODEC( "H-264", "h264" )
127 ADD_VCODEC( "WMV1", "WMV1" )
128 ADD_VCODEC( "WMV2" , "WMV2" )
129 ADD_VCODEC( "M-JPEG", "MJPG" )
130 ADD_VCODEC( "Theora", "theo" )
132 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
133 ADD_ACODEC( "MPEG Audio", "mpga" )
134 ADD_ACODEC( "MP3", "mp3" )
135 ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
136 ADD_ACODEC( "A52/AC-3", "a52" )
137 ADD_ACODEC( "Vorbis", "vorb" )
138 ADD_ACODEC( "Flac", "flac" )
139 ADD_ACODEC( "Speex", "spx" )
140 ADD_ACODEC( "WAV", "s16l" )
141 ADD_ACODEC( "WMA", "wma" )
143 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
144 ADD_SCALING( "0.25" )
146 ADD_SCALING( "0.75" )
148 ADD_SCALING( "1.25" )
150 ADD_SCALING( "1.75" )
153 ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
154 "This is automatically generated "
155 "when you change the above settings,\n"
156 "but you can update it manually." ) ) ;
158 // /* Connect everything to the updateMRL function */
159 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
160 #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
161 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
162 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
164 CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
165 CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
166 CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
167 CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
168 CS( HTTPPort ); CS( RTPPort ); CS( MMSHPort ); CS( UDPPort );
170 CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
171 CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
173 CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
175 CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
176 CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
178 CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
180 CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
181 CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse() );
182 CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
183 CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
184 CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
185 CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
187 okButton = new QPushButton( qtr( "&Stream" ) );
188 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
190 okButton->setDefault( true );
191 ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
192 ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
194 BUTTONACT( okButton, ok() );
195 BUTTONACT( cancelButton, cancel() );
197 if( b_transcode_only ) toggleSout();
199 CONNECT( ui.UDPOutput, toggled( bool ), this, changeUDPandRTPmess( bool ) );}
201 void SoutDialog::fileBrowse()
203 QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
204 qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
205 ui.fileEdit->setText( fileName );
209 void SoutDialog::setVTranscodeOptions( bool b_trans )
211 ui.vCodecLabel->setEnabled( b_trans );
212 ui.vCodecBox->setEnabled( b_trans );
213 ui.vBitrateLabel->setEnabled( b_trans );
214 ui.vBitrateSpin->setEnabled( b_trans );
215 ui.vScaleLabel->setEnabled( b_trans );
216 ui.vScaleBox->setEnabled( b_trans );
219 void SoutDialog::setATranscodeOptions( bool b_trans )
221 ui.aCodecLabel->setEnabled( b_trans );
222 ui.aCodecBox->setEnabled( b_trans );
223 ui.aBitrateLabel->setEnabled( b_trans );
224 ui.aBitrateSpin->setEnabled( b_trans );
225 ui.aChannelsLabel->setEnabled( b_trans );
226 ui.aChannelsSpin->setEnabled( b_trans );
229 void SoutDialog::setSTranscodeOptions( bool b_trans )
231 ui.subsCodecBox->setEnabled( b_trans );
232 ui.subsOverlay->setEnabled( b_trans );
235 void SoutDialog::setRawOptions( bool b_raw )
238 ui.tabWidget->setDisabled( true );
240 SoutDialog::setOptions();
243 void SoutDialog::setOptions()
245 QString profileString =
246 ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
247 msg_Dbg( p_intf, "Profile Used: %s", qta( profileString ));
250 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
252 ui.muxName ##Mux->setChecked( true ); \
254 ui.transcodeAudio->setChecked( hasAudio ); \
255 index = ui.aCodecBox->findText( vCodecName ); \
256 if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
258 ui.transcodeVideo->setChecked( hasVideo ); \
259 index = ui.aCodecBox->findText( vCodecName ); \
260 if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
263 /* ADD HERE the profiles you want and need */
265 if( profileString == "IPod" ) setProfile( MP4, true, "mp4a", true, "mp4v" )
266 else if( profileString == "XBox" ) setProfile( ASF, true, "wma", true, "WMV2" )
268 /* If the profile is not a custom one, then disable the tabWidget */
269 if ( profileString == "Custom" )
270 ui.tabWidget->setEnabled( true );
272 ui.tabWidget->setDisabled( true );
274 /* Update the MRL !! */
279 void SoutDialog::toggleSout()
281 //Toggle all the streaming options.
282 TOGGLEV( ui.HTTPOutput ) ; TOGGLEV( ui.RTPOutput ) ; TOGGLEV( ui.MMSHOutput ) ; TOGGLEV( ui.UDPOutput ) ;
283 TOGGLEV( ui.HTTPEdit ) ; TOGGLEV( ui.RTPEdit ) ; TOGGLEV( ui.MMSHEdit ) ; TOGGLEV( ui.UDPEdit ) ;
284 TOGGLEV( ui.HTTPLabel ) ; TOGGLEV( ui.RTPLabel ) ; TOGGLEV( ui.MMSHLabel ) ; TOGGLEV( ui.UDPLabel ) ;
285 TOGGLEV( ui.HTTPPortLabel ) ; TOGGLEV( ui.RTPPortLabel ) ; TOGGLEV( ui.MMSHPortLabel ) ; TOGGLEV( ui.UDPPortLabel )
286 TOGGLEV( ui.HTTPPort ) ; TOGGLEV( ui.RTPPort ) ; TOGGLEV( ui.MMSHPort ) ; TOGGLEV( ui.UDPPort ) ;
288 TOGGLEV( ui.sap ); TOGGLEV( ui.sapName );
289 TOGGLEV( ui.sapGroup ); TOGGLEV( ui.sapGroupLabel );
290 TOGGLEV( ui.ttlLabel ); TOGGLEV( ui.ttl );
292 if( b_transcode_only ) okButton->setText( "&Save" );
293 else okButton->setText( "&Stream" );
298 void SoutDialog::changeUDPandRTPmess( bool b_udp )
300 ui.RTPEdit->setVisible( !b_udp );
301 ui.RTPLabel->setVisible( !b_udp );
302 ui.RTPPort->setVisible( !b_udp );
303 ui.RTPPortLabel->setVisible( !b_udp );
304 ui.UDPEdit->setVisible( b_udp );
305 ui.UDPLabel->setVisible( b_udp );
306 ui.UDPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Video Port:" ) );
307 ui.RTPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Audio Port:" ) );
310 void SoutDialog::ok()
312 mrl = ui.mrlEdit->text();
316 void SoutDialog::cancel()
322 void SoutDialog::updateMRL()
324 sout_gui_descr_t sout;
325 memset( &sout, 0, sizeof( sout_gui_descr_t ) );
326 unsigned int counter = 0;
328 sout.b_local = ui.localOutput->isChecked();
329 sout.b_file = ui.fileOutput->isChecked();
330 sout.b_http = ui.HTTPOutput->isChecked();
331 sout.b_mms = ui.MMSHOutput->isChecked();
332 sout.b_icecast = ui.IcecastOutput->isChecked();
333 sout.b_rtp = ui.RTPOutput->isChecked();
334 sout.b_udp = ui.UDPOutput->isChecked();
335 sout.b_sap = ui.sap->isChecked();
336 sout.b_all_es = ui.soutAll->isChecked();
337 sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
338 sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
339 sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
340 sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
341 sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
342 sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
343 sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
344 sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
345 sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
346 sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
347 sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
348 sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
349 sout.i_http = ui.HTTPPort->value();
350 sout.i_mms = ui.MMSHPort->value();
351 sout.i_rtp = ui.RTPPort->value();
352 sout.i_udp = ui.UDPPort->value();
353 sout.i_icecast = ui.IcecastPort->value();
354 sout.i_ab = ui.aBitrateSpin->value();
355 sout.i_vb = ui.vBitrateSpin->value();
356 sout.i_channels = ui.aChannelsSpin->value();
357 sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
358 sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
359 sout.psz_name = strdup( qtu( ui.sapName->text() ) );
361 if ( sout.b_local ) counter++ ;
362 if ( sout.b_file ) counter++ ;
363 if ( sout.b_http ) counter++ ;
364 if ( sout.b_mms ) counter++ ;
365 if ( sout.b_rtp ) counter++ ;
366 if ( sout.b_udp ) counter ++;
367 if ( sout.b_icecast ) counter ++;
369 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
372 SMUX( MPEG1Mux, "mpeg" );
373 SMUX( OggMux, "ogg" );
374 SMUX( ASFMux, "asf" );
375 SMUX( MP4Mux, "mp4" );
376 SMUX( MOVMux, "mov" );
377 SMUX( WAVMux, "wav" );
378 SMUX( RAWMux, "raw" );
379 SMUX( FLVMux, "flv" );
380 SMUX( MKVMux, "mkv" );
385 if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
387 if ( ui.transcodeVideo->isChecked() )
389 mrl = ":sout=#transcode{";
390 mrl.append( "vcodec=" );
391 mrl.append( sout.psz_vcodec );
394 mrl.append( QString::number( sout.i_vb,10 ) );
396 mrl.append( "scale=" );
397 mrl.append( QString::number( sout.f_scale ) );
401 if ( ui.transcodeAudio->isChecked() )
409 mrl = ":sout=#transcode{";
411 mrl.append( "acodec=" );
412 mrl.append( sout.psz_acodec );
415 mrl.append( QString::number( sout.i_ab,10 ) );
417 mrl.append( "channels=" );
418 mrl.append( QString::number( sout.i_channels,10 ) );
424 if ( sout.b_local || sout.b_file || sout.b_http ||
425 sout.b_mms || sout.b_rtp || sout.b_udp )
428 #define ISMORE() if ( more ) mrl.append( "," );
429 #define ATLEASTONE() if ( counter ) mrl.append( "dst=" );
434 mrl.append( ",mux=");\
435 mrl.append( sout.psz_mux ); \
449 mrl.append( "duplicate{" );
456 mrl.append( "display" );
464 mrl.append( "std{access=file" );
466 mrl.append( ",dst=" );
467 mrl.append( sout.psz_file );
476 mrl.append( "std{access=http" );
478 mrl.append( ",dst=" );
479 mrl.append( sout.psz_http );
481 mrl.append( QString::number( sout.i_http,10 ) );
490 mrl.append( "std{access=mmsh" );
492 mrl.append( ",dst=" );
493 mrl.append( sout.psz_mms );
495 mrl.append( QString::number( sout.i_mms,10 ) );
504 mrl.append( "rtp{" );
506 mrl.append( ",dst=" );
507 mrl.append( sout.psz_rtp );
509 mrl.append( QString::number( sout.i_rtp,10 ) );
518 mrl.append( "std{access=udp" );
520 mrl.append( ",dst=" );
521 mrl.append( sout.psz_udp );
523 mrl.append( QString::number( sout.i_udp,10 ) );
526 mrl.append( ",sap," );
527 mrl.append( "group=\"" );
528 mrl.append( sout.psz_group );
530 mrl.append( "name=\"" );
531 mrl.append( sout.psz_name );
552 mrl.append( ":sout-all" );
554 ui.mrlEdit->setText( mrl );
555 free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
556 free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
557 free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
558 free( sout.psz_name ); free( sout.psz_group );
559 free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
560 free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );