]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt4 - Use a main instance of Sout for VLM. Clean DP since all dialogs (except Bookmar...
[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 void SoutDialog::fileBrowse()
139 {
140     ui.tabWidget->setTabEnabled( 0,false );
141     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file" ), "",
142         qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
143     ui.fileEdit->setText( fileName );
144     updateMRL();
145 }
146
147 void SoutDialog::setVTranscodeOptions( bool b_trans )
148 {
149     ui.vCodecLabel->setEnabled( b_trans );
150     ui.vCodecBox->setEnabled( b_trans );
151     ui.vBitrateLabel->setEnabled( b_trans );
152     ui.vBitrateSpin->setEnabled( b_trans );
153     ui.vScaleLabel->setEnabled( b_trans );
154     ui.vScaleBox->setEnabled( b_trans );
155 }
156
157 void SoutDialog::setATranscodeOptions( bool b_trans )
158 {
159     ui.aCodecLabel->setEnabled( b_trans );
160     ui.aCodecBox->setEnabled( b_trans );
161     ui.aBitrateLabel->setEnabled( b_trans );
162     ui.aBitrateSpin->setEnabled( b_trans );
163     ui.aChannelsLabel->setEnabled( b_trans );
164     ui.aChannelsSpin->setEnabled( b_trans );
165 }
166
167 void SoutDialog::setSTranscodeOptions( bool b_trans )
168 {
169     ui.subsCodecBox->setEnabled( b_trans );
170     ui.subsOverlay->setEnabled( b_trans );
171 }
172
173 void SoutDialog::setRawOptions( bool b_raw )
174 {
175     if( b_raw )
176     {
177         ui.tabWidget->setDisabled( true );
178     }
179     else
180     {
181         SoutDialog::setOptions();
182     }
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 = ui.aCodecBox->findText( vCodecName );  \
197         if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
198         \
199         ui.transcodeVideo->setChecked( hasVideo ); \
200         index = ui.aCodecBox->findText( vCodecName );  \
201         if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
202     }
203
204     /* ADD HERE the profiles you want and need */
205     /* FIXME */
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     unsigned 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_icecast = ui.IcecastOutput->isChecked();
264     sout.b_rtp = ui.RTPOutput->isChecked();
265     sout.b_udp = ui.UDPOutput->isChecked();
266     sout.b_sap = ui.sap->isChecked();
267     sout.b_all_es = ui.soutAll->isChecked();
268     sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
269     sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
270     sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );
271     sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
272     sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
273     sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
274     sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
275     sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
276     sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
277     sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
278     sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
279     sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
280     sout.i_http = ui.HTTPPort->value();
281     sout.i_mms = ui.MMSHPort->value();
282     sout.i_rtp = ui.RTPPort->value();
283     sout.i_udp = ui.UDPPort->value();
284     sout.i_icecast = ui.IcecastPort->value();
285     sout.i_ab = ui.aBitrateSpin->value();
286     sout.i_vb = ui.vBitrateSpin->value();
287     sout.i_channels = ui.aChannelsSpin->value();
288     sout.f_scale = atof( qta( ui.vScaleBox->currentText() ) );
289     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
290     sout.psz_name = strdup( qtu( ui.sapName->text() ) );
291
292     if ( sout.b_local ) counter++ ;
293     if ( sout.b_file ) counter++ ;
294     if ( sout.b_http ) counter++ ;
295     if ( sout.b_mms ) counter++ ;
296     if ( sout.b_rtp ) counter++ ;
297     if ( sout.b_udp ) counter ++;
298     if ( sout.b_icecast ) counter ++;
299
300 #define SMUX( x, txt ) if( ui.x->isChecked() ) sout.psz_mux = strdup( txt );
301     SMUX( PSMux, "ps" );
302     SMUX( TSMux, "ts" );
303     SMUX( MPEG1Mux, "mpeg" );
304     SMUX( OggMux, "ogg" );
305     SMUX( ASFMux, "asf" );
306     SMUX( MP4Mux, "mp4" );
307     SMUX( MOVMux, "mov" );
308     SMUX( WAVMux, "wav" );
309     SMUX( RAWMux, "raw" );
310     SMUX( FLVMux, "flv" );
311     SMUX( MKVMux, "mkv" );
312
313     bool trans = false;
314     bool more = false;
315
316     if ( ui.transcodeVideo->isChecked() || ui.transcodeAudio->isChecked() )
317     {
318         if ( ui.transcodeVideo->isChecked() )
319         {
320             mrl = ":sout=#transcode{";
321             mrl.append( "vcodec=" );
322             mrl.append( sout.psz_vcodec );
323             mrl.append( "," );
324             mrl.append( "vb=" );
325             mrl.append( QString::number( sout.i_vb,10 ) );
326             mrl.append( "," );
327             mrl.append( "scale=" );
328             mrl.append( QString::number( sout.f_scale ) );
329             trans = true;
330         }
331
332         if ( ui.transcodeAudio->isChecked() )
333         {
334             if ( trans )
335             {
336                 mrl.append( "," );
337             }
338             else
339             {
340                 mrl = ":sout=#transcode{";
341             }
342             mrl.append( "acodec=" );
343             mrl.append( sout.psz_acodec );
344             mrl.append( "," );
345             mrl.append( "ab=" );
346             mrl.append( QString::number( sout.i_ab,10 ) );
347             mrl.append( "," );
348             mrl.append( "channels=" );
349             mrl.append( QString::number( sout.i_channels,10 ) );
350             trans = true;
351         }
352         mrl.append( "}" );
353     }
354
355     if ( sout.b_local || sout.b_file || sout.b_http || sout.b_mms || sout.b_rtp || sout.b_udp )
356     {
357
358 #define ISMORE() if ( more ) mrl.append( "," );
359 #define ATLEASTONE() if ( counter ) mrl.append( "dst=" );
360
361 #define CHECKMUX() \
362        if( sout.psz_mux ) \
363        {                  \
364          mrl.append( ",mux=");\
365          mrl.append( sout.psz_mux ); \
366        }
367
368         if ( trans )
369         {
370             mrl.append( ":" );
371         }
372         else
373         {
374             mrl = ":sout=#";
375         }
376
377         if ( counter )
378         {
379             mrl.append( "duplicate{" );
380         }
381
382         if ( sout.b_local )
383         {
384             ISMORE();
385             ATLEASTONE()
386                 mrl.append( "display" );
387             more = true;
388         }
389
390         if ( sout.b_file )
391         {
392             ISMORE();
393             ATLEASTONE()
394                 mrl.append( "std{access=file" );
395             CHECKMUX();
396             mrl.append( ",dst=" );
397             mrl.append( sout.psz_file );
398             mrl.append( "}" );
399             more = true;
400         }
401
402         if ( sout.b_http )
403         {
404             ISMORE();
405             ATLEASTONE()
406                 mrl.append( "std{access=http" );
407             CHECKMUX();
408             mrl.append( ",dst=" );
409             mrl.append( sout.psz_http );
410             mrl.append( ":" );
411             mrl.append( QString::number( sout.i_http,10 ) );
412             mrl.append( "}" );
413             more = true;
414         }
415
416         if ( sout.b_mms )
417         {
418             ISMORE();
419             ATLEASTONE()
420                 mrl.append( "std{access=mmsh" );
421             CHECKMUX();
422             mrl.append( ",dst=" );
423             mrl.append( sout.psz_mms );
424             mrl.append( ":" );
425             mrl.append( QString::number( sout.i_mms,10 ) );
426             mrl.append( "}" );
427             more = true;
428         }
429
430         if ( sout.b_rtp )
431         {
432             ISMORE();
433             ATLEASTONE()
434                 mrl.append( "rtp{" );
435             CHECKMUX();
436             mrl.append( ",dst=" );
437             mrl.append( sout.psz_rtp );
438             mrl.append( ":" );
439             mrl.append( QString::number( sout.i_rtp,10 ) );
440             mrl.append( "}" );
441             more = true;
442         }
443
444         if ( sout.b_udp )
445         {
446             ISMORE();
447             ATLEASTONE()
448             mrl.append( "std{access=udp" );
449             CHECKMUX();
450             mrl.append( ",dst=" );
451             mrl.append( sout.psz_udp );
452             mrl.append( ":" );
453             mrl.append( QString::number( sout.i_udp,10 ) );
454             if ( sout.b_sap )
455             {
456                 mrl.append( ",sap," );
457                 mrl.append( "group=\"" );
458                 mrl.append( sout.psz_group );
459                 mrl.append( "\"," );
460                 mrl.append( "name=\"" );
461                 mrl.append( sout.psz_name );
462                 mrl.append( "\"" );
463             }
464             mrl.append( "}" );
465             more = true;
466         }
467
468         if( sout.b_icecast )
469         {
470             // TODO
471         }
472
473         if ( counter )
474         {
475             mrl.append( "}" );
476         }
477     }
478
479 #undef CHECKMUX
480
481     if ( sout.b_all_es )
482         mrl.append( ":sout-all" );
483
484     ui.mrlEdit->setText( mrl );
485     free( sout.psz_acodec ); free( sout.psz_vcodec ); free( sout.psz_scodec );
486     free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
487     free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
488     free( sout.psz_name ); free( sout.psz_group );
489     free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
490     free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );
491 }