* modules/misc/dummy/renderer.c:
[vlc.git] / modules / gui / wxwindows / v4l.cpp
1 /*****************************************************************************
2  * v4l.cpp : wxWindows plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2001 VideoLAN
5  * $Id: v4l.cpp,v 1.5 2003/12/04 16:49:43 sam Exp $
6  *
7  * Authors: Mohammed Adnène Trojette <adn@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31
32 #include <vlc/vlc.h>
33
34 #ifdef WIN32                                                 /* mingw32 hack */
35 #undef Yield
36 #undef CreateDialog
37 #endif
38
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
41
42 #include <wx/wxprec.h>
43 #include <wx/wx.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>
49
50 #include <vlc/intf.h>
51
52 #include "wxwindows.h"
53
54 #ifndef wxRB_SINGLE
55 #   define wxRB_SINGLE 0
56 #endif
57
58 /*****************************************************************************
59  * Event Table.
60  *****************************************************************************/
61
62 /* IDs for the controls and the menu commands */
63 enum
64 {
65     MRL_Event,
66
67     Size_Event,
68     Norm_Event,
69     FrequencyEnable_Event,Frequency_Event,
70
71     AudioDevice_Event, ADevLocation, AudioChannel_Event,
72
73     BitrateEnable_Event, MaxBitrateEnable_Event,
74     Bitrate_Event, MaxBitrate_Event
75 };
76
77 BEGIN_EVENT_TABLE(V4LDialog, wxDialog)
78     /* Button events */
79     EVT_BUTTON(wxID_OK, V4LDialog::OnOk)
80     EVT_BUTTON(wxID_CANCEL, V4LDialog::OnCancel)
81
82     /* Events generated by the common panel */
83     EVT_CHECKBOX(Size_Event, V4LDialog::OnSizeEnable)
84     EVT_COMBOBOX(Size_Event, V4LDialog::OnSize)
85     EVT_CHECKBOX(Norm_Event, V4LDialog::OnNormEnable)
86     EVT_COMBOBOX(Norm_Event, V4LDialog::OnNorm)
87     EVT_CHECKBOX(FrequencyEnable_Event, V4LDialog::OnFrequencyEnable)
88     EVT_SPINCTRL(Frequency_Event, V4LDialog::OnFrequency)
89
90    /* Events generated by the audio panel */
91     EVT_CHECKBOX(AudioDevice_Event, V4LDialog::OnAudioEnable)
92     EVT_TEXT(ADevLocation, V4LDialog::OnAudioChange)
93     EVT_SPINCTRL(AudioChannel_Event, V4LDialog::OnAudioChannel)
94
95     /* Events generated by the bitrate panel */
96     EVT_CHECKBOX(BitrateEnable_Event, V4LDialog::OnBitrateEnable)
97     EVT_SPINCTRL(Bitrate_Event, V4LDialog::OnBitrate)
98     EVT_CHECKBOX(MaxBitrateEnable_Event, V4LDialog::OnMaxBitrateEnable)
99     EVT_SPINCTRL(MaxBitrate_Event, V4LDialog::OnMaxBitrate)
100
101 END_EVENT_TABLE()
102
103 /*****************************************************************************
104  * Constructor.
105  *****************************************************************************/
106 V4LDialog::V4LDialog( intf_thread_t *_p_intf, wxWindow* _p_parent ):
107     wxDialog( _p_parent, -1, wxU(_("Video Device Advanced Options")),
108              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
109 {
110     /* Initializations */
111     p_intf = _p_intf;
112     p_parent = _p_parent;
113     SetIcon( *p_intf->p_sys->p_icon );
114
115     /* Create a panel to put everything in */
116     wxPanel *panel = new wxPanel( this, -1 );
117     panel->SetAutoLayout( TRUE );
118
119     /* Create MRL combobox */
120     wxBoxSizer *mrl_sizer_sizer = new wxBoxSizer( wxHORIZONTAL );
121     wxStaticBox *mrl_box = new wxStaticBox( panel, -1,
122                                wxU(_("Video Device MRL")) );
123     wxStaticBoxSizer *mrl_sizer = new wxStaticBoxSizer( mrl_box,
124                                                         wxHORIZONTAL );
125     wxStaticText *mrl_label = new wxStaticText( panel, -1,
126                                                 wxU(_("Destination Target:")));
127     mrl_combo = new wxComboBox( panel, MRL_Event, wxT(""),
128                                 wxPoint(20,25), wxSize(200, -1), 0, NULL );
129     mrl_combo->SetToolTip( wxU(_("You can use this field directly by typing "
130         "the full MRL you want to open.\n""Alternatively, the field will be "
131         "filled automatically when you use the controls below")) );
132
133     mrl_sizer->Add( mrl_label, 0, wxALL | wxALIGN_CENTER, 5 );
134     mrl_sizer->Add( mrl_combo, 1, wxALL | wxALIGN_CENTER, 5 );
135     mrl_sizer_sizer->Add( mrl_sizer, 1, wxEXPAND | wxALL, 5 );
136
137     /* Create the common panel */
138     wxPanel *common_panel = CommonPanel( panel );
139
140     /* Create the audio panel */
141     wxPanel *audio_panel = AudioPanel( panel );
142
143     /* Create the bitrate panel */
144     wxPanel *bitrate_panel = BitratePanel( panel );
145
146     /* Separation */
147     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
148
149     /* Create the buttons */
150     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
151     ok_button->SetDefault();
152     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
153                                             wxU(_("Cancel")) );
154
155     /* Place everything in sizers */
156     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
157     button_sizer->Add( ok_button, 0, wxALL, 5 );
158     button_sizer->Add( cancel_button, 0, wxALL, 5 );
159     button_sizer->Layout();
160     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
161     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
162     panel_sizer->Add( mrl_sizer_sizer, 0, wxEXPAND, 5 );
163     panel_sizer->Add( common_panel, 1, wxEXPAND | wxALL, 5 );
164     panel_sizer->Add( audio_panel, 1, wxEXPAND | wxALL, 5 );
165     panel_sizer->Add( bitrate_panel, 1, wxEXPAND | wxALL, 5 );
166     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
167     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
168                       wxALL, 5 );
169     panel_sizer->Layout();
170     panel->SetSizerAndFit( panel_sizer );
171     main_sizer->Add( panel, 1, wxGROW, 0 );
172     main_sizer->Layout();
173     SetSizerAndFit( main_sizer );
174 }
175
176 V4LDialog::~V4LDialog()
177 {
178 }
179
180 wxArrayString V4LDialog::GetOptions()
181 {
182    return SeparateEntries( mrl_combo->GetValue() );
183 }
184
185 /*****************************************************************************
186  * Private methods.
187  *****************************************************************************/
188 void V4LDialog::UpdateMRL()
189 {
190     wxString audio;
191     if( audio_checkbox->IsChecked() )
192         {
193             audio = wxT(":adev=")
194                     + audio_device->GetLineText(0)
195                     + wxString::Format( wxT(":audio=%d"),
196                         audio_channel->GetValue() );
197         }
198
199     wxString common;
200     {
201         if( size_checkbox->IsChecked() )
202         {
203             common += wxT(":size=")
204                 + size_combo->GetValue();
205         }
206
207         if( norm_checkbox->IsChecked() )
208         {
209             common += wxT(":norm=")
210                     + norm_combo->GetValue();
211         }
212
213         if( frequency_checkbox->IsChecked() )
214         {
215             common += wxString::Format( wxT(":frequency=%d"),
216                                         frequency->GetValue() );
217         }
218
219     }
220
221     wxString rate;
222     {
223         if( bitrate_checkbox->IsChecked() )
224         {
225             rate += wxString::Format( wxT(":bitrate=%d"),
226                                       bitrate->GetValue() );
227         }
228
229         if( maxbitrate_checkbox->IsChecked() )
230         {
231             rate += wxString::Format( wxT(":maxbitrate=%d"),
232                                       maxbitrate->GetValue() );
233         }
234     }
235
236     if( !audio.IsEmpty() || !common.IsEmpty() || !rate.IsEmpty() )
237         mrl_combo->SetValue( audio + common + rate);
238     else
239         mrl_combo->SetValue( wxT("") );
240 }
241
242 wxPanel *V4LDialog::CommonPanel( wxWindow* parent )
243 {
244     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
245                                   wxSize(200, 200) );
246
247     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
248                                    wxU(_("Common Options")) );
249     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
250                                                           wxVERTICAL );
251
252     wxFlexGridSizer *subpanel_sizer;
253
254     common_subpanel = new wxPanel( panel, -1 );
255
256     subpanel_sizer = new wxFlexGridSizer( 2, 3, 20 );
257
258     static const wxString size_array[] =
259     {
260         wxT("subqcif"),
261         wxT("qsif"),
262         wxT("qcif"),
263         wxT("sif"),
264         wxT("cif"),
265         wxT("vga"),
266     };
267
268     size_checkbox = new wxCheckBox( common_subpanel,
269                                     Size_Event,
270                                     wxU(_("Size")) );
271     size_combo = new wxComboBox( common_subpanel, Size_Event, wxT(""),
272                                  wxPoint(20,25), wxSize( 120, -1),
273                                  WXSIZEOF(size_array), size_array,
274                                  wxCB_READONLY );
275     size_combo->SetSelection(5);
276
277     subpanel_sizer->Add( size_checkbox, 0, wxALIGN_LEFT |
278                          wxALIGN_CENTER_VERTICAL );
279     subpanel_sizer->Add( size_combo, 0, wxALIGN_RIGHT |
280                          wxALIGN_CENTER_VERTICAL );
281
282     static const wxString norm_array[] =
283     {
284         wxT("pal"),
285         wxT("secam"),
286         wxT("ntsc")
287     };
288
289     norm_checkbox = new wxCheckBox( common_subpanel,
290                                      Norm_Event,
291                                      wxU(_("Norm")) );
292     norm_combo = new wxComboBox( common_subpanel, Norm_Event, wxT(""),
293                                  wxPoint(20,25), wxSize( 120, -1),
294                                  WXSIZEOF(norm_array), norm_array,
295                                  wxCB_READONLY );
296     norm_combo->SetSelection(1);
297     norm_combo->SetToolTip( wxU(_( "Standard of the analogic signal" )) );
298     subpanel_sizer->Add( norm_checkbox, 0, wxALIGN_LEFT |
299                          wxALIGN_CENTER_VERTICAL );
300     subpanel_sizer->Add( norm_combo, 0, wxALIGN_RIGHT |
301                          wxALIGN_CENTER_VERTICAL );
302
303     frequency_checkbox = new wxCheckBox( common_subpanel,
304                                          FrequencyEnable_Event,
305                                          wxU(_("Frequency")) );
306     frequency = new wxSpinCtrl( common_subpanel, Frequency_Event,
307                                 wxT("479250") );
308     frequency->SetToolTip( wxU(_("The frequency in kHz" )) );
309
310     subpanel_sizer->Add( frequency_checkbox, 0, wxALIGN_LEFT |
311                          wxALIGN_CENTER_VERTICAL );
312     subpanel_sizer->Add( frequency, 0, wxALIGN_RIGHT |
313                          wxALIGN_CENTER_VERTICAL );
314
315     common_subpanel->SetSizerAndFit( subpanel_sizer );
316
317     /* Stuff everything into the main panel */
318     panel_sizer->Add( common_subpanel, 1,
319                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
320
321     panel->SetSizerAndFit( panel_sizer );
322
323     /* Update panel */
324     size_combo->Disable();
325     norm_combo->Disable();
326     frequency->Disable();
327
328     return panel;
329 }
330
331 wxPanel *V4LDialog::AudioPanel( wxWindow* parent )
332 {
333     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
334                                   wxSize(200, 200) );
335
336     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
337                                    wxU(_("Audio Options")) );
338     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
339                                                           wxVERTICAL );
340
341     wxStaticText *label;
342     wxFlexGridSizer *subpanel_sizer;
343
344     audio_subpanel = new wxPanel( panel, -1 );
345
346     subpanel_sizer = new wxFlexGridSizer( 2, 2, 20 );
347
348     audio_checkbox = new wxCheckBox( audio_subpanel,
349                                      AudioDevice_Event,
350                                      wxU(_("Audio Device")) );
351     audio_device = new wxTextCtrl( audio_subpanel, ADevLocation,
352                                    wxT("/dev/dsp"),
353                                    wxDefaultPosition, wxSize( 120, -1 ),
354                                    wxTE_PROCESS_ENTER);
355     audio_device->SetToolTip( wxU(_("Audio device")) );
356     label = new wxStaticText( audio_subpanel, -1, wxU(_("Channel")) );
357     audio_channel = new wxSpinCtrl( audio_subpanel, AudioChannel_Event,
358                                     wxT("0") );
359     audio_channel->SetToolTip( wxU(_("Usually 0 is for mono "
360                                      "and 1 for stereo")) );
361     subpanel_sizer->Add( audio_checkbox, 0, wxALIGN_RIGHT |
362                                             wxALIGN_CENTER_VERTICAL );
363     subpanel_sizer->Add( audio_device, 1, wxALIGN_RIGHT );
364     subpanel_sizer->Add( label, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL );
365     subpanel_sizer->Add( audio_channel, 0, wxALIGN_RIGHT |
366                          wxALIGN_CENTER_VERTICAL );
367
368     audio_subpanel->SetSizerAndFit( subpanel_sizer );
369
370     /* Stuff everything into the main panel */
371     panel_sizer->Add( audio_subpanel, 1,
372                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
373
374     panel->SetSizerAndFit( panel_sizer );
375
376     /* Update panel */
377     audio_device->Disable();
378     audio_channel->Disable();
379
380     return panel;
381 }
382
383 wxPanel *V4LDialog::BitratePanel( wxWindow* parent )
384 {
385     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
386                                   wxSize(200, 200) );
387
388     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
389                                    wxU(_("Bitrate Options")) );
390     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
391                                                           wxVERTICAL );
392
393     wxFlexGridSizer *subpanel_sizer;
394
395     bitrate_subpanel = new wxPanel( panel, -1 );
396
397     subpanel_sizer = new wxFlexGridSizer( 2, 2, 20 );
398
399     bitrate_checkbox = new wxCheckBox( bitrate_subpanel,
400                                        BitrateEnable_Event,
401                                        wxU(_("Bitrate")) );
402     bitrate = new wxSpinCtrl( bitrate_subpanel, Bitrate_Event, wxT("3000") );
403     bitrate->SetToolTip( wxU(_("The average bitrate of the stream")) );
404     subpanel_sizer->Add( bitrate_checkbox, 0, wxALIGN_LEFT |
405                          wxALIGN_CENTER_VERTICAL );
406     subpanel_sizer->Add( bitrate, 0, wxALIGN_RIGHT |
407                          wxALIGN_CENTER_VERTICAL );
408
409     maxbitrate_checkbox = new wxCheckBox( bitrate_subpanel,
410                                           MaxBitrateEnable_Event,
411                                           wxU(_("Maximum Bitrate")) );
412     maxbitrate = new wxSpinCtrl( bitrate_subpanel, MaxBitrate_Event, wxT("3000") );
413
414     subpanel_sizer->Add( maxbitrate_checkbox, 0, wxALIGN_LEFT |
415                          wxALIGN_CENTER_VERTICAL );
416     subpanel_sizer->Add( maxbitrate, 0, wxALIGN_RIGHT |
417                          wxALIGN_CENTER_VERTICAL );
418
419     bitrate_subpanel->SetSizerAndFit( subpanel_sizer );
420
421     /* Stuff everything into the main panel */
422     panel_sizer->Add( bitrate_subpanel, 1,
423                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
424
425     panel->SetSizerAndFit( panel_sizer );
426
427     /* Update panel */
428     bitrate->Disable();
429     maxbitrate->Disable();
430
431     return panel;
432 }
433
434
435 /*****************************************************************************
436  * Events methods.
437  *****************************************************************************/
438 void V4LDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
439 {
440     mrl_combo->Append( mrl_combo->GetValue() );
441     EndModal( wxID_OK );
442 }
443
444 void V4LDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
445 {
446     EndModal( wxID_CANCEL );
447 }
448
449 void V4LDialog::OnMRLChange( wxCommandEvent& event )
450 {
451     //mrl = event.GetString();
452 }
453
454 /******************************************************************************
455  * Common panel event methods.
456  ******************************************************************************/
457 void V4LDialog::OnSizeEnable( wxCommandEvent& event )
458 {
459     UpdateMRL();
460     size_combo->Enable( event.GetInt() );
461 }
462
463 void V4LDialog::OnSize( wxCommandEvent& event )
464 {
465     UpdateMRL();
466 }
467
468 void V4LDialog::OnNormEnable( wxCommandEvent& event )
469 {
470     norm_combo->Enable( event.GetInt() );
471     UpdateMRL();
472 }
473
474 void V4LDialog::OnNorm( wxCommandEvent& event )
475 {
476     UpdateMRL();
477 }
478
479 void V4LDialog::OnFrequencyEnable( wxCommandEvent& event )
480 {
481     frequency->SetRange( 0, 1200000 );
482     frequency->Enable( event.GetInt() );
483     UpdateMRL();
484 }
485
486 void V4LDialog::OnFrequency( wxCommandEvent& event )
487 {
488     UpdateMRL();
489 }
490
491 /*****************************************************************************
492  * Audio panel event methods.
493  *****************************************************************************/
494 void V4LDialog::OnAudioEnable( wxCommandEvent& event )
495 {
496     audio_channel->SetRange( 0, 255 );
497
498     audio_device->Enable( event.GetInt() );
499     audio_channel->Enable( event.GetInt() );
500     UpdateMRL();
501 }
502
503 void V4LDialog::OnAudioChange( wxCommandEvent& event )
504 {
505     UpdateMRL();
506 }
507
508 void V4LDialog::OnAudioChannel( wxCommandEvent& event )
509 {
510     UpdateMRL();
511 }
512
513 /******************************************************************************
514  * Bitrate panel event methods.
515  ******************************************************************************/
516 void V4LDialog::OnBitrateEnable( wxCommandEvent& event )
517 {
518     bitrate->SetRange( 0, 10000 );
519     bitrate->Enable( event.GetInt() );
520     UpdateMRL();
521 }
522
523 void V4LDialog::OnBitrate( wxCommandEvent& event )
524 {
525     UpdateMRL();
526 }
527
528 void V4LDialog::OnMaxBitrateEnable( wxCommandEvent& event )
529 {
530     maxbitrate->SetRange( 0, 10000 );
531     maxbitrate->Enable( event.GetInt() );
532     UpdateMRL();
533 }
534
535 void V4LDialog::OnMaxBitrate( wxCommandEvent& event )
536 {
537     UpdateMRL();
538 }