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