1 /*****************************************************************************
2 * vlcshell.c: a VideoLAN Client plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: vlcshell.cpp,v 1.2 2002/09/30 11:05:41 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"
172 if( instance == NULL )
174 return NPERR_INVALID_INSTANCE_ERROR;
177 VlcPlugin * p_plugin = new VlcPlugin( instance );
179 if( p_plugin == NULL )
181 return NPERR_OUT_OF_MEMORY_ERROR;
184 instance->pdata = p_plugin;
186 p_plugin->fMode = mode;
187 p_plugin->fWindow = NULL;
188 p_plugin->window = 0;
190 p_plugin->p_vlc = vlc_create_r();
191 if( p_plugin->p_vlc == NULL )
195 return NPERR_GENERIC_ERROR;
198 i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
201 vlc_destroy_r( p_plugin->p_vlc );
202 p_plugin->p_vlc = NULL;
205 return NPERR_GENERIC_ERROR;
208 vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
209 vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
211 p_plugin->b_stream = 0;
212 p_plugin->b_autoplay = 0;
213 p_plugin->psz_target = NULL;
215 for( i = 0; i < argc ; i++ )
217 if( !strcmp( argn[i], "target" ) )
219 p_plugin->psz_target = argv[i];
221 else if( !strcmp( argn[i], "autoplay" ) )
223 if( !strcmp( argv[i], "yes" ) )
225 p_plugin->b_autoplay = 1;
228 else if( !strcmp( argn[i], "loop" ) )
230 if( !strcmp( argv[i], "yes" ) )
232 vlc_set_r( p_plugin->p_vlc, "loop", "1" );
237 if( p_plugin->psz_target )
239 p_plugin->psz_target = strdup( p_plugin->psz_target );
242 return NPERR_NO_ERROR;
245 NPError NPP_Destroy( NPP instance, NPSavedData** save )
247 if( instance == NULL )
249 return NPERR_INVALID_INSTANCE_ERROR;
252 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
254 if( p_plugin != NULL )
256 if( p_plugin->p_vlc != NULL )
258 vlc_stop_r( p_plugin->p_vlc );
259 vlc_destroy_r( p_plugin->p_vlc );
260 p_plugin->p_vlc = NULL;
263 if( p_plugin->psz_target )
265 free( p_plugin->psz_target );
266 p_plugin->psz_target = NULL;
272 instance->pdata = NULL;
274 return NPERR_NO_ERROR;
277 NPError NPP_SetWindow( NPP instance, NPWindow* window )
281 if( instance == NULL )
283 return NPERR_INVALID_INSTANCE_ERROR;
286 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
288 /* Write the window ID for vlc */
289 sprintf( psz_window, "%li", (long int)window->window );
290 vlc_set_r( p_plugin->p_vlc, "x11-drawable", psz_window );
291 vlc_set_r( p_plugin->p_vlc, "xvideo-drawable", psz_window );
295 * Before setting window to point to the
296 * new window, you may wish to compare the new window
297 * info to the previous window (if any) to note window
301 Widget netscape_widget;
303 p_plugin->window = (Window) window->window;
304 p_plugin->x = window->x;
305 p_plugin->y = window->y;
306 p_plugin->width = window->width;
307 p_plugin->height = window->height;
308 p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
310 netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
311 XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
312 Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
314 p_plugin->fWindow = window;
317 if( !p_plugin->b_stream )
319 int i_mode = PLAYLIST_APPEND;
321 if( p_plugin->b_autoplay )
323 i_mode |= PLAYLIST_GO;
326 if( p_plugin->psz_target )
328 vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
329 i_mode, PLAYLIST_END );
330 p_plugin->b_stream = 1;
335 return NPERR_NO_ERROR;
338 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
339 NPBool seekable, uint16 *stype )
341 if( instance == NULL )
343 return NPERR_INVALID_INSTANCE_ERROR;
347 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
350 fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
352 /* We want a *filename* ! */
356 if( p_plugin->b_stream == 0 )
358 p_plugin->psz_target = strdup( stream->url );
359 p_plugin->b_stream = 1;
363 return NPERR_NO_ERROR;
366 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
367 * mode so we can take any size stream in our
368 * write call (since we ignore it) */
370 #define SARASS_SIZE (1024*1024)
372 int32 NPP_WriteReady( NPP instance, NPStream *stream )
376 fprintf(stderr, "NPP_WriteReady\n");
378 if (instance != NULL)
380 p_plugin = (VlcPlugin*) instance->pdata;
381 /* Muahahahahahahaha */
382 return STREAMBUFSIZE;
383 /*return SARASS_SIZE;*/
386 /* Number of bytes ready to accept in NPP_Write() */
387 return STREAMBUFSIZE;
392 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
393 int32 len, void *buffer )
395 fprintf(stderr, "NPP_Write %i\n", len);
397 if( instance != NULL )
399 /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
402 return len; /* The number of bytes accepted */
406 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
408 if( instance == NULL )
410 return NPERR_INVALID_INSTANCE_ERROR;
413 return NPERR_NO_ERROR;
417 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
419 if( instance == NULL )
424 VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
426 fprintf(stderr, "NPP_StreamAsFile\n");
427 vlc_add_target_r( p_plugin->p_vlc, fname,
428 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
432 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
434 fprintf(stderr,"filename : %s\n", fname);
435 ((VlcPlugin*) instance->pdata)->SetFileName(fname);
437 fprintf(stderr,"SetFileNeme ok. \n");
442 void NPP_URLNotify( NPP instance, const char* url,
443 NPReason reason, void* notifyData )
445 /***** Insert NPP_URLNotify code here *****\
446 PluginInstance* p_plugin;
447 if (instance != NULL)
448 p_plugin = (PluginInstance*) instance->pdata;
449 \*********************************************/
453 void NPP_Print( NPP instance, NPPrint* printInfo )
455 if( printInfo == NULL )
460 if( instance != NULL )
462 /***** Insert NPP_Print code here *****\
463 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
464 \**************************************/
466 if( printInfo->mode == NP_FULL )
470 * If your plugin would like to take over
471 * printing completely when it is in full-screen mode,
472 * set printInfo->pluginPrinted to TRUE and print your
473 * plugin as you see fit. If your plugin wants Netscape
474 * to handle printing in this case, set
475 * printInfo->pluginPrinted to FALSE (the default) and
476 * do nothing. If you do want to handle printing
477 * yourself, printOne is true if the print button
478 * (as opposed to the print menu) was clicked.
479 * On the Macintosh, platformPrint is a THPrint; on
480 * Windows, platformPrint is a structure
481 * (defined in npapi.h) containing the printer name, port,
485 /***** Insert NPP_Print code here *****\
486 void* platformPrint =
487 printInfo->print.fullPrint.platformPrint;
489 printInfo->print.fullPrint.printOne;
490 \**************************************/
493 printInfo->print.fullPrint.pluginPrinted = FALSE;
497 /* If not fullscreen, we must be embedded */
500 * If your plugin is embedded, or is full-screen
501 * but you returned false in pluginPrinted above, NPP_Print
502 * will be called with mode == NP_EMBED. The NPWindow
503 * in the printInfo gives the location and dimensions of
504 * the embedded plugin on the printed page. On the
505 * Macintosh, platformPrint is the printer port; on
506 * Windows, platformPrint is the handle to the printing
510 /***** Insert NPP_Print code here *****\
511 NPWindow* printWindow =
512 &(printInfo->print.embedPrint.window);
513 void* platformPrint =
514 printInfo->print.embedPrint.platformPrint;
515 \**************************************/
520 /******************************************************************************
522 *****************************************************************************/
524 static void Redraw( Widget w, XtPointer closure, XEvent *event )
526 VlcPlugin* p_plugin = (VlcPlugin*)closure;
529 const char * psz_text = "(no picture)";
531 gcv.foreground = BlackPixel( p_plugin->display, 0 );
532 gc = XCreateGC( p_plugin->display, p_plugin->window, GCForeground, &gcv );
534 XFillRectangle( p_plugin->display, p_plugin->window, gc,
535 0, 0, p_plugin->width, p_plugin->height );
537 gcv.foreground = WhitePixel( p_plugin->display, 0 );
538 XChangeGC( p_plugin->display, gc, GCForeground, &gcv );
540 XDrawString( p_plugin->display, p_plugin->window, gc,
541 p_plugin->width / 2 - 40, p_plugin->height / 2,
542 psz_text, strlen(psz_text) );
544 XFreeGC( p_plugin->display, gc );