1 /*****************************************************************************
2 * vlcshell.c: a VideoLAN Client plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: vlcshell.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <plugin/npapi.h>
35 #include <X11/Intrinsic.h>
36 #include <X11/StringDefs.h>
43 #include "vlcplugin.h"
45 /******************************************************************************
46 * Unix-only declarations
47 ******************************************************************************/
49 static void Redraw( Widget w, XtPointer closure, XEvent *event );
52 /******************************************************************************
53 * Windows-only declarations
54 *****************************************************************************/
56 HINSTANCE g_hDllInstance = NULL;
59 DllMain( HINSTANCE hinstDLL, // handle of DLL module
60 DWORD fdwReason, // reason for calling function
64 case DLL_PROCESS_ATTACH:
65 g_hDllInstance = hinstDLL;
67 case DLL_THREAD_ATTACH:
68 case DLL_PROCESS_DETACH:
69 case DLL_THREAD_DETACH:
76 /******************************************************************************
78 *****************************************************************************/
79 char * NPP_GetMIMEDescription( void )
81 return PLUGIN_MIMETYPES;
84 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
86 static nsIID nsid = VLCINTF_IID;
90 case NPPVpluginNameString:
91 *((char **)value) = PLUGIN_NAME;
92 return NPERR_NO_ERROR;
94 case NPPVpluginDescriptionString:
95 *((char **)value) = PLUGIN_DESCRIPTION;
96 return NPERR_NO_ERROR;
99 if( instance == NULL )
101 return NPERR_INVALID_INSTANCE_ERROR;
104 VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
108 case NPPVpluginScriptableInstance:
109 *(nsISupports**)value = p_plugin->getScriptable();
110 if( *(nsISupports**)value == NULL )
112 return NPERR_OUT_OF_MEMORY_ERROR;
116 case NPPVpluginScriptableIID:
117 *(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
118 if( *(nsIID**)value == NULL )
120 return NPERR_OUT_OF_MEMORY_ERROR;
122 **(nsIID**)value = nsid;
126 return NPERR_GENERIC_ERROR;
129 return NPERR_NO_ERROR;
132 /******************************************************************************
133 * General Plug-in Calls
134 *****************************************************************************/
135 NPError NPP_Initialize( void )
137 return NPERR_NO_ERROR;
140 jref NPP_GetJavaClass( void )
145 void NPP_Shutdown( void )
150 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
151 char* argn[], char* argv[], NPSavedData* saved )
159 /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
160 , "--vout", "xvideo,x11,dummy"
161 /*, "--aout", "none"*/
168 if( instance == NULL )
170 return NPERR_INVALID_INSTANCE_ERROR;
173 VlcPlugin * p_plugin = new VlcPlugin( instance );
175 if( p_plugin == NULL )
177 return NPERR_OUT_OF_MEMORY_ERROR;
180 instance->pdata = p_plugin;
182 p_plugin->fMode = mode;
183 p_plugin->fWindow = NULL;
184 p_plugin->window = 0;
186 p_plugin->p_vlc = vlc_create_r();
187 if( p_plugin->p_vlc == NULL )
191 return NPERR_GENERIC_ERROR;
194 i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
197 vlc_destroy_r( p_plugin->p_vlc );
198 p_plugin->p_vlc = NULL;
201 return NPERR_GENERIC_ERROR;
204 vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
205 vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
206 vlc_set_r( p_plugin->p_vlc, "audio", "0" );
208 i_ret = vlc_run_r( p_plugin->p_vlc );
211 vlc_destroy_r( p_plugin->p_vlc );
212 p_plugin->p_vlc = NULL;
215 return NPERR_GENERIC_ERROR;
218 p_plugin->b_stream = 0;
219 p_plugin->psz_target = NULL;
221 for( i = 0; i < argc ; i++ )
223 fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
224 if( !strcmp(argn[i],"target") )
226 fprintf(stderr, "target specified: %s\n", argv[i]);
227 p_plugin->psz_target = strdup( argv[i] );
231 /*vlc_set_r( p_plugin->psz_target, argn[i], argv[i] );*/
235 return NPERR_NO_ERROR;
238 NPError NPP_Destroy( NPP instance, NPSavedData** save )
240 if( instance == NULL )
242 return NPERR_INVALID_INSTANCE_ERROR;
245 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
247 if( p_plugin != NULL )
249 if( p_plugin->p_vlc != NULL )
251 vlc_destroy_r( p_plugin->p_vlc );
252 p_plugin->p_vlc = NULL;
255 if( p_plugin->psz_target )
257 free( p_plugin->psz_target );
258 p_plugin->psz_target = NULL;
264 instance->pdata = NULL;
266 return NPERR_NO_ERROR;
269 NPError NPP_SetWindow( NPP instance, NPWindow* window )
273 if( instance == NULL )
275 return NPERR_INVALID_INSTANCE_ERROR;
278 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
280 /* Write the window ID for vlc */
281 sprintf( psz_window, "%li", (long int)window->window );
282 vlc_set_r( p_plugin->p_vlc, "x11-drawable", psz_window );
283 vlc_set_r( p_plugin->p_vlc, "xvideo-drawable", psz_window );
287 * Before setting window to point to the
288 * new window, you may wish to compare the new window
289 * info to the previous window (if any) to note window
293 Widget netscape_widget;
295 p_plugin->window = (Window) window->window;
296 p_plugin->x = window->x;
297 p_plugin->y = window->y;
298 p_plugin->width = window->width;
299 p_plugin->height = window->height;
300 p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
302 netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
303 XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
304 Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
306 p_plugin->fWindow = window;
309 if( !p_plugin->b_stream )
311 p_plugin->b_stream = 1;
312 if( p_plugin->psz_target )
314 vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
315 PLAYLIST_APPEND, PLAYLIST_END );
316 vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
317 PLAYLIST_APPEND, PLAYLIST_END );
322 return NPERR_NO_ERROR;
325 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
326 NPBool seekable, uint16 *stype )
328 if( instance == NULL )
330 return NPERR_INVALID_INSTANCE_ERROR;
333 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
335 fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
337 /* We want a *filename* ! */
341 if( p_plugin->b_stream == 0 )
343 p_plugin->psz_target = strdup( stream->url );
344 p_plugin->b_stream = 1;
348 return NPERR_NO_ERROR;
351 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
352 * mode so we can take any size stream in our
353 * write call (since we ignore it) */
355 #define SARASS_SIZE (1024*1024)
357 int32 NPP_WriteReady( NPP instance, NPStream *stream )
361 fprintf(stderr, "NPP_WriteReady\n");
363 if (instance != NULL)
365 p_plugin = (VlcPlugin*) instance->pdata;
366 /* Muahahahahahahaha */
367 return STREAMBUFSIZE;
368 /*return SARASS_SIZE;*/
371 /* Number of bytes ready to accept in NPP_Write() */
372 return STREAMBUFSIZE;
377 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
378 int32 len, void *buffer )
380 fprintf(stderr, "NPP_Write %i\n", len);
382 if (instance != NULL)
384 /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
387 return len; /* The number of bytes accepted */
391 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
393 if( instance == NULL )
395 return NPERR_INVALID_INSTANCE_ERROR;
398 VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
400 return NPERR_NO_ERROR;
404 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
406 if( instance == NULL )
411 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
413 fprintf(stderr, "NPP_StreamAsFile\n");
414 vlc_add_target_r( p_plugin->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
415 vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
416 PLAYLIST_APPEND, PLAYLIST_END );
420 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
422 fprintf(stderr,"filename : %s\n", fname);
423 ((VlcPlugin*) instance->pdata)->SetFileName(fname);
425 fprintf(stderr,"SetFileNeme ok. \n");
430 void NPP_URLNotify( NPP instance, const char* url,
431 NPReason reason, void* notifyData )
433 /***** Insert NPP_URLNotify code here *****\
434 PluginInstance* p_plugin;
435 if (instance != NULL)
436 p_plugin = (PluginInstance*) instance->pdata;
437 \*********************************************/
441 void NPP_Print( NPP instance, NPPrint* printInfo )
443 if(printInfo == NULL)
446 if (instance != NULL) {
447 /***** Insert NPP_Print code here *****\
448 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
449 \**************************************/
451 if (printInfo->mode == NP_FULL) {
454 * If your plugin would like to take over
455 * printing completely when it is in full-screen mode,
456 * set printInfo->pluginPrinted to TRUE and print your
457 * plugin as you see fit. If your plugin wants Netscape
458 * to handle printing in this case, set
459 * printInfo->pluginPrinted to FALSE (the default) and
460 * do nothing. If you do want to handle printing
461 * yourself, printOne is true if the print button
462 * (as opposed to the print menu) was clicked.
463 * On the Macintosh, platformPrint is a THPrint; on
464 * Windows, platformPrint is a structure
465 * (defined in npapi.h) containing the printer name, port,
469 /***** Insert NPP_Print code here *****\
470 void* platformPrint =
471 printInfo->print.fullPrint.platformPrint;
473 printInfo->print.fullPrint.printOne;
474 \**************************************/
477 printInfo->print.fullPrint.pluginPrinted = FALSE;
479 else { /* If not fullscreen, we must be embedded */
482 * If your plugin is embedded, or is full-screen
483 * but you returned false in pluginPrinted above, NPP_Print
484 * will be called with mode == NP_EMBED. The NPWindow
485 * in the printInfo gives the location and dimensions of
486 * the embedded plugin on the printed page. On the
487 * Macintosh, platformPrint is the printer port; on
488 * Windows, platformPrint is the handle to the printing
492 /***** Insert NPP_Print code here *****\
493 NPWindow* printWindow =
494 &(printInfo->print.embedPrint.window);
495 void* platformPrint =
496 printInfo->print.embedPrint.platformPrint;
497 \**************************************/
502 /******************************************************************************
504 *****************************************************************************/
506 static void Redraw( Widget w, XtPointer closure, XEvent *event )
508 VlcPlugin* p_plugin = (VlcPlugin*)closure;
511 const char* text = "hello d00dZ, I'm in void Redraw()";
513 XtVaGetValues(w, XtNbackground, &gcv.background,
514 XtNforeground, &gcv.foreground, 0);
515 gc = XCreateGC(p_plugin->display, p_plugin->window,
516 GCForeground|GCBackground, &gcv);
517 XDrawRectangle(p_plugin->display, p_plugin->window, gc,
518 0, 0, p_plugin->width-1, p_plugin->height-1);
519 XDrawString(p_plugin->display, p_plugin->window, gc,
520 p_plugin->width/2 - 100, p_plugin->height/2,