]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/sout.cpp
* Made open and sout QDialogs
[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: Errors.cpp 16024 2006-07-13 13:51:05Z xtophe $
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 <QFileDialog>
29
30 SoutDialog::SoutDialog( QWidget *parent, intf_thread_t *_p_intf ) :
31                                                 QVLCDialog( parent,  _p_intf )
32 {
33     //setWindowTitle( qtr( "Stream output") );
34     setModal( true );
35     /* UI stuff */
36     ui.setupUi( this );
37 #define ADD_VCODEC( name, fcc) ui.vCodec->addItem( name, QVariant( fcc ) );
38     ADD_VCODEC( "MPEG-1", "mp1v" );
39     ADD_VCODEC( "MPEG-2", "mp2v" );
40     ADD_VCODEC( "MPEG-4", "mp4v" );
41     ADD_VCODEC( "DIVX 1" , "DIV1" );
42     ADD_VCODEC( "DIVX 2" , "DIV1" );
43     ADD_VCODEC( "DIVX 3" , "DIV1" );
44     ADD_VCODEC( "H-263", "H263" );
45     ADD_VCODEC( "H-264", "h264" );
46     ADD_VCODEC( "WMV1", "WMV1" );
47     ADD_VCODEC( "WMV2" , "WMV2" );
48     ADD_VCODEC( "M-JPEG", "MJPG" );
49     ADD_VCODEC( "Theora", "theo" );
50
51 #define ADD_ACODEC( name, fcc) ui.aCodec->addItem( name, QVariant( fcc ) );
52     ADD_ACODEC( "MPEG Audio", "mpga" );
53     ADD_ACODEC( "MP3", "mp3" );
54     ADD_ACODEC( "MPEG 4 Audio (AAC)", "mp4a");
55     ADD_ACODEC( "A52/AC3", "a52");
56     ADD_ACODEC( "Vorbis", "vorb" );
57     ADD_ACODEC( "Flac", "flac" );
58     ADD_ACODEC( "Speex", "spx" );
59     ADD_ACODEC( "WAV", "s16l" );
60
61     ui.vScale->addItem( "0.25" );
62     ui.vScale->addItem( "0.5" );
63     ui.vScale->addItem( "0.75" );
64     ui.vScale->addItem( "1" );
65     ui.vScale->addItem( "1.25" );
66     ui.vScale->addItem( "1.5" );
67     ui.vScale->addItem( "1.75" );
68     ui.vScale->addItem( "2" );
69
70     /* Connect everything to the updateMRL function */
71 #define CB(x) CONNECT( ui.x, clicked(bool), this, updateMRL() );
72 #define CT(x) CONNECT( ui.x, textChanged(const QString), this, updateMRL() );
73 #define CS(x) CONNECT( ui.x, valueChanged(int), this, updateMRL() );
74 #define CC(x) CONNECT( ui.x, currentIndexChanged(int), this, updateMRL() );
75     /* Output */
76     CB( fileOutput ); CB( HTTPOutput ); CB( localOutput );
77     CB( UDPOutput ); CB( MMSHOutput ); CB( rawInput );
78     CT( fileEdit ); CT( HTTPEdit ); CT( UDPEdit ); CT( MMSHEdit );
79     CS( HTTPPort ); CS( UDPPort ); CS( MMSHPort );
80     /* Transcode */
81     CC( vCodec ); CC( sCodec ); CC( aCodec ) ;
82     CB( transcodeVideo ); CB( transcodeAudio ); CB( transcodeSubs );
83     CB( sOverlay );
84     CS( vBitrate ); CS( aBitrate ); CS( aChannels ); CC( vScale );
85     /* Mux */
86     CB( PSMux ); CB( TSMux ); CB( MPEG1Mux ); CB( OggMux ); CB( ASFMux );
87     CB( MP4Mux ); CB( MOVMux ); CB( WAVMux ); CB( RAWMux );
88     /* Misc */
89     CB( soutAll ); CS( ttl ); CT( sapName ); CT( sapGroup );
90
91     CONNECT( ui.fileSelectButton, clicked(), this, fileBrowse() );
92
93     BUTTONACT( ui.okButton, ok());
94     BUTTONACT( ui.cancelButton, cancel());
95 }
96
97 void SoutDialog::fileBrowse()
98 {
99     QString f = QFileDialog::getOpenFileName( this, qtr("Save file"), "", "" );
100     ui.fileEdit->setText( f );
101     updateMRL();
102 }
103
104 void SoutDialog::ok()
105 {
106     mrl = ui.mrlEdit->text();
107     accept();
108 }
109 void SoutDialog::cancel()
110 {
111     mrl = ui.mrlEdit->text();
112     reject();
113 }
114
115 void SoutDialog::updateMRL()
116 {
117     sout_gui_descr_t pd;
118     memset( &pd, 0, sizeof( sout_gui_descr_t ) );
119
120     /* Output */
121     pd.b_dump = ui.rawInput->isChecked();
122     if( pd.b_dump ) goto end;
123
124     pd.b_local = ui.localOutput->isChecked();
125     pd.b_file = ui.fileOutput->isChecked();
126     pd.b_http = ui.HTTPOutput->isChecked();
127     pd.b_mms = ui.MMSHOutput->isChecked();
128     pd.b_udp = ui.UDPOutput->isChecked();
129
130     pd.psz_file = ui.fileOutput->isChecked() ?
131                             strdup(qtu( ui.fileEdit->text() ) ): NULL;
132     pd.psz_http = ui.HTTPOutput->isChecked() ?
133                             strdup(qtu( ui.HTTPEdit->text() ) ) : NULL;
134     pd.psz_mms = ui.MMSHOutput->isChecked() ?
135                             strdup(qtu( ui.MMSHEdit->text() ) ): NULL;
136     pd.psz_udp = ui.UDPOutput->isChecked() ?
137                             strdup( qtu( ui.UDPEdit->text() ) ): NULL;
138
139     pd.i_http = ui.HTTPPort->value();
140     pd.i_mms = ui.MMSHPort->value();
141     pd.i_udp = ui.UDPPort->value();
142
143     /* Mux */
144 #define SMUX(x, txt) if( ui.x##Mux->isChecked() ) pd.psz_mux = strdup(txt);
145     SMUX( PS, "ps" );
146     SMUX( TS, "ts" );
147     SMUX( MPEG1, "mpeg" );
148     SMUX( Ogg, "ogg" );
149     SMUX( ASF, "asf" );
150     SMUX( MP4, "mp4" );
151     SMUX( MOV, "mov" );
152     SMUX( WAV, "wav" );
153     SMUX( RAW, "raw" );
154
155     /* Transcode */
156     pd.b_soverlay = ui.sOverlay->isChecked();
157     pd.i_vb = ui.vBitrate->value();
158     pd.i_ab = ui.aBitrate->value();
159     pd.i_channels = ui.aChannels->value();
160     pd.f_scale = atof( qta( ui.vScale->currentText() ) );
161
162     pd.psz_vcodec = ui.transcodeVideo->isChecked() ?
163                      strdup( qtu( ui.vCodec->itemData(
164                             ui.vCodec->currentIndex() ). toString() ) ) : NULL;
165     pd.psz_acodec = ui.transcodeAudio->isChecked() ?
166                      strdup( qtu( ui.aCodec->itemData(
167                             ui.aCodec->currentIndex() ).toString() ) ) : NULL;
168     pd.psz_scodec = ui.transcodeSubs->isChecked() ?
169                      strdup( qtu( ui.sCodec->itemData(
170                             ui.sCodec->currentIndex() ).toString() ) ) : NULL;
171     pd.b_sap = ui.sap->isChecked();
172     pd.b_all_es = ui.soutAll->isChecked();
173     pd.psz_name = qtu( ui.sapName->text() );
174     pd.psz_group = qtu( ui.sapGroup->text() );
175     pd.i_ttl = ui.ttl->value() ;
176 end:
177     sout_chain_t* p_chain = streaming_ChainNew();
178     streaming_GuiDescToChain( VLC_OBJECT(p_intf), p_chain, &pd );
179     char *psz_mrl = streaming_ChainToPsz( p_chain );
180
181     ui.mrlEdit->setText( qfu( strdup(psz_mrl) ) );
182     free( pd.psz_acodec ); free( pd.psz_vcodec ); free( pd.psz_scodec );
183     free( pd.psz_file );free( pd.psz_http ); free( pd.psz_mms );
184     free( pd.psz_udp ); free( pd.psz_mux );
185 }