1 /*****************************************************************************
2 * vlcshell.c: a VideoLAN Client plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: vlcshell.cpp,v 1.5 2002/10/22 21:10:28 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"*/
173 if( instance == NULL )
175 return NPERR_INVALID_INSTANCE_ERROR;
178 VlcPlugin * p_plugin = new VlcPlugin( instance );
180 if( p_plugin == NULL )
182 return NPERR_OUT_OF_MEMORY_ERROR;
185 instance->pdata = p_plugin;
187 p_plugin->fMode = mode;
188 p_plugin->fWindow = NULL;
192 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 = "dummy";
215 VLC_Set( p_plugin->i_vlc, "conf::intf", value );
217 value.psz_string = "directx,dummy";
219 value.psz_string = "xvideo,x11,dummy";
221 VLC_Set( p_plugin->i_vlc, "conf::vout", value );
223 value.psz_string = "none";//"directx,waveout,dummy";
225 value.psz_string = "dsp,dummy";
227 VLC_Set( p_plugin->i_vlc, "conf::aout", value );
229 p_plugin->b_stream = 0;
230 p_plugin->b_autoplay = 0;
231 p_plugin->psz_target = NULL;
233 for( i = 0; i < argc ; i++ )
235 if( !strcmp( argn[i], "target" ) )
237 p_plugin->psz_target = argv[i];
239 else if( !strcmp( argn[i], "autoplay" ) )
241 if( !strcmp( argv[i], "yes" ) )
243 p_plugin->b_autoplay = 1;
246 else if( !strcmp( argn[i], "loop" ) )
248 if( !strcmp( argv[i], "yes" ) )
250 value.b_bool = VLC_TRUE;
251 VLC_Set( p_plugin->i_vlc, "conf::loop", value );
256 if( p_plugin->psz_target )
258 p_plugin->psz_target = strdup( p_plugin->psz_target );
261 return NPERR_NO_ERROR;
264 NPError NPP_Destroy( NPP instance, NPSavedData** save )
266 if( instance == NULL )
268 return NPERR_INVALID_INSTANCE_ERROR;
271 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
273 if( p_plugin != NULL )
275 if( p_plugin->i_vlc )
277 VLC_Stop( p_plugin->i_vlc );
278 VLC_Destroy( p_plugin->i_vlc );
282 if( p_plugin->psz_target )
284 free( p_plugin->psz_target );
285 p_plugin->psz_target = NULL;
291 instance->pdata = NULL;
293 return NPERR_NO_ERROR;
296 NPError NPP_SetWindow( NPP instance, NPWindow* window )
300 if( instance == NULL )
302 return NPERR_INVALID_INSTANCE_ERROR;
305 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
307 /* Write the window ID for vlc */
308 //value.p_address = (void*)window->window;
309 //VLC_Set( p_plugin->i_vlc, "drawable", value );
310 /* FIXME: this cast sucks */
311 value.i_int = (int) (long long) (void *) window->window;
312 VLC_Set( p_plugin->i_vlc, "conf::x11-drawable", value );
313 VLC_Set( p_plugin->i_vlc, "conf::xvideo-drawable", value );
317 * Before setting window to point to the
318 * new window, you may wish to compare the new window
319 * info to the previous window (if any) to note window
326 Widget netscape_widget;
328 p_plugin->window = (Window) window->window;
329 p_plugin->x = window->x;
330 p_plugin->y = window->y;
331 p_plugin->width = window->width;
332 p_plugin->height = window->height;
333 p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
335 netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
336 XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
337 Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
340 p_plugin->fWindow = window;
343 if( !p_plugin->b_stream )
345 int i_mode = PLAYLIST_APPEND;
347 if( p_plugin->b_autoplay )
349 i_mode |= PLAYLIST_GO;
352 if( p_plugin->psz_target )
354 VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target,
355 i_mode, PLAYLIST_END );
356 p_plugin->b_stream = 1;
361 return NPERR_NO_ERROR;
364 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
365 NPBool seekable, uint16 *stype )
367 if( instance == NULL )
369 return NPERR_INVALID_INSTANCE_ERROR;
373 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
376 fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
378 /* We want a *filename* ! */
382 if( p_plugin->b_stream == 0 )
384 p_plugin->psz_target = strdup( stream->url );
385 p_plugin->b_stream = 1;
389 return NPERR_NO_ERROR;
392 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
393 * mode so we can take any size stream in our
394 * write call (since we ignore it) */
396 #define SARASS_SIZE (1024*1024)
398 int32 NPP_WriteReady( NPP instance, NPStream *stream )
402 fprintf(stderr, "NPP_WriteReady\n");
404 if (instance != NULL)
406 p_plugin = (VlcPlugin*) instance->pdata;
407 /* Muahahahahahahaha */
408 return STREAMBUFSIZE;
409 /*return SARASS_SIZE;*/
412 /* Number of bytes ready to accept in NPP_Write() */
413 return STREAMBUFSIZE;
418 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
419 int32 len, void *buffer )
421 fprintf(stderr, "NPP_Write %i\n", (int)len);
423 if( instance != NULL )
425 /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
428 return len; /* The number of bytes accepted */
432 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
434 if( instance == NULL )
436 return NPERR_INVALID_INSTANCE_ERROR;
439 return NPERR_NO_ERROR;
443 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
445 if( instance == NULL )
450 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
452 fprintf(stderr, "NPP_StreamAsFile\n");
453 VLC_AddTarget( p_plugin->i_vlc, fname,
454 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
458 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
460 fprintf(stderr,"filename : %s\n", fname);
461 ((VlcPlugin*) instance->pdata)->SetFileName(fname);
463 fprintf(stderr,"SetFileNeme ok. \n");
468 void NPP_URLNotify( NPP instance, const char* url,
469 NPReason reason, void* notifyData )
471 /***** Insert NPP_URLNotify code here *****\
472 PluginInstance* p_plugin;
473 if (instance != NULL)
474 p_plugin = (PluginInstance*) instance->pdata;
475 \*********************************************/
479 void NPP_Print( NPP instance, NPPrint* printInfo )
481 if( printInfo == NULL )
486 if( instance != NULL )
488 /***** Insert NPP_Print code here *****\
489 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
490 \**************************************/
492 if( printInfo->mode == NP_FULL )
496 * If your plugin would like to take over
497 * printing completely when it is in full-screen mode,
498 * set printInfo->pluginPrinted to TRUE and print your
499 * plugin as you see fit. If your plugin wants Netscape
500 * to handle printing in this case, set
501 * printInfo->pluginPrinted to FALSE (the default) and
502 * do nothing. If you do want to handle printing
503 * yourself, printOne is true if the print button
504 * (as opposed to the print menu) was clicked.
505 * On the Macintosh, platformPrint is a THPrint; on
506 * Windows, platformPrint is a structure
507 * (defined in npapi.h) containing the printer name, port,
511 /***** Insert NPP_Print code here *****\
512 void* platformPrint =
513 printInfo->print.fullPrint.platformPrint;
515 printInfo->print.fullPrint.printOne;
516 \**************************************/
519 printInfo->print.fullPrint.pluginPrinted = FALSE;
523 /* If not fullscreen, we must be embedded */
526 * If your plugin is embedded, or is full-screen
527 * but you returned false in pluginPrinted above, NPP_Print
528 * will be called with mode == NP_EMBED. The NPWindow
529 * in the printInfo gives the location and dimensions of
530 * the embedded plugin on the printed page. On the
531 * Macintosh, platformPrint is the printer port; on
532 * Windows, platformPrint is the handle to the printing
536 /***** Insert NPP_Print code here *****\
537 NPWindow* printWindow =
538 &(printInfo->print.embedPrint.window);
539 void* platformPrint =
540 printInfo->print.embedPrint.platformPrint;
541 \**************************************/
546 /******************************************************************************
548 *****************************************************************************/
550 static void Redraw( Widget w, XtPointer closure, XEvent *event )
552 VlcPlugin* p_plugin = (VlcPlugin*)closure;
555 const char * psz_text = "(no picture)";
557 gcv.foreground = BlackPixel( p_plugin->display, 0 );
558 gc = XCreateGC( p_plugin->display, p_plugin->window, GCForeground, &gcv );
560 XFillRectangle( p_plugin->display, p_plugin->window, gc,
561 0, 0, p_plugin->width, p_plugin->height );
563 gcv.foreground = WhitePixel( p_plugin->display, 0 );
564 XChangeGC( p_plugin->display, gc, GCForeground, &gcv );
566 XDrawString( p_plugin->display, p_plugin->window, gc,
567 p_plugin->width / 2 - 40, p_plugin->height / 2,
568 psz_text, strlen(psz_text) );
570 XFreeGC( p_plugin->display, gc );