Changeset f90b88ab5852ddaf8f3a11d67df0370c8641fb70

Show
Ignore:
Timestamp:
02/25/08 10:22:32 (4 months ago)
Author:
Jean-Paul Saman <jpsaman@videolan.org>
git-committer:
Jean-Paul Saman <jpsaman@videolan.org> 1203931352 +0000
git-parent:

[e9347d2d89166c53ece29004c1a0d46f3cf9182e]

git-author:
Jean-Paul Saman <jpsaman@videolan.org> 1203931352 +0000
Message:

Cleanup and fix crash when plugin wasn't playing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/mozilla/vlcplugin.cpp

    r2e888fd rf90b88a  
    4545    b_stream(0), 
    4646    b_autoplay(1), 
     47    i_control_height(45), 
    4748    psz_target(NULL), 
    4849    libvlc_instance(NULL), 
  • projects/mozilla/vlcplugin.h

    r1e9ff27 rf90b88a  
    106106    char *   psz_target; 
    107107 
     108#if XP_UNIX 
     109    /* toolbar */ 
     110    int     i_control_height; 
     111#endif 
    108112private: 
    109113    /* VLC reference */ 
     
    124128    unsigned int     i_width, i_height; 
    125129    Window           npvideo, npcontrol; 
     130 
    126131#endif 
    127132}; 
  • projects/mozilla/vlcshell.cpp

    r2e888fd rf90b88a  
    5353 
    5454#define WINDOW_TEXT "Video is loading..." 
    55 #define CONTROL_HEIGHT 45 
     55 
     56#ifndef __MAX 
     57#   define __MAX(a, b)   ( ((a) > (b)) ? (a) : (b) ) 
     58#endif 
     59#ifndef __MIN 
     60#   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) ) 
     61#endif 
    5662 
    5763/***************************************************************************** 
     
    498504 
    499505            Window video = XCreateSimpleWindow( p_display, parent, 0, 0, 
    500                            window->width, window->height - CONTROL_HEIGHT, 0, 
     506                           window->width, window->height - p_plugin->i_control_height, 0, 
    501507                           i_blackColor, i_blackColor ); 
    502508            Window controls = XCreateSimpleWindow( p_display, parent, 0, 
    503                             window->height - CONTROL_HEIGHT-1, window->width, 
    504                             CONTROL_HEIGHT-1, 0, i_blackColor, i_blackColor ); 
     509                            window->height - p_plugin->i_control_height-1, window->width, 
     510                            p_plugin->i_control_height-1, 0, i_blackColor, i_blackColor ); 
    505511 
    506512            XMapWindow( p_display, parent ); 
     
    775781 
    776782    /* Toolbar */ 
    777     XImage *p_playIcon = NULL; 
    778     XImage *p_pauseIcon = NULL; 
    779     XImage *p_stopIcon = NULL; 
     783    XImage *p_btnPlay = NULL; 
     784    XImage *p_btnPause = NULL; 
     785    XImage *p_btnStop = NULL; 
    780786    XImage *p_timeline = NULL; 
    781     XImage *p_timeKnob = NULL; 
    782     XImage *p_fscreen = NULL; 
    783     XImage *p_muteIcon = NULL; 
    784     XImage *p_unmuteIcon = NULL; 
     787    XImage *p_btnTime = NULL; 
     788    XImage *p_btnFullscreen = NULL; 
     789    XImage *p_btnMute = NULL; 
     790    XImage *p_btnUnmute = NULL; 
    785791 
    786792    libvlc_media_instance_t *p_md = NULL; 
     
    793799    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display; 
    794800 
     801    /* load icons */ 
     802    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm", 
     803                        &p_btnPlay, NULL, NULL); 
     804    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     805                                        p_btnPlay->height ); 
     806    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm", 
     807                        &p_btnPause, NULL, NULL); 
     808    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     809                                        p_btnPause->height ); 
     810    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm", 
     811                        &p_btnStop, NULL, NULL ); 
     812    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     813                                        p_btnStop->height ); 
     814    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm", 
     815                        &p_timeline, NULL, NULL); 
     816    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     817                                        p_timeline->height ); 
     818    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm", 
     819                        &p_btnTime, NULL, NULL); 
     820    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     821                                        p_btnTime->height ); 
     822    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm", 
     823                        &p_btnFullscreen, NULL, NULL); 
     824    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     825                                        p_btnFullscreen->height); 
     826    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm", 
     827                        &p_btnMute, NULL, NULL); 
     828    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     829                                        p_btnMute->height); 
     830    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm", 
     831                        &p_btnUnmute, NULL, NULL); 
     832    p_plugin->i_control_height = __MAX( p_plugin->i_control_height, 
     833                                        p_btnUnmute->height); 
     834 
     835    if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline || 
     836        !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute ) 
     837        fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH ); 
     838 
    795839    gcv.foreground = BlackPixel( p_display, 0 ); 
    796840    gc = XCreateGC( p_display, video, GCForeground, &gcv ); 
    797841 
    798842    XFillRectangle( p_display, video, gc, 
    799                     0, 0, window.width, window.height - CONTROL_HEIGHT ); 
     843                    0, 0, window.width, window.height - p_plugin->i_control_height ); 
    800844 
    801845    gcv.foreground = WhitePixel( p_display, 0 ); 
     
    803847 
    804848    XDrawString( p_display, video, gc, 
    805                  window.width / 2 - 40, (window.height - CONTROL_HEIGHT) / 2, 
     849                 window.width / 2 - 40, (window.height - p_plugin->i_control_height) / 2, 
    806850                 WINDOW_TEXT, strlen(WINDOW_TEXT) ); 
    807851 
     
    811855 
    812856    XFillRectangle( p_display, control, gc, 
    813                     0, 0, window.width, CONTROL_HEIGHT ); 
     857                    0, 0, window.width, p_plugin->i_control_height ); 
    814858 
    815859 
     
    842886    libvlc_media_instance_release(p_md); 
    843887 
    844     /* load icons */ 
    845     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm", 
    846                         &p_playIcon, NULL, NULL); 
    847     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm", 
    848                         &p_pauseIcon, NULL, NULL); 
    849     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm", 
    850                         &p_stopIcon, NULL, NULL ); 
    851     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm", 
    852                         &p_timeline, NULL, NULL); 
    853     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm", 
    854                         &p_timeKnob, NULL, NULL); 
    855     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm", 
    856                         &p_fscreen, NULL, NULL); 
    857     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm", 
    858                         &p_muteIcon, NULL, NULL); 
    859     XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm", 
    860                         &p_unmuteIcon, NULL, NULL); 
    861  
    862 #if 1 /* DEBUG */ 
    863     if( !p_playIcon ) 
    864     { 
    865         fprintf(stderr, "Error: playImage not found\n"); 
    866     } 
    867     if( !p_pauseIcon ) 
    868     { 
    869         fprintf(stderr, "Error: pauseImage not found\n"); 
    870     } 
    871     if( !p_stopIcon ) 
    872     { 
    873         fprintf(stderr, "Error: stopImage not found\n"); 
    874     } 
    875     if( !p_timeline ) 
    876     { 
    877         fprintf(stderr, "Error: TimeLineImage not found\n"); 
    878     } 
    879     if( !p_timeKnob ) 
    880     { 
    881         fprintf(stderr, "Error: TimeIcon not found\n"); 
    882     } 
    883     if( !p_fscreen ) 
    884     { 
    885         fprintf(stderr, "Error: FullscreenImage not found\n"); 
    886     } 
    887     if( !p_muteIcon ) 
    888     { 
    889         fprintf(stderr, "Error: MuteImage not found\n"); 
    890     } 
    891     if( !p_unmuteIcon ) 
    892     { 
    893         fprintf(stderr, "Error: UnMuteImage not found\n"); 
    894     } 
    895 #endif 
    896  
    897888    /* position icons */ 
    898     if( p_pauseIcon && (i_playing == 1) ) 
    899     { 
    900         XPutImage( p_display, control, gc, p_pauseIcon, 0, 0, 4, 14, 
    901                    p_pauseIcon->width, p_pauseIcon->height ); 
    902     } 
    903     else if( p_playIcon
    904     { 
    905         XPutImage( p_display, control, gc, p_playIcon, 0, 0, 4, 14, 
    906                    p_playIcon->width, p_playIcon->height ); 
    907     } 
    908  
    909     if( p_stopIcon
    910         XPutImage( p_display, control, gc, p_stopIcon, 0, 0, 39, 14, 
    911                    p_stopIcon->width, p_stopIcon->height ); 
    912     if( p_fscreen ) 
    913         XPutImage( p_display, control, gc, p_fscreen, 0, 0, 67, 21, 
    914                    p_fscreen->width, p_fscreen->height ); 
    915  
    916     if( p_unmuteIcon && b_mute ) 
    917     { 
    918         XPutImage( p_display, control, gc, p_unmuteIcon, 0, 0, 94, 30, 
    919                  p_unmuteIcon->width, p_unmuteIcon->height ); 
    920     } 
    921     else if( p_muteIcon
    922     { 
    923         XPutImage( p_display, control, gc, p_muteIcon, 0, 0, 94, 30, 
    924                    p_muteIcon->width, p_muteIcon->height ); 
     889    if( p_btnPause && (i_playing == 1) ) 
     890    { 
     891        XPutImage( p_display, control, gc, p_btnPause, 0, 0, 4, 14, 
     892                   p_btnPause->width, p_btnPause->height ); 
     893    } 
     894    else if( p_btnPlay
     895    { 
     896        XPutImage( p_display, control, gc, p_btnPlay, 0, 0, 4, 14, 
     897                   p_btnPlay->width, p_btnPlay->height ); 
     898    } 
     899 
     900    if( p_btnStop
     901        XPutImage( p_display, control, gc, p_btnStop, 0, 0, 39, 14, 
     902                   p_btnStop->width, p_btnStop->height ); 
     903    if( p_btnFullscreen ) 
     904        XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, 67, 21, 
     905                   p_btnFullscreen->width, p_btnFullscreen->height ); 
     906 
     907    if( p_btnUnmute && b_mute ) 
     908    { 
     909        XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, 94, 30, 
     910                   p_btnUnmute->width, p_btnUnmute->height ); 
     911    } 
     912    else if( p_btnMute
     913    { 
     914        XPutImage( p_display, control, gc, p_btnMute, 0, 0, 94, 30, 
     915                   p_btnMute->width, p_btnMute->height ); 
    925916    } 
    926917 
     
    928919        XPutImage( p_display, control, gc, p_timeline, 0, 0, 4, 4, 
    929920                   (window.width-8), p_timeline->height ); 
    930     if( p_timeKnob && (f_position > 0) ) 
     921    if( p_btnTime && (f_position > 0) ) 
    931922    { 
    932923        f_position = (((float)window.width-8)/100)*f_position; 
    933         XPutImage( p_display, control, gc, p_timeKnob, 0, 0, (4+f_position), 2, 
    934                    p_timeKnob->width, p_timeKnob->height ); 
     924        XPutImage( p_display, control, gc, p_btnTime, 0, 0, (4+f_position), 2, 
     925                   p_btnTime->width, p_btnTime->height ); 
    935926    } 
    936927 
    937928    /* Cleanup */ 
    938     if( p_playIcon )   XDestroyImage( p_playIcon ); 
    939     if( p_pauseIcon )  XDestroyImage( p_pauseIcon ); 
    940     if( p_stopIcon )   XDestroyImage( p_stopIcon ); 
    941     if( p_timeline )   XDestroyImage( p_timeline ); 
    942     if( p_timeKnob )   XDestroyImage( p_timeKnob ); 
    943     if( p_fscreen )    XDestroyImage( p_fscreen ); 
    944     if( p_muteIcon )   XDestroyImage( p_muteIcon ); 
    945     if( p_unmuteIcon ) XDestroyImage( p_unmuteIcon ); 
     929    if( p_btnPlay )  XDestroyImage( p_btnPlay ); 
     930    if( p_btnPause ) XDestroyImage( p_btnPause ); 
     931    if( p_btnStop )  XDestroyImage( p_btnStop ); 
     932    if( p_timeline ) XDestroyImage( p_timeline ); 
     933    if( p_btnTime )  XDestroyImage( p_btnTime ); 
     934    if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen ); 
     935    if( p_btnMute )  XDestroyImage( p_btnMute ); 
     936    if( p_btnUnmute ) XDestroyImage( p_btnUnmute ); 
    946937 
    947938    XFreeGC( p_display, gc ); 
     
    958949    int i_yPos = event->xbutton.y; 
    959950 
    960     libvlc_exception_t ex; 
    961     libvlc_exception_init( &ex ); 
    962     libvlc_media_instance_t *p_md = 
    963             libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex); 
    964     libvlc_exception_clear( &ex ); 
    965  
    966     /* jump in the movie */ 
    967     if( i_yPos <= (i_height-30) ) 
    968     { 
    969         vlc_int64_t f_length; 
     951    if( p_plugin ) 
     952    { 
     953        libvlc_exception_t ex; 
    970954        libvlc_exception_init( &ex ); 
    971         f_length = libvlc_media_instance_get_length( p_md, &ex ) / 100; 
     955        libvlc_media_instance_t *p_md = 
     956                libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex); 
    972957        libvlc_exception_clear( &ex ); 
    973958 
    974         f_length = (float)f_length * 
    975                    ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) ); 
    976  
    977         libvlc_exception_init( &ex ); 
    978         libvlc_media_instance_set_time( p_md, f_length, &ex ); 
    979         libvlc_exception_clear( &ex ); 
    980     } 
    981  
    982     /* play/pause toggle */ 
    983     if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) ) 
    984     { 
    985         int i_playing; 
    986         libvlc_exception_init( &ex ); 
    987         i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex ); 
    988         libvlc_exception_clear( &ex ); 
    989  
    990         libvlc_exception_init( &ex ); 
    991         if( i_playing == 1 ) 
    992             libvlc_playlist_pause( p_plugin->getVLC(), &ex ); 
    993         else 
    994             libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex ); 
    995         libvlc_exception_clear( &ex ); 
    996     } 
    997  
    998     /* stop */ 
    999     if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) ) 
    1000     { 
    1001         libvlc_exception_init( &ex ); 
    1002         libvlc_playlist_stop( p_plugin->getVLC(), &ex ); 
    1003         libvlc_exception_clear( &ex ); 
    1004     } 
    1005  
    1006     /* fullscreen */ 
    1007     if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) ) 
    1008     { 
    1009         libvlc_exception_init( &ex ); 
    1010         libvlc_set_fullscreen( p_md, 1, &ex ); 
    1011         libvlc_exception_clear( &ex ); 
    1012     } 
    1013  
    1014     /* mute toggle */ 
    1015     if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109)) 
    1016     { 
    1017         libvlc_exception_init( &ex ); 
    1018         libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex ); 
    1019         libvlc_exception_clear( &ex ); 
    1020     } 
    1021     libvlc_media_instance_release( p_md ); 
    1022  
     959        /* jump in the movie */ 
     960        if( i_yPos <= (i_height-30) ) 
     961        { 
     962            vlc_int64_t f_length; 
     963            libvlc_exception_init( &ex ); 
     964            f_length = libvlc_media_instance_get_length( p_md, &ex ) / 100; 
     965            libvlc_exception_clear( &ex ); 
     966 
     967            f_length = (float)f_length * 
     968                    ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) ); 
     969 
     970            libvlc_exception_init( &ex ); 
     971            libvlc_media_instance_set_time( p_md, f_length, &ex ); 
     972            libvlc_exception_clear( &ex ); 
     973        } 
     974 
     975        /* play/pause toggle */ 
     976        if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) ) 
     977        { 
     978            int i_playing; 
     979            libvlc_exception_init( &ex ); 
     980            i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex ); 
     981            libvlc_exception_clear( &ex ); 
     982 
     983            libvlc_exception_init( &ex ); 
     984            if( i_playing == 1 ) 
     985                libvlc_playlist_pause( p_plugin->getVLC(), &ex ); 
     986            else 
     987                libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex ); 
     988            libvlc_exception_clear( &ex ); 
     989        } 
     990 
     991        /* stop */ 
     992        if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) ) 
     993        { 
     994            libvlc_exception_init( &ex ); 
     995            libvlc_playlist_stop( p_plugin->getVLC(), &ex ); 
     996            libvlc_exception_clear( &ex ); 
     997        } 
     998 
     999        /* fullscreen */ 
     1000        if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) ) 
     1001        { 
     1002            libvlc_exception_init( &ex ); 
     1003            libvlc_set_fullscreen( p_md, 1, &ex ); 
     1004            libvlc_exception_clear( &ex ); 
     1005        } 
     1006 
     1007        /* mute toggle */ 
     1008        if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109)) 
     1009        { 
     1010            libvlc_exception_init( &ex ); 
     1011            libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex ); 
     1012            libvlc_exception_clear( &ex ); 
     1013        } 
     1014        libvlc_media_instance_release( p_md ); 
     1015    } 
    10231016    Redraw( w, closure, event ); 
    10241017} 
     
    10481041#endif /* X11_RESIZE_DEBUG */ 
    10491042 
    1050     if( ! p_plugin->setSize(window.width, (window.height - CONTROL_HEIGHT)) ) 
     1043    if( ! p_plugin->setSize(window.width, (window.height - p_plugin->i_control_height)) ) 
    10511044    { 
    10521045        /* size already set */ 
     
    10541047    } 
    10551048 
    1056  
    1057     i_ret = XResizeWindow( p_display, drawable, window.width, (window.height - CONTROL_HEIGHT) ); 
     1049    i_ret = XResizeWindow( p_display, drawable, window.width, (window.height - p_plugin->i_control_height) ); 
    10581050 
    10591051#ifdef X11_RESIZE_DEBUG 
     
    10871079 
    10881080        i_ret = XResizeWindow( p_display, base_window, 
    1089                 window.width, ( window.height - CONTROL_HEIGHT ) ); 
     1081                window.width, ( window.height - p_plugin->i_control_height ) ); 
    10901082 
    10911083#ifdef X11_RESIZE_DEBUG 
     
    11031095 
    11041096#endif /* XP_UNIX */ 
    1105