]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
Qt: implement previous button and make an introduction text to the sout...
[vlc] / modules / gui / qt4 / dialogs / sout.cpp
1 /*****************************************************************************
2  * sout.cpp : Stream output dialog ( old-style )
3  ****************************************************************************
4  * Copyright (C) 2007-2008 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 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include "dialogs/sout.hpp"
35 #include "util/qt_dirs.hpp"
36 #include "components/sout/sout_widgets.hpp"
37
38 #include <QString>
39 #include <QFileDialog>
40
41 struct streaming_account_t
42 {
43     char *psz_username; /*< username of account */
44     char *psz_password; /*< password of account */
45 };
46
47 struct sout_gui_descr_t
48 {
49     /* Access types */
50     bool b_local;   /*< local access module */
51     bool b_file;    /*< file access module */
52     bool b_http;    /*< http access module */
53     bool b_mms;     /*< mms access module */
54     bool b_rtp;     /*< rtp access module */
55     bool b_udp;     /*< udp access module */
56     bool b_dump;    /*< dump access module */
57     bool b_icecast; /*< icecast access module */
58
59     char *psz_file;     /*< filename */
60     char *psz_http;     /*< HTTP servername or ipaddress */
61     char *psz_mms;      /*< MMS servername or ipaddress */
62     char *psz_rtp;      /*< RTP servername or ipaddress */
63     char *psz_udp;      /*< UDP servername or ipaddress */
64     char *psz_icecast;  /*< Icecast servername or ipaddress*/
65
66     int32_t i_http;     /*< http port number */
67     int32_t i_mms;      /*< mms port number */
68     int32_t i_rtp;      /*< rtp port number */
69     int32_t i_rtp_audio;      /*< rtp port number */
70     int32_t i_rtp_video;      /*< rtp port number */
71     int32_t i_udp;      /*< udp port number */
72     int32_t i_icecast;  /*< icecast port number */
73
74     /* Mux */
75     char *psz_mux;      /*< name of muxer to use in streaming */
76
77     /* Misc */
78     bool b_sap;   /*< send SAP announcement */
79     bool b_all_es;/*< send all elementary streams from source stream */
80     bool b_sout_keep;
81     char *psz_group;    /*< SAP Group name */
82     char *psz_name;     /*< SAP name */
83     int32_t i_ttl;      /*< Time To Live (TTL) for network traversal */
84
85     /* Icecast */
86     char *psz_icecast_mountpoint;/*< path to Icecast mountpoint */
87     struct streaming_account_t sa_icecast;  /*< Icecast account information */
88 };
89
90 SoutDialog* SoutDialog::instance = NULL;
91
92 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf, QString inputMRL )
93            : QVLCDialog( parent,  _p_intf )
94 {
95     setWindowTitle( qtr( "Stream Output" ) );
96
97     /* UI stuff */
98     ui.setupUi( this );
99     ui.inputBox->setMRL( inputMRL );
100     ui.helpEdit->setPlainText( "This dialog will allow you to stream or convert "
101             "your media, locally, on your private network or on the "
102             "Internet.\n"
103             "You should start by checking that your input matches what you "
104             "want and go on with the \"Next\" button.\n" );
105
106     changeUDPandRTPmess( false );
107
108 /* ADD HERE for new profiles */
109 #define ADD_PROFILE( name, shortname ) ui.profileBox->addItem( qtr( name ), QVariant( QString( shortname ) ) );
110 /*    ADD_PROFILE( "Custom" , "Custom" )
111     ADD_PROFILE( "Ogg / Theora", "theora" )
112     ADD_PROFILE( "Ogg / Vorbis", "vorbis" )
113     ADD_PROFILE( "MPEG-2", "mpeg2" )
114     ADD_PROFILE( "MP3", "mp3" )
115     ADD_PROFILE( "MPEG-4 audio AAC", "aac" )
116     ADD_PROFILE( "MPEG-4 / DivX", "mp4" )
117     ADD_PROFILE( "H264", "h264" )
118     ADD_PROFILE( "IPod (mp4/aac)", "IPod" )
119     ADD_PROFILE( "XBox", "XBox" )
120     ADD_PROFILE( "Windows (wmv/asf)", "Windows" )
121     ADD_PROFILE( "PSP", "PSP")
122
123 */
124     ui.mrlEdit->setToolTip ( qtr( "Stream output string.\n"
125                 "This is automatically generated "
126                  "when you change the above settings,\n"
127                  "but you can change it manually." ) ) ;
128
129 //     /* Connect everything to the updateMRL function */
130  #define CB( x ) CONNECT( ui.x, toggled( bool ), this, updateMRL() );
131  #define CT( x ) CONNECT( ui.x, textChanged( const QString ), this, updateMRL() );
132  #define CS( x ) CONNECT( ui.x, valueChanged( int ), this, updateMRL() );
133  #define CC( x ) CONNECT( ui.x, currentIndexChanged( int ), this, updateMRL() );
134     /* Output */
135     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
136     CB( RTPOutput ); CB( MMSHOutput ); CB( rawInput ); CB( UDPOutput );
137     CT( fileEdit ); CT( HTTPEdit ); CT( RTPEdit ); CT( MMSHEdit ); CT( UDPEdit );
138     CT( IcecastEdit ); CT( IcecastMountpointEdit ); CT( IcecastNamePassEdit );
139     CS( HTTPPort ); CS( RTPPort ); CS( RTPPort2 ); CS( MMSHPort ); CS( UDPPort );
140     /* Misc */
141     CB( soutAll ); CB( soutKeep );  CS( ttl ); CT( sapName ); CT( sapGroup );
142
143 //    CONNECT( ui.profileSelect, optionsChanged(), this, updateMRL() );
144     CONNECT( ui.fileSelectButton, clicked() , this, fileBrowse()  );
145     CONNECT( ui.rawInput, toggled( bool ), this, setRawOptions( bool ) );
146
147     okButton = new QPushButton( qtr( "&Stream" ) );
148     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
149
150     okButton->setDefault( true );
151     ui.acceptButtonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
152     ui.acceptButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
153
154     BUTTONACT( okButton, ok() );
155     BUTTONACT( cancelButton, cancel() );
156
157     CONNECT( ui.UDPOutput, toggled( bool ), this, changeUDPandRTPmess( bool ) );
158     CONNECT( ui.RTPOutput, clicked(bool), this, RTPtoggled( bool ) );
159
160     BUTTONACT( ui.nextButton, next() );
161     BUTTONACT( ui.nextButton2, next() );
162     BUTTONACT( ui.prevButton, prev() );
163     BUTTONACT( ui.prevButton2, prev() );
164 }
165
166 void SoutDialog::next()
167 {
168     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() + 1 );
169 }
170
171 void SoutDialog::prev()
172 {
173     ui.toolBox->setCurrentIndex( ui.toolBox->currentIndex() - 1 );
174 }
175
176
177 void SoutDialog::fileBrowse()
178 {
179     QString fileName = QFileDialog::getSaveFileName( this, qtr( "Save file..." ),
180             "", qtr( "Containers (*.ps *.ts *.mpg *.ogg *.asf *.mp4 *.mov *.wav *.raw *.flv)" ) );
181     ui.fileEdit->setText( toNativeSeparators( fileName ) );
182     updateMRL();
183 }
184
185 void SoutDialog::setRawOptions( bool b_raw )
186 {
187     ui.localOutput->setEnabled( !b_raw );
188     ui.HTTPOutput->setEnabled( !b_raw );
189     ui.MMSHOutput->setEnabled( !b_raw );
190     ui.UDPOutput->setEnabled( !b_raw );
191     ui.RTPOutput->setEnabled( !b_raw );
192     ui.IcecastOutput->setEnabled( !b_raw );
193     ui.UDPRTPLabel->setEnabled( !b_raw );
194
195     if( b_raw ) 
196         ;
197 //        ui.tabWidget->setDisabled( true );
198     else
199         setOptions();
200 }
201
202 void SoutDialog::setOptions()
203 {
204 /*    QString profileString =
205         ui.profileBox->itemData( ui.profileBox->currentIndex() ).toString();
206     msg_Dbg( p_intf, "Profile Used: %s",  qtu( profileString )); */
207     int index;
208
209 #define setProfile( muxName, hasVideo, vCodecName, hasAudio, aCodecName ) \
210     { \
211         ui.muxName ##Mux->setChecked( true ); \
212         \
213         ui.transcodeAudio->setChecked( hasAudio ); \
214         index = ui.aCodecBox->findData( aCodecName );  \
215         if( index >= 0 ) ui.aCodecBox->setCurrentIndex( index ); \
216         \
217         ui.transcodeVideo->setChecked( hasVideo ); \
218         index = ui.vCodecBox->findData( vCodecName );  \
219         if( index >=0 ) ui.vCodecBox->setCurrentIndex( index ); \
220     }
221
222     /* ADD HERE the profiles you want and need */
223 /*    if( profileString == "IPod" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
224     else if( profileString == "theora" ) setProfile( Ogg, true, "theo", true, "vorb" )
225     else if( profileString == "vorbis" ) setProfile( Ogg, false, "", true, "vorb" )
226     else if( profileString == "mpeg2" ) setProfile( TS, true, "mp2v", true, "mpga" )
227     else if( profileString == "mp3" ) setProfile( RAW, false, "", true, "mp3" )
228     else if( profileString == "aac" ) setProfile( MP4, false, "", true, "mp4a" )
229     else if( profileString == "mp4" ) setProfile( MP4, true, "mp4v", true, "mp4a" )
230     else if( profileString == "h264" ) setProfile( TS, true, "h264", true, "mp4a" )
231     else if( profileString == "XBox" ) setProfile( ASF, true, "WMV2", true, "wma" )
232     else if( profileString == "Windows" ) setProfile( ASF, true, "WMV2", true, "wma" )
233     else if( profileString == "PSP" ) setProfile( MP4, true, "mp4v", true, "mp4a" )*/
234
235         /* If the profile is not a custom one, then disable the tabWidget */
236       /*  if ( profileString == "Custom" )
237             ui.tabWidget->setEnabled( true );
238         else
239             ui.tabWidget->setDisabled( true );
240
241     /* Update the MRL !! */
242     updateMRL();
243 }
244
245 void SoutDialog::changeUDPandRTPmess( bool b_udp )
246 {
247     ui.RTPEdit->setVisible( !b_udp );
248     ui.RTPLabel->setVisible( !b_udp );
249     ui.RTPPort->setVisible( !b_udp );
250     ui.RTPPortLabel->setVisible( !b_udp );
251     ui.UDPEdit->setVisible( b_udp );
252     ui.UDPLabel->setVisible( b_udp );
253     ui.UDPPortLabel->setText( b_udp ? qtr( "Port:") : qtr( "Audio Port:" ) );
254     ui.RTPPort2->setVisible( !b_udp );
255     ui.RTPPortLabel2->setVisible( !b_udp );
256 }
257
258 void SoutDialog::RTPtoggled( bool b_en )
259 {
260     if( !b_en )
261     {
262         if( ui.RTPPort->value() == ui.UDPPort->value() )
263         {
264             ui.UDPPort->setValue( ui.UDPPort->value() + 1 );
265         }
266
267         while( ui.RTPPort2->value() == ui.UDPPort->value() ||
268                 ui.RTPPort2->value() == ui.RTPPort->value() )
269         {
270             ui.RTPPort2->setValue( ui.RTPPort2->value() + 1 );
271         }
272     }
273     ui.sap->setEnabled( b_en );
274     ui.RTPLabel->setEnabled( b_en );
275     ui.RTPEdit->setEnabled( b_en );
276     ui.UDPOutput->setEnabled( b_en );
277     ui.UDPRTPLabel->setEnabled( b_en );
278     ui.UDPEdit->setEnabled( b_en );
279     ui.UDPPort->setEnabled( b_en );
280     ui.UDPPortLabel->setEnabled( b_en );
281     ui.RTPPort2->setEnabled( b_en );
282     ui.RTPPortLabel2->setEnabled( b_en );
283 }
284
285 void SoutDialog::ok()
286 {
287     mrl = ui.mrlEdit->toPlainText();
288     accept();
289 }
290
291 void SoutDialog::cancel()
292 {
293     mrl.clear();
294     reject();
295 }
296
297 void SoutDialog::updateMRL()
298 {
299     sout_gui_descr_t sout;
300     memset( &sout, 0, sizeof( sout_gui_descr_t ) );
301     unsigned int counter = 0;
302
303     sout.b_local = ui.localOutput->isChecked();
304     sout.b_file = ui.fileOutput->isChecked();
305     sout.b_http = ui.HTTPOutput->isChecked();
306     sout.b_mms = ui.MMSHOutput->isChecked();
307     sout.b_icecast = ui.IcecastOutput->isChecked();
308     sout.b_rtp = ui.RTPOutput->isChecked();
309     sout.b_udp = ui.UDPOutput->isChecked();
310     sout.b_dump = ui.rawInput->isChecked();
311     sout.b_sap = ui.sap->isChecked();
312     sout.b_all_es = ui.soutAll->isChecked();
313     sout.b_sout_keep = ui.soutKeep->isChecked();
314 /*    sout.psz_vcodec = strdup( qtu( ui.vCodecBox->itemData( ui.vCodecBox->currentIndex() ).toString() ) );
315     sout.psz_acodec = strdup( qtu( ui.aCodecBox->itemData( ui.aCodecBox->currentIndex() ).toString() ) );
316     sout.psz_scodec = strdup( qtu( ui.subsCodecBox->itemData( ui.subsCodecBox->currentIndex() ).toString() ) );*/
317     sout.psz_file = strdup( qtu( ui.fileEdit->text() ) );
318     sout.psz_http = strdup( qtu( ui.HTTPEdit->text() ) );
319     sout.psz_mms = strdup( qtu( ui.MMSHEdit->text() ) );
320     sout.psz_rtp = strdup( qtu( ui.RTPEdit->text() ) );
321     sout.psz_udp = strdup( qtu( ui.UDPEdit->text() ) );
322     sout.psz_icecast = strdup( qtu( ui.IcecastEdit->text() ) );
323     sout.sa_icecast.psz_username = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
324     sout.sa_icecast.psz_password = strdup( qtu( ui.IcecastNamePassEdit->text() ) );
325     sout.psz_icecast_mountpoint = strdup( qtu( ui.IcecastMountpointEdit->text() ) );
326     sout.i_http = ui.HTTPPort->value();
327     sout.i_mms = ui.MMSHPort->value();
328     sout.i_rtp = ui.RTPPort->value();
329     sout.i_rtp_audio = sout.i_udp = ui.UDPPort->value();
330     sout.i_rtp_video = ui.RTPPort2->value();
331     sout.i_icecast = ui.IcecastPort->value();
332 /*    sout.i_ab = ui.aBitrateSpin->value();
333     sout.i_vb = ui.vBitrateSpin->value();
334     sout.i_channels = ui.aChannelsSpin->value();
335     sout.f_scale = atof( qtu( ui.vScaleBox->currentText() ) ); */
336     sout.psz_group = strdup( qtu( ui.sapGroup->text() ) );
337     sout.psz_name = strdup( qtu( ui.sapName->text() ) );
338
339     if ( sout.b_local ) counter++ ;
340     if ( sout.b_file ) counter++ ;
341     if ( sout.b_http ) counter++ ;
342     if ( sout.b_mms ) counter++ ;
343     if ( sout.b_rtp ) counter++ ;
344     if ( sout.b_udp ) counter ++;
345     if ( sout.b_icecast ) counter ++;
346
347     sout.psz_mux = strdup( qtu( ui.profileSelect->getMux() ) );
348
349     bool trans = false;
350     bool more = false;
351
352     SoutMrl smrl( ":sout=#" );
353
354     /* Special case for demuxdump */
355     if ( sout.b_file && sout.b_dump )
356     {
357         mrl = ":demux=dump :demuxdump-file=";
358         mrl.append( qfu( sout.psz_file ) );
359     }
360     else {
361     if( !ui.profileSelect->getTranscode().isEmpty() )
362     {
363         smrl.begin( ui.profileSelect->getTranscode() );
364         smrl.end();
365     }
366
367     /* Protocol output */
368     if ( sout.b_local || sout.b_file || sout.b_http ||
369          sout.b_mms || sout.b_rtp || sout.b_udp || sout.b_icecast )
370     {
371         if( counter > 1 )
372             smrl.begin( "duplicate" );
373
374 #define ADD(m) do { if( counter > 1 ) { \
375                 smrl.option( "dst", m.getMrl() ); \
376             } else { \
377                 smrl.begin( m.getMrl() ); \
378                 smrl.end(); \
379             } } while(0)
380
381         if ( sout.b_local )
382         {
383             SoutMrl m;
384             m.begin( "display" );
385             m.end();
386
387             ADD( m );
388             more = true;
389         }
390
391         if ( sout.b_file )
392         {
393             SoutMrl m;
394
395             m.begin( "std" );
396             m.option( "access", "file" );
397             if( sout.psz_mux )
398                 m.option( "mux", qfu( sout.psz_mux ) );
399             m.option( "dst", qfu( sout.psz_file ) );
400             m.end();
401
402             ADD( m );
403             more = true;
404         }
405
406         if ( sout.b_http )
407         {
408             SoutMrl m;
409
410             m.begin( "std" );
411             m.option(  "access", "http" );
412             if( sout.psz_mux )
413                 m.option( "mux", qfu( sout.psz_mux ) );
414             m.option( "dst", qfu( sout.psz_http ), sout.i_http );
415             m.end();
416
417             ADD( m );
418             more = true;
419         }
420
421         if ( sout.b_mms )
422         {
423             SoutMrl m;
424
425             m.begin( "std" );
426             m.option(  "access", "mmsh" );
427             m.option( "mux", "asfh" );
428             m.option( "dst", qfu( sout.psz_mms ), sout.i_mms );
429             m.end();
430
431             ADD( m );
432             more = true;
433         }
434
435         if ( sout.b_rtp )
436         {
437             SoutMrl m;
438             if ( sout.b_udp )
439             {
440                 m.begin( "std" );
441                 m.option(  "access", "udp" );
442                 if( sout.psz_mux )
443                     m.option( "mux", qfu( sout.psz_mux ) );
444                 m.option( "dst", qfu( sout.psz_udp ), sout.i_udp );
445             }
446             else
447             {
448                 m.begin( "rtp" );
449
450                 if( sout.psz_rtp && *sout.psz_rtp )
451                     m.option( "dst", qfu( sout.psz_rtp ) );
452                 if( sout.psz_mux )
453                     m.option( "mux", qfu( sout.psz_mux ) );
454
455                 m.option( "port", sout.i_rtp );
456                 if( !sout.psz_mux || strncmp( sout.psz_mux, "ts", 2 ) )
457                 {
458                     m.option( "port-audio", sout.i_rtp_audio );
459                     m.option( "port-video", sout.i_rtp_video );
460                 }
461             }
462
463             /* SAP */
464             if ( sout.b_sap )
465             {
466                 m.option( "sap" );
467                 m.option( "group", qfu( sout.psz_group ) );
468                 m.option( "name", qfu( sout.psz_name ) );
469             }
470
471             m.end();
472             ADD( m );
473             more = true;
474         }
475
476         if( sout.b_icecast )
477         {
478             SoutMrl m;
479             QString url;
480
481             url = qfu(sout.sa_icecast.psz_username) + "@"
482                 + qfu( sout.psz_icecast )
483                 + ":" + QString::number( sout.i_icecast, 10 )
484                 + "/" + qfu( sout.psz_icecast_mountpoint );
485
486             m.begin( "std" );
487             m.option( "access", "shout" );
488             m.option( "mux", "ogg" );
489             m.option( "dst", url );
490             m.end();
491
492             ADD( m );
493             more = true;
494         }
495
496         if ( counter )
497             smrl.end();
498
499         mrl = smrl.getMrl();
500     }
501     }
502
503     if ( sout.b_all_es )
504         mrl.append( " :sout-all" );
505
506     if ( sout.b_sout_keep )
507         mrl.append( " :sout-keep" );
508
509     ui.mrlEdit->setPlainText( mrl );
510     free( sout.psz_file );free( sout.psz_http ); free( sout.psz_mms );
511     free( sout.psz_rtp ); free( sout.psz_udp ); free( sout.psz_mux );
512     free( sout.psz_name ); free( sout.psz_group );
513     free( sout.psz_icecast ); free( sout.psz_icecast_mountpoint );
514     free( sout.sa_icecast.psz_password ); free( sout.sa_icecast.psz_username );
515 }
516
517