]> git.sesse.net Git - vlc/blobdiff - mozilla/vlcshell.cpp
* modules/audio_output/directx.c: don't use hardware buffers for <= 2 channels.
[vlc] / mozilla / vlcshell.cpp
index ab594092166bf26ca091f4138ef250d1f0574333..24401e6caf40a7d7189cf03066c65ad052bafde2 100644 (file)
@@ -2,7 +2,7 @@
  * vlcshell.cpp: a VLC plugin for Mozilla
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: vlcshell.cpp,v 1.12 2003/04/09 17:27:51 sam Exp $
+ * $Id: vlcshell.cpp,v 1.29 2004/01/25 17:52:17 gbazin Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include "config.h"
+
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 /* vlc stuff */
 #ifdef USE_LIBVLC
 #endif
 
 /* Mozilla stuff */
+#ifdef HAVE_MOZILLA_CONFIG_H
+#   include <mozilla-config.h>
+#endif
+#include <nsISupports.h>
+#include <nsMemory.h>
 #include <npapi.h>
+#include <jri.h>
+
+#if !defined(XP_MACOSX) && !defined(XP_UNIX) && !defined(XP_WIN)
+#define XP_UNIX 1
+#elif defined(XP_MACOSX)
+#undef XP_UNIX
+#endif
 
 #ifdef XP_WIN
     /* Windows stuff */
 #endif
 
+#ifdef XP_MACOSX
+    /* Mac OS X stuff */
+#   include <Quickdraw.h>
+#endif
+
 #ifdef XP_UNIX
     /* X11 stuff */
 #   include <X11/Xlib.h>
 #   include <X11/StringDefs.h>
 #endif
 
-#ifdef XP_MAC
-    /* Mac OS X stuff */
-#   include <QuickDraw.h>
-#endif
-
 #include "vlcpeer.h"
 #include "vlcplugin.h"
 
 static void Redraw( Widget w, XtPointer closure, XEvent *event );
 #endif
 
+/*****************************************************************************
+ * MacOS-only declarations
+******************************************************************************/
+#ifdef XP_MACOSX
+#   define VOUT_PLUGINS "macosx"
+#   define AOUT_PLUGINS "macosx"
+
+#endif
+
 /*****************************************************************************
  * Windows-only declarations
  *****************************************************************************/
 #ifdef XP_WIN
-#   define VOUT_PLUGINS "directx,dummy"
-#   define AOUT_PLUGINS "none" /* "directx,waveout,dummy" */
-
-HINSTANCE g_hDllInstance = NULL;
-
-BOOL WINAPI
-DllMain( HINSTANCE  hinstDLL,                   // handle of DLL module
-                    DWORD  fdwReason,       // reason for calling function
-                    LPVOID  lpvReserved)
-{
-    switch (fdwReason)
-    {
-        case DLL_PROCESS_ATTACH:
-            g_hDllInstance = hinstDLL;
-            break;
-        case DLL_THREAD_ATTACH:
-        case DLL_PROCESS_DETACH:
-        case DLL_THREAD_DETACH:
-            break;
-    }
-    return TRUE;
-}
+#   define VOUT_PLUGINS "directx,wingdi,dummy"
+#   define AOUT_PLUGINS "directx,waveout,dummy"
 
+#if defined(XP_WIN) && !USE_LIBVLC
 LRESULT CALLBACK Manage( HWND, UINT, WPARAM, LPARAM );
 #endif
+#endif
 
 /******************************************************************************
  * UNIX-only API calls
@@ -113,6 +119,7 @@ char * NPP_GetMIMEDescription( void )
 
 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 {
+
     static nsIID nsid = VLCINTF_IID;
     static char psz_desc[1000];
 
@@ -173,23 +180,27 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 /******************************************************************************
  * Mac-only API calls
  *****************************************************************************/
-#ifdef XP_MAC
+#ifdef XP_MACOSX
 int16 NPP_HandleEvent( NPP instance, void * event )
 {
+    VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
+    vlc_value_t value;
+
     if( instance == NULL )
     {
         return false;
     }
 
-    Boolean eventHandled = false;
+    EventRecord *pouetEvent = (EventRecord*)event;
 
-#if 0
-    TPlugin *pPlugin = (TPlugin*)instance->pdata;
-    if( pPlugin != NULL && event != NULL )
+    if (pouetEvent->what == 6)
     {
-        eventHandled = pPlugin->HandleEvent( *(EventRecord*)event );
+        value.i_int = 1;
+        VLC_Set( p_plugin->i_vlc, "drawableredraw", value );
+        return true;
     }
-#endif
+
+    Boolean eventHandled = false;
 
     return eventHandled;
 }
@@ -217,15 +228,11 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
                  char* argn[], char* argv[], NPSavedData* saved )
 {
     int i;
+
 #if USE_LIBVLC
     vlc_value_t value;
     int i_ret;
 
-    char *ppsz_foo[] =
-    {
-        "vlc"
-        /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
-    };
 #endif
 
     if( instance == NULL )
@@ -267,7 +274,64 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
         return NPERR_GENERIC_ERROR;
     }
 
-    i_ret = VLC_Init( p_plugin->i_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
+    {
+#ifdef XP_MACOSX
+        char *home_user;
+        char *directory;
+        char *plugin_path;
+        char *ppsz_argv[] = { "vlc", "--plugin-path", NULL };
+
+        home_user = strdup( getenv("HOME") );
+        directory = strdup( "/Library/Internet Plug-Ins/VLC Plugin.plugin/"
+                            "Contents/MacOS/modules" );
+        plugin_path = malloc( strlen( directory ) + strlen( home_user ) );
+        memcpy( plugin_path , home_user , strlen(home_user) );
+        memcpy( plugin_path + strlen( home_user ) , directory ,
+                strlen( directory ) );
+
+        ppsz_argv[2] = plugin_path;
+
+#elif defined(XP_WIN)
+        char *ppsz_argv[] = { NULL, "-vv" };
+        HKEY h_key;
+        DWORD i_type, i_data = MAX_PATH + 1;
+        char p_data[MAX_PATH + 1];
+        if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
+                          0, KEY_READ, &h_key ) == ERROR_SUCCESS )
+        {
+             if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
+                                  (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
+             {
+                 if( i_type == REG_SZ )
+                 {
+                     strcat( p_data, "\\vlc" );
+                     ppsz_argv[0] = p_data;
+                 }
+             }
+             RegCloseKey( h_key );
+        }
+
+        if( !ppsz_argv[0] ) ppsz_argv[0] = "vlc";
+
+#else
+        char *ppsz_argv[] =
+        {
+            "vlc"
+            /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
+        };
+
+#endif
+
+        i_ret = VLC_Init( p_plugin->i_vlc, sizeof(ppsz_argv)/sizeof(char*),
+                          ppsz_argv );
+
+#ifdef XP_MACOSX
+        free( home_user );
+        free( directory );
+        free( plugin_path );
+#endif
+    }
+
     if( i_ret )
     {
         VLC_Destroy( p_plugin->i_vlc );
@@ -378,6 +442,22 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
 
 NPError NPP_SetWindow( NPP instance, NPWindow* window )
 {
+    vlc_value_t value;
+#ifdef XP_MACOSX
+    vlc_value_t valuex;
+    vlc_value_t valuey;
+    vlc_value_t valuew;
+    vlc_value_t valueh;
+    vlc_value_t valuet;
+    vlc_value_t valuel;
+    vlc_value_t valueb;
+    vlc_value_t valuer;
+    vlc_value_t valueportx;
+    vlc_value_t valueporty;
+    Rect black_rect;
+    char * text;
+#endif
+
     if( instance == NULL )
     {
         return NPERR_INVALID_INSTANCE_ERROR;
@@ -387,11 +467,61 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
 
     /* Write the window ID for vlc */
 #if USE_LIBVLC
-    vlc_value_t value;
 
+#ifdef XP_MACOSX
+    value.i_int = ((NP_Port*) (window->window))->port;
+    VLC_Set( p_plugin->i_vlc, "drawable", value );
+
+    valueportx.i_int = ((NP_Port*) (window->window))->portx;
+    valueporty.i_int = ((NP_Port*) (window->window))->porty;
+    VLC_Set( p_plugin->i_vlc, "drawableportx", valueportx );
+    VLC_Set( p_plugin->i_vlc, "drawableporty", valueporty );
+
+    valuex.i_int = window->x;
+    valuey.i_int = window->y;
+    valuew.i_int = window->width;
+    valueh.i_int = window->height;
+    valuet.i_int = window->clipRect.top;
+    valuel.i_int = window->clipRect.left;
+    valueb.i_int = window->clipRect.bottom;
+    valuer.i_int = window->clipRect.right;
+
+    VLC_Set( p_plugin->i_vlc, "drawablet", valuet );
+    VLC_Set( p_plugin->i_vlc, "drawablel", valuel );
+    VLC_Set( p_plugin->i_vlc, "drawableb", valueb );
+    VLC_Set( p_plugin->i_vlc, "drawabler", valuer );
+    VLC_Set( p_plugin->i_vlc, "drawablex", valuex );
+    VLC_Set( p_plugin->i_vlc, "drawabley", valuey );
+    VLC_Set( p_plugin->i_vlc, "drawablew", valuew );
+    VLC_Set( p_plugin->i_vlc, "drawableh", valueh );
+
+    p_plugin->window = window;
+
+    /* draw the beautiful "No Picture" */
+
+    black_rect.top = valuet.i_int - valuey.i_int;
+    black_rect.left = valuel.i_int - valuex.i_int;
+    black_rect.bottom = valueb.i_int - valuey.i_int;
+    black_rect.right = valuer.i_int - valuex.i_int;
+
+    SetPort( value.i_int );
+    SetOrigin( valueportx.i_int , valueporty.i_int );
+    ForeColor(blackColor);
+    PenMode( patCopy );
+    PaintRect( &black_rect );
+
+    ForeColor(whiteColor);
+    text = strdup( WINDOW_TEXT );
+    MoveTo( valuew.i_int / 2 - 40 , valueh.i_int / 2 );
+    DrawText( text , 0 , strlen(text) );
+    free(text);
+
+#else
     /* FIXME: this cast sucks */
     value.i_int = (int) (ptrdiff_t) (void *) window->window;
     VLC_Set( p_plugin->i_vlc, "drawable", value );
+#endif
+
 #endif
 
     /*
@@ -408,8 +538,10 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         /* Window was destroyed. Invalidate everything. */
         if( p_plugin->p_npwin )
         {
+#if !USE_LIBVLC
             SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
                            (LONG)p_plugin->pf_wndproc );
+#endif
             p_plugin->pf_wndproc = NULL;
             p_plugin->p_hwnd = NULL;
         }
@@ -424,24 +556,31 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         {
             /* Same window, but something may have changed. First we
              * update the plugin structure, then we redraw the window */
-            InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
             p_plugin->i_width = window->width;
             p_plugin->i_height = window->height;
             p_plugin->p_npwin = window;
+#if !USE_LIBVLC
+            InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
             UpdateWindow( p_plugin->p_hwnd );
+#endif
             return NPERR_NO_ERROR;
         }
 
         /* Window has changed. Destroy the one we have, and go
          * on as if it was a real initialization. */
+#if !USE_LIBVLC
         SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
                        (LONG)p_plugin->pf_wndproc );
+#endif
         p_plugin->pf_wndproc = NULL;
         p_plugin->p_hwnd = NULL;
     }
 
+#if !USE_LIBVLC
     p_plugin->pf_wndproc = (WNDPROC)SetWindowLong( (HWND)window->window,
                                                    GWL_WNDPROC, (LONG)Manage );
+#endif
+
     p_plugin->p_hwnd = (HWND)window->window;
     SetProp( p_plugin->p_hwnd, "w00t", (HANDLE)p_plugin );
     InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
@@ -476,7 +615,7 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         {
 #if USE_LIBVLC
             VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target,
-                           i_mode, PLAYLIST_END );
+                           0, 0, i_mode, PLAYLIST_END );
 #endif
             p_plugin->b_stream = VLC_TRUE;
         }
@@ -576,7 +715,7 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
 #if USE_LIBVLC
     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
 
-    VLC_AddTarget( p_plugin->i_vlc, fname,
+    VLC_AddTarget( p_plugin->i_vlc, fname, 0, 0,
                    PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
 #endif
 }
@@ -663,14 +802,13 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
 /******************************************************************************
  * Windows-only methods
  *****************************************************************************/
-#ifdef XP_WIN
+#if defined(XP_WIN) && !USE_LIBVLC
 LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
 {
     VlcPlugin* p_plugin = (VlcPlugin*) GetProp( p_hwnd, "w00t" );
 
     switch( i_msg )
     {
-#if !USE_LIBVLC
         case WM_PAINT:
         {
             PAINTSTRUCT paintstruct;
@@ -687,7 +825,6 @@ LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
             EndPaint( p_hwnd, &paintstruct );
             break;
         }
-#endif
         default:
             p_plugin->pf_wndproc( p_hwnd, i_msg, wpar, lpar );
             break;