1 /*****************************************************************************
2 * vlcshell.c: a VideoLAN Client plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: vlcshell.cpp,v 1.4 2002/10/11 22:32:56 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 *****************************************************************************/
40 # include <X11/Xlib.h>
41 # include <X11/Intrinsic.h>
42 # include <X11/StringDefs.h>
46 #include "vlcplugin.h"
48 /*****************************************************************************
49 * Unix-only declarations
50 ******************************************************************************/
52 static void Redraw( Widget w, XtPointer closure, XEvent *event );
55 /*****************************************************************************
56 * Windows-only declarations
57 *****************************************************************************/
59 HINSTANCE g_hDllInstance = NULL;
62 DllMain( HINSTANCE hinstDLL, // handle of DLL module
63 DWORD fdwReason, // reason for calling function
67 case DLL_PROCESS_ATTACH:
68 g_hDllInstance = hinstDLL;
70 case DLL_THREAD_ATTACH:
71 case DLL_PROCESS_DETACH:
72 case DLL_THREAD_DETACH:
79 /******************************************************************************
81 *****************************************************************************/
82 char * NPP_GetMIMEDescription( void )
84 return PLUGIN_MIMETYPES;
87 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
89 static nsIID nsid = VLCINTF_IID;
90 static char psz_desc[1000];
94 case NPPVpluginNameString:
95 *((char **)value) = PLUGIN_NAME;
96 return NPERR_NO_ERROR;
98 case NPPVpluginDescriptionString:
99 snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, VLC_Version() );
100 psz_desc[1000-1] = 0;
101 *((char **)value) = psz_desc;
102 return NPERR_NO_ERROR;
109 if( instance == NULL )
111 return NPERR_INVALID_INSTANCE_ERROR;
114 VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
118 case NPPVpluginScriptableInstance:
119 *(nsISupports**)value = p_plugin->GetPeer();
120 if( *(nsISupports**)value == NULL )
122 return NPERR_OUT_OF_MEMORY_ERROR;
126 case NPPVpluginScriptableIID:
127 *(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
128 if( *(nsIID**)value == NULL )
130 return NPERR_OUT_OF_MEMORY_ERROR;
132 **(nsIID**)value = nsid;
136 return NPERR_GENERIC_ERROR;
139 return NPERR_NO_ERROR;
142 /******************************************************************************
143 * General Plug-in Calls
144 *****************************************************************************/
145 NPError NPP_Initialize( void )
147 return NPERR_NO_ERROR;
150 jref NPP_GetJavaClass( void )
155 void NPP_Shutdown( void )
160 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
161 char* argn[], char* argv[], NPSavedData* saved )
170 /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
171 , "--vout", "xvideo,x11,dummy"
177 if( instance == NULL )
179 return NPERR_INVALID_INSTANCE_ERROR;
182 VlcPlugin * p_plugin = new VlcPlugin( instance );
184 if( p_plugin == NULL )
186 return NPERR_OUT_OF_MEMORY_ERROR;
189 instance->pdata = p_plugin;
191 p_plugin->fMode = mode;
192 p_plugin->fWindow = NULL;
193 p_plugin->window = 0;
195 p_plugin->i_vlc = VLC_Create();
196 if( p_plugin->i_vlc < 0 )
201 return NPERR_GENERIC_ERROR;
204 i_ret = VLC_Init( p_plugin->i_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
207 VLC_Destroy( p_plugin->i_vlc );
211 return NPERR_GENERIC_ERROR;
214 value.psz_string = "xvideo,x11,dummy";
215 VLC_Set( p_plugin->i_vlc, "conf::vout", value );
216 value.psz_string = "dummy";
217 VLC_Set( p_plugin->i_vlc, "conf::intf", value );
219 p_plugin->b_stream = 0;
220 p_plugin->b_autoplay = 0;
221 p_plugin->psz_target = NULL;
223 for( i = 0; i < argc ; i++ )
225 if( !strcmp( argn[i], "target" ) )
227 p_plugin->psz_target = argv[i];
229 else if( !strcmp( argn[i], "autoplay" ) )
231 if( !strcmp( argv[i], "yes" ) )
233 p_plugin->b_autoplay = 1;
236 else if( !strcmp( argn[i], "loop" ) )
238 if( !strcmp( argv[i], "yes" ) )
240 value.b_bool = VLC_TRUE;
241 VLC_Set( p_plugin->i_vlc, "conf::loop", value );
246 if( p_plugin->psz_target )
248 p_plugin->psz_target = strdup( p_plugin->psz_target );
251 return NPERR_NO_ERROR;
254 NPError NPP_Destroy( NPP instance, NPSavedData** save )
256 if( instance == NULL )
258 return NPERR_INVALID_INSTANCE_ERROR;
261 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
263 if( p_plugin != NULL )
265 if( p_plugin->i_vlc )
267 VLC_Stop( p_plugin->i_vlc );
268 VLC_Destroy( p_plugin->i_vlc );
272 if( p_plugin->psz_target )
274 free( p_plugin->psz_target );
275 p_plugin->psz_target = NULL;
281 instance->pdata = NULL;
283 return NPERR_NO_ERROR;
286 NPError NPP_SetWindow( NPP instance, NPWindow* window )
290 if( instance == NULL )
292 return NPERR_INVALID_INSTANCE_ERROR;
295 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
297 /* Write the window ID for vlc */
298 value.p_address = (void*)window->window;
299 VLC_Set( p_plugin->i_vlc, "drawable", value );
303 * Before setting window to point to the
304 * new window, you may wish to compare the new window
305 * info to the previous window (if any) to note window
309 Widget netscape_widget;
311 p_plugin->window = (Window) window->window;
312 p_plugin->x = window->x;
313 p_plugin->y = window->y;
314 p_plugin->width = window->width;
315 p_plugin->height = window->height;
316 p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
318 netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
319 XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
320 Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
322 p_plugin->fWindow = window;
325 if( !p_plugin->b_stream )
327 int i_mode = PLAYLIST_APPEND;
329 if( p_plugin->b_autoplay )
331 i_mode |= PLAYLIST_GO;
334 if( p_plugin->psz_target )
336 VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target,
337 i_mode, PLAYLIST_END );
338 p_plugin->b_stream = 1;
343 return NPERR_NO_ERROR;
346 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
347 NPBool seekable, uint16 *stype )
349 if( instance == NULL )
351 return NPERR_INVALID_INSTANCE_ERROR;
355 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
358 fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
360 /* We want a *filename* ! */
364 if( p_plugin->b_stream == 0 )
366 p_plugin->psz_target = strdup( stream->url );
367 p_plugin->b_stream = 1;
371 return NPERR_NO_ERROR;
374 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
375 * mode so we can take any size stream in our
376 * write call (since we ignore it) */
378 #define SARASS_SIZE (1024*1024)
380 int32 NPP_WriteReady( NPP instance, NPStream *stream )
384 fprintf(stderr, "NPP_WriteReady\n");
386 if (instance != NULL)
388 p_plugin = (VlcPlugin*) instance->pdata;
389 /* Muahahahahahahaha */
390 return STREAMBUFSIZE;
391 /*return SARASS_SIZE;*/
394 /* Number of bytes ready to accept in NPP_Write() */
395 return STREAMBUFSIZE;
400 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
401 int32 len, void *buffer )
403 fprintf(stderr, "NPP_Write %i\n", len);
405 if( instance != NULL )
407 /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
410 return len; /* The number of bytes accepted */
414 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
416 if( instance == NULL )
418 return NPERR_INVALID_INSTANCE_ERROR;
421 return NPERR_NO_ERROR;
425 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
427 if( instance == NULL )
432 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
434 fprintf(stderr, "NPP_StreamAsFile\n");
435 VLC_AddTarget( p_plugin->i_vlc, fname,
436 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
440 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
442 fprintf(stderr,"filename : %s\n", fname);
443 ((VlcPlugin*) instance->pdata)->SetFileName(fname);
445 fprintf(stderr,"SetFileNeme ok. \n");
450 void NPP_URLNotify( NPP instance, const char* url,
451 NPReason reason, void* notifyData )
453 /***** Insert NPP_URLNotify code here *****\
454 PluginInstance* p_plugin;
455 if (instance != NULL)
456 p_plugin = (PluginInstance*) instance->pdata;
457 \*********************************************/
461 void NPP_Print( NPP instance, NPPrint* printInfo )
463 if( printInfo == NULL )
468 if( instance != NULL )
470 /***** Insert NPP_Print code here *****\
471 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
472 \**************************************/
474 if( printInfo->mode == NP_FULL )
478 * If your plugin would like to take over
479 * printing completely when it is in full-screen mode,
480 * set printInfo->pluginPrinted to TRUE and print your
481 * plugin as you see fit. If your plugin wants Netscape
482 * to handle printing in this case, set
483 * printInfo->pluginPrinted to FALSE (the default) and
484 * do nothing. If you do want to handle printing
485 * yourself, printOne is true if the print button
486 * (as opposed to the print menu) was clicked.
487 * On the Macintosh, platformPrint is a THPrint; on
488 * Windows, platformPrint is a structure
489 * (defined in npapi.h) containing the printer name, port,
493 /***** Insert NPP_Print code here *****\
494 void* platformPrint =
495 printInfo->print.fullPrint.platformPrint;
497 printInfo->print.fullPrint.printOne;
498 \**************************************/
501 printInfo->print.fullPrint.pluginPrinted = FALSE;
505 /* If not fullscreen, we must be embedded */
508 * If your plugin is embedded, or is full-screen
509 * but you returned false in pluginPrinted above, NPP_Print
510 * will be called with mode == NP_EMBED. The NPWindow
511 * in the printInfo gives the location and dimensions of
512 * the embedded plugin on the printed page. On the
513 * Macintosh, platformPrint is the printer port; on
514 * Windows, platformPrint is the handle to the printing
518 /***** Insert NPP_Print code here *****\
519 NPWindow* printWindow =
520 &(printInfo->print.embedPrint.window);
521 void* platformPrint =
522 printInfo->print.embedPrint.platformPrint;
523 \**************************************/
528 /******************************************************************************
530 *****************************************************************************/
532 static void Redraw( Widget w, XtPointer closure, XEvent *event )
534 VlcPlugin* p_plugin = (VlcPlugin*)closure;
537 const char * psz_text = "(no picture)";
539 gcv.foreground = BlackPixel( p_plugin->display, 0 );
540 gc = XCreateGC( p_plugin->display, p_plugin->window, GCForeground, &gcv );
542 XFillRectangle( p_plugin->display, p_plugin->window, gc,
543 0, 0, p_plugin->width, p_plugin->height );
545 gcv.foreground = WhitePixel( p_plugin->display, 0 );
546 XChangeGC( p_plugin->display, gc, GCForeground, &gcv );
548 XDrawString( p_plugin->display, p_plugin->window, gc,
549 p_plugin->width / 2 - 40, p_plugin->height / 2,
550 psz_text, strlen(psz_text) );
552 XFreeGC( p_plugin->display, gc );