]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt4 - FIXME and comments fix. If you want to help, just grep -r FIXME *
[vlc] / modules / gui / qt4 / dialogs / sout.cpp
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
7  *
8  * $Id$
9  *
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>
14  *
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.
19  *
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.
24  *
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  *****************************************************************************/
29
30 #include "dialogs/sout.hpp"
31 #include <vlc_streaming.h>
32
33 #include <iostream>
34 #include <QString>
35 #include <QFileDialog>
36
37 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf,
38                      bool _transcode_only ) : QVLCDialog( parent,  _p_intf )
39 {
40     setWindowTitle( qtr( "Stream output" ) );
41
42     b_transcode_only = _transcode_only;
43
44     /* UI stuff */
45     ui.setupUi( this );
46
47     ui.UDPEdit->hide(); ui.UDPLabel->hide();
48     ui.UDPPort->hide(); ui.UDPPortLabel->hide();
49 /* ADD HERE for new profiles */
50 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
51     ADD_PROFILE( "Custom" , "Custom" )
52     ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
53     ADD_PROFILE( "XBox", "XBox" )
54     ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
55     ADD_PROFILE( "PSP", "PSP")
56     ADD_PROFILE( "GSM", "GSM" )
57
58 #define ADD_VCODEC( name, fourcc ) ui.vCodecBox->addItem( name, QVariant( fourcc ) );
59     ADD_VCODEC( "MPEG-1", "mp1v" )
60     ADD_VCODEC( "MPEG-2", "mp2v" )
61     ADD_VCODEC( "MPEG-4", "mp4v" )
62     ADD_VCODEC( "DIVX 1" , "DIV1" )
63     ADD_VCODEC( "DIVX 2" , "DIV1" )
64     ADD_VCODEC( "DIVX 3" , "DIV1" )
65     ADD_VCODEC( "H-263", "H263" )
66     ADD_VCODEC( "H-264", "h264" )
67     ADD_VCODEC( "WMV1", "WMV1" )
68     ADD_VCODEC( "WMV2" , "WMV2" )
69     ADD_VCODEC( "M-JPEG", "MJPG" )
70     ADD_VCODEC( "Theora", "theo" )
71
72 #define ADD_ACODEC( name, fourcc ) ui.aCodecBox->addItem( name, QVariant( fourcc ) );
73     ADD_ACODEC( "MPEG Audio", "mpga" )
74     ADD_ACODEC( "MP3", "mp3" )
75     ADD_ACODEC( "MPEG 4 Audio ( AAC )", "mp4a" )
76     ADD_ACODEC( "A52/AC-3", "a52" )
77     ADD_ACODEC( "Vorbis", "vorb" )
78     ADD_ACODEC( "Flac", "flac" )
79     ADD_ACODEC( "Speex", "spx" )
80     ADD_ACODEC( "WAV", "s16l" )
81     ADD_ACODEC( "WMA", "wma" )
82
83 #define ADD_SCALING( factor ) ui.vScaleBox->addItem( factor );
84     ADD_SCALING( "0.25" )
85     ADD_SCALING( "0.5" )
86     ADD_SCALING( "0.75" )
87     ADD_SCALING( "1" )
88     ADD_SCALING( "1.25" )
89     ADD_SCALING( "1.5" )
90     ADD_SCALING( "1.75" )
91     ADD_SCALING( "2" )
92
93     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n This is automatically generated "
94                                                 "when you change the above settings,\n but you can update it manually." ) ) ;
95
96 //     /* Connect everything to the updateMRL function */
97  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
98  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
99  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
100  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
101 //     /* Output */
102     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
103     CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
104     CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
105     CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
106     CS( HTTPPort ); CS( RTPPort ); CS( MMSHPort ); CS( UDPPort );
107 //     /* Transcode */
108     CC( vCodecBox ); CC( subsCodecBox ); CC( aCodecBox ) ;
109     CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
110 //     CB( sOverlay );
111     CS( vBitrateSpin ); CS( aBitrateSpin ); CS( aChannelsSpin ); CC( vScaleBox );
112 //     /* Mux */
113     CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
114     CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux ); CB( FLVMux );
115 //     /* Misc */
116     CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
117 //
118     CONNECT( ui.profileBox, activated( const QString & ), this, setOptions() );
119     CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse()  );
120     CONNECT( ui.transcodeVideo, toggled( bool ), this, setVTranscodeOptions( bool ) );
121     CONNECT( ui.transcodeAudio, toggled( bool ), this, setATranscodeOptions( bool ) );
122     CONNECT( ui.transcodeSubs, toggled( bool ), this, setSTranscodeOptions( bool ) );
123     CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
124
125     okButton = new QPushButton( qtr( "&Stream" ) );
126     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
127
128     okButton->setDefault( true );
129     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
130     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
131
132     BUTTONACT( okButton, ok() );
133     BUTTONACT( cancelButton, cancel() );
134
135     if( b_transcode_only ) toggleSout();
136 }
137
138 QString SoutDialog::getMrl()
139 {
140     return mrl;
141 }
142
143 void SoutDialog::fileBrowse()
144 {
145     ui.tabWidget->setTabEnabled( 0,false );
146     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
147         qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
148     ui.fileEdit->setText( fileName );
149     updateMRL();
150 }
151
152 void SoutDialog::setVTranscodeOptions( bool b_trans )
153 {
154     ui.vCodecLabel->setEnabled( b_trans );
155     ui.vCodecBox->setEnabled( b_trans );
156     ui.vBitrateLabel->setEnabled( b_trans );
157     ui.vBitrateSpin->setEnabled( b_trans );
158     ui.vScaleLabel->setEnabled( b_trans );
159     ui.vScaleBox->setEnabled( b_trans );
160 }
161
162 void SoutDialog::setATranscodeOptions( bool b_trans )
163 {
164     ui.aCodecLabel->setEnabled( b_trans );
165     ui.aCodecBox->setEnabled( b_trans );
166     ui.aBitrateLabel->setEnabled( b_trans );
167     ui.aBitrateSpin->setEnabled( b_trans );
168     ui.aChannelsLabel->setEnabled( b_trans );
169     ui.aChannelsSpin->setEnabled( b_trans );
170 }
171
172 void SoutDialog::setSTranscodeOptions( bool b_trans )
173 {
174     ui.subsCodecBox->setEnabled( b_trans );
175     ui.subsOverlay->setEnabled( b_trans );
176 }
177
178 void SoutDialog::setRawOptions( bool b_raw )
179 {
180     if( b_raw )
181     {
182         ui.tabWidget->setDisabled( true );
183     }
184     else
185     {
186         SoutDialog::setOptions();
187     }
188 }
189
190 void SoutDialog::setOptions()
191 {
192     QString profileString = ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
193     msg_Dbg( p_intf, "Profile Used: %s",  qta( profileString ));
194     int index;
195
196 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
197     { \
198         ui.muxName ##Mux->setChecked( true ); \
199         \
200         ui.transcodeAudio->setChecked( hasAudio ); \
201         index = ui.aCodecBox->findText( vCodecName );  \
202         if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
203         \
204         ui.transcodeVideo->setChecked( hasVideo ); \
205         index = ui.aCodecBox->findText( vCodecName );  \
206         if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
207     }
208
209     /* ADD HERE the profiles you want and need */
210     /* FIXME */
211     if( profileString == "IPod" ) setProfile( MP4, true, "mp4a", true, "mp4v" )
212     else if( profileString == "XBox" ) setProfile( ASF, true, "wma", true, "WMV2" )
213
214         /* If the profile is not a custom one, then disable the tabWidget */
215         if ( profileString == "Custom" )
216         {
217             ui.tabWidget->setEnabled( true );
218         }
219         else
220         {
221             ui.tabWidget->setDisabled( true );
222         }
223
224     /* Update the MRL !! */
225     updateMRL();
226 }
227
228 void SoutDialog::toggleSout()
229 {
230     //Toggle all the streaming options.
231     TOGGLEV( ui.HTTPOutput ) ; TOGGLEV( ui.RTPOutput ) ; TOGGLEV( ui.MMSHOutput ) ; TOGGLEV( ui.UDPOutput ) ;
232     TOGGLEV( ui.HTTPEdit ) ; TOGGLEV( ui.RTPEdit ) ; TOGGLEV( ui.MMSHEdit ) ; TOGGLEV( ui.UDPEdit ) ;
233     TOGGLEV( ui.HTTPLabel ) ; TOGGLEV( ui.RTPLabel ) ; TOGGLEV( ui.MMSHLabel ) ; TOGGLEV( ui.UDPLabel ) ;
234     TOGGLEV( ui.HTTPPortLabel ) ; TOGGLEV( ui.RTPPortLabel ) ; TOGGLEV( ui.MMSHPortLabel ) ; TOGGLEV( ui.UDPPortLabel )
235     TOGGLEV( ui.HTTPPort ) ; TOGGLEV( ui.RTPPort ) ; TOGGLEV( ui.MMSHPort ) ; TOGGLEV( ui.UDPPort ) ;
236
237     TOGGLEV( ui.sap ); TOGGLEV( ui.sapName );
238     TOGGLEV( ui.sapGroup ); TOGGLEV( ui.sapGroupLabel );
239     TOGGLEV( ui.ttlLabel ); TOGGLEV( ui.ttl );
240
241     if( b_transcode_only ) okButton->setText( "&Save" );
242     else okButton->setText( "&Stream" );
243
244     updateGeometry();
245 }
246
247 void SoutDialog::ok()
248 {
249     mrl = ui.mrlEdit->text();
250     accept();
251 }
252 void SoutDialog::cancel()
253 {
254     mrl = ui.mrlEdit->text();
255     reject();
256 }
257
258 void SoutDialog::updateMRL()
259 {
260     sout_gui_descr_t sout;
261     memset( &sout, 0, sizeof( sout_gui_descr_t ) );
262     unsigned int counter = 0;
263
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_icecast = ui.IcecastOutput->isChecked();
269     sout.b_rtp = ui.RTPOutput->isChecked();
270     sout.b_udp = ui.UDPOutput->isChecked();
271     sout.b_sap = ui.sap->isChecked();
272     sout.b_all_es = ui.soutAll->isChecked();
273     sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
274     sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
275     sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
276     sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
277     sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
278     sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
279     sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
280     sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
281     sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
282     sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
283     sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
284     sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
285     sout.i_http = ui.HTTPPort->value();
286     sout.i_mms = ui.MMSHPort->value();
287     sout.i_rtp = ui.RTPPort->value();
288     sout.i_udp = ui.UDPPort->value();
289     sout.i_icecast = ui.IcecastPort->value();
290     sout.i_ab = ui.aBitrateSpin->value();
291     sout.i_vb = ui.vBitrateSpin->value();
292     sout.i_channels = ui.aChannelsSpin->value();
293     sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
294     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
295     sout.psz_name = strdup( qtu( ui.sapName->text() ) );
296
297     if ( sout.b_local ) counter++ ;
298     if ( sout.b_file ) counter++ ;
299     if ( sout.b_http ) counter++ ;
300     if ( sout.b_mms ) counter++ ;
301     if ( sout.b_rtp ) counter++ ;
302     if ( sout.b_udp ) counter ++;
303     if ( sout.b_icecast ) counter ++;
304
305 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
306     SMUX( PSMux, "ps" );
307     SMUX( TSMux, "ts" );
308     SMUX( MPEG1Mux, "mpeg" );
309     SMUX( OggMux, "ogg" );
310     SMUX( ASFMux, "asf" );
311     SMUX( MP4Mux, "mp4" );
312     SMUX( MOVMux, "mov" );
313     SMUX( WAVMux, "wav" );
314     SMUX( RAWMux, "raw" );
315     SMUX( FLVMux, "flv" );
316     SMUX( MKVMux, "mkv" );
317
318     bool trans = false;
319     bool more = false;
320
321     if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
322     {
323         if ( ui.transcodeVideo->isChecked() )
324         {
325             mrl = ":sout=#transcode{";
326             mrl.append( "vcodec=" );
327             mrl.append( sout.psz_vcodec );
328             mrl.append( "," );
329             mrl.append( "vb=" );
330             mrl.append( QString::number( sout.i_vb,10 ) );
331             mrl.append( "," );
332             mrl.append( "scale=" );
333             mrl.append( QString::number( sout.f_scale ) );
334             trans = true;
335         }
336
337         if ( ui.transcodeAudio->isChecked() )
338         {
339             if ( trans )
340             {
341                 mrl.append( "," );
342             }
343             else
344             {
345                 mrl = ":sout=#transcode{";
346             }
347             mrl.append( "acodec=" );
348             mrl.append( sout.psz_acodec );
349             mrl.append( "," );
350             mrl.append( "ab=" );
351             mrl.append( QString::number( sout.i_ab,10 ) );
352             mrl.append( "," );
353             mrl.append( "channels=" );
354             mrl.append( QString::number( sout.i_channels,10 ) );
355             trans = true;
356         }
357         mrl.append( "}" );
358     }
359
360     if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_rtp || sout.b_udp )
361     {
362
363 #define ISMORE() if ( more ) mrl.append( "," );
364 #define ATLEASTONE() if ( counter ) mrl.append( "dst=" );
365
366 #define CHECKMUX() \
367        if( sout.psz_mux ) \
368        {                  \
369          mrl.append( ",mux=");\
370          mrl.append( sout.psz_mux ); \
371        }
372
373         if ( trans )
374         {
375             mrl.append( ":" );
376         }
377         else
378         {
379             mrl = ":sout=#";
380         }
381
382         if ( counter )
383         {
384             mrl.append( "duplicate{" );
385         }
386
387         if ( sout.b_local )
388         {
389             ISMORE();
390             ATLEASTONE()
391                 mrl.append( "display" );
392             more = true;
393         }
394
395         if ( sout.b_file )
396         {
397             ISMORE();
398             ATLEASTONE()
399                 mrl.append( "std{access=file" );
400             CHECKMUX();
401             mrl.append( ",dst=" );
402             mrl.append( sout.psz_file );
403             mrl.append( "}" );
404             more = true;
405         }
406
407         if ( sout.b_http )
408         {
409             ISMORE();
410             ATLEASTONE()
411                 mrl.append( "std{access=http" );
412             CHECKMUX();
413             mrl.append( ",dst=" );
414             mrl.append( sout.psz_http );
415             mrl.append( ":" );
416             mrl.append( QString::number( sout.i_http,10 ) );
417             mrl.append( "}" );
418             more = true;
419         }
420
421         if ( sout.b_mms )
422         {
423             ISMORE();
424             ATLEASTONE()
425                 mrl.append( "std{access=mmsh" );
426             CHECKMUX();
427             mrl.append( ",dst=" );
428             mrl.append( sout.psz_mms );
429             mrl.append( ":" );
430             mrl.append( QString::number( sout.i_mms,10 ) );
431             mrl.append( "}" );
432             more = true;
433         }
434
435         if ( sout.b_rtp )
436         {
437             ISMORE();
438             ATLEASTONE()
439                 mrl.append( "rtp{" );
440             CHECKMUX();
441             mrl.append( ",dst=" );
442             mrl.append( sout.psz_rtp );
443             mrl.append( ":" );
444             mrl.append( QString::number( sout.i_rtp,10 ) );
445             mrl.append( "}" );
446             more = true;
447         }
448
449         if ( sout.b_udp )
450         {
451             ISMORE();
452             ATLEASTONE()
453             mrl.append( "std{access=udp" );
454             CHECKMUX();
455             mrl.append( ",dst=" );
456             mrl.append( sout.psz_udp );
457             mrl.append( ":" );
458             mrl.append( QString::number( sout.i_udp,10 ) );
459             if ( sout.b_sap )
460             {
461                 mrl.append( ",sap," );
462                 mrl.append( "group=\"" );
463                 mrl.append( sout.psz_group );
464                 mrl.append( "\"," );
465                 mrl.append( "name=\"" );
466                 mrl.append( sout.psz_name );
467                 mrl.append( "\"" );
468             }
469             mrl.append( "}" );
470             more = true;
471         }
472
473         if( sout.b_icecast )
474         {
475             // TODO
476         }
477
478         if ( counter )
479         {
480             mrl.append( "}" );
481         }
482     }
483
484 #undef CHECKMUX
485
486     if ( sout.b_all_es )
487         mrl.append( ":sout-all" );
488
489     ui.mrlEdit->setText( mrl );
490     free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
491     free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
492     free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
493     free( sout.psz_name ); free( sout.psz_group );
494     free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
495     free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );
496 }