Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

wizard.cpp

00001 /*****************************************************************************
00002  * wizard.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: wizard.cpp 13306 2005-11-21 10:23:12Z zorglub $
00006  *
00007  * Authors: Clément Stenac <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <errno.h>                                                 /* ENOMEM */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 
00032 #include <vlc/vlc.h>
00033 #include <vlc/intf.h>
00034 #include "network.h"
00035 
00036 #include "wxwidgets.h"
00037 
00038 #include "streamdata.h"
00039 
00040 #include <wx/statline.h>
00041 
00042 class wizHelloPage;
00043 class wizInputPage;
00044 
00045 /*****************************************************************************
00046  * Define events
00047  *****************************************************************************/
00048 enum
00049 {
00050     ActionRadio0_Event, ActionRadio1_Event,
00051     MoreInfoStreaming_Event,
00052     MoreInfoTranscode_Event,
00053 
00054     Open_Event , Choose_Event ,
00055     ListView_Event,
00056     InputRadio0_Event, InputRadio1_Event,
00057     PartialEnable_Event,
00058 
00059     MethodRadio0_Event, MethodRadio1_Event,
00060     MethodRadio2_Event, MethodRadio3_Event,
00061 
00062     EncapRadio0_Event, EncapRadio1_Event,
00063     EncapRadio2_Event, EncapRadio3_Event,
00064     EncapRadio4_Event, EncapRadio5_Event,
00065     EncapRadio6_Event, EncapRadio7_Event,
00066     EncapRadio8_Event, EncapRadio9_Event,
00067     EncapRadio10_Event, EncapRadio11_Event,
00068 
00069     VideoEnable_Event, VideoCodec_Event,VideoBitrate_Event,
00070     AudioEnable_Event, AudioCodec_Event,AudioBitrate_Event,
00071 
00072     SAP_Event,
00073 
00074 };
00075 
00076 #define TEXTWIDTH 55
00077 #define ACTION_STREAM 0
00078 #define ACTION_TRANSCODE 1
00079 
00080 BEGIN_EVENT_TABLE(WizardDialog, wxWizard)
00081 END_EVENT_TABLE()
00082 
00083 /*****************************************************************************
00084  * Wizard strings
00085  *****************************************************************************/
00086 
00087 #define ERROR_MSG _("Error")
00088 #define ITEM_NAME _("Streaming/Transcoding Wizard")
00089 
00090 /* Hello page */
00091 #define HELLO_TITLE _("Streaming/Transcoding Wizard")
00092 #define HELLO_TEXT _("This wizard helps you to stream, transcode or" \
00093                      " save a stream.")
00094 #define HELLO_STREAMING _("Stream to network")
00095 #define HELLO_STREAMING_DESC _("Use this to stream on a network.")
00096 #define HELLO_TRANSCODE _("Transcode/Save to file")
00097 #define HELLO_TRANSCODE_DESC _("Use this to re-encode a stream and save it to a file.")
00098 #define HELLO_NOTICE _("This wizard only gives access to a small subset of VLC's streaming and transcoding capabilities. Use the Open and Stream Output dialogs to get all of them.")
00099 
00100 #define MOREINFO_STREAM _("Use this to stream on a network")
00101 
00102 #define MOREINFO_TRANSCODE _("Use this to save a stream to a file. You have the possibility to reencode the stream. You can save whatever VLC can read.\nPlease notice that VLC is not very suited " \
00103              "for file to file transcoding. You should use its transcoding " \
00104              "features to save network streams, for example." )
00105 
00106 /* Input page */
00107 #define INPUT_TITLE _("Choose input")
00108 #define INPUT_TEXT _("Choose here your input stream.")
00109 
00110 #define INPUT_OPEN _("Select a stream" )
00111 #define INPUT_PL _( "Existing playlist item" )
00112 
00113 #define CHOOSE_STREAM _("You must choose a stream")
00114 #define NO_PLAYLIST _("Uh Oh! Unable to find playlist !")
00115 
00116 #define PARTIAL _("Use this to read only a part of the stream. " \
00117                   "You must be able to control the incoming stream " \
00118                   "(for example, a file or a disc, but not a RTP/UDP " \
00119                   "network stream.)\n" \
00120                   "Enter the starting and ending times (in seconds).")
00121 
00122 #define INPUT_BUTTON _("Choose")
00123 
00124 /* Transcode 1 */
00125 #define TRANSCODE1_TITLE _("Transcode")
00126 #define TRANSCODE1_TEXT _("If you want to change the compression format of the audio or video tracks, fill in this page. (If you only want to change the container format, proceed to next page.)")
00127 
00128 #define TR_VIDEO_TEXT0 _("If your stream has video and you want to " \
00129                          "transcode it, enable this.")
00130 #define TR_VIDEO_TEXT _("Select your video codec. Click one to get more " \
00131                         "information.")
00132 
00133 #define TR_AUDIO_TEXT0 _("If your stream has audio and you want to "\
00134                          "transcode it, enable this.")
00135 #define TR_AUDIO_TEXT _("Select your audio codec. Click one to get more " \
00136                         "information.")
00137 
00138 /* Streaming 1 */
00139 #define STREAMING1_TITLE _("Streaming")
00140 #define STREAMING1_TEXT _("In this page, you will select how your input stream will be sent.")
00141 
00142 
00143 #define INVALID_MCAST_ADDRESS _("This does not appear to be a valid " \
00144                                 "multicast address" )
00145 #define NO_ADDRESS_TEXT _("You need to enter an address" )
00146 
00147 /* Encap  */
00148 #define ENCAP_TITLE _("Encapsulation format")
00149 #define ENCAP_TEXT _("In this page, you will select how the stream will be "\
00150                      "encapsulated. Depending on the choices you made, all "\
00151                      "formats won't be available." )
00152 
00153 
00154 /* Transcode 2 */
00155 #define EXTRATRANSCODE_TITLE _("Additional transcode options")
00156 #define EXTRATRANSCODE_TEXT _("In this page, you will define a few " \
00157                               "additionnal parameters for your transcoding" )
00158 
00159 #define CHOOSE_OUTFILE _("You must choose a file to save to")
00160 
00161 /* Streaming 2 */
00162 #define EXTRASTREAMING_TITLE _("Additional streaming options")
00163 #define EXTRASTREAMING_TEXT _("In this page, you will define a few " \
00164                               "additionnal parameters for your stream" )
00165 
00166 #define TTL _("Define the TTL (Time-To-Live) of the stream. This parameter " \
00167               "is the maximum number of routers your stream can go through. " \
00168               "If you don't know what it means, or if you want to stream on " \
00169               "your local network only, leave this setting to 1." )
00170 
00171 #define SAP _("When streaming using UDP, you can announce your streams " \
00172               "using the SAP/SDP announcing protocol. This way, the clients " \
00173               "won't have to type in the multicast address, it will appear " \
00174               "in their playlist if they enable the SAP extra interface.\n" \
00175               "If you want to give a name to your stream, enter it here, " \
00176               "else, a default name will be used" )
00177 
00178 /*****************************************************************************
00179  * All the pages of the wizard, declaration
00180  *****************************************************************************/
00181 
00182 /* Declare classes */
00183 class wizHelloPage : public wxWizardPageSimple
00184 {
00185     public:
00186         wizHelloPage( wxWizard *parent);
00187         void OnActionChange( wxCommandEvent& event );
00188         void OnWizardPageChanging(wxWizardEvent& event);
00189         void OnMoreInfo( wxCommandEvent& event );
00190     protected:
00191         int i_action;
00192         WizardDialog *p_parent;
00193         wxRadioButton *action_radios[2];
00194         DECLARE_EVENT_TABLE()
00195 };
00196 
00197 BEGIN_EVENT_TABLE(wizHelloPage, wxWizardPageSimple)
00198     EVT_RADIOBUTTON( ActionRadio0_Event, wizHelloPage::OnActionChange)
00199     EVT_RADIOBUTTON( ActionRadio1_Event, wizHelloPage::OnActionChange)
00200     EVT_BUTTON( MoreInfoStreaming_Event, wizHelloPage::OnMoreInfo )
00201     EVT_BUTTON( MoreInfoTranscode_Event, wizHelloPage::OnMoreInfo )
00202 
00203     EVT_WIZARD_PAGE_CHANGING(-1, wizHelloPage::OnWizardPageChanging)
00204 END_EVENT_TABLE()
00205 
00206 
00207 class wizInputPage : public wxWizardPage
00208 {
00209     public:
00210         wizInputPage( wxWizard *, wxWizardPage *, intf_thread_t *);
00211         wizInputPage::~wizInputPage();
00212         void OnWizardPageChanging(wxWizardEvent& event);
00213         void OnInputChange( wxCommandEvent& event );
00214         void OnEnablePartial(wxCommandEvent& event);
00215         virtual wxWizardPage *GetPrev() const;
00216         virtual wxWizardPage *GetNext() const;
00217         void SetStreamingPage( wxWizardPage *page);
00218         void SetTranscodePage( wxWizardPage *page);
00219         void SetAction( int i_action );
00220         void SetPintf( intf_thread_t *p_intf );
00221         void SetUri( char *psz_uri );
00222         void SetPartial( int i_from, int i_to );
00223 
00224     protected:
00225         bool b_chosen;
00226         intf_thread_t *p_intf;
00227         int i_action;
00228         int i_input;
00229 
00230         void OnChoose( wxCommandEvent& event );
00231 
00232         WizardDialog *p_parent;
00233         wxRadioButton *input_radios[2];
00234         wxCheckBox *enable_checkbox;
00235         wxBoxSizer *mainSizer;
00236         wxArrayString mrl;
00237         wxTextCtrl *mrl_text;
00238         wxTextCtrl *from_text;
00239         wxTextCtrl *to_text;
00240         OpenDialog *p_open_dialog;
00241         wxListView *listview;
00242         wxPanel *open_panel;
00243         wxPanel *radio_panel; /* radio buttons should be in their own panel... */
00244         wxWizardPage *p_prev;
00245         wxWizardPage *p_streaming_page;
00246         wxWizardPage *p_transcode_page;
00247 
00248         DECLARE_EVENT_TABLE()
00249 };
00250 
00251 BEGIN_EVENT_TABLE(wizInputPage, wxWizardPage)
00252     EVT_RADIOBUTTON( InputRadio0_Event, wizInputPage::OnInputChange)
00253     EVT_RADIOBUTTON( InputRadio1_Event, wizInputPage::OnInputChange)
00254     EVT_BUTTON( Choose_Event, wizInputPage::OnChoose)
00255     EVT_CHECKBOX( PartialEnable_Event, wizInputPage::OnEnablePartial)
00256     EVT_WIZARD_PAGE_CHANGING(-1, wizInputPage::OnWizardPageChanging)
00257 END_EVENT_TABLE()
00258 
00259 
00260 class wizTranscodeCodecPage : public wxWizardPage
00261 {
00262 public:
00263     wizTranscodeCodecPage( wxWizard *parent, wxWizardPage *next);
00264     ~wizTranscodeCodecPage();
00265     void wizTranscodeCodecPage::OnWizardPageChanging(wxWizardEvent& event);
00266     virtual wxWizardPage *GetPrev() const;
00267     virtual wxWizardPage *GetNext() const;
00268     void SetPrev( wxWizardPage *page);
00269 protected:
00270     wxCheckBox *video_checkbox;
00271     wxComboBox *video_combo;
00272     wxComboBox *vb_combo;
00273     wxStaticText * video_text;
00274     wxCheckBox *audio_checkbox;
00275     wxComboBox *audio_combo;
00276     wxComboBox *ab_combo;
00277     wxStaticText * audio_text;
00278 
00279     WizardDialog *p_parent;
00280     int i_audio_codec;
00281     int i_video_codec;
00282 
00283     char *vcodec;
00284     char *acodec;
00285 
00286     wxWizardPage *p_prev;
00287     wxWizardPage *p_next;
00288 
00289     void OnVideoCodecChange(wxCommandEvent& event);
00290     void OnAudioCodecChange(wxCommandEvent& event);
00291     void OnEnableVideo(wxCommandEvent& event);
00292     void OnEnableAudio(wxCommandEvent& event);
00293 
00294     DECLARE_EVENT_TABLE()
00295 };
00296 
00297 BEGIN_EVENT_TABLE(wizTranscodeCodecPage, wxWizardPage)
00298    EVT_CHECKBOX( VideoEnable_Event, wizTranscodeCodecPage::OnEnableVideo)
00299    EVT_CHECKBOX( AudioEnable_Event, wizTranscodeCodecPage::OnEnableAudio)
00300    EVT_COMBOBOX( VideoCodec_Event, wizTranscodeCodecPage::OnVideoCodecChange)
00301    EVT_COMBOBOX( AudioCodec_Event, wizTranscodeCodecPage::OnAudioCodecChange)
00302    EVT_WIZARD_PAGE_CHANGING(-1, wizTranscodeCodecPage::OnWizardPageChanging)
00303 END_EVENT_TABLE()
00304 
00305 class wizStreamingMethodPage : public wxWizardPage
00306 {
00307 public:
00308     wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
00309                             wxWizardPage *next) ;
00310     void OnWizardPageChanging(wxWizardEvent& event);
00311     virtual wxWizardPage *GetPrev() const;
00312     virtual wxWizardPage *GetNext() const;
00313     void SetPrev( wxWizardPage *page);
00314 protected:
00315     DECLARE_EVENT_TABLE()
00316     int i_method;
00317     wxBoxSizer *mainSizer;
00318     wxStaticBoxSizer *address_sizer;
00319     wxStaticText *address_text;
00320     wxTextCtrl *address_txtctrl;
00321     WizardDialog * p_parent;
00322     void OnMethodChange( wxCommandEvent& event );
00323     wxRadioButton *method_radios[4];
00324     wxWizardPage *p_prev;
00325     wxWizardPage *p_next;
00326     intf_thread_t *p_intf;
00327 };
00328 
00329 BEGIN_EVENT_TABLE(wizStreamingMethodPage, wxWizardPage)
00330     EVT_RADIOBUTTON( MethodRadio0_Event, wizStreamingMethodPage::OnMethodChange)
00331     EVT_RADIOBUTTON( MethodRadio1_Event, wizStreamingMethodPage::OnMethodChange)
00332     EVT_RADIOBUTTON( MethodRadio2_Event, wizStreamingMethodPage::OnMethodChange)
00333     EVT_RADIOBUTTON( MethodRadio3_Event, wizStreamingMethodPage::OnMethodChange)
00334     EVT_WIZARD_PAGE_CHANGING(-1, wizStreamingMethodPage::OnWizardPageChanging)
00335 END_EVENT_TABLE()
00336 
00337 
00338 class wizEncapPage : public wxWizardPage
00339 {
00340 public:
00341     wizEncapPage( wxWizard *parent);
00342     wizEncapPage::~wizEncapPage();
00343     void OnWizardPageChanging(wxWizardEvent& event);
00344     virtual wxWizardPage *GetPrev() const;
00345     virtual wxWizardPage *GetNext() const;
00346     void SetStreamingPage( wxWizardPage *page);
00347     void SetTranscodePage( wxWizardPage *page);
00348     void SetPrev( wxWizardPage *page);
00349     void SetAction( int );
00350     void EnableEncap( int encap );
00351 protected:
00352     DECLARE_EVENT_TABLE()
00353     int i_encap;
00354     int i_mux;
00355     int i_action;
00356     void OnEncapChange( wxCommandEvent& event );
00357     wxRadioButton *encap_radios[MUXERS_NUMBER];
00358     WizardDialog *p_parent;
00359     wxWizardPage *p_prev;
00360     wxWizardPage *p_streaming_page;
00361     wxWizardPage *p_transcode_page;
00362 };
00363 
00364 BEGIN_EVENT_TABLE(wizEncapPage, wxWizardPage)
00365     EVT_WIZARD_PAGE_CHANGING(-1, wizEncapPage::OnWizardPageChanging)
00366     EVT_RADIOBUTTON( EncapRadio0_Event, wizEncapPage::OnEncapChange)
00367     EVT_RADIOBUTTON( EncapRadio1_Event, wizEncapPage::OnEncapChange)
00368     EVT_RADIOBUTTON( EncapRadio2_Event, wizEncapPage::OnEncapChange)
00369     EVT_RADIOBUTTON( EncapRadio3_Event, wizEncapPage::OnEncapChange)
00370     EVT_RADIOBUTTON( EncapRadio4_Event, wizEncapPage::OnEncapChange)
00371     EVT_RADIOBUTTON( EncapRadio5_Event, wizEncapPage::OnEncapChange)
00372     EVT_RADIOBUTTON( EncapRadio6_Event, wizEncapPage::OnEncapChange)
00373     EVT_RADIOBUTTON( EncapRadio7_Event, wizEncapPage::OnEncapChange)
00374     EVT_RADIOBUTTON( EncapRadio8_Event, wizEncapPage::OnEncapChange)
00375     EVT_RADIOBUTTON( EncapRadio9_Event, wizEncapPage::OnEncapChange)
00376     EVT_RADIOBUTTON( EncapRadio10_Event, wizEncapPage::OnEncapChange)
00377 END_EVENT_TABLE()
00378 
00379 /* Additional settings for transcode */
00380 class wizTranscodeExtraPage : public wxWizardPage
00381 {
00382 public:
00383     wizTranscodeExtraPage( wxWizard *parent, wxWizardPage *prev,
00384                             wxWizardPage *next);
00385     virtual wxWizardPage *GetPrev() const;
00386     virtual wxWizardPage *GetNext() const;
00387     void OnWizardPageChanging( wxWizardEvent& event );
00388 protected:
00389     DECLARE_EVENT_TABLE()
00390     void wizTranscodeExtraPage::OnSelectFile(wxCommandEvent&);
00391     wxTextCtrl *file_text;
00392     WizardDialog *p_parent;
00393     wxWizardPage *p_prev;
00394     wxWizardPage *p_next;
00395 };
00396 
00397 BEGIN_EVENT_TABLE(wizTranscodeExtraPage, wxWizardPage)
00398     EVT_BUTTON( Open_Event, wizTranscodeExtraPage::OnSelectFile)
00399     EVT_WIZARD_PAGE_CHANGING(-1, wizTranscodeExtraPage::OnWizardPageChanging)
00400 END_EVENT_TABLE()
00401 
00402 /* Additional settings for streaming */
00403 class wizStreamingExtraPage : public wxWizardPage
00404 {
00405 public:
00406     wizStreamingExtraPage( wxWizard *parent, wxWizardPage *prev,
00407                             wxWizardPage *next);
00408     virtual wxWizardPage *GetPrev() const;
00409     virtual wxWizardPage *GetNext() const;
00410     void OnWizardPageChanging(wxWizardEvent&);
00411     void OnSAP( wxCommandEvent&);
00412     wxCheckBox *sap_checkbox;
00413     wxTextCtrl *sap_text;
00414 protected:
00415     friend class wizEncapPage;
00416     DECLARE_EVENT_TABLE()
00417     WizardDialog *p_parent;
00418     wxWizardPage *p_prev;
00419     wxWizardPage *p_next;
00420 
00421     wxSpinCtrl *ttl_spin;
00422 };
00423 
00424 BEGIN_EVENT_TABLE(wizStreamingExtraPage, wxWizardPage)
00425     EVT_CHECKBOX( SAP_Event, wizStreamingExtraPage::OnSAP )
00426     EVT_WIZARD_PAGE_CHANGING(-1, wizStreamingExtraPage::OnWizardPageChanging)
00427 END_EVENT_TABLE()
00428 
00429 
00430 /* Local functions */
00431 static void pageHeader( wxWindow *window, wxBoxSizer *sizer,
00432                        char *psz_title, char *psz_text);
00433 
00434 static void pageHeader( wxWindow *window, wxBoxSizer *sizer,
00435                         char *psz_title, char *psz_text)
00436 {
00437     wxStaticText *wtitle = new wxStaticText( window, -1, wxU( psz_title ) );
00438     wxFont font = wtitle->GetFont();
00439     font.SetPointSize(14);
00440     wtitle->SetFont(font);
00441     sizer->Add( wtitle, 0, wxALL, 5 );
00442     sizer->Add( new wxStaticText( window, -1,
00443                 wxU( vlc_wraptext( psz_text , TEXTWIDTH, false ) ) ),
00444                         0, wxALL, 5 );
00445 }
00446 
00447 /***************************************************************************
00448  * Implementation of the pages
00449  ***************************************************************************/
00450 
00451 
00452 /***************************************************
00453  * First page: choose between stream and transcode *
00454  ***************************************************/
00455 wizHelloPage::wizHelloPage( wxWizard *parent) : wxWizardPageSimple(parent)
00456 {
00457         i_action = 0;
00458         p_parent = (WizardDialog *)parent;
00459         wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
00460 
00461         /* Create the texts */
00462         pageHeader( this, mainSizer, HELLO_TITLE, HELLO_TEXT );
00463 
00464         /* Create the radio buttons with their helps */
00465         action_radios[0] = new wxRadioButton( this, ActionRadio0_Event,
00466                                               wxU( HELLO_STREAMING ) );
00467         action_radios[1] = new wxRadioButton( this, ActionRadio1_Event,
00468                                               wxU( HELLO_TRANSCODE ) );
00469         i_action = 0;
00470 
00471         mainSizer->Add( 0, 0, 1 );
00472 
00473         wxBoxSizer *stream_sizer = new wxBoxSizer( wxHORIZONTAL );
00474         stream_sizer->Add( action_radios[0], 0, wxALL, 5 );
00475         stream_sizer->Add( 0,0,1 );
00476         stream_sizer->Add( new wxButton( this, MoreInfoStreaming_Event,
00477                                 wxU( _("More Info")) ), 0, 0, 0 );
00478         mainSizer->Add( stream_sizer, 0, wxALL | wxEXPAND , 5 );
00479 
00480         wxBoxSizer *transcode_sizer = new wxBoxSizer( wxHORIZONTAL );
00481         transcode_sizer->Add( action_radios[1], 0, wxALL, 5 );
00482         transcode_sizer->Add( 0,0,1);
00483         transcode_sizer->Add( new wxButton( this, MoreInfoTranscode_Event,
00484                                 wxU( _("More Info")) ), 0 ,  0 , 0 );
00485         mainSizer->Add( transcode_sizer, 0, wxALL | wxEXPAND, 5 );
00486 
00487         mainSizer->Add( 0, 0, 1 );
00488 
00489         mainSizer->Add( new wxStaticLine(this, -1 ), 0, wxEXPAND| wxTOP|
00490                         wxBOTTOM, 5 );
00491 
00492         mainSizer->Add( new wxStaticText(this, -1,
00493                         wxU( vlc_wraptext(HELLO_NOTICE , TEXTWIDTH , false ))),
00494                         0, wxALL, 5 );
00495 
00496         SetSizer(mainSizer);
00497         mainSizer->Fit(this);
00498     }
00499 
00500 void wizHelloPage::OnMoreInfo(wxCommandEvent& event)
00501 {
00502     wxString msg;
00503     msg.Printf( wxString( wxU( event.GetId() == MoreInfoStreaming_Event ?
00504                                     MOREINFO_STREAM :
00505                                     MOREINFO_TRANSCODE ) ) );
00506     wxMessageBox( msg, wxU(_("More information")),
00507                   wxOK | wxICON_INFORMATION, this->p_parent );
00508 }
00509 
00510 void wizHelloPage::OnActionChange( wxCommandEvent& event )
00511 {
00512     i_action = event.GetId() - ActionRadio0_Event;
00513     ((wizInputPage *)GetNext())->SetAction( i_action );
00514     p_parent->SetAction( i_action );
00515 }
00516 
00517 void wizHelloPage::OnWizardPageChanging(wxWizardEvent& event)
00518 {
00519     ((wizInputPage *)GetNext())->SetAction( i_action );
00520     p_parent->SetAction( i_action );
00521 }
00522 
00523 /************************************
00524  * Second page: choose input stream *
00525  ************************************/
00526 wizInputPage::wizInputPage( wxWizard *parent, wxWizardPage *prev, intf_thread_t *_p_intf) :
00527               wxWizardPage(parent)
00528 {
00529     p_prev = prev;
00530     p_intf = _p_intf;
00531     p_parent = (WizardDialog *)parent;
00532     b_chosen = false;
00533     p_open_dialog = NULL;
00534     listview = NULL;
00535     mrl_text = NULL;
00536     mainSizer = new wxBoxSizer(wxVERTICAL);
00537 
00538     /* Create the texts */
00539     pageHeader( this, mainSizer, INPUT_TITLE, INPUT_TEXT );
00540 
00541     mainSizer->Add( 0,20,0 );
00542 
00543     radio_panel = new wxPanel(this, -1);
00544     radio_panel->SetAutoLayout( TRUE );
00545 
00546     wxBoxSizer *radioSizer = new wxBoxSizer(wxVERTICAL);
00547 
00548     /* Create the radio buttons */
00549     input_radios[0] = new wxRadioButton( radio_panel, InputRadio0_Event ,
00550                                wxU( INPUT_OPEN ) );
00551     radioSizer->Add( input_radios[0], 0, wxALL, 5 );
00552     input_radios[1] = new wxRadioButton( radio_panel, InputRadio1_Event ,
00553                                wxU( INPUT_PL ) );  
00554     radioSizer->Add( input_radios[1], 0, wxALL, 5 );
00555 
00556     radio_panel->SetSizer( radioSizer );
00557     radioSizer->Layout();
00558     radioSizer->Fit(radio_panel);
00559     mainSizer->Add( radio_panel );
00560 
00561     i_input = 0;
00562 
00563     /* Open Panel */
00564     open_panel = new wxPanel(this, -1);
00565     open_panel->SetAutoLayout( TRUE );
00566 
00567     wxBoxSizer *openSizer = new wxBoxSizer(wxHORIZONTAL);
00568 
00569     mrl_text = new wxTextCtrl( open_panel, -1, wxU( "" ), wxDefaultPosition,
00570                               wxSize(200,25) );
00571 
00572     openSizer->Add( mrl_text, 0 , wxALL, 5 );
00573     openSizer->Add( new wxButton( open_panel, Choose_Event, wxU(_("Choose...")) ), 0, wxALL, 5 );
00574 
00575     open_panel->SetSizer( openSizer );
00576     openSizer->Layout();
00577     openSizer->Fit(open_panel);
00578     mainSizer->Add( open_panel );
00579 
00580     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
00581                                        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00582 
00583     if( p_playlist )
00584     {
00585         if( p_playlist->i_size > 0)
00586         {
00587             listview = new wxListView( this, ListView_Event,
00588                                        wxDefaultPosition, wxDefaultSize,
00589                                        wxLC_REPORT | wxSUNKEN_BORDER );
00590             listview->InsertColumn( 0, wxU(_("Name")) );
00591             listview->InsertColumn( 1, wxU(_("URI")) );
00592             listview->SetColumnWidth( 0, 250 );
00593             listview->SetColumnWidth( 1, 100 );
00594             for( int i=0 ; i < p_playlist->i_size ; i++ )
00595             {
00596                 wxString filename = wxL2U( p_playlist->pp_items[i]->input.
00597                                                                     psz_name );
00598                 listview->InsertItem( i, filename );
00599                 listview->SetItem( i, 1, wxL2U( p_playlist->pp_items[i]->
00600                                                             input.psz_uri) );
00601                 listview->SetItemData( i,
00602                                   (long)p_playlist->pp_items[i]->input.i_id );
00603             }
00604             listview->Select( p_playlist->i_index , TRUE);
00605             mainSizer->Add( listview, 1, wxALL|wxEXPAND, 5 );
00606 
00607             listview->Hide();
00608             mainSizer->Hide( listview );
00609             mainSizer->Layout();
00610         }
00611         else
00612         {
00613             input_radios[1]->Disable();
00614         }
00615         vlc_object_release( p_playlist );
00616     }
00617     else
00618     {
00619         input_radios[1]->Disable();
00620     }
00621 
00622     /* Partial Extract Box */
00623     mainSizer->Add( 0, 10, 0 );
00624     wxStaticBox *partial_box = new wxStaticBox( this, -1,
00625                     wxU(_("Partial Extract")) );
00626 
00627     wxStaticBoxSizer *partial_sizer = new wxStaticBoxSizer( partial_box,
00628                                                           wxVERTICAL );
00629 
00630     enable_checkbox = new wxCheckBox( this, PartialEnable_Event,
00631                                                 wxU(_("Enable") ) );
00632     enable_checkbox->SetToolTip(wxU(_(PARTIAL) ) ) ;
00633     partial_sizer->Add( enable_checkbox, 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 ); //wxLEFT
00634 
00635     wxFlexGridSizer *partial_sizer2 = new wxFlexGridSizer( 4 , 1 , 20 );
00636     partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "From" ) ) ),
00637                          0 , wxLEFT , 5 );
00638     from_text = new wxTextCtrl( this, -1, wxT(""),
00639                                 wxDefaultPosition, wxSize( 80,25 ) );
00640     partial_sizer2->Add( from_text, 0 , wxALIGN_RIGHT);
00641     partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "To" ) ) ),
00642                          0 , wxLEFT , 5 );
00643     to_text = new wxTextCtrl( this, -1, wxT(""),
00644                                   wxDefaultPosition, wxSize( 80 , 25 ) );
00645     partial_sizer2->Add( to_text, 0 , wxALIGN_RIGHT );
00646 
00647     partial_sizer->Add( partial_sizer2, 0, wxALL, 0 );
00648 
00649     partial_sizer->Fit( partial_box );
00650 
00651     mainSizer->Add( partial_sizer, 0, 0, 0 );
00652 
00653     from_text->Disable();
00654     to_text->Disable();
00655     SetSizer(mainSizer);
00656     mainSizer->Fit(this);
00657     mainSizer->Layout();
00658 }
00659 
00660 wizInputPage::~wizInputPage()
00661 {
00662 }
00663 
00664 void wizInputPage::OnInputChange( wxCommandEvent& event )
00665 {
00666     i_input = event.GetId() - InputRadio0_Event;
00667     if( i_input == 0 )
00668     {
00669         if( listview )
00670         {
00671             listview->Hide();
00672             mainSizer->Hide( listview );
00673             open_panel->Show();
00674             mainSizer->Show( open_panel );
00675             mainSizer->Layout();
00676         }
00677     }
00678     else
00679     {
00680         open_panel->Hide();
00681         mainSizer->Hide( open_panel );
00682         listview->Show();
00683         mainSizer->Show( listview );
00684         mainSizer->Layout();
00685     }
00686 }
00687 
00688 void wizInputPage::OnEnablePartial(wxCommandEvent& event)
00689 {
00690    from_text->Enable( event.IsChecked() );
00691    to_text->Enable( event.IsChecked() );
00692 }
00693 
00694 
00695 void wizInputPage::OnChoose(wxCommandEvent& event)
00696 {
00697     p_open_dialog = new OpenDialog( p_intf, this, -1, -1, OPEN_STREAM );
00698     if(  p_open_dialog->ShowModal() == wxID_OK &&
00699          !p_open_dialog->mrl.IsEmpty() )
00700     {
00701         mrl_text->SetValue(p_open_dialog->mrl[0] );
00702     }
00703     delete p_open_dialog;
00704     p_open_dialog = NULL;
00705 }
00706 
00707 void wizInputPage::OnWizardPageChanging(wxWizardEvent& event)
00708 {
00709     if( i_input == 0)
00710     {
00711         if( mrl_text->GetValue().IsSameAs( wxT(""), TRUE ) &&
00712                         event.GetDirection() )
00713         {
00714             wxMessageBox( wxU( CHOOSE_STREAM ), wxU( ERROR_MSG ),
00715                           wxICON_WARNING | wxOK, this->p_parent );
00716             event.Veto();
00717             return;
00718         }
00719         else
00720         {
00721             p_parent->SetMrl( (const char *)mrl_text->GetValue().mb_str() );
00722         }
00723     }
00724     else
00725     {
00726         int i = -1;
00727         i = listview->GetNextItem( i , wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
00728         if( i != -1 )
00729         {
00730             long data = listview->GetItemData( i );            
00731             playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
00732                                       VLC_OBJECT_PLAYLIST, FIND_ANYWHERE);
00733             if( p_playlist )
00734             {
00735                 playlist_item_t * p_item = playlist_LockItemGetById(
00736                                                    p_playlist, (int)data );
00737                 if( p_item )
00738                 {
00739                     p_parent->SetMrl( (const char*)p_item->input.psz_uri );
00740                 }
00741                 else
00742                     event.Veto();
00743             }
00744             else
00745                 event.Veto();
00746         }
00747     }
00748     if( enable_checkbox->IsChecked() )
00749     {
00750         int i_from = atoi( from_text->GetValue().mb_str() );
00751         int i_to = atoi( to_text->GetValue().mb_str() );
00752         p_parent->SetPartial( i_from, i_to );
00753     }
00754     return;
00755 }
00756 
00757 wxWizardPage *wizInputPage::GetPrev() const { return p_prev; }
00758 wxWizardPage *wizInputPage::GetNext() const
00759 {
00760     if( i_action == ACTION_STREAM )
00761         return p_streaming_page;
00762     else
00763        return p_transcode_page;
00764 }
00765 
00766 void wizInputPage::SetStreamingPage( wxWizardPage *page)
00767 {
00768     p_streaming_page = page;
00769 }
00770 
00771 void wizInputPage::SetTranscodePage( wxWizardPage *page)
00772 {
00773     p_transcode_page = page;
00774 }
00775 
00776 void wizInputPage::SetAction( int i_action )
00777 {
00778     this->i_action = i_action;
00779 }
00780 
00781 void wizInputPage::SetPintf( intf_thread_t *p_intf )
00782 {
00783     this->p_intf = p_intf;
00784 }
00785 
00786 void wizInputPage::SetUri( char *psz_uri )
00787 {
00788     mrl_text->SetValue( wxU( psz_uri ) );
00789 }
00790 
00791 void wizInputPage::SetPartial( int i_from, int i_to )
00792 {
00793    wxString msg;
00794    msg.Printf( wxString( wxT( "%i") ), i_from );
00795    from_text->Enable( TRUE );
00796    from_text->SetValue( msg );
00797    msg.Printf( wxString( wxT( "%i") ), i_to );
00798    to_text->Enable( TRUE );
00799    to_text->SetValue( msg );
00800    enable_checkbox->SetValue( TRUE );
00801 }
00802 
00803 /***************************************************
00804  * First transcode page: choose codecs             *
00805  ***************************************************/
00806 wizTranscodeCodecPage::wizTranscodeCodecPage( wxWizard *parent,
00807                        wxWizardPage *next) : wxWizardPage(parent)
00808 {
00809     int i;
00810 
00811     p_next = next;
00812 
00813     acodec = NULL;
00814     vcodec = NULL;
00815     p_parent = (WizardDialog *) parent;
00816 
00817     wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
00818 
00819     /* Header */
00820     pageHeader( this, main_sizer,  TRANSCODE1_TITLE, TRANSCODE1_TEXT );
00821 
00822     /* Video Box */
00823     wxStaticBox *video_box = new wxStaticBox( this, -1, wxU(_("Video")) );
00824     wxStaticBoxSizer *video_sizer = new wxStaticBoxSizer( video_box,
00825                                                           wxVERTICAL );
00826     /* Line 1 : only the checkbox */
00827     wxFlexGridSizer *video_sizer1 = new wxFlexGridSizer( 2,3,20 );
00828     video_sizer1->Add( new wxCheckBox( this, VideoEnable_Event,
00829                        wxU(_("Transcode video") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL , 5 );
00830     video_sizer1->Add( 0,0,1);
00831     /* Line 2 : codec */
00832     video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT ,5);
00833     video_combo = new wxComboBox( this, VideoCodec_Event, wxT(""),
00834                                   wxDefaultPosition, wxSize(200,25), 0, NULL, 
00835                                   wxCB_DROPDOWN| wxCB_READONLY );
00836     for( i= 0; vcodecs_array[i].psz_display != NULL; i++ )
00837     {
00838         video_combo->Append( wxU( vcodecs_array[i].psz_display ) ,
00839                             (void *)&vcodecs_array[i] );
00840     }
00841     i_video_codec = 0;
00842     video_combo->SetSelection(0);
00843 
00844     video_sizer1->Add( video_combo, 0 , wxALIGN_LEFT , 0 );
00845 
00846     video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
00847                        wxLEFT ,5);
00848     vb_combo = new wxComboBox( this, VideoBitrate_Event, wxT("1024"),
00849                                wxDefaultPosition, wxDefaultSize,
00850                                WXSIZEOF(vbitrates_array), vbitrates_array, wxCB_READONLY );
00851     video_sizer1->Add( vb_combo, 0, wxALIGN_LEFT , 0 );
00852 
00853     /* Line 3 : text */
00854     video_text = new wxStaticText( this, -1,
00855                      wxU( vlc_wraptext( TR_VIDEO_TEXT, TEXTWIDTH, false) ) );
00856     /* Fill the main video sizer */
00857     video_sizer->Add( video_sizer1 , 0, wxEXPAND , 5 );
00858     video_sizer->Add( video_text, 0, wxLEFT|wxTOP , 5 );
00859 
00860 
00861     /* Audio box */
00862     wxStaticBox *audio_box = new wxStaticBox( this, -1, wxU(_("Audio")) );
00863     wxStaticBoxSizer *audio_sizer = new wxStaticBoxSizer( audio_box,
00864                                                           wxVERTICAL );
00865     /* Line1: enabler */
00866     wxFlexGridSizer *audio_sizer1 = new wxFlexGridSizer( 2,3,20);
00867     audio_sizer1->Add( new wxCheckBox( this, AudioEnable_Event,
00868                             wxU(_("Transcode audio") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 );
00869     audio_sizer1->Add( 0, 0, 1 );
00870 
00871     /* Line 2 : codec */
00872     audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT,5);
00873     audio_combo = new wxComboBox( this, AudioCodec_Event, wxT(""),
00874                                   wxDefaultPosition, wxSize(200,25), 0, NULL, 
00875                                   wxCB_DROPDOWN| wxCB_READONLY );
00876     for( i= 0; acodecs_array[i].psz_display != NULL; i++ )
00877     {
00878         audio_combo->Append( wxU( acodecs_array[i].psz_display ) ,
00879                             (void *)&acodecs_array[i] );
00880     }
00881     i_audio_codec = 0;
00882     audio_combo->SetSelection(0);
00883     audio_sizer1->Add( audio_combo, 0 , wxALIGN_LEFT, 0 );
00884 
00885     audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
00886                        wxLEFT ,5);
00887     ab_combo = new wxComboBox( this, AudioBitrate_Event, wxT("192"),
00888                                wxDefaultPosition, wxDefaultSize,
00889                                WXSIZEOF(abitrates_array), abitrates_array, wxCB_READONLY );
00890     audio_sizer1->Add( ab_combo, 0, wxALIGN_LEFT, 0 );
00891 
00892     /* Line 3 : text */
00893     audio_text = new wxStaticText( this, -1,
00894                      wxU( vlc_wraptext( TR_AUDIO_TEXT, TEXTWIDTH, false) ) );
00895 
00896     audio_sizer->Add(audio_sizer1, 0, wxEXPAND, 5);
00897     audio_sizer->Add( audio_text, 0, wxLEFT | wxTOP, 5 );
00898 
00899     main_sizer->Add( video_sizer, 1, wxGROW, 0 );
00900     main_sizer->Add( audio_sizer, 1, wxGROW, 0 );
00901     main_sizer->Layout();
00902     SetSizerAndFit( main_sizer );
00903 
00904     /* Default disabled */
00905     video_combo->Disable(); video_text->Disable();vb_combo->Disable();
00906     audio_combo->Disable(); audio_text->Disable();ab_combo->Disable();
00907 
00908 }
00909 
00910 wizTranscodeCodecPage::~wizTranscodeCodecPage()
00911 {
00912     if( acodec ) free( acodec );
00913     if( vcodec ) free( vcodec );
00914 }
00915 
00916 void wizTranscodeCodecPage::OnEnableVideo(wxCommandEvent& event)
00917 {
00918    video_combo->Enable( event.IsChecked() );
00919    vb_combo->Enable( event.IsChecked() );
00920    video_text->Enable( event.IsChecked() );
00921 }
00922 
00923 void wizTranscodeCodecPage::OnEnableAudio(wxCommandEvent& event)
00924 {
00925    audio_combo->Enable( event.IsChecked() );
00926    ab_combo->Enable( event.IsChecked() );
00927    audio_text->Enable( event.IsChecked() );
00928 }
00929 
00930 void wizTranscodeCodecPage::OnVideoCodecChange(wxCommandEvent& event)
00931 {
00932     struct codec *c = (struct codec*)
00933              (video_combo->GetClientData(video_combo->GetSelection()));
00934     video_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH, false) ) );
00935     i_video_codec = video_combo->GetSelection();
00936     vcodec = strdup(c->psz_codec);
00937 }
00938 
00939 void wizTranscodeCodecPage::OnAudioCodecChange(wxCommandEvent& event)
00940 {
00941     struct codec *c = (struct codec*)
00942              (audio_combo->GetClientData(audio_combo->GetSelection()));
00943     audio_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH, false) ) );
00944     i_audio_codec = audio_combo->GetSelection();
00945     acodec = strdup(c->psz_codec);
00946 
00947 }
00948 
00949 void wizTranscodeCodecPage::OnWizardPageChanging(wxWizardEvent& event)
00950 {
00951     unsigned int i,j;
00952 
00953     if( !event.GetDirection() )
00954     {
00955             GetPrev()->Enable();
00956             return;
00957     }
00958 
00959     /* Set the dummy codec ( accept all muxers ) if needed */
00960     if( !video_combo->IsEnabled() )
00961     {
00962         i_video_codec = VCODECS_NUMBER;
00963     }
00964     if( !audio_combo->IsEnabled() )
00965     {
00966         i_audio_codec = ACODECS_NUMBER;
00967     }
00968 
00969     ((wizEncapPage *)GetNext())->SetPrev(this);
00970 
00971     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
00972     {
00973         if( vcodecs_array[i_video_codec].muxers[i] != -1 )
00974         {
00975             for( j = 0 ; j<  MUXERS_NUMBER ; j++ )
00976             {
00977                 if( acodecs_array[i_audio_codec].muxers[j] ==
00978                               vcodecs_array[i_video_codec].muxers[i] )
00979                 {
00980                     ((wizEncapPage*)GetNext())->EnableEncap(
00981                                vcodecs_array[i_video_codec].muxers[i] );
00982                 }
00983             }
00984         }
00985     }
00986     struct codec *c = (struct codec*)
00987              (video_combo->GetClientData( video_combo->IsEnabled() ?
00988                                           video_combo->GetSelection(): i_video_codec ));
00989     vcodec = strdup(c->psz_codec);
00990     c = (struct codec*)
00991            (audio_combo->GetClientData( audio_combo->IsEnabled() ?
00992                                        audio_combo->GetSelection() : i_audio_codec ));
00993     acodec = strdup(c->psz_codec);
00994 
00995     int vb = atoi(vb_combo->GetValue().mb_str() );
00996     if( vb == 0 )
00997     {
00998          vb = 1024;
00999     }
01000     int ab = atoi(ab_combo->GetValue().mb_str() );
01001     if( ab == 0)
01002     {
01003         ab = 192;
01004     }
01005 
01006     p_parent->SetTranscode( vcodec, vb , acodec, ab );
01007     ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
01008     p_parent->SetAction( p_parent->GetAction() );
01009 
01010     return;
01011 }
01012 
01013 wxWizardPage *wizTranscodeCodecPage::GetPrev() const { return p_prev; }
01014 wxWizardPage *wizTranscodeCodecPage::GetNext() const { return p_next; }
01015 void wizTranscodeCodecPage::SetPrev( wxWizardPage *page) {p_prev = page; }
01016 
01017 
01018 /***************************************************
01019  * First streaming page: choose method             *
01020  ***************************************************/
01021 wizStreamingMethodPage::wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
01022     wxWizardPage *next) : wxWizardPage(parent), p_intf( p_this )
01023 {
01024     int i;
01025     p_next = next;
01026     p_parent = (WizardDialog *)parent;
01027 
01028     mainSizer = new wxBoxSizer(wxVERTICAL);
01029 
01030     /* Create the texts */
01031     pageHeader( this, mainSizer,  STREAMING1_TITLE, STREAMING1_TEXT );
01032 
01033     mainSizer->Add( 0,50,0 );
01034 
01035     i_method = 0;
01036 
01037     wxStaticBox *method_box = new wxStaticBox( this, -1,
01038                                                wxU(_("Streaming method")) );
01039     wxStaticBoxSizer *method_sizer = new wxStaticBoxSizer(method_box,
01040                                                           wxHORIZONTAL );
01041     for( i = 0 ; i< 3 ; i++ )
01042     {
01043         method_radios[i] = new wxRadioButton( this, MethodRadio0_Event + i,
01044                                wxU( methods_array[i].psz_method ) );
01045         method_radios[i]->SetToolTip( wxU(_( methods_array[i].psz_descr ) ) );
01046         method_sizer->Add( method_radios[i], 0, wxALL, 5 );
01047     }
01048 
01049     method_sizer->Layout();
01050 
01051     wxStaticBox *address_box = new wxStaticBox( this, -1,
01052                     wxU(_("Destination")) );
01053 
01054     address_sizer = new wxStaticBoxSizer(address_box,
01055                                          wxVERTICAL );
01056 
01057     /* Big kludge, we take the longest text to get the size */
01058     address_text = new wxStaticText(this, -1,
01059                wxU( vlc_wraptext(methods_array[2].psz_address,
01060                                  TEXTWIDTH, false ) ),
01061                wxDefaultPosition, wxDefaultSize );
01062 
01063     address_txtctrl = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
01064                                       wxSize(200,25));
01065     address_sizer->Add( address_text, 0, wxALL, 5 );
01066     address_sizer->Add( address_txtctrl, 0, wxALL, 5 );
01067     address_sizer->Layout();
01068 
01069     /* Set the minimum size */
01070     address_sizer->SetMinSize( address_sizer->GetSize() );
01071     address_text->SetLabel( wxU(
01072      vlc_wraptext( _(methods_array[0].psz_address), TEXTWIDTH, false)));
01073 
01074     mainSizer->Add( method_sizer, 0, wxALL | wxEXPAND, 5 );
01075     mainSizer->Add( address_sizer, 0, wxALL | wxEXPAND, 5 );
01076 
01077     mainSizer->Add( 0,0,1 );
01078 
01079     mainSizer->Layout();
01080 
01081     SetSizer(mainSizer);
01082     mainSizer->Fit(this);
01083 
01084     return;
01085 }
01086 
01087 void wizStreamingMethodPage::OnWizardPageChanging(wxWizardEvent& event)
01088 {
01089     unsigned int i;
01090     if( !event.GetDirection() ) return;
01091 
01092     /* Check valid address */
01093     if( i_method == 1
01094      && !net_AddressIsMulticast( (vlc_object_t *)p_intf,
01095                                  address_txtctrl->GetValue().mb_str()) )
01096     {
01097         wxMessageBox( wxU( INVALID_MCAST_ADDRESS ) , wxU( ERROR_MSG ),
01098                       wxICON_WARNING | wxOK, this->p_parent );
01099         event.Veto();
01100 
01101     }
01102     else if( i_method == 0 && address_txtctrl->GetValue().IsEmpty() )
01103     {
01104         wxMessageBox( wxU( NO_ADDRESS_TEXT ) , wxU( ERROR_MSG ),
01105                       wxICON_WARNING | wxOK, this->p_parent );
01106         event.Veto();
01107 
01108     }
01109 
01110     ((wizEncapPage *)GetNext())->SetPrev(this);
01111     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
01112     {
01113         if( methods_array[i_method].muxers[i] != -1 )
01114         {
01115             ((wizEncapPage*)GetNext())->EnableEncap(
01116                                methods_array[i_method].muxers[i] );
01117         }
01118     }
01119     p_parent->SetStream( methods_array[i_method].psz_access ,
01120                          address_txtctrl->GetValue().mb_str() );
01121 
01122     /* Set the action for the muxer page */
01123     ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
01124     return;
01125 }
01126 
01127 wxWizardPage *wizStreamingMethodPage::GetPrev() const { return p_prev; }
01128 wxWizardPage *wizStreamingMethodPage::GetNext() const { return p_next; }
01129 
01130 void wizStreamingMethodPage::SetPrev( wxWizardPage *page) {p_prev = page; }
01131 
01132 
01133 void wizStreamingMethodPage::OnMethodChange( wxCommandEvent& event )
01134 {
01135     i_method = event.GetId() - MethodRadio0_Event;
01136     address_text->SetLabel( wxU(
01137      vlc_wraptext( _(methods_array[i_method].psz_address), TEXTWIDTH, false)));
01138     address_sizer->Layout();
01139     mainSizer->Layout();
01140 }
01141 
01142 /***************************************************
01143  * Choose encapsulation format                     *
01144  ***************************************************/
01145 wizEncapPage::wizEncapPage( wxWizard *parent ) : wxWizardPage(parent)
01146 {
01147     int i;
01148     i_mux = 0;
01149     p_parent = (WizardDialog *)parent;
01150     p_streaming_page = NULL;
01151     p_transcode_page = NULL;
01152     p_prev = NULL;
01153     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
01154 
01155     /* Create the texts */
01156     pageHeader( this, mainSizer, ENCAP_TITLE, ENCAP_TEXT );
01157 
01158     mainSizer->Add( 0,0,1 );
01159 
01160     for( i = 0 ; i< MUXERS_NUMBER ; i++ )
01161     {
01162         encap_radios[i] = new wxRadioButton( this, EncapRadio0_Event + i,
01163                                wxU( encaps_array[i].psz_encap ) );
01164         encap_radios[i]->SetToolTip( wxU(_( encaps_array[i].psz_descr ) ) );
01165         mainSizer->Add( encap_radios[i], 0, wxLEFT, 5 );
01166         encap_radios[i]->Disable();
01167     }
01168 
01169     mainSizer->Add( 0,0,1 );
01170 
01171     SetSizer(mainSizer);
01172     mainSizer->Fit(this);
01173 }
01174 
01175 wizEncapPage::~wizEncapPage()
01176 {
01177 }
01178 
01179 void wizEncapPage::OnWizardPageChanging(wxWizardEvent& event)
01180 {
01181     int i;
01182     if( !event.GetDirection() )
01183     {
01184         for( i = 0 ; i< MUXERS_NUMBER ; i++ )
01185         {
01186             encap_radios[i]->Disable();
01187         }
01188     }
01189     p_parent->SetMux( encaps_array[i_mux].psz_mux );
01190 
01191     if( p_parent->GetAction() == ACTION_STREAM )
01192     {
01193         if( strstr( p_parent->method, "udp" ))
01194         {
01195             ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable();
01196             ((wizStreamingExtraPage *)GetNext())->sap_text->Enable(false);
01197         }
01198         else
01199         {
01200            ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable( false );
01201            ((wizStreamingExtraPage *)GetNext())->sap_text->Enable( false );
01202         }
01203     }
01204 
01205     return;
01206 }
01207 
01208 
01209 void wizEncapPage::OnEncapChange( wxCommandEvent& event )
01210 {
01211     i_mux = event.GetId() - EncapRadio0_Event;
01212 }
01213 
01214 void wizEncapPage::EnableEncap( int encap )
01215 {
01216     int i;
01217     for( i = 0 ; i< MUXERS_NUMBER ; i++)
01218     {
01219         if( encaps_array[i].id == encap )
01220         {
01221             encap_radios[i]->Enable();
01222             encap_radios[i]->SetValue(true);
01223             i_mux = i;
01224         }
01225     }
01226 }
01227 
01228 void wizEncapPage::SetStreamingPage( wxWizardPage *page)
01229 {
01230     p_streaming_page = page;
01231 }
01232 
01233 void wizEncapPage::SetTranscodePage( wxWizardPage *page)
01234 {
01235     p_transcode_page = page;
01236 }
01237 
01238 wxWizardPage *wizEncapPage::GetPrev() const { return p_prev; }
01239 
01240 wxWizardPage *wizEncapPage::GetNext() const
01241 {
01242     if( i_action== ACTION_STREAM )
01243         return p_streaming_page;
01244     else
01245        return p_transcode_page;
01246 }
01247 
01248 void wizEncapPage::SetAction( int i_act  ) { i_action = i_act; }
01249 
01250 void wizEncapPage::SetPrev( wxWizardPage *page) { p_prev = page; }
01251 
01252 /***************************************************
01253  * Extra transcoding page : Select file            *
01254  ***************************************************/
01255 wizTranscodeExtraPage::wizTranscodeExtraPage( wxWizard *parent,
01256                        wxWizardPage *prev,
01257                        wxWizardPage *next) : wxWizardPage(parent)
01258 {
01259     p_next = next;
01260     p_prev = prev;
01261     p_parent = (WizardDialog *) parent;
01262     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
01263 
01264     /* Create the texts */
01265     pageHeader( this, mainSizer, EXTRATRANSCODE_TITLE, EXTRATRANSCODE_TEXT );
01266 
01267     mainSizer->Add( 0, 0, 1 );
01268 
01269     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 2, 1 );
01270     sizer->Add( new wxStaticText( this, -1,
01271                     wxU(_("Select the file to save to") ) ),
01272                     0, wxALL, 5 );
01273     sizer->Add( 0, 0, 1 );
01274 
01275     file_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
01276                                 wxSize( 150, -1 ) );
01277 
01278     sizer->Add( file_text, 0,  wxALL, 5 );
01279     sizer->Add( new wxButton( this, Open_Event, wxU("Choose") ) );
01280 
01281     mainSizer->Add( sizer, 0, 0, 0) ;
01282 
01283     mainSizer->Add( 0, 0, 1 );
01284     SetSizer(mainSizer);
01285     mainSizer->Fit(this);
01286 }
01287 
01288 void wizTranscodeExtraPage::OnSelectFile( wxCommandEvent &event)
01289 {
01290     wxFileDialog *file_dialog =  new wxFileDialog( this, wxU(_("Save to file")),
01291                    wxT(""), wxT(""), wxT("*"), wxSAVE );
01292 
01293     if( file_dialog && file_dialog->ShowModal() == wxID_OK )
01294     {
01295         if( file_dialog->GetFilename().mb_str() )
01296         {
01297             file_text->SetValue( file_dialog->GetPath() );
01298         }
01299     }
01300 }
01301 
01302 void wizTranscodeExtraPage::OnWizardPageChanging( wxWizardEvent& event )
01303 {
01304     if( event.GetDirection() && file_text->GetValue().IsEmpty() )
01305     {
01306         wxMessageBox( wxU( CHOOSE_OUTFILE ), wxU( ERROR_MSG ),
01307                       wxICON_WARNING | wxOK, this->p_parent );
01308         event.Veto();
01309     }
01310     if( event.GetDirection() )
01311     {
01312        p_parent->SetTranscodeOut( file_text->GetValue().mb_str());
01313     }
01314 }
01315 
01316 wxWizardPage *wizTranscodeExtraPage::GetPrev() const { return p_prev; }
01317 wxWizardPage *wizTranscodeExtraPage::GetNext() const {return p_next; }
01318 
01319 /***********************************************************
01320  *  Extra streaming page
01321  ***********************************************************/
01322 wizStreamingExtraPage::wizStreamingExtraPage( wxWizard *parent,
01323                        wxWizardPage *prev,
01324                        wxWizardPage *next) : wxWizardPage(parent)
01325 {
01326     p_next = next;
01327     p_prev = prev;
01328     p_parent = (WizardDialog *) parent;
01329     wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
01330 
01331     /* Create the texts */
01332     pageHeader( this, mainSizer, EXTRASTREAMING_TITLE, EXTRASTREAMING_TEXT );
01333 
01334     mainSizer->Add( 0, 0, 1 );
01335 
01336     wxFlexGridSizer *sizer = new wxFlexGridSizer( 2,2,1) ;
01337 
01338     /* TTL */
01339     sizer->Add( new wxStaticText( this, -1, wxU(_("Time-To-Live (TTL)"))),
01340                     0, wxALL,  5 );
01341     ttl_spin = new wxSpinCtrl( this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
01342                     0, 1, 255, 1 );
01343     ttl_spin->SetToolTip(wxU(_(TTL) ) ) ;
01344     sizer->Add( ttl_spin, 0, wxALL , 5 );
01345 
01346     /* SAP announce */
01347     sap_checkbox =  new wxCheckBox( this, SAP_Event, wxU(_("SAP Announce")) );
01348     sap_checkbox->SetToolTip( wxU(_( SAP ) ) );
01349     sizer->Add( sap_checkbox, 0, 0 , 0 );
01350     sap_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
01351                     wxSize(100,25) );
01352     sap_text->SetToolTip( wxU(_( SAP ) ) );
01353     sizer->Add( sap_text, 0, wxALL , 5 );
01354 
01355     mainSizer->Add(sizer, 0, wxALL, 5 );
01356 
01357     mainSizer->Add( 0, 0, 1 );
01358 
01359     SetSizer(mainSizer);
01360     mainSizer->Fit(this);
01361 }
01362 
01363 void wizStreamingExtraPage::OnSAP( wxCommandEvent &event )
01364 {
01365     sap_text->Enable( event.IsChecked() );
01366 }
01367 
01368 void wizStreamingExtraPage::OnWizardPageChanging(wxWizardEvent& event)
01369 {
01370     if( sap_checkbox->IsChecked() )
01371     {
01372         if( sap_text->GetValue().IsEmpty() )
01373         {
01374             p_parent->SetSAP( true, NULL );
01375         }
01376         else
01377         {
01378             p_parent->SetSAP( true,
01379                              (const char *)sap_text->GetValue().mb_str() );
01380         }
01381     }
01382     else
01383     {
01384         p_parent->SetSAP( false, NULL );
01385     }
01386 
01387     p_parent->SetTTL( ttl_spin->GetValue() );
01388 }
01389 
01390 wxWizardPage *wizStreamingExtraPage::GetPrev() const { return p_prev; }
01391 wxWizardPage *wizStreamingExtraPage::GetNext() const {return p_next; }
01392 
01393 
01394 /***************************************************************************
01395  * Implementation of the wizard itself
01396  ***************************************************************************/
01397 wizHelloPage *page1;
01398 wizInputPage *page2 ;
01399 wizTranscodeCodecPage *tr_page1 ;
01400 wizStreamingMethodPage *st_page1;
01401 wizTranscodeExtraPage *tr_page2 ;
01402 wizStreamingExtraPage *st_page2;
01403 wizEncapPage *encap_page;
01404 
01405 WizardDialog::WizardDialog(intf_thread_t *_p_intf, wxWindow *_p_parent,
01406                            char *psz_uri, int _i_from, int _i_to  ) :
01407 wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, wxDefaultPosition)
01408 {
01409     /* Initializations */
01410     p_intf = _p_intf;
01411     SetPageSize(wxSize(400,420));
01412 
01413     /* Initialize structure */
01414     i_action = 0;
01415     i_from = _i_from;
01416     i_to = _i_to;
01417     i_ttl = 1;
01418     vb = 0;
01419     ab = 0;
01420     acodec=NULL;
01421     vcodec=NULL;
01422 
01423     page1 = new wizHelloPage(this);
01424     page2 = new wizInputPage(this, page1, p_intf);
01425 
01426     if( psz_uri )
01427     {
01428         page2->SetUri( psz_uri );
01429     }
01430     if( i_from != 0 || i_to != 0 )
01431     {
01432         page2->SetPartial( i_from, i_to );
01433     }
01434 
01435     encap_page = new wizEncapPage(this );
01436     tr_page1 = new wizTranscodeCodecPage(this, encap_page );
01437     st_page1 = new wizStreamingMethodPage( p_intf, this, encap_page);
01438 
01439     tr_page2 = new wizTranscodeExtraPage(this, encap_page, NULL );
01440     st_page2 = new wizStreamingExtraPage(this, encap_page, NULL );
01441 
01442     /* Page 1 -> 2 */
01443     page1->SetNext( page2 );
01444     /* 2->1 in constructor of 2 */
01445 
01446     /* Page 2 -> 3 */
01447     page2->SetTranscodePage(tr_page1);
01448     page2->SetStreamingPage(st_page1);
01449     page2->SetPintf( p_intf );
01450     tr_page1->SetPrev(page2);
01451     st_page1->SetPrev(page2);
01452 
01453     /* Page 3 -> 4 */
01454     encap_page->SetTranscodePage( tr_page2 );
01455     encap_page->SetStreamingPage( st_page2 );
01456     /* 3->4 in constructor of 3 */
01457 //    encap_page->SetPrev(tr_page1);
01458 }
01459 
01460 WizardDialog::~WizardDialog()
01461 {
01462     Destroy();
01463     delete page1;
01464     delete page2;
01465     delete tr_page1;
01466     delete st_page1 ;
01467     delete st_page2;
01468     delete tr_page2;
01469     delete encap_page;
01470 }
01471 
01472 void WizardDialog::SetMrl( const char *mrl )
01473 {
01474     this->mrl = strdup( mrl );
01475 }
01476 
01477 void WizardDialog::SetTTL( int i_ttl )
01478 {
01479     this->i_ttl = i_ttl;
01480 }
01481 
01482 void WizardDialog::SetSAP( bool b_enabled, const char *psz_text )
01483 {
01484     this->b_sap = b_enabled;
01485     if( b_enabled )
01486     {
01487         if( psz_text != NULL )
01488         {
01489             this->psz_sap_name = strdup( psz_text );
01490         }
01491         else
01492         {
01493             this->psz_sap_name = NULL;
01494         }
01495     }
01496 }
01497 
01498 void WizardDialog::SetPartial( int i_from, int i_to )
01499 {
01500     this->i_from = i_from;
01501     this->i_to = i_to;
01502 }
01503 
01504 void WizardDialog::SetTranscode( char const *vcodec, int vb,
01505                                  char const *acodec, int ab)
01506 {
01507     if( strcmp( vcodec, "dummy") )
01508     {
01509         this->vcodec= strdup(vcodec);
01510     }
01511     if( strcmp( acodec, "dummy" ) )
01512     {
01513         this->acodec = strdup(acodec);
01514     }
01515     this->vb = vb;
01516     this->ab = ab;
01517 }
01518 
01519 void WizardDialog::SetStream( char const *method, char const *address )
01520 {
01521     this->method = strdup( method );
01522     this->address = strdup( address );
01523 }
01524 
01525 void WizardDialog::SetTranscodeOut( char const *address )
01526 {
01527     char *psz_utf8 = FromLocale( address );
01528     this->address = strdup( psz_utf8 );
01529     LocaleFree( psz_utf8 );
01530 }
01531 
01532 void WizardDialog::SetMux( char const *mux )
01533 {
01534     this->mux = strdup( mux );
01535 }
01536 
01537 void WizardDialog::SetAction( int i_action )
01538 {
01539     this->i_action = i_action;
01540 }
01541 
01542 int WizardDialog::GetAction()
01543 {
01544     return i_action;
01545 }
01546 
01547 void WizardDialog::Run()
01548 {
01549     if( RunWizard(page1) )
01550     {
01551         int i_size;
01552         char *psz_opt;
01553 
01554         if( i_action == ACTION_TRANSCODE )
01555         {
01556             msg_Dbg( p_intf,"Starting transcode of %s to file %s",
01557                                   mrl, address);
01558             msg_Dbg( p_intf,"Using %s (%i kbps) / %s (%i kbps),encap %s",
01559                                 vcodec,vb,acodec,ab,mux);
01560             char *psz_transcode;
01561 
01562             if( vcodec != NULL || acodec != NULL )
01563             {
01564                 int i_tr_size = 14;
01565                 if( vcodec != NULL )
01566                     i_tr_size += strlen( vcodec ) + 17;
01567                 if( acodec != NULL )
01568                     i_tr_size += strlen( acodec ) + 17;
01569 
01570                 if( vb > 999999 )
01571                     vb = 999999;
01572                 else if( vb < 0 )
01573                     vb = 0;
01574 
01575                 if( ab > 999999 )
01576                     ab = 999999;
01577                 else if( ab < 0 )
01578                     ab = 0;
01579 
01580                 psz_transcode = (char *)malloc( i_tr_size * sizeof(char) );
01581 
01582                 strcpy( psz_transcode, "transcode{" );
01583                 if( vcodec != NULL )
01584                 {
01585                     sprintf( psz_transcode + strlen( psz_transcode ),
01586                              "vcodec=%s,vb=%i%s", vcodec, vb,
01587                              ( acodec != NULL ) ? "," : "}:" );
01588                 }
01589                 if( acodec != NULL )
01590                 {
01591                     sprintf( psz_transcode + strlen( psz_transcode ),
01592                              "acodec=%s,ab=%i}:", acodec, ab );
01593                 }
01594             }
01595             else
01596                 psz_transcode = "";
01597 
01598             i_size = 73 + strlen(mux) + strlen(address) + strlen(psz_transcode);
01599             psz_opt = (char *)malloc( i_size * sizeof(char) );
01600             snprintf( psz_opt, i_size, ":sout=#%sstandard{mux=%s,url=%s,"
01601                       "access=file}", psz_transcode, mux, address );
01602 
01603             if( *psz_transcode )
01604                 free( psz_transcode );
01605         }
01606         else
01607         {
01608             msg_Dbg( p_intf, "Starting stream of %s to %s using %s, encap %s",
01609                                mrl, address, method, mux);
01610             if( b_sap )
01611             {
01612                 char *psz_sap_option = NULL;
01613                 if( psz_sap_name )
01614                 {
01615                     psz_sap_option = (char *) malloc( strlen( psz_sap_name )
01616                                                + 15 );
01617                     snprintf( psz_sap_option,strlen( psz_sap_name ) + 15,
01618                              "sap,name=\"%s\"",psz_sap_name );
01619                 }
01620                 else
01621                     psz_sap_option = strdup( "sap" );
01622 
01623                 i_size = 40 + strlen(mux) + strlen(address) +
01624                               strlen( psz_sap_option);
01625                 psz_opt = (char *)malloc( i_size * sizeof(char) );
01626                 snprintf( psz_opt, i_size,
01627                           ":sout=#standard{mux=%s,url=%s,access=%s,%s}",
01628                           mux, address,method, psz_sap_option);
01629                 if( psz_sap_option ) free( psz_sap_option );
01630             }
01631             else
01632             {
01633                 i_size = 40 + strlen(mux) + strlen(address);
01634                 psz_opt = (char *)malloc( i_size * sizeof(char) );
01635                 snprintf( psz_opt, i_size,
01636                           ":sout=#standard{mux=%s,url=%s,access=%s}",
01637                           mux, address,method);
01638             }
01639         }
01640 
01641         playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
01642                             VLC_OBJECT_PLAYLIST, FIND_ANYWHERE);
01643         if( p_playlist )
01644         {
01645             playlist_item_t *p_item = playlist_ItemNew( p_playlist, mrl,
01646                                                         ITEM_NAME );
01647             playlist_ItemAddOption( p_item, psz_opt);
01648             if( i_from != 0)
01649             {
01650                 char psz_from[20];
01651                 snprintf( psz_from, 20, "start-time=%i", i_from);
01652                 playlist_ItemAddOption( p_item, psz_from);
01653             }
01654             if( i_to != 0)
01655             {
01656                 char psz_to[20];
01657                 snprintf( psz_to, 20, "stop-time=%i", i_to);
01658                 playlist_ItemAddOption( p_item, psz_to);
01659             }
01660 
01661             char psz_ttl[20];
01662             snprintf( psz_ttl, 20, "ttl=%i",i_ttl );
01663             playlist_ItemAddOption( p_item, psz_ttl );
01664 
01665             playlist_AddItem( p_playlist, p_item, PLAYLIST_GO, PLAYLIST_END );
01666             vlc_object_release(p_playlist);
01667         }
01668         else
01669         {
01670             wxMessageBox( wxU( NO_PLAYLIST ), wxU( ERROR_MSG ),
01671                           wxICON_WARNING | wxOK, this );
01672         }
01673     }
01674 }

Generated on Tue Dec 20 10:14:48 2005 for vlc-0.8.4a by  doxygen 1.4.2