1 /*****************************************************************************
2 * vlcshell.c: a VideoLAN Client plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: vlcshell.cpp,v 1.3 2002/10/03 18:56:09 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 *****************************************************************************/
41 # include <X11/Xlib.h>
42 # include <X11/Intrinsic.h>
43 # include <X11/StringDefs.h>
47 #include "vlcplugin.h"
49 /*****************************************************************************
50 * Unix-only declarations
51 ******************************************************************************/
53 static void Redraw( Widget w, XtPointer closure, XEvent *event );
56 /*****************************************************************************
57 * Windows-only declarations
58 *****************************************************************************/
60 HINSTANCE g_hDllInstance = NULL;
63 DllMain( HINSTANCE hinstDLL, // handle of DLL module
64 DWORD fdwReason, // reason for calling function
68 case DLL_PROCESS_ATTACH:
69 g_hDllInstance = hinstDLL;
71 case DLL_THREAD_ATTACH:
72 case DLL_PROCESS_DETACH:
73 case DLL_THREAD_DETACH:
80 /******************************************************************************
82 *****************************************************************************/
83 char * NPP_GetMIMEDescription( void )
85 return PLUGIN_MIMETYPES;
88 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
90 static nsIID nsid = VLCINTF_IID;
94 case NPPVpluginNameString:
95 *((char **)value) = PLUGIN_NAME;
96 return NPERR_NO_ERROR;
98 case NPPVpluginDescriptionString:
99 *((char **)value) = PLUGIN_DESCRIPTION;
100 return NPERR_NO_ERROR;
103 if( instance == NULL )
105 return NPERR_INVALID_INSTANCE_ERROR;
108 VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
112 case NPPVpluginScriptableInstance:
113 *(nsISupports**)value = p_plugin->GetPeer();
114 if( *(nsISupports**)value == NULL )
116 return NPERR_OUT_OF_MEMORY_ERROR;
120 case NPPVpluginScriptableIID:
121 *(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
122 if( *(nsIID**)value == NULL )
124 return NPERR_OUT_OF_MEMORY_ERROR;
126 **(nsIID**)value = nsid;
130 return NPERR_GENERIC_ERROR;
133 return NPERR_NO_ERROR;
136 /******************************************************************************
137 * General Plug-in Calls
138 *****************************************************************************/
139 NPError NPP_Initialize( void )
141 return NPERR_NO_ERROR;
144 jref NPP_GetJavaClass( void )
149 void NPP_Shutdown( void )
154 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
155 char* argn[], char* argv[], NPSavedData* saved )
163 /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
164 , "--vout", "xvideo,x11,dummy"
170 if( instance == NULL )
172 return NPERR_INVALID_INSTANCE_ERROR;
175 VlcPlugin * p_plugin = new VlcPlugin( instance );
177 if( p_plugin == NULL )
179 return NPERR_OUT_OF_MEMORY_ERROR;
182 instance->pdata = p_plugin;
184 p_plugin->fMode = mode;
185 p_plugin->fWindow = NULL;
186 p_plugin->window = 0;
188 p_plugin->p_vlc = vlc_create_r();
189 if( p_plugin->p_vlc == NULL )
193 return NPERR_GENERIC_ERROR;
196 i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
199 vlc_destroy_r( p_plugin->p_vlc );
200 p_plugin->p_vlc = NULL;
203 return NPERR_GENERIC_ERROR;
206 vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
207 vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
209 p_plugin->b_stream = 0;
210 p_plugin->b_autoplay = 0;
211 p_plugin->psz_target = NULL;
213 for( i = 0; i < argc ; i++ )
215 if( !strcmp( argn[i], "target" ) )
217 p_plugin->psz_target = argv[i];
219 else if( !strcmp( argn[i], "autoplay" ) )
221 if( !strcmp( argv[i], "yes" ) )
223 p_plugin->b_autoplay = 1;
226 else if( !strcmp( argn[i], "loop" ) )
228 if( !strcmp( argv[i], "yes" ) )
230 vlc_set_r( p_plugin->p_vlc, "loop", "1" );
235 if( p_plugin->psz_target )
237 p_plugin->psz_target = strdup( p_plugin->psz_target );
240 return NPERR_NO_ERROR;
243 NPError NPP_Destroy( NPP instance, NPSavedData** save )
245 if( instance == NULL )
247 return NPERR_INVALID_INSTANCE_ERROR;
250 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
252 if( p_plugin != NULL )
254 if( p_plugin->p_vlc != NULL )
256 vlc_stop_r( p_plugin->p_vlc );
257 vlc_destroy_r( p_plugin->p_vlc );
258 p_plugin->p_vlc = NULL;
261 if( p_plugin->psz_target )
263 free( p_plugin->psz_target );
264 p_plugin->psz_target = NULL;
270 instance->pdata = NULL;
272 return NPERR_NO_ERROR;
275 NPError NPP_SetWindow( NPP instance, NPWindow* window )
279 if( instance == NULL )
281 return NPERR_INVALID_INSTANCE_ERROR;
284 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
286 /* Write the window ID for vlc */
287 sprintf( psz_window, "%li", (long int)window->window );
288 vlc_set_r( p_plugin->p_vlc, "x11-drawable", psz_window );
289 vlc_set_r( p_plugin->p_vlc, "xvideo-drawable", psz_window );
293 * Before setting window to point to the
294 * new window, you may wish to compare the new window
295 * info to the previous window (if any) to note window
299 Widget netscape_widget;
301 p_plugin->window = (Window) window->window;
302 p_plugin->x = window->x;
303 p_plugin->y = window->y;
304 p_plugin->width = window->width;
305 p_plugin->height = window->height;
306 p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
308 netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
309 XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
310 Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
312 p_plugin->fWindow = window;
315 if( !p_plugin->b_stream )
317 int i_mode = PLAYLIST_APPEND;
319 if( p_plugin->b_autoplay )
321 i_mode |= PLAYLIST_GO;
324 if( p_plugin->psz_target )
326 vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
327 i_mode, PLAYLIST_END );
328 p_plugin->b_stream = 1;
333 return NPERR_NO_ERROR;
336 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
337 NPBool seekable, uint16 *stype )
339 if( instance == NULL )
341 return NPERR_INVALID_INSTANCE_ERROR;
345 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
348 fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
350 /* We want a *filename* ! */
354 if( p_plugin->b_stream == 0 )
356 p_plugin->psz_target = strdup( stream->url );
357 p_plugin->b_stream = 1;
361 return NPERR_NO_ERROR;
364 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
365 * mode so we can take any size stream in our
366 * write call (since we ignore it) */
368 #define SARASS_SIZE (1024*1024)
370 int32 NPP_WriteReady( NPP instance, NPStream *stream )
374 fprintf(stderr, "NPP_WriteReady\n");
376 if (instance != NULL)
378 p_plugin = (VlcPlugin*) instance->pdata;
379 /* Muahahahahahahaha */
380 return STREAMBUFSIZE;
381 /*return SARASS_SIZE;*/
384 /* Number of bytes ready to accept in NPP_Write() */
385 return STREAMBUFSIZE;
390 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
391 int32 len, void *buffer )
393 fprintf(stderr, "NPP_Write %i\n", len);
395 if( instance != NULL )
397 /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
400 return len; /* The number of bytes accepted */
404 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
406 if( instance == NULL )
408 return NPERR_INVALID_INSTANCE_ERROR;
411 return NPERR_NO_ERROR;
415 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
417 if( instance == NULL )
422 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
424 fprintf(stderr, "NPP_StreamAsFile\n");
425 vlc_add_target_r( p_plugin->p_vlc, fname,
426 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
430 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
432 fprintf(stderr,"filename : %s\n", fname);
433 ((VlcPlugin*) instance->pdata)->SetFileName(fname);
435 fprintf(stderr,"SetFileNeme ok. \n");
440 void NPP_URLNotify( NPP instance, const char* url,
441 NPReason reason, void* notifyData )
443 /***** Insert NPP_URLNotify code here *****\
444 PluginInstance* p_plugin;
445 if (instance != NULL)
446 p_plugin = (PluginInstance*) instance->pdata;
447 \*********************************************/
451 void NPP_Print( NPP instance, NPPrint* printInfo )
453 if( printInfo == NULL )
458 if( instance != NULL )
460 /***** Insert NPP_Print code here *****\
461 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
462 \**************************************/
464 if( printInfo->mode == NP_FULL )
468 * If your plugin would like to take over
469 * printing completely when it is in full-screen mode,
470 * set printInfo->pluginPrinted to TRUE and print your
471 * plugin as you see fit. If your plugin wants Netscape
472 * to handle printing in this case, set
473 * printInfo->pluginPrinted to FALSE (the default) and
474 * do nothing. If you do want to handle printing
475 * yourself, printOne is true if the print button
476 * (as opposed to the print menu) was clicked.
477 * On the Macintosh, platformPrint is a THPrint; on
478 * Windows, platformPrint is a structure
479 * (defined in npapi.h) containing the printer name, port,
483 /***** Insert NPP_Print code here *****\
484 void* platformPrint =
485 printInfo->print.fullPrint.platformPrint;
487 printInfo->print.fullPrint.printOne;
488 \**************************************/
491 printInfo->print.fullPrint.pluginPrinted = FALSE;
495 /* If not fullscreen, we must be embedded */
498 * If your plugin is embedded, or is full-screen
499 * but you returned false in pluginPrinted above, NPP_Print
500 * will be called with mode == NP_EMBED. The NPWindow
501 * in the printInfo gives the location and dimensions of
502 * the embedded plugin on the printed page. On the
503 * Macintosh, platformPrint is the printer port; on
504 * Windows, platformPrint is the handle to the printing
508 /***** Insert NPP_Print code here *****\
509 NPWindow* printWindow =
510 &(printInfo->print.embedPrint.window);
511 void* platformPrint =
512 printInfo->print.embedPrint.platformPrint;
513 \**************************************/
518 /******************************************************************************
520 *****************************************************************************/
522 static void Redraw( Widget w, XtPointer closure, XEvent *event )
524 VlcPlugin* p_plugin = (VlcPlugin*)closure;
527 const char * psz_text = "(no picture)";
529 gcv.foreground = BlackPixel( p_plugin->display, 0 );
530 gc = XCreateGC( p_plugin->display, p_plugin->window, GCForeground, &gcv );
532 XFillRectangle( p_plugin->display, p_plugin->window, gc,
533 0, 0, p_plugin->width, p_plugin->height );
535 gcv.foreground = WhitePixel( p_plugin->display, 0 );
536 XChangeGC( p_plugin->display, gc, GCForeground, &gcv );
538 XDrawString( p_plugin->display, p_plugin->window, gc,
539 p_plugin->width / 2 - 40, p_plugin->height / 2,
540 psz_text, strlen(psz_text) );
542 XFreeGC( p_plugin->display, gc );