1 /*****************************************************************************
2 * streamout.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: streamout.cpp,v 1.2 2003/03/22 11:21:58 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() );
232 mrl = "udp" + encapsulation + ":"
233 + net_addr->GetLineText(0)
234 + wxString::Format( ":%d", net_port->GetValue() );
238 mrl = "rtp" + encapsulation + ":"
239 + net_addr->GetLineText(0)
240 + wxString::Format( ":%d", net_port->GetValue() );
244 mrl_combo->SetValue( mrl );
247 wxPanel *SoutDialog::AccessPanel( wxWindow* parent )
250 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
253 wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 4, 20 );
254 wxStaticBox *panel_box = new wxStaticBox( panel, -1, _("Output Method") );
255 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
258 static const wxString access_output_array[] =
268 access_radios[i] = new wxRadioButton( panel, AccessRadio1_Event + i,
269 access_output_array[i],
270 wxDefaultPosition, wxDefaultSize,
273 access_subpanels[i] = new wxPanel( panel, -1,
274 wxDefaultPosition, wxDefaultSize );
278 wxFlexGridSizer *subpanel_sizer;
280 subpanel_sizer = new wxFlexGridSizer( 3, 1, 20 );
281 label = new wxStaticText( access_subpanels[0], -1, _("Filename") );
282 file_combo = new wxComboBox( access_subpanels[0], FileName_Event, "",
283 wxPoint(20,25), wxSize(200, -1), 0, NULL );
284 wxButton *browse_button = new wxButton( access_subpanels[0],
285 FileBrowse_Event, _("Browse...") );
286 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
287 subpanel_sizer->Add( file_combo, 1,
288 wxEXPAND | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
289 subpanel_sizer->Add( browse_button, 0,
290 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
292 access_subpanels[0]->SetSizerAndFit( subpanel_sizer );
295 subpanel_sizer = new wxFlexGridSizer( 4, 1, 20 );
296 label = new wxStaticText( access_subpanels[2], -1, _("Address") );
297 net_addr = new wxTextCtrl( access_subpanels[2], NetAddr_Event, "",
298 wxDefaultPosition, wxSize( 200, -1 ),
300 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
301 subpanel_sizer->Add( net_addr, 1,
302 wxEXPAND | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
304 label = new wxStaticText( access_subpanels[2], -1, _("Port") );
305 net_port = new wxSpinCtrl( access_subpanels[2], NetPort_Event,
306 wxString::Format(_("%d"), 0/*val*/),
307 wxDefaultPosition, wxDefaultSize,
311 subpanel_sizer->Add( label, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL );
312 subpanel_sizer->Add( net_port, 0,
313 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
315 access_subpanels[2]->SetSizerAndFit( subpanel_sizer );
318 /* Stuff everything into the main panel */
321 sizer->Add( access_radios[i], 0,
322 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
323 sizer->Add( access_subpanels[i], 1, wxEXPAND | wxALIGN_CENTER_VERTICAL
327 panel_sizer->Add( sizer, 1, wxEXPAND, 0 );
329 panel->SetSizerAndFit( panel_sizer );
334 wxPanel *SoutDialog::EncapsulationPanel( wxWindow* parent )
337 wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
340 wxStaticBox *panel_box = new wxStaticBox( panel, -1,
341 _("Encapsulation Method") );
342 wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
345 static const wxString encapsulation_array[] =
353 /* Stuff everything into the main panel */
356 encapsulation_radios[i] =
357 new wxRadioButton( panel, EncapsulationRadio1_Event + i,
358 encapsulation_array[i] );
359 panel_sizer->Add( encapsulation_radios[i], 0,
360 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
363 panel->SetSizerAndFit( panel_sizer );
365 /* Update encapsulation panel */
366 encapsulation_radios[0]->Enable();
367 i_encapsulation_type = TS_ENCAPSULATION;
372 void SoutDialog::ParseMRL()
374 /* Initialise MRL value */
375 char *psz_sout = config_GetPsz( p_intf, "sout" );
383 wxString access = mrl.BeforeFirst( '/' );
384 wxString encapsulation = mrl.BeforeFirst( ':' ).AfterFirst('/');
386 if( !access.Cmp( "http" ) )
388 i_access_type = HTTP_ACCESS_OUT;
390 else if( !access.Cmp( "udp" ) )
392 i_access_type = UDP_ACCESS_OUT;
394 else if( !access.Cmp( "rtp" ) )
396 i_access_type = RTP_ACCESS_OUT;
400 i_access_type = FILE_ACCESS_OUT;
403 if( !encapsulation.Cmp( "ps" ) )
405 i_encapsulation_type = PS_ENCAPSULATION;
407 else if( !encapsulation.Cmp( "avi" ) )
409 i_encapsulation_type = AVI_ENCAPSULATION;
411 else if( !encapsulation.Cmp( "ogg" ) )
413 i_encapsulation_type = OGG_ENCAPSULATION;
417 i_encapsulation_type = TS_ENCAPSULATION;
420 wxString second_part = mrl.AfterFirst( ':' );
422 if( i_access_type == FILE_ACCESS_OUT )
424 /* The whole second part of the MRL is the filename */
425 file_combo->SetValue( second_part );
429 /* we've got address:port */
430 wxString address = second_part.BeforeLast( ':' );
431 net_addr->SetValue( address );
434 wxString port = second_part.AfterLast( ':' );
435 if( port.ToLong( &i_port ) )
437 net_port->SetValue( i_port );
441 net_port->SetValue( config_GetInt( p_intf, "server-port" ) );
445 /* Update access output panel */
446 wxCommandEvent dummy_event;
447 dummy_event.SetId( AccessRadio1_Event + i_access_type );
448 OnAccessTypeChange( dummy_event );
450 /* Update encapsulation output panel */
451 dummy_event.SetId( EncapsulationRadio1_Event + i_encapsulation_type );
452 OnEncapsulationChange( dummy_event );
455 /*****************************************************************************
457 *****************************************************************************/
458 void SoutDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
463 void SoutDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
465 EndModal( wxID_CANCEL );
468 void SoutDialog::OnMRLChange( wxCommandEvent& event )
470 mrl = event.GetString();
473 /*****************************************************************************
474 * Access output panel event methods.
475 *****************************************************************************/
476 void SoutDialog::OnAccessTypeChange( wxCommandEvent& event )
479 i_access_type = event.GetId() - AccessRadio1_Event;
481 switch( i_access_type )
483 case FILE_ACCESS_OUT:
484 access_subpanels[0]->Enable();
485 access_subpanels[2]->Disable();
486 access_subpanels[3]->Disable();
487 for( i = 1; i < 4; i++ )
489 encapsulation_radios[i]->Enable();
493 case HTTP_ACCESS_OUT:
494 access_subpanels[0]->Disable();
495 access_subpanels[2]->Enable();
496 access_subpanels[3]->Disable();
497 for( i = 1; i < 4; i++ )
499 encapsulation_radios[i]->Enable();
505 access_subpanels[0]->Disable();
506 access_subpanels[2]->Enable();
507 access_subpanels[3]->Enable();
508 for( i = 1; i < 4; i++ )
510 encapsulation_radios[i]->Disable();
512 encapsulation_radios[TS_ENCAPSULATION]->SetValue(true);
513 i_encapsulation_type = TS_ENCAPSULATION;
517 for( i = 0; i < 4; i++ )
519 access_radios[i]->SetValue( event.GetId() == (AccessRadio1_Event+i) );
525 /*****************************************************************************
526 * File access output event methods.
527 *****************************************************************************/
528 void SoutDialog::OnFileChange( wxCommandEvent& WXUNUSED(event) )
533 void SoutDialog::OnFileBrowse( wxCommandEvent& WXUNUSED(event) )
535 wxFileDialog dialog( this, _("Save file"), "", "", "*.*", wxSAVE );
537 if( dialog.ShowModal() == wxID_OK )
539 file_combo->SetValue( dialog.GetPath() );
544 /*****************************************************************************
545 * Net access output event methods.
546 *****************************************************************************/
547 void SoutDialog::OnNetChange( wxCommandEvent& WXUNUSED(event) )
552 /*****************************************************************************
553 * Encapsulation panel event methods.
554 *****************************************************************************/
555 void SoutDialog::OnEncapsulationChange( wxCommandEvent& event )
557 i_encapsulation_type = event.GetId() - EncapsulationRadio1_Event;