~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to src/terminal/terminal.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
307
307
        
308
308
        /*reload term part*/
309
309
 
310
 
        sOpt = gf_cfg_get_key(term->user->config, "Systems", "AlwaysDrawBIFS");
 
310
        sOpt = gf_cfg_get_key(term->user->config, "Systems", "DrawLateFrames");
311
311
        if (sOpt && !stricmp(sOpt, "yes"))
312
 
                term->flags &= ~GF_TERM_SYSDEC_RESYNC;
 
312
                term->flags &= ~GF_TERM_DROP_LATE_FRAMES;
313
313
        else
314
 
                term->flags |= GF_TERM_SYSDEC_RESYNC;
 
314
                term->flags |= GF_TERM_DROP_LATE_FRAMES;
315
315
 
316
316
        sOpt = gf_cfg_get_key(term->user->config, "Systems", "ForceSingleClock");
317
317
        if (sOpt && !stricmp(sOpt, "yes")) 
517
517
        }
518
518
}
519
519
 
 
520
Bool gf_term_is_type_supported(GF_Terminal *term, const char* mime)
 
521
{
 
522
        if (mime) {
 
523
                /* TODO: handle codecs and params */
 
524
                const char *sPlug;
 
525
                sPlug = gf_cfg_get_key(term->user->config, "MimeTypes", mime);
 
526
                if (sPlug) {
 
527
                        return 1;
 
528
                } else {
 
529
                        return 0;
 
530
                }
 
531
        } else {
 
532
                return 0;
 
533
        }
 
534
}
520
535
 
521
536
GF_EXPORT
522
537
GF_Terminal *gf_term_new(GF_User *user)
537
552
        memset(tmp, 0, sizeof(GF_Terminal));
538
553
 
539
554
        /*just for safety*/
540
 
        gf_sys_init(0);
 
555
        gf_sys_init(GF_FALSE);
541
556
 
542
557
        tmp->user = user;
543
558
 
630
645
                        gf_list_add(tmp->unthreaded_extensions, ifce);
631
646
        }
632
647
 
 
648
        gf_term_lock_media_queue(tmp, 1);
633
649
        if (!gf_list_count(tmp->unthreaded_extensions)) {
634
650
                gf_list_del(tmp->unthreaded_extensions);
635
651
                tmp->unthreaded_extensions = NULL;
636
652
        }
 
653
        gf_term_lock_media_queue(tmp, 0);
 
654
 
637
655
        if (0 == gf_cfg_get_key_count(user->config, "MimeTypes")){
638
 
          GF_LOG(GF_LOG_INFO, GF_LOG_MEDIA, ("[Terminal] Initializing Mime Types..."));
639
 
          /* No mime-types detected, probably the first launch */
640
 
          for (i=0; i< gf_modules_get_count(user->modules); i++) {
641
 
                GF_BaseInterface *ifce = gf_modules_load_interface(user->modules, i, GF_NET_CLIENT_INTERFACE);
642
 
                if (ifce) {
643
 
                  GF_InputService * service = (GF_InputService*) ifce;
644
 
                  GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Core] Asking mime types supported for new module %s...\n", ifce->module_name));
645
 
                  if (service->RegisterMimeTypes){
646
 
                    u32 num = service->RegisterMimeTypes(service);
647
 
                    GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Core] module %s has registered %u new mime-types.\n", ifce->module_name, num));
648
 
                  } else {
649
 
                    GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Core] Module %s has not declared any RegisterMimeTypes method, cannot guess its supported mime-types.\n", ifce->module_name));
650
 
                  }
651
 
                  gf_modules_close_interface(ifce);
 
656
                GF_LOG(GF_LOG_INFO, GF_LOG_MEDIA, ("[Terminal] Initializing Mime Types..."));
 
657
                /* No mime-types detected, probably the first launch */
 
658
                for (i=0; i< gf_modules_get_count(user->modules); i++) {
 
659
                        GF_BaseInterface *ifce = gf_modules_load_interface(user->modules, i, GF_NET_CLIENT_INTERFACE);
 
660
                        if (ifce) {
 
661
                                GF_InputService * service = (GF_InputService*) ifce;
 
662
                                GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Core] Asking mime types supported for new module %s...\n", ifce->module_name));
 
663
                                if (service->RegisterMimeTypes){
 
664
                                        u32 num = service->RegisterMimeTypes(service);
 
665
                                        GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("[Core] module %s has registered %u new mime-types.\n", ifce->module_name, num));
 
666
                                } else {
 
667
                                        GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Core] Module %s has not declared any RegisterMimeTypes method, cannot guess its supported mime-types.\n", ifce->module_name));
 
668
                                }
 
669
                                gf_modules_close_interface(ifce);
 
670
                        }
652
671
                }
653
 
          }
654
 
          GF_LOG(GF_LOG_INFO, GF_LOG_MEDIA, ("[Terminal] Finished Initializing Mime Types."));
655
 
          
 
672
                GF_LOG(GF_LOG_INFO, GF_LOG_MEDIA, ("[Terminal] Finished Initializing Mime Types."));
656
673
        }
657
674
 
658
675
        tmp->uri_relocators = gf_list_new();
777
794
{
778
795
        GF_Event evt;
779
796
        if (!term || !term->user) return;
 
797
        memset(&evt, 0, sizeof(GF_Event));
780
798
        evt.type = GF_EVENT_MESSAGE;
781
799
        evt.message.service = service;
782
800
        evt.message.message = message;
907
925
        case GF_OPT_MEDIA_CACHE:
908
926
                gf_term_set_cache_state(term, value);
909
927
                return GF_OK;
 
928
        case GF_OPT_HTTP_MAX_RATE:
 
929
                gf_dm_set_data_rate(term->downloader, value);
 
930
                return GF_OK;
 
931
        case GF_OPT_VIDEO_BENCH:
 
932
                term->bench_mode = value;
 
933
                //fallthrough
910
934
        default:
911
935
                return gf_sc_set_option(term->compositor, type, value);
912
936
        }
922
946
}
923
947
 
924
948
GF_EXPORT
925
 
Double gf_term_get_simulation_frame_rate(GF_Terminal *term)
 
949
Double gf_term_get_simulation_frame_rate(GF_Terminal *term, u32 *nb_frames_drawn)
926
950
{
927
 
        return term ? term->compositor->frame_rate : 0.0;
 
951
        if (!term) return 0.0;
 
952
        if (nb_frames_drawn) *nb_frames_drawn = term->compositor->frame_number;
 
953
        return term->compositor->frame_rate;
928
954
}
929
955
 
930
956
 
964
990
                                if (!ck) return GF_STATE_PAUSED;
965
991
                        }
966
992
                        if (ck->Buffering)
967
 
                                return GF_STATE_STEP_PAUSE;
 
993
                                return GF_STATE_PLAYING;
968
994
                }
969
995
                if (term->play_state != GF_STATE_PLAYING) return GF_STATE_PAUSED;
970
996
                return GF_STATE_PLAYING;
973
999
                else if (term->root_scene && term->root_scene->root_od->net_service->cache) return GF_MEDIA_CACHE_RUNNING;
974
1000
                else return GF_MEDIA_CACHE_ENABLED;
975
1001
        case GF_OPT_CAN_SELECT_STREAMS: return (term->root_scene && term->root_scene->is_dynamic_scene) ? 1 : 0;
 
1002
        case GF_OPT_HTTP_MAX_RATE: return gf_dm_get_data_rate(term->downloader);
 
1003
        case GF_OPT_VIDEO_BENCH: return term->bench_mode ? GF_TRUE : GF_FALSE;
 
1004
 
976
1005
        default: return gf_sc_get_option(term->compositor, type);
977
1006
        }
978
1007
}
1117
1146
        }
1118
1147
 
1119
1148
        /*extensions*/
 
1149
        gf_term_lock_media_queue(term, 1);
1120
1150
        if (!term->reload_state && term->unthreaded_extensions) {
1121
1151
                u32 i, count;
1122
1152
                count = gf_list_count(term->unthreaded_extensions);
1125
1155
                        ifce->process(ifce, GF_TERM_EXT_PROCESS, NULL);
1126
1156
                }
1127
1157
        }
 
1158
        gf_term_lock_media_queue(term, 0);
1128
1159
 
1129
1160
        
1130
1161
        /*need to reload*/
1246
1277
}
1247
1278
 
1248
1279
#ifndef GPAC_DISABLE_SVG
1249
 
static void media_event_collect_info(GF_ClientService *net, GF_ObjectManager *odm, GF_DOMMediaEvent *media_event, u32 *min_time, u32 *min_buffer)
 
1280
void media_event_collect_info(GF_ClientService *net, GF_ObjectManager *odm, GF_DOMMediaEvent *media_event, u32 *min_time, u32 *min_buffer)
1250
1281
{
1251
1282
        u32 i=0;
1252
1283
        GF_Channel *ch;
1255
1286
                u32 val;
1256
1287
                if (ch->service != net) continue;
1257
1288
 
1258
 
                media_event->bufferValid = 1;
 
1289
                gf_mx_p(ch->mx);
 
1290
                
 
1291
                media_event->bufferValid = GF_TRUE;
1259
1292
                if (ch->BufferTime>0) {
1260
1293
                        if (ch->MaxBuffer) {
1261
1294
                                val = (ch->BufferTime * 100) / ch->MaxBuffer;
1269
1302
                        *min_time = 0;
1270
1303
                        *min_buffer = 0;
1271
1304
                }
 
1305
                gf_mx_v(ch->mx);
1272
1306
        }
1273
1307
}
1274
1308
#endif
1275
1309
 
1276
 
void gf_term_service_media_event_with_download(GF_ObjectManager *odm, u32 event_type, u64 loaded_size, u64 total_size, u32 bytes_per_sec)
 
1310
void gf_term_service_media_event_with_download(GF_ObjectManager *odm, GF_EventType event_type, u64 loaded_size, u64 total_size, u32 bytes_per_sec)
1277
1311
{
1278
1312
#ifndef GPAC_DISABLE_SVG
1279
1313
        u32 i, count, min_buffer, min_time;
1285
1319
 
1286
1320
        if (!odm || !odm->net_service) return;
1287
1321
        if (odm->mo) {
1288
 
                count = gf_list_count(odm->mo->nodes);
 
1322
                count = gf_mo_event_target_count(odm->mo);
1289
1323
                if (!count) return;
1290
 
                if (!(gf_node_get_dom_event_filter(gf_list_get(odm->mo->nodes, 0)) & GF_DOM_EVENT_MEDIA))
 
1324
                if (0 && !(gf_node_get_dom_event_filter((GF_Node *)gf_event_target_get_node(gf_mo_event_target_get(odm->mo, 0))) & GF_DOM_EVENT_MEDIA))
1291
1325
                        return;
1292
1326
        } else {
1293
1327
                count = 0;
1295
1329
 
1296
1330
 
1297
1331
        memset(&media_event, 0, sizeof(GF_DOMMediaEvent));
1298
 
        media_event.bufferValid = 0;
 
1332
        media_event.bufferValid = GF_FALSE;
1299
1333
        media_event.session_name = odm->net_service->url;
1300
1334
 
1301
1335
        min_time = min_buffer = (u32) -1;
1325
1359
        if (!locked) return;
1326
1360
 
1327
1361
        for (i=0; i<count; i++) {
1328
 
                GF_Node *node = gf_list_get(odm->mo->nodes, i);
1329
 
                gf_dom_event_fire(node, &evt);
 
1362
                GF_DOMEventTarget *target = (GF_DOMEventTarget *)gf_list_get(odm->mo->evt_targets, i);
 
1363
                sg_fire_dom_event(target, &evt, scene->graph, NULL);
1330
1364
        }
1331
1365
        if (!count) {
1332
1366
                GF_Node *root = gf_sg_get_root_node(scene->graph);
1333
1367
                if (root) gf_dom_event_fire(root, &evt);
1334
1368
        }
1335
 
        gf_sc_lock(odm->term->compositor, 0);
 
1369
        gf_sc_lock(odm->term->compositor, GF_FALSE);
1336
1370
#endif
1337
1371
}
1338
1372
 
1339
 
void gf_term_service_media_event(GF_ObjectManager *odm, u32 event_type)
 
1373
void gf_term_service_media_event(GF_ObjectManager *odm, GF_EventType event_type)
1340
1374
{
1341
1375
        gf_term_service_media_event_with_download(odm, event_type, 0, 0, 0);
1342
1376
}
1496
1530
        gf_term_cleanup_pending_session(term, ns);
1497
1531
}
1498
1532
 
 
1533
GF_ClientService *gf_term_get_service_from_url(GF_Terminal *term, const char *url)
 
1534
{
 
1535
        u32 i = 0;
 
1536
        GF_ClientService *ns;
 
1537
        while ( (ns = (GF_ClientService*)gf_list_enum(term->net_services, &i)) ) {
 
1538
                if (!strcmp(ns->url, url)) {
 
1539
                        return ns;
 
1540
                }
 
1541
        }
 
1542
        return NULL;
 
1543
}
 
1544
 
1499
1545
/*connects given channel to its URL if needed*/
1500
1546
GF_Err gf_term_connect_remote_channel(GF_Terminal *term, GF_Channel *ch, char *URL)
1501
1547
{
1579
1625
Bool gf_term_user_event(GF_Terminal * term, GF_Event *evt)
1580
1626
{
1581
1627
        if (term) return gf_sc_user_event(term->compositor, evt);
1582
 
        return 0;
 
1628
        return GF_FALSE;
1583
1629
}
1584
1630
 
1585
1631
 
1594
1640
GF_EXPORT
1595
1641
u32 gf_term_get_time_in_ms(GF_Terminal *term)
1596
1642
{
 
1643
        GF_Clock *ck;
1597
1644
        if (!term || !term->root_scene) return 0;
1598
 
        if (term->root_scene->scene_codec && term->root_scene->scene_codec->ck) return gf_clock_ellapse_time(term->root_scene->scene_codec->ck);
1599
 
        else if (term->root_scene->dyn_ck) return gf_clock_ellapse_time(term->root_scene->dyn_ck);
1600
 
        return 0;
 
1645
        ck = NULL;
 
1646
        if (term->root_scene->scene_codec && term->root_scene->scene_codec->ck) ck = term->root_scene->scene_codec->ck;
 
1647
        else if (term->root_scene->dyn_ck) ck = term->root_scene->dyn_ck;
 
1648
 
 
1649
        if (!ck) return 0;
 
1650
        if (!ck->has_seen_eos && ck->last_TS_rendered) return ck->last_TS_rendered;
 
1651
        return gf_clock_elapse_time(ck);
1601
1652
}
1602
1653
 
1603
1654
GF_Node *gf_term_pick_node(GF_Terminal *term, s32 X, s32 Y)
1665
1716
}
1666
1717
 
1667
1718
 
 
1719
GF_EXPORT
1668
1720
void gf_term_attach_service(GF_Terminal *term, GF_InputService *service_hdl)
1669
1721
{
1670
1722
        Bool net_check_interface(GF_InputService *ifce);
1718
1770
        GF_SceneLoader load;
1719
1771
 
1720
1772
        if (!term) return GF_BAD_PARAM;
 
1773
        
 
1774
        if (type && (!stricmp(type, "application/ecmascript") || !stricmp(type, "js")) )  {
 
1775
                return gf_scene_execute_script(term->root_scene->graph, com);
 
1776
        }
1721
1777
 
1722
1778
        memset(&load, 0, sizeof(GF_SceneLoader));
1723
1779
        load.localPath = gf_cfg_get_key(term->user->config, "General", "CacheDirectory");
1841
1897
        return gf_sc_release_screen_buffer(term->compositor, framebuffer);
1842
1898
}
1843
1899
 
1844
 
 
1845
 
static void gf_term_sample_scenetime(GF_Scene *scene)
1846
 
{
1847
 
        u32 i, count;
1848
 
        Bool locked = gf_mx_try_lock(scene->root_od->term->net_mx);
1849
 
        /*we cannot grab the network mutex, therefore we are not sure if some resources are not being destroyed.
1850
 
        TODO: add a dedicated mutex for this condition instead of using the global net mutex*/
1851
 
        if (!locked) return;
1852
 
 
1853
 
        gf_scene_sample_time(scene);
1854
 
        count = gf_list_count(scene->resources);
1855
 
        for (i=0; i<count; i++) {
1856
 
                GF_ObjectManager *odm = gf_list_get(scene->resources, i);
1857
 
                if (odm->subscene) gf_term_sample_scenetime(odm->subscene);
1858
 
        }
1859
 
        gf_mx_v(scene->root_od->term->net_mx);
1860
 
}
1861
 
 
1862
 
u32 gf_term_sample_clocks(GF_Terminal *term)
1863
 
{
1864
 
        if (term->root_scene) {
1865
 
                gf_term_sample_scenetime(term->root_scene);
1866
 
                return (u32) (1000*term->root_scene->simulation_time);
1867
 
        }
1868
 
        return 0;
1869
 
}
1870
 
 
 
1900
GF_EXPORT
1871
1901
const char *gf_term_get_text_selection(GF_Terminal *term, Bool probe_only)
1872
1902
{
1873
1903
        Bool has_text;
1879
1909
}
1880
1910
 
1881
1911
 
 
1912
GF_EXPORT
1882
1913
GF_Err gf_term_paste_text(GF_Terminal *term, const char *txt, Bool probe_only)
1883
1914
{
1884
1915
        if (!term) return GF_BAD_PARAM;
1886
1917
        return gf_sc_paste_text(term->compositor, txt);
1887
1918
}
1888
1919
 
 
1920
GF_EXPORT
1889
1921
Bool gf_term_forward_event(GF_Terminal *term, GF_Event *evt, Bool consumed, Bool forward_only)
1890
1922
{
1891
1923
        if (!term) return 0;
2067
2099
                                gf_term_set_option(term, GF_OPT_PLAY_STATE, GF_STATE_STEP_PAUSE);
2068
2100
                                break;
2069
2101
                        case GF_ACTION_EXIT:
 
2102
                                memset(&evt, 0, sizeof(GF_Event));
2070
2103
                                evt.type = GF_EVENT_QUIT;
2071
2104
                                gf_term_send_event(term, &evt);
2072
2105
                                break;
2251
2284
        }
2252
2285
        i=0;
2253
2286
        while (NULL != (odm = gf_list_enum(scene->resources, &i))) {
2254
 
                if (odm->codec)
 
2287
                if (odm->codec) 
2255
2288
                        odm->codec->decio->SetCapabilities(odm->codec->decio, caps);
2256
2289
                if (odm->net_service && (odm->net_service != root_service) )
2257
2290
                        odm->net_service->ifce->ServiceCommand(odm->net_service->ifce, &net_cmd);
2266
2299
        gf_scene_switch_quality(term->root_scene, up);
2267
2300
}
2268
2301
 
 
2302
GF_EXPORT
 
2303
GF_Err gf_term_get_visual_output_size(GF_Terminal *term, u32 *width, u32 *height)
 
2304
{
 
2305
        if (!term) return GF_BAD_PARAM;
 
2306
        if (width) *width = term->compositor->vp_width;
 
2307
        if (height) *height = term->compositor->vp_height;
 
2308
        return GF_OK;
 
2309
}
 
 
b'\\ No newline at end of file'