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