313
Bool Osmozilla_EventProc(void *priv, GF_Event *evt)
315
Bool nsOsmozillaInstance::EventProc(GF_Event *evt)
315
nsOsmozillaInstance *gpac = (nsOsmozillaInstance *) priv;
316
if (!gpac->m_term) return 0;
319
if (!m_term) return 0;
318
321
switch (evt->type) {
319
322
case GF_EVT_MESSAGE:
323
const char *servName = "main service";
324
323
if (!evt->message.message) return 0;
325
if (evt->message.error)
326
fprintf(stdout, "plugin :%s (%s): %s\n", evt->message.message, servName, gf_error_to_string(evt->message.error));
328
else if (strstr(evt->message.message, "Download") || strstr(evt->message.message, "Buffering") || strstr(evt->message.message, "Importing"))
329
fprintf(stdout, "plugin :%s (%s)\r", evt->message.message, servName);
324
if (evt->message.error)
325
sprintf((char *)msg, "GPAC: %s (%s)", evt->message.message, gf_error_to_string(evt->message.error));
331
fprintf(stdout, "plugin :%s (%s)\n", evt->message.message, servName);
327
sprintf((char *)msg, "GPAC: %s", evt->message.message);
329
NPN_Status(mInstance, msg);
331
case GF_EVT_PROGRESS:
332
if (evt->progress.done == evt->progress.total) {
333
NPN_Status(mInstance, "");
336
if (evt->progress.progress_type==0) szTitle = "Buffer ";
337
else if (evt->progress.progress_type==1) szTitle = "Download ";
338
else if (evt->progress.progress_type==2) szTitle = "Import ";
339
sprintf(msg, "(GPAC) %s: %02.2f", szTitle, (100.0*evt->progress.done) / evt->progress.total);
340
NPN_Status(mInstance, msg);
344
/*IGNORE any scene size, just work with the size allocated in the parent doc*/
345
case GF_EVT_SCENE_SIZE:
346
gf_term_set_size(m_term, m_width, m_height);
348
/*window has been resized (full-screen plugin), resize*/
336
349
case GF_EVT_SIZE:
337
gf_term_set_size(gpac->m_term, gpac->m_width, gpac->m_height);
350
m_width = evt->size.width;
351
m_height = evt->size.height;
352
gf_term_set_size(m_term, m_width, m_height);
339
354
case GF_EVT_CONNECT:
340
gpac->m_bIsConnected = 1;
341
/*pause upon connection*/
342
if (!gpac->m_bAutoStart) {
343
gpac->m_bAutoStart = 1;
344
gf_term_set_option(gpac->m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);
355
m_bIsConnected = evt->connect.is_connected;
347
case GF_EVT_DURATION:
357
case GF_EVT_DURATION:
358
m_bCanSeek = evt->duration.can_seek;
359
m_Duration = evt->duration.duration;
349
361
case GF_EVT_LDOUBLECLICK:
350
gf_term_set_option(gpac->m_term, GF_OPT_FULLSCREEN, !gf_term_get_option(gpac->m_term, GF_OPT_FULLSCREEN));
362
gf_term_set_option(m_term, GF_OPT_FULLSCREEN, !gf_term_get_option(m_term, GF_OPT_FULLSCREEN));
352
364
case GF_EVT_VKEYDOWN:
353
365
if ((evt->key.key_states & GF_KM_ALT)) {
355
367
switch (evt->key.vk_code) {
357
gf_term_set_option(gpac->m_term, GF_OPT_NAVIGATION_TYPE, 1);
369
gf_term_set_option(m_term, GF_OPT_NAVIGATION_TYPE, 1);
359
371
case GF_VK_ESCAPE:
360
gf_term_set_option(gpac->m_term, GF_OPT_FULLSCREEN, !gf_term_get_option(gpac->m_term, GF_OPT_FULLSCREEN));
372
gf_term_set_option(m_term, GF_OPT_FULLSCREEN, !gf_term_get_option(m_term, GF_OPT_FULLSCREEN));
377
case GF_EVT_NAVIGATE_INFO:
378
strcpy(msg, evt->navigate.to_url);
379
NPN_Status(mInstance, msg);
381
case GF_EVT_NAVIGATE:
382
if (gf_term_is_supported_url(m_term, evt->navigate.to_url, 1, 1)) {
383
gf_term_navigate_to(m_term, evt->navigate.to_url);
387
char *target = "_self";
389
for (i=0; i<evt->navigate.param_count; i++) {
390
if (!strcmp(evt->navigate.parameters[i], "_parent")) target = "_parent";
391
else if (!strcmp(evt->navigate.parameters[i], "_blank")) target = "_blank";
392
else if (!strcmp(evt->navigate.parameters[i], "_top")) target = "_top";
393
else if (!strcmp(evt->navigate.parameters[i], "_new")) target = "_new";
394
else if (!strnicmp(evt->navigate.parameters[i], "_target=", 8)) target = (char *) evt->navigate.parameters[i]+8;
396
NPN_GetURL(mInstance, evt->navigate.to_url, target);
404
Bool Osmozilla_EventProc(void *priv, GF_Event *evt)
406
nsOsmozillaInstance *gpac = (nsOsmozillaInstance *) priv;
407
return gpac->EventProc(evt);
370
410
NPError nsOsmozillaInstance::SetWindow(NPWindow* aWindow)
372
412
if (mInitialized) {
373
m_width = aWindow->width;
374
m_height = aWindow->height;
375
if (m_bIsConnected) gf_term_set_size(m_term, m_width, m_height);
413
m_width = aWindow->width;
414
m_height = aWindow->height;
415
if (m_bIsConnected) gf_term_set_size(m_term, m_width, m_height);
378
419
if(aWindow == NULL) return FALSE;
380
421
m_width = aWindow->width;
390
m_user.os_window_handler = aWindow->window;
391
/*HACK - although we don't use the display in the X11 plugin, this is
392
used to signal that the user is mozilla and prevent some X11 calls crashing the browser in file playing mode (eg, "firefox myfile.mp4" )*/
393
m_user.os_display =((NPSetWindowCallbackStruct *)aWindow->ws_info)->display;
394
XSynchronize((Display *) m_user.os_display, True);
395
m_user.os_window_handler = aWindow->window;
431
m_user.os_window_handler = aWindow->window;
432
/*HACK - although we don't use the display in the X11 plugin, this is used to signal that
433
the user is mozilla and prevent some X11 calls crashing the browser in file playing mode
434
(eg, "firefox myfile.mp4" )*/
435
m_user.os_display =((NPSetWindowCallbackStruct *)aWindow->ws_info)->display;
436
XSynchronize((Display *) m_user.os_display, True);
437
m_user.os_window_handler = aWindow->window;
444
/*setup 3D mode if requested*/
445
gf_cfg_set_key(m_user.config, "Rendering", "RendererName", m_bUse3D ? "GPAC 3D Renderer" : "GPAC 2D Renderer");
398
446
m_term = gf_term_new(&m_user);
399
447
if (! m_term) return NPERR_GENERIC_ERROR;
404
449
mInitialized = TRUE;
406
452
if (!m_szURL) return TRUE;
408
/*all protocols not handled by mozilla are just ignored, so we get them from the option list
409
and forget about mozilla...*/
410
if (!strnicmp(m_szURL, "rtsp://", 7)
411
|| !strnicmp(m_szURL, "rtp://", 6)
415
gf_term_connect(m_term, (const char *) m_szURL);
453
/*connect from 0 and pause if not autoplay*/
454
gf_term_connect_from_time(m_term, m_szURL, 0, m_bAutoStart ? 0 : 1);
424
458
void nsOsmozillaInstance::SetOptions()
426
const char *sOpt = gf_cfg_get_key(m_user.config, "General", "Loop");
427
m_Loop = (sOpt && !stricmp(sOpt, "yes")) ? 1 : 0;
428
461
m_bAutoStart = 1;
430
464
/*options sent from plugin*/
431
465
for(int i=0;i<m_argc;i++) {
432
if (!stricmp(m_argn[i],"Autostart") && !stricmp(m_argv[i], "False"))
466
if (!stricmp(m_argn[i],"autostart") && (!stricmp(m_argv[i], "false") || !stricmp(m_argv[i], "no")) )
433
467
m_bAutoStart = 0;
435
469
else if (!stricmp(m_argn[i],"src") ) {
470
if (m_szURL) free(m_szURL);
436
471
m_szURL = strdup(m_argv[i]);
438
else if (!stricmp(m_argn[i],"AspectRatio")) {
473
else if (!stricmp(m_argn[i],"use3d") && (!stricmp(m_argv[i], "true") || !stricmp(m_argv[i], "yes") ) ) {
476
else if (!stricmp(m_argn[i],"loop") && (!stricmp(m_argv[i], "true") || !stricmp(m_argv[i], "yes") ) ) {
479
else if (!stricmp(m_argn[i],"aspectratio")) {
439
480
u32 ar = GF_ASPECT_RATIO_KEEP;
440
if (!stricmp(m_argv[i], "Keep")) ar = GF_ASPECT_RATIO_KEEP;
481
if (!stricmp(m_argv[i], "keep")) ar = GF_ASPECT_RATIO_KEEP;
441
482
else if (!stricmp(m_argv[i], "16:9")) ar = GF_ASPECT_RATIO_16_9;
442
483
else if (!stricmp(m_argv[i], "4:3")) ar = GF_ASPECT_RATIO_4_3;
443
else if (!stricmp(m_argv[i], "Fill")) ar = GF_ASPECT_RATIO_FILL_SCREEN;
484
else if (!stricmp(m_argv[i], "fill")) ar = GF_ASPECT_RATIO_FILL_SCREEN;
444
485
gf_term_set_option(m_term, GF_OPT_ASPECT_RATIO, ar);
489
/*URL is not absolute, request new stream to mozilla - we don't pass absolute URLs since some may not be
492
Bool absolute_url = 0;
493
if (strstr(m_szURL, "://")) absolute_url = 1;
494
else if (m_szURL[0] == '/') {
495
FILE *test = fopen(m_szURL, "rb");
501
else if ((m_szURL[1] == ':') && (m_szURL[2] == '\\')) absolute_url = 1;
503
if (!absolute_url) NPN_GetURL(mInstance, m_szURL, NULL);
449
510
NPError nsOsmozillaInstance::NewStream(NPMIMEType type, NPStream * stream,
450
511
NPBool seekable, uint16 * stype)
513
if (m_szURL) free(m_szURL);
452
514
m_szURL = strdup((const char *)stream->url);
453
gf_term_connect(m_term, (const char *) m_szURL);
516
/*connect from 0 and pause if not autoplay*/
517
gf_term_connect_from_time(m_term, m_szURL, 0, m_bAutoStart ? 0 : 1);
519
/*we handle data fetching ourselves*/
454
520
*stype = NP_SEEK;
455
521
return NPERR_NO_ERROR;
465
531
return NPERR_NO_ERROR;
468
void nsOsmozillaInstance::StreamAsFile(NPStream* stream, const char* fname)
470
m_szURL = strdup((const char *)stream->url);
471
gf_term_connect(m_term, (const char *) m_szURL);
474
void nsOsmozillaInstance::URLNotify(const char *url, NPReason reason, void *notifyData)
478
534
uint16 nsOsmozillaInstance::HandleEvent(void* event)
483
void nsOsmozillaInstance::SetArg(nsPluginCreateData * aCreateDataStruct)
485
m_argc=aCreateDataStruct->argc;
486
m_argv=aCreateDataStruct->argv;
487
m_argn=aCreateDataStruct->argn;
490
539
void nsOsmozillaInstance::Pause()
492
gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);
542
if (gf_term_get_option(m_term, GF_OPT_PLAY_STATE) == GF_STATE_PAUSED) {
543
gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);
545
gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);
495
550
void nsOsmozillaInstance::Play()
498
if (!m_bIsConnected && !m_bAutoStart) {
500
gf_term_connect(m_term, (const char *) m_szURL);
552
if (!m_bIsConnected) {
553
if (m_szURL) gf_term_connect(m_term, (const char *) m_szURL);
503
555
gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);
506
void nsOsmozillaInstance::Reload()
508
gf_term_reload(m_term);
559
void nsOsmozillaInstance::Stop()
561
gf_term_disconnect(m_term);
564
#include <gpac/term_info.h>
565
void nsOsmozillaInstance::Update(const char *type, const char *commands)
568
GF_Err e = gf_term_scene_update(m_term, (char *) type, (char *) commands);
571
sprintf((char *)szMsg, "GPAC: Error applying update (%s)", gf_error_to_string(e) );
572
NPN_Status(mInstance, szMsg);