1 /*****************************************************************************
2 * vlcplugin.c: a VideoLAN Client plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: vlcplugin.c,v 1.1 2002/07/04 18:11:57 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>
41 #include "vlcplugin.h"
43 /*******************************************************************************
44 * Unix-only declarations
45 ******************************************************************************/
46 static void Redraw( Widget w, XtPointer closure, XEvent *event );
48 /*******************************************************************************
50 ******************************************************************************/
51 char* NPP_GetMIMEDescription( void )
53 return( PLUGIN_MIMETYPES );
56 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
58 NPError err = NPERR_NO_ERROR;
59 if (variable == NPPVpluginNameString)
60 *((char **)value) = PLUGIN_NAME;
61 else if (variable == NPPVpluginDescriptionString)
62 *((char **)value) = PLUGIN_DESCRIPTION;
64 err = NPERR_GENERIC_ERROR;
69 /*******************************************************************************
70 * General Plug-in Calls
71 ******************************************************************************/
72 NPError NPP_Initialize( void )
74 fprintf(stderr, "NPP_Initialize\n");
75 return NPERR_NO_ERROR;
78 jref NPP_GetJavaClass( void )
80 return NULL; /* Java disabled */
83 void NPP_Shutdown( void )
88 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
89 char* argn[], char* argv[], NPSavedData* saved )
91 NPError result = NPERR_NO_ERROR;
99 //"--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins",
100 "--vout", "xvideo,x11,dummy",
106 fprintf(stderr, "NPP_New\n");
108 if (instance == NULL)
109 return NPERR_INVALID_INSTANCE_ERROR;
111 instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
113 This = (PluginInstance*) instance->pdata;
116 return NPERR_OUT_OF_MEMORY_ERROR;
119 /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
121 This->fWindow = NULL;
126 This->p_vlc = vlc_create();
127 if( This->p_vlc == NULL )
129 return NPERR_GENERIC_ERROR;
132 i_ret = vlc_init( This->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
135 vlc_destroy( This->p_vlc );
137 return NPERR_GENERIC_ERROR;
140 i_ret = vlc_run( This->p_vlc );
143 vlc_end( This->p_vlc );
144 vlc_destroy( This->p_vlc );
146 return NPERR_GENERIC_ERROR;
150 This->psz_target = NULL;
152 for( i = 0; i < argc ; i++ )
154 fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
155 if(!strcmp(argn[i],"target"))
157 fprintf(stderr, "target specified: %s\n", argv[i]);
158 This->psz_target = strdup( argv[i] );
162 //__config_PutPsz( This->psz_target, argn[i], argv[i] );
169 NPError NPP_Destroy( NPP instance, NPSavedData** save )
171 PluginInstance* This;
173 fprintf(stderr, "NPP_Destroy\n");
175 if (instance == NULL)
176 return NPERR_INVALID_INSTANCE_ERROR;
178 This = (PluginInstance*) instance->pdata;
180 if( This->p_vlc != NULL )
182 vlc_stop( This->p_vlc );
183 vlc_end( This->p_vlc );
184 vlc_destroy( This->p_vlc );
188 if( This->psz_target )
190 free( This->psz_target );
191 This->psz_target = NULL;
195 NPN_MemFree(instance->pdata);
196 instance->pdata = NULL;
199 return NPERR_NO_ERROR;
202 NPError NPP_SetWindow( NPP instance, NPWindow* window )
204 NPError result = NPERR_NO_ERROR;
205 PluginInstance* This;
207 fprintf(stderr, "NPP_SetWindow\n");
209 if (instance == NULL)
210 return NPERR_INVALID_INSTANCE_ERROR;
212 This = (PluginInstance*) instance->pdata;
214 __config_PutInt( This->p_vlc, "x11-drawable", window->window );
215 __config_PutInt( This->p_vlc, "xvideo-drawable", window->window );
218 * Before setting window to point to the
219 * new window, you may wish to compare the new window
220 * info to the previous window (if any) to note window
225 Widget netscape_widget;
227 This->window = (Window) window->window;
230 This->width = window->width;
231 This->height = window->height;
232 This->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
234 netscape_widget = XtWindowToWidget(This->display, This->window);
235 XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, This);
236 Redraw(netscape_widget, (XtPointer)This, NULL);
239 This->fWindow = window;
242 if( !This->b_stream )
245 if( This->psz_target )
247 vlc_add_target( This->p_vlc, This->psz_target, PLAYLIST_APPEND, PLAYLIST_END );
249 vlc_add_target( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END );
258 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
259 NPBool seekable, uint16 *stype )
261 PluginInstance* This;
263 fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
265 if (instance == NULL)
266 return NPERR_INVALID_INSTANCE_ERROR;
268 This = (PluginInstance*) instance->pdata;
270 /* We want a *filename* ! */
274 if( This->b_stream == 0 )
276 This->psz_target = strdup( stream->url );
281 return NPERR_NO_ERROR;
285 /* PLUGIN DEVELOPERS:
286 * These next 2 functions are directly relevant in a plug-in which
287 * handles the data in a streaming manner. If you want zero bytes
288 * because no buffer space is YET available, return 0. As long as
289 * the stream has not been written to the plugin, Navigator will
290 * continue trying to send bytes. If the plugin doesn't want them,
291 * just return some large number from NPP_WriteReady(), and
292 * ignore them in NPP_Write(). For a NP_ASFILE stream, they are
293 * still called but can safely be ignored using this strategy.
296 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
297 * mode so we can take any size stream in our
298 * write call (since we ignore it) */
300 #define SARASS_SIZE (1024*1024)
302 int32 NPP_WriteReady( NPP instance, NPStream *stream )
304 PluginInstance* This;
306 fprintf(stderr, "NPP_WriteReady\n");
308 if (instance != NULL)
310 This = (PluginInstance*) instance->pdata;
311 /* Muahahahahahahaha */
312 return STREAMBUFSIZE;
313 //return SARASS_SIZE;
316 /* Number of bytes ready to accept in NPP_Write() */
317 return STREAMBUFSIZE;
322 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
323 int32 len, void *buffer )
325 fprintf(stderr, "NPP_Write %i\n", len);
327 if (instance != NULL)
329 //PluginInstance* This = (PluginInstance*) instance->pdata;
332 return len; /* The number of bytes accepted */
336 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
338 PluginInstance* This;
339 fprintf(stderr, "NPP_DestroyStream\n");
341 if (instance == NULL)
342 return NPERR_INVALID_INSTANCE_ERROR;
343 This = (PluginInstance*) instance->pdata;
345 return NPERR_NO_ERROR;
349 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
351 PluginInstance* This;
352 fprintf(stderr, "NPP_StreamAsFile\n");
353 if (instance != NULL)
355 This = (PluginInstance*) instance->pdata;
356 vlc_add_target( This->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
358 vlc_add_target( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END );
363 void NPP_Print( NPP instance, NPPrint* printInfo )
365 fprintf(stderr, "NPP_Print\n");
367 if(printInfo == NULL)
370 if (instance != NULL) {
371 PluginInstance* This = (PluginInstance*) instance->pdata;
373 if (printInfo->mode == NP_FULL) {
376 * If your plugin would like to take over
377 * printing completely when it is in full-screen mode,
378 * set printInfo->pluginPrinted to TRUE and print your
379 * plugin as you see fit. If your plugin wants Netscape
380 * to handle printing in this case, set
381 * printInfo->pluginPrinted to FALSE (the default) and
382 * do nothing. If you do want to handle printing
383 * yourself, printOne is true if the print button
384 * (as opposed to the print menu) was clicked.
385 * On the Macintosh, platformPrint is a THPrint; on
386 * Windows, platformPrint is a structure
387 * (defined in npapi.h) containing the printer name, port,
391 void* platformPrint =
392 printInfo->print.fullPrint.platformPrint;
394 printInfo->print.fullPrint.printOne;
397 printInfo->print.fullPrint.pluginPrinted = FALSE;
399 else { /* If not fullscreen, we must be embedded */
402 * If your plugin is embedded, or is full-screen
403 * but you returned false in pluginPrinted above, NPP_Print
404 * will be called with mode == NP_EMBED. The NPWindow
405 * in the printInfo gives the location and dimensions of
406 * the embedded plugin on the printed page. On the
407 * Macintosh, platformPrint is the printer port; on
408 * Windows, platformPrint is the handle to the printing
412 NPWindow* printWindow =
413 &(printInfo->print.embedPrint.window);
414 void* platformPrint =
415 printInfo->print.embedPrint.platformPrint;
420 /*******************************************************************************
422 // Notifies the instance of the completion of a URL request.
424 // NPP_URLNotify is called when Netscape completes a NPN_GetURLNotify or
425 // NPN_PostURLNotify request, to inform the plug-in that the request,
426 // identified by url, has completed for the reason specified by reason. The most
427 // common reason code is NPRES_DONE, indicating simply that the request
428 // completed normally. Other possible reason codes are NPRES_USER_BREAK,
429 // indicating that the request was halted due to a user action (for example,
430 // clicking the "Stop" button), and NPRES_NETWORK_ERR, indicating that the
431 // request could not be completed (for example, because the URL could not be
432 // found). The complete list of reason codes is found in npapi.h.
434 // The parameter notifyData is the same plug-in-private value passed as an
435 // argument to the corresponding NPN_GetURLNotify or NPN_PostURLNotify
436 // call, and can be used by your plug-in to uniquely identify the request.
437 ******************************************************************************/
438 void NPP_URLNotify( NPP instance, const char* url, NPReason reason,
443 /*******************************************************************************
445 ******************************************************************************/
446 static void Redraw( Widget w, XtPointer closure, XEvent *event )
448 PluginInstance* This = (PluginInstance*)closure;
451 const char* text = "hello d00dZ, I'm in void Redraw()";
453 XtVaGetValues(w, XtNbackground, &gcv.background,
454 XtNforeground, &gcv.foreground, 0);
455 gc = XCreateGC(This->display, This->window,
456 GCForeground|GCBackground, &gcv);
457 XDrawRectangle(This->display, This->window, gc,
458 0, 0, This->width-1, This->height-1);
459 XDrawString(This->display, This->window, gc,
460 This->width/2 - 100, This->height/2,