Commit 5555c82c authored by Sam Hocevar's avatar Sam Hocevar

* ./mozilla/*: added hooks so that the vlc plugin is scriptable from

    javascript. It's also in C++, but we didn't have the choice.
parent cf891bad
...@@ -2028,9 +2028,9 @@ then ...@@ -2028,9 +2028,9 @@ then
LDFLAGS="${save_LDFLAGS}" LDFLAGS="${save_LDFLAGS}"
fi fi
MOZILLA=1 MOZILLA=1
mozilla_CFLAGS="${mozilla_CFLAGS} `${MOZILLA_CONFIG} --cflags plugin java --defines | xargs`"
dnl Workaround for http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=150490 dnl Workaround for http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=150490
mozilla_LDFLAGS="${mozilla_LDFLAGS} `${MOZILLA_CONFIG} --libs | sed 's#-I\(.*\)/mozilla/\([^ ]*\)#-I\1/\2 -I\1/mozilla/\2#g'`" [mozilla_CFLAGS="${CPPFLAGS_mozilla} `${MOZILLA_CONFIG} --cflags plugin xpcom java | sed 's,-I\([^ ]*\)/mozilla/\([^ ]*\),-I\1/\2 -I\1/mozilla/\2,g' | xargs`"]
mozilla_LDFLAGS="${mozilla_LDFLAGS} `${MOZILLA_CONFIG} --libs plugin xpcom`"
fi fi
fi fi
......
vlcintf.h
vlcintf.xpt
...@@ -6,10 +6,13 @@ ...@@ -6,10 +6,13 @@
# #
# Source objects # Source objects
# #
C_SRC = vlcplugin.c npunix.c CPP_SRC = vlcplugin.cpp vlcpeer.cpp vlcshell.cpp
C_SRC = npunix.c
CPP_OBJ = $(CPP_SRC:%.cpp=%.o)
C_OBJ = $(C_SRC:%.c=%.o) C_OBJ = $(C_SRC:%.c=%.o)
PLUGIN_OBJ = libvlcplugin.so PLUGIN_OBJ = libvlcplugin.so
COMPONENT = vlcintf.xpt
# #
# Virtual targets # Virtual targets
...@@ -25,20 +28,35 @@ clean: ...@@ -25,20 +28,35 @@ clean:
install: install:
mkdir -p $(DESTDIR)$(libdir)/mozilla/plugins mkdir -p $(DESTDIR)$(libdir)/mozilla/plugins
$(INSTALL) -m 644 $(PLUGIN_OBJ) $(DESTDIR)$(libdir)/mozilla/plugins $(INSTALL) -m 644 $(PLUGIN_OBJ) $(DESTDIR)$(libdir)/mozilla/plugins
mkdir -p $(DESTDIR)$(libdir)/mozilla/components
$(INSTALL) -m 644 $(COMPONENT) $(DESTDIR)$(libdir)/mozilla/components
uninstall: uninstall:
rm -f $(DESTDIR)$(libdir)/mozilla/plugins/$(PLUGIN_OBJ) rm -f $(DESTDIR)$(libdir)/mozilla/plugins/$(PLUGIN_OBJ)
-rmdir $(DESTDIR)$(libdir)/mozilla/plugins -rmdir $(DESTDIR)$(libdir)/mozilla/plugins
rm -f $(DESTDIR)$(libdir)/mozilla/components/$(COMPONENT)
-rmdir $(DESTDIR)$(libdir)/mozilla/components
-rmdir $(DESTDIR)$(libdir)/mozilla -rmdir $(DESTDIR)$(libdir)/mozilla
FORCE: FORCE:
$(PLUGIN_OBJ): Makefile ../lib/libvlc.a $(BUILTIN_OBJ:%=../%) $(C_OBJ) $(PLUGIN_OBJ): Makefile ../lib/libvlc.a $(BUILTIN_OBJ:%=../%) $(C_OBJ) $(CPP_OBJ) $(COMPONENT)
$(CC) -shared $(LDFLAGS) -L../lib $(mozilla_LDFLAGS) $(C_OBJ) -lvlc $(BUILTIN_OBJ:%=../%) $(builtins_LDFLAGS) -o $@ $(CC) -shared $(LDFLAGS) -L../lib $(mozilla_LDFLAGS) $(C_OBJ) $(CPP_OBJ) -lvlc $(BUILTIN_OBJ:%=../%) $(builtins_LDFLAGS) -o $@
$(C_OBJ): %.o: %.c vlcplugin.h $(CPP_OBJ): %.o: %.cpp vlcplugin.h vlcpeer.h vlcintf.h classinfo.h
$(CC) $(CFLAGS) -I.. -I../include $(mozilla_CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -I.. -I../include $(mozilla_CFLAGS) -c $< -o $@
$(C_OBJ): %.o: %.c vlcplugin.h vlcpeer.h vlcintf.h classinfo.h
$(CC) $(CFLAGS) -I.. -I../include $(mozilla_CFLAGS) -c $< -o $@
vlcintf.xpt: vlcintf.idl
/usr/lib/mozilla/xpidl -I/usr/share/idl/mozilla -m typelib \
-o vlcintf vlcintf.idl
vlcintf.h: vlcintf.idl
/usr/lib/mozilla/xpidl -I/usr/share/idl/mozilla -m header \
-o vlcintf vlcintf.idl
../%: ../%:
@cd .. && $(MAKE) $(@:../%=%) @cd .. && $(MAKE) $(@:../%=%)
#include "nsIClassInfo.h"
// helper class to implement all necessary nsIClassInfo method stubs
// and to set flags used by the security system
class ClassInfo : public nsIClassInfo
{
// These flags are used by the DOM and security systems to signal that
// JavaScript callers are allowed to call this object's scritable methods.
NS_IMETHOD GetFlags(PRUint32 *aFlags)
{*aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
return NS_OK;}
NS_IMETHOD GetImplementationLanguage(PRUint32 *aImplementationLanguage)
{*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
return NS_OK;}
// The rest of the methods can safely return error codes...
NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetContractID(char * *aContractID)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetClassDescription(char * *aClassDescription)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetClassID(nsCID * *aClassID)
{return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
{return NS_ERROR_NOT_IMPLEMENTED;}
};
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Stephen Mak <smak@sun.com>
*/
/* /*
* npunix.c * npunix.c
* *
...@@ -70,12 +93,25 @@ NPN_GetValue(NPP instance, NPNVariable variable, void *r_value) ...@@ -70,12 +93,25 @@ NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
instance, variable, r_value); instance, variable, r_value);
} }
NPError
NPN_SetValue(NPP instance, NPPVariable variable, void *value)
{
return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
instance, variable, value);
}
NPError NPError
NPN_GetURL(NPP instance, const char* url, const char* window) NPN_GetURL(NPP instance, const char* url, const char* window)
{ {
return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window); return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
} }
NPError
NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
{
return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
}
NPError NPError
NPN_PostURL(NPP instance, const char* url, const char* window, NPN_PostURL(NPP instance, const char* url, const char* window,
uint32 len, const char* buf, NPBool file) uint32 len, const char* buf, NPBool file)
...@@ -84,6 +120,14 @@ NPN_PostURL(NPP instance, const char* url, const char* window, ...@@ -84,6 +120,14 @@ NPN_PostURL(NPP instance, const char* url, const char* window,
url, window, len, buf, file); url, window, len, buf, file);
} }
NPError
NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len,
const char* buf, NPBool file, void* notifyData)
{
return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
instance, url, window, len, buf, file, notifyData);
}
NPError NPError
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{ {
...@@ -157,6 +201,27 @@ jref NPN_GetJavaPeer(NPP instance) ...@@ -157,6 +201,27 @@ jref NPN_GetJavaPeer(NPP instance)
instance); instance);
} }
void
NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
{
CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
invalidRect);
}
void
NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
{
CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
invalidRegion);
}
void
NPN_ForceRedraw(NPP instance)
{
CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
}
/*********************************************************************** /***********************************************************************
* *
...@@ -241,6 +306,16 @@ Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) ...@@ -241,6 +306,16 @@ Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
return err; return err;
} }
void
Private_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData)
{
PLUGINDEBUGSTR("URLNotify");
NPP_URLNotify(instance, url, reason, notifyData);
}
void void
Private_Print(NPP instance, NPPrint* platformPrint) Private_Print(NPP instance, NPPrint* platformPrint)
...@@ -249,6 +324,13 @@ Private_Print(NPP instance, NPPrint* platformPrint) ...@@ -249,6 +324,13 @@ Private_Print(NPP instance, NPPrint* platformPrint)
NPP_Print(instance, platformPrint); NPP_Print(instance, platformPrint);
} }
NPError
Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
{
PLUGINDEBUGSTR("GetValue");
return NPP_GetValue(instance, variable, r_value);
}
JRIGlobalRef JRIGlobalRef
Private_GetJavaClass(void) Private_GetJavaClass(void)
{ {
...@@ -285,7 +367,7 @@ NP_GetMIMEDescription(void) ...@@ -285,7 +367,7 @@ NP_GetMIMEDescription(void)
* that the navigator needs. * that the navigator needs.
*/ */
NPError NPError
NP_GetValue(void *future, NPPVariable variable, void *value) NP_GetValue(NPP future, NPPVariable variable, void *value)
{ {
return NPP_GetValue(future, variable, value); return NPP_GetValue(future, variable, value);
} }
...@@ -350,6 +432,7 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) ...@@ -350,6 +432,7 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
gNetscapeFuncs.size = nsTable->size; gNetscapeFuncs.size = nsTable->size;
gNetscapeFuncs.posturl = nsTable->posturl; gNetscapeFuncs.posturl = nsTable->posturl;
gNetscapeFuncs.geturl = nsTable->geturl; gNetscapeFuncs.geturl = nsTable->geturl;
gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
gNetscapeFuncs.requestread = nsTable->requestread; gNetscapeFuncs.requestread = nsTable->requestread;
gNetscapeFuncs.newstream = nsTable->newstream; gNetscapeFuncs.newstream = nsTable->newstream;
gNetscapeFuncs.write = nsTable->write; gNetscapeFuncs.write = nsTable->write;
...@@ -381,8 +464,10 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) ...@@ -381,8 +464,10 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady); pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
pluginFuncs->write = NewNPP_WriteProc(Private_Write); pluginFuncs->write = NewNPP_WriteProc(Private_Write);
pluginFuncs->print = NewNPP_PrintProc(Private_Print); pluginFuncs->print = NewNPP_PrintProc(Private_Print);
pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
pluginFuncs->event = NULL; pluginFuncs->event = NULL;
pluginFuncs->javaClass = Private_GetJavaClass(); pluginFuncs->javaClass = Private_GetJavaClass();
pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
err = NPP_Initialize(); err = NPP_Initialize();
} }
......
#include "nsISupports.idl"
[scriptable, uuid(ea92ef52-afe4-4212-bacb-dfe9fca94cd6)]
interface VlcIntf : nsISupports
{
void play();
void pause();
void stop();
};
/*****************************************************************************
* vlcpeer.cpp: a VideoLAN Client plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: vlcpeer.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <vlc/vlc.h>
#include "npapi.h"
#include "vlcpeer.h"
#include "vlcplugin.h"
#include "nsMemory.h"
NS_IMPL_ISUPPORTS2( VlcPeer, VlcIntf, nsIClassInfo )
VlcPeer::VlcPeer()
{
NS_INIT_ISUPPORTS();
}
VlcPeer::VlcPeer( VlcPlugin * plugin )
{
NS_INIT_ISUPPORTS();
p_plugin = plugin;
}
VlcPeer::~VlcPeer()
{
;
}
NS_IMETHODIMP VlcPeer::Play()
{
if( p_plugin )
{
p_plugin->Play();
}
return NS_OK;
}
NS_IMETHODIMP VlcPeer::Pause()
{
if( p_plugin )
{
p_plugin->Pause();
}
return NS_OK;
}
NS_IMETHODIMP VlcPeer::Stop()
{
if( p_plugin )
{
p_plugin->Stop();
}
return NS_OK;
}
/*****************************************************************************
* vlcpeer.h: a VideoLAN plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: vlcpeer.h,v 1.1 2002/09/17 08:18:24 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include "vlcintf.h"
#include "classinfo.h"
#include "nsMemory.h"
class VlcPlugin;
class VlcPeer : public VlcIntf, public ClassInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_VLCINTF
VlcPeer();
VlcPeer( VlcPlugin * );
void Disable() { p_plugin = NULL; }
virtual ~VlcPeer();
/* additional members */
private:
VlcPlugin * p_plugin;
};
/*****************************************************************************
* vlcplugin.cpp: a VideoLAN Client plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: vlcplugin.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <npapi.h>
#include <vlc/vlc.h>
#include "vlcpeer.h"
#include "vlcplugin.h"
/*****************************************************************************
* VlcPlugin methods
*****************************************************************************/
VlcPlugin::VlcPlugin( NPP instance )
{
p_instance = instance;
p_peer = NULL;
}
VlcPlugin::~VlcPlugin()
{
if( p_peer )
{
p_peer->Disable();
p_peer->Release();
}
}
void VlcPlugin::SetInstance( NPP instance )
{
p_instance = instance;
}
NPP VlcPlugin::GetInstance()
{
return p_instance;
}
void VlcPlugin::SetFileName(const char * filename)
{
fprintf(stderr, "VlcPlugin::SetFilename %s\n", filename);
#if 0
FILE * fh;
fh = fopen(filename, "rb");
if(!fh)
{
fprintf(stderr, "Error while opening %s.\n", filename);
return;
}
fseek(fh, 0, SEEK_END);
m_lSize = ftell(fh);
m_szSound = (char*) malloc(m_lSize);
if(!m_szSound)
{
fprintf(stderr, "Error while allocating memory.\n");
fclose(fh);
return;
}
rewind(fh);
long pos = 0;
do
{
pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
fprintf(stderr, "pos = %d\n", pos);
}
while (pos < m_lSize -1);
fclose (fh);
fprintf(stderr, "File loaded\n");
#endif
return;
}
void VlcPlugin::Play()
{
fprintf(stderr, "VlcPlugin::Play\n");
}
void VlcPlugin::Pause()
{
fprintf(stderr, "VlcPlugin::Pause\n");
}
void VlcPlugin::Stop()
{
fprintf(stderr, "VlcPlugin::Stop\n");
}
VlcIntf* VlcPlugin::getScriptable()
{
if( !p_peer )
{
p_peer = new VlcPeer( this );
if( p_peer == NULL )
{
return NULL;
}
NS_ADDREF( p_peer );
}
// a getter should addref for its caller.
NS_ADDREF( p_peer );
return p_peer;
}
/***************************************************************************** /*****************************************************************************
* videolan.c: a VideoLAN plugin for Mozilla * vlcplugin.h: a VideoLAN plugin for Mozilla
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: vlcplugin.h,v 1.2 2002/07/23 20:12:55 sam Exp $ * $Id: vlcplugin.h,v 1.3 2002/09/17 08:18:24 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -24,8 +24,23 @@ ...@@ -24,8 +24,23 @@
/******************************************************************************* /*******************************************************************************
* Instance state information about the plugin. * Instance state information about the plugin.
******************************************************************************/ ******************************************************************************/
typedef struct _PluginInstance class VlcPlugin
{ {
public:
VlcPlugin( NPP );
virtual ~VlcPlugin();
void SetInstance( NPP );
NPP GetInstance();
void SetFileName( const char* );
void Play();
void Pause();
void Stop();
VlcIntf* getScriptable();
/* Window settings */
NPWindow* fWindow; NPWindow* fWindow;
uint16 fMode; uint16 fMode;
...@@ -36,11 +51,14 @@ typedef struct _PluginInstance ...@@ -36,11 +51,14 @@ typedef struct _PluginInstance
uint32 width, height; uint32 width, height;
/* vlc data members */ /* vlc data members */
vlc_t *p_vlc; vlc_t * p_vlc;
int b_stream; int b_stream;
char *psz_target; char * psz_target;
} PluginInstance; private:
NPP p_instance;
VlcPeer* p_peer;
};
/******************************************************************************* /*******************************************************************************
* Plugin properties. * Plugin properties.
...@@ -49,7 +67,7 @@ typedef struct _PluginInstance ...@@ -49,7 +67,7 @@ typedef struct _PluginInstance
#define PLUGIN_DESCRIPTION \ #define PLUGIN_DESCRIPTION \
"VideoLAN Client Multimedia Player Plugin <br>" \ "VideoLAN Client Multimedia Player Plugin <br>" \
" <br>" \ " <br>" \
COPYRIGHT_MESSAGE " <br>" \ /*COPYRIGHT_MESSAGE*/ " <br>" \
"VideoLAN WWW: <a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>" "VideoLAN WWW: <a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
#define PLUGIN_MIMETYPES \ #define PLUGIN_MIMETYPES \
......
/***************************************************************************** /*****************************************************************************
* vlcplugin.c: a VideoLAN Client plugin for Mozilla * vlcshell.c: a VideoLAN Client plugin for Mozilla
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: vlcplugin.c,v 1.5 2002/08/20 18:08:51 sam Exp $ * $Id: vlcshell.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -37,59 +37,119 @@ ...@@ -37,59 +37,119 @@
/* vlc stuff */ /* vlc stuff */
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include "config.h"
#include "vlcpeer.h"
#include "vlcplugin.h" #include "vlcplugin.h"
/******************************************************************************* /******************************************************************************
* Unix-only declarations * Unix-only declarations
******************************************************************************/ ******************************************************************************/
#ifndef WIN32
static void Redraw( Widget w, XtPointer closure, XEvent *event ); static void Redraw( Widget w, XtPointer closure, XEvent *event );
#endif
/******************************************************************************
* Windows-only declarations
*****************************************************************************/
#ifdef WIN32
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;
}
#endif
/******************************************************************************
* UNIX-only API calls * UNIX-only API calls
******************************************************************************/ *****************************************************************************/
char* NPP_GetMIMEDescription( void ) char * NPP_GetMIMEDescription( void )
{ {
return( PLUGIN_MIMETYPES ); return PLUGIN_MIMETYPES;
} }
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
{ {
NPError err = NPERR_NO_ERROR; static nsIID nsid = VLCINTF_IID;
if (variable == NPPVpluginNameString)
switch( variable )
{
case NPPVpluginNameString:
*((char **)value) = PLUGIN_NAME; *((char **)value) = PLUGIN_NAME;
else if (variable == NPPVpluginDescriptionString) return NPERR_NO_ERROR;
case NPPVpluginDescriptionString:
*((char **)value) = PLUGIN_DESCRIPTION; *((char **)value) = PLUGIN_DESCRIPTION;
else return NPERR_NO_ERROR;
err = NPERR_GENERIC_ERROR; }
return err; if( instance == NULL )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
switch( variable )
{
case NPPVpluginScriptableInstance:
*(nsISupports**)value = p_plugin->getScriptable();
if( *(nsISupports**)value == NULL )
{
return NPERR_OUT_OF_MEMORY_ERROR;
}
break;
case NPPVpluginScriptableIID:
*(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
if( *(nsIID**)value == NULL )
{
return NPERR_OUT_OF_MEMORY_ERROR;
}
**(nsIID**)value = nsid;
break;
default:
return NPERR_GENERIC_ERROR;
}
return NPERR_NO_ERROR;
} }
/******************************************************************************* /******************************************************************************
* General Plug-in Calls * General Plug-in Calls
******************************************************************************/ *****************************************************************************/
NPError NPP_Initialize( void ) NPError NPP_Initialize( void )
{ {
fprintf(stderr, "NPP_Initialize\n");
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
jref NPP_GetJavaClass( void ) jref NPP_GetJavaClass( void )
{ {
return NULL; /* Java disabled */ return NULL;
} }
void NPP_Shutdown( void ) void NPP_Shutdown( void )
{ {
/* Java disabled */ ;
} }
NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
char* argn[], char* argv[], NPSavedData* saved ) char* argn[], char* argv[], NPSavedData* saved )
{ {
NPError result = NPERR_NO_ERROR;
PluginInstance* This;
int i_ret; int i_ret;
int i; int i;
...@@ -98,122 +158,130 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, ...@@ -98,122 +158,130 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
"vlc" "vlc"
/*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/ /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
, "--vout", "xvideo,x11,dummy" , "--vout", "xvideo,x11,dummy"
/*, "--aout", "none"*/
, "--intf", "dummy" , "--intf", "dummy"
, "--noaudio" /*, "--noaudio"*/
, "-q"
/*, "-v"*/ /*, "-v"*/
}; };
fprintf(stderr, "NPP_New\n"); if( instance == NULL )
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
instance->pdata = NPN_MemAlloc(sizeof(PluginInstance)); VlcPlugin * p_plugin = new VlcPlugin( instance );
This = (PluginInstance*) instance->pdata;
if (This == NULL) if( p_plugin == NULL )
{
return NPERR_OUT_OF_MEMORY_ERROR; return NPERR_OUT_OF_MEMORY_ERROR;
}
{ instance->pdata = p_plugin;
/* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
This->fMode = mode;
This->fWindow = NULL;
This->window = 0; p_plugin->fMode = mode;
} p_plugin->fWindow = NULL;
p_plugin->window = 0;
This->p_vlc = vlc_create_r(); p_plugin->p_vlc = vlc_create_r();
if( This->p_vlc == NULL ) if( p_plugin->p_vlc == NULL )
{ {
delete p_plugin;
p_plugin = NULL;
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
i_ret = vlc_init_r( This->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo ); i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
if( i_ret ) if( i_ret )
{ {
vlc_destroy_r( This->p_vlc ); vlc_destroy_r( p_plugin->p_vlc );
This->p_vlc = NULL; p_plugin->p_vlc = NULL;
delete p_plugin;
p_plugin = NULL;
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
vlc_set_r( This->p_vlc, "vout", "xvideo,x11,dummy" ); vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
vlc_set_r( This->p_vlc, "intf", "dummy" ); vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
vlc_set_r( This->p_vlc, "audio", 0 ); vlc_set_r( p_plugin->p_vlc, "audio", "0" );
i_ret = vlc_run_r( This->p_vlc ); i_ret = vlc_run_r( p_plugin->p_vlc );
if( i_ret ) if( i_ret )
{ {
vlc_destroy_r( This->p_vlc ); vlc_destroy_r( p_plugin->p_vlc );
This->p_vlc = NULL; p_plugin->p_vlc = NULL;
delete p_plugin;
p_plugin = NULL;
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
This->b_stream = 0; p_plugin->b_stream = 0;
This->psz_target = NULL; p_plugin->psz_target = NULL;
for( i = 0; i < argc ; i++ ) for( i = 0; i < argc ; i++ )
{ {
fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]); fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
if(!strcmp(argn[i],"target")) if( !strcmp(argn[i],"target") )
{ {
fprintf(stderr, "target specified: %s\n", argv[i]); fprintf(stderr, "target specified: %s\n", argv[i]);
This->psz_target = strdup( argv[i] ); p_plugin->psz_target = strdup( argv[i] );
} }
else else
{ {
/*vlc_set_r( This->psz_target, argn[i], argv[i] );*/ /*vlc_set_r( p_plugin->psz_target, argn[i], argv[i] );*/
} }
} }
return result; return NPERR_NO_ERROR;
} }
NPError NPP_Destroy( NPP instance, NPSavedData** save ) NPError NPP_Destroy( NPP instance, NPSavedData** save )
{ {
PluginInstance* This; if( instance == NULL )
{
fprintf(stderr, "NPP_Destroy\n");
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
This = (PluginInstance*) instance->pdata; VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
if( This->p_vlc != NULL ) if( p_plugin != NULL )
{
if( p_plugin->p_vlc != NULL )
{ {
vlc_destroy_r( This->p_vlc ); vlc_destroy_r( p_plugin->p_vlc );
This->p_vlc = NULL; p_plugin->p_vlc = NULL;
} }
if( This->psz_target ) if( p_plugin->psz_target )
{ {
free( This->psz_target ); free( p_plugin->psz_target );
This->psz_target = NULL; p_plugin->psz_target = NULL;
} }
if (This != NULL) { delete p_plugin;
NPN_MemFree(instance->pdata);
instance->pdata = NULL;
} }
instance->pdata = NULL;
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
NPError NPP_SetWindow( NPP instance, NPWindow* window ) NPError NPP_SetWindow( NPP instance, NPWindow* window )
{ {
NPError result = NPERR_NO_ERROR; char psz_window[32];
PluginInstance* This;
fprintf(stderr, "NPP_SetWindow\n");
if (instance == NULL) if( instance == NULL )
{
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
This = (PluginInstance*) instance->pdata; /* Write the window ID for vlc */
sprintf( psz_window, "%li", (long int)window->window );
vlc_set_r( p_plugin->p_vlc, "x11-drawable", psz_window );
vlc_set_r( p_plugin->p_vlc, "xvideo-drawable", psz_window );
vlc_set_r( This->p_vlc, "x11-drawable", window->window );
vlc_set_r( This->p_vlc, "xvideo-drawable", window->window );
/* /*
* PLUGIN DEVELOPERS: * PLUGIN DEVELOPERS:
* Before setting window to point to the * Before setting window to point to the
...@@ -222,78 +290,64 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) ...@@ -222,78 +290,64 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
* size changes, etc. * size changes, etc.
*/ */
{
Widget netscape_widget; Widget netscape_widget;
This->window = (Window) window->window; p_plugin->window = (Window) window->window;
This->x = window->x; p_plugin->x = window->x;
This->y = window->y; p_plugin->y = window->y;
This->width = window->width; p_plugin->width = window->width;
This->height = window->height; p_plugin->height = window->height;
This->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display; p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
netscape_widget = XtWindowToWidget(This->display, This->window); netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, This); XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
Redraw(netscape_widget, (XtPointer)This, NULL); Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
}
This->fWindow = window; p_plugin->fWindow = window;
#if 1 #if 1
if( !This->b_stream ) if( !p_plugin->b_stream )
{ {
This->b_stream = 1; p_plugin->b_stream = 1;
if( This->psz_target ) if( p_plugin->psz_target )
{ {
vlc_add_target_r( This->p_vlc, This->psz_target, PLAYLIST_APPEND, PLAYLIST_END ); vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
/* We loop, dude */ PLAYLIST_APPEND, PLAYLIST_END );
vlc_add_target_r( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END ); vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
PLAYLIST_APPEND, PLAYLIST_END );
} }
} }
#endif #endif
return result; return NPERR_NO_ERROR;
} }
NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream, NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
NPBool seekable, uint16 *stype ) NPBool seekable, uint16 *stype )
{ {
PluginInstance* This; if( instance == NULL )
{
fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
This = (PluginInstance*) instance->pdata; VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
/* We want a *filename* ! */ /* We want a *filename* ! */
*stype = NP_ASFILE; *stype = NP_ASFILE;
#if 0 #if 0
if( This->b_stream == 0 ) if( p_plugin->b_stream == 0 )
{ {
This->psz_target = strdup( stream->url ); p_plugin->psz_target = strdup( stream->url );
This->b_stream = 1; p_plugin->b_stream = 1;
} }
#endif #endif
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
/* PLUGIN DEVELOPERS:
* These next 2 functions are directly relevant in a plug-in which
* handles the data in a streaming manner. If you want zero bytes
* because no buffer space is YET available, return 0. As long as
* the stream has not been written to the plugin, Navigator will
* continue trying to send bytes. If the plugin doesn't want them,
* just return some large number from NPP_WriteReady(), and
* ignore them in NPP_Write(). For a NP_ASFILE stream, they are
* still called but can safely be ignored using this strategy.
*/
int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
* mode so we can take any size stream in our * mode so we can take any size stream in our
* write call (since we ignore it) */ * write call (since we ignore it) */
...@@ -302,13 +356,13 @@ int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile ...@@ -302,13 +356,13 @@ int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
int32 NPP_WriteReady( NPP instance, NPStream *stream ) int32 NPP_WriteReady( NPP instance, NPStream *stream )
{ {
PluginInstance* This; VlcPlugin* p_plugin;
fprintf(stderr, "NPP_WriteReady\n"); fprintf(stderr, "NPP_WriteReady\n");
if (instance != NULL) if (instance != NULL)
{ {
This = (PluginInstance*) instance->pdata; p_plugin = (VlcPlugin*) instance->pdata;
/* Muahahahahahahaha */ /* Muahahahahahahaha */
return STREAMBUFSIZE; return STREAMBUFSIZE;
/*return SARASS_SIZE;*/ /*return SARASS_SIZE;*/
...@@ -327,7 +381,7 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset, ...@@ -327,7 +381,7 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
if (instance != NULL) if (instance != NULL)
{ {
/*PluginInstance* This = (PluginInstance*) instance->pdata;*/ /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
} }
return len; /* The number of bytes accepted */ return len; /* The number of bytes accepted */
...@@ -336,12 +390,12 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset, ...@@ -336,12 +390,12 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
{ {
PluginInstance* This; if( instance == NULL )
fprintf(stderr, "NPP_DestroyStream\n"); {
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
This = (PluginInstance*) instance->pdata; }
VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
...@@ -349,27 +403,50 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) ...@@ -349,27 +403,50 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
{ {
PluginInstance* This; if( instance == NULL )
fprintf(stderr, "NPP_StreamAsFile\n");
if (instance != NULL)
{ {
This = (PluginInstance*) instance->pdata; return;
vlc_add_target_r( This->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
/* We loop, dude */
vlc_add_target_r( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END );
} }
VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
fprintf(stderr, "NPP_StreamAsFile\n");
vlc_add_target_r( p_plugin->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
PLAYLIST_APPEND, PLAYLIST_END );
} }
#if 0
void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
{
fprintf(stderr,"filename : %s\n", fname);
((VlcPlugin*) instance->pdata)->SetFileName(fname);
void NPP_Print( NPP instance, NPPrint* printInfo ) fprintf(stderr,"SetFileNeme ok. \n");
}
#endif
void NPP_URLNotify( NPP instance, const char* url,
NPReason reason, void* notifyData )
{ {
fprintf(stderr, "NPP_Print\n"); /***** Insert NPP_URLNotify code here *****\
PluginInstance* p_plugin;
if (instance != NULL)
p_plugin = (PluginInstance*) instance->pdata;
\*********************************************/
}
void NPP_Print( NPP instance, NPPrint* printInfo )
{
if(printInfo == NULL) if(printInfo == NULL)
return; return;
if (instance != NULL) { if (instance != NULL) {
PluginInstance* This = (PluginInstance*) instance->pdata; /***** Insert NPP_Print code here *****\
PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
\**************************************/
if (printInfo->mode == NP_FULL) { if (printInfo->mode == NP_FULL) {
/* /*
...@@ -389,10 +466,12 @@ void NPP_Print( NPP instance, NPPrint* printInfo ) ...@@ -389,10 +466,12 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
* etc. * etc.
*/ */
/***** Insert NPP_Print code here *****\
void* platformPrint = void* platformPrint =
printInfo->print.fullPrint.platformPrint; printInfo->print.fullPrint.platformPrint;
NPBool printOne = NPBool printOne =
printInfo->print.fullPrint.printOne; printInfo->print.fullPrint.printOne;
\**************************************/
/* Do the default*/ /* Do the default*/
printInfo->print.fullPrint.pluginPrinted = FALSE; printInfo->print.fullPrint.pluginPrinted = FALSE;
...@@ -410,56 +489,37 @@ void NPP_Print( NPP instance, NPPrint* printInfo ) ...@@ -410,56 +489,37 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
* device context. * device context.
*/ */
/***** Insert NPP_Print code here *****\
NPWindow* printWindow = NPWindow* printWindow =
&(printInfo->print.embedPrint.window); &(printInfo->print.embedPrint.window);
void* platformPrint = void* platformPrint =
printInfo->print.embedPrint.platformPrint; printInfo->print.embedPrint.platformPrint;
\**************************************/
} }
} }
} }
/******************************************************************************* /******************************************************************************
// NPP_URLNotify:
// Notifies the instance of the completion of a URL request.
//
// NPP_URLNotify is called when Netscape completes a NPN_GetURLNotify or
// NPN_PostURLNotify request, to inform the plug-in that the request,
// identified by url, has completed for the reason specified by reason. The most
// common reason code is NPRES_DONE, indicating simply that the request
// completed normally. Other possible reason codes are NPRES_USER_BREAK,
// indicating that the request was halted due to a user action (for example,
// clicking the "Stop" button), and NPRES_NETWORK_ERR, indicating that the
// request could not be completed (for example, because the URL could not be
// found). The complete list of reason codes is found in npapi.h.
//
// The parameter notifyData is the same plug-in-private value passed as an
// argument to the corresponding NPN_GetURLNotify or NPN_PostURLNotify
// call, and can be used by your plug-in to uniquely identify the request.
******************************************************************************/
void NPP_URLNotify( NPP instance, const char* url, NPReason reason,
void* notifyData )
{
}
/*******************************************************************************
* UNIX-only methods * UNIX-only methods
******************************************************************************/ *****************************************************************************/
#ifndef WIN32
static void Redraw( Widget w, XtPointer closure, XEvent *event ) static void Redraw( Widget w, XtPointer closure, XEvent *event )
{ {
PluginInstance* This = (PluginInstance*)closure; VlcPlugin* p_plugin = (VlcPlugin*)closure;
GC gc; GC gc;
XGCValues gcv; XGCValues gcv;
const char* text = "hello d00dZ, I'm in void Redraw()"; const char* text = "hello d00dZ, I'm in void Redraw()";
XtVaGetValues(w, XtNbackground, &gcv.background, XtVaGetValues(w, XtNbackground, &gcv.background,
XtNforeground, &gcv.foreground, 0); XtNforeground, &gcv.foreground, 0);
gc = XCreateGC(This->display, This->window, gc = XCreateGC(p_plugin->display, p_plugin->window,
GCForeground|GCBackground, &gcv); GCForeground|GCBackground, &gcv);
XDrawRectangle(This->display, This->window, gc, XDrawRectangle(p_plugin->display, p_plugin->window, gc,
0, 0, This->width-1, This->height-1); 0, 0, p_plugin->width-1, p_plugin->height-1);
XDrawString(This->display, This->window, gc, XDrawString(p_plugin->display, p_plugin->window, gc,
This->width/2 - 100, This->height/2, p_plugin->width/2 - 100, p_plugin->height/2,
text, strlen(text)); text, strlen(text));
return; return;
} }
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment