1 /*****************************************************************************
2 * sout.cpp : Stream output dialog ( old-style )
3 ****************************************************************************
4 * Copyright (C) 2006 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 *****************************************************************************/
33 #include "dialogs/sout.hpp"
36 #include <QFileDialog>
38 struct streaming_account_t
40 char *psz_username; /*< username of account */
41 char *psz_password; /*< password of account */
44 struct sout_gui_descr_t
47 bool b_local; /*< local access module */
48 bool b_file; /*< file access module */
49 bool b_http; /*< http access module */
50 bool b_mms; /*< mms access module */
51 bool b_rtp; /*< rtp access module */
52 bool b_udp; /*< udp access module */
53 bool b_dump; /*< dump access module */
54 bool b_icecast; /*< icecast access module */
56 char *psz_file; /*< filename */
57 char *psz_http; /*< HTTP servername or ipaddress */
58 char *psz_mms; /*< MMS servername or ipaddress */
59 char *psz_rtp; /*< RTP servername or ipaddress */
60 char *psz_udp; /*< UDP servername or ipaddress */
61 char *psz_icecast; /*< Icecast servername or ipaddress*/
63 int32_t i_http; /*< http port number */
64 int32_t i_mms; /*< mms port number */
65 int32_t i_rtp; /*< rtp port number */
66 int32_t i_udp; /*< udp port number */
67 int32_t i_icecast; /*< icecast port number */
70 char *psz_mux; /*< name of muxer to use in streaming */
73 bool b_soverlay; /*< enable burning overlay in the video */
74 char *psz_vcodec; /*< video codec to use in transcoding */
75 char *psz_acodec; /*< audio codec to use in transcoding */
76 char *psz_scodec; /*< subtitle codec to use in transcoding */
77 int32_t i_vb; /*< video bitrate to use in transcoding */
78 int32_t i_ab; /*< audio bitrate to use in transcoding */
79 int32_t i_channels; /*< number of audio channels to use in transcoding */
80 float f_scale; /*< scaling factor to use in transcoding */
83 bool b_sap; /*< send SAP announcement */
84 bool b_all_es;/*< send all elementary streams from source stream */
85 char *psz_group; /*< SAP Group name */
86 char *psz_name; /*< SAP name */
87 int32_t i_ttl; /*< Time To Live (TTL) for network traversal */
90 char *psz_icecast_mountpoint;/*< path to Icecast mountpoint */
91 struct streaming_account_t sa_icecast; /*< Icecast account information */
94 SoutDialog* SoutDialog::instance = NULL;
96 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
97 bool _transcode_only ) : QVLCDialog( parent, _p_intf )
99 setWindowTitle( qtr( "Stream output" ) );
101 b_transcode_only = _transcode_only;
106 ui.UDPEdit->hide(); ui.UDPLabel->hide();
107 ui.UDPPort->hide(); ui.UDPPortLabel->hide();
108 /* ADD HERE for new profiles */
109 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
110 ADD_PROFILE( "Custom" , "Custom" )
111 ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
112 ADD_PROFILE( "XBox", "XBox" )
113 ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
114 ADD_PROFILE( "PSP", "PSP")
115 ADD_PROFILE( "GSM", "GSM" )
117 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
118 ADD_VCODEC( "MPEG-1", "mp1v" )
119 ADD_VCODEC( "MPEG-2", "mp2v" )
120 ADD_VCODEC( "MPEG-4", "mp4v" )
121 ADD_VCODEC( "DIVX 1" , "DIV1" )
122 ADD_VCODEC( "DIVX 2" , "DIV1" )
123 ADD_VCODEC( "DIVX 3" , "DIV1" )
124 ADD_VCODEC( "H-263", "H263" )
125 ADD_VCODEC( "H-264", "h264" )
126 ADD_VCODEC( "WMV1", "WMV1" )
127 ADD_VCODEC( "WMV2" , "WMV2" )
128 ADD_VCODEC( "M-JPEG", "MJPG" )
129 ADD_VCODEC( "Theora", "theo" )
131 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
132 ADD_ACODEC( "MPEG Audio", "mpga" )
133 ADD_ACODEC( "MP3", "mp3" )
134 ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
135 ADD_ACODEC( "A52/AC-3", "a52" )
136 ADD_ACODEC( "Vorbis", "vorb" )
137 ADD_ACODEC( "Flac", "flac" )
138 ADD_ACODEC( "Speex", "spx" )
139 ADD_ACODEC( "WAV", "s16l" )
140 ADD_ACODEC( "WMA", "wma" )
142 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
143 ADD_SCALING( "0.25" )
145 ADD_SCALING( "0.75" )
147 ADD_SCALING( "1.25" )
149 ADD_SCALING( "1.75" )
152 ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n This is automatically generated "
153 "when you change the above settings,\n but you can update it manually." ) ) ;
155 // /* Connect everything to the updateMRL function */
156 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
157 #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
158 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
159 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
161 CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
162 CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
163 CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
164 CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
165 CS( HTTPPort ); CS( RTPPort ); CS( MMSHPort ); CS( UDPPort );
167 CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
168 CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
170 CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
172 CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
173 CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
175 CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
177 CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
178 CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse() );
179 CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
180 CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
181 CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
182 CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
184 okButton = new QPushButton( qtr( "&Stream" ) );
185 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
187 okButton->setDefault( true );
188 ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
189 ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
191 BUTTONACT( okButton, ok() );
192 BUTTONACT( cancelButton, cancel() );
194 if( b_transcode_only ) toggleSout();
197 void SoutDialog::fileBrowse()
199 ui.tabWidget->setTabEnabled( 0,false );
200 QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
201 qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
202 ui.fileEdit->setText( fileName );
206 void SoutDialog::setVTranscodeOptions( bool b_trans )
208 ui.vCodecLabel->setEnabled( b_trans );
209 ui.vCodecBox->setEnabled( b_trans );
210 ui.vBitrateLabel->setEnabled( b_trans );
211 ui.vBitrateSpin->setEnabled( b_trans );
212 ui.vScaleLabel->setEnabled( b_trans );
213 ui.vScaleBox->setEnabled( b_trans );
216 void SoutDialog::setATranscodeOptions( bool b_trans )
218 ui.aCodecLabel->setEnabled( b_trans );
219 ui.aCodecBox->setEnabled( b_trans );
220 ui.aBitrateLabel->setEnabled( b_trans );
221 ui.aBitrateSpin->setEnabled( b_trans );
222 ui.aChannelsLabel->setEnabled( b_trans );
223 ui.aChannelsSpin->setEnabled( b_trans );
226 void SoutDialog::setSTranscodeOptions( bool b_trans )
228 ui.subsCodecBox->setEnabled( b_trans );
229 ui.subsOverlay->setEnabled( b_trans );
232 void SoutDialog::setRawOptions( bool b_raw )
236 ui.tabWidget->setDisabled( true );
240 SoutDialog::setOptions();
244 void SoutDialog::setOptions()
246 QString profileString = 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" )
271 ui.tabWidget->setEnabled( true );
275 ui.tabWidget->setDisabled( true );
278 /* Update the MRL !! */
282 void SoutDialog::toggleSout()
284 //Toggle all the streaming options.
285 TOGGLEV( ui.HTTPOutput ) ; TOGGLEV( ui.RTPOutput ) ; TOGGLEV( ui.MMSHOutput ) ; TOGGLEV( ui.UDPOutput ) ;
286 TOGGLEV( ui.HTTPEdit ) ; TOGGLEV( ui.RTPEdit ) ; TOGGLEV( ui.MMSHEdit ) ; TOGGLEV( ui.UDPEdit ) ;
287 TOGGLEV( ui.HTTPLabel ) ; TOGGLEV( ui.RTPLabel ) ; TOGGLEV( ui.MMSHLabel ) ; TOGGLEV( ui.UDPLabel ) ;
288 TOGGLEV( ui.HTTPPortLabel ) ; TOGGLEV( ui.RTPPortLabel ) ; TOGGLEV( ui.MMSHPortLabel ) ; TOGGLEV( ui.UDPPortLabel )
289 TOGGLEV( ui.HTTPPort ) ; TOGGLEV( ui.RTPPort ) ; TOGGLEV( ui.MMSHPort ) ; TOGGLEV( ui.UDPPort ) ;
291 TOGGLEV( ui.sap ); TOGGLEV( ui.sapName );
292 TOGGLEV( ui.sapGroup ); TOGGLEV( ui.sapGroupLabel );
293 TOGGLEV( ui.ttlLabel ); TOGGLEV( ui.ttl );
295 if( b_transcode_only ) okButton->setText( "&Save" );
296 else okButton->setText( "&Stream" );
301 void SoutDialog::ok()
303 mrl = ui.mrlEdit->text();
306 void SoutDialog::cancel()
308 mrl = ui.mrlEdit->text();
312 void SoutDialog::updateMRL()
314 sout_gui_descr_t sout;
315 memset( &sout, 0, sizeof( sout_gui_descr_t ) );
316 unsigned int counter = 0;
318 sout.b_local = ui.localOutput->isChecked();
319 sout.b_file = ui.fileOutput->isChecked();
320 sout.b_http = ui.HTTPOutput->isChecked();
321 sout.b_mms = ui.MMSHOutput->isChecked();
322 sout.b_icecast = ui.IcecastOutput->isChecked();
323 sout.b_rtp = ui.RTPOutput->isChecked();
324 sout.b_udp = ui.UDPOutput->isChecked();
325 sout.b_sap = ui.sap->isChecked();
326 sout.b_all_es = ui.soutAll->isChecked();
327 sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
328 sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
329 sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
330 sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
331 sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
332 sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
333 sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
334 sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
335 sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
336 sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
337 sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
338 sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
339 sout.i_http = ui.HTTPPort->value();
340 sout.i_mms = ui.MMSHPort->value();
341 sout.i_rtp = ui.RTPPort->value();
342 sout.i_udp = ui.UDPPort->value();
343 sout.i_icecast = ui.IcecastPort->value();
344 sout.i_ab = ui.aBitrateSpin->value();
345 sout.i_vb = ui.vBitrateSpin->value();
346 sout.i_channels = ui.aChannelsSpin->value();
347 sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
348 sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
349 sout.psz_name = strdup( qtu( ui.sapName->text() ) );
351 if ( sout.b_local ) counter++ ;
352 if ( sout.b_file ) counter++ ;
353 if ( sout.b_http ) counter++ ;
354 if ( sout.b_mms ) counter++ ;
355 if ( sout.b_rtp ) counter++ ;
356 if ( sout.b_udp ) counter ++;
357 if ( sout.b_icecast ) counter ++;
359 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
362 SMUX( MPEG1Mux, "mpeg" );
363 SMUX( OggMux, "ogg" );
364 SMUX( ASFMux, "asf" );
365 SMUX( MP4Mux, "mp4" );
366 SMUX( MOVMux, "mov" );
367 SMUX( WAVMux, "wav" );
368 SMUX( RAWMux, "raw" );
369 SMUX( FLVMux, "flv" );
370 SMUX( MKVMux, "mkv" );
375 if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
377 if ( ui.transcodeVideo->isChecked() )
379 mrl = ":sout=#transcode{";
380 mrl.append( "vcodec=" );
381 mrl.append( sout.psz_vcodec );
384 mrl.append( QString::number( sout.i_vb,10 ) );
386 mrl.append( "scale=" );
387 mrl.append( QString::number( sout.f_scale ) );
391 if ( ui.transcodeAudio->isChecked() )
399 mrl = ":sout=#transcode{";
401 mrl.append( "acodec=" );
402 mrl.append( sout.psz_acodec );
405 mrl.append( QString::number( sout.i_ab,10 ) );
407 mrl.append( "channels=" );
408 mrl.append( QString::number( sout.i_channels,10 ) );
414 if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_rtp || sout.b_udp )
417 #define ISMORE() if ( more ) mrl.append( "," );
418 #define ATLEASTONE() if ( counter ) mrl.append( "dst=" );
423 mrl.append( ",mux=");\
424 mrl.append( sout.psz_mux ); \
438 mrl.append( "duplicate{" );
445 mrl.append( "display" );
453 mrl.append( "std{access=file" );
455 mrl.append( ",dst=" );
456 mrl.append( sout.psz_file );
465 mrl.append( "std{access=http" );
467 mrl.append( ",dst=" );
468 mrl.append( sout.psz_http );
470 mrl.append( QString::number( sout.i_http,10 ) );
479 mrl.append( "std{access=mmsh" );
481 mrl.append( ",dst=" );
482 mrl.append( sout.psz_mms );
484 mrl.append( QString::number( sout.i_mms,10 ) );
493 mrl.append( "rtp{" );
495 mrl.append( ",dst=" );
496 mrl.append( sout.psz_rtp );
498 mrl.append( QString::number( sout.i_rtp,10 ) );
507 mrl.append( "std{access=udp" );
509 mrl.append( ",dst=" );
510 mrl.append( sout.psz_udp );
512 mrl.append( QString::number( sout.i_udp,10 ) );
515 mrl.append( ",sap," );
516 mrl.append( "group=\"" );
517 mrl.append( sout.psz_group );
519 mrl.append( "name=\"" );
520 mrl.append( sout.psz_name );
541 mrl.append( ":sout-all" );
543 ui.mrlEdit->setText( mrl );
544 free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
545 free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
546 free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
547 free( sout.psz_name ); free( sout.psz_group );
548 free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
549 free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );