~ubuntu-branches/ubuntu/raring/gpac/raring

« back to all changes in this revision

Viewing changes to applications/osmozilla/osmozilla.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-24 23:34:57 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070124233457-zzlls8afkt0nyakj
Tags: 0.4.2~rc2-0ubuntu1
* New upstream release
  * Most notably MP4 tagging support via MP4Box -itags
* debian/patches/01_64bits.dpatch: dropped; included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
#ifdef XP_WIN
175
175
        m_hWnd = NULL;
176
176
#endif
177
 
        
 
177
 
178
178
        mScriptablePeer = NULL;
179
179
        mInitialized = 0;
180
180
 
183
183
        m_term = NULL;
184
184
        m_bIsConnected = 0;
185
185
        
186
 
        
187
 
        SetArg(aCreateDataStruct);
 
186
        m_argc=aCreateDataStruct->argc;
 
187
        m_argv=aCreateDataStruct->argv;
 
188
        m_argn=aCreateDataStruct->argn;
188
189
}
189
190
 
190
191
nsOsmozillaInstance::~nsOsmozillaInstance()
207
208
        const char *str;
208
209
        
209
210
        if(aWindow == NULL) return FALSE;
 
211
        
210
212
 
211
213
#ifdef XP_WIN
212
214
        gpac_cfg = "GPAC.cfg";
310
312
    return rv;
311
313
}
312
314
 
313
 
Bool Osmozilla_EventProc(void *priv, GF_Event *evt)
 
315
Bool nsOsmozillaInstance::EventProc(GF_Event *evt)
314
316
{
315
 
        nsOsmozillaInstance *gpac = (nsOsmozillaInstance *) priv;
316
 
        if (!gpac->m_term) return 0;
317
 
        
 
317
        char msg[1024];
 
318
 
 
319
        if (!m_term) return 0;
 
320
 
318
321
        switch (evt->type) {
319
322
        case GF_EVT_MESSAGE:
320
 
        /*FIXME !!!*/
321
 
#if 0
322
 
        {       
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));
327
 
                /*file download*/
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));
330
326
                else
331
 
                        fprintf(stdout, "plugin :%s (%s)\n", evt->message.message, servName);
332
 
        }
333
 
#endif
334
 
                break;
335
 
 
 
327
                        sprintf((char *)msg, "GPAC: %s", evt->message.message);
 
328
 
 
329
                NPN_Status(mInstance, msg);
 
330
                break;
 
331
        case GF_EVT_PROGRESS:
 
332
                if (evt->progress.done == evt->progress.total) {
 
333
                        NPN_Status(mInstance, "");
 
334
                } else {
 
335
                        char *szTitle = "";
 
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);
 
341
                }
 
342
                break;
 
343
 
 
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);
 
347
                break;
 
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);
338
353
                break;
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);
345
 
                }
 
355
                m_bIsConnected = evt->connect.is_connected;
346
356
                break;
347
 
        case GF_EVT_DURATION:           
 
357
        case GF_EVT_DURATION:   
 
358
                m_bCanSeek = evt->duration.can_seek;
 
359
                m_Duration = evt->duration.duration;
348
360
                break;
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));
351
363
                break;
352
364
        case GF_EVT_VKEYDOWN:
353
365
                if ((evt->key.key_states & GF_KM_ALT)) {
354
 
    } else {
 
366
            } else {
355
367
                        switch (evt->key.vk_code) {
356
368
                        case GF_VK_HOME:
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);
358
370
                                break;
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));
361
373
                                break;
362
374
                        }
363
 
    }
364
 
    break;
 
375
                }
 
376
            break;
 
377
        case GF_EVT_NAVIGATE_INFO:
 
378
                strcpy(msg, evt->navigate.to_url);
 
379
                NPN_Status(mInstance, msg);
 
380
                break;
 
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);
 
384
                        return 1;
 
385
                } else {
 
386
                        u32 i;
 
387
                        char *target = "_self";
 
388
 
 
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;
 
395
                        }
 
396
                        NPN_GetURL(mInstance, evt->navigate.to_url, target);
 
397
                        return 1;
 
398
                }
 
399
                break;
365
400
        }
366
401
        return 0;
367
402
}
368
403
 
 
404
Bool Osmozilla_EventProc(void *priv, GF_Event *evt)
 
405
{
 
406
        nsOsmozillaInstance *gpac = (nsOsmozillaInstance *) priv;
 
407
        return gpac->EventProc(evt);
 
408
}
369
409
 
370
410
NPError nsOsmozillaInstance::SetWindow(NPWindow* aWindow)
371
411
{
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);
376
 
    return TRUE;
377
 
  }
 
413
                m_width = aWindow->width;
 
414
                m_height = aWindow->height;
 
415
                if (m_bIsConnected) gf_term_set_size(m_term, m_width, m_height);
 
416
                return TRUE;
 
417
        }
 
418
        
378
419
        if(aWindow == NULL) return FALSE;
379
420
 
380
421
        m_width = aWindow->width;
387
428
#endif
388
429
 
389
430
#ifdef XP_UNIX
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;
396
438
#endif
397
 
                
 
439
 
 
440
        m_prev_time = 0;
 
441
        m_url_changed = 0;
 
442
        SetOptions();
 
443
 
 
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;
400
448
 
401
 
        m_prev_time = 0;
402
 
        SetOptions();
403
 
        m_url_changed = 0;
404
449
        mInitialized = TRUE;
405
450
 
 
451
        /*stream not ready*/
406
452
        if (!m_szURL) return TRUE;
407
 
 
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) 
412
 
                ) {
413
 
 
414
 
                if (m_bAutoStart) 
415
 
                        gf_term_connect(m_term, (const char *) m_szURL);
416
 
        } else {
417
 
                free(m_szURL);
418
 
                m_szURL = NULL;
419
 
        }
 
453
        /*connect from 0 and pause if not autoplay*/
 
454
        gf_term_connect_from_time(m_term, m_szURL, 0, m_bAutoStart ? 0 : 1);
420
455
        return TRUE;
421
456
}
422
457
 
423
 
 
424
458
void nsOsmozillaInstance::SetOptions()
425
459
{
426
 
        const char *sOpt = gf_cfg_get_key(m_user.config, "General", "Loop");
427
 
        m_Loop = (sOpt && !stricmp(sOpt, "yes")) ? 1 : 0;
 
460
        m_bLoop = 0;
428
461
        m_bAutoStart = 1;
 
462
        m_bUse3D = 0;           
429
463
 
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;
434
468
 
435
469
                else if (!stricmp(m_argn[i],"src") ) {
 
470
                        if (m_szURL) free(m_szURL);
436
471
                        m_szURL = strdup(m_argv[i]);
437
472
                }
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") ) ) {
 
474
                        m_bUse3D = 1;
 
475
                }
 
476
                else if (!stricmp(m_argn[i],"loop") && (!stricmp(m_argv[i], "true") || !stricmp(m_argv[i], "yes") ) ) {
 
477
                        m_bLoop = 1;
 
478
                }
 
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);
445
486
                }
446
487
        }
 
488
 
 
489
        /*URL is not absolute, request new stream to mozilla - we don't pass absolute URLs since some may not be 
 
490
        handled by gecko */
 
491
        if (m_szURL) {
 
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");
 
496
                        if (test) {     
 
497
                                absolute_url = 1;
 
498
                                fclose(test);
 
499
                        }
 
500
                }
 
501
                else if ((m_szURL[1] == ':') && (m_szURL[2] == '\\')) absolute_url = 1;
 
502
 
 
503
                if (!absolute_url) NPN_GetURL(mInstance, m_szURL, NULL);
 
504
                free(m_szURL);
 
505
                m_szURL = NULL;
 
506
        }
 
507
 
447
508
}
448
509
 
449
510
NPError nsOsmozillaInstance::NewStream(NPMIMEType type, NPStream * stream,
450
511
                                    NPBool seekable, uint16 * stype)
451
512
{
 
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);
 
515
 
 
516
        /*connect from 0 and pause if not autoplay*/
 
517
        gf_term_connect_from_time(m_term, m_szURL, 0, m_bAutoStart ? 0 : 1);
 
518
 
 
519
        /*we handle data fetching ourselves*/
454
520
    *stype = NP_SEEK;
455
521
    return NPERR_NO_ERROR;
456
522
}
465
531
        return NPERR_NO_ERROR;
466
532
}
467
533
 
468
 
void nsOsmozillaInstance::StreamAsFile(NPStream* stream, const char* fname)
469
 
{
470
 
        m_szURL = strdup((const char *)stream->url);
471
 
        gf_term_connect(m_term, (const char *) m_szURL);
472
 
}
473
 
 
474
 
void nsOsmozillaInstance::URLNotify(const char *url, NPReason reason, void *notifyData)
475
 
{
476
 
}
477
 
 
478
534
uint16 nsOsmozillaInstance::HandleEvent(void* event)
479
535
{
480
536
  return true;
481
537
}
482
538
 
483
 
void nsOsmozillaInstance::SetArg(nsPluginCreateData * aCreateDataStruct)
484
 
{
485
 
        m_argc=aCreateDataStruct->argc;
486
 
        m_argv=aCreateDataStruct->argv;
487
 
        m_argn=aCreateDataStruct->argn;
488
 
}
489
 
 
490
539
void nsOsmozillaInstance::Pause()
491
540
{
492
 
        gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);
 
541
        if (m_term) {
 
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);
 
544
                } else {
 
545
                gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PAUSED);
 
546
                }
 
547
        }
493
548
}
494
549
 
495
550
void nsOsmozillaInstance::Play()
496
551
{
497
 
        /*for RTSP & co*/
498
 
        if (!m_bIsConnected && !m_bAutoStart) {
499
 
                m_bAutoStart = 1;
500
 
                gf_term_connect(m_term, (const char *) m_szURL);
501
 
        }
502
 
        else
 
552
        if (!m_bIsConnected) {
 
553
                if (m_szURL) gf_term_connect(m_term, (const char *) m_szURL);
 
554
        } else {
503
555
                gf_term_set_option(m_term, GF_OPT_PLAY_STATE, GF_STATE_PLAYING);
504
 
}
505
 
 
506
 
void nsOsmozillaInstance::Reload()
507
 
{
508
 
        gf_term_reload(m_term);
 
556
        }
 
557
}
 
558
 
 
559
void nsOsmozillaInstance::Stop()
 
560
{
 
561
        gf_term_disconnect(m_term);
 
562
}
 
563
 
 
564
#include <gpac/term_info.h>
 
565
void nsOsmozillaInstance::Update(const char *type, const char *commands)
 
566
{
 
567
        if (m_term) {
 
568
                GF_Err e = gf_term_scene_update(m_term, (char *) type, (char *) commands);
 
569
                if (e) {
 
570
                        char szMsg[1024];
 
571
                        sprintf((char *)szMsg, "GPAC: Error applying update (%s)", gf_error_to_string(e) );
 
572
                        NPN_Status(mInstance, szMsg);
 
573
                }
 
574
        }
509
575
}
510
576
 
511
577
 
539
605
//NS_IMPL_ISUPPORTS2(nsOsmozillaPeer, nsITestPlugin, nsIClassInfo)
540
606
 
541
607
        // the following method will be callable from JavaScript
542
 
NS_IMETHODIMP nsOsmozillaPeer::Pause()
543
 
{
544
 
        mPlugin->Pause();
545
 
        return NS_OK;
546
 
}
547
 
 
548
 
NS_IMETHODIMP nsOsmozillaPeer::Play()
549
 
{
550
 
        mPlugin->Play();
551
 
        return NS_OK;
552
 
}
553
 
 
554
 
NS_IMETHODIMP nsOsmozillaPeer::Reload()
555
 
{
556
 
        mPlugin->Reload();
557
 
        return NS_OK;
 
608
NS_IMETHODIMP nsOsmozillaPeer::Pause() { mPlugin->Pause(); return NS_OK; }
 
609
NS_IMETHODIMP nsOsmozillaPeer::Play() { mPlugin->Play(); return NS_OK; }
 
610
NS_IMETHODIMP nsOsmozillaPeer::Stop() { mPlugin->Stop(); return NS_OK; }
 
611
 
 
612
NS_IMETHODIMP nsOsmozillaPeer::Update(const char *type, const char *commands) 
 
613
{
 
614
        mPlugin->Update(type, commands); 
 
615
        return NS_OK; 
558
616
}
559
617
 
560
618
void nsOsmozillaPeer::SetInstance(nsOsmozillaInstance * plugin)