1 /*****************************************************************************
2 * streamout.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: streamout.cpp,v 1.3 2003/03/29 11:15:14 gbazin Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
44 #include <wx/notebook.h>
45 #include <wx/textctrl.h>
46 #include <wx/combobox.h>
47 #include <wx/spinctrl.h>
48 #include <wx/statline.h>
52 #include "wxwindows.h"
55 # define wxRB_SINGLE 0
74 /*****************************************************************************
76 *****************************************************************************/
78 /* IDs for the controls and the menu commands */
81 Notebook_Event = wxID_HIGHEST,
88 AccessRadio1_Event, AccessRadio2_Event,
89 AccessRadio3_Event, AccessRadio4_Event,
93 EncapsulationRadio1_Event, EncapsulationRadio2_Event,
94 EncapsulationRadio3_Event, EncapsulationRadio4_Event,
97 BEGIN_EVENT_TABLE(SoutDialog, wxDialog)
99 EVT_BUTTON(wxID_OK, SoutDialog::OnOk)
100 EVT_BUTTON(wxID_CANCEL, SoutDialog::OnCancel)
102 /* Events generated by the access output panel */
103 EVT_RADIOBUTTON(AccessRadio1_Event, SoutDialog::OnAccessTypeChange)
104 EVT_RADIOBUTTON(AccessRadio2_Event, SoutDialog::OnAccessTypeChange)
105 EVT_RADIOBUTTON(AccessRadio3_Event, SoutDialog::OnAccessTypeChange)
106 EVT_RADIOBUTTON(AccessRadio4_Event, SoutDialog::OnAccessTypeChange)
107 EVT_TEXT(FileName_Event, SoutDialog::OnFileChange)
108 EVT_BUTTON(FileBrowse_Event, SoutDialog::OnFileBrowse)
109 EVT_TEXT(NetPort_Event, SoutDialog::OnNetChange)
110 EVT_SPINCTRL(NetPort_Event, SoutDialog::OnNetChange)
111 EVT_TEXT(NetAddr_Event, SoutDialog::OnNetChange)
113 /* Events generated by the encapsulation panel */
114 EVT_RADIOBUTTON(EncapsulationRadio1_Event,
115 SoutDialog::OnEncapsulationChange)
116 EVT_RADIOBUTTON(EncapsulationRadio2_Event,
117 SoutDialog::OnEncapsulationChange)
118 EVT_RADIOBUTTON(EncapsulationRadio3_Event,
119 SoutDialog::OnEncapsulationChange)
120 EVT_RADIOBUTTON(EncapsulationRadio4_Event,
121 SoutDialog::OnEncapsulationChange)
125 /*****************************************************************************
127 *****************************************************************************/
128 SoutDialog::SoutDialog( intf_thread_t *_p_intf, Interface *_p_main_interface ):
129 wxDialog( _p_main_interface, -1, _("Stream Output"), wxDefaultPosition,
130 wxDefaultSize, wxDEFAULT_FRAME_STYLE )
132 /* Initializations */
134 p_main_interface = _p_main_interface;
136 /* Create a panel to put everything in */
137 wxPanel *panel = new wxPanel( this, -1 );
138 panel->SetAutoLayout( TRUE );
140 /* Create MRL combobox */
141 wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
142 wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
143 _("Stream Output MRL") );
144 wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
146 wxStaticText *mrl_label = new wxStaticText( panel, -1,
147 _("Destination Target:") );
148 mrl_combo = new wxComboBox( panel, MRL_Event, mrl,
149 wxPoint(20,25), wxSize(120, -1),
151 mrl_sizer->Add( mrl_label, 0, wxEXPAND | wxALL, 5 );
152 mrl_sizer->Add( mrl_combo, 1, wxEXPAND | wxALL, 5 );
153 mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
155 /* Create the output encapsulation panel */
156 encapsulation_panel = EncapsulationPanel( panel );
158 /* Create the access output panel */
159 access_panel = AccessPanel( panel );
162 wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
164 /* Create the buttons */
165 wxButton *ok_button = new wxButton( panel, wxID_OK, _("OK") );
166 ok_button->SetDefault();
167 wxButton *cancel_button = new wxButton( panel, wxID_CANCEL, _("Cancel") );
169 /* Place everything in sizers */
170 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
171 button_sizer->Add( ok_button, 0, wxALL, 5 );
172 button_sizer->Add( cancel_button, 0, wxALL, 5 );
173 button_sizer->Layout();
174 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
175 wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
176 panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
177 panel_sizer->Add( access_panel, 1, wxEXPAND | wxALL, 5 );
178 panel_sizer->Add( encapsulation_panel, 0, wxEXPAND | wxALL, 5 );
179 panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
180 panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
182 panel_sizer->Layout();
183 panel->SetSizerAndFit( panel_sizer );
184 main_sizer->Add( panel, 1, wxGROW, 0 );
185 main_sizer->Layout();
186 SetSizerAndFit( main_sizer );
188 /* Update all the values */
192 SoutDialog::~SoutDialog()
196 /*****************************************************************************
198 *****************************************************************************/
199 void SoutDialog::UpdateMRL()
201 wxString encapsulation;
203 switch( i_encapsulation_type )
205 case PS_ENCAPSULATION:
206 encapsulation = "/ps";
208 case AVI_ENCAPSULATION:
209 encapsulation = "/avi";
211 case OGG_ENCAPSULATION:
212 encapsulation = "/ogg";
214 case TS_ENCAPSULATION:
216 encapsulation = "/ts";
220 switch( i_access_type )
222 case FILE_ACCESS_OUT:
223 mrl = "file" + encapsulation + ":" + file_combo->GetValue();
226 case HTTP_ACCESS_OUT:
227 mrl = "http" + encapsulation + ":" + net_addr->GetLineText(0)
228 + wxString::Format( ":%d", net_port->GetValue() );
233 mrl = ( i_access_type == UDP_ACCESS_OUT ) ? "udp" : "rtp";
234 mrl += encapsulation + ":" + net_addr->GetLineText(0);
235 if( net_port->GetValue() != config_GetInt( p_intf, "server-port" ) )
237 mrl += wxString::Format( ":%d", net_port->GetValue() );
242 mrl_combo->SetValue( mrl );
245 wxPanel *SoutDialog::AccessPanel( wxWindow* parent )
248 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
251 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
252 wxStaticBox *panel_box = new wxStaticBox( panel, -1, _("Output Method") );
253 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
256 static const wxString access_output_array[] =
266 access_radios[i] = new wxRadioButton( panel, AccessRadio1_Event + i,
267 access_output_array[i],
268 wxDefaultPosition, wxDefaultSize,
271 access_subpanels[i] = new wxPanel( panel, -1,
272 wxDefaultPosition, wxDefaultSize );
276 wxFlexGridSizer *subpanel_sizer;
278 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
279 label = new wxStaticText( access_subpanels[0], -1, _("Filename") );
280 file_combo = new wxComboBox( access_subpanels[0], FileName_Event, "",
281 wxPoint(20,25), wxSize(200, -1), 0, NULL );
282 wxButton *browse_button = new wxButton( access_subpanels[0],
283 FileBrowse_Event, _("Browse...") );
284 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
285 subpanel_sizer->Add( file_combo, 1,
286 wxEXPAND | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
287 subpanel_sizer->Add( browse_button, 0,
288 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
290 access_subpanels[0]->SetSizerAndFit( subpanel_sizer );
293 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
294 label = new wxStaticText( access_subpanels[2], -1, _("Address") );
295 net_addr = new wxTextCtrl( access_subpanels[2], NetAddr_Event, "",
296 wxDefaultPosition, wxSize( 200, -1 ),
298 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
299 subpanel_sizer->Add( net_addr, 1,
300 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
302 int val = config_GetInt( p_intf, "server-port" );
303 label = new wxStaticText( access_subpanels[2], -1, _("Port") );
304 net_port = new wxSpinCtrl( access_subpanels[2], NetPort_Event,
305 wxString::Format(_("%d"), val),
306 wxDefaultPosition, wxDefaultSize,
310 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
311 subpanel_sizer->Add( net_port, 0,
312 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
314 access_subpanels[2]->SetSizerAndFit( subpanel_sizer );
317 /* Stuff everything into the main panel */
320 sizer->Add( access_radios[i], 0,
321 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
322 sizer->Add( access_subpanels[i], 1, wxEXPAND | wxALIGN_CENTER_VERTICAL
326 panel_sizer->Add( sizer, 1, wxEXPAND, 0 );
328 panel->SetSizerAndFit( panel_sizer );
333 wxPanel *SoutDialog::EncapsulationPanel( wxWindow* parent )
336 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
339 wxStaticBox *panel_box = new wxStaticBox( panel, -1,
340 _("Encapsulation Method") );
341 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
344 static const wxString encapsulation_array[] =
352 /* Stuff everything into the main panel */
355 encapsulation_radios[i] =
356 new wxRadioButton( panel, EncapsulationRadio1_Event + i,
357 encapsulation_array[i] );
358 panel_sizer->Add( encapsulation_radios[i], 0,
359 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5 );
362 panel->SetSizerAndFit( panel_sizer );
364 /* Update encapsulation panel */
365 encapsulation_radios[0]->Enable();
366 i_encapsulation_type = TS_ENCAPSULATION;
371 void SoutDialog::ParseMRL()
373 /* Initialise MRL value */
374 char *psz_sout = config_GetPsz( p_intf, "sout" );
382 wxString access = mrl.BeforeFirst( '/' );
383 wxString encapsulation = mrl.BeforeFirst( ':' ).AfterFirst('/');
385 if( !access.Cmp( "http" ) )
387 i_access_type = HTTP_ACCESS_OUT;
389 else if( !access.Cmp( "udp" ) )
391 i_access_type = UDP_ACCESS_OUT;
393 else if( !access.Cmp( "rtp" ) )
395 i_access_type = RTP_ACCESS_OUT;
399 i_access_type = FILE_ACCESS_OUT;
402 if( !encapsulation.Cmp( "ps" ) )
404 i_encapsulation_type = PS_ENCAPSULATION;
406 else if( !encapsulation.Cmp( "avi" ) )
408 i_encapsulation_type = AVI_ENCAPSULATION;
410 else if( !encapsulation.Cmp( "ogg" ) )
412 i_encapsulation_type = OGG_ENCAPSULATION;
416 i_encapsulation_type = TS_ENCAPSULATION;
419 wxString second_part = mrl.AfterFirst( ':' );
421 if( i_access_type == FILE_ACCESS_OUT )
423 /* The whole second part of the MRL is the filename */
424 file_combo->SetValue( second_part );
428 /* we've got address:port */
429 wxString address = second_part.BeforeLast( ':' );
430 net_addr->SetValue( address );
433 wxString port = second_part.AfterLast( ':' );
434 if( port.ToLong( &i_port ) )
436 net_port->SetValue( i_port );
440 net_port->SetValue( config_GetInt( p_intf, "server-port" ) );
444 /* Update access output panel */
445 wxCommandEvent dummy_event;
446 dummy_event.SetId( AccessRadio1_Event + i_access_type );
447 OnAccessTypeChange( dummy_event );
449 /* Update encapsulation output panel */
450 dummy_event.SetId( EncapsulationRadio1_Event + i_encapsulation_type );
451 OnEncapsulationChange( dummy_event );
454 /*****************************************************************************
456 *****************************************************************************/
457 void SoutDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
462 void SoutDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
464 EndModal( wxID_CANCEL );
467 void SoutDialog::OnMRLChange( wxCommandEvent& event )
469 mrl = event.GetString();
472 /*****************************************************************************
473 * Access output panel event methods.
474 *****************************************************************************/
475 void SoutDialog::OnAccessTypeChange( wxCommandEvent& event )
478 i_access_type = event.GetId() - AccessRadio1_Event;
480 switch( i_access_type )
482 case FILE_ACCESS_OUT:
483 access_subpanels[0]->Enable();
484 access_subpanels[2]->Disable();
485 access_subpanels[3]->Disable();
486 for( i = 1; i < 4; i++ )
488 encapsulation_radios[i]->Enable();
492 case HTTP_ACCESS_OUT:
493 access_subpanels[0]->Disable();
494 access_subpanels[2]->Enable();
495 access_subpanels[3]->Disable();
496 for( i = 1; i < 4; i++ )
498 encapsulation_radios[i]->Enable();
504 access_subpanels[0]->Disable();
505 access_subpanels[2]->Enable();
506 access_subpanels[3]->Enable();
507 for( i = 1; i < 4; i++ )
509 encapsulation_radios[i]->Disable();
511 encapsulation_radios[TS_ENCAPSULATION]->SetValue(true);
512 i_encapsulation_type = TS_ENCAPSULATION;
516 for( i = 0; i < 4; i++ )
518 access_radios[i]->SetValue( event.GetId() == (AccessRadio1_Event+i) );
524 /*****************************************************************************
525 * File access output event methods.
526 *****************************************************************************/
527 void SoutDialog::OnFileChange( wxCommandEvent& WXUNUSED(event) )
532 void SoutDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
534 wxFileDialog dialog( this, _("Save file"), "", "", "*.*", wxSAVE );
536 if( dialog.ShowModal() == wxID_OK )
538 file_combo->SetValue( dialog.GetPath() );
543 /*****************************************************************************
544 * Net access output event methods.
545 *****************************************************************************/
546 void SoutDialog::OnNetChange( wxCommandEvent& WXUNUSED(event) )
551 /*****************************************************************************
552 * Encapsulation panel event methods.
553 *****************************************************************************/
554 void SoutDialog::OnEncapsulationChange( wxCommandEvent& event )
556 i_encapsulation_type = event.GetId() - EncapsulationRadio1_Event;