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