wizard.cpp 52.4 KB
Newer Older
1 2 3
/*****************************************************************************
 * wizard.cpp : wxWindows plugin for vlc
 *****************************************************************************
4
 * Copyright (C) 2000-2005 the VideoLAN team
5 6
 * $Id$
 *
7
 * Authors: Clément Stenac <zorglub@videolan.org>
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
27
#include "dialogs/wizard.hpp"
28
#include "streamdata.h"
29
#include "dialogs/open.hpp"
30

31
#include <wx/listctrl.h>
32
#include <wx/statline.h>
Clément Stenac's avatar
Clément Stenac committed
33 34
#include <vlc_network.h>
#include <vlc_charset.h>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

class wizHelloPage;
class wizInputPage;

/*****************************************************************************
 * Define events
 *****************************************************************************/
enum
{
    ActionRadio0_Event, ActionRadio1_Event,
    MoreInfoStreaming_Event,
    MoreInfoTranscode_Event,

    Open_Event , Choose_Event ,
    ListView_Event,
    InputRadio0_Event, InputRadio1_Event,
    PartialEnable_Event,

    MethodRadio0_Event, MethodRadio1_Event,
    MethodRadio2_Event, MethodRadio3_Event,

    EncapRadio0_Event, EncapRadio1_Event,
    EncapRadio2_Event, EncapRadio3_Event,
    EncapRadio4_Event, EncapRadio5_Event,
    EncapRadio6_Event, EncapRadio7_Event,
    EncapRadio8_Event, EncapRadio9_Event,
    EncapRadio10_Event, EncapRadio11_Event,

    VideoEnable_Event, VideoCodec_Event,VideoBitrate_Event,
    AudioEnable_Event, AudioCodec_Event,AudioBitrate_Event,

    SAP_Event,

};

#define TEXTWIDTH 55
#define ACTION_STREAM 0
#define ACTION_TRANSCODE 1

BEGIN_EVENT_TABLE(WizardDialog, wxWizard)
END_EVENT_TABLE()

/*****************************************************************************
 * Wizard strings
 *****************************************************************************/

#define ERROR_MSG _("Error")
#define ITEM_NAME _("Streaming/Transcoding Wizard")

/* Hello page */
#define HELLO_TITLE _("Streaming/Transcoding Wizard")
#define HELLO_TEXT _("This wizard helps you to stream, transcode or" \
Felix Paul Kühne's avatar
OSX:  
Felix Paul Kühne committed
87
                     " save a stream.")
88
#define HELLO_STREAMING _("Stream to network")
Felix Paul Kühne's avatar
OSX:  
Felix Paul Kühne committed
89
#define HELLO_STREAMING_DESC _("Use this to stream on a network.")
90
#define HELLO_TRANSCODE _("Transcode/Save to file")
91 92
#define HELLO_TRANSCODE_DESC _("Use this to re-encode a stream and save it "\
        "to a file.")
93
#define HELLO_NOTICE _("This wizard only contains a small subset " \
94
        "of VLC's streaming and transcoding capabilities. Use the Open "\
95
        "and Stream Output dialogs to access all of them.")
96 97 98

#define MOREINFO_STREAM _("Use this to stream on a network")

99 100 101 102 103
#define MOREINFO_TRANSCODE _("Saves the stream to a file. The stream must " \
        "be a format that VLC recognizes. If desired, the stream can also " \
        "be transcoded to another format.\n\nPlease note that VLC is not very" \
        " suited for file-to-file transcoding. Its transcoding " \
        "features are more appropriate for saving network streams." )
104 105

/* Input page */
106 107
#define INPUT_TITLE _("Input")
#define INPUT_TEXT _("Input stream")
108 109 110 111 112

#define INPUT_OPEN _("Select a stream" )
#define INPUT_PL _( "Existing playlist item" )

#define CHOOSE_STREAM _("You must choose a stream")
113
#define NO_PLAYLIST _("Unable to find playlist")
114 115

#define PARTIAL _("Use this to read only a part of the stream. " \
116 117
                  "To use, enter the starting and ending times (in seconds)." \
                  "\n\nNote: You must be able to control the incoming stream " \
118
                  "(for example, a file or a disc, but not a RTP/UDP " \
119 120
                  "network stream).\n" \
)
121 122 123 124 125

#define INPUT_BUTTON _("Choose")

/* Transcode 1 */
#define TRANSCODE1_TITLE _("Transcode")
126 127 128
#define TRANSCODE1_TEXT _("Changes the compression format " \
        "of the audio or video tracks. To change only the " \
        "container format, proceed to the next page.")
129

130 131 132
#define TR_VIDEO_TEXT0 _("Transcode video (if available)" )
#define TR_VIDEO_TEXT _("Select the target video codec. Choose a codec to " \
                        "display more information about it.")
133

134 135 136
#define TR_AUDIO_TEXT0 _("Transcode audio (if available)"
#define TR_AUDIO_TEXT _("Select the target audio codec. Choose a codec to " \
                        "display more information about it.")
137 138 139

/* Streaming 1 */
#define STREAMING1_TITLE _("Streaming")
140
#define STREAMING1_TEXT _("Determines how the input stream will be sent.")
141 142 143 144


#define INVALID_MCAST_ADDRESS _("This does not appear to be a valid " \
                                "multicast address" )
145
#define NO_ADDRESS_TEXT _("Please enter an address" )
146 147 148

/* Encap  */
#define ENCAP_TITLE _("Encapsulation format")
149 150 151
#define ENCAP_TEXT _("Determines how the stream will be encapsulated. " \
                     "Depending on the previous choices, some formats " \
                     "might not be available." )
152 153 154 155


/* Transcode 2 */
#define EXTRATRANSCODE_TITLE _("Additional transcode options")
156 157
#define EXTRATRANSCODE_TEXT _("Defines a few additional parameters " \
                              "for the transcoding." )
158 159 160 161 162

#define CHOOSE_OUTFILE _("You must choose a file to save to")

/* Streaming 2 */
#define EXTRASTREAMING_TITLE _("Additional streaming options")
163 164
#define EXTRASTREAMING_TEXT _("Defines a few additional parameters " \
                              "for the stream." )
165 166 167 168 169 170

#define TTL _("Define the TTL (Time-To-Live) of the stream. This parameter " \
              "is the maximum number of routers your stream can go through. " \
              "If you don't know what it means, or if you want to stream on " \
              "your local network only, leave this setting to 1." )

171
#define SAP _("When streaming using RTP, you can announce your streams " \
172 173 174
              "using the SAP/SDP announcing protocol. This way, the clients " \
              "won't have to type in the multicast address, it will appear " \
              "in their playlist if they enable the SAP extra interface.\n" \
175 176
              "If you want to give a name to your stream, enter it here. " \
              "Otherwise, a default name will be used." )
177 178 179 180 181 182 183 184 185 186

/*****************************************************************************
 * All the pages of the wizard, declaration
 *****************************************************************************/

/* Declare classes */
class wizHelloPage : public wxWizardPageSimple
{
    public:
        wizHelloPage( wxWizard *parent);
187
        void OnActionChange( wxCommandEvent& event );
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
        void OnWizardPageChanging(wxWizardEvent& event);
        void OnMoreInfo( wxCommandEvent& event );
    protected:
        int i_action;
        WizardDialog *p_parent;
        wxRadioButton *action_radios[2];
        DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(wizHelloPage, wxWizardPageSimple)
    EVT_RADIOBUTTON( ActionRadio0_Event, wizHelloPage::OnActionChange)
    EVT_RADIOBUTTON( ActionRadio1_Event, wizHelloPage::OnActionChange)
    EVT_BUTTON( MoreInfoStreaming_Event, wizHelloPage::OnMoreInfo )
    EVT_BUTTON( MoreInfoTranscode_Event, wizHelloPage::OnMoreInfo )

    EVT_WIZARD_PAGE_CHANGING(-1, wizHelloPage::OnWizardPageChanging)
END_EVENT_TABLE()


class wizInputPage : public wxWizardPage
{
    public:
        wizInputPage( wxWizard *, wxWizardPage *, intf_thread_t *);
211
        ~wizInputPage();
212
        void OnWizardPageChanging(wxWizardEvent& event);
213
        void OnInputChange( wxCommandEvent& event );
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
        void OnEnablePartial(wxCommandEvent& event);
        virtual wxWizardPage *GetPrev() const;
        virtual wxWizardPage *GetNext() const;
        void SetStreamingPage( wxWizardPage *page);
        void SetTranscodePage( wxWizardPage *page);
        void SetAction( int i_action );
        void SetPintf( intf_thread_t *p_intf );
        void SetUri( char *psz_uri );
        void SetPartial( int i_from, int i_to );

    protected:
        bool b_chosen;
        intf_thread_t *p_intf;
        int i_action;
        int i_input;

        void OnChoose( wxCommandEvent& event );

        WizardDialog *p_parent;
        wxRadioButton *input_radios[2];
        wxCheckBox *enable_checkbox;
        wxBoxSizer *mainSizer;
        wxArrayString mrl;
        wxTextCtrl *mrl_text;
        wxTextCtrl *from_text;
        wxTextCtrl *to_text;
        OpenDialog *p_open_dialog;
        wxListView *listview;
        wxPanel *open_panel;
243
        wxPanel *radio_panel; /* radio buttons should be in their own panel... */
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
        wxWizardPage *p_prev;
        wxWizardPage *p_streaming_page;
        wxWizardPage *p_transcode_page;

        DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(wizInputPage, wxWizardPage)
    EVT_RADIOBUTTON( InputRadio0_Event, wizInputPage::OnInputChange)
    EVT_RADIOBUTTON( InputRadio1_Event, wizInputPage::OnInputChange)
    EVT_BUTTON( Choose_Event, wizInputPage::OnChoose)
    EVT_CHECKBOX( PartialEnable_Event, wizInputPage::OnEnablePartial)
    EVT_WIZARD_PAGE_CHANGING(-1, wizInputPage::OnWizardPageChanging)
END_EVENT_TABLE()


class wizTranscodeCodecPage : public wxWizardPage
{
public:
    wizTranscodeCodecPage( wxWizard *parent, wxWizardPage *next);
    ~wizTranscodeCodecPage();
265
    void OnWizardPageChanging(wxWizardEvent& event);
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
    virtual wxWizardPage *GetPrev() const;
    virtual wxWizardPage *GetNext() const;
    void SetPrev( wxWizardPage *page);
protected:
    wxCheckBox *video_checkbox;
    wxComboBox *video_combo;
    wxComboBox *vb_combo;
    wxStaticText * video_text;
    wxCheckBox *audio_checkbox;
    wxComboBox *audio_combo;
    wxComboBox *ab_combo;
    wxStaticText * audio_text;

    WizardDialog *p_parent;
    int i_audio_codec;
    int i_video_codec;

    char *vcodec;
    char *acodec;

    wxWizardPage *p_prev;
    wxWizardPage *p_next;

    void OnVideoCodecChange(wxCommandEvent& event);
    void OnAudioCodecChange(wxCommandEvent& event);
    void OnEnableVideo(wxCommandEvent& event);
    void OnEnableAudio(wxCommandEvent& event);

    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(wizTranscodeCodecPage, wxWizardPage)
   EVT_CHECKBOX( VideoEnable_Event, wizTranscodeCodecPage::OnEnableVideo)
   EVT_CHECKBOX( AudioEnable_Event, wizTranscodeCodecPage::OnEnableAudio)
   EVT_COMBOBOX( VideoCodec_Event, wizTranscodeCodecPage::OnVideoCodecChange)
   EVT_COMBOBOX( AudioCodec_Event, wizTranscodeCodecPage::OnAudioCodecChange)
   EVT_WIZARD_PAGE_CHANGING(-1, wizTranscodeCodecPage::OnWizardPageChanging)
END_EVENT_TABLE()

class wizStreamingMethodPage : public wxWizardPage
{
public:
308 309
    wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
                            wxWizardPage *next) ;
310 311 312 313 314 315 316 317 318 319 320 321
    void OnWizardPageChanging(wxWizardEvent& event);
    virtual wxWizardPage *GetPrev() const;
    virtual wxWizardPage *GetNext() const;
    void SetPrev( wxWizardPage *page);
protected:
    DECLARE_EVENT_TABLE()
    int i_method;
    wxBoxSizer *mainSizer;
    wxStaticBoxSizer *address_sizer;
    wxStaticText *address_text;
    wxTextCtrl *address_txtctrl;
    WizardDialog * p_parent;
322
    void OnMethodChange( wxCommandEvent& event );
323 324 325
    wxRadioButton *method_radios[4];
    wxWizardPage *p_prev;
    wxWizardPage *p_next;
326
    intf_thread_t *p_intf;
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
};

BEGIN_EVENT_TABLE(wizStreamingMethodPage, wxWizardPage)
    EVT_RADIOBUTTON( MethodRadio0_Event, wizStreamingMethodPage::OnMethodChange)
    EVT_RADIOBUTTON( MethodRadio1_Event, wizStreamingMethodPage::OnMethodChange)
    EVT_RADIOBUTTON( MethodRadio2_Event, wizStreamingMethodPage::OnMethodChange)
    EVT_RADIOBUTTON( MethodRadio3_Event, wizStreamingMethodPage::OnMethodChange)
    EVT_WIZARD_PAGE_CHANGING(-1, wizStreamingMethodPage::OnWizardPageChanging)
END_EVENT_TABLE()


class wizEncapPage : public wxWizardPage
{
public:
    wizEncapPage( wxWizard *parent);
342
    ~wizEncapPage();
343 344 345 346 347 348 349 350 351 352 353 354 355
    void OnWizardPageChanging(wxWizardEvent& event);
    virtual wxWizardPage *GetPrev() const;
    virtual wxWizardPage *GetNext() const;
    void SetStreamingPage( wxWizardPage *page);
    void SetTranscodePage( wxWizardPage *page);
    void SetPrev( wxWizardPage *page);
    void SetAction( int );
    void EnableEncap( int encap );
protected:
    DECLARE_EVENT_TABLE()
    int i_encap;
    int i_mux;
    int i_action;
356
    void OnEncapChange( wxCommandEvent& event );
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
    wxRadioButton *encap_radios[MUXERS_NUMBER];
    WizardDialog *p_parent;
    wxWizardPage *p_prev;
    wxWizardPage *p_streaming_page;
    wxWizardPage *p_transcode_page;
};

BEGIN_EVENT_TABLE(wizEncapPage, wxWizardPage)
    EVT_WIZARD_PAGE_CHANGING(-1, wizEncapPage::OnWizardPageChanging)
    EVT_RADIOBUTTON( EncapRadio0_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio1_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio2_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio3_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio4_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio5_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio6_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio7_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio8_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio9_Event, wizEncapPage::OnEncapChange)
    EVT_RADIOBUTTON( EncapRadio10_Event, wizEncapPage::OnEncapChange)
END_EVENT_TABLE()

/* Additional settings for transcode */
class wizTranscodeExtraPage : public wxWizardPage
{
public:
    wizTranscodeExtraPage( wxWizard *parent, wxWizardPage *prev,
                            wxWizardPage *next);
    virtual wxWizardPage *GetPrev() const;
    virtual wxWizardPage *GetNext() const;
    void OnWizardPageChanging( wxWizardEvent& event );
protected:
    DECLARE_EVENT_TABLE()
390
    void OnSelectFile(wxCommandEvent&);
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
    wxTextCtrl *file_text;
    WizardDialog *p_parent;
    wxWizardPage *p_prev;
    wxWizardPage *p_next;
};

BEGIN_EVENT_TABLE(wizTranscodeExtraPage, wxWizardPage)
    EVT_BUTTON( Open_Event, wizTranscodeExtraPage::OnSelectFile)
    EVT_WIZARD_PAGE_CHANGING(-1, wizTranscodeExtraPage::OnWizardPageChanging)
END_EVENT_TABLE()

/* Additional settings for streaming */
class wizStreamingExtraPage : public wxWizardPage
{
public:
    wizStreamingExtraPage( wxWizard *parent, wxWizardPage *prev,
                            wxWizardPage *next);
    virtual wxWizardPage *GetPrev() const;
    virtual wxWizardPage *GetNext() const;
    void OnWizardPageChanging(wxWizardEvent&);
    void OnSAP( wxCommandEvent&);
    wxCheckBox *sap_checkbox;
    wxTextCtrl *sap_text;
protected:
    friend class wizEncapPage;
    DECLARE_EVENT_TABLE()
    WizardDialog *p_parent;
    wxWizardPage *p_prev;
    wxWizardPage *p_next;

    wxSpinCtrl *ttl_spin;
};

BEGIN_EVENT_TABLE(wizStreamingExtraPage, wxWizardPage)
    EVT_CHECKBOX( SAP_Event, wizStreamingExtraPage::OnSAP )
    EVT_WIZARD_PAGE_CHANGING(-1, wizStreamingExtraPage::OnWizardPageChanging)
END_EVENT_TABLE()


/* Local functions */
static void pageHeader( wxWindow *window, wxBoxSizer *sizer,
                       char *psz_title, char *psz_text);

static void pageHeader( wxWindow *window, wxBoxSizer *sizer,
                        char *psz_title, char *psz_text)
{
    wxStaticText *wtitle = new wxStaticText( window, -1, wxU( psz_title ) );
    wxFont font = wtitle->GetFont();
    font.SetPointSize(14);
    wtitle->SetFont(font);
    sizer->Add( wtitle, 0, wxALL, 5 );
    sizer->Add( new wxStaticText( window, -1,
443
                wxU( vlc_wraptext( psz_text , TEXTWIDTH ) ) ),
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
                        0, wxALL, 5 );
}

/***************************************************************************
 * Implementation of the pages
 ***************************************************************************/


/***************************************************
 * First page: choose between stream and transcode *
 ***************************************************/
wizHelloPage::wizHelloPage( wxWizard *parent) : wxWizardPageSimple(parent)
{
        i_action = 0;
        p_parent = (WizardDialog *)parent;
        wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);

        /* Create the texts */
        pageHeader( this, mainSizer, HELLO_TITLE, HELLO_TEXT );

        /* Create the radio buttons with their helps */
        action_radios[0] = new wxRadioButton( this, ActionRadio0_Event,
                                              wxU( HELLO_STREAMING ) );
        action_radios[1] = new wxRadioButton( this, ActionRadio1_Event,
                                              wxU( HELLO_TRANSCODE ) );
        i_action = 0;

        mainSizer->Add( 0, 0, 1 );

        wxBoxSizer *stream_sizer = new wxBoxSizer( wxHORIZONTAL );
        stream_sizer->Add( action_radios[0], 0, wxALL, 5 );
        stream_sizer->Add( 0,0,1 );
        stream_sizer->Add( new wxButton( this, MoreInfoStreaming_Event,
                                wxU( _("More Info")) ), 0, 0, 0 );
        mainSizer->Add( stream_sizer, 0, wxALL | wxEXPAND , 5 );

        wxBoxSizer *transcode_sizer = new wxBoxSizer( wxHORIZONTAL );
        transcode_sizer->Add( action_radios[1], 0, wxALL, 5 );
        transcode_sizer->Add( 0,0,1);
        transcode_sizer->Add( new wxButton( this, MoreInfoTranscode_Event,
                                wxU( _("More Info")) ), 0 ,  0 , 0 );
        mainSizer->Add( transcode_sizer, 0, wxALL | wxEXPAND, 5 );

        mainSizer->Add( 0, 0, 1 );

        mainSizer->Add( new wxStaticLine(this, -1 ), 0, wxEXPAND| wxTOP|
                        wxBOTTOM, 5 );

        mainSizer->Add( new wxStaticText(this, -1,
493
                        wxU( vlc_wraptext(HELLO_NOTICE , TEXTWIDTH ))),
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
                        0, wxALL, 5 );

        SetSizer(mainSizer);
        mainSizer->Fit(this);
    }

void wizHelloPage::OnMoreInfo(wxCommandEvent& event)
{
    wxString msg;
    msg.Printf( wxString( wxU( event.GetId() == MoreInfoStreaming_Event ?
                                    MOREINFO_STREAM :
                                    MOREINFO_TRANSCODE ) ) );
    wxMessageBox( msg, wxU(_("More information")),
                  wxOK | wxICON_INFORMATION, this->p_parent );
}

510
void wizHelloPage::OnActionChange( wxCommandEvent& event )
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
{
    i_action = event.GetId() - ActionRadio0_Event;
    ((wizInputPage *)GetNext())->SetAction( i_action );
    p_parent->SetAction( i_action );
}

void wizHelloPage::OnWizardPageChanging(wxWizardEvent& event)
{
    ((wizInputPage *)GetNext())->SetAction( i_action );
    p_parent->SetAction( i_action );
}

/************************************
 * Second page: choose input stream *
 ************************************/
wizInputPage::wizInputPage( wxWizard *parent, wxWizardPage *prev, intf_thread_t *_p_intf) :
              wxWizardPage(parent)
{
    p_prev = prev;
    p_intf = _p_intf;
    p_parent = (WizardDialog *)parent;
    b_chosen = false;
    p_open_dialog = NULL;
534 535
    listview = NULL;
    mrl_text = NULL;
536 537 538 539 540 541 542
    mainSizer = new wxBoxSizer(wxVERTICAL);

    /* Create the texts */
    pageHeader( this, mainSizer, INPUT_TITLE, INPUT_TEXT );

    mainSizer->Add( 0,20,0 );

543 544 545 546 547
    radio_panel = new wxPanel(this, -1);
    radio_panel->SetAutoLayout( TRUE );

    wxBoxSizer *radioSizer = new wxBoxSizer(wxVERTICAL);

548
    /* Create the radio buttons */
549
    input_radios[0] = new wxRadioButton( radio_panel, InputRadio0_Event ,
550
                               wxU( INPUT_OPEN ) );
551 552
    radioSizer->Add( input_radios[0], 0, wxALL, 5 );
    input_radios[1] = new wxRadioButton( radio_panel, InputRadio1_Event ,
553
                               wxU( INPUT_PL ) );
554 555 556 557 558 559 560
    radioSizer->Add( input_radios[1], 0, wxALL, 5 );

    radio_panel->SetSizer( radioSizer );
    radioSizer->Layout();
    radioSizer->Fit(radio_panel);
    mainSizer->Add( radio_panel );

561 562 563 564 565
    i_input = 0;

    /* Open Panel */
    open_panel = new wxPanel(this, -1);
    open_panel->SetAutoLayout( TRUE );
566

567 568 569 570
    wxBoxSizer *openSizer = new wxBoxSizer(wxHORIZONTAL);

    mrl_text = new wxTextCtrl( open_panel, -1, wxU( "" ), wxDefaultPosition,
                              wxSize(200,25) );
571

572 573
    openSizer->Add( mrl_text, 0 , wxALL, 5 );
    openSizer->Add( new wxButton( open_panel, Choose_Event, wxU(_("Choose...")) ), 0, wxALL, 5 );
574

575 576 577 578 579
    open_panel->SetSizer( openSizer );
    openSizer->Layout();
    openSizer->Fit(open_panel);
    mainSizer->Add( open_panel );

Antoine Cellerier's avatar
Antoine Cellerier committed
580
    playlist_t *p_playlist = pl_Hold( p_intf );
581 582
    if( p_playlist )
    {
583
        if( !playlist_IsEmpty( p_playlist ) )
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
        {
            listview = new wxListView( this, ListView_Event,
                                       wxDefaultPosition, wxDefaultSize,
                                       wxLC_REPORT | wxSUNKEN_BORDER );
            listview->InsertColumn( 0, wxU(_("Name")) );
            listview->InsertColumn( 1, wxU(_("URI")) );
            listview->SetColumnWidth( 0, 250 );
            listview->SetColumnWidth( 1, 100 );
            mainSizer->Add( listview, 1, wxALL|wxEXPAND, 5 );

            listview->Hide();
            mainSizer->Hide( listview );
            mainSizer->Layout();
        }
        else
        {
            input_radios[1]->Disable();
        }
602
        pl_Release( p_intf );
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
    }
    else
    {
        input_radios[1]->Disable();
    }

    /* Partial Extract Box */
    mainSizer->Add( 0, 10, 0 );
    wxStaticBox *partial_box = new wxStaticBox( this, -1,
                    wxU(_("Partial Extract")) );

    wxStaticBoxSizer *partial_sizer = new wxStaticBoxSizer( partial_box,
                                                          wxVERTICAL );

    enable_checkbox = new wxCheckBox( this, PartialEnable_Event,
                                                wxU(_("Enable") ) );
    enable_checkbox->SetToolTip(wxU(_(PARTIAL) ) ) ;
    partial_sizer->Add( enable_checkbox, 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 ); //wxLEFT

    wxFlexGridSizer *partial_sizer2 = new wxFlexGridSizer( 4 , 1 , 20 );
    partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "From" ) ) ),
                         0 , wxLEFT , 5 );
    from_text = new wxTextCtrl( this, -1, wxT(""),
                                wxDefaultPosition, wxSize( 80,25 ) );
    partial_sizer2->Add( from_text, 0 , wxALIGN_RIGHT);
    partial_sizer2->Add( new wxStaticText(this, -1, wxU(_( "To" ) ) ),
                         0 , wxLEFT , 5 );
    to_text = new wxTextCtrl( this, -1, wxT(""),
                                  wxDefaultPosition, wxSize( 80 , 25 ) );
    partial_sizer2->Add( to_text, 0 , wxALIGN_RIGHT );

    partial_sizer->Add( partial_sizer2, 0, wxALL, 0 );

    partial_sizer->Fit( partial_box );

    mainSizer->Add( partial_sizer, 0, 0, 0 );

    from_text->Disable();
    to_text->Disable();
    SetSizer(mainSizer);
    mainSizer->Fit(this);
    mainSizer->Layout();
}

wizInputPage::~wizInputPage()
{
}

651
void wizInputPage::OnInputChange( wxCommandEvent& event )
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
{
    i_input = event.GetId() - InputRadio0_Event;
    if( i_input == 0 )
    {
        if( listview )
        {
            listview->Hide();
            mainSizer->Hide( listview );
            open_panel->Show();
            mainSizer->Show( open_panel );
            mainSizer->Layout();
        }
    }
    else
    {
        open_panel->Hide();
        mainSizer->Hide( open_panel );
        listview->Show();
        mainSizer->Show( listview );
        mainSizer->Layout();
    }
}

void wizInputPage::OnEnablePartial(wxCommandEvent& event)
{
   from_text->Enable( event.IsChecked() );
   to_text->Enable( event.IsChecked() );
}


void wizInputPage::OnChoose(wxCommandEvent& event)
{
    p_open_dialog = new OpenDialog( p_intf, this, -1, -1, OPEN_STREAM );
    if(  p_open_dialog->ShowModal() == wxID_OK &&
         !p_open_dialog->mrl.IsEmpty() )
    {
        mrl_text->SetValue(p_open_dialog->mrl[0] );
    }
    delete p_open_dialog;
    p_open_dialog = NULL;
}

void wizInputPage::OnWizardPageChanging(wxWizardEvent& event)
{
    if( i_input == 0)
    {
        if( mrl_text->GetValue().IsSameAs( wxT(""), TRUE ) &&
                        event.GetDirection() )
        {
            wxMessageBox( wxU( CHOOSE_STREAM ), wxU( ERROR_MSG ),
                          wxICON_WARNING | wxOK, this->p_parent );
            event.Veto();
            return;
        }
        else
        {
708
            p_parent->SetMrl( (const char *)mrl_text->GetValue().mb_str(wxConvUTF8) );
709 710 711 712 713 714 715 716
        }
    }
    else
    {
        int i = -1;
        i = listview->GetNextItem( i , wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if( i != -1 )
        {
717
            long data = listview->GetItemData( i );
Antoine Cellerier's avatar
Antoine Cellerier committed
718
            playlist_t *p_playlist = pl_Hold( p_intf );
719 720
            if( p_playlist )
            {
721
                playlist_item_t * p_item = playlist_ItemGetById( p_playlist, (int)data, false );
722 723
                if( p_item )
                {
724 725 726
                    const char *psz_uri = input_item_GetURI( p_item->p_input );
                    p_parent->SetMrl( psz_uri );
                    free( psz_uri );
727 728 729
                }
                else
                    event.Veto();
730
                pl_Release( p_intf );
731 732 733
            }
            else
                event.Veto();
734 735 736 737
        }
    }
    if( enable_checkbox->IsChecked() )
    {
738 739
        int i_from = atoi( from_text->GetValue().mb_str(wxConvUTF8) );
        int i_to = atoi( to_text->GetValue().mb_str(wxConvUTF8) );
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
        p_parent->SetPartial( i_from, i_to );
    }
    return;
}

wxWizardPage *wizInputPage::GetPrev() const { return p_prev; }
wxWizardPage *wizInputPage::GetNext() const
{
    if( i_action == ACTION_STREAM )
        return p_streaming_page;
    else
       return p_transcode_page;
}

void wizInputPage::SetStreamingPage( wxWizardPage *page)
{
    p_streaming_page = page;
}

void wizInputPage::SetTranscodePage( wxWizardPage *page)
{
    p_transcode_page = page;
}

void wizInputPage::SetAction( int i_action )
{
    this->i_action = i_action;
}

void wizInputPage::SetPintf( intf_thread_t *p_intf )
{
    this->p_intf = p_intf;
}

void wizInputPage::SetUri( char *psz_uri )
{
    mrl_text->SetValue( wxU( psz_uri ) );
}

void wizInputPage::SetPartial( int i_from, int i_to )
{
   wxString msg;
   msg.Printf( wxString( wxT( "%i") ), i_from );
   from_text->Enable( TRUE );
   from_text->SetValue( msg );
   msg.Printf( wxString( wxT( "%i") ), i_to );
   to_text->Enable( TRUE );
   to_text->SetValue( msg );
   enable_checkbox->SetValue( TRUE );
}

/***************************************************
 * First transcode page: choose codecs             *
 ***************************************************/
wizTranscodeCodecPage::wizTranscodeCodecPage( wxWizard *parent,
                       wxWizardPage *next) : wxWizardPage(parent)
{
797 798
    int i;

799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
    p_next = next;

    acodec = NULL;
    vcodec = NULL;
    p_parent = (WizardDialog *) parent;

    wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);

    /* Header */
    pageHeader( this, main_sizer,  TRANSCODE1_TITLE, TRANSCODE1_TEXT );

    /* Video Box */
    wxStaticBox *video_box = new wxStaticBox( this, -1, wxU(_("Video")) );
    wxStaticBoxSizer *video_sizer = new wxStaticBoxSizer( video_box,
                                                          wxVERTICAL );
    /* Line 1 : only the checkbox */
    wxFlexGridSizer *video_sizer1 = new wxFlexGridSizer( 2,3,20 );
    video_sizer1->Add( new wxCheckBox( this, VideoEnable_Event,
                       wxU(_("Transcode video") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL , 5 );
    video_sizer1->Add( 0,0,1);
    /* Line 2 : codec */
    video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT ,5);
    video_combo = new wxComboBox( this, VideoCodec_Event, wxT(""),
822
                                  wxDefaultPosition, wxSize(200,25), 0, NULL,
823
                                  wxCB_DROPDOWN| wxCB_READONLY );
824
    for( i= 0; vcodecs_array[i].psz_display != NULL; i++ )
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
    {
        video_combo->Append( wxU( vcodecs_array[i].psz_display ) ,
                            (void *)&vcodecs_array[i] );
    }
    i_video_codec = 0;
    video_combo->SetSelection(0);

    video_sizer1->Add( video_combo, 0 , wxALIGN_LEFT , 0 );

    video_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
                       wxLEFT ,5);
    vb_combo = new wxComboBox( this, VideoBitrate_Event, wxT("1024"),
                               wxDefaultPosition, wxDefaultSize,
                               WXSIZEOF(vbitrates_array), vbitrates_array, wxCB_READONLY );
    video_sizer1->Add( vb_combo, 0, wxALIGN_LEFT , 0 );

    /* Line 3 : text */
    video_text = new wxStaticText( this, -1,
843
                     wxU( vlc_wraptext( TR_VIDEO_TEXT, TEXTWIDTH ) ) );
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
    /* Fill the main video sizer */
    video_sizer->Add( video_sizer1 , 0, wxEXPAND , 5 );
    video_sizer->Add( video_text, 0, wxLEFT|wxTOP , 5 );


    /* Audio box */
    wxStaticBox *audio_box = new wxStaticBox( this, -1, wxU(_("Audio")) );
    wxStaticBoxSizer *audio_sizer = new wxStaticBoxSizer( audio_box,
                                                          wxVERTICAL );
    /* Line1: enabler */
    wxFlexGridSizer *audio_sizer1 = new wxFlexGridSizer( 2,3,20);
    audio_sizer1->Add( new wxCheckBox( this, AudioEnable_Event,
                            wxU(_("Transcode audio") ) ), 0 , wxALIGN_CENTER_VERTICAL|wxALL, 5 );
    audio_sizer1->Add( 0, 0, 1 );

    /* Line 2 : codec */
    audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Codec"))),0,wxLEFT,5);
    audio_combo = new wxComboBox( this, AudioCodec_Event, wxT(""),
862
                                  wxDefaultPosition, wxSize(200,25), 0, NULL,
863
                                  wxCB_DROPDOWN| wxCB_READONLY );
864
    for( i= 0; acodecs_array[i].psz_display != NULL; i++ )
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
    {
        audio_combo->Append( wxU( acodecs_array[i].psz_display ) ,
                            (void *)&acodecs_array[i] );
    }
    i_audio_codec = 0;
    audio_combo->SetSelection(0);
    audio_sizer1->Add( audio_combo, 0 , wxALIGN_LEFT, 0 );

    audio_sizer1->Add( new wxStaticText(this, -1, wxU(_("Bitrate (kb/s)"))),0,
                       wxLEFT ,5);
    ab_combo = new wxComboBox( this, AudioBitrate_Event, wxT("192"),
                               wxDefaultPosition, wxDefaultSize,
                               WXSIZEOF(abitrates_array), abitrates_array, wxCB_READONLY );
    audio_sizer1->Add( ab_combo, 0, wxALIGN_LEFT, 0 );

    /* Line 3 : text */
    audio_text = new wxStaticText( this, -1,
882
                     wxU( vlc_wraptext( TR_AUDIO_TEXT, TEXTWIDTH ) ) );
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899

    audio_sizer->Add(audio_sizer1, 0, wxEXPAND, 5);
    audio_sizer->Add( audio_text, 0, wxLEFT | wxTOP, 5 );

    main_sizer->Add( video_sizer, 1, wxGROW, 0 );
    main_sizer->Add( audio_sizer, 1, wxGROW, 0 );
    main_sizer->Layout();
    SetSizerAndFit( main_sizer );

    /* Default disabled */
    video_combo->Disable(); video_text->Disable();vb_combo->Disable();
    audio_combo->Disable(); audio_text->Disable();ab_combo->Disable();

}

wizTranscodeCodecPage::~wizTranscodeCodecPage()
{
900 901
    free( acodec );
    free( vcodec );
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
}

void wizTranscodeCodecPage::OnEnableVideo(wxCommandEvent& event)
{
   video_combo->Enable( event.IsChecked() );
   vb_combo->Enable( event.IsChecked() );
   video_text->Enable( event.IsChecked() );
}

void wizTranscodeCodecPage::OnEnableAudio(wxCommandEvent& event)
{
   audio_combo->Enable( event.IsChecked() );
   ab_combo->Enable( event.IsChecked() );
   audio_text->Enable( event.IsChecked() );
}

void wizTranscodeCodecPage::OnVideoCodecChange(wxCommandEvent& event)
{
    struct codec *c = (struct codec*)
             (video_combo->GetClientData(video_combo->GetSelection()));
922
    video_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH ) ) );
923 924 925 926 927 928 929 930
    i_video_codec = video_combo->GetSelection();
    vcodec = strdup(c->psz_codec);
}

void wizTranscodeCodecPage::OnAudioCodecChange(wxCommandEvent& event)
{
    struct codec *c = (struct codec*)
             (audio_combo->GetClientData(audio_combo->GetSelection()));
931
    audio_text->SetLabel( wxU( vlc_wraptext(c->psz_descr, TEXTWIDTH ) ) );
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
    i_audio_codec = audio_combo->GetSelection();
    acodec = strdup(c->psz_codec);

}

void wizTranscodeCodecPage::OnWizardPageChanging(wxWizardEvent& event)
{
    unsigned int i,j;

    if( !event.GetDirection() )
    {
            GetPrev()->Enable();
            return;
    }

    /* Set the dummy codec ( accept all muxers ) if needed */
    if( !video_combo->IsEnabled() )
    {
        i_video_codec = VCODECS_NUMBER;
    }
    if( !audio_combo->IsEnabled() )
    {
        i_audio_codec = ACODECS_NUMBER;
    }

    ((wizEncapPage *)GetNext())->SetPrev(this);

    for( i = 0 ; i< MUXERS_NUMBER ; i++ )
    {
        if( vcodecs_array[i_video_codec].muxers[i] != -1 )
        {
            for( j = 0 ; j<  MUXERS_NUMBER ; j++ )
            {
                if( acodecs_array[i_audio_codec].muxers[j] ==
                              vcodecs_array[i_video_codec].muxers[i] )
                {
                    ((wizEncapPage*)GetNext())->EnableEncap(
                               vcodecs_array[i_video_codec].muxers[i] );
                }
            }
        }
    }
    struct codec *c = (struct codec*)
             (video_combo->GetClientData( video_combo->IsEnabled() ?
                                          video_combo->GetSelection(): i_video_codec ));
    vcodec = strdup(c->psz_codec);
    c = (struct codec*)
           (audio_combo->GetClientData( audio_combo->IsEnabled() ?
                                       audio_combo->GetSelection() : i_audio_codec ));
    acodec = strdup(c->psz_codec);

983
    int vb = atoi(vb_combo->GetValue().mb_str(wxConvUTF8) );
984 985 986 987
    if( vb == 0 )
    {
         vb = 1024;
    }
988
    int ab = atoi(ab_combo->GetValue().mb_str(wxConvUTF8) );
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
    if( ab == 0)
    {
        ab = 192;
    }

    p_parent->SetTranscode( vcodec, vb , acodec, ab );
    ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
    p_parent->SetAction( p_parent->GetAction() );

    return;
}

wxWizardPage *wizTranscodeCodecPage::GetPrev() const { return p_prev; }
wxWizardPage *wizTranscodeCodecPage::GetNext() const { return p_next; }
void wizTranscodeCodecPage::SetPrev( wxWizardPage *page) {p_prev = page; }


/***************************************************
 * First streaming page: choose method             *
 ***************************************************/
1009 1010
wizStreamingMethodPage::wizStreamingMethodPage( intf_thread_t *p_this, wxWizard *parent,
    wxWizardPage *next) : wxWizardPage(parent), p_intf( p_this )
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
{
    int i;
    p_next = next;
    p_parent = (WizardDialog *)parent;

    mainSizer = new wxBoxSizer(wxVERTICAL);

    /* Create the texts */
    pageHeader( this, mainSizer,  STREAMING1_TITLE, STREAMING1_TEXT );

    mainSizer->Add( 0,50,0 );

    i_method = 0;

    wxStaticBox *method_box = new wxStaticBox( this, -1,
                                               wxU(_("Streaming method")) );
    wxStaticBoxSizer *method_sizer = new wxStaticBoxSizer(method_box,
                                                          wxHORIZONTAL );
    for( i = 0 ; i< 3 ; i++ )
    {
        method_radios[i] = new wxRadioButton( this, MethodRadio0_Event + i,
                               wxU( methods_array[i].psz_method ) );
        method_radios[i]->SetToolTip( wxU(_( methods_array[i].psz_descr ) ) );
        method_sizer->Add( method_radios[i], 0, wxALL, 5 );
    }

    method_sizer->Layout();

    wxStaticBox *address_box = new wxStaticBox( this, -1,
                    wxU(_("Destination")) );

    address_sizer = new wxStaticBoxSizer(address_box,
                                         wxVERTICAL );

    /* Big kludge, we take the longest text to get the size */
    address_text = new wxStaticText(this, -1,
1047
               wxU( vlc_wraptext(methods_array[2].psz_address, TEXTWIDTH ) ),
1048 1049
               wxDefaultPosition, wxDefaultSize );

1050 1051
    address_txtctrl = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
                                      wxSize(200,25));
1052 1053 1054 1055 1056 1057 1058
    address_sizer->Add( address_text, 0, wxALL, 5 );
    address_sizer->Add( address_txtctrl, 0, wxALL, 5 );
    address_sizer->Layout();

    /* Set the minimum size */
    address_sizer->SetMinSize( address_sizer->GetSize() );
    address_text->SetLabel( wxU(
1059
     vlc_wraptext( _(methods_array[0].psz_address), TEXTWIDTH )));
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079

    mainSizer->Add( method_sizer, 0, wxALL | wxEXPAND, 5 );
    mainSizer->Add( address_sizer, 0, wxALL | wxEXPAND, 5 );

    mainSizer->Add( 0,0,1 );

    mainSizer->Layout();

    SetSizer(mainSizer);
    mainSizer->Fit(this);

    return;
}

void wizStreamingMethodPage::OnWizardPageChanging(wxWizardEvent& event)
{
    unsigned int i;
    if( !event.GetDirection() ) return;

    /* Check valid address */
1080
    if( i_method == 0 && address_txtctrl->GetValue().IsEmpty() )
1081
    {
1082
        wxMessageBox( wxU( NO_ADDRESS_TEXT ) , wxU( ERROR_MSG ),
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
                      wxICON_WARNING | wxOK, this->p_parent );
        event.Veto();

    }

    ((wizEncapPage *)GetNext())->SetPrev(this);
    for( i = 0 ; i< MUXERS_NUMBER ; i++ )
    {
        if( methods_array[i_method].muxers[i] != -1 )
        {
            ((wizEncapPage*)GetNext())->EnableEncap(
                               methods_array[i_method].muxers[i] );
        }
    }
    p_parent->SetStream( methods_array[i_method].psz_access ,
1098
                         address_txtctrl->GetValue().mb_str(wxConvUTF8) );
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110

    /* Set the action for the muxer page */
    ((wizEncapPage*)GetNext())->SetAction( p_parent->GetAction() );
    return;
}

wxWizardPage *wizStreamingMethodPage::GetPrev() const { return p_prev; }
wxWizardPage *wizStreamingMethodPage::GetNext() const { return p_next; }

void wizStreamingMethodPage::SetPrev( wxWizardPage *page) {p_prev = page; }


1111
void wizStreamingMethodPage::OnMethodChange( wxCommandEvent& event )
1112 1113 1114
{
    i_method = event.GetId() - MethodRadio0_Event;
    address_text->SetLabel( wxU(
1115
     vlc_wraptext( _(methods_array[i_method].psz_address), TEXTWIDTH )));
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
    address_sizer->Layout();
    mainSizer->Layout();
}

/***************************************************
 * Choose encapsulation format                     *
 ***************************************************/
wizEncapPage::wizEncapPage( wxWizard *parent ) : wxWizardPage(parent)
{
    int i;
    i_mux = 0;
    p_parent = (WizardDialog *)parent;
    p_streaming_page = NULL;
    p_transcode_page = NULL;
    p_prev = NULL;
    wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);

    /* Create the texts */
    pageHeader( this, mainSizer, ENCAP_TITLE, ENCAP_TEXT );

    mainSizer->Add( 0,0,1 );

    for( i = 0 ; i< MUXERS_NUMBER ; i++ )
    {
        encap_radios[i] = new wxRadioButton( this, EncapRadio0_Event + i,
                               wxU( encaps_array[i].psz_encap ) );
        encap_radios[i]->SetToolTip( wxU(_( encaps_array[i].psz_descr ) ) );
        mainSizer->Add( encap_radios[i], 0, wxLEFT, 5 );
        encap_radios[i]->Disable();
    }

    mainSizer->Add( 0,0,1 );

    SetSizer(mainSizer);
    mainSizer->Fit(this);
}

wizEncapPage::~wizEncapPage()
{
}

void wizEncapPage::OnWizardPageChanging(wxWizardEvent& event)
{
    int i;
    if( !event.GetDirection() )
    {
        for( i = 0 ; i< MUXERS_NUMBER ; i++ )
        {
            encap_radios[i]->Disable();
        }
    }
    p_parent->SetMux( encaps_array[i_mux].psz_mux );

    if( p_parent->GetAction() == ACTION_STREAM )
    {
1171
        if( strstr( p_parent->method, "rtp" ))
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
        {
            ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable();
            ((wizStreamingExtraPage *)GetNext())->sap_text->Enable(false);
        }
        else
        {
           ((wizStreamingExtraPage *)GetNext())->sap_checkbox->Enable( false );
           ((wizStreamingExtraPage *)GetNext())->sap_text->Enable( false );
        }
    }

    return;
}


1187
void wizEncapPage::OnEncapChange( wxCommandEvent& event )
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
{
    i_mux = event.GetId() - EncapRadio0_Event;
}

void wizEncapPage::EnableEncap( int encap )
{
    int i;
    for( i = 0 ; i< MUXERS_NUMBER ; i++)
    {
        if( encaps_array[i].id == encap )
        {
            encap_radios[i]->Enable();
            encap_radios[i]->SetValue(true);
            i_mux = i;
        }
    }
}

void wizEncapPage::SetStreamingPage( wxWizardPage *page)
{
    p_streaming_page = page;
}

void wizEncapPage::SetTranscodePage( wxWizardPage *page)
{
    p_transcode_page = page;
}

wxWizardPage *wizEncapPage::GetPrev() const { return p_prev; }

wxWizardPage *wizEncapPage::GetNext() const
{
    if( i_action== ACTION_STREAM )
        return p_streaming_page;
    else
       return p_transcode_page;
}

void wizEncapPage::SetAction( int i_act  ) { i_action = i_act; }

void wizEncapPage::SetPrev( wxWizardPage *page) { p_prev = page; }

/***************************************************
 * Extra transcoding page : Select file            *
 ***************************************************/
wizTranscodeExtraPage::wizTranscodeExtraPage( wxWizard *parent,
                       wxWizardPage *prev,
                       wxWizardPage *next) : wxWizardPage(parent)
{
    p_next = next;
    p_prev = prev;
    p_parent = (WizardDialog *) parent;
    wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);

    /* Create the texts */
    pageHeader( this, mainSizer, EXTRATRANSCODE_TITLE, EXTRATRANSCODE_TEXT );

    mainSizer->Add( 0, 0, 1 );

    wxFlexGridSizer *sizer = new wxFlexGridSizer( 2, 2, 1 );
    sizer->Add( new wxStaticText( this, -1,
                    wxU(_("Select the file to save to") ) ),
                    0, wxALL, 5 );
    sizer->Add( 0, 0, 1 );

    file_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
                                wxSize( 150, -1 ) );

    sizer->Add( file_text, 0,  wxALL, 5 );
    sizer->Add( new wxButton( this, Open_Event, wxU("Choose") ) );

    mainSizer->Add( sizer, 0, 0, 0) ;

    mainSizer->Add( 0, 0, 1 );
    SetSizer(mainSizer);
    mainSizer->Fit(this);
}

void wizTranscodeExtraPage::OnSelectFile( wxCommandEvent &event)
{
1268
    wxFileDialog *file_dialog =  new wxFileDialog( this, wxU(_("Save to file")),
1269 1270 1271 1272
                   wxT(""), wxT(""), wxT("*"), wxSAVE );

    if( file_dialog && file_dialog->ShowModal() == wxID_OK )
    {
1273
        if( file_dialog->GetFilename().mb_str(wxConvUTF8) )
1274
        {
1275
            file_text->SetValue( file_dialog->GetPath() );
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
        }
    }
}

void wizTranscodeExtraPage::OnWizardPageChanging( wxWizardEvent& event )
{
    if( event.GetDirection() && file_text->GetValue().IsEmpty() )
    {
        wxMessageBox( wxU( CHOOSE_OUTFILE ), wxU( ERROR_MSG ),
                      wxICON_WARNING | wxOK, this->p_parent );
        event.Veto();
    }
    if( event.GetDirection() )
    {
1290
       p_parent->SetTranscodeOut( file_text->GetValue() );
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
    }
}

wxWizardPage *wizTranscodeExtraPage::GetPrev() const { return p_prev; }
wxWizardPage *wizTranscodeExtraPage::GetNext() const {return p_next; }

/***********************************************************
 *  Extra streaming page
 ***********************************************************/
wizStreamingExtraPage::wizStreamingExtraPage( wxWizard *parent,
                       wxWizardPage *prev,
                       wxWizardPage *next) : wxWizardPage(parent)
{
    p_next = next;
    p_prev = prev;
    p_parent = (WizardDialog *) parent;
    wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);

    /* Create the texts */
    pageHeader( this, mainSizer, EXTRASTREAMING_TITLE, EXTRASTREAMING_TEXT );

    mainSizer->Add( 0, 0, 1 );

    wxFlexGridSizer *sizer = new wxFlexGridSizer( 2,2,1) ;

    /* TTL */
    sizer->Add( new wxStaticText( this, -1, wxU(_("Time-To-Live (TTL)"))),
                    0, wxALL,  5 );
    ttl_spin = new wxSpinCtrl( this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
                    0, 1, 255, 1 );
    ttl_spin->SetToolTip(wxU(_(TTL) ) ) ;
    sizer->Add( ttl_spin, 0, wxALL , 5 );

    /* SAP announce */
    sap_checkbox =  new wxCheckBox( this, SAP_Event, wxU(_("SAP Announce")) );
    sap_checkbox->SetToolTip( wxU(_( SAP ) ) );
    sizer->Add( sap_checkbox, 0, 0 , 0 );
    sap_text = new wxTextCtrl( this, -1, wxU(""), wxDefaultPosition,
                    wxSize(100,25) );
    sap_text->SetToolTip( wxU(_( SAP ) ) );
    sizer->Add( sap_text, 0, wxALL , 5 );

    mainSizer->Add(sizer, 0, wxALL, 5 );

    mainSizer->Add( 0, 0, 1 );

    SetSizer(mainSizer);
    mainSizer->Fit(this);
}

void wizStreamingExtraPage::OnSAP( wxCommandEvent &event )
{
    sap_text->Enable( event.IsChecked() );
}

void wizStreamingExtraPage::OnWizardPageChanging(wxWizardEvent& event)
{
    if( sap_checkbox->IsChecked() )
    {
        if( sap_text->GetValue().IsEmpty() )
        {
            p_parent->SetSAP( true, NULL );
        }
        else
        {
            p_parent->SetSAP( true,
1357
                             (const char *)sap_text->GetValue().mb_str(wxConvUTF8) );
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
        }
    }
    else
    {
        p_parent->SetSAP( false, NULL );
    }

    p_parent->SetTTL( ttl_spin->GetValue() );
}

wxWizardPage *wizStreamingExtraPage::GetPrev() const { return p_prev; }
wxWizardPage *wizStreamingExtraPage::GetNext() const {return p_next; }


/***************************************************************************
 * Implementation of the wizard itself
 ***************************************************************************/
wizHelloPage *page1;
wizInputPage *page2 ;
wizTranscodeCodecPage *tr_page1 ;
wizStreamingMethodPage *st_page1;
wizTranscodeExtraPage *tr_page2 ;
wizStreamingExtraPage *st_page2;
wizEncapPage *encap_page;

WizardDialog::WizardDialog(intf_thread_t *_p_intf, wxWindow *_p_parent,
                           char *psz_uri, int _i_from, int _i_to  ) :
wxWizard( _p_parent, -1, wxU(_("Streaming/Transcoding Wizard")), wxNullBitmap, wxDefaultPosition)
{
    /* Initializations */
    p_intf = _p_intf;
    SetPageSize(wxSize(400,420));

    /* Initialize structure */
    i_action = 0;
    i_from = _i_from;
    i_to = _i_to;
    i_ttl = 1;
    vb = 0;
    ab = 0;
    acodec=NULL;
    vcodec=NULL;

    page1 = new wizHelloPage(this);
    page2 = new wizInputPage(this, page1, p_intf);

    if( psz_uri )
    {
        page2->SetUri( psz_uri );
    }
    if( i_from != 0 || i_to != 0 )
    {
        page2->SetPartial( i_from, i_to );
    }

    encap_page = new wizEncapPage(this );
    tr_page1 = new wizTranscodeCodecPage(this, encap_page );
1415
    st_page1 = new wizStreamingMethodPage( p_intf, this, encap_page);
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481

    tr_page2 = new wizTranscodeExtraPage(this, encap_page, NULL );
    st_page2 = new wizStreamingExtraPage(this, encap_page, NULL );

    /* Page 1 -> 2 */
    page1->SetNext( page2 );
    /* 2->1 in constructor of 2 */

    /* Page 2 -> 3 */
    page2->SetTranscodePage(tr_page1);
    page2->SetStreamingPage(st_page1);
    page2->SetPintf( p_intf );
    tr_page1->SetPrev(page2);
    st_page1->SetPrev(page2);

    /* Page 3 -> 4 */
    encap_page->SetTranscodePage( tr_page2 );
    encap_page->SetStreamingPage( st_page2 );
    /* 3->4 in constructor of 3 */
//    encap_page->SetPrev(tr_page1);
}

WizardDialog::~WizardDialog()
{
    Destroy();
    delete page1;
    delete page2;
    delete tr_page1;
    delete st_page1 ;
    delete st_page2;
    delete tr_page2;
    delete encap_page;
}

void WizardDialog::SetMrl( const char *mrl )
{
    this->mrl = strdup( mrl );
}

void WizardDialog::SetTTL( int i_ttl )
{
    this->i_ttl = i_ttl;
}

void WizardDialog::SetSAP( bool b_enabled, const char *psz_text )
{
    this->b_sap = b_enabled;
    if( b_enabled )
    {
        if( psz_text != NULL )
        {
            this->psz_sap_name = strdup( psz_text );
        }
        else
        {
            this->psz_sap_name = NULL;
        }
    }
}

void WizardDialog::SetPartial( int i_from, int i_to )
{
    this->i_from = i_from;
    this->i_to = i_to;
}

1482 1483
void WizardDialog::SetTranscode( char const *vcodec, int vb,
                                 char const *acodec, int ab)
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
{
    if( strcmp( vcodec, "dummy") )
    {
        this->vcodec= strdup(vcodec);
    }
    if( strcmp( acodec, "dummy" ) )
    {
        this->acodec = strdup(acodec);
    }
    this->vb = vb;
    this->ab = ab;
}

1497
void WizardDialog::SetStream( char const *method, char const *address )
1498 1499 1500 1501 1502
{
    this->method = strdup( method );
    this->address = strdup( address );
}

1503
void WizardDialog::SetTranscodeOut( wxString address )
1504
{
1505
    char *psz_utf8 = wxFromLocale( address );
1506
    this->address = strdup( psz_utf8 );
1507
    wxLocaleFree( psz_utf8 );
1508 1509
}

1510
void WizardDialog::SetMux( char const *mux )
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532
{
    this->mux = strdup( mux );
}

void WizardDialog::SetAction( int i_action )
{
    this->i_action = i_action;
}

int WizardDialog::GetAction()
{
    return i_action;
}

void WizardDialog::Run()
{
    if( RunWizard(page1) )
    {
        char *psz_opt;

        if( i_action == ACTION_TRANSCODE )
        {
1533
            msg_Dbg( p_intf,"starting transcode of %s to file %s",
1534
                                  mrl, address);
1535
            msg_Dbg( p_intf,"using %s (%i kbps) / %s (%i kbps),encap %s",
1536
                                vcodec,vb,acodec,ab,mux);
1537
            char *psz_transcode;
Clément Stenac's avatar
Clément Stenac committed
1538

1539
            if( vcodec != NULL || acodec != NULL )
1540
            {
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
                int i_tr_size = 14;
                if( vcodec != NULL )
                    i_tr_size += strlen( vcodec ) + 17;
                if( acodec != NULL )
                    i_tr_size += strlen( acodec ) + 17;

                if( vb > 999999 )
                    vb = 999999;
                else if( vb < 0 )
                    vb = 0;

                if( ab > 999999 )
                    ab = 999999;
                else if( ab < 0 )
                    ab = 0;

1557
                psz_transcode = (char *)malloc( i_tr_size );
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570

                strcpy( psz_transcode, "transcode{" );
                if( vcodec != NULL )
                {
                    sprintf( psz_transcode + strlen( psz_transcode ),
                             "vcodec=%s,vb=%i%s", vcodec, vb,
                             ( acodec != NULL ) ? "," : "}:" );
                }
                if( acodec != NULL )
                {
                    sprintf( psz_transcode + strlen( psz_transcode ),
                             "acodec=%s,ab=%i}:", acodec, ab );
                }
1571 1572
            }
            else
1573 1574
                psz_transcode = "";

1575
            asprintf( &psz_opt, ":sout=#%sstandard{mux=%s,dst=%s,"
1576 1577 1578 1579
                      "access=file}", psz_transcode, mux, address );

            if( *psz_transcode )
                free( psz_transcode );
1580 1581 1582
        }
        else
        {
1583 1584 1585
            char *psz_sap_option = NULL;
            bool v6;

1586
            msg_Dbg( p_intf, "starting stream of %s to %s using %s, encap %s",
1587
                               mrl, address, method, mux );
1588 1589 1590 1591
            if( b_sap )
            {
                if( psz_sap_name )
                {
1592 1593
                    asprintf( &psz_sap_option,
                              ",sap,name=\"%s\"", psz_sap_name );
1594 1595
                }
                else
1596 1597
                    psz_sap_option = strdup( ",sap" );