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"
35 #include "util/qt_dirs.hpp"
36 #include "components/sout/sout_widgets.hpp"
39 #include <QFileDialog>
41 struct streaming_account_t
43 char *psz_username; /*< username of account */
44 char *psz_password; /*< password of account */
47 struct sout_gui_descr_t
50 bool b_local; /*< local access module */
51 bool b_file; /*< file access module */
52 bool b_http; /*< http access module */
53 bool b_mms; /*< mms access module */
54 bool b_rtp; /*< rtp access module */
55 bool b_udp; /*< udp access module */
56 bool b_dump; /*< dump access module */
57 bool b_icecast; /*< icecast access module */
59 char *psz_file; /*< filename */
60 char *psz_http; /*< HTTP servername or ipaddress */
61 char *psz_mms; /*< MMS servername or ipaddress */
62 char *psz_rtp; /*< RTP servername or ipaddress */
63 char *psz_udp; /*< UDP servername or ipaddress */
64 char *psz_icecast; /*< Icecast servername or ipaddress*/
66 int32_t i_http; /*< http port number */
67 int32_t i_mms; /*< mms port number */
68 int32_t i_rtp; /*< rtp port number */
69 int32_t i_rtp_audio; /*< rtp port number */
70 int32_t i_rtp_video; /*< rtp port number */
71 int32_t i_udp; /*< udp port number */
72 int32_t i_icecast; /*< icecast port number */
75 char *psz_mux; /*< name of muxer to use in streaming */
78 bool b_sap; /*< send SAP announcement */
79 bool b_all_es;/*< send all elementary streams from source stream */
81 char *psz_group; /*< SAP Group name */
82 char *psz_name; /*< SAP name */
83 int32_t i_ttl; /*< Time To Live (TTL) for network traversal */
86 char *psz_icecast_mountpoint;/*< path to Icecast mountpoint */
87 struct streaming_account_t sa_icecast; /*< Icecast account information */
90 SoutDialog* SoutDialog::instance = NULL;
92 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf )
93 : QVLCDialog( parent, _p_intf )
95 setWindowTitle( qtr( "Stream Output" ) );
100 changeUDPandRTPmess( false );
102 /* ADD HERE for new profiles */
103 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
104 /* ADD_PROFILE( "Custom" , "Custom" )
105 ADD_PROFILE( "Ogg / Theora", "theora" )
106 ADD_PROFILE( "Ogg / Vorbis", "vorbis" )
107 ADD_PROFILE( "MPEG-2", "mpeg2" )
108 ADD_PROFILE( "MP3", "mp3" )
109 ADD_PROFILE( "MPEG-4 audio AAC", "aac" )
110 ADD_PROFILE( "MPEG-4 / DivX", "mp4" )
111 ADD_PROFILE( "H264", "h264" )
112 ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
113 ADD_PROFILE( "XBox", "XBox" )
114 ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
115 ADD_PROFILE( "PSP", "PSP")
118 ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
119 "This is automatically generated "
120 "when you change the above settings,\n"
121 "but you can change it manually." ) ) ;
123 // /* Connect everything to the updateMRL function */
124 #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
125 #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
126 #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
127 #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
129 CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
130 CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
131 CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
132 CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
133 CS( HTTPPort ); CS( RTPPort ); CS( RTPPort2 ); CS( MMSHPort ); CS( UDPPort );
135 CB( soutAll ); CB( soutKeep ); CS( ttl ); CT( sapName ); CT( sapGroup );
137 // CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
138 CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse() );
139 CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
141 okButton = new QPushButton( qtr( "&Stream" ) );
142 QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
144 okButton->setDefault( true );
145 ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
146 ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
148 BUTTONACT( okButton, ok() );
149 BUTTONACT( cancelButton, cancel() );
151 CONNECT( ui.UDPOutput, toggled( bool ), this, changeUDPandRTPmess( bool ) );
152 CONNECT( ui.RTPOutput, clicked(bool), this, RTPtoggled( bool ) );
154 BUTTONACT( ui.nextButton, next() );
155 BUTTONACT( ui.nextButton2, next() );
158 void SoutDialog::next()
160 ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
163 void SoutDialog::fileBrowse()
165 QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
166 "", qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
167 ui.fileEdit->setText( toNativeSeparators( fileName ) );
171 void SoutDialog::setRawOptions( bool b_raw )
173 ui.localOutput->setEnabled( !b_raw );
174 ui.HTTPOutput->setEnabled( !b_raw );
175 ui.MMSHOutput->setEnabled( !b_raw );
176 ui.UDPOutput->setEnabled( !b_raw );
177 ui.RTPOutput->setEnabled( !b_raw );
178 ui.IcecastOutput->setEnabled( !b_raw );
179 ui.UDPRTPLabel->setEnabled( !b_raw );
183 // ui.tabWidget->setDisabled( true );
188 void SoutDialog::setOptions()
190 /* QString profileString =
191 ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
192 msg_Dbg( p_intf, "Profile Used: %s", qtu( profileString )); */
195 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
197 ui.muxName ##Mux->setChecked( true ); \
199 ui.transcodeAudio->setChecked( hasAudio ); \
200 index = ui.aCodecBox->findData( aCodecName ); \
201 if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
203 ui.transcodeVideo->setChecked( hasVideo ); \
204 index = ui.vCodecBox->findData( vCodecName ); \
205 if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
208 /* ADD HERE the profiles you want and need */
209 /* if( profileString == "IPod" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
210 else if( profileString == "theora" ) setProfile( Ogg, true, "theo", true, "vorb" )
211 else if( profileString == "vorbis" ) setProfile( Ogg, false, "", true, "vorb" )
212 else if( profileString == "mpeg2" ) setProfile( TS, true, "mp2v", true, "mpga" )
213 else if( profileString == "mp3" ) setProfile( RAW, false, "", true, "mp3" )
214 else if( profileString == "aac" ) setProfile( MP4, false, "", true, "mp4a" )
215 else if( profileString == "mp4" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
216 else if( profileString == "h264" ) setProfile( TS, true, "h264", true, "mp4a" )
217 else if( profileString == "XBox" ) setProfile( ASF, true, "WMV2", true, "wma" )
218 else if( profileString == "Windows" ) setProfile( ASF, true, "WMV2", true, "wma" )
219 else if( profileString == "PSP" ) setProfile( MP4, true, "mp4v", true, "mp4a" )*/
221 /* If the profile is not a custom one, then disable the tabWidget */
222 /* if ( profileString == "Custom" )
223 ui.tabWidget->setEnabled( true );
225 ui.tabWidget->setDisabled( true );
227 /* Update the MRL !! */
231 void SoutDialog::changeUDPandRTPmess( bool b_udp )
233 ui.RTPEdit->setVisible( !b_udp );
234 ui.RTPLabel->setVisible( !b_udp );
235 ui.RTPPort->setVisible( !b_udp );
236 ui.RTPPortLabel->setVisible( !b_udp );
237 ui.UDPEdit->setVisible( b_udp );
238 ui.UDPLabel->setVisible( b_udp );
239 ui.UDPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Audio Port:" ) );
240 ui.RTPPort2->setVisible( !b_udp );
241 ui.RTPPortLabel2->setVisible( !b_udp );
244 void SoutDialog::RTPtoggled( bool b_en )
248 if( ui.RTPPort->value() == ui.UDPPort->value() )
250 ui.UDPPort->setValue( ui.UDPPort->value() + 1 );
253 while( ui.RTPPort2->value() == ui.UDPPort->value() ||
254 ui.RTPPort2->value() == ui.RTPPort->value() )
256 ui.RTPPort2->setValue( ui.RTPPort2->value() + 1 );
259 ui.sap->setEnabled( b_en );
260 ui.RTPLabel->setEnabled( b_en );
261 ui.RTPEdit->setEnabled( b_en );
262 ui.UDPOutput->setEnabled( b_en );
263 ui.UDPRTPLabel->setEnabled( b_en );
264 ui.UDPEdit->setEnabled( b_en );
265 ui.UDPPort->setEnabled( b_en );
266 ui.UDPPortLabel->setEnabled( b_en );
267 ui.RTPPort2->setEnabled( b_en );
268 ui.RTPPortLabel2->setEnabled( b_en );
271 void SoutDialog::ok()
273 mrl = ui.mrlEdit->toPlainText();
277 void SoutDialog::cancel()
283 void SoutDialog::updateMRL()
285 sout_gui_descr_t sout;
286 memset( &sout, 0, sizeof( sout_gui_descr_t ) );
287 unsigned int counter = 0;
289 sout.b_local = ui.localOutput->isChecked();
290 sout.b_file = ui.fileOutput->isChecked();
291 sout.b_http = ui.HTTPOutput->isChecked();
292 sout.b_mms = ui.MMSHOutput->isChecked();
293 sout.b_icecast = ui.IcecastOutput->isChecked();
294 sout.b_rtp = ui.RTPOutput->isChecked();
295 sout.b_udp = ui.UDPOutput->isChecked();
296 sout.b_dump = ui.rawInput->isChecked();
297 sout.b_sap = ui.sap->isChecked();
298 sout.b_all_es = ui.soutAll->isChecked();
299 sout.b_sout_keep = ui.soutKeep->isChecked();
300 /* sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
301 sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
302 sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );*/
303 sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
304 sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
305 sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
306 sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
307 sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
308 sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
309 sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
310 sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
311 sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
312 sout.i_http = ui.HTTPPort->value();
313 sout.i_mms = ui.MMSHPort->value();
314 sout.i_rtp = ui.RTPPort->value();
315 sout.i_rtp_audio = sout.i_udp = ui.UDPPort->value();
316 sout.i_rtp_video = ui.RTPPort2->value();
317 sout.i_icecast = ui.IcecastPort->value();
318 /* sout.i_ab = ui.aBitrateSpin->value();
319 sout.i_vb = ui.vBitrateSpin->value();
320 sout.i_channels = ui.aChannelsSpin->value();
321 sout.f_scale = atof( qtu( ui.vScaleBox->currentText() ) ); */
322 sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
323 sout.psz_name = strdup( qtu( ui.sapName->text() ) );
325 if ( sout.b_local ) counter++ ;
326 if ( sout.b_file ) counter++ ;
327 if ( sout.b_http ) counter++ ;
328 if ( sout.b_mms ) counter++ ;
329 if ( sout.b_rtp ) counter++ ;
330 if ( sout.b_udp ) counter ++;
331 if ( sout.b_icecast ) counter ++;
333 sout.psz_mux = strdup( qtu( ui.profileSelect->getMux() ) );
338 SoutMrl smrl( ":sout=#" );
340 /* Special case for demuxdump */
341 if ( sout.b_file && sout.b_dump )
343 mrl = ":demux=dump :demuxdump-file=";
344 mrl.append( qfu( sout.psz_file ) );
347 if( !ui.profileSelect->getTranscode().isEmpty() )
349 smrl.begin( ui.profileSelect->getTranscode() );
353 /* Protocol output */
354 if ( sout.b_local || sout.b_file || sout.b_http ||
355 sout.b_mms || sout.b_rtp || sout.b_udp || sout.b_icecast )
358 smrl.begin( "duplicate" );
360 #define ADD(m) do { if( counter > 1 ) { \
361 smrl.option( "dst", m.getMrl() ); \
363 smrl.begin( m.getMrl() ); \
370 m.begin( "display" );
382 m.option( "access", "file" );
384 m.option( "mux", qfu( sout.psz_mux ) );
385 m.option( "dst", qfu( sout.psz_file ) );
397 m.option( "access", "http" );
399 m.option( "mux", qfu( sout.psz_mux ) );
400 m.option( "dst", qfu( sout.psz_http ), sout.i_http );
412 m.option( "access", "mmsh" );
413 m.option( "mux", "asfh" );
414 m.option( "dst", qfu( sout.psz_mms ), sout.i_mms );
427 m.option( "access", "udp" );
429 m.option( "mux", qfu( sout.psz_mux ) );
430 m.option( "dst", qfu( sout.psz_udp ), sout.i_udp );
436 if( sout.psz_rtp && *sout.psz_rtp )
437 m.option( "dst", qfu( sout.psz_rtp ) );
439 m.option( "mux", qfu( sout.psz_mux ) );
441 m.option( "port", sout.i_rtp );
442 if( !sout.psz_mux || strncmp( sout.psz_mux, "ts", 2 ) )
444 m.option( "port-audio", sout.i_rtp_audio );
445 m.option( "port-video", sout.i_rtp_video );
453 m.option( "group", qfu( sout.psz_group ) );
454 m.option( "name", qfu( sout.psz_name ) );
467 url = qfu(sout.sa_icecast.psz_username) + "@"
468 + qfu( sout.psz_icecast )
469 + ":" + QString::number( sout.i_icecast, 10 )
470 + "/" + qfu( sout.psz_icecast_mountpoint );
473 m.option( "access", "shout" );
474 m.option( "mux", "ogg" );
475 m.option( "dst", url );
490 mrl.append( " :sout-all" );
492 if ( sout.b_sout_keep )
493 mrl.append( " :sout-keep" );
495 ui.mrlEdit->setPlainText( mrl );
496 free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
497 free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
498 free( sout.psz_name ); free( sout.psz_group );
499 free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
500 free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );