wizard.cpp

来自「uclinux 下的vlc播放器源代码」· C++ 代码 · 共 1,664 行 · 第 1/4 页

CPP
1,664
字号
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){    wxFileDialog *file_dialog =  new wxFileDialog( this, wxU(_("Save to file")),                   wxT(""), wxT(""), wxT("*"), wxSAVE );    if( file_dialog && file_dialog->ShowModal() == wxID_OK )    {        if( file_dialog->GetFilename().mb_str(wxConvUTF8) )        {            file_text->SetValue( file_dialog->GetPath() );        }    }}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() )    {       p_parent->SetTranscodeOut( file_text->GetValue() );    }}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,                  (const char *)sap_text->GetValue().mb_str(wxConvUTF8) );        }    }    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 );    st_page1 = new wizStreamingMethodPage( p_intf, this, encap_page);    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;}void WizardDialog::SetTranscode( char const *vcodec, int vb,                                 char const *acodec, int ab){    if( strcmp( vcodec, "dummy") )    {        this->vcodec= strdup(vcodec);    }    if( strcmp( acodec, "dummy" ) )    {        this->acodec = strdup(acodec);    }    this->vb = vb;    this->ab = ab;}void WizardDialog::SetStream( char const *method, char const *address ){    this->method = strdup( method );    this->address = strdup( address );}void WizardDialog::SetTranscodeOut( wxString address ){    char *psz_utf8 = wxFromLocale( address );    this->address = strdup( psz_utf8 );    wxLocaleFree( psz_utf8 );}void WizardDialog::SetMux( char const *mux ){    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 )        {            msg_Dbg( p_intf,"starting transcode of %s to file %s",                                  mrl, address);            msg_Dbg( p_intf,"using %s (%i kbps) / %s (%i kbps),encap %s",                                vcodec,vb,acodec,ab,mux);            char *psz_transcode;            if( vcodec != NULL || acodec != NULL )            {                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;                psz_transcode = (char *)malloc( i_tr_size * sizeof(char) );                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 );                }            }            else                psz_transcode = "";            asprintf( &psz_opt, ":sout=#%sstandard{mux=%s,dst=%s,"                      "access=file}", psz_transcode, mux, address );            if( *psz_transcode )                free( psz_transcode );        }        else        {            char *psz_sap_option = NULL;            bool v6;            msg_Dbg( p_intf, "starting stream of %s to %s using %s, encap %s",                               mrl, address, method, mux );            if( b_sap )            {                if( psz_sap_name )                {                    asprintf( &psz_sap_option,                              ",sap,name=\"%s\"", psz_sap_name );                }                else                    psz_sap_option = strdup( ",sap" );            }            /* Add brackets automatically for IPv6 if they are missing */            v6 = ( address[0] != '[' ) && ( strchr( address, ':' ) != NULL );            asprintf( &psz_opt,                      ":sout=#standard{mux=%s,dst=%s%s%s,access=%s%s}",                      mux, v6 ? "[" : "", address, v6 ? "]" : "", method,                      psz_sap_option ?: "" );            if( psz_sap_option ) free( psz_sap_option );        }        playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,                            VLC_OBJECT_PLAYLIST, FIND_ANYWHERE);        if( p_playlist )        {            playlist_item_t *p_item = playlist_ItemNew( p_playlist, mrl,                                                        ITEM_NAME );            playlist_ItemAddOption( p_item, psz_opt);            if( i_from != 0)            {                char psz_from[20];                snprintf( psz_from, 20, "start-time=%i", i_from);                playlist_ItemAddOption( p_item, psz_from);            }            if( i_to != 0)            {                char psz_to[20];                snprintf( psz_to, 20, "stop-time=%i", i_to);                playlist_ItemAddOption( p_item, psz_to);            }            char psz_ttl[20];            snprintf( psz_ttl, 20, "ttl=%i",i_ttl );            playlist_ItemAddOption( p_item, psz_ttl );            playlist_AddItem( p_playlist, p_item, PLAYLIST_GO, PLAYLIST_END );            vlc_object_release(p_playlist);        }        else        {            wxMessageBox( wxU( NO_PLAYLIST ), wxU( ERROR_MSG ),                          wxICON_WARNING | wxOK, this );        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?