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