Changeset a593fa18ef93069b6152cc571561c5ccc053e67b

Show
Ignore:
Timestamp:
27/08/06 18:18:59 (2 years ago)
Author:
Damien Fouilleul <damienf@videolan.org>
git-committer:
Damien Fouilleul <damienf@videolan.org> 1156695539 +0000
git-parent:

[faef0357a70215aed00dd680b7c430f365f2992f]

git-author:
Damien Fouilleul <damienf@videolan.org> 1156695539 +0000
Message:

all: rewrite of mozilla plugin
- added a couple of support APIs in libvlc
- retired XPCOM interface, all scripting now goes through NPObject apis
- new APIs using libvlc (roughly similar to java bindings)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/video_output.h

    r6b7fbfe ra593fa1  
    276276    VOUT_SNAPSHOT, 
    277277    VOUT_CLOSE, 
    278     VOUT_SET_FOCUS         /* arg1= vlc_bool_t       res=    */ 
     278    VOUT_SET_FOCUS,         /* arg1= vlc_bool_t       res=    */ 
     279    VOUT_SET_VIEWPORT       /* arg1= view rect, arg2=clip rect, res= */ 
    279280}; 
    280281 
  • include/vlc/libvlc.h

    r44de024 ra593fa1  
    357357 
    358358/** 
    359  * Get current mute status 
     359 * change the video output parent 
    360360 * \param p_instance libvlc instance 
    361361 * \param drawable the new parent window (Drawable on X11, CGrafPort on MacOSX, HWND on Win32) 
     
    365365int libvlc_video_reparent( libvlc_input_t *, libvlc_drawable_t, libvlc_exception_t * ); 
    366366 
     367/** 
     368 * Set the video output parent 
     369 * \param p_instance libvlc instance 
     370 * \param drawable the new parent window (Drawable on X11, CGrafPort on MacOSX, HWND on Win32) 
     371 * \param p_exception an initialized exception 
     372 */ 
     373void libvlc_video_set_parent( libvlc_instance_t *, libvlc_drawable_t, libvlc_exception_t * ); 
     374 
     375/** 
     376 * Set the video output size 
     377 * \param p_instance libvlc instance 
     378 * \param width new width for video drawable 
     379 * \param height new height for video drawable 
     380 * \param p_exception an initialized exception 
     381 */ 
     382void libvlc_video_set_size( libvlc_instance_t *, int, int, libvlc_exception_t * ); 
     383 
     384/** 
     385* Downcast to this general type as placeholder for a platform specific one, such as: 
     386*  Drawable on X11, 
     387*  CGrafPort on MacOSX, 
     388*  HWND on win32 
     389*/ 
     390typedef struct 
     391{ 
     392    int top, left; 
     393    int bottom, right; 
     394} 
     395libvlc_rectangle_t; 
     396 
     397/** 
     398 * Set the video output viewport for a windowless video ouput (MacOS X only) 
     399 * \param p_instance libvlc instance 
     400 * \param view coordinates within video drawable 
     401 * \param clip coordinates within video drawable 
     402 * \param p_exception an initialized exception 
     403 */ 
     404void libvlc_video_set_viewport( libvlc_instance_t *, const libvlc_rectangle_t *, const libvlc_rectangle_t *, libvlc_exception_t * ); 
     405 
    367406 
    368407/** @} */ 
     
    380419 * @{ 
    381420 */ 
     421 
     422/** 
     423 * Toggle mute status 
     424 * \param p_instance libvlc instance 
     425 * \param p_exception an initialized exception 
     426 * \return void 
     427 */ 
     428void libvlc_audio_toggle_mute( libvlc_instance_t *, libvlc_exception_t * ); 
    382429 
    383430/** 
  • modules/gui/macosx/voutgl.m

    r7a6b8a5 ra593fa1  
    8787static void aglEnd    ( vout_thread_t * p_vout ); 
    8888static int  aglManage ( vout_thread_t * p_vout ); 
     89static int  aglControl( vout_thread_t *, int, va_list ); 
    8990static void aglSwap   ( vout_thread_t * p_vout ); 
    90  
    91 static int DrawableRedraw( vlc_object_t *p_this, const char *psz_name, 
    92     vlc_value_t oval, vlc_value_t nval, void *param); 
    9391 
    9492int E_(OpenVideoGL)  ( vlc_object_t * p_this ) 
     
    132130            AGL_NONE }; 
    133131 
    134         AGLDevice screen; 
    135132        AGLPixelFormat pixFormat; 
    136133 
    137134        p_vout->p_sys->b_embedded = VLC_TRUE; 
    138135 
    139         screen = GetGWorldDevice((CGrafPtr)value_drawable.i_int); 
    140         if( NULL == screen ) 
    141         { 
    142             msg_Err( p_vout, "can't find screen device for drawable" ); 
    143             return VLC_EGENERIC; 
    144         } 
    145          
    146         pixFormat = aglChoosePixelFormat(&screen, 1, ATTRIBUTES); 
     136        pixFormat = aglChoosePixelFormat(NULL, 0, ATTRIBUTES); 
    147137        if( NULL == pixFormat ) 
    148138        { 
     
    159149        } 
    160150        else { 
    161             // tell opengl to sync buffer swap with vertical retrace 
    162             GLint param = 1
     151            // tell opengl not to sync buffer swap with vertical retrace 
     152            GLint param = 0
    163153            aglSetInteger(p_vout->p_sys->agl_ctx, AGL_SWAP_INTERVAL, &param); 
    164154            aglEnable(p_vout->p_sys->agl_ctx, AGL_SWAP_INTERVAL); 
     
    168158        p_vout->pf_end              = aglEnd; 
    169159        p_vout->pf_manage           = aglManage; 
    170         p_vout->pf_control          = NULL
     160        p_vout->pf_control          = aglControl
    171161        p_vout->pf_swap             = aglSwap; 
    172162        p_vout->pf_lock             = Lock; 
     
    208198    if( p_vout->p_sys->b_embedded ) 
    209199    { 
    210         var_DelCallback(p_vout->p_vlc, "drawableredraw", DrawableRedraw, p_vout); 
    211200        aglDestroyContext(p_vout->p_sys->agl_ctx); 
    212201    } 
     
    457446 *****************************************************************************/ 
    458447 
    459 static void UpdateEmbeddedGeometry( vout_thread_t *p_vout ); 
     448static void aglSetViewport( vout_thread_t *p_vout, Rect viewBounds, Rect clipBounds ); 
    460449static void aglReshape( vout_thread_t * p_vout ); 
    461450 
    462451static int aglInit( vout_thread_t * p_vout ) 
    463452{ 
    464     UpdateEmbeddedGeometry(p_vout); 
    465     var_AddCallback(p_vout->p_vlc, "drawableredraw", DrawableRedraw, p_vout); 
     453    vlc_value_t val; 
     454 
     455    Rect viewBounds;     
     456    Rect clipBounds; 
     457     
     458    var_Get( p_vout->p_vlc, "drawable", &val ); 
     459    p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int; 
     460    aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable); 
     461 
     462    var_Get( p_vout->p_vlc, "drawable-view-top", &val ); 
     463    viewBounds.top = val.i_int; 
     464    var_Get( p_vout->p_vlc, "drawable-view-left", &val ); 
     465    viewBounds.left = val.i_int; 
     466    var_Get( p_vout->p_vlc, "drawable-view-bottom", &val ); 
     467    viewBounds.bottom = val.i_int; 
     468    var_Get( p_vout->p_vlc, "drawable-view-right", &val ); 
     469    viewBounds.right = val.i_int; 
     470    var_Get( p_vout->p_vlc, "drawable-clip-top", &val ); 
     471    clipBounds.top = val.i_int; 
     472    var_Get( p_vout->p_vlc, "drawable-clip-left", &val ); 
     473    clipBounds.left = val.i_int; 
     474    var_Get( p_vout->p_vlc, "drawable-clip-bottom", &val ); 
     475    clipBounds.bottom = val.i_int; 
     476    var_Get( p_vout->p_vlc, "drawable-clip-right", &val ); 
     477    clipBounds.right = val.i_int; 
     478 
     479    aglSetViewport(p_vout, viewBounds, clipBounds); 
    466480 
    467481    aglSetCurrentContext(p_vout->p_sys->agl_ctx); 
     
    548562} 
    549563 
     564static int aglControl( vout_thread_t *p_vout, int i_query, va_list args ) 
     565{ 
     566    switch( i_query ) 
     567    { 
     568        case VOUT_SET_VIEWPORT: 
     569    { 
     570        Rect viewBounds, clipBounds; 
     571            viewBounds.top = va_arg( args, int); 
     572            viewBounds.left = va_arg( args, int); 
     573            viewBounds.bottom = va_arg( args, int); 
     574            viewBounds.right = va_arg( args, int); 
     575            clipBounds.top = va_arg( args, int); 
     576            clipBounds.left = va_arg( args, int); 
     577            clipBounds.bottom = va_arg( args, int); 
     578            clipBounds.right = va_arg( args, int); 
     579        aglSetViewport(p_vout, viewBounds, clipBounds); 
     580            return VLC_SUCCESS; 
     581    } 
     582 
     583        case VOUT_REPARENT: 
     584    { 
     585        AGLDrawable drawable = (AGLDrawable)va_arg( args, int); 
     586        if( drawable != p_vout->p_sys->agl_drawable ) 
     587        { 
     588        p_vout->p_sys->agl_drawable = drawable; 
     589        aglSetDrawable(p_vout->p_sys->agl_ctx, drawable); 
     590        } 
     591            return VLC_SUCCESS; 
     592    } 
     593 
     594        default: 
     595            return vout_vaControlDefault( p_vout, i_query, args ); 
     596    } 
     597} 
     598 
    550599static void aglSwap( vout_thread_t * p_vout ) 
    551600{ 
     
    554603} 
    555604 
    556 static void UpdateEmbeddedGeometry( vout_thread_t *p_vout ) 
    557 
    558     vlc_value_t val; 
    559     vlc_value_t valt, vall, valb, valr, valx, valy, valw, valh, 
    560                 valportx, valporty; 
    561  
    562     Rect winBounds;     
    563     Rect clientBounds; 
    564      
    565     GLint rect[4]; 
    566  
    567     var_Get( p_vout->p_vlc, "drawable", &val ); 
    568     var_Get( p_vout->p_vlc, "drawablet", &valt ); 
    569     var_Get( p_vout->p_vlc, "drawablel", &vall ); 
    570     var_Get( p_vout->p_vlc, "drawableb", &valb ); 
    571     var_Get( p_vout->p_vlc, "drawabler", &valr ); 
    572     var_Get( p_vout->p_vlc, "drawablex", &valx ); 
    573     var_Get( p_vout->p_vlc, "drawabley", &valy ); 
    574     var_Get( p_vout->p_vlc, "drawablew", &valw ); 
    575     var_Get( p_vout->p_vlc, "drawableh", &valh ); 
    576     var_Get( p_vout->p_vlc, "drawableportx", &valportx ); 
    577     var_Get( p_vout->p_vlc, "drawableporty", &valporty ); 
    578  
     605static void aglSetViewport( vout_thread_t *p_vout, Rect viewBounds, Rect clipBounds ) 
     606
    579607    // mozilla plugin provides coordinates based on port bounds 
    580608    // however AGL coordinates are based on window structure region 
    581609    // and are vertically flipped 
    582  
    583     GetWindowBounds(GetWindowFromPort((CGrafPtr)val.i_int), 
     610    GLint rect[4]; 
     611    CGrafPtr port = (CGrafPtr)p_vout->p_sys->agl_drawable; 
     612    Rect winBounds, clientBounds; 
     613 
     614    GetWindowBounds(GetWindowFromPort(port), 
    584615        kWindowStructureRgn, &winBounds); 
    585     GetWindowBounds(GetWindowFromPort((CGrafPtr)val.i_int), 
     616    GetWindowBounds(GetWindowFromPort(port), 
    586617        kWindowContentRgn, &clientBounds); 
    587618 
    588619    /* update video clipping bounds in drawable */ 
    589620    rect[0] = (clientBounds.left-winBounds.left) 
    590             + vall.i_int;                       // from window left edge 
     621            + clipBounds.left;                  // from window left edge 
    591622    rect[1] = (winBounds.bottom-winBounds.top) 
    592623            - (clientBounds.top-winBounds.top) 
    593             - valb.i_int;                       // from window bottom edge 
    594     rect[2] = valr.i_int-vall.i_int;            // width 
    595     rect[3] = valb.i_int-valt.i_int;            // height 
     624            - clipBounds.bottom;                // from window bottom edge 
     625    rect[2] = clipBounds.right-clipBounds.left; // width 
     626    rect[3] = clipBounds.bottom-clipBounds.top; // height 
    596627    aglSetInteger(p_vout->p_sys->agl_ctx, AGL_BUFFER_RECT, rect); 
    597628    aglEnable(p_vout->p_sys->agl_ctx, AGL_BUFFER_RECT); 
    598629 
    599630    /* update video internal bounds in drawable */ 
    600     p_vout->p_sys->i_offx   = -vall.i_int - valportx.i_int; 
    601     p_vout->p_sys->i_offy   = valb.i_int + valporty.i_int - valh.i_int;  
    602     p_vout->p_sys->i_width  = valw.i_int; 
    603     p_vout->p_sys->i_height = valh.i_int; 
    604  
    605     if( p_vout->p_sys->agl_drawable == (AGLDrawable)val.i_int ) 
    606     { 
    607         aglUpdateContext(p_vout->p_sys->agl_ctx); 
    608     } 
    609     else 
    610     { 
    611         p_vout->p_sys->agl_drawable = (AGLDrawable)val.i_int; 
    612         aglSetDrawable(p_vout->p_sys->agl_ctx, p_vout->p_sys->agl_drawable); 
    613     } 
     631    p_vout->p_sys->i_width  = viewBounds.right-viewBounds.left; 
     632    p_vout->p_sys->i_height = viewBounds.bottom-viewBounds.top; 
     633    p_vout->p_sys->i_offx   = -clipBounds.left - viewBounds.left; 
     634    p_vout->p_sys->i_offy   = clipBounds.bottom + viewBounds.top 
     635                            - p_vout->p_sys->i_height;  
     636 
     637    aglUpdateContext(p_vout->p_sys->agl_ctx); 
    614638    aglReshape( p_vout ); 
    615639} 
    616640 
    617 /* If we're embedded, the application is expected to indicate a 
    618  * window change (move/resize/etc) via the "drawableredraw" value. 
    619  */ 
    620  
    621 static int DrawableRedraw( vlc_object_t *p_this, const char *psz_name, 
    622     vlc_value_t oval, vlc_value_t nval, void *param) 
    623 { 
    624     vout_thread_t *p_vout = (vout_thread_t *)param; 
    625  
    626     UpdateEmbeddedGeometry( p_vout ); 
    627  
    628     return VLC_SUCCESS; 
    629 } 
    630  
  • mozilla/Makefile.am

    r5b36930 ra593fa1  
    55noinst_LIBRARIES = $(noinst_LIBRARIES_mozilla) 
    66 
    7 MOSTLYCLEANFILES = $(npvlc_DATA) $(vlcintf_xpt_DATA) 
     7MOSTLYCLEANFILES = $(npvlc_DATA) 
    88CLEANFILES = stamp-pic $(BUILT_SOURCES) 
    9 EXTRA_DIST = $(DIST_sources) vlcintf.idl npvlc_rc.rc vlc.r 
     9EXTRA_DIST = $(DIST_sources) npvlc_rc.rc vlc.r 
    1010 
    1111SOURCES_mozilla_common = \ 
     
    1313    vlcplugin.cpp \ 
    1414    vlcplugin.h \ 
    15     vlcpeer.cpp \ 
    16     vlcpeer.h \ 
    17     vlcruntime.cpp \ 
    18     vlcruntime.h \ 
     15    control/npolibvlc.cpp \ 
     16    control/npolibvlc.h \ 
     17    control/npovlc.cpp \ 
     18    control/npovlc.h \ 
     19    control/nporuntime.cpp \ 
     20    control/nporuntime.h \ 
    1921    support/classinfo.h 
    2022 
     
    142144noinst_LIBRARIES_mozilla = libnpvlc.a 
    143145 
    144 $(SOURCES_mozilla): vlcintf.h 
    145  
    146 BUILT_SOURCES = vlcintf.h 
    147 vlcintf_xpt_DATA = vlcintf.xpt 
    148  
    149146if USE_LIBTOOL 
    150147# FIXME: name is incorrect on Win32 & Darwin 
     
    176173    @if test -f "$@.exe"; then mv -f "$@.exe" "$@"; fi 
    177174 
    178 vlcintf_xptdir = $(libdir)/mozilla/components 
    179 vlcintf.xpt: vlcintf.idl 
    180     $(XPIDL) $(XPIDL_INCL) \ 
    181       -m typelib -o vlcintf $(srcdir)/vlcintf.idl 
    182  
    183 vlcintf.h: vlcintf.idl 
    184     $(XPIDL) $(XPIDL_INCL) \ 
    185       -m header -o vlcintf $(srcdir)/vlcintf.idl 
    186  
    187175############################################################################### 
    188176# Stamp rules 
  • mozilla/vlcplugin.cpp

    r20defc2 ra593fa1  
    2727#include "config.h" 
    2828 
    29 #include <vlc/vlc.h> 
    30  
    3129#ifdef HAVE_MOZILLA_CONFIG_H 
    3230#   include <mozilla-config.h> 
    3331#endif 
    34 #include <nsISupports.h> 
    35 #include <nsMemory.h> 
    36 #include <npapi.h> 
    37  
    38 #if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN) 
    39 #define XP_UNIX 1 
    40 #elif defined(XP_MACOSX) 
    41 #undef XP_UNIX 
    42 #endif 
    4332 
    4433#include "vlcplugin.h" 
     34#include "control/npovlc.h" 
     35#include "control/npolibvlc.h" 
    4536 
    4637/***************************************************************************** 
    4738 * VlcPlugin constructor and destructor 
    4839 *****************************************************************************/ 
    49 VlcPlugin::VlcPlugin( NPP instance ) 
    50 
    51     p_instance = instance; 
    52     p_peer = NULL; 
    53 
    54  
     40VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) : 
     41    i_npmode(mode), 
     42    b_stream(0), 
     43    b_autoplay(0), 
     44    psz_target(NULL), 
     45    libvlc_instance(NULL), 
     46    scriptClass(NULL), 
     47    p_browser(instance), 
     48    psz_baseURL(NULL) 
     49#if XP_WIN 
     50    ,pf_wndproc(NULL) 
     51#endif 
     52#if XP_UNIX 
     53    ,i_width((unsigned)-1) 
     54    ,i_height((unsigned)-1) 
     55#endif 
     56
     57    memset(&npwindow, 0, sizeof(NPWindow)); 
     58
     59 
     60static int boolValue(const char *value) { 
     61    return ( !strcmp(value, "1") ||  
     62             !strcasecmp(value, "true") || 
     63             !strcasecmp(value, "yes") ); 
     64
     65 
     66NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) 
     67
     68    /* prepare VLC command line */ 
     69    char *ppsz_argv[32] = 
     70    { 
     71        "vlc", 
     72        "-vv", 
     73        "--no-stats", 
     74        "--intf", "dummy", 
     75    }; 
     76    int ppsz_argc = 5; 
     77 
     78    /* locate VLC module path */ 
     79#ifdef XP_MACOSX 
     80    ppsz_argv[ppsz_argc++] = "--plugin-path"; 
     81    ppsz_argv[ppsz_argc++] = "/Library/Internet Plug-Ins/VLC Plugin.plugin/" 
     82                             "Contents/MacOS/modules"; 
     83#elif defined(XP_WIN) 
     84    HKEY h_key; 
     85    DWORD i_type, i_data = MAX_PATH + 1; 
     86    char p_data[MAX_PATH + 1]; 
     87    if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC", 
     88                      0, KEY_READ, &h_key ) == ERROR_SUCCESS ) 
     89    { 
     90         if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type, 
     91                              (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS ) 
     92         { 
     93             if( i_type == REG_SZ ) 
     94             { 
     95                 strcat( p_data, "\\vlc" ); 
     96                 ppsz_argv[0] = p_data; 
     97             } 
     98         } 
     99         RegCloseKey( h_key ); 
     100    } 
     101    ppsz_argv[ppsz_argc++] = "--no-one-instance"; 
     102#if 1 
     103    ppsz_argv[0] = "F:\\Cygwin\\home\\Damien\\dev\\videolan\\vlc-trunk\\vlc"; 
     104#endif 
     105 
     106#endif /* XP_MACOSX */ 
     107 
     108    const char *version = NULL; 
     109 
     110    /* parse plugin arguments */ 
     111    for( int i = 0; i < argc ; i++ ) 
     112    { 
     113        fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); 
     114 
     115        if( !strcmp( argn[i], "target" ) 
     116         || !strcmp( argn[i], "mrl") 
     117         || !strcmp( argn[i], "filename") 
     118         || !strcmp( argn[i], "src") ) 
     119        { 
     120            psz_target = argv[i]; 
     121        } 
     122        else if( !strcmp( argn[i], "autoplay") 
     123              || !strcmp( argn[i], "autostart") ) 
     124        { 
     125            b_autoplay = boolValue(argv[i]); 
     126        } 
     127        else if( !strcmp( argn[i], "fullscreen" ) ) 
     128        { 
     129            if( boolValue(argv[i]) ) 
     130            { 
     131                ppsz_argv[ppsz_argc++] = "--fullscreen"; 
     132            } 
     133            else 
     134            { 
     135                ppsz_argv[ppsz_argc++] = "--no-fullscreen"; 
     136            } 
     137        } 
     138        else if( !strcmp( argn[i], "mute" ) ) 
     139        { 
     140            if( boolValue(argv[i]) ) 
     141            { 
     142                ppsz_argv[ppsz_argc++] = "--volume"; 
     143                ppsz_argv[ppsz_argc++] = "0"; 
     144            } 
     145        } 
     146        else if( !strcmp( argn[i], "loop") 
     147              || !strcmp( argn[i], "autoloop") ) 
     148        { 
     149            if( boolValue(argv[i]) ) 
     150            { 
     151                ppsz_argv[ppsz_argc++] = "--loop"; 
     152            } 
     153            else { 
     154                ppsz_argv[ppsz_argc++] = "--no-loop"; 
     155            } 
     156        } 
     157        else if( !strcmp( argn[i], "version") ) 
     158    { 
     159        version = argv[i]; 
     160    } 
     161    } 
     162 
     163    libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, NULL); 
     164    if( ! libvlc_instance ) 
     165    { 
     166        return NPERR_GENERIC_ERROR; 
     167    } 
     168 
     169    /* 
     170    ** fetch plugin base URL, which is the URL of the page containing the plugin 
     171    ** this URL is used for making absolute URL from relative URL that may be 
     172    ** passed as an MRL argument 
     173    */ 
     174    NPObject *plugin; 
     175 
     176    if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) ) 
     177    { 
     178        /* 
     179        ** is there a better way to get that info ? 
     180        */ 
     181        static const char docLocHref[] = "document.location.href"; 
     182        NPString script; 
     183        NPVariant result; 
     184 
     185        script.utf8characters = docLocHref; 
     186        script.utf8length = sizeof(docLocHref)-1; 
     187 
     188        if( NPN_Evaluate(p_browser, plugin, &script, &result) ) 
     189        { 
     190            if( NPVARIANT_IS_STRING(result) ) 
     191            { 
     192                NPString &location = NPVARIANT_TO_STRING(result); 
     193 
     194                psz_baseURL = new char[location.utf8length+1]; 
     195                if( psz_baseURL ) 
     196                { 
     197                    strncpy(psz_baseURL, location.utf8characters, location.utf8length); 
     198                    psz_baseURL[location.utf8length] = '\0'; 
     199                } 
     200            } 
     201            NPN_ReleaseVariantValue(&result); 
     202        } 
     203        NPN_ReleaseObject(plugin); 
     204    } 
     205 
     206    if( psz_target ) 
     207    { 
     208        // get absolute URL from src 
     209        psz_target = getAbsoluteURL(psz_target); 
     210    } 
     211 
     212    /* assign plugin script root class */ 
     213    if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) ) 
     214    { 
     215    /* new APIs */ 
     216    scriptClass = new RuntimeNPClass<LibvlcRootNPObject>(); 
     217    } 
     218    else 
     219    { 
     220    /* legacy APIs */ 
     221    scriptClass = new RuntimeNPClass<VlcNPObject>(); 
     222    } 
     223 
     224    return NPERR_NO_ERROR; 
     225
     226 
     227#if 0 
     228#ifdef XP_WIN 
     229/* This is really ugly but there is a deadlock when stopping a stream 
     230 * (in VLC_CleanUp()) because the video output is a child of the drawable but 
     231 * is in a different thread. */ 
     232static void HackStopVout( VlcPlugin* p_plugin ) 
     233
     234    MSG msg; 
     235    HWND hwnd; 
     236    vlc_value_t value; 
     237 
     238    int i_vlc = libvlc_get_vlc_id(p_plugin->libvlc_instance); 
     239    VLC_VariableGet( i_vlc, "drawable", &value ); 
     240 
     241    hwnd = FindWindowEx( (HWND)value.i_int, 0, 0, 0 ); 
     242    if( !hwnd ) return; 
     243 
     244    PostMessage( hwnd, WM_CLOSE, 0, 0 ); 
     245 
     246    do 
     247    { 
     248        while( PeekMessage( &msg, (HWND)value.i_int, 0, 0, PM_REMOVE ) ) 
     249        { 
     250            TranslateMessage(&msg); 
     251            DispatchMessage(&msg); 
     252        } 
     253        if( FindWindowEx( (HWND)value.i_int, 0, 0, 0 ) ) Sleep( 10 ); 
     254    } 
     255    while( (hwnd = FindWindowEx( (HWND)value.i_int, 0, 0, 0 )) ); 
     256
     257#endif /* XP_WIN */ 
     258#endif 
    55259 
    56260VlcPlugin::~VlcPlugin() 
    57261{ 
    58     if( p_peer ) 
    59     { 
    60         p_peer->Disable(); 
    61         p_peer->Release(); 
    62     } 
    63 
    64  
     262    delete psz_baseURL; 
     263    delete psz_target; 
     264    if( libvlc_instance ) 
     265        libvlc_destroy(libvlc_instance); 
     266
    65267 
    66268/***************************************************************************** 
    67269 * VlcPlugin methods 
    68270 *****************************************************************************/ 
    69 void VlcPlugin::SetInstance( NPP instance ) 
    70 
    71     p_instance = instance; 
    72 
    73  
    74  
    75 NPP VlcPlugin::GetInstance() 
    76 
    77     return p_instance; 
    78 
    79  
    80  
    81 VlcIntf* VlcPlugin::GetPeer() 
    82 
    83     if( !p_peer ) 
    84     { 
    85         p_peer = new VlcPeer( this ); 
    86         if( p_peer == NULL ) 
    87         { 
    88             return NULL; 
    89         } 
    90  
    91         NS_ADDREF( p_peer ); 
    92     } 
    93  
    94     NS_ADDREF( p_peer ); 
    95     return p_peer; 
    96 
    97  
     271 
     272char *VlcPlugin::getAbsoluteURL(const char *url) 
     273
     274    if( NULL != url ) 
     275    { 
     276        // check whether URL is already absolute 
     277        const char *end=strchr(url, ':'); 
     278        if( (NULL != end) && (end != url) ) 
     279        { 
     280            // validate protocol header 
     281            const char *start = url; 
     282            while( start != end ) { 
     283                char c = *start | 0x20; 
     284                if( (c < 'a') || (c > 'z') ) 
     285                    // not valid protocol header, assume relative URL 
     286                    break; 
     287                ++start; 
     288            } 
     289            /* we have a protocol header, therefore URL is absolute */ 
     290            return strdup(url); 
     291        } 
     292 
     293        if( psz_baseURL ) 
     294        { 
     295            size_t baseLen = strlen(psz_baseURL); 
     296            char *href = new char[baseLen+strlen(url)]; 
     297            if( href ) 
     298            { 
     299                /* prepend base URL */ 
     300                strcpy(href, psz_baseURL); 
     301 
     302                /* 
     303                ** relative url could be empty, 
     304                ** in which case return base URL 
     305                */ 
     306                if( '\0' == *url ) 
     307                    return href; 
     308 
     309                /* 
     310                ** locate pathname part of base URL 
     311                */ 
     312 
     313                /* skip over protocol part  */ 
     314                char *pathstart = strchr(href, ':'); 
     315                char *pathend; 
     316                if( '/' == *(++pathstart) ) 
     317                { 
     318                    if( '/' == *(++pathstart) ) 
     319                    { 
     320                        ++pathstart; 
     321                    } 
     322                } 
     323                /* skip over host part */ 
     324                pathstart = strchr(pathstart, '/'); 
     325                pathend = href+baseLen; 
     326                if( ! pathstart ) 
     327                { 
     328                    // no path, add a / past end of url (over '\0') 
     329                    pathstart = pathend; 
     330                    *pathstart = '/'; 
     331                } 
     332 
     333                /* relative URL made of an absolute path ? */ 
     334                if( '/' == *url ) 
     335                { 
     336                    /* replace path completely */ 
     337                    strcpy(pathstart, url); 
     338                    return href; 
     339                } 
     340 
     341                /* find last path component and replace it */  
     342                while( '/' != *pathend) --pathend; 
     343 
     344                /* 
     345                ** if relative url path starts with one or more '../', 
     346                ** factor them out of href so that we return a 
     347                ** normalized URL 
     348                */ 
     349                while( pathend != pathstart ) 
     350                { 
     351                    const char *p = url; 
     352                    if( '.' != *p ) 
     353                        break; 
     354                    ++p; 
     355                    if( '.' != *p )  
     356                        break; 
     357                    ++p; 
     358                    if( '/' != *p )  
     359                        break; 
     360                    ++p; 
     361                    url = p; 
     362                    while( '/' != *pathend ) --pathend; 
     363                } 
     364                /* concatenate remaining base URL and relative URL */ 
     365                strcpy(pathend+1, url); 
     366            } 
     367            return href; 
     368        } 
     369    } 
     370    return NULL; 
     371
     372 
     373#if XP_UNIX 
     374int  VlcPlugin::setSize(unsigned width, unsigned height) 
     375
     376    int diff = (width != i_width) || (height != i_height); 
     377 
     378    i_width = width; 
     379    i_height = height; 
     380 
     381    /* return size */ 
     382    return diff; 
     383
     384#endif 
     385 
  • mozilla/vlcplugin.h

    r20defc2 ra593fa1  
    22 * vlcplugin.h: a VLC plugin for Mozilla 
    33 ***************************************************************************** 
    4  * Copyright (C) 2002-2005 the VideoLAN team 
     4 * Copyright (C) 2002-2006 the VideoLAN team 
    55 * $Id$ 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     8            Damien Fouilleul <damienf@videolan.org> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    2829#define __VLCPLUGIN_H__ 
    2930 
    30 #include "vlcpeer.h" 
     31#include <vlc/libvlc.h> 
     32#include <npapi.h> 
     33#include "control/nporuntime.h" 
    3134 
    3235#if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN) 
     
    3639#endif 
    3740 
     41#if 0 
    3842#ifdef XP_WIN 
    3943    /* Windows stuff */ 
     
    5155#   include <X11/StringDefs.h> 
    5256#endif 
     57#endif 
    5358 
    5459class VlcPlugin 
    5560{ 
    5661public: 
    57              VlcPlugin( NPP );  
     62             VlcPlugin( NPP, uint16 );  
    5863    virtual ~VlcPlugin(); 
    5964 
    60     void     SetInstance( NPP ); 
    61     NPP      GetInstance(); 
    62     VlcIntf* GetPeer(); 
     65    NPError             init(int argc, char* const argn[], char* const argv[]); 
     66    libvlc_instance_t*  getVLC()  
     67                            { return libvlc_instance; }; 
     68    NPP                 getBrowser() 
     69                            { return p_browser; }; 
     70    char*               getAbsoluteURL(const char *url); 
     71    const NPWindow*     getWindow() 
     72                            { return &npwindow; }; 
     73    void                setWindow(const NPWindow *window) 
     74                            { npwindow = *window; }; 
    6375 
    64     /* Window settings */ 
    65     NPWindow* p_npwin; 
    66     uint16    i_npmode; 
    67     uint32    i_width, i_height; 
     76    NPClass*            getScriptClass() 
     77                            { return scriptClass; }; 
    6878 
    69 #ifdef XP_WIN 
    70     /* Windows data members */ 
    71     HWND     p_hwnd; 
    72     WNDPROC  pf_wndproc; 
     79#if XP_WIN 
     80    WNDPROC             getWindowProc() 
     81                            { return pf_wndproc; }; 
     82    void                setWindowProc(WNDPROC wndproc) 
     83                            { pf_wndproc = wndproc; }; 
    7384#endif 
    7485 
    75 #ifdef XP_UNIX 
    76     /* UNIX data members */ 
    77     Window   window; 
    78     Display *p_display; 
     86#if XP_UNIX 
     87    int                 setSize(unsigned width, unsigned height); 
    7988#endif 
    8089 
    81 #ifdef XP_MACOSX 
    82     /* MACOS data members */ 
    83     NPWindow *window; 
    84 #endif 
     90    uint16    i_npmode; /* either NP_EMBED or NP_FULL */ 
    8591 
    86  
    87     /* vlc data members */ 
    88     int      i_vlc; 
     92    /* plugin properties */ 
    8993    int      b_stream; 
    9094    int      b_autoplay; 
     
    9296 
    9397private: 
    94     NPP      p_instance; 
    95     VlcPeer* p_peer; 
     98    /* VLC reference */ 
     99    libvlc_instance_t *libvlc_instance; 
     100    NPClass           *scriptClass; 
     101 
     102    /* browser reference */ 
     103    NPP     p_browser; 
     104    char*   psz_baseURL; 
     105 
     106    /* display settings */ 
     107    NPWindow  npwindow; 
     108#if XP_WIN 
     109    WNDPROC   pf_wndproc; 
     110#endif 
     111#if XP_UNIX 
     112    unsigned int     i_width, i_height; 
     113#endif 
    96114}; 
    97115 
  • mozilla/vlcshell.cpp

    r31eaf45 ra593fa1  
    2222 *****************************************************************************/ 
    2323 
    24 /* XXX: disable VLC here */ 
    25 #define USE_LIBVLC 1 
    26  
    2724/***************************************************************************** 
    2825 * Preamble 
     
    3431#include <stdlib.h> 
    3532 
    36 /* vlc stuff */ 
    37 #ifdef USE_LIBVLC 
    38 #   include <vlc/vlc.h> 
    39 #endif 
    40  
    4133/* Mozilla stuff */ 
    4234#ifdef HAVE_MOZILLA_CONFIG_H 
    4335#   include <mozilla-config.h> 
    4436#endif 
    45 #include <nsISupports.h> 
    46 #include <nsMemory.h> 
    47 #include <npapi.h> 
    48 #include <npruntime.h> 
    4937 
    5038/* This is from mozilla java, do we really need it? */ 
     
    5442 
    5543#include "vlcplugin.h" 
    56 #include "vlcruntime.h" 
    57  
    58 #if USE_LIBVLC 
    59 #   define WINDOW_TEXT "(no picture)" 
    60 #else 
    61 #   define WINDOW_TEXT "(no libvlc)" 
    62 #endif 
    6344 
    6445/* Enable/disable debugging printf's for X11 resizing */ 
    6546#undef X11_RESIZE_DEBUG 
     47 
     48#define WINDOW_TEXT "(no video)" 
    6649 
    6750/***************************************************************************** 
     
    7255#   define AOUT_PLUGINS "esd,arts,alsa,oss,dummy" 
    7356 
    74 static unsigned int i_previous_height = 100000; 
    75 static unsigned int i_previous_width = 100000; 
    76  
    7757static void Redraw( Widget w, XtPointer closure, XEvent *event ); 
    7858static void Resize( Widget w, XtPointer closure, XEvent *event ); 
     59 
    7960#endif 
    8061 
     
    8566#   define VOUT_PLUGINS "opengl,macosx,dummy" 
    8667#   define AOUT_PLUGINS "auhal,macosx,dummy" 
    87  
    8868#endif 
    8969 
     
    9575#   define AOUT_PLUGINS "directx,waveout,dummy" 
    9676 
    97 #if defined(XP_WIN) && !USE_LIBVLC 
    98 LRESULT CALLBACK Manage( HWND, UINT, WPARAM, LPARAM ); 
    99 #endif 
     77static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar ); 
     78 
    10079#endif 
    10180 
     
    11190{ 
    11291 
    113     static nsIID nsid = VLCINTF_IID; 
    11492    static char psz_desc[1000]; 
    11593 
     94    /* plugin class variables */ 
    11695    switch( variable ) 
    11796    { 
     
    121100 
    122101        case NPPVpluginDescriptionString: 
    123 #if USE_LIBVLC 
    124             snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, VLC_Version() ); 
    125 #else /* USE_LIBVLC */ 
    126             snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, "(disabled)" ); 
    127 #endif /* USE_LIBVLC */ 
    128             psz_desc[1000-1] = 0; 
     102            snprintf( psz_desc, sizeof(psz_desc)-1, PLUGIN_DESCRIPTION, VLC_Version() ); 
     103            psz_desc[sizeof(psz_desc)-1] = 0; 
    129104            *((char **)value) = psz_desc; 
    130105            return NPERR_NO_ERROR; 
    131106 
    132107        default: 
    133             /* go on... */ 
     108            /* move on to instance variables ... */ 
    134109            break; 
    135110    } 
     
    140115    } 
    141116 
    142     VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata; 
     117    /* plugin instance variables */ 
     118 
     119    VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata); 
     120    if( NULL == p_plugin ) 
     121    { 
     122        // plugin has not been initialized yet ! 
     123        return NPERR_INVALID_INSTANCE_ERROR; 
     124    } 
    143125 
    144126    switch( variable ) 
    145127    { 
    146         case NPPVpluginScriptableInstance: 
    147             *(nsISupports**)value = p_plugin->GetPeer(); 
    148             if( *(nsISupports**)value == NULL ) 
     128        case NPPVp