Imported Upstream version 0.4.5+svn4002~dfsg0
Alessio Treglia
12 years ago
4 | 4 | ifeq ($(DISABLE_ISOFF), no) |
5 | 5 | APPDIRS+=mp4box |
6 | 6 | ifeq ($(DISABLE_M2TS), no) |
7 | ifeq ($(DISABLE_SENG), no) | |
7 | 8 | APPDIRS+=mp42ts |
9 | endif | |
8 | 10 | endif |
9 | 11 | endif |
10 | 12 |
33 | 33 | |
34 | 34 | #error "Cannot compile MP42TS if GPAC is not built with ISO File Format support" |
35 | 35 | |
36 | #else | |
36 | #endif | |
37 | ||
38 | #ifdef GPAC_DISABLE_MPEG2TS_MUX | |
39 | ||
40 | #error "Cannot compile MP42TS if GPAC is not built with MPEG2-TS Muxing support" | |
41 | ||
42 | #endif | |
37 | 43 | |
38 | 44 | |
39 | 45 | #define DEFAULT_PCR_OFFSET 18000 |
439 | 445 | return GF_OK; |
440 | 446 | } |
441 | 447 | |
448 | #ifndef GPAC_DISABLE_STREAMING | |
442 | 449 | typedef struct |
443 | 450 | { |
444 | 451 | /*RTP channel*/ |
496 | 503 | } |
497 | 504 | return GF_OK; |
498 | 505 | } |
506 | #endif | |
499 | 507 | |
500 | 508 | static GF_Err void_input_ctrl(GF_ESInterface *ifce, u32 act_type, void *param) |
501 | 509 | { |
731 | 739 | { |
732 | 740 | GF_Err e; |
733 | 741 | u64 last_src_modif, mod_time; |
734 | Bool has_carousel=0; | |
735 | 742 | M2TSProgram *prog = (M2TSProgram *)param; |
736 | 743 | GF_SceneEngine *seng = prog->seng; |
737 | 744 | GF_SimpleDataDescriptor *audio_desc; |
740 | 747 | u32 period, ts_delta; |
741 | 748 | u16 es_id, aggregate_on_stream; |
742 | 749 | e = GF_OK; |
743 | if (prog->rate){ | |
744 | has_carousel = 1; | |
745 | } | |
746 | 750 | gf_sleep(2000); /*TODO: events instead? What are we waiting for?*/ |
747 | 751 | gf_seng_encode_context(seng, SampleCallBack); |
748 | 752 | |
910 | 914 | return e ? 1 : 0; |
911 | 915 | } |
912 | 916 | |
913 | ||
917 | #ifndef GPAC_DISABLE_STREAMING | |
914 | 918 | static void rtp_sl_packet_cbk(void *udta, char *payload, u32 size, GF_SLHeader *hdr, GF_Err e) |
915 | 919 | { |
916 | 920 | GF_ESIRTP *rtp = (GF_ESIRTP*)udta; |
1026 | 1030 | } |
1027 | 1031 | fprintf(stderr, "RTP interface initialized\n"); |
1028 | 1032 | } |
1033 | #endif /*GPAC_DISABLE_STREAMING*/ | |
1029 | 1034 | |
1030 | 1035 | void fill_seng_es_ifce(GF_ESInterface *ifce, u32 i, GF_SceneEngine *seng, u32 period) |
1031 | 1036 | { |
1059 | 1064 | |
1060 | 1065 | static Bool open_program(M2TSProgram *prog, char *src, u32 carousel_rate, u32 mpeg4_signaling, char *update, char *audio_input_ip, u16 audio_input_port, char *video_buffer, Bool force_real_time, u32 bifs_use_pes) |
1061 | 1066 | { |
1067 | #ifndef GPAC_DISABLE_STREAMING | |
1062 | 1068 | GF_SDPInfo *sdp; |
1069 | #endif | |
1063 | 1070 | u32 i; |
1064 | 1071 | GF_Err e; |
1065 | 1072 | |
1211 | 1218 | return 1; |
1212 | 1219 | } |
1213 | 1220 | |
1221 | #ifndef GPAC_DISABLE_STREAMING | |
1214 | 1222 | /*open SDP file*/ |
1215 | 1223 | if (strstr(src, ".sdp")) { |
1216 | 1224 | GF_X_Attribute *att; |
1279 | 1287 | gf_sdp_info_del(sdp); |
1280 | 1288 | |
1281 | 1289 | return 2; |
1282 | } | |
1283 | else if (strstr(src, ".bt")) //open .bt file | |
1290 | } else | |
1291 | #endif /*GPAC_DISABLE_STREAMING*/ | |
1292 | if (strstr(src, ".bt")) //open .bt file | |
1284 | 1293 | { |
1285 | 1294 | u32 load_type=0; |
1286 | 1295 | prog->seng = gf_seng_init(prog, src, load_type, NULL, (load_type == GF_SM_LOAD_DIMS) ? 1 : 0); |
1788 | 1797 | char *ts_out = NULL, *udp_out = NULL, *rtp_out = NULL, *audio_input_ip = NULL; |
1789 | 1798 | FILE *ts_output_file = NULL; |
1790 | 1799 | GF_Socket *ts_output_udp_sk = NULL, *audio_input_udp_sk = NULL; |
1800 | #ifndef GPAC_DISABLE_STREAMING | |
1791 | 1801 | GF_RTPChannel *ts_output_rtp = NULL; |
1792 | 1802 | GF_RTSPTransport tr; |
1793 | 1803 | GF_RTPHeader hdr; |
1804 | #endif | |
1794 | 1805 | char *video_buffer; |
1795 | 1806 | u32 video_buffer_size; |
1796 | 1807 | u16 output_port = 0, audio_input_port = 0; |
1822 | 1833 | last_video_time = 0; |
1823 | 1834 | audio_input_type = 0; |
1824 | 1835 | ts_output_udp_sk = NULL; |
1836 | udp_out = NULL; | |
1837 | #ifndef GPAC_DISABLE_STREAMING | |
1825 | 1838 | ts_output_rtp = NULL; |
1839 | rtp_out = NULL; | |
1840 | #endif | |
1841 | ts_out = NULL; | |
1826 | 1842 | src_name = NULL; |
1827 | ts_out = NULL; | |
1828 | udp_out = NULL; | |
1829 | rtp_out = NULL; | |
1830 | 1843 | nb_progs = 0; |
1831 | 1844 | mux_rate = 0; |
1832 | 1845 | run_time = 0; |
1912 | 1925 | goto exit; |
1913 | 1926 | } |
1914 | 1927 | } |
1928 | #ifndef GPAC_DISABLE_STREAMING | |
1915 | 1929 | if (rtp_out != NULL) { |
1916 | 1930 | ts_output_rtp = gf_rtp_new(); |
1917 | 1931 | gf_rtp_set_ports(ts_output_rtp, output_port); |
1947 | 1961 | hdr.SSRC = tr.SSRC; |
1948 | 1962 | hdr.Marker = 0; |
1949 | 1963 | } |
1964 | #endif /*GPAC_DISABLE_STREAMING*/ | |
1950 | 1965 | |
1951 | 1966 | /************************************/ |
1952 | 1967 | /* create streaming audio input */ |
2107 | 2122 | fprintf(stderr, "Error %s sending UDP packet\n", gf_error_to_string(e)); |
2108 | 2123 | } |
2109 | 2124 | } |
2125 | #ifndef GPAC_DISABLE_STREAMING | |
2110 | 2126 | if (ts_output_rtp != NULL) { |
2111 | 2127 | hdr.SequenceNumber++; |
2112 | 2128 | /*muxer clock at 90k*/ |
2119 | 2135 | fprintf(stderr, "Error %s sending RTP packet\n", gf_error_to_string(e)); |
2120 | 2136 | } |
2121 | 2137 | } |
2138 | #endif | |
2122 | 2139 | if (status>=GF_M2TS_STATE_PADDING) { |
2123 | 2140 | break; |
2124 | 2141 | } |
2172 | 2189 | } |
2173 | 2190 | if (ts_output_file) fclose(ts_output_file); |
2174 | 2191 | if (ts_output_udp_sk) gf_sk_del(ts_output_udp_sk); |
2192 | #ifndef GPAC_DISABLE_STREAMING | |
2175 | 2193 | if (ts_output_rtp) gf_rtp_del(ts_output_rtp); |
2194 | #endif | |
2176 | 2195 | if (ts_out) gf_free(ts_out); |
2177 | 2196 | if (audio_input_udp_sk) gf_sk_del(audio_input_udp_sk); |
2178 | 2197 | if (audio_input_buffer) gf_free (audio_input_buffer); |
2179 | 2198 | if (video_buffer) gf_free(video_buffer); |
2180 | 2199 | if (udp_out) gf_free(udp_out); |
2200 | #ifndef GPAC_DISABLE_STREAMING | |
2181 | 2201 | if (rtp_out) gf_free(rtp_out); |
2202 | #endif | |
2182 | 2203 | if (aac_reader) AAC_Reader_del(aac_reader); |
2183 | 2204 | if (muxer) gf_m2ts_mux_del(muxer); |
2184 | 2205 | |
2207 | 2228 | return 1; |
2208 | 2229 | } |
2209 | 2230 | |
2210 | #endif /*GPAC_DISABLE_ISOM*/ |
931 | 931 | /*track done*/ |
932 | 932 | if ((tki->stop_state==2) || (!is_last && (tki->sample_count == tki->last_sample)) ) { |
933 | 933 | if (tki->has_non_raps) last_rap_sample_time = 0; |
934 | time = (Double) (s64) ( gf_isom_get_sample_dts(mp4, tki->tk, tki->last_sample+1) - tki->firstDTS); | |
935 | time /= tki->time_scale; | |
936 | if (file_split_dur==(Double)GF_MAX_FLOAT || file_split_dur<time) file_split_dur = time; | |
934 | 937 | continue; |
935 | 938 | } |
936 | 939 |
36 | 36 | |
37 | 37 | #else |
38 | 38 | |
39 | #ifndef GPAC_DISABLE_STREAMING | |
39 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
40 | 40 | |
41 | 41 | void PrintStreamerUsage() |
42 | 42 | { |
804 | 804 | } |
805 | 805 | |
806 | 806 | |
807 | #endif /*GPAC_DISABLE_STREAMING*/ | |
807 | #endif /*!defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG)*/ | |
808 | 808 | |
809 | 809 | #endif /*defined(GPAC_DISABLE_ISOM) || defined(GPAC_DISABLE_ISOM_WRITE)*/ |
106 | 106 | #endif |
107 | 107 | |
108 | 108 | |
109 | #ifndef GPAC_DISABLE_STREAMING | |
109 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
110 | 110 | void PrintStreamerUsage(); |
111 | 111 | int stream_file_rtp(int argc, char **argv); |
112 | 112 | int live_session(int argc, char **argv); |
822 | 822 | |
823 | 823 | #endif /*GPAC_DISABLE_ISOM_HINTING*/ |
824 | 824 | |
825 | #ifndef GPAC_DISABLE_ISOM_WRITE | |
825 | #if !defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_AV_PARSERS) | |
826 | 826 | |
827 | 827 | static void check_media_profile(GF_ISOFile *file, u32 track) |
828 | 828 | { |
912 | 912 | gf_isom_set_pl_indication(file, GF_ISOM_PL_INLINE, 0); |
913 | 913 | } |
914 | 914 | |
915 | #endif | |
915 | #endif /*!defined(GPAC_DISABLE_ISOM_WRITE) && !defined(GPAC_DISABLE_AV_PARSERS)*/ | |
916 | 916 | |
917 | 917 | /*return value: |
918 | 918 | 0: not supported |
1203 | 1203 | #ifndef GPAC_DISABLE_SCENE_ENCODER |
1204 | 1204 | GF_SMEncodeOptions opts; |
1205 | 1205 | #endif |
1206 | #ifndef GPAC_DISABLE_STREAMING | |
1206 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
1207 | 1207 | SDPLine sdp_lines[MAX_CUMUL_OPS]; |
1208 | 1208 | #endif |
1209 | 1209 | Double InterleavingTime, split_duration, split_start, import_fps, dash_duration; |
1385 | 1385 | i++; |
1386 | 1386 | } |
1387 | 1387 | #endif /*GPAC_DISABLE_MEDIA_EXPORT*/ |
1388 | ||
1389 | #ifndef GPAC_DISABLE_STREAMING | |
1388 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
1390 | 1389 | else if (!stricmp(arg, "-rtp")) { |
1391 | 1390 | stream_rtp = 1; |
1392 | 1391 | } |
1393 | #endif | |
1394 | 1392 | else if (!stricmp(arg, "-live")) { |
1395 | 1393 | live_scene = 1; |
1396 | 1394 | } |
1395 | #endif | |
1397 | 1396 | else if (!stricmp(arg, "-diod")) { |
1398 | 1397 | dump_iod = 1; |
1399 | 1398 | } |
1589 | 1588 | else if (!stricmp(arg, "-mtu")) { CHECK_NEXT_ARG MTUSize = atoi(argv[i+1]); i++; } |
1590 | 1589 | else if (!stricmp(arg, "-cardur")) { CHECK_NEXT_ARG car_dur = atoi(argv[i+1]); i++; } |
1591 | 1590 | else if (!stricmp(arg, "-rate")) { CHECK_NEXT_ARG rtp_rate = atoi(argv[i+1]); i++; } |
1591 | #ifndef GPAC_DISABLE_SENG | |
1592 | 1592 | else if (!stricmp(arg, "-add-sdp") || !stricmp(arg, "-sdp_ex")) { |
1593 | 1593 | char *id; |
1594 | 1594 | CHECK_NEXT_ARG |
1615 | 1615 | nb_sdp_ex++; |
1616 | 1616 | i++; |
1617 | 1617 | } |
1618 | #endif /*GPAC_DISABLE_SENG*/ | |
1618 | 1619 | #endif /*GPAC_DISABLE_ISOM_HINTING*/ |
1619 | 1620 | |
1620 | 1621 | else if (!stricmp(arg, "-single")) { |
2099 | 2100 | else if (!strcmp(argv[i+1], "crypt")) PrintEncryptUsage(); |
2100 | 2101 | else if (!strcmp(argv[i+1], "meta")) PrintMetaUsage(); |
2101 | 2102 | else if (!strcmp(argv[i+1], "swf")) PrintSWFUsage(); |
2102 | #ifndef GPAC_DISABLE_STREAMING | |
2103 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
2103 | 2104 | else if (!strcmp(argv[i+1], "rtp")) PrintStreamerUsage(); |
2104 | 2105 | else if (!strcmp(argv[i+1], "live")) PrintLiveUsage (); |
2105 | 2106 | #endif |
2114 | 2115 | PrintEncryptUsage(); |
2115 | 2116 | PrintMetaUsage(); |
2116 | 2117 | PrintSWFUsage(); |
2117 | #ifndef GPAC_DISABLE_STREAMING | |
2118 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
2118 | 2119 | PrintStreamerUsage(); |
2119 | 2120 | PrintLiveUsage (); |
2120 | 2121 | #endif |
2139 | 2140 | return 1; |
2140 | 2141 | } |
2141 | 2142 | |
2142 | #ifndef GPAC_DISABLE_STREAMING | |
2143 | #if !defined(GPAC_DISABLE_STREAMING) && !defined(GPAC_DISABLE_SENG) | |
2143 | 2144 | if (live_scene) { |
2144 | 2145 | return live_session(argc, argv); |
2145 | 2146 | } |
2146 | 2147 | if (stream_rtp) { |
2147 | 2148 | return stream_file_rtp(argc, argv); |
2148 | 2149 | } |
2149 | #endif /*GPAC_DISABLE_STREAMING*/ | |
2150 | #endif | |
2150 | 2151 | |
2151 | 2152 | if (raw_cat) { |
2152 | 2153 | char chunk[4096]; |
2785 | 2786 | } |
2786 | 2787 | |
2787 | 2788 | if (remove_sys_tracks) { |
2789 | #ifndef GPAC_DISABLE_AV_PARSERS | |
2788 | 2790 | remove_systems_tracks(file); |
2791 | #endif | |
2789 | 2792 | needSave = 1; |
2790 | 2793 | if (conv_type < GF_ISOM_CONV_TYPE_ISMA_EX) conv_type = 0; |
2791 | 2794 | } |
3214 | 3217 | u32 k, l, sps_id1, sps_id2; |
3215 | 3218 | GF_AVCConfig *avccfg1 = gf_isom_avc_config_get(in, j+1, 1); |
3216 | 3219 | GF_AVCConfig *avccfg2 = gf_isom_avc_config_get(init_seg, track, 1); |
3220 | #ifndef GPAC_DISABLE_AV_PARSERS | |
3217 | 3221 | for (k=0; k<gf_list_count(avccfg2->sequenceParameterSets); k++) { |
3218 | 3222 | GF_AVCConfigSlot *slc = gf_list_get(avccfg2->sequenceParameterSets, k); |
3219 | 3223 | gf_avc_get_sps_info(slc->data, slc->size, &sps_id1, NULL, NULL, NULL, NULL); |
3226 | 3230 | } |
3227 | 3231 | } |
3228 | 3232 | } |
3233 | #endif | |
3229 | 3234 | /*no conflicts in SPS ids, merge all SPS in a single sample desc*/ |
3230 | 3235 | if (do_merge) { |
3231 | 3236 | while (gf_list_count(avccfg1->sequenceParameterSets)) { |
3362 | 3367 | } |
3363 | 3368 | if (e) goto err_exit; |
3364 | 3369 | |
3365 | #ifndef GPAC_DISABLE_ISOM_HINTING | |
3370 | #if !defined(GPAC_DISABLE_ISOM_HINTING) && !defined(GPAC_DISABLE_SENG) | |
3366 | 3371 | for (i=0; i<nb_sdp_ex; i++) { |
3367 | 3372 | if (sdp_lines[i].trackID) { |
3368 | 3373 | u32 track = gf_isom_get_track_by_id(file, sdp_lines[i].trackID); |
3391 | 3396 | needSave = 1; |
3392 | 3397 | } |
3393 | 3398 | } |
3394 | #endif /*GPAC_DISABLE_ISOM_HINTING*/ | |
3399 | #endif /*!defined(GPAC_DISABLE_ISOM_HINTING) && !defined(GPAC_DISABLE_SENG)*/ | |
3395 | 3400 | |
3396 | 3401 | if (cprt) { |
3397 | 3402 | e = gf_isom_set_copyright(file, "und", cprt); |
156 | 156 | BITMAPINFOHEADER fi; |
157 | 157 | FILE *fout; |
158 | 158 | u32 j, i; |
159 | char *ptr, *prev; | |
160 | ||
161 | prev = strrchr(rad_name, '.'); | |
162 | //if (prev) prev[0] = '\0'; | |
159 | char *ptr; | |
163 | 160 | |
164 | 161 | if (fb->pixel_format==GF_PIXEL_GREYSCALE) sprintf(str, "%s_%d_depth.bmp", rad_name, img_num); |
165 | 162 | else sprintf(str, "%s_%d.bmp", rad_name, img_num); |
258 | 255 | { |
259 | 256 | FILE *fout; |
260 | 257 | u32 i, j; |
261 | char val; | |
262 | 258 | unsigned char *depth; |
263 | 259 | |
264 | 260 | depth = (unsigned char *) fb->video_buffer; |
269 | 265 | for (i=0;i<fb->width; i++) { |
270 | 266 | |
271 | 267 | #ifdef GPAC_USE_TINYGL |
272 | val = fputc(depth[2*i+j*fb->width*sizeof(unsigned short)], fout); | |
273 | val = fputc(depth[2*i+j*fb->width*sizeof(unsigned short) + 1], fout); | |
268 | fputc(depth[2*i+j*fb->width*sizeof(unsigned short)], fout); | |
269 | fputc(depth[2*i+j*fb->width*sizeof(unsigned short) + 1], fout); | |
274 | 270 | #else |
275 | val = fputc(depth[i+j*fb->width], fout); | |
271 | fputc(depth[i+j*fb->width], fout); | |
276 | 272 | #endif |
277 | 273 | } |
278 | 274 | } |
284 | 280 | |
285 | 281 | FILE *fout; |
286 | 282 | u32 i, j; |
287 | char val; | |
288 | 283 | unsigned char *buf; |
289 | 284 | |
290 | 285 | buf = (unsigned char *) fb->video_buffer; |
296 | 291 | if (!fout) return; |
297 | 292 | for (j=0; j<fb->height; j++) { |
298 | 293 | for (i=0;i<fb->width*4; i++) { |
299 | val = fputc(buf[i+j*fb->pitch_y], fout); | |
294 | fputc(buf[i+j*fb->pitch_y], fout); | |
300 | 295 | } |
301 | 296 | } |
302 | 297 | fclose(fout); |
1185 | 1185 | if (!strcmp(str, "Raw Video Output")) fprintf(stdout, "WARNING: using raw output video (memory only) - no display used\n"); |
1186 | 1186 | /*check audio output*/ |
1187 | 1187 | str = gf_cfg_get_key(cfg_file, "Audio", "DriverName"); |
1188 | if (!str || !strcmp(str, "No Audio Output Available")) fprintf(stdout, "WARNING: no audio output availble - make sure no other program is locking the sound card\n"); | |
1188 | if (!str || !strcmp(str, "No Audio Output Available")) fprintf(stdout, "WARNING: no audio output available - make sure no other program is locking the sound card\n"); | |
1189 | 1189 | |
1190 | 1190 | str = gf_cfg_get_key(cfg_file, "General", "NoMIMETypeFetch"); |
1191 | 1191 | no_mime_check = (str && !stricmp(str, "yes")) ? 1 : 0; |
664 | 664 | #spidermonkey test for new API |
665 | 665 | if test "$has_js" = "no" ; then |
666 | 666 | |
667 | cat > $TMPCPP << EOF | |
667 | cat > $TMPCPP << EOF | |
668 | 668 | #include <jsapi.h> |
669 | 669 | int main( void ) { JSContext *cx; jsval *rp; return JS_AddValueRoot(cx, rp); } |
670 | 670 | EOF |
691 | 691 | if test "$has_js" = "no" ; then |
692 | 692 | js_inc="/usr/include/$i" |
693 | 693 | js_flags="-DXP_UNIX -I$js_inc" |
694 | js_lib="-L/usr/lib/$i/ -lxul -lmozsqlite3 -lmozalloc -lnss3" | |
694 | js_lib="-L/usr/lib/$i/ -lxul -lmozsqlite3 -lmozalloc -lnssutil3 -lnss3" | |
695 | 695 | if $cpp -o $TMPO $TMPCPP $js_flags $js_lib 2> /dev/null ; then |
696 | 696 | has_js="$i" |
697 | elif $cpp -o $TMPO $TMPCPP $js_flags -lnssutil3 $js_lib -lssl3 2> /dev/null ; then | |
698 | #firefox 11 compatibility | |
699 | has_js="$i" | |
700 | js_lib="-lnssutil3 $js_lib -lssl3" | |
697 | 701 | fi |
698 | 702 | fi |
699 | 703 | done |
815 | 819 | #if the lib has been compiled with or without the macro. We currently just decide that if the macro is present |
816 | 820 | #in the header, it was enabled in the build |
817 | 821 | if test "$new_js_api" = "no" ; then |
818 | if grep MOZILLA_1_8_BRANCH $js_inc/jsapi.h > /dev/null 2>&1 ; then | |
819 | js_flags="-DMOZILLA_1_8_BRANCH $js_flags" | |
820 | echo "WARNING: Turning on MOZILLA_1_8_BRANCH SpiderMonkey macro" | |
821 | echo "If you have troubles with scripts in GPAC, disable this macro and recompile" | |
822 | fi | |
822 | if grep MOZILLA_1_8_BRANCH $js_inc/jsapi.h > /dev/null 2>&1 ; then | |
823 | js_flags="-DMOZILLA_1_8_BRANCH $js_flags" | |
824 | echo "WARNING: Turning on MOZILLA_1_8_BRANCH SpiderMonkey macro" | |
825 | echo "If you have troubles with scripts in GPAC, disable this macro and recompile" | |
826 | fi | |
823 | 827 | else |
824 | #check presence of ***RuntimeThread | |
825 | if grep RuntimeThread $js_inc/jsapi.h > /dev/null 2>&1 ; then | |
826 | js_flags="$js_flags" | |
827 | else | |
828 | js_flags="-DNO_JS_RUNTIMETHREAD $js_flags" | |
829 | fi | |
828 | cat > $TMPC << EOF | |
829 | #include <jsapi.h> | |
830 | int main( void ) { JSContext *cx; JS_SetRuntimeThread(cx); } | |
831 | EOF | |
832 | if $cc -o $TMPO $TMPC $js_flags $LDFLAGS $js_lib 2> /dev/null ; then | |
833 | js_flags="$js_flags" | |
834 | else | |
835 | js_flags="-DNO_JS_RUNTIMETHREAD $js_flags" | |
836 | fi | |
830 | 837 | fi |
831 | 838 | fi |
832 | 839 | fi |
1421 | 1428 | } |
1422 | 1429 | EOF |
1423 | 1430 | |
1424 | if $cc -o $TMPE $TMPC $LDFLAGS > /dev/null 2>&1 ; then | |
1431 | if $cc -o $TMPE $TMPC $LDFLAGS $extralibs > /dev/null 2>&1 ; then | |
1425 | 1432 | has_ipv6="yes" |
1426 | 1433 | fi |
1427 | 1434 | |
1887 | 1894 | if $cc -o $TMPO $TMPCPP -I$xulsdk_path $LDFLAGS 2> /dev/null ; then |
1888 | 1895 | has_xul="system" |
1889 | 1896 | xul_flags="-I$xulsdk_path $xul_flags" |
1890 | else | |
1897 | fi | |
1898 | ||
1899 | if test "$has_xul" = "no" ; then | |
1900 | if $pkg_config --exists libxul 2> /dev/null ; then | |
1901 | if $cpp -o $TMPO $TMPCPP `$pkg_config --cflags libxul` `$pkg_config --libs libxul` ; then | |
1902 | has_xul="system" | |
1903 | xul_flags="`$pkg_config --cflags libxul` `$pkg_config --libs libxul`" | |
1904 | fi | |
1905 | fi | |
1906 | fi | |
1907 | ||
1908 | if test "$has_xul" = "no" ; then | |
1891 | 1909 | if $cc -o $TMPO $TMPCPP $xul_flags -I$local_inc/gecko-sdk/include $LDFLAGS 2> /dev/null ; then |
1892 | 1910 | has_xul="local" |
1893 | 1911 | xul_flags="-I$local_inc/gecko-sdk/include $xul_flags" |
1894 | 1912 | else |
1895 | #xulrunner directories are sometimes included through js packages | |
1896 | if test "$has_js" = "system" ;then | |
1897 | if $cpp -o $TMPO $TMPCPP $js_flags $js_lib_pkg $LDFLAGS 2> /dev/null ; then | |
1913 | #xulrunner directories are sometimes included through js/xul/ff packages | |
1914 | if test ! "$has_js" = "no" -a ! "$has_js" = "local" ; then | |
1915 | if $cc -o $TMPO $TMPCPP $js_flags $js_lib_pkg $LDFLAGS 2> /dev/null ; then | |
1898 | 1916 | xul_flags=`$pkg_config --cflags mozilla-js` |
1899 | has_xul="system" | |
1917 | has_xul="$has_js" | |
1900 | 1918 | fi |
1901 | 1919 | fi |
1902 | 1920 | fi |
2334 | 2352 | fi |
2335 | 2353 | |
2336 | 2354 | ldir=`pwd` |
2337 | CFLAGS="$CFLAGS -DGPAC_HAVE_CONFIG_H -I\"$ldir\"" | |
2338 | CPPFLAGS="$CPPFLAGS -DGPAC_HAVE_CONFIG_H -I\"$ldir\"" | |
2355 | CFLAGS="$CFLAGS -fvisibility=\"hidden\" -DGPAC_HAVE_CONFIG_H -I\"$ldir\"" | |
2356 | CPPFLAGS="$CPPFLAGS" | |
2339 | 2357 | |
2340 | 2358 | |
2341 | 2359 | echo "Creating config.mak" |
2501 | 2519 | echo "XML2_CFLAGS=$libxml2_cflags" >> config.mak |
2502 | 2520 | echo "XML2_LIBS=$libxml2_lib_flags" >> config.mak |
2503 | 2521 | fi |
2522 | if test "$disable_parsers" = "yes" ; then | |
2523 | disable_m2ts_mux="yes" | |
2524 | fi | |
2504 | 2525 | if test "$disable_m2ts_mux" = "yes" -o "$disable_m2ts" = "yes" ; then |
2505 | 2526 | echo "DISABLE_M2TS=yes" >> config.mak |
2506 | 2527 | else |
2507 | 2528 | echo "DISABLE_M2TS=no" >> config.mak |
2529 | fi | |
2530 | if test "$disable_beng" = "no"; then | |
2531 | echo "DISABLE_SENG=no" >> config.mak | |
2508 | 2532 | fi |
2509 | 2533 | |
2510 | 2534 | echo "GPAC_USE_TINYGL=$has_tinygl" >> config.mak |
0 | 0 | // 01122011 AMD1 startWidget listWidgets getWidget implemented |
1 | ||
2 | var iphone_wm_gui = (function () { | |
3 | ||
4 | // to make sure the initialization is done only once | |
5 | var init = true; | |
6 | ||
7 | // constant | |
8 | var xlinkns = 'http://www.w3.org/1999/xlink'; | |
9 | //var evns = 'http://www.w3.org/2001/xml-events'; | |
10 | ||
11 | // state of the widget manager: displays homepage (value=home) or executes widget (value="exec") | |
12 | var state = 'home'; | |
13 | ||
14 | // convenience variables for SVG elements | |
15 | var homepage = null, arrows = null, icons = null, widgetContainer = null, homebar = null, execbar = null; | |
16 | ||
17 | // where is the index into pages of icons on the home page | |
18 | var where = 0,maxwhere = 0,whereW = 0; | |
19 | ||
20 | // array of activated widgets | |
21 | var activatedWidgets = new Array(); | |
22 | var numActivatedWidgets = 0; | |
23 | ||
24 | // variables for flexible layout | |
25 | // variables for flexible layout | |
26 | var totalWidth = 0,totalHeight = 0,iconNbHoriz = 0,iconNbVert = 0,iconsPerPage = 0; | |
27 | ||
28 | //previous size | |
29 | var previousWidth = 0,previousHeight = 0; | |
30 | ||
31 | // to differentiate between install icon and scan dir for icons | |
32 | var isThisAScan = null; | |
33 | ||
34 | // preferred icon type | |
35 | var preferredIconType = '.svg'; | |
36 | ||
37 | // adapt layout to the size of the screen | |
38 | function adaptLayoutToSize() { | |
39 | if (l_deb < log_level) { | |
40 | alert("[UI] adaptLayoutToSize"); | |
41 | } | |
42 | var tmpObject, tmpObj2; | |
43 | // get size to adapt to | |
44 | totalWidth = document.documentElement.viewport.width; | |
45 | totalHeight = document.documentElement.viewport.height; | |
46 | if (totalWidth == 0) { | |
47 | totalWidth = 160; | |
48 | } | |
49 | if (totalHeight == 0) { | |
50 | totalHeight = 280; | |
51 | } | |
52 | while (totalWidth < 160 || totalHeight < 280) { | |
53 | totalWidth *= 4; | |
54 | totalHeight *= 4; | |
55 | } | |
56 | // min size is 160 by 280 | |
57 | if (totalWidth < 160) { | |
58 | totalWidth = 160; | |
59 | } | |
60 | if (totalHeight < 280) { | |
61 | totalHeight = 280; | |
62 | } | |
63 | // round to lower multiple of 80 | |
64 | totalWidth -= totalWidth % 80; | |
65 | var iconHeight = totalHeight - 120; | |
66 | iconHeight -= iconHeight % 80; | |
67 | // how many lines and columns of icons | |
68 | iconNbHoriz = totalWidth / 80; | |
69 | iconNbVert = iconHeight / 80; | |
70 | totalHeight = iconHeight + 120; | |
71 | // 120 is upper bar (60) + lower bar (60) | |
72 | iconsPerPage = iconNbHoriz * iconNbVert; | |
73 | // fix svg viewbox | |
74 | document.getElementById("svg").setAttribute("viewBox", "0 0 " + totalWidth + " " + totalHeight); | |
75 | // fix odd line | |
76 | tmpObj2 = document.getElementById("odd"); | |
77 | var i, already = tmpObj2.getElementsByTagName("use").length; | |
78 | //alert("odd line "+already+" "+iconNbHoriz); | |
79 | for (i = already; i < iconNbHoriz; i++) { | |
80 | tmpObject = document.createElement("use"); | |
81 | tmpObject.setAttribute("x", i * 80); | |
82 | tmpObject.setAttributeNS(xlinkns, "href", (((i % 2) == 0) ? "#lightRect" : "#darkRect" )); | |
83 | tmpObj2.appendChild(tmpObject); | |
84 | } | |
85 | // fix even line | |
86 | tmpObj2 = document.getElementById("even"); | |
87 | already = tmpObj2.getElementsByTagName("use").length; | |
88 | //alert("even line "+already+" "+iconNbHoriz); | |
89 | for (i = already; i < iconNbHoriz; i++) { | |
90 | tmpObject = document.createElement("use"); | |
91 | tmpObject.setAttribute("x", i * 80); | |
92 | tmpObject.setAttributeNS(xlinkns, "href", (((i % 2) == 0) ? "#darkRect" : "#lightRect" )); | |
93 | tmpObj2.appendChild(tmpObject); | |
94 | } | |
95 | // fix frame (black with rounded corners) | |
96 | tmpObject = document.getElementById("frame"); | |
97 | tmpObject.setAttribute("width", totalWidth); | |
98 | tmpObject.setAttribute("height", totalHeight); | |
99 | tmpObject = document.getElementById("frame2"); | |
100 | tmpObject.setAttribute("width", totalWidth); | |
101 | tmpObject.setAttribute("height", totalHeight); | |
102 | // fix screen (white) | |
103 | tmpObject = document.getElementById("screen"); | |
104 | tmpObject.setAttribute("width", totalWidth); | |
105 | tmpObject.setAttribute("height", totalHeight - 120); | |
106 | // fix grid back (gray) | |
107 | tmpObject = document.getElementById("gridback"); | |
108 | tmpObject.setAttribute("width", totalWidth); | |
109 | tmpObject.setAttribute("height", totalHeight - 120); | |
110 | // fix icon background grid | |
111 | tmpObject = document.getElementById("grid"); | |
112 | already = tmpObject.getElementsByTagName("use").length; | |
113 | for (i = already; i < iconNbVert; i++) { | |
114 | tmpObj2 = document.createElement("use"); | |
115 | tmpObj2.setAttribute("y", i * 80); | |
116 | tmpObj2.setAttributeNS(xlinkns, "href", (((i % 2) == 0) ? "#odd" : "#even" )); | |
117 | tmpObject.appendChild(tmpObj2); | |
118 | } | |
119 | // if there are already too many lines, remove the extra ones otherwise they are rendered on top of the lower | |
120 | // part of the decoration | |
121 | if (already > iconNbVert) { | |
122 | while (already-- > iconNbVert) { | |
123 | tmpObject.removeChild(tmpObject.lastChild); | |
124 | } | |
125 | } | |
126 | // fix commands (lower bar) | |
127 | document.getElementById("commands").setAttribute("transform", "translate(0, " + (totalHeight - 60) + ")"); | |
128 | document.getElementById("homeButton").setAttribute("transform", "translate(" + (totalWidth / 2) + ", 30)"); | |
129 | document.getElementById("right").setAttribute("transform", "translate(" + (totalWidth - 50) + ", 10)"); | |
130 | document.getElementById("rightW").setAttribute("transform", "translate(" + (totalWidth - 50) + ", 10)"); | |
131 | // fix the cuts (white rects left and right because we have no clipping) | |
132 | tmpObject = document.getElementById("leftCut"); | |
133 | tmpObject.setAttribute("width", totalWidth); | |
134 | tmpObject.setAttribute("height", totalHeight); | |
135 | tmpObject.setAttribute("x", -1 - totalWidth); | |
136 | tmpObject = document.getElementById("rightCut"); | |
137 | tmpObject.setAttribute("width", totalWidth); | |
138 | tmpObject.setAttribute("height", totalHeight); | |
139 | tmpObject.setAttribute("x", 1 + totalWidth); | |
140 | // respace executing widgets if any | |
141 | tmpObject = widgetContainer.getElementsByTagName("g"); | |
142 | for (i = 0; i < tmpObject.length; i++) { | |
143 | var gg = tmpObject.item(i); | |
144 | gg.setAttribute("transform", "translate(" + (totalWidth * (i - 1)) + ", 0)"); | |
145 | if (gg.firstElementChild != null) { | |
146 | gg.firstElementChild.setAttribute("width", totalWidth); | |
147 | gg.firstElementChild.setAttribute("height", totalHeight - 120); | |
148 | } | |
149 | } | |
150 | } | |
151 | ||
152 | // | |
153 | // widget close on click at "Kill" button | |
154 | // | |
155 | function on_kill_widget() { | |
156 | if (state == 'exec') { | |
157 | widget_close(activatedWidgets[whereW]); | |
158 | } | |
159 | } | |
160 | ||
161 | // | |
162 | // widget get on click at "GetW" button | |
163 | // | |
164 | function on_get_widget() { | |
165 | alert("on_get_widget "+WidgetManager.MPEGUStandardServiceProviders.length); | |
166 | if (WidgetManager.MPEGUStandardServiceProviders.length != 0) { | |
167 | upnp_renders = selector_window1(); | |
168 | upnp_renders.on_select = function(item) { | |
169 | upnp_renders.unregister(root); | |
170 | upnp_renders = null; | |
171 | if (item == -1) { | |
172 | return; | |
173 | } | |
174 | alert("upnp_renders.on_select(" + item + ")"); | |
175 | var device = WidgetManager.MPEGUStandardServiceProviders[item]; | |
176 | device.standardService.SetActionListener("listWidgets", get_widget_callback(device), true); | |
177 | device.standardService.CallAction("listWidgets", new Array()); | |
178 | } | |
179 | upnp_renders.register(root); | |
180 | } | |
181 | } | |
182 | ||
183 | function get_widget_callback(device) { | |
184 | return function() { | |
185 | //alert("get_widget_callback"); | |
186 | // msgHandler is the first argument, the next arguments are from the reply to listWidgets | |
187 | var act = arguments[0]; | |
188 | var act1 = act.GetArgumentValue("widgetCodes"); | |
189 | var act2 = act.GetArgumentValue("widgetNames"); | |
190 | //alert(act1+" "+act2); | |
191 | target_widgets = selector_window2(act1.split(" "), act2.split(" ")); | |
192 | target_widgets.on_select = function(item) { | |
193 | alert("target_widgets.on_select"); | |
194 | target_widgets.unregister(root); | |
195 | target_widgets = null; | |
196 | if (item == -1) { | |
197 | return; | |
198 | } | |
199 | alert("target_widgets.on_select(" + item + ")"); | |
200 | var args = new Array(); | |
201 | args[0] = "widgetCode"; | |
202 | args[1] = item; | |
203 | device.standardService.CallAction("getWidget", args); | |
204 | } | |
205 | target_widgets.register(root); | |
206 | } | |
207 | } | |
208 | ||
209 | // | |
210 | // creates the menu of available targets for pushing a widget elsewhere | |
211 | // | |
212 | function selector_window1() { | |
213 | var i, count, render; | |
214 | var selector = document.createElement('g'), obj, child; | |
215 | selector.setAttribute('transform', 'translate(10,10)'); | |
216 | count = WidgetManager.MPEGUStandardServiceProviders.length; | |
217 | selector.appendChild(rect(0, 0, 300, 20 * (count + 1), 'white', 'black')); | |
218 | for (i = 0; i < count; i++) { | |
219 | render = WidgetManager.MPEGUStandardServiceProviders[i]; | |
220 | obj = createtext(render.Name, 'black', 5, 17 + (20 * i), 15, 'sans-serif'); | |
221 | obj.setAttribute('id', "select" + i); | |
222 | selector.appendChild(obj); | |
223 | obj.addEventListener('mouseover', sw1("select" + i), false); | |
224 | obj.addEventListener('mouseout', sw2("select" + i), false); | |
225 | obj.addEventListener('click', sw4(i), false); | |
226 | } | |
227 | obj = createtext('Cancel', 'rgb(0,0,120)', 55, 17 + (20 * i), 15, 'sans-serif'); | |
228 | obj.setAttribute('id', "canc"); | |
229 | selector.appendChild(obj); | |
230 | obj.addEventListener('mouseover', function(evt) { document.getElementById("canc").setAttribute("fill", "red"); }, false); | |
231 | obj.addEventListener('mouseout', function(evt) { document.getElementById("canc").setAttribute("fill", "black"); }, false); | |
232 | obj.addEventListener('click', function(evt) { upnp_renders.on_select(-1); }, false); | |
233 | selector.register = function(disp) { | |
234 | disp.appendChild(this); | |
235 | }; | |
236 | selector.unregister = function(disp) { | |
237 | disp.removeChild(this); | |
238 | }; | |
239 | return selector; | |
240 | } | |
241 | ||
242 | // | |
243 | // creates the menu of available targets for pushing a widget elsewhere | |
244 | // | |
245 | function selector_window2(codes, names) { | |
246 | alert("selector_window2"); | |
247 | var i, count, render; | |
248 | var selector = document.createElement('g'), obj, child; | |
249 | selector.setAttribute('transform', 'translate(10,10)'); | |
250 | count = codes.length; | |
251 | selector.appendChild(rect(0, 0, 300, 20 * (count + 1), 'white', 'black')); | |
252 | for (i = 0; i < count; i++) { | |
253 | render = names[i]; | |
254 | obj = createtext(render, 'black', 5, 17 + (20 * i), 15, 'sans-serif'); | |
255 | obj.setAttribute('id', "selecto" + i); | |
256 | selector.appendChild(obj); | |
257 | obj.addEventListener('mouseover', sw1("selecto" + i), false); | |
258 | obj.addEventListener('mouseout', sw2("selecto" + i), false); | |
259 | obj.addEventListener('click', sw5(i), false); | |
260 | } | |
261 | obj = createtext('Cancel', 'rgb(0,0,120)', 55, 17 + (20 * i), 15, 'sans-serif'); | |
262 | obj.setAttribute('id', "cance"); | |
263 | selector.appendChild(obj); | |
264 | obj.addEventListener('mouseover', function(evt) { document.getElementById("cance").setAttribute("fill", "red"); }, false); | |
265 | obj.addEventListener('mouseout', function(evt) { document.getElementById("cance").setAttribute("fill", "black"); }, false); | |
266 | obj.addEventListener('click', function(evt) { target_widgets.on_select(-1); }, false); | |
267 | selector.register = function(disp) { | |
268 | disp.appendChild(this); | |
269 | }; | |
270 | selector.unregister = function(disp) { | |
271 | disp.removeChild(this); | |
272 | }; | |
273 | return selector; | |
274 | } | |
275 | ||
276 | function sw4(si) { | |
277 | return function(evt) { upnp_renders.on_select(si); }; | |
278 | } | |
279 | ||
280 | function sw5(si) { | |
281 | return function(evt) { target_widgets.on_select(si); }; | |
282 | } | |
283 | ||
284 | // | |
285 | // when deleting an executing widgets, all executing widgets to its right are moved to the left | |
286 | // | |
287 | function recurseMoveAfterDelete(target) { | |
288 | if (target != null && target.nextElementSibling != null) { | |
289 | var v = target.nextElementSibling; | |
290 | recurseMoveAfterDelete(v); | |
291 | v.setAttribute("transform", target.getAttribute("transform")); | |
292 | } | |
293 | } | |
294 | ||
295 | // | |
296 | // click on home button to switch from icons to executing widgets | |
297 | // | |
298 | function home_button(evt) { | |
299 | if (l_deb < log_level) { | |
300 | alert("[UI] home_button"); | |
301 | } | |
302 | if (state != 'home') { | |
303 | state = 'home'; | |
304 | widgetContainer.setAttribute('display', 'none'); | |
305 | homepage.setAttribute('display', 'inline'); | |
306 | homebar.setAttribute('display', 'inline'); | |
307 | execbar.setAttribute('display', 'none'); | |
308 | arrows.setAttribute('display', 'inline'); | |
309 | arrowsW.setAttribute('display', 'none'); | |
310 | widgetAddList.setAttribute('display', 'none'); | |
311 | } else { | |
312 | state = 'exec'; | |
313 | widgetContainer.setAttribute('display', 'inline'); | |
314 | homepage.setAttribute('display', 'none'); | |
315 | homebar.setAttribute('display', 'none'); | |
316 | execbar.setAttribute('display', 'inline'); | |
317 | arrows.setAttribute('display', 'none'); | |
318 | arrowsW.setAttribute('display', 'inline'); | |
319 | widgetAddList.setAttribute('display', 'none'); | |
320 | } | |
321 | } | |
322 | ||
323 | // constants | |
324 | var adjustFrom = "0,0"; | |
325 | var animDue = true; | |
326 | ||
327 | // | |
328 | // after each change of icon page, this function adjusts the visibility of arrows in the lower bar | |
329 | // | |
330 | function adjustwhere(animDue) { | |
331 | if (l_deb < log_level) { | |
332 | alert("[UI] adjust " + where + " 0 " + maxwhere); | |
333 | } | |
334 | document.getElementById("left").setAttribute("display", ((where > 0) ? "inline" : "none")); | |
335 | document.getElementById("right").setAttribute("display", ((where < maxwhere) ? "inline" : "none")); | |
336 | if (!animDue) { | |
337 | icons.setAttribute("transform", 'translate(' + (-80 * iconNbHoriz * where) + ',0)'); | |
338 | } else { | |
339 | var aw = document.createElement("animateTransform"); | |
340 | aw.setAttribute("attributeName", "transform"); | |
341 | aw.setAttribute("type", "translate"); | |
342 | //alert('time '+document.documentElement.getCurrentTime()); | |
343 | aw.setAttribute("begin", document.documentElement.getCurrentTime()); | |
344 | aw.setAttribute("dur", "1s"); | |
345 | aw.setAttribute("fill", "freeze"); | |
346 | aw.setAttributeNS(xlinkns, "href", "#icons"); | |
347 | aw.setAttribute("from", adjustFrom); | |
348 | aw.setAttribute("to", (-80 * iconNbHoriz * where) + ",0"); | |
349 | document.documentElement.appendChild(aw); | |
350 | } | |
351 | adjustFrom = (-80 * iconNbHoriz * where) + ",0"; | |
352 | } | |
353 | ||
354 | // | |
355 | // action of the left button on the lower bar | |
356 | // | |
357 | function left_button() { | |
358 | if (l_deb < log_level) { | |
359 | alert("[UI] left button " + where + " 0"); | |
360 | } | |
361 | if (where > 0) { | |
362 | where--; | |
363 | adjustwhere(true); | |
364 | } | |
365 | } | |
366 | ||
367 | // | |
368 | // action of the right button of the lower bar | |
369 | // | |
370 | function right_button() { | |
371 | if (l_deb < log_level) { | |
372 | alert("[UI] right button " + where + " " + maxwhere); | |
373 | } | |
374 | if (where < maxwhere) { | |
375 | where++; | |
376 | adjustwhere(true); | |
377 | } | |
378 | } | |
379 | ||
380 | var adjustFromW = "0,0"; | |
381 | var oldwhereW = -1; | |
382 | ||
383 | // | |
384 | // after each change of icon page, this function adjusts the visibility of arrows in the lower bar | |
385 | // | |
386 | function adjustWhereWidgets(animDue) { | |
387 | if (oldwhereW != whereW) { | |
388 | // hide oldwhereW | |
389 | if (oldwhereW >= 0 && activatedWidgets[oldwhereW] != null) { | |
390 | WidgetManager.corein_message(activatedWidgets[oldwhereW], "hide"); | |
391 | } | |
392 | } | |
393 | if (l_deb < log_level) { | |
394 | alert("[UI] adjustW " + whereW + " 0 " + (numActivatedWidgets - 1)); | |
395 | } | |
396 | document.getElementById("leftW").setAttribute("display", ((whereW > 0) ? "inline" : "none")); | |
397 | document.getElementById("rightW").setAttribute("display", ((whereW < (numActivatedWidgets - 1)) ? "inline" : "none")); | |
398 | if (!animDue) { | |
399 | widgetContainer.setAttribute("transform", "translate(" + (-totalWidth * whereW) + ",0)"); | |
400 | } else { | |
401 | var aw = document.createElement("animateTransform"); | |
402 | aw.setAttribute("attributeName", "transform"); | |
403 | aw.setAttribute("type", "translate"); | |
404 | aw.setAttribute("begin", document.documentElement.getCurrentTime()); | |
405 | aw.setAttribute("dur", "1s"); | |
406 | aw.setAttribute("fill", "freeze"); | |
407 | aw.setAttributeNS(xlinkns, "href", "#widget"); | |
408 | aw.setAttribute("from", adjustFromW); | |
409 | aw.setAttribute("to", (-totalWidth * whereW) + ",0"); | |
410 | document.documentElement.appendChild(aw); | |
411 | } | |
412 | adjustFromW = (-totalWidth * whereW) + ",0"; | |
413 | document.getElementById("widgetName").textContent = | |
414 | (whereW >= 0 && activatedWidgets[whereW] != null ? activatedWidgets[whereW].shortName : '-'); | |
415 | if (oldwhereW != whereW) { | |
416 | // show whereW | |
417 | if (whereW >= 0 && activatedWidgets[whereW] != null) { | |
418 | WidgetManager.corein_message(activatedWidgets[whereW], "show"); | |
419 | } | |
420 | oldwhereW = whereW; | |
421 | } | |
422 | } | |
423 | ||
424 | // | |
425 | // action of the left button on the lower bar | |
426 | // | |
427 | function left_buttonW() { | |
428 | if (l_deb < log_level) { | |
429 | alert("[UI] left button " + whereW); | |
430 | } | |
431 | if (whereW > 0) { | |
432 | whereW--; | |
433 | adjustWhereWidgets(animDue); | |
434 | } | |
435 | } | |
436 | ||
437 | // | |
438 | // action of the right button of the lower bar | |
439 | // | |
440 | function right_buttonW() { | |
441 | if (l_deb < log_level) { | |
442 | alert("[UI] right button " + whereW + " " + (numActivatedWidgets - 1)); | |
443 | } | |
444 | if (whereW < (numActivatedWidgets - 1)) { | |
445 | whereW++; | |
446 | adjustWhereWidgets(animDue); | |
447 | } | |
448 | } | |
449 | ||
450 | // | |
451 | // action of each icon, starting the matching widget | |
452 | // | |
453 | function activating_widget(w) { | |
454 | if (l_deb < log_level) { | |
455 | alert("[UI] activating widget: " + w.name); | |
456 | } | |
457 | widget_add(w); | |
458 | } | |
459 | ||
460 | // | |
461 | // main initialization function | |
462 | // init variables, then init the widget manager C code, then inits UPnP | |
463 | // | |
464 | function initialize() { | |
465 | if (l_deb < log_level) { | |
466 | alert("[UI] initialize"); | |
467 | } | |
468 | init = false; | |
469 | var display_width = parseInt(gpac.getOption('Widgets', 'LastWMWidth')); | |
470 | var display_height = parseInt(gpac.getOption('Widgets', 'LastWMHeight')); | |
471 | if (display_width && display_height) { | |
472 | gpac.set_size(display_width, display_height); | |
473 | } | |
474 | root = document.documentElement; | |
475 | homepage = document.getElementById('homepage'); | |
476 | homebar = document.getElementById('homebar'); | |
477 | execbar = document.getElementById('execbar'); | |
478 | arrows = document.getElementById('arrows'); | |
479 | arrowsW = document.getElementById('arrowsW'); | |
480 | icons = document.getElementById('icons'); | |
481 | widgetContainer = document.getElementById('widget'); | |
482 | widgetAddList = document.getElementById('widgetAddList'); | |
483 | /* Setup the GPAC Widget Manager - this will also scan the available widgets */ | |
484 | log_level = l_inf; | |
485 | widget_manager_init(); | |
486 | WidgetManager.on_widget_remove = widget_remove; | |
487 | WidgetManager.on_widget_add = widget_add; | |
488 | /* register the callback to be notified of incoming widgets */ | |
489 | has_upnp = (typeof UPnP != 'undefined'); | |
490 | if (has_upnp) { | |
491 | /* setting the callback to allow other devices to push their widgets */ | |
492 | UPnP.onMediaConnect = onMediaConnect; | |
493 | /* Tell GPAC that the calls to the main Renderer (like open, ...) must be forwared to this scene */ | |
494 | UPnP.BindRenderer(); | |
495 | } | |
496 | WidgetManager.coreOutShow = coreOutShowImplementation; | |
497 | WidgetManager.coreOutGetAttention = coreOutGetAttentionImplementation; | |
498 | WidgetManager.coreOutHide = coreOutHideImplementation; | |
499 | WidgetManager.coreOutRequestDeactivate = coreOutRequestDeactivateImplementation; | |
500 | WidgetManager.coreOutInstallWidget = coreOutInstallWidgetImplementation; | |
501 | WidgetManager.coreOutActivateTemporaryWidget = coreOutActivateTemporaryWidgetImplementation; | |
502 | WidgetManager.coreOutMigrateComponent = coreOutMigrateComponentImplementation; | |
503 | WidgetManager.coreOutRequestMigrationTargets = coreOutRequestMigrationTargetsImplementation; | |
504 | } | |
505 | ||
506 | // | |
507 | // implementation of core:out install widget | |
508 | // | |
509 | function coreOutInstallWidgetImplementation(wid, args) { | |
510 | var w = widgetInstall(args[0], true, false, wid); | |
511 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
512 | if (ifce != null) { | |
513 | wmjs_core_out_invoke_reply(coreOut.installWidgetMessage, ifce.get_message("installWidget"), | |
514 | wid, (w != null ? 1 : 0)); // send return code 1 = success | |
515 | } | |
516 | } | |
517 | ||
518 | // | |
519 | // implementation of core:out activate temporary widget | |
520 | // | |
521 | function coreOutActivateTemporaryWidgetImplementation(wid, args) { | |
522 | var w = widgetInstall(args[0], true, true, null); | |
523 | if (w != null) { | |
524 | activating_widget(w); | |
525 | } | |
526 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
527 | if (ifce != null) { | |
528 | wmjs_core_out_invoke_reply(coreOut.activateTemporaryWidgetMessage, ifce.get_message("activateTemporaryWidget"), | |
529 | wid, (w != null ? 1 : 0)); // send return code 1 = success | |
530 | } | |
531 | } | |
532 | ||
533 | // | |
534 | // implementation of core:out migrate component | |
535 | // | |
536 | function coreOutMigrateComponentImplementation(wid, args) { | |
537 | //alert("coreOutMigrateComponent "+wid.name+" "+args.length); | |
538 | var comp = wid.get_component(args[0], true); | |
539 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
540 | if (comp == null) { | |
541 | log(l_err, 'Component ' + args[0] + ' cannot be found in widget ' + wid.name); | |
542 | if (ifce != null) { | |
543 | wmjs_core_out_invoke_reply(coreOut.migrateComponentMessage, ifce.get_message("migrateComponent"), wid, 0); | |
544 | } | |
545 | return; | |
546 | } | |
547 | if (args.length > 1 && args[1] != null) { | |
548 | //WidgetManager.migrate_widget(UPnP.GetMediaRenderer(parseInt(args[1])), comp); | |
549 | WidgetManager.migrate_widget(WidgetManager.get_mpegu_service_providers(parseInt(args[1])), comp); | |
550 | widget_close(comp); | |
551 | } else { | |
552 | upnp_renders = selector_window(comp); | |
553 | upnp_renders.on_select = function(item, wid) { | |
554 | upnp_renders.unregister(root); | |
555 | upnp_renders = null; | |
556 | if (item == -1) { | |
557 | return; | |
558 | } | |
559 | if (comp != null) { | |
560 | alert("upnp_renders.on_select(" + item + "," + comp.name + ")"); | |
561 | //WidgetManager.migrate_widget(UPnP.GetMediaRenderer(item), comp); | |
562 | WidgetManager.migrate_widget(WidgetManager.get_mpegu_service_providers(item), comp); | |
563 | widget_close(comp); | |
564 | } | |
565 | }; | |
566 | upnp_renders.register(root); | |
567 | } | |
568 | if (ifce != null) { | |
569 | wmjs_core_out_invoke_reply(coreOut.migrateComponentMessage, ifce.get_message("migrateComponent"), wid, 1); // send return code 1 = success | |
570 | } | |
571 | } | |
572 | ||
573 | // | |
574 | // implementation of core:out request migration targets | |
575 | // | |
576 | function coreOutRequestMigrationTargetsImplementation(wid, args) { | |
577 | var count = UPnP.MediaRenderersCount, codes = new Array(), names = new Array(), descriptions = new Array(), i; | |
578 | for (i = 0; i < count; i++) { | |
579 | var render = UPnP.GetMediaRenderer(i); | |
580 | codes.push("" + i); | |
581 | names.push(render.Name); | |
582 | descriptions.push(render.HostName + " " + render.UUID); | |
583 | } | |
584 | i = null; | |
585 | var ifce_count = wid.num_interfaces, j; | |
586 | for (j = 0; j < ifce_count; j++) { | |
587 | var ifce = wid.get_interface(j); | |
588 | if (ifce.type == "urn:mpeg:mpegu:schema:widgets:core:out:2010") { | |
589 | i = ifce; | |
590 | break; | |
591 | } | |
592 | } | |
593 | if (i != null) { | |
594 | wmjs_core_out_invoke_reply(coreOut.requestMigrationTargetsMessage, i.get_message("requestMigrationTargets"), | |
595 | wid, codes, names, descriptions); | |
596 | } | |
597 | } | |
598 | ||
599 | // | |
600 | // implementation of core:out Show message | |
601 | // this is a request by the widget to be shown | |
602 | // | |
603 | function coreOutShowImplementation(wid, args) { | |
604 | //alert("core:out show "+wid.name); | |
605 | var target = widgetContainer.firstElementChild; | |
606 | var i; | |
607 | for (i = 0; i < numActivatedWidgets; i++) { | |
608 | //alert("is it "+activatedWidgets[i].name); | |
609 | if (activatedWidgets[i] == wid) { | |
610 | break; | |
611 | } | |
612 | target = target.nextElementSibling; | |
613 | } | |
614 | // here, i is the index of the current widget | |
615 | //alert(" "+i+" "+numActivatedWidgets); | |
616 | if (i < numActivatedWidgets) { | |
617 | whereW = i; | |
618 | adjustWhereWidgets(false); | |
619 | } | |
620 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
621 | if (ifce != null) { | |
622 | wmjs_core_out_invoke_reply(coreOut.showMessage, ifce.get_message("show"), wid, 1); // send return code 1 = success | |
623 | } | |
624 | } | |
625 | ||
626 | // | |
627 | // implementation of core:out GetAttention message | |
628 | // this is a request by the widget to be shown and some special signal is given | |
629 | // | |
630 | function coreOutGetAttentionImplementation(wid, args) { | |
631 | //alert("core:out getAttention "+wid.name); | |
632 | var target = widgetContainer.firstElementChild; | |
633 | var i; | |
634 | for (i = 0; i < numActivatedWidgets; i++) { | |
635 | //alert("is it "+activatedWidgets[i].name); | |
636 | if (activatedWidgets[i] == wid) { | |
637 | break; | |
638 | } | |
639 | target = target.nextElementSibling; | |
640 | } | |
641 | // here, i is the index of the current widget | |
642 | //alert(" "+i+" "+numActivatedWidgets); | |
643 | if (i < numActivatedWidgets) { | |
644 | whereW = i; | |
645 | adjustWhereWidgets(false); | |
646 | } | |
647 | document.getElementById("getAttention").beginElement(); | |
648 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
649 | if (ifce != null) { | |
650 | wmjs_core_out_invoke_reply(coreOut.getAttentionMessage, ifce.get_message("getAttention"), wid, 1); // send return code 1 = success | |
651 | } | |
652 | } | |
653 | ||
654 | // | |
655 | // implementation of core:out hide message | |
656 | // this is a request by the widget to be hidden (some other widget (if any) is shown) | |
657 | // | |
658 | function coreOutHideImplementation(wid, args) { | |
659 | //alert("core:out hide "+wid.name); | |
660 | var target = widgetContainer.firstElementChild; | |
661 | var i; | |
662 | for (i = 0; i < numActivatedWidgets; i++) { | |
663 | //alert("is it "+activatedWidgets[i].name); | |
664 | if (activatedWidgets[i] == wid) { | |
665 | break; | |
666 | } | |
667 | target = target.nextElementSibling; | |
668 | } | |
669 | // here, i is the index of the current widget | |
670 | //alert("hide "+i+" "+numActivatedWidgets); | |
671 | if (i < numActivatedWidgets) { | |
672 | if (whereW > 0) { | |
673 | whereW--; | |
674 | } | |
675 | else if (whereW < numActivatedWidgets - 1) { | |
676 | whereW++; | |
677 | } | |
678 | else { | |
1 | /* wrapper as a module | |
2 | var iphone_wm_gui = (function () { | |
3 | */ | |
4 | // to make sure the initialization is done only once | |
5 | var init = true; | |
6 | ||
7 | // constant | |
8 | var xlinkns = 'http://www.w3.org/1999/xlink'; | |
9 | //var evns = 'http://www.w3.org/2001/xml-events'; | |
10 | ||
11 | // state of the widget manager: displays homepage (value=home) or executes widget (value="exec") | |
12 | var state = 'home'; | |
13 | ||
14 | // convenience variables for SVG elements | |
15 | var homepage = null, arrows = null, icons = null, widgetContainer = null, homebar = null, execbar = null; | |
16 | ||
17 | // where is the index into pages of icons on the home page | |
18 | var where = 0,maxwhere = 0,whereW = 0; | |
19 | ||
20 | // array of activated widgets | |
21 | var activatedWidgets = new Array(); | |
22 | var numActivatedWidgets = 0; | |
23 | ||
24 | // variables for flexible layout | |
25 | // variables for flexible layout | |
26 | var totalWidth = 0,totalHeight = 0,iconNbHoriz = 0,iconNbVert = 0,iconsPerPage = 0; | |
27 | ||
28 | //previous size | |
29 | var previousWidth = 0,previousHeight = 0; | |
30 | ||
31 | // to differentiate between install icon and scan dir for icons | |
32 | var isThisAScan = null; | |
33 | ||
34 | // preferred icon type | |
35 | var preferredIconType = '.svg'; | |
36 | ||
37 | // adapt layout to the size of the screen | |
38 | function adaptLayoutToSize() { | |
39 | if (l_deb < log_level) { | |
40 | alert("[UI] adaptLayoutToSize"); | |
41 | } | |
42 | display_width = parseInt( gpac.getOption('General', 'LastWidth') ); | |
43 | display_height = parseInt( gpac.getOption('General', 'LastHeight') ); | |
44 | alert("display "+display_width+" "+display_height); | |
45 | if (!gpac.fullscreen && display_width && display_height) { | |
46 | gpac.set_size(display_width, display_height); | |
47 | } | |
48 | var tmpObject, tmpObj2; | |
49 | // get size to adapt to | |
50 | totalWidth = document.documentElement.viewport.width; | |
51 | totalHeight = document.documentElement.viewport.height; | |
52 | if (totalWidth == 0) { | |
53 | totalWidth = 160; | |
54 | } | |
55 | if (totalHeight == 0) { | |
56 | totalHeight = 280; | |
57 | } | |
58 | while (totalWidth < 160 || totalHeight < 280) { | |
59 | totalWidth *= 4; | |
60 | totalHeight *= 4; | |
61 | } | |
62 | // min size is 160 by 280 | |
63 | if (totalWidth < 160) { | |
64 | totalWidth = 160; | |
65 | } | |
66 | if (totalHeight < 280) { | |
67 | totalHeight = 280; | |
68 | } | |
69 | // round to lower multiple of 80 | |
70 | totalWidth -= totalWidth % 80; | |
71 | var iconHeight = totalHeight - 120; | |
72 | iconHeight -= iconHeight % 80; | |
73 | // how many lines and columns of icons | |
74 | iconNbHoriz = totalWidth / 80; | |
75 | iconNbVert = iconHeight / 80; | |
76 | totalHeight = iconHeight + 120; | |
77 | // 120 is upper bar (60) + lower bar (60) | |
78 | iconsPerPage = iconNbHoriz * iconNbVert; | |
79 | // fix svg viewbox | |
80 | document.getElementById("svg").setAttribute("viewBox", "0 0 " + totalWidth + " " + totalHeight); | |
81 | // fix odd line | |
82 | tmpObj2 = document.getElementById("odd"); | |
83 | var i, already = tmpObj2.getElementsByTagName("use").length; | |
84 | //alert("odd line "+already+" "+iconNbHoriz); | |
85 | for (i = already; i < iconNbHoriz; i++) { | |
86 | tmpObject = document.createElement("use"); | |
87 | tmpObject.setAttribute("x", i * 80); | |
88 | tmpObject.setAttributeNS(xlinkns, "href", (((i % 2) == 0) ? "#lightRect" : "#darkRect" )); | |
89 | tmpObj2.appendChild(tmpObject); | |
90 | } | |
91 | // fix even line | |
92 | tmpObj2 = document.getElementById("even"); | |
93 | already = tmpObj2.getElementsByTagName("use").length; | |
94 | //alert("even line "+already+" "+iconNbHoriz); | |
95 | for (i = already; i < iconNbHoriz; i++) { | |
96 | tmpObject = document.createElement("use"); | |
97 | tmpObject.setAttribute("x", i * 80); | |
98 | tmpObject.setAttributeNS(xlinkns, "href", (((i % 2) == 0) ? "#darkRect" : "#lightRect" )); | |
99 | tmpObj2.appendChild(tmpObject); | |
100 | } | |
101 | // fix frame (black with rounded corners) | |
102 | tmpObject = document.getElementById("frame"); | |
103 | tmpObject.setAttribute("width", totalWidth); | |
104 | tmpObject.setAttribute("height", totalHeight); | |
105 | tmpObject = document.getElementById("frame2"); | |
106 | tmpObject.setAttribute("width", totalWidth); | |
107 | tmpObject.setAttribute("height", totalHeight); | |
108 | // fix screen (white) | |
109 | tmpObject = document.getElementById("screen"); | |
110 | tmpObject.setAttribute("width", totalWidth); | |
111 | tmpObject.setAttribute("height", totalHeight - 120); | |
112 | // fix grid back (gray) | |
113 | tmpObject = document.getElementById("gridback"); | |
114 | tmpObject.setAttribute("width", totalWidth); | |
115 | tmpObject.setAttribute("height", totalHeight - 120); | |
116 | // fix icon background grid | |
117 | tmpObject = document.getElementById("grid"); | |
118 | already = tmpObject.getElementsByTagName("use").length; | |
119 | for (i = already; i < iconNbVert; i++) { | |
120 | tmpObj2 = document.createElement("use"); | |
121 | tmpObj2.setAttribute("y", i * 80); | |
122 | tmpObj2.setAttributeNS(xlinkns, "href", (((i % 2) == 0) ? "#odd" : "#even" )); | |
123 | tmpObject.appendChild(tmpObj2); | |
124 | } | |
125 | // if there are already too many lines, remove the extra ones otherwise they are rendered on top of the lower | |
126 | // part of the decoration | |
127 | if (already > iconNbVert) { | |
128 | while (already-- > iconNbVert) { | |
129 | tmpObject.removeChild(tmpObject.lastChild); | |
130 | } | |
131 | } | |
132 | // fix commands (lower bar) | |
133 | document.getElementById("commands").setAttribute("transform", "translate(0, " + (totalHeight - 60) + ")"); | |
134 | document.getElementById("homeButton").setAttribute("transform", "translate(" + (totalWidth / 2) + ", 30)"); | |
135 | document.getElementById("right").setAttribute("transform", "translate(" + (totalWidth - 50) + ", 10)"); | |
136 | document.getElementById("rightW").setAttribute("transform", "translate(" + (totalWidth - 50) + ", 10)"); | |
137 | // fix the cuts (white rects left and right because we have no clipping) | |
138 | tmpObject = document.getElementById("leftCut"); | |
139 | tmpObject.setAttribute("width", totalWidth); | |
140 | tmpObject.setAttribute("height", totalHeight); | |
141 | tmpObject.setAttribute("x", -1 - totalWidth); | |
142 | tmpObject = document.getElementById("rightCut"); | |
143 | tmpObject.setAttribute("width", totalWidth); | |
144 | tmpObject.setAttribute("height", totalHeight); | |
145 | tmpObject.setAttribute("x", 1 + totalWidth); | |
146 | // respace executing widgets if any | |
147 | tmpObject = widgetContainer.getElementsByTagName("g"); | |
148 | for (i = 0; i < tmpObject.length; i++) { | |
149 | var gg = tmpObject.item(i); | |
150 | gg.setAttribute("transform", "translate(" + (totalWidth * (i - 1)) + ", 0)"); | |
151 | if (gg.firstElementChild != null) { | |
152 | gg.firstElementChild.setAttribute("width", totalWidth); | |
153 | gg.firstElementChild.setAttribute("height", totalHeight - 120); | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | // | |
159 | // widget close on click at "Kill" button | |
160 | // | |
161 | function on_kill_widget() { | |
162 | if (state == 'exec') { | |
163 | widget_close(activatedWidgets[whereW]); | |
164 | } | |
165 | } | |
166 | ||
167 | // | |
168 | // widget get on click at "GetW" button | |
169 | // | |
170 | function on_get_widget() { | |
171 | alert("on_get_widget " + WidgetManager.MPEGUStandardServiceProviders.length); | |
172 | if (WidgetManager.MPEGUStandardServiceProviders.length != 0) { | |
173 | upnp_renders = selector_window1(); | |
174 | upnp_renders.on_select = function(item) { | |
175 | upnp_renders.unregister(root); | |
176 | upnp_renders = null; | |
177 | if (item == -1) { | |
679 | 178 | return; |
680 | 179 | } |
681 | adjustWhereWidgets(false); | |
682 | } | |
683 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
684 | if (ifce != null) { | |
685 | wmjs_core_out_invoke_reply(coreOut.hideMessage, ifce.get_message("hide"), wid, 1); // send return code 1 = success | |
686 | } | |
687 | } | |
688 | ||
689 | // | |
690 | // implementation of core:out requestDeactivate message | |
691 | // this is a request by the widget to be stopped | |
692 | // | |
693 | function coreOutRequestDeactivateImplementation(wid, args) { | |
694 | //alert("core:out hide "+wid.name); | |
695 | var target = widgetContainer.firstElementChild; | |
696 | var i; | |
697 | for (i = 0; i < numActivatedWidgets; i++) { | |
698 | //alert("is it "+activatedWidgets[i].name); | |
699 | if (activatedWidgets[i] == wid) { | |
700 | break; | |
180 | alert("upnp_renders.on_select(" + item + ")"); | |
181 | var device = WidgetManager.MPEGUStandardServiceProviders[item]; | |
182 | device.standardService.SetActionListener("listWidgets", get_widget_callback(device), true); | |
183 | device.standardService.CallAction("listWidgets", new Array()); | |
184 | } | |
185 | upnp_renders.register(root); | |
186 | } | |
187 | } | |
188 | ||
189 | function get_widget_callback(device) { | |
190 | return function() { | |
191 | //alert("get_widget_callback"); | |
192 | // msgHandler is the first argument, the next arguments are from the reply to listWidgets | |
193 | var act = arguments[0]; | |
194 | var act1 = act.GetArgumentValue("widgetCodes"); | |
195 | var act2 = act.GetArgumentValue("widgetNames"); | |
196 | //alert(act1+" "+act2); | |
197 | target_widgets = selector_window2(act1.split(" "), act2.split(" ")); | |
198 | target_widgets.on_select = function(item) { | |
199 | alert("target_widgets.on_select"); | |
200 | target_widgets.unregister(root); | |
201 | target_widgets = null; | |
202 | if (item == -1) { | |
203 | return; | |
701 | 204 | } |
702 | target = target.nextElementSibling; | |
703 | } | |
704 | // here, i is the index of the current widget | |
705 | //alert("hide "+i+" "+numActivatedWidgets); | |
706 | if (i < numActivatedWidgets) { | |
707 | widget_close(activatedWidgets[i]); | |
708 | } | |
709 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
710 | if (ifce != null) { | |
711 | wmjs_core_out_invoke_reply(coreOut.requestDeactivateMessage, ifce.get_message("requestDeactivate"), wid, 1); // send return code 1 = success | |
712 | } | |
713 | } | |
714 | ||
715 | // | |
716 | // WM callback for when a component is activated by its parent | |
717 | // | |
718 | function widget_add(w) { | |
719 | log(l_inf, "widget add " + w.name); | |
720 | if (!w.activated) { | |
721 | if (sameFileIgnoringSVGView(w.icon, w.main)) { | |
722 | // same file in icon and main | |
723 | } else { | |
724 | widget_launch(w, document.createElement("animation")); | |
725 | } | |
726 | } else if (w.multipleInstances) { | |
727 | var newwid = WidgetManager.open(w.manifest, null); | |
728 | widget_launch(newwid, document.createElement("animation")); | |
729 | } else return false; | |
205 | alert("target_widgets.on_select(" + item + ")"); | |
206 | var args = new Array(); | |
207 | args[0] = "widgetCode"; | |
208 | args[1] = item; | |
209 | device.standardService.SetActionListener("getWidget", get_widget_callback2, true); | |
210 | device.standardService.CallAction("getWidget", args); | |
211 | } | |
212 | target_widgets.register(root); | |
213 | } | |
214 | } | |
215 | ||
216 | function get_widget_callback2() { | |
217 | // msgHandler is the first argument, the next arguments are from the reply to listWidgets | |
218 | alert("callback2-1"); | |
219 | var act = arguments[0]; | |
220 | var act1 = act.GetArgumentValue("widgetUrl"); | |
221 | var act2 = act.GetArgumentValue("widgetContext"); | |
222 | alert("callback2-2 " + act1 + " " + act2); | |
223 | var wid = WidgetManager.load(act1, null, act2); | |
224 | WidgetManager.on_widget_add(wid); | |
225 | } | |
226 | ||
227 | // | |
228 | // creates the menu of available targets for pushing a widget elsewhere | |
229 | // | |
230 | function selector_window1() { | |
231 | var i, count, render; | |
232 | var selector = document.createElement('g'), obj, child; | |
233 | selector.setAttribute('transform', 'translate(10,10)'); | |
234 | count = WidgetManager.MPEGUStandardServiceProviders.length; | |
235 | selector.appendChild(rect(0, 0, 300, 20 * (count + 1), 'white', 'black', null)); | |
236 | for (i = 0; i < count; i++) { | |
237 | render = WidgetManager.MPEGUStandardServiceProviders[i]; | |
238 | obj = createtext(render.Name, 'black', 5, 17 + (20 * i), 15, 'sans-serif'); | |
239 | obj.setAttribute('id', "select" + i); | |
240 | selector.appendChild(obj); | |
241 | obj.addEventListener('mouseover', sw1("select" + i), false); | |
242 | obj.addEventListener('mouseout', sw2("select" + i), false); | |
243 | obj.addEventListener('click', sw4(i), false); | |
244 | } | |
245 | obj = createtext('Cancel', 'rgb(0,0,120)', 55, 17 + (20 * i), 15, 'sans-serif'); | |
246 | obj.setAttribute('id', "canc"); | |
247 | selector.appendChild(obj); | |
248 | obj.addEventListener('mouseover', function() { document.getElementById("canc").setAttribute("fill", "red"); }, false); | |
249 | obj.addEventListener('mouseout', function() { document.getElementById("canc").setAttribute("fill", "black"); }, false); | |
250 | obj.addEventListener('click', function() { upnp_renders.on_select(-1); }, false); | |
251 | selector.register = function(disp) { | |
252 | disp.appendChild(this); | |
253 | }; | |
254 | selector.unregister = function(disp) { | |
255 | disp.removeChild(this); | |
256 | }; | |
257 | return selector; | |
258 | } | |
259 | ||
260 | // | |
261 | // creates the menu of available targets for pushing a widget elsewhere | |
262 | // | |
263 | function selector_window2(codes, names) { | |
264 | alert("selector_window2"); | |
265 | var i, count, render; | |
266 | var selector = document.createElement('g'), obj, child; | |
267 | selector.setAttribute('transform', 'translate(10,10)'); | |
268 | count = codes.length; | |
269 | selector.appendChild(rect(0, 0, 300, 20 * (count + 1), 'white', 'black', null)); | |
270 | for (i = 0; i < count; i++) { | |
271 | render = names[i]; | |
272 | obj = createtext(render, 'black', 5, 17 + (20 * i), 15, 'sans-serif'); | |
273 | obj.setAttribute('id', "selecto" + i); | |
274 | selector.appendChild(obj); | |
275 | obj.addEventListener('mouseover', sw1("selecto" + i), false); | |
276 | obj.addEventListener('mouseout', sw2("selecto" + i), false); | |
277 | obj.addEventListener('click', sw5(i), false); | |
278 | } | |
279 | obj = createtext('Cancel', 'rgb(0,0,120)', 55, 17 + (20 * i), 15, 'sans-serif'); | |
280 | obj.setAttribute('id', "cance"); | |
281 | selector.appendChild(obj); | |
282 | obj.addEventListener('mouseover', function() { document.getElementById("cance").setAttribute("fill", "red"); }, false); | |
283 | obj.addEventListener('mouseout', function() { document.getElementById("cance").setAttribute("fill", "black"); }, false); | |
284 | obj.addEventListener('click', function() { target_widgets.on_select(-1); }, false); | |
285 | selector.register = function(disp) { | |
286 | disp.appendChild(this); | |
287 | }; | |
288 | selector.unregister = function(disp) { | |
289 | disp.removeChild(this); | |
290 | }; | |
291 | return selector; | |
292 | } | |
293 | ||
294 | function sw4(si) { | |
295 | return function() { upnp_renders.on_select(si); }; | |
296 | } | |
297 | ||
298 | function sw5(si) { | |
299 | return function() { target_widgets.on_select(si); }; | |
300 | } | |
301 | ||
302 | // | |
303 | // when deleting an executing widgets, all executing widgets to its right are moved to the left | |
304 | // | |
305 | function recurseMoveAfterDelete(target) { | |
306 | if (target != null && target.nextElementSibling != null) { | |
307 | var v = target.nextElementSibling; | |
308 | recurseMoveAfterDelete(v); | |
309 | v.setAttribute("transform", target.getAttribute("transform")); | |
310 | } | |
311 | } | |
312 | ||
313 | // | |
314 | // click on home button to switch from icons to executing widgets | |
315 | // | |
316 | function home_button(evt) { | |
317 | if (l_deb < log_level) { | |
318 | alert("[UI] home_button"); | |
319 | } | |
320 | if (state != 'home') { | |
321 | state = 'home'; | |
322 | widgetContainer.setAttribute('display', 'none'); | |
323 | homepage.setAttribute('display', 'inline'); | |
324 | homebar.setAttribute('display', 'inline'); | |
325 | execbar.setAttribute('display', 'none'); | |
326 | arrows.setAttribute('display', 'inline'); | |
327 | arrowsW.setAttribute('display', 'none'); | |
328 | widgetAddList.setAttribute('display', 'none'); | |
329 | } else { | |
730 | 330 | state = 'exec'; |
731 | 331 | widgetContainer.setAttribute('display', 'inline'); |
732 | 332 | homepage.setAttribute('display', 'none'); |
735 | 335 | arrows.setAttribute('display', 'none'); |
736 | 336 | arrowsW.setAttribute('display', 'inline'); |
737 | 337 | widgetAddList.setAttribute('display', 'none'); |
738 | return true; | |
739 | } | |
740 | ||
741 | function sameFileIgnoringSVGView(name1, name2) { | |
742 | if (name1 == name2) { | |
743 | return true; | |
744 | } | |
745 | if (name1 == null) { | |
746 | return false; | |
747 | } | |
748 | var i1 = name1.indexOf("#"); | |
749 | var i2 = name2.indexOf("#"); | |
750 | if (i1 < 0) { | |
751 | i1 = name1.length; | |
752 | } | |
753 | else { | |
754 | i1--; | |
755 | } | |
756 | if (i2 < 0) { | |
757 | i2 = name2.length; | |
758 | } | |
759 | else { | |
760 | i2--; | |
761 | } | |
762 | return name1.substring(0, i1) == name2.substring(0, i2); | |
763 | } | |
764 | ||
765 | // | |
766 | // recompute the number of widgets loaded currently | |
767 | // | |
768 | function getNbWidgets() { | |
769 | var i, nbWidgets = 0; | |
770 | for (i = 0; i < WidgetManager.num_widgets; i++) { | |
771 | var w = WidgetManager.get(i); | |
772 | if (w != null && w.loaded) { | |
773 | nbWidgets++; | |
774 | } | |
775 | } | |
776 | return nbWidgets; | |
777 | } | |
778 | ||
779 | // | |
780 | // just resize the window and viewport, and initialize the first time this is called | |
781 | // | |
782 | function resize() { | |
783 | if (init) { | |
784 | initialize(); | |
785 | } | |
786 | if (document.documentElement.viewport.width == previousWidth && document.documentElement.viewport.height == previousHeight) { | |
787 | return; | |
788 | } | |
789 | if (l_deb < log_level) { | |
790 | alert("[UI] start initialize() w:" + document.documentElement.viewport.width + " h:" + document.documentElement.viewport.height); | |
791 | } | |
792 | adaptLayoutToSize(); | |
793 | // start by filling the "home page" with known icons | |
794 | where = 0; | |
795 | var nbWidgets = getNbWidgets(); | |
796 | maxwhere = ((nbWidgets - 1) - ((nbWidgets - 1) % iconsPerPage)) / iconsPerPage; | |
797 | var wid; | |
798 | var iconIterator = document.getElementById("icons").firstElementChild; | |
799 | var position = 0; | |
800 | for (i = 1; i <= WidgetManager.num_widgets; i++) { | |
801 | wid = WidgetManager.get(i - 1); | |
802 | // alert("build:"+wid.main+" "+wid.loaded); | |
803 | if (wid.loaded) { | |
804 | insert_icon(wid, position, i - 1, iconIterator); | |
805 | WidgetManager.corein_message(wid, 'setSize', 'width', totalWidth, 'height', totalHeight - 120, 'dpi', 96); | |
806 | position++; | |
807 | if (iconIterator != null) { | |
808 | iconIterator = iconIterator.nextElementSibling; | |
809 | } | |
810 | } | |
811 | } | |
812 | adjustwhere(false); | |
813 | adjustWhereWidgets(false); | |
814 | previousWidth = document.documentElement.viewport.width; | |
815 | previousHeight = document.documentElement.viewport.height; | |
816 | gpac.setOption("Widgets", "LastWMWidth", '' + previousWidth); | |
817 | gpac.setOption("Widgets", "LastWMHeight", '' + previousHeight); | |
818 | } | |
819 | ||
820 | // | |
821 | // function inserting an icon on the home page | |
822 | // | |
823 | function insert_icon(widget, position, widgetIndex, previousIcon) { | |
824 | if (l_deb < log_level) { | |
825 | alert("[UI] insert_icon: " + widget.shortName + " " + position + " " + widgetIndex + " WMnw:" + WidgetManager.num_widgets); | |
826 | } | |
827 | widget.loaded = true; | |
828 | if (l_deb < log_level) { | |
829 | alert("[UI] widget name: " + widget.name); | |
830 | } | |
831 | var icon = null, original = null; | |
832 | for (var i = 0; i < widget.icons.length; i++) { | |
833 | // default to the first icon even if not of the preferred type | |
834 | if (i == 0) { | |
835 | icon = widget.icons[0].relocated_src; | |
836 | //original = widget.icons[0].original; | |
837 | // alert("choosing default icon " + icon); | |
838 | } | |
839 | // check for preferred type | |
840 | if (widget.icons[i].relocated_src.indexOf(preferredIconType) > 0) { | |
841 | icon = widget.icons[i].relocated_src; | |
842 | //original = widget.icons[i].original; | |
843 | break; | |
844 | } | |
845 | } | |
846 | var shortName = widget.shortName; | |
847 | if (typeof shortName == 'undefined') { | |
848 | shortName = widget.name.substring(0, 9); | |
849 | } | |
850 | createIconSVGdecoration(previousIcon, widget, (((position % iconNbHoriz) * 80) + ((80 * (position - (position % iconsPerPage))) / iconNbVert)), | |
851 | ((((position % iconsPerPage) - (position % iconNbHoriz)) / iconNbHoriz) * 80), "icons", icon, | |
852 | shortName, widgetIndex); | |
853 | } | |
854 | ||
855 | /*function restoreFragmentOnURL(iconUrl, original) { | |
856 | var l = original.indexOf('#'); | |
857 | if (l >= 0) { | |
858 | return iconUrl + original.substring(l); | |
859 | } | |
860 | return iconUrl; | |
861 | }*/ | |
862 | ||
863 | // constant | |
864 | // const corein = "urn:mpeg:mpegu:schema:widgets:core:in:2010"; | |
865 | ||
866 | // | |
867 | // commodity method to empty a list of children | |
868 | // | |
869 | function removeAllChildren(o) { | |
870 | if (o != null && o.hasChildNodes()) { | |
871 | while (o.childNodes.length >= 1) { | |
872 | o.removeChild(o.firstChild); | |
873 | } | |
874 | } | |
875 | } | |
876 | ||
877 | // | |
878 | // create the home page icon with all its behaviours | |
879 | // | |
880 | function createIconSVGdecoration(previousIcon, widget, x, y, fatherId, iconUrl, name, widIndex) { | |
881 | var g, g2; | |
882 | if (l_inf < log_level) { | |
883 | alert("[UI] createIconSVGdecoration " + iconUrl + " " + x + " " + y); | |
884 | } | |
885 | if (previousIcon != null) { | |
886 | g = previousIcon; | |
887 | } else { | |
888 | g = document.createElement("g"); | |
889 | document.getElementById(fatherId).appendChild(g); | |
890 | } | |
891 | g.setAttribute("transform", 'translate(' + x + ',' + y + ')'); | |
892 | if (previousIcon != null) { | |
893 | g2 = g.firstElementChild; | |
894 | } else { | |
895 | g2 = document.createElement("g"); | |
896 | g2.setAttribute("transform", 'translate(15,10)'); | |
897 | g.appendChild(g2); | |
898 | } | |
899 | if (iconUrl == null || iconUrl == "") { | |
900 | iconUrl = "icons/face-surprise.svg"; | |
901 | } | |
902 | // | |
903 | // process differently cases where widget.icon == widget.main | |
904 | // | |
905 | var container; | |
906 | if (sameFileIgnoringSVGView(iconUrl, widget.main) && widget.main.indexOf('.svg') >= 0) { | |
907 | // see if the animation already exists | |
908 | container = document.getElementById(name); | |
909 | if (container == null) { | |
910 | // if the animation does not exist yet, create it | |
911 | container = media('animation', iconUrl, 50, 50); | |
912 | // store the animation in the main defs | |
913 | document.getElementById("mainDefs").appendChild(container); | |
914 | container.setAttribute('id', name); | |
915 | } | |
916 | if (previousIcon == null) { | |
917 | // put the container in a use | |
918 | var use = document.createElement("use"); | |
919 | use.setAttribute('id', 'iconContainer' + name); | |
920 | use.setAttributeNS(xlinkns, 'href', '#' + name); | |
921 | g2.appendChild(use); | |
922 | } | |
923 | } else { | |
924 | if (previousIcon == null) { | |
925 | container = appropriateElementForMedia(iconUrl, 50, 50); | |
926 | container.setAttribute('id', name); | |
927 | g2.appendChild(container); | |
928 | } | |
929 | } | |
930 | if (previousIcon == null) { | |
931 | g2 = document.createElement("g"); | |
932 | g2.setAttribute("transform", 'translate(40,70)'); | |
933 | g.appendChild(g2); | |
934 | var anim = createtext(name, 'white', 0, 0, 14, 'Arial Unicode MS'); | |
935 | anim.setAttribute("text-anchor", "middle"); | |
936 | anim.setAttribute("display-align", "center"); | |
937 | g2.appendChild(anim); | |
938 | var rect = invisible_rect(80, 80); | |
939 | g.appendChild(rect); | |
940 | rect.addEventListener("click", csi(widget), false); | |
941 | } | |
942 | } | |
943 | ||
944 | function csi(widget) { | |
945 | return function(evt) { activating_widget(widget);}; | |
946 | } | |
947 | ||
948 | // | |
949 | // widget closing action (WM callback) | |
950 | // | |
951 | function widget_close(wid) { | |
952 | if (wid == null) { | |
953 | return; | |
954 | } | |
955 | if (l_inf <= log_level) { | |
956 | alert('[UI] widget_close:' + wid.name); | |
957 | } | |
958 | // maybe inform the widget that it is going to be deactivated | |
959 | WidgetManager.corein_message(wid, "deactivate"); | |
960 | var target = widgetContainer.firstElementChild; | |
961 | var i; | |
962 | for (i = 0; i < numActivatedWidgets; i++) { | |
963 | if (activatedWidgets[i] == wid) { | |
964 | break; | |
965 | } | |
966 | target = target.nextElementSibling; | |
967 | } | |
968 | if (target != null) { | |
969 | // move next widgets back one slot | |
970 | recurseMoveAfterDelete(target); | |
971 | // stop the subscene | |
972 | if (target.firstElementChild != null) { | |
973 | target.firstElementChild.setAttributeNS(xlinkns, "href", ""); | |
974 | } | |
975 | // end trying | |
976 | widgetContainer.removeChild(target); | |
977 | } | |
978 | wid.deactivate(); | |
979 | wid.activated = false; | |
980 | activatedWidgets.splice(i, 1); | |
981 | numActivatedWidgets--; | |
982 | whereW = (whereW >= i ? (whereW > 0 ? whereW - 1 : 0) : whereW); | |
983 | adjustWhereWidgets(false); | |
984 | // if no more widgets, go back to the icons | |
985 | if (numActivatedWidgets == 0) { | |
986 | state = 'home'; | |
987 | widgetContainer.setAttribute('display', 'none'); | |
988 | homepage.setAttribute('display', 'inline'); | |
989 | homebar.setAttribute('display', 'inline'); | |
990 | execbar.setAttribute('display', 'none'); | |
991 | arrows.setAttribute('display', 'inline'); | |
992 | arrowsW.setAttribute('display', 'none'); | |
993 | widgetAddList.setAttribute('display', 'none'); | |
994 | } | |
995 | if (!wid.permanent) { | |
996 | WidgetManager.unload(wid, false); | |
997 | } | |
998 | } | |
999 | ||
1000 | // | |
1001 | // widget unloading action (WM callback) | |
1002 | // | |
1003 | function widget_remove(wid) { | |
1004 | if (l_deb <= log_level) { | |
1005 | alert('[UI] widget_remove:' + wid.name); | |
1006 | } | |
1007 | widget_close(wid); | |
1008 | WidgetManager.unload(wid, false); | |
1009 | } | |
1010 | ||
1011 | // | |
1012 | // widget launcher action | |
1013 | // | |
1014 | function widget_launch(wid, scene_container) { | |
1015 | if (l_inf <= log_level) { | |
1016 | alert('[UI] widget_launch:' + wid.name); | |
1017 | } | |
1018 | var tmp = document.createElement("g"); | |
1019 | tmp.setAttribute("transform", "translate(" + (totalWidth * numActivatedWidgets) + ", 0)"); | |
1020 | widgetContainer.appendChild(tmp); | |
1021 | var icon = null; | |
1022 | alert("wid: " + wid.name + "|" + wid.shortName); | |
1023 | if (typeof wid.shortName != 'undefined') { | |
1024 | var container = document.getElementById(wid.shortName); | |
1025 | if (container != null) { | |
1026 | icon = container.getAttributeNS(xlinkns, 'href'); | |
1027 | } | |
1028 | } | |
1029 | if (icon != null && | |
1030 | sameFileIgnoringSVGView(icon, wid.main) && | |
1031 | endsWith(wid.main, '.svg')) { | |
1032 | // get the animation with id=shortName stored in mainDefs | |
1033 | scene_container = document.getElementById(wid.shortName); | |
1034 | // get the original use on it, used in the icon | |
1035 | var iconContainer = document.getElementById('iconContainer' + wid.shortName); | |
1036 | // create a new use | |
1037 | var use = document.createElement('use'); | |
1038 | // point to the animation | |
1039 | use.setAttributeNS(xlinkns, 'href', '#' + wid.shortName); | |
1040 | // resize the animation | |
1041 | scene_container.setAttribute("width", totalWidth); | |
1042 | scene_container.setAttribute("height", totalHeight - 120); | |
1043 | // resize the original use //TODO fix the aspect ratio conservation | |
1044 | var m, t = Math.abs(totalHeight - 120 - totalWidth) / 2; | |
1045 | if (totalWidth > totalHeight - 120) { | |
1046 | m = 50 / (totalHeight - 120); | |
1047 | iconContainer.setAttribute('transform', 'scale(' + m + ',' + m + ') translate(' + (-t) + ',0)'); | |
1048 | } else { | |
1049 | m = 50 / totalWidth; | |
1050 | iconContainer.setAttribute('transform', 'scale(' + m + ',' + m + ') translate(0,' + (-t) + ') '); | |
1051 | } | |
1052 | // add the new use as widget execution container | |
1053 | tmp.appendChild(use); | |
1054 | wid.activate(scene_container); | |
1055 | } else { | |
1056 | scene_container.setAttribute("width", totalWidth); | |
1057 | scene_container.setAttribute("height", totalHeight - 120); | |
1058 | tmp.appendChild(scene_container); | |
1059 | scene_container.setAttributeNS(xlinkns, 'href', wid.main); | |
1060 | wid.activate(scene_container); | |
1061 | } | |
1062 | wid.activated = true; | |
1063 | activatedWidgets.splice(numActivatedWidgets, 0, wid); | |
1064 | whereW = numActivatedWidgets; | |
1065 | numActivatedWidgets++; | |
1066 | adjustWhereWidgets(false); | |
1067 | wid.load_component = widget_load_component; | |
1068 | wid.permanent = true; | |
1069 | wid.on_load = function () { | |
1070 | WidgetManager.corein_message(this, 'setSize', 'width', totalWidth, 'height', totalHeight - 120, 'dpi', 96); | |
1071 | }; | |
1072 | // | |
1073 | if (log_level > l_inf) { | |
1074 | var i = 0; | |
1075 | alert(">>>>>>>>>>>>> " + wid.name + " interfaces:"); | |
1076 | for (; i < wid.num_interfaces; i++) { | |
1077 | alert("" + wid.get_interface(i).type); | |
1078 | } | |
1079 | } | |
1080 | // | |
1081 | } | |
1082 | ||
1083 | // | |
1084 | // widget load component (WM callback) | |
1085 | // | |
1086 | function widget_load_component(comp, is_unload) { | |
1087 | if (l_deb <= log_level) { | |
1088 | alert('[UI] widget_load_component:' + comp.name); | |
1089 | } | |
1090 | if (is_unload) { | |
1091 | widget_close(comp); | |
1092 | comp.parent = null; | |
1093 | } else { | |
1094 | widget_add(comp); | |
1095 | comp.permanent = false; | |
1096 | comp.parent = this; | |
1097 | } | |
1098 | } | |
1099 | ||
1100 | var upnp_renders = null, target_widgets = null; | |
1101 | ||
1102 | // | |
1103 | // widget remoting function | |
1104 | // | |
1105 | function on_widget_remote() { | |
1106 | if (WidgetManager.MPEGUStandardServiceProviders.length != 0 && numActivatedWidgets > 0) { | |
1107 | upnp_renders = selector_window(activatedWidgets[whereW]); | |
1108 | upnp_renders.on_select = function(item, wid) { | |
1109 | upnp_renders.unregister(root); | |
1110 | upnp_renders = null; | |
1111 | if (item == -1) { | |
1112 | return; | |
1113 | } | |
1114 | if (wid != null) { | |
1115 | alert("upnp_renders.on_select(" + item + "," + wid.name + ")"); | |
1116 | //WidgetManager.migrate_widget(UPnP.GetMediaRenderer(item), wid); | |
1117 | WidgetManager.migrate_widget(WidgetManager.get_mpegu_service_providers(item), wid); | |
1118 | widget_close(wid); | |
1119 | } | |
1120 | }; | |
1121 | upnp_renders.register(root); | |
1122 | } | |
1123 | } | |
1124 | ||
1125 | // | |
1126 | // creates the menu of available targets for pushing a widget elsewhere | |
1127 | // | |
1128 | function selector_window(widget) { | |
1129 | var i, count, render; | |
1130 | var selector = document.createElement('g'), obj, child; | |
1131 | selector.setAttribute('transform', 'translate(10,10)'); | |
1132 | count = WidgetManager.MPEGUStandardServiceProviders.length; | |
1133 | selector.appendChild(rect(0, 0, 300, 20 * (count + 1), 'white', 'black')); | |
1134 | for (i = 0; i < count; i++) { | |
1135 | render = WidgetManager.MPEGUStandardServiceProviders[i]; | |
1136 | obj = createtext(render.Name, 'black', 5, 17 + (20 * i), 15, 'sans-serif'); | |
1137 | obj.setAttribute('id', "selector" + i); | |
1138 | selector.appendChild(obj); | |
1139 | obj.addEventListener('mouseover', sw1("selector" + i), false); | |
1140 | obj.addEventListener('mouseout', sw2("selector" + i), false); | |
1141 | obj.addEventListener('click', sw3(i, widget), false); | |
1142 | } | |
1143 | obj = createtext('Cancel', 'rgb(0,0,120)', 55, 17 + (20 * i), 15, 'sans-serif'); | |
1144 | obj.setAttribute('id', "cancel"); | |
1145 | selector.appendChild(obj); | |
1146 | obj.addEventListener('mouseover', function(evt) { document.getElementById("cancel").setAttribute("fill", "red"); }, false); | |
1147 | obj.addEventListener('mouseout', function(evt) { document.getElementById("cancel").setAttribute("fill", "black"); }, false); | |
1148 | obj.addEventListener('click', function(evt) { upnp_renders.on_select(-1, null); }, false); | |
1149 | selector.register = function(disp) { | |
1150 | disp.appendChild(this); | |
1151 | }; | |
1152 | selector.unregister = function(disp) { | |
1153 | disp.removeChild(this); | |
1154 | }; | |
1155 | return selector; | |
1156 | } | |
1157 | ||
1158 | function sw1(s) { | |
1159 | return function(evt) { document.getElementById(s).setAttribute("fill", "blue"); }; | |
1160 | } | |
1161 | ||
1162 | function sw2(s) { | |
1163 | return function(evt) { document.getElementById(s).setAttribute("fill", "black"); }; | |
1164 | } | |
1165 | ||
1166 | function sw3(si, widget) { | |
1167 | return function(evt) { upnp_renders.on_select(si, widget); }; | |
1168 | } | |
1169 | ||
1170 | // | |
1171 | // when a widget is pushed to here, install the widget and execute it | |
1172 | // | |
1173 | function onMediaConnect(url, src_ip) { | |
1174 | if (l_inf <= log_level) { | |
1175 | alert('[UI] onMediaConnect :\"' + url + '\"'); | |
1176 | } | |
1177 | if (WidgetManager.probe(url)) { | |
1178 | var w = WidgetManager.open(url, src_ip); | |
1179 | if (w == null) { | |
338 | } | |
339 | } | |
340 | ||
341 | // constants | |
342 | var adjustFrom = "0,0"; | |
343 | var animDue = true; | |
344 | ||
345 | // | |
346 | // after each change of icon page, this function adjusts the visibility of arrows in the lower bar | |
347 | // | |
348 | function adjustwhere(animDue) { | |
349 | if (l_deb < log_level) { | |
350 | alert("[UI] adjust " + where + " 0 " + maxwhere); | |
351 | } | |
352 | document.getElementById("left").setAttribute("display", ((where > 0) ? "inline" : "none")); | |
353 | document.getElementById("right").setAttribute("display", ((where < maxwhere) ? "inline" : "none")); | |
354 | if (!animDue) { | |
355 | icons.setAttribute("transform", 'translate(' + (-80 * iconNbHoriz * where) + ',0)'); | |
356 | } else { | |
357 | var aw = document.createElement("animateTransform"); | |
358 | aw.setAttribute("attributeName", "transform"); | |
359 | aw.setAttribute("type", "translate"); | |
360 | //alert('time '+document.documentElement.getCurrentTime()); | |
361 | aw.setAttribute("begin", document.documentElement.getCurrentTime()); | |
362 | aw.setAttribute("dur", "1s"); | |
363 | aw.setAttribute("fill", "freeze"); | |
364 | aw.setAttributeNS(xlinkns, "href", "#icons"); | |
365 | aw.setAttribute("from", adjustFrom); | |
366 | aw.setAttribute("to", (-80 * iconNbHoriz * where) + ",0"); | |
367 | document.documentElement.appendChild(aw); | |
368 | } | |
369 | adjustFrom = (-80 * iconNbHoriz * where) + ",0"; | |
370 | } | |
371 | ||
372 | // | |
373 | // action of the left button on the lower bar | |
374 | // | |
375 | function left_button() { | |
376 | if (l_deb < log_level) { | |
377 | alert("[UI] left button " + where + " 0"); | |
378 | } | |
379 | if (where > 0) { | |
380 | where--; | |
381 | adjustwhere(true); | |
382 | } | |
383 | } | |
384 | ||
385 | // | |
386 | // action of the right button of the lower bar | |
387 | // | |
388 | function right_button() { | |
389 | if (l_deb < log_level) { | |
390 | alert("[UI] right button " + where + " " + maxwhere); | |
391 | } | |
392 | if (where < maxwhere) { | |
393 | where++; | |
394 | adjustwhere(true); | |
395 | } | |
396 | } | |
397 | ||
398 | var adjustFromW = "0,0"; | |
399 | var oldwhereW = -1; | |
400 | ||
401 | // | |
402 | // after each change of icon page, this function adjusts the visibility of arrows in the lower bar | |
403 | // | |
404 | function adjustWhereWidgets(animDue) { | |
405 | if (oldwhereW != whereW) { | |
406 | // hide oldwhereW | |
407 | if (oldwhereW >= 0 && activatedWidgets[oldwhereW] != null) { | |
408 | WidgetManager.corein_message(activatedWidgets[oldwhereW], "hide"); | |
409 | } | |
410 | } | |
411 | if (l_deb < log_level) { | |
412 | alert("[UI] adjustW " + whereW + " 0 " + (numActivatedWidgets - 1)); | |
413 | } | |
414 | document.getElementById("leftW").setAttribute("display", ((whereW > 0) ? "inline" : "none")); | |
415 | document.getElementById("rightW").setAttribute("display", ((whereW < (numActivatedWidgets - 1)) ? "inline" : "none")); | |
416 | if (!animDue) { | |
417 | widgetContainer.setAttribute("transform", "translate(" + (-totalWidth * whereW) + ",0)"); | |
418 | } else { | |
419 | var aw = document.createElement("animateTransform"); | |
420 | aw.setAttribute("attributeName", "transform"); | |
421 | aw.setAttribute("type", "translate"); | |
422 | aw.setAttribute("begin", document.documentElement.getCurrentTime()); | |
423 | aw.setAttribute("dur", "1s"); | |
424 | aw.setAttribute("fill", "freeze"); | |
425 | aw.setAttributeNS(xlinkns, "href", "#widget"); | |
426 | aw.setAttribute("from", adjustFromW); | |
427 | aw.setAttribute("to", (-totalWidth * whereW) + ",0"); | |
428 | document.documentElement.appendChild(aw); | |
429 | } | |
430 | adjustFromW = (-totalWidth * whereW) + ",0"; | |
431 | document.getElementById("widgetName").textContent = | |
432 | (whereW >= 0 && activatedWidgets[whereW] != null ? activatedWidgets[whereW].shortName : '-'); | |
433 | if (oldwhereW != whereW) { | |
434 | // show whereW | |
435 | if (whereW >= 0 && activatedWidgets[whereW] != null) { | |
436 | WidgetManager.corein_message(activatedWidgets[whereW], "show"); | |
437 | } | |
438 | oldwhereW = whereW; | |
439 | } | |
440 | } | |
441 | ||
442 | // | |
443 | // action of the left button on the lower bar | |
444 | // | |
445 | function left_buttonW() { | |
446 | if (l_deb < log_level) { | |
447 | alert("[UI] left button " + whereW); | |
448 | } | |
449 | if (whereW > 0) { | |
450 | whereW--; | |
451 | adjustWhereWidgets(animDue); | |
452 | } | |
453 | } | |
454 | ||
455 | // | |
456 | // action of the right button of the lower bar | |
457 | // | |
458 | function right_buttonW() { | |
459 | if (l_deb < log_level) { | |
460 | alert("[UI] right button " + whereW + " " + (numActivatedWidgets - 1)); | |
461 | } | |
462 | if (whereW < (numActivatedWidgets - 1)) { | |
463 | whereW++; | |
464 | adjustWhereWidgets(animDue); | |
465 | } | |
466 | } | |
467 | ||
468 | // | |
469 | // action of each icon, starting the matching widget | |
470 | // | |
471 | function activating_widget(w) { | |
472 | if (l_deb < log_level) { | |
473 | alert("[UI] activating widget: " + w.name); | |
474 | } | |
475 | widget_add(w); | |
476 | } | |
477 | ||
478 | // | |
479 | // main initialization function | |
480 | // init variables, then init the widget manager C code, then inits UPnP | |
481 | // | |
482 | function initialize() { | |
483 | if (l_deb < log_level) { | |
484 | alert("[UI] initialize"); | |
485 | } | |
486 | init = false; | |
487 | var display_width = parseInt(gpac.getOption('Widgets', 'LastWMWidth')); | |
488 | var display_height = parseInt(gpac.getOption('Widgets', 'LastWMHeight')); | |
489 | if (display_width && display_height) { | |
490 | gpac.set_size(display_width, display_height); | |
491 | } | |
492 | root = document.documentElement; | |
493 | homepage = document.getElementById('homepage'); | |
494 | homebar = document.getElementById('homebar'); | |
495 | execbar = document.getElementById('execbar'); | |
496 | arrows = document.getElementById('arrows'); | |
497 | arrowsW = document.getElementById('arrowsW'); | |
498 | icons = document.getElementById('icons'); | |
499 | widgetContainer = document.getElementById('widget'); | |
500 | widgetAddList = document.getElementById('widgetAddList'); | |
501 | /* Setup the GPAC Widget Manager - this will also scan the available widgets */ | |
502 | log_level = l_inf; | |
503 | widget_manager_init(); | |
504 | WidgetManager.on_widget_remove = widget_remove; | |
505 | WidgetManager.on_widget_add = widget_add; | |
506 | /* register the callback to be notified of incoming widgets */ | |
507 | has_upnp = (typeof UPnP != 'undefined'); | |
508 | if (has_upnp) { | |
509 | /* setting the callback to allow other devices to push their widgets */ | |
510 | UPnP.onMediaConnect = onMediaConnect; | |
511 | /* Tell GPAC that the calls to the main Renderer (like open, ...) must be forwared to this scene */ | |
512 | UPnP.BindRenderer(); | |
513 | } | |
514 | WidgetManager.coreOutShow = coreOutShowImplementation; | |
515 | WidgetManager.coreOutGetAttention = coreOutGetAttentionImplementation; | |
516 | WidgetManager.coreOutHide = coreOutHideImplementation; | |
517 | WidgetManager.coreOutRequestDeactivate = coreOutRequestDeactivateImplementation; | |
518 | WidgetManager.coreOutInstallWidget = coreOutInstallWidgetImplementation; | |
519 | WidgetManager.coreOutActivateTemporaryWidget = coreOutActivateTemporaryWidgetImplementation; | |
520 | WidgetManager.coreOutMigrateComponent = coreOutMigrateComponentImplementation; | |
521 | WidgetManager.coreOutRequestMigrationTargets = coreOutRequestMigrationTargetsImplementation; | |
522 | } | |
523 | ||
524 | // | |
525 | // implementation of core:out install widget | |
526 | // | |
527 | function coreOutInstallWidgetImplementation(wid, args) { | |
528 | var w = widgetInstall(args[0], true, false, wid); | |
529 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
530 | if (ifce != null) { | |
531 | wmjs_core_out_invoke_reply(coreOut.installWidgetMessage, ifce.get_message("installWidget"), | |
532 | wid, (w != null ? 1 : 0)); // send return code 1 = success | |
533 | } | |
534 | } | |
535 | ||
536 | // | |
537 | // implementation of core:out activate temporary widget | |
538 | // | |
539 | function coreOutActivateTemporaryWidgetImplementation(wid, args) { | |
540 | var w = widgetInstall(args[0], true, true, null); | |
541 | if (w != null) { | |
542 | activating_widget(w); | |
543 | } | |
544 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
545 | if (ifce != null) { | |
546 | wmjs_core_out_invoke_reply(coreOut.activateTemporaryWidgetMessage, ifce.get_message("activateTemporaryWidget"), | |
547 | wid, (w != null ? 1 : 0)); // send return code 1 = success | |
548 | } | |
549 | } | |
550 | ||
551 | // | |
552 | // implementation of core:out migrate component | |
553 | // | |
554 | function coreOutMigrateComponentImplementation(wid, args) { | |
555 | //alert("coreOutMigrateComponent "+wid.name+" "+args.length); | |
556 | var comp = wid.get_component(args[0], true); | |
557 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
558 | if (comp == null) { | |
559 | log(l_err, 'Component ' + args[0] + ' cannot be found in widget ' + wid.name); | |
560 | if (ifce != null) { | |
561 | wmjs_core_out_invoke_reply(coreOut.migrateComponentMessage, ifce.get_message("migrateComponent"), wid, 0); | |
562 | } | |
563 | return; | |
564 | } | |
565 | if (args.length > 1 && args[1] != null) { | |
566 | //WidgetManager.migrate_widget(UPnP.GetMediaRenderer(parseInt(args[1])), comp); | |
567 | WidgetManager.migrate_widget(WidgetManager.get_mpegu_service_providers(parseInt(args[1])), comp); | |
568 | widget_close(comp); | |
569 | } else { | |
570 | upnp_renders = selector_window(comp); | |
571 | upnp_renders.on_select = function(item, wid) { | |
572 | upnp_renders.unregister(root); | |
573 | upnp_renders = null; | |
574 | if (item == -1) { | |
1180 | 575 | return; |
1181 | 576 | } |
1182 | widget_add(w); | |
1183 | adjustWhereWidgets(false); | |
1184 | w.permanent = false; | |
1185 | } | |
1186 | } | |
1187 | ||
577 | if (comp != null) { | |
578 | alert("upnp_renders.on_select(" + item + "," + comp.name + ")"); | |
579 | //WidgetManager.migrate_widget(UPnP.GetMediaRenderer(item), comp); | |
580 | WidgetManager.migrate_widget(WidgetManager.get_mpegu_service_providers(item), comp); | |
581 | widget_close(comp); | |
582 | } | |
583 | }; | |
584 | upnp_renders.register(root); | |
585 | } | |
586 | if (ifce != null) { | |
587 | wmjs_core_out_invoke_reply(coreOut.migrateComponentMessage, ifce.get_message("migrateComponent"), wid, 1); // send return code 1 = success | |
588 | } | |
589 | } | |
590 | ||
591 | // | |
592 | // implementation of core:out request migration targets | |
593 | // | |
594 | function coreOutRequestMigrationTargetsImplementation(wid, args) { | |
595 | var count = UPnP.MediaRenderersCount, codes = new Array(), names = new Array(), descriptions = new Array(), i; | |
596 | for (i = 0; i < count; i++) { | |
597 | var render = UPnP.GetMediaRenderer(i); | |
598 | codes.push("" + i); | |
599 | names.push(render.Name); | |
600 | descriptions.push(render.HostName + " " + render.UUID); | |
601 | } | |
602 | i = null; | |
603 | var ifce_count = wid.num_interfaces, j; | |
604 | for (j = 0; j < ifce_count; j++) { | |
605 | var ifce = wid.get_interface(j); | |
606 | if (ifce.type == "urn:mpeg:mpegu:schema:widgets:core:out:2010") { | |
607 | i = ifce; | |
608 | break; | |
609 | } | |
610 | } | |
611 | if (i != null) { | |
612 | wmjs_core_out_invoke_reply(coreOut.requestMigrationTargetsMessage, i.get_message("requestMigrationTargets"), | |
613 | wid, codes, names, descriptions); | |
614 | } | |
615 | } | |
616 | ||
617 | // | |
618 | // implementation of core:out Show message | |
619 | // this is a request by the widget to be shown | |
620 | // | |
621 | function coreOutShowImplementation(wid, args) { | |
622 | //alert("core:out show "+wid.name); | |
623 | var target = widgetContainer.firstElementChild; | |
624 | var i; | |
625 | for (i = 0; i < numActivatedWidgets; i++) { | |
626 | //alert("is it "+activatedWidgets[i].name); | |
627 | if (activatedWidgets[i] == wid) { | |
628 | break; | |
629 | } | |
630 | target = target.nextElementSibling; | |
631 | } | |
632 | // here, i is the index of the current widget | |
633 | //alert(" "+i+" "+numActivatedWidgets); | |
634 | if (i < numActivatedWidgets) { | |
635 | whereW = i; | |
636 | adjustWhereWidgets(false); | |
637 | } | |
638 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
639 | if (ifce != null) { | |
640 | wmjs_core_out_invoke_reply(coreOut.showMessage, ifce.get_message("show"), wid, 1); // send return code 1 = success | |
641 | } | |
642 | } | |
643 | ||
644 | // | |
645 | // implementation of core:out GetAttention message | |
646 | // this is a request by the widget to be shown and some special signal is given | |
647 | // | |
648 | function coreOutGetAttentionImplementation(wid, args) { | |
649 | //alert("core:out getAttention "+wid.name); | |
650 | var target = widgetContainer.firstElementChild; | |
651 | var i; | |
652 | for (i = 0; i < numActivatedWidgets; i++) { | |
653 | //alert("is it "+activatedWidgets[i].name); | |
654 | if (activatedWidgets[i] == wid) { | |
655 | break; | |
656 | } | |
657 | target = target.nextElementSibling; | |
658 | } | |
659 | // here, i is the index of the current widget | |
660 | //alert(" "+i+" "+numActivatedWidgets); | |
661 | if (i < numActivatedWidgets) { | |
662 | whereW = i; | |
663 | adjustWhereWidgets(false); | |
664 | } | |
665 | document.getElementById("getAttention").beginElement(); | |
666 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
667 | if (ifce != null) { | |
668 | wmjs_core_out_invoke_reply(coreOut.getAttentionMessage, ifce.get_message("getAttention"), wid, 1); // send return code 1 = success | |
669 | } | |
670 | } | |
671 | ||
672 | // | |
673 | // implementation of core:out hide message | |
674 | // this is a request by the widget to be hidden (some other widget (if any) is shown) | |
675 | // | |
676 | function coreOutHideImplementation(wid, args) { | |
677 | //alert("core:out hide "+wid.name); | |
678 | var target = widgetContainer.firstElementChild; | |
679 | var i; | |
680 | for (i = 0; i < numActivatedWidgets; i++) { | |
681 | //alert("is it "+activatedWidgets[i].name); | |
682 | if (activatedWidgets[i] == wid) { | |
683 | break; | |
684 | } | |
685 | target = target.nextElementSibling; | |
686 | } | |
687 | // here, i is the index of the current widget | |
688 | //alert("hide "+i+" "+numActivatedWidgets); | |
689 | if (i < numActivatedWidgets) { | |
690 | if (whereW > 0) { | |
691 | whereW--; | |
692 | } | |
693 | else if (whereW < numActivatedWidgets - 1) { | |
694 | whereW++; | |
695 | } | |
696 | else { | |
697 | return; | |
698 | } | |
699 | adjustWhereWidgets(false); | |
700 | } | |
701 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
702 | if (ifce != null) { | |
703 | wmjs_core_out_invoke_reply(coreOut.hideMessage, ifce.get_message("hide"), wid, 1); // send return code 1 = success | |
704 | } | |
705 | } | |
706 | ||
707 | // | |
708 | // implementation of core:out requestDeactivate message | |
709 | // this is a request by the widget to be stopped | |
710 | // | |
711 | function coreOutRequestDeactivateImplementation(wid, args) { | |
712 | //alert("core:out hide "+wid.name); | |
713 | var target = widgetContainer.firstElementChild; | |
714 | var i; | |
715 | for (i = 0; i < numActivatedWidgets; i++) { | |
716 | //alert("is it "+activatedWidgets[i].name); | |
717 | if (activatedWidgets[i] == wid) { | |
718 | break; | |
719 | } | |
720 | target = target.nextElementSibling; | |
721 | } | |
722 | // here, i is the index of the current widget | |
723 | //alert("hide "+i+" "+numActivatedWidgets); | |
724 | if (i < numActivatedWidgets) { | |
725 | widget_close(activatedWidgets[i]); | |
726 | } | |
727 | var ifce = getInterfaceByType(wid, "urn:mpeg:mpegu:schema:widgets:core:out:2010"); | |
728 | if (ifce != null) { | |
729 | wmjs_core_out_invoke_reply(coreOut.requestDeactivateMessage, ifce.get_message("requestDeactivate"), wid, 1); // send return code 1 = success | |
730 | } | |
731 | } | |
732 | ||
733 | // | |
734 | // WM callback for when a component is activated by its parent | |
735 | // | |
736 | function widget_add(w) { | |
737 | log(l_inf, "widget add " + w.name); | |
738 | if (!w.activated) { | |
739 | if (sameFileIgnoringSVGView(w.icon, w.main)) { | |
740 | // same file in icon and main | |
741 | } else { | |
742 | widget_launch(w, document.createElement("animation")); | |
743 | } | |
744 | } else if (w.multipleInstances) { | |
745 | var newwid = WidgetManager.open(w.manifest, null); | |
746 | widget_launch(newwid, document.createElement("animation")); | |
747 | } else { | |
748 | return false; | |
749 | } | |
750 | state = 'exec'; | |
751 | widgetContainer.setAttribute('display', 'inline'); | |
752 | homepage.setAttribute('display', 'none'); | |
753 | homebar.setAttribute('display', 'none'); | |
754 | execbar.setAttribute('display', 'inline'); | |
755 | arrows.setAttribute('display', 'none'); | |
756 | arrowsW.setAttribute('display', 'inline'); | |
757 | widgetAddList.setAttribute('display', 'none'); | |
758 | return true; | |
759 | } | |
760 | ||
761 | function sameFileIgnoringSVGView(name1, name2) { | |
762 | if (name1 == name2) { | |
763 | return true; | |
764 | } | |
765 | if (name1 == null) { | |
766 | return false; | |
767 | } | |
768 | var i1 = name1.indexOf("#"); | |
769 | var i2 = name2.indexOf("#"); | |
770 | if (i1 < 0) { | |
771 | i1 = name1.length; | |
772 | } | |
773 | else { | |
774 | i1--; | |
775 | } | |
776 | if (i2 < 0) { | |
777 | i2 = name2.length; | |
778 | } | |
779 | else { | |
780 | i2--; | |
781 | } | |
782 | return name1.substring(0, i1) == name2.substring(0, i2); | |
783 | } | |
784 | ||
785 | // | |
786 | // recompute the number of widgets loaded currently | |
787 | // | |
788 | function getNbWidgets() { | |
789 | var i, nbWidgets = 0; | |
790 | for (i = 0; i < WidgetManager.num_widgets; i++) { | |
791 | var w = WidgetManager.get(i); | |
792 | if (w != null && w.loaded) { | |
793 | nbWidgets++; | |
794 | } | |
795 | } | |
796 | return nbWidgets; | |
797 | } | |
798 | ||
799 | // | |
800 | // just resize the window and viewport, and initialize the first time this is called | |
801 | // | |
802 | function resize() { | |
803 | if (init) { | |
804 | initialize(); | |
805 | } | |
806 | if (document.documentElement.viewport.width == previousWidth && document.documentElement.viewport.height == previousHeight) { | |
807 | return; | |
808 | } | |
809 | if (l_deb < log_level) { | |
810 | alert("[UI] start initialize() w:" + document.documentElement.viewport.width + " h:" + document.documentElement.viewport.height); | |
811 | } | |
812 | adaptLayoutToSize(); | |
813 | // start by filling the "home page" with known icons | |
814 | where = 0; | |
815 | var nbWidgets = getNbWidgets(); | |
816 | maxwhere = ((nbWidgets - 1) - ((nbWidgets - 1) % iconsPerPage)) / iconsPerPage; | |
817 | var wid; | |
818 | var iconIterator = document.getElementById("icons").firstElementChild; | |
819 | var position = 0; | |
820 | for (i = 1; i <= WidgetManager.num_widgets; i++) { | |
821 | wid = WidgetManager.get(i - 1); | |
822 | // alert("build:"+wid.main+" "+wid.loaded); | |
823 | if (wid.loaded) { | |
824 | insert_icon(wid, position, i - 1, iconIterator); | |
825 | WidgetManager.corein_message(wid, 'setSize', 'width', totalWidth, 'height', totalHeight - 120, 'dpi', 96); | |
826 | position++; | |
827 | if (iconIterator != null) { | |
828 | iconIterator = iconIterator.nextElementSibling; | |
829 | } | |
830 | } | |
831 | } | |
832 | adjustwhere(false); | |
833 | adjustWhereWidgets(false); | |
834 | previousWidth = document.documentElement.viewport.width; | |
835 | previousHeight = document.documentElement.viewport.height; | |
836 | gpac.setOption("Widgets", "LastWMWidth", '' + previousWidth); | |
837 | gpac.setOption("Widgets", "LastWMHeight", '' + previousHeight); | |
838 | } | |
839 | ||
840 | // | |
841 | // function inserting an icon on the home page | |
842 | // | |
843 | function insert_icon(widget, position, widgetIndex, previousIcon) { | |
844 | if (l_deb < log_level) { | |
845 | alert("[UI] insert_icon: " + widget.shortName + " " + position + " " + widgetIndex + " WMnw:" + WidgetManager.num_widgets); | |
846 | } | |
847 | widget.loaded = true; | |
848 | if (l_deb < log_level) { | |
849 | alert("[UI] widget name: " + widget.name); | |
850 | } | |
851 | var icon = null, original = null; | |
852 | for (var i = 0; i < widget.icons.length; i++) { | |
853 | // default to the first icon even if not of the preferred type | |
854 | if (i == 0) { | |
855 | icon = widget.icons[0].relocated_src; | |
856 | //original = widget.icons[0].original; | |
857 | // alert("choosing default icon " + icon); | |
858 | } | |
859 | // check for preferred type | |
860 | if (widget.icons[i].relocated_src.indexOf(preferredIconType) > 0) { | |
861 | icon = widget.icons[i].relocated_src; | |
862 | //original = widget.icons[i].original; | |
863 | break; | |
864 | } | |
865 | } | |
866 | var shortName = widget.shortName; | |
867 | if (typeof shortName == 'undefined') { | |
868 | shortName = widget.name.substring(0, 9); | |
869 | } | |
870 | createIconSVGdecoration(previousIcon, widget, (((position % iconNbHoriz) * 80) + ((80 * (position - (position % iconsPerPage))) / iconNbVert)), | |
871 | ((((position % iconsPerPage) - (position % iconNbHoriz)) / iconNbHoriz) * 80), "icons", icon, | |
872 | shortName, widgetIndex); | |
873 | } | |
874 | ||
875 | // constant | |
876 | // const corein = "urn:mpeg:mpegu:schema:widgets:core:in:2010"; | |
877 | ||
878 | // | |
879 | // commodity method to empty a list of children | |
880 | // | |
881 | function removeAllChildren(o) { | |
882 | if (o != null && o.hasChildNodes()) { | |
883 | while (o.childNodes.length >= 1) { | |
884 | o.removeChild(o.firstChild); | |
885 | } | |
886 | } | |
887 | } | |
888 | ||
889 | // | |
890 | // create the home page icon with all its behaviours | |
891 | // | |
892 | function createIconSVGdecoration(previousIcon, widget, x, y, fatherId, iconUrl, name, widIndex) { | |
893 | var g, g2; | |
894 | if (l_inf < log_level) { | |
895 | alert("[UI] createIconSVGdecoration " + iconUrl + " " + x + " " + y); | |
896 | } | |
897 | if (previousIcon != null) { | |
898 | g = previousIcon; | |
899 | } else { | |
900 | g = document.createElement("g"); | |
901 | document.getElementById(fatherId).appendChild(g); | |
902 | } | |
903 | g.setAttribute("transform", 'translate(' + x + ',' + y + ')'); | |
904 | if (previousIcon != null) { | |
905 | g2 = g.firstElementChild; | |
906 | } else { | |
907 | g2 = document.createElement("g"); | |
908 | g2.setAttribute("transform", 'translate(15,10)'); | |
909 | g.appendChild(g2); | |
910 | } | |
911 | if (iconUrl == null || iconUrl == "") { | |
912 | iconUrl = "icons/face-surprise.svg"; | |
913 | } | |
1188 | 914 | // |
1189 | // file list vars | |
915 | // process differently cases where widget.icon == widget.main | |
1190 | 916 | // |
1191 | var flstart = 0,fllist = null,maxFileNames = 14; | |
1192 | ||
1193 | // | |
1194 | // create a file menu in the main screen, allowing to navigate directories and choose widget config files | |
1195 | // | |
1196 | function on_widget_add_menu() { | |
1197 | state = 'list'; | |
1198 | widgetContainer.setAttribute('display', 'none'); | |
1199 | homepage.setAttribute('display', 'none'); | |
1200 | homebar.setAttribute('display', 'none'); | |
1201 | execbar.setAttribute('display', 'inline'); | |
1202 | arrows.setAttribute('display', 'none'); | |
1203 | arrowsW.setAttribute('display', 'none'); | |
1204 | widgetAddList.setAttribute('display', 'inline'); | |
1205 | maxFileNames = Math.round(((iconNbVert * 80) / 25) - 1.4); | |
1206 | isThisAScan = false; | |
1207 | refillWidgetAddList(false); | |
1208 | } | |
1209 | ||
1210 | // | |
1211 | // create a file menu in the main screen, allowing to navigate directories and choose a directory to scan for widgets | |
1212 | // and load all their icons | |
1213 | // | |
1214 | function on_dir_scan() { | |
1215 | state = 'list'; | |
1216 | widgetContainer.setAttribute('display', 'none'); | |
1217 | homepage.setAttribute('display', 'none'); | |
1218 | homebar.setAttribute('display', 'none'); | |
1219 | execbar.setAttribute('display', 'inline'); | |
1220 | arrows.setAttribute('display', 'none'); | |
1221 | arrowsW.setAttribute('display', 'none'); | |
1222 | widgetAddList.setAttribute('display', 'inline'); | |
1223 | maxFileNames = Math.round(((iconNbVert * 80) / 25) - 1.4); | |
1224 | isThisAScan = true; | |
1225 | refillWidgetAddList(true); | |
1226 | } | |
1227 | ||
1228 | // | |
1229 | // remove all installed icons | |
1230 | // | |
1231 | function on_clean_up() { | |
1232 | var i; | |
1233 | //if (l_inf <= log_level) alert('[UI] unloading ' + WidgetManager.num_widgets + ' widgets'); | |
1234 | for (i = WidgetManager.num_widgets - 1; i >= 0; i--) { | |
1235 | var w = WidgetManager.get(i); | |
1236 | if (w.loaded) { | |
1237 | alert("unloading " + w.name); | |
1238 | w.loaded = false; | |
1239 | WidgetManager.unload(w, false); | |
1240 | } | |
1241 | } | |
1242 | where = 0; | |
1243 | maxwhere = 0; | |
1244 | removeAllChildren(document.getElementById("icons")); | |
1245 | adjustwhere(false); | |
1246 | } | |
1247 | ||
1248 | // | |
1249 | // install, but do not launch, the widget whose config.xml has been chosen, and return to the home page | |
1250 | // | |
1251 | function widgetInstall(uri, manual, temporary, parent_wid) { | |
1252 | var wid, j, count = WidgetManager.num_widgets, nbWidgets = getNbWidgets(); | |
1253 | for (j = 0; j < count; j++) { | |
1254 | wid = WidgetManager.get(j); | |
1255 | if (wid.url == uri) { | |
1256 | if (wid.loaded) { | |
1257 | break; | |
1258 | } | |
1259 | if (temporary) { | |
1260 | wid.permanent = false; | |
1261 | } | |
1262 | else { | |
1263 | insert_icon(wid, nbWidgets, nbWidgets); | |
1264 | } | |
1265 | } | |
1266 | } | |
1267 | if (j == count) { | |
1268 | wid = WidgetManager.open(uri, null, parent_wid); | |
1269 | if (wid != null) { | |
1270 | if (temporary) { | |
1271 | wid.permanent = false; | |
1272 | } | |
1273 | else { | |
1274 | insert_icon(wid, nbWidgets, nbWidgets); | |
1275 | } | |
1276 | } | |
1277 | } | |
1278 | if (manual) { | |
1279 | return wid; | |
1280 | } | |
917 | var container; | |
918 | if (sameFileIgnoringSVGView(iconUrl, widget.main) && widget.main.indexOf('.svg') >= 0) { | |
919 | // see if the animation already exists | |
920 | container = document.getElementById(name); | |
921 | if (container == null) { | |
922 | // if the animation does not exist yet, create it | |
923 | container = media('animation', iconUrl, 50, 50); | |
924 | // store the animation in the main defs | |
925 | document.getElementById("mainDefs").appendChild(container); | |
926 | container.setAttribute('id', name); | |
927 | } | |
928 | if (previousIcon == null) { | |
929 | // put the container in a use | |
930 | var use = document.createElement("use"); | |
931 | use.setAttribute('id', 'iconContainer' + name); | |
932 | use.setAttributeNS(xlinkns, 'href', '#' + name); | |
933 | g2.appendChild(use); | |
934 | } | |
935 | } else { | |
936 | if (previousIcon == null) { | |
937 | container = appropriateElementForMedia(iconUrl, 50, 50); | |
938 | container.setAttribute('id', name); | |
939 | g2.appendChild(container); | |
940 | } | |
941 | } | |
942 | if (previousIcon == null) { | |
943 | g2 = document.createElement("g"); | |
944 | g2.setAttribute("transform", 'translate(40,70)'); | |
945 | g.appendChild(g2); | |
946 | var anim = createtext(name, 'white', 0, 0, 14, 'Arial Unicode MS'); | |
947 | anim.setAttribute("text-anchor", "middle"); | |
948 | anim.setAttribute("display-align", "center"); | |
949 | g2.appendChild(anim); | |
950 | var rect = invisible_rect(80, 80); | |
951 | g.appendChild(rect); | |
952 | rect.addEventListener("click", csi(widget), false); | |
953 | } | |
954 | } | |
955 | ||
956 | function csi(widget) { | |
957 | return function(evt) { activating_widget(widget);}; | |
958 | } | |
959 | ||
960 | // | |
961 | // widget closing action (WM callback) | |
962 | // | |
963 | function widget_close(wid) { | |
964 | if (wid == null) { | |
965 | return; | |
966 | } | |
967 | if (l_inf <= log_level) { | |
968 | alert('[UI] widget_close:' + wid.name); | |
969 | } | |
970 | // maybe inform the widget that it is going to be deactivated | |
971 | WidgetManager.corein_message(wid, "deactivate"); | |
972 | var target = widgetContainer.firstElementChild; | |
973 | var i; | |
974 | for (i = 0; i < numActivatedWidgets; i++) { | |
975 | if (activatedWidgets[i] == wid) { | |
976 | break; | |
977 | } | |
978 | target = target.nextElementSibling; | |
979 | } | |
980 | if (target != null) { | |
981 | // move next widgets back one slot | |
982 | recurseMoveAfterDelete(target); | |
983 | // stop the subscene | |
984 | if (target.firstElementChild != null) { | |
985 | target.firstElementChild.setAttributeNS(xlinkns, "href", ""); | |
986 | } | |
987 | // end trying | |
988 | widgetContainer.removeChild(target); | |
989 | } | |
990 | wid.deactivate(); | |
991 | wid.activated = false; | |
992 | activatedWidgets.splice(i, 1); | |
993 | numActivatedWidgets--; | |
994 | whereW = (whereW >= i ? (whereW > 0 ? whereW - 1 : 0) : whereW); | |
995 | adjustWhereWidgets(false); | |
996 | // if no more widgets, go back to the icons | |
997 | if (numActivatedWidgets == 0) { | |
1281 | 998 | state = 'home'; |
1282 | 999 | widgetContainer.setAttribute('display', 'none'); |
1283 | 1000 | homepage.setAttribute('display', 'inline'); |
1285 | 1002 | execbar.setAttribute('display', 'none'); |
1286 | 1003 | arrows.setAttribute('display', 'inline'); |
1287 | 1004 | arrowsW.setAttribute('display', 'none'); |
1288 | removeAllChildren(widgetAddList); | |
1289 | maxwhere = ((nbWidgets - 1) - ((nbWidgets - 1) % iconsPerPage)) / iconsPerPage; | |
1290 | where = maxwhere; | |
1291 | adjustwhere(false); | |
1005 | widgetAddList.setAttribute('display', 'none'); | |
1006 | } | |
1007 | if (!wid.permanent) { | |
1008 | WidgetManager.unload(wid, false); | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | // | |
1013 | // widget unloading action (WM callback) | |
1014 | // | |
1015 | function widget_remove(wid) { | |
1016 | if (l_deb <= log_level) { | |
1017 | alert('[UI] widget_remove:' + wid.name); | |
1018 | } | |
1019 | widget_close(wid); | |
1020 | WidgetManager.unload(wid, false); | |
1021 | } | |
1022 | ||
1023 | // | |
1024 | // widget launcher action | |
1025 | // | |
1026 | function widget_launch(wid, scene_container) { | |
1027 | if (l_inf <= log_level) { | |
1028 | alert('[UI] widget_launch:' + wid.name); | |
1029 | } | |
1030 | var tmp = document.createElement("g"); | |
1031 | tmp.setAttribute("transform", "translate(" + (totalWidth * numActivatedWidgets) + ", 0)"); | |
1032 | widgetContainer.appendChild(tmp); | |
1033 | var icon = null; | |
1034 | alert("wid: " + wid.name + "|" + wid.shortName); | |
1035 | if (typeof wid.shortName != 'undefined') { | |
1036 | var container = document.getElementById(wid.shortName); | |
1037 | if (container != null) { | |
1038 | icon = container.getAttributeNS(xlinkns, 'href'); | |
1039 | } | |
1040 | } | |
1041 | if (icon != null && | |
1042 | sameFileIgnoringSVGView(icon, wid.main) && | |
1043 | endsWith(wid.main, '.svg')) { | |
1044 | // get the animation with id=shortName stored in mainDefs | |
1045 | scene_container = document.getElementById(wid.shortName); | |
1046 | // get the original use on it, used in the icon | |
1047 | var iconContainer = document.getElementById('iconContainer' + wid.shortName); | |
1048 | // create a new use | |
1049 | var use = document.createElement('use'); | |
1050 | // point to the animation | |
1051 | use.setAttributeNS(xlinkns, 'href', '#' + wid.shortName); | |
1052 | // resize the animation | |
1053 | scene_container.setAttribute("width", totalWidth); | |
1054 | scene_container.setAttribute("height", totalHeight - 120); | |
1055 | // resize the original use | |
1056 | //should do: fix the aspect ratio conservation | |
1057 | var m, t = Math.abs(totalHeight - 120 - totalWidth) / 2; | |
1058 | if (totalWidth > totalHeight - 120) { | |
1059 | m = 50 / (totalHeight - 120); | |
1060 | iconContainer.setAttribute('transform', 'scale(' + m + ',' + m + ') translate(' + (-t) + ',0)'); | |
1061 | } else { | |
1062 | m = 50 / totalWidth; | |
1063 | iconContainer.setAttribute('transform', 'scale(' + m + ',' + m + ') translate(0,' + (-t) + ') '); | |
1064 | } | |
1065 | // add the new use as widget execution container | |
1066 | tmp.appendChild(use); | |
1067 | wid.activate(scene_container); | |
1068 | } else { | |
1069 | scene_container.setAttribute("width", totalWidth); | |
1070 | scene_container.setAttribute("height", totalHeight - 120); | |
1071 | tmp.appendChild(scene_container); | |
1072 | scene_container.setAttributeNS(xlinkns, 'href', wid.main); | |
1073 | wid.activate(scene_container); | |
1074 | } | |
1075 | wid.activated = true; | |
1076 | activatedWidgets.splice(numActivatedWidgets, 0, wid); | |
1077 | whereW = numActivatedWidgets; | |
1078 | numActivatedWidgets++; | |
1079 | adjustWhereWidgets(false); | |
1080 | wid.load_component = widget_load_component; | |
1081 | wid.permanent = true; | |
1082 | wid.on_load = function () { | |
1083 | WidgetManager.corein_message(this, 'setSize', 'width', totalWidth, 'height', totalHeight - 120, 'dpi', 96); | |
1084 | }; | |
1085 | // | |
1086 | if (log_level > l_inf) { | |
1087 | var i = 0; | |
1088 | alert(">>>>>>>>>>>>> " + wid.name + " interfaces:"); | |
1089 | for (; i < wid.num_interfaces; i++) { | |
1090 | alert("" + wid.get_interface(i).type); | |
1091 | } | |
1092 | } | |
1093 | // | |
1094 | } | |
1095 | ||
1096 | // | |
1097 | // widget load component (WM callback) | |
1098 | // | |
1099 | function widget_load_component(comp, is_unload) { | |
1100 | if (l_deb <= log_level) { | |
1101 | alert('[UI] widget_load_component:' + comp.name); | |
1102 | } | |
1103 | if (is_unload) { | |
1104 | widget_close(comp); | |
1105 | comp.parent = null; | |
1106 | } else { | |
1107 | widget_add(comp); | |
1108 | comp.permanent = false; | |
1109 | comp.parent = this; | |
1110 | } | |
1111 | } | |
1112 | ||
1113 | var upnp_renders = null, target_widgets = null; | |
1114 | ||
1115 | // | |
1116 | // widget remoting function | |
1117 | // | |
1118 | function on_widget_remote() { | |
1119 | if (WidgetManager.MPEGUStandardServiceProviders.length != 0 && numActivatedWidgets > 0) { | |
1120 | upnp_renders = selector_window(activatedWidgets[whereW]); | |
1121 | upnp_renders.on_select = function(item, wid) { | |
1122 | upnp_renders.unregister(root); | |
1123 | upnp_renders = null; | |
1124 | if (item == -1) { | |
1125 | return; | |
1126 | } | |
1127 | if (wid != null) { | |
1128 | alert("upnp_renders.on_select(" + item + "," + wid.name + ")"); | |
1129 | //WidgetManager.migrate_widget(UPnP.GetMediaRenderer(item), wid); | |
1130 | WidgetManager.migrate_widget(WidgetManager.get_mpegu_service_providers(item), wid); | |
1131 | widget_close(wid); | |
1132 | } | |
1133 | }; | |
1134 | upnp_renders.register(root); | |
1135 | } | |
1136 | } | |
1137 | ||
1138 | // | |
1139 | // creates the menu of available targets for pushing a widget elsewhere | |
1140 | // | |
1141 | function selector_window(widget) { | |
1142 | var i, count, render; | |
1143 | var selector = document.createElement('g'), obj, child; | |
1144 | selector.setAttribute('transform', 'translate(10,10)'); | |
1145 | count = WidgetManager.MPEGUStandardServiceProviders.length; | |
1146 | selector.appendChild(rect(0, 0, 300, 20 * (count + 1), 'white', 'black')); | |
1147 | for (i = 0; i < count; i++) { | |
1148 | render = WidgetManager.MPEGUStandardServiceProviders[i]; | |
1149 | obj = createtext(render.Name, 'black', 5, 17 + (20 * i), 15, 'sans-serif'); | |
1150 | obj.setAttribute('id', "selector" + i); | |
1151 | selector.appendChild(obj); | |
1152 | obj.addEventListener('mouseover', sw1("selector" + i), false); | |
1153 | obj.addEventListener('mouseout', sw2("selector" + i), false); | |
1154 | obj.addEventListener('click', sw3(i, widget), false); | |
1155 | } | |
1156 | obj = createtext('Cancel', 'rgb(0,0,120)', 55, 17 + (20 * i), 15, 'sans-serif'); | |
1157 | obj.setAttribute('id', "cancel"); | |
1158 | selector.appendChild(obj); | |
1159 | obj.addEventListener('mouseover', function(evt) { document.getElementById("cancel").setAttribute("fill", "red"); }, false); | |
1160 | obj.addEventListener('mouseout', function(evt) { document.getElementById("cancel").setAttribute("fill", "black"); }, false); | |
1161 | obj.addEventListener('click', function(evt) { upnp_renders.on_select(-1, null); }, false); | |
1162 | selector.register = function(disp) { | |
1163 | disp.appendChild(this); | |
1164 | }; | |
1165 | selector.unregister = function(disp) { | |
1166 | disp.removeChild(this); | |
1167 | }; | |
1168 | return selector; | |
1169 | } | |
1170 | ||
1171 | function sw1(s) { | |
1172 | return function(evt) { document.getElementById(s).setAttribute("fill", "blue"); }; | |
1173 | } | |
1174 | ||
1175 | function sw2(s) { | |
1176 | return function(evt) { document.getElementById(s).setAttribute("fill", "black"); }; | |
1177 | } | |
1178 | ||
1179 | function sw3(si, widget) { | |
1180 | return function(evt) { upnp_renders.on_select(si, widget); }; | |
1181 | } | |
1182 | ||
1183 | // | |
1184 | // when a widget is pushed to here, install the widget and execute it | |
1185 | // | |
1186 | function onMediaConnect(url, src_ip) { | |
1187 | if (l_inf <= log_level) { | |
1188 | alert('[UI] onMediaConnect :\"' + url + '\"'); | |
1189 | } | |
1190 | if (WidgetManager.probe(url)) { | |
1191 | var w = WidgetManager.open(url, src_ip); | |
1192 | if (w == null) { | |
1193 | return; | |
1194 | } | |
1195 | widget_add(w); | |
1196 | adjustWhereWidgets(false); | |
1197 | w.permanent = false; | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | // | |
1202 | // file list vars | |
1203 | // | |
1204 | var flstart = 0,fllist = null,maxFileNames = 14; | |
1205 | ||
1206 | // | |
1207 | // create a file menu in the main screen, allowing to navigate directories and choose widget config files | |
1208 | // | |
1209 | function on_widget_add_menu() { | |
1210 | state = 'list'; | |
1211 | widgetContainer.setAttribute('display', 'none'); | |
1212 | homepage.setAttribute('display', 'none'); | |
1213 | homebar.setAttribute('display', 'none'); | |
1214 | execbar.setAttribute('display', 'inline'); | |
1215 | arrows.setAttribute('display', 'none'); | |
1216 | arrowsW.setAttribute('display', 'none'); | |
1217 | widgetAddList.setAttribute('display', 'inline'); | |
1218 | maxFileNames = Math.round(((iconNbVert * 80) / 25) - 1.4); | |
1219 | isThisAScan = false; | |
1220 | refillWidgetAddList(false); | |
1221 | } | |
1222 | ||
1223 | // | |
1224 | // create a file menu in the main screen, allowing to navigate directories and choose a directory to scan for widgets | |
1225 | // and load all their icons | |
1226 | // | |
1227 | function on_dir_scan() { | |
1228 | state = 'list'; | |
1229 | widgetContainer.setAttribute('display', 'none'); | |
1230 | homepage.setAttribute('display', 'none'); | |
1231 | homebar.setAttribute('display', 'none'); | |
1232 | execbar.setAttribute('display', 'inline'); | |
1233 | arrows.setAttribute('display', 'none'); | |
1234 | arrowsW.setAttribute('display', 'none'); | |
1235 | widgetAddList.setAttribute('display', 'inline'); | |
1236 | maxFileNames = Math.round(((iconNbVert * 80) / 25) - 1.4); | |
1237 | isThisAScan = true; | |
1238 | refillWidgetAddList(true); | |
1239 | } | |
1240 | ||
1241 | // | |
1242 | // remove all installed icons | |
1243 | // | |
1244 | function on_clean_up() { | |
1245 | var i; | |
1246 | //if (l_inf <= log_level) alert('[UI] unloading ' + WidgetManager.num_widgets + ' widgets'); | |
1247 | for (i = WidgetManager.num_widgets - 1; i >= 0; i--) { | |
1248 | var w = WidgetManager.get(i); | |
1249 | if (w.loaded) { | |
1250 | alert("unloading " + w.name); | |
1251 | w.loaded = false; | |
1252 | WidgetManager.unload(w, false); | |
1253 | } | |
1254 | } | |
1255 | where = 0; | |
1256 | maxwhere = 0; | |
1257 | removeAllChildren(document.getElementById("icons")); | |
1258 | adjustwhere(false); | |
1259 | } | |
1260 | ||
1261 | // | |
1262 | // install, but do not launch, the widget whose config.xml has been chosen, and return to the home page | |
1263 | // | |
1264 | function widgetInstall(uri, manual, temporary, parent_wid) { | |
1265 | var wid, j, count = WidgetManager.num_widgets, nbWidgets = getNbWidgets(); | |
1266 | for (j = 0; j < count; j++) { | |
1267 | wid = WidgetManager.get(j); | |
1268 | if (wid.url == uri) { | |
1269 | if (wid.loaded) { | |
1270 | break; | |
1271 | } | |
1272 | if (temporary) { | |
1273 | wid.permanent = false; | |
1274 | } | |
1275 | else { | |
1276 | insert_icon(wid, nbWidgets, nbWidgets); | |
1277 | } | |
1278 | } | |
1279 | } | |
1280 | if (j == count) { | |
1281 | wid = WidgetManager.open(uri, null, parent_wid); | |
1282 | if (wid != null) { | |
1283 | if (temporary) { | |
1284 | wid.permanent = false; | |
1285 | } | |
1286 | else { | |
1287 | insert_icon(wid, nbWidgets, nbWidgets); | |
1288 | } | |
1289 | } | |
1290 | } | |
1291 | if (manual) { | |
1292 | 1292 | return wid; |
1293 | 1293 | } |
1294 | ||
1295 | // | |
1296 | // clean up file list space and refill it | |
1297 | // | |
1298 | function refillWidgetAddList(flag) { | |
1299 | removeAllChildren(widgetAddList); | |
1300 | fllist = null; | |
1301 | flstart = 0; | |
1302 | fllist = gpac.enum_directory(gpac.last_working_directory, "", false); | |
1303 | fillWidgetAddList(flag); | |
1304 | } | |
1305 | ||
1306 | // | |
1307 | // go to parent directory | |
1308 | // | |
1309 | function flUpDir(evt) { | |
1310 | var s = gpac.last_working_directory; | |
1311 | if (l_inf <= log_level) { | |
1312 | alert("[UI] lwd:" + gpac.last_working_directory); | |
1313 | } | |
1314 | var index = s.lastIndexOf("\\"); | |
1294 | state = 'home'; | |
1295 | widgetContainer.setAttribute('display', 'none'); | |
1296 | homepage.setAttribute('display', 'inline'); | |
1297 | homebar.setAttribute('display', 'inline'); | |
1298 | execbar.setAttribute('display', 'none'); | |
1299 | arrows.setAttribute('display', 'inline'); | |
1300 | arrowsW.setAttribute('display', 'none'); | |
1301 | removeAllChildren(widgetAddList); | |
1302 | maxwhere = ((nbWidgets - 1) - ((nbWidgets - 1) % iconsPerPage)) / iconsPerPage; | |
1303 | where = maxwhere; | |
1304 | adjustwhere(false); | |
1305 | return wid; | |
1306 | } | |
1307 | ||
1308 | // | |
1309 | // clean up file list space and refill it | |
1310 | // | |
1311 | function refillWidgetAddList(flag) { | |
1312 | removeAllChildren(widgetAddList); | |
1313 | fllist = null; | |
1314 | flstart = 0; | |
1315 | fllist = gpac.enum_directory(gpac.last_working_directory, "", false); | |
1316 | fillWidgetAddList(flag); | |
1317 | } | |
1318 | ||
1319 | // | |
1320 | // go to parent directory | |
1321 | // | |
1322 | function flUpDir(evt) { | |
1323 | var s = gpac.last_working_directory; | |
1324 | if (l_inf <= log_level) { | |
1325 | alert("[UI] lwd:" + gpac.last_working_directory); | |
1326 | } | |
1327 | var index = s.lastIndexOf("\\"); | |
1328 | if (index != -1) { | |
1329 | gpac.last_working_directory = s.substring(0, index); | |
1330 | refillWidgetAddList(isThisAScan); | |
1331 | } else { | |
1332 | index = s.lastIndexOf("/"); | |
1315 | 1333 | if (index != -1) { |
1316 | 1334 | gpac.last_working_directory = s.substring(0, index); |
1317 | 1335 | refillWidgetAddList(isThisAScan); |
1318 | 1336 | } else { |
1319 | index = s.lastIndexOf("/"); | |
1320 | if (index != -1) { | |
1321 | gpac.last_working_directory = s.substring(0, index); | |
1322 | refillWidgetAddList(isThisAScan); | |
1323 | } else { | |
1324 | gpac.last_working_directory = "/"; | |
1325 | refillWidgetAddList(isThisAScan); | |
1326 | } | |
1327 | } | |
1328 | } | |
1329 | ||
1330 | // | |
1331 | // go to a named directory | |
1332 | // | |
1333 | function flGoTo(newDir) { | |
1334 | //alert("goto "+newDir); | |
1335 | var s = gpac.last_working_directory; | |
1336 | if (s == "/") { | |
1337 | gpac.last_working_directory = newDir; | |
1338 | } else { | |
1339 | var c = s.charAt(s.length - 1); | |
1340 | if (c != '\\' && c != '/') { | |
1341 | s += "/"; | |
1342 | } | |
1343 | gpac.last_working_directory = s + newDir; | |
1344 | } | |
1345 | //alert(gpac.last_working_directory); | |
1346 | refillWidgetAddList(isThisAScan); | |
1347 | } | |
1348 | ||
1349 | // | |
1350 | // if the directory contains more files that can be shown, show previous page of file names | |
1351 | // | |
1352 | function flPrevFiles(evt) { | |
1353 | if (flstart == 0) { | |
1354 | return; | |
1355 | } | |
1356 | flstart -= maxFileNames; | |
1357 | if (flstart < 0) { | |
1358 | flstart = 0; | |
1359 | } | |
1337 | gpac.last_working_directory = "/"; | |
1338 | refillWidgetAddList(isThisAScan); | |
1339 | } | |
1340 | } | |
1341 | } | |
1342 | ||
1343 | // | |
1344 | // go to a named directory | |
1345 | // | |
1346 | function flGoTo(newDir) { | |
1347 | //alert("goto "+newDir); | |
1348 | var s = gpac.last_working_directory; | |
1349 | if (s == "/") { | |
1350 | gpac.last_working_directory = newDir; | |
1351 | } else { | |
1352 | var c = s.charAt(s.length - 1); | |
1353 | if (c != '\\' && c != '/') { | |
1354 | s += "/"; | |
1355 | } | |
1356 | gpac.last_working_directory = s + newDir; | |
1357 | } | |
1358 | //alert(gpac.last_working_directory); | |
1359 | refillWidgetAddList(isThisAScan); | |
1360 | } | |
1361 | ||
1362 | // | |
1363 | // if the directory contains more files that can be shown, show previous page of file names | |
1364 | // | |
1365 | function flPrevFiles(evt) { | |
1366 | if (flstart == 0) { | |
1367 | return; | |
1368 | } | |
1369 | flstart -= maxFileNames; | |
1370 | if (flstart < 0) { | |
1371 | flstart = 0; | |
1372 | } | |
1373 | removeAllChildren(widgetAddList); | |
1374 | fillWidgetAddList(isThisAScan); | |
1375 | } | |
1376 | ||
1377 | // | |
1378 | // if the directory contains more files that can be shown, show next page of file names | |
1379 | // | |
1380 | function flNextFiles(evt) { | |
1381 | if (flstart + maxFileNames < fllist.length) { | |
1382 | flstart += maxFileNames; | |
1360 | 1383 | removeAllChildren(widgetAddList); |
1361 | 1384 | fillWidgetAddList(isThisAScan); |
1362 | 1385 | } |
1363 | ||
1364 | // | |
1365 | // if the directory contains more files that can be shown, show next page of file names | |
1366 | // | |
1367 | function flNextFiles(evt) { | |
1368 | if (flstart + maxFileNames < fllist.length) { | |
1369 | flstart += maxFileNames; | |
1370 | removeAllChildren(widgetAddList); | |
1371 | fillWidgetAddList(isThisAScan); | |
1372 | } | |
1373 | } | |
1374 | ||
1375 | // | |
1376 | // scan the current directory recursively for widgets, clean up and return to home page | |
1377 | // | |
1378 | function flScanDir(evt) { | |
1379 | scan_directory(gpac.last_working_directory); | |
1380 | state = 'home'; | |
1381 | var nbWidgets = getNbWidgets(); | |
1382 | widgetContainer.setAttribute('display', 'none'); | |
1383 | homepage.setAttribute('display', 'inline'); | |
1384 | homebar.setAttribute('display', 'inline'); | |
1385 | execbar.setAttribute('display', 'none'); | |
1386 | arrows.setAttribute('display', 'inline'); | |
1387 | arrowsW.setAttribute('display', 'none'); | |
1388 | removeAllChildren(widgetAddList); | |
1389 | maxwhere = ((nbWidgets - 1) - ((nbWidgets - 1) % iconsPerPage)) / iconsPerPage; | |
1390 | where = maxwhere; | |
1391 | adjustwhere(false); | |
1392 | } | |
1393 | ||
1394 | // | |
1395 | // scanning | |
1396 | // | |
1397 | function scan_directory(dir) { | |
1398 | var ii, j, count, list, w, uri, loadedWidgets = 0; | |
1399 | list = gpac.enum_directory(dir, '.xml;.wgt', 0); | |
1400 | for (ii = 0; ii < list.length; ii++) { | |
1401 | uri = list[ii].path + list[ii].name; | |
1402 | if (list[ii].directory) { | |
1403 | scan_directory(uri); | |
1404 | } else { | |
1405 | count = WidgetManager.num_widgets; | |
1406 | for (j = 0; j < count; j++) { | |
1407 | var wid = WidgetManager.get(j); | |
1386 | } | |
1387 | ||
1388 | // | |
1389 | // scan the current directory recursively for widgets, clean up and return to home page | |
1390 | // | |
1391 | function flScanDir(evt) { | |
1392 | scan_directory(gpac.last_working_directory); | |
1393 | state = 'home'; | |
1394 | var nbWidgets = getNbWidgets(); | |
1395 | widgetContainer.setAttribute('display', 'none'); | |
1396 | homepage.setAttribute('display', 'inline'); | |
1397 | homebar.setAttribute('display', 'inline'); | |
1398 | execbar.setAttribute('display', 'none'); | |
1399 | arrows.setAttribute('display', 'inline'); | |
1400 | arrowsW.setAttribute('display', 'none'); | |
1401 | removeAllChildren(widgetAddList); | |
1402 | maxwhere = ((nbWidgets - 1) - ((nbWidgets - 1) % iconsPerPage)) / iconsPerPage; | |
1403 | where = maxwhere; | |
1404 | adjustwhere(false); | |
1405 | } | |
1406 | ||
1407 | // | |
1408 | // scanning | |
1409 | // | |
1410 | function scan_directory(dir) { | |
1411 | var ii, j, count, list, w, uri, loadedWidgets = 0; | |
1412 | list = gpac.enum_directory(dir, '.xml;.wgt', 0); | |
1413 | for (ii = 0; ii < list.length; ii++) { | |
1414 | uri = list[ii].path + list[ii].name; | |
1415 | if (list[ii].directory) { | |
1416 | scan_directory(uri); | |
1417 | } else { | |
1418 | count = WidgetManager.num_widgets; | |
1419 | for (j = 0; j < count; j++) { | |
1420 | var wid = WidgetManager.get(j); | |
1421 | if (wid.loaded) { | |
1422 | loadedWidgets++; | |
1423 | } | |
1424 | if (wid.url == uri) { | |
1408 | 1425 | if (wid.loaded) { |
1409 | loadedWidgets++; | |
1410 | } | |
1411 | if (wid.url == uri) { | |
1412 | if (wid.loaded) { | |
1413 | break; | |
1414 | } | |
1415 | insert_icon(wid, getNbWidgets(), j); | |
1416 | 1426 | break; |
1417 | 1427 | } |
1418 | } | |
1419 | if (j == count) { | |
1420 | w = WidgetManager.open(uri, null); | |
1421 | if (w != null) { | |
1422 | insert_icon(w, loadedWidgets, WidgetManager.num_widgets - 1); | |
1423 | } | |
1428 | insert_icon(wid, getNbWidgets(), j); | |
1429 | break; | |
1424 | 1430 | } |
1425 | 1431 | } |
1426 | } | |
1427 | } | |
1428 | ||
1429 | // | |
1430 | // create the up, prev, next button, show current directory and as many file names as possible | |
1431 | // the file names are active: clicking on a directory name goes to that directory | |
1432 | // clicking on a file tries to load that file as a widget | |
1433 | // | |
1434 | function fillWidgetAddList(flag) { | |
1435 | if (flag) { | |
1436 | widgetAddList.appendChild(use("cartoucheflag")); | |
1437 | document.getElementById("dirflag").textContent = gpac.last_working_directory; | |
1438 | } else { | |
1439 | widgetAddList.appendChild(use("cartouche")); | |
1440 | document.getElementById("dir").textContent = gpac.last_working_directory; | |
1441 | } | |
1442 | // next lines are file names | |
1443 | var obj; | |
1444 | for (i = 0; i < (fllist.length - flstart) && i < maxFileNames; i++) { | |
1445 | obj = use("fileMenuElement" + i); | |
1446 | obj.setAttribute('transform', 'translate(0,' + (25 * (i + 1)) + ')'); | |
1447 | widgetAddList.appendChild(obj); | |
1448 | document.getElementById("fileMenuElement" + i + "u").setAttributeNS(xlinkns, 'href', "#" + (fllist[i + flstart].directory ? 'folder' : 'new')); | |
1449 | document.getElementById("fileMenuElement" + i + "t").textContent = fllist[i + flstart].name; | |
1450 | if (obj.listener != null) { | |
1451 | obj.removeEventListener("click", obj.listener); | |
1432 | if (j == count) { | |
1433 | w = WidgetManager.open(uri, null); | |
1434 | if (w != null) { | |
1435 | insert_icon(w, loadedWidgets, WidgetManager.num_widgets - 1); | |
1436 | } | |
1452 | 1437 | } |
1453 | if (fllist[i + flstart].directory) { | |
1454 | obj.listener = createGoto(escaping(fllist[i + flstart].name)); | |
1455 | obj.addEventListener("click", obj.listener, false); | |
1456 | } else if (isWidgetFileName(fllist[i + flstart].name)) { | |
1457 | obj.listener = createWidgetInstall(escaping(gpac.last_working_directory + '/' + fllist[i + flstart].name)); | |
1458 | obj.addEventListener("click", obj.listener, false); | |
1459 | } | |
1460 | } | |
1461 | } | |
1462 | ||
1463 | function createGoto(s) { | |
1464 | return function () { | |
1465 | flGoTo(s); | |
1466 | }; | |
1467 | } | |
1468 | ||
1469 | function createWidgetInstall(s) { | |
1470 | return function () { | |
1471 | widgetInstall(s, false, false, null); | |
1472 | }; | |
1473 | } | |
1474 | ||
1475 | // // // // // // // // // // // // // // // | |
1476 | // function library | |
1477 | // // // // // // // // // // // // // // // | |
1478 | ||
1479 | function isWidgetFileName(s) { | |
1480 | if (endsWith(s, 'config.xml')) { | |
1481 | return true; | |
1482 | } | |
1483 | if (endsWith(s, '.wgt')) { | |
1484 | return true; | |
1485 | } | |
1486 | return false; | |
1487 | } | |
1488 | ||
1489 | // | |
1490 | // replace globally \ with / in a string | |
1491 | // | |
1492 | function escaping(s) { | |
1493 | s = s.replace(/\\/g, '/'); | |
1494 | return s; | |
1495 | } | |
1496 | ||
1497 | // | |
1498 | // create rect | |
1499 | // | |
1500 | function rect(x, y, w, h, fill, stroke, id) { | |
1501 | var child = document.createElement('rect'); | |
1502 | if (id != null) { | |
1503 | child.setAttribute('id', id); | |
1504 | } | |
1505 | child.setAttribute('x', x); | |
1506 | child.setAttribute('y', y); | |
1507 | child.setAttribute('width', w); | |
1508 | child.setAttribute('height', h); | |
1509 | child.setAttribute('fill', fill); | |
1510 | child.setAttribute('stroke', stroke); | |
1511 | return child; | |
1512 | } | |
1513 | ||
1514 | // | |
1515 | // create text | |
1516 | // | |
1517 | function createtext(content, fill, x, y, size, family) { | |
1518 | var child = document.createElement('text'); | |
1519 | child.setAttribute('fill', fill); | |
1520 | child.textContent = content; | |
1521 | child.setAttribute('x', x); | |
1522 | child.setAttribute('y', y); | |
1523 | child.setAttribute('font-size', size); | |
1524 | child.setAttribute('font-family', family); | |
1525 | return child; | |
1526 | } | |
1527 | ||
1528 | // | |
1529 | // create invisible rect getting all events | |
1530 | // | |
1531 | function invisible_rect(w, h) { | |
1532 | var child = document.createElement('rect'); | |
1533 | child.setAttribute('width', w); | |
1534 | child.setAttribute('height', h); | |
1535 | child.setAttribute('fill', 'none'); | |
1536 | child.setAttribute('stroke', 'none'); | |
1537 | child.setAttribute('pointer-events', 'all'); | |
1538 | return child; | |
1539 | } | |
1540 | ||
1541 | // | |
1542 | // create animation | |
1543 | // | |
1544 | function media(etype, uri, w, h) { | |
1545 | var child = document.createElement(etype); | |
1546 | child.setAttributeNS(xlinkns, 'href', uri); | |
1547 | child.setAttribute('width', w); | |
1548 | child.setAttribute('height', h); | |
1549 | if (etype == 'animation') { | |
1550 | child.setAttributeNS('http://gpac.sourceforge.net/svg-extensions', 'use-as-primary', 'false'); | |
1551 | } | |
1552 | return child; | |
1553 | } | |
1554 | ||
1555 | // | |
1556 | // create use | |
1557 | // | |
1558 | function use(uri) { | |
1559 | var child = document.createElement('use'); | |
1560 | child.setAttributeNS(xlinkns, 'href', '#' + uri); | |
1561 | return child; | |
1562 | } | |
1563 | ||
1564 | // | |
1565 | // create appropriate element for media reference by the given uri | |
1566 | // | |
1567 | function appropriateElementForMedia(uri, w, h) { | |
1568 | if (uri.indexOf('#') != -1) { | |
1569 | return media('animation', uri, w, h); | |
1570 | } | |
1571 | if (endsWith(uri, '.svg')) { | |
1572 | return media('animation', uri, w, h); | |
1573 | } | |
1574 | if (endsWith(uri, '.bt')) { | |
1575 | return media('animation', uri, w, h); | |
1576 | } | |
1577 | if (endsWith(uri, '.png')) { | |
1578 | return media('image', uri, w, h); | |
1579 | } | |
1580 | if (endsWith(uri, '.jpg')) { | |
1581 | return media('image', uri, w, h); | |
1582 | } | |
1583 | if (endsWith(uri, '.gif')) { | |
1584 | return media('image', uri, w, h); | |
1585 | } | |
1586 | if (l_war <= log_level) { | |
1587 | alert("[UI] WARNING: bad suffix for an icon URI: " + uri); | |
1588 | } | |
1438 | } | |
1439 | } | |
1440 | } | |
1441 | ||
1442 | // | |
1443 | // create the up, prev, next button, show current directory and as many file names as possible | |
1444 | // the file names are active: clicking on a directory name goes to that directory | |
1445 | // clicking on a file tries to load that file as a widget | |
1446 | // | |
1447 | function fillWidgetAddList(flag) { | |
1448 | if (flag) { | |
1449 | widgetAddList.appendChild(use("cartoucheflag")); | |
1450 | document.getElementById("dirflag").textContent = gpac.last_working_directory; | |
1451 | } else { | |
1452 | widgetAddList.appendChild(use("cartouche")); | |
1453 | document.getElementById("dir").textContent = gpac.last_working_directory; | |
1454 | } | |
1455 | // next lines are file names | |
1456 | var obj; | |
1457 | for (i = 0; i < (fllist.length - flstart) && i < maxFileNames; i++) { | |
1458 | obj = use("fileMenuElement" + i); | |
1459 | obj.setAttribute('transform', 'translate(0,' + (25 * (i + 1)) + ')'); | |
1460 | widgetAddList.appendChild(obj); | |
1461 | document.getElementById("fileMenuElement" + i + "u").setAttributeNS(xlinkns, 'href', "#" + (fllist[i + flstart].directory ? 'folder' : 'new')); | |
1462 | document.getElementById("fileMenuElement" + i + "t").textContent = fllist[i + flstart].name; | |
1463 | if (obj.listener != null) { | |
1464 | obj.removeEventListener("click", obj.listener); | |
1465 | } | |
1466 | if (fllist[i + flstart].directory) { | |
1467 | obj.listener = createGoto(escaping(fllist[i + flstart].name)); | |
1468 | obj.addEventListener("click", obj.listener, false); | |
1469 | } else if (isWidgetFileName(fllist[i + flstart].name)) { | |
1470 | obj.listener = createWidgetInstall(escaping(gpac.last_working_directory + '/' + fllist[i + flstart].name)); | |
1471 | obj.addEventListener("click", obj.listener, false); | |
1472 | } | |
1473 | } | |
1474 | } | |
1475 | ||
1476 | function createGoto(s) { | |
1477 | return function () { | |
1478 | flGoTo(s); | |
1479 | }; | |
1480 | } | |
1481 | ||
1482 | function createWidgetInstall(s) { | |
1483 | return function () { | |
1484 | widgetInstall(s, false, false, null); | |
1485 | }; | |
1486 | } | |
1487 | ||
1488 | // // // // // // // // // // // // // // // | |
1489 | // function library | |
1490 | // // // // // // // // // // // // // // // | |
1491 | ||
1492 | function isWidgetFileName(s) { | |
1493 | if (endsWith(s, 'config.xml')) { | |
1494 | return true; | |
1495 | } | |
1496 | if (endsWith(s, '.wgt')) { | |
1497 | return true; | |
1498 | } | |
1499 | return false; | |
1500 | } | |
1501 | ||
1502 | // | |
1503 | // replace globally \ with / in a string | |
1504 | // | |
1505 | function escaping(s) { | |
1506 | s = s.replace(/\\/g, '/'); | |
1507 | return s; | |
1508 | } | |
1509 | ||
1510 | // | |
1511 | // create rect | |
1512 | // | |
1513 | function rect(x, y, w, h, fill, stroke, id) { | |
1514 | var child = document.createElement('rect'); | |
1515 | if (id != null) { | |
1516 | child.setAttribute('id', id); | |
1517 | } | |
1518 | child.setAttribute('x', x); | |
1519 | child.setAttribute('y', y); | |
1520 | child.setAttribute('width', w); | |
1521 | child.setAttribute('height', h); | |
1522 | child.setAttribute('fill', fill); | |
1523 | child.setAttribute('stroke', stroke); | |
1524 | return child; | |
1525 | } | |
1526 | ||
1527 | // | |
1528 | // create text | |
1529 | // | |
1530 | function createtext(content, fill, x, y, size, family) { | |
1531 | var child = document.createElement('text'); | |
1532 | child.setAttribute('fill', fill); | |
1533 | child.textContent = content; | |
1534 | child.setAttribute('x', x); | |
1535 | child.setAttribute('y', y); | |
1536 | child.setAttribute('font-size', size); | |
1537 | child.setAttribute('font-family', family); | |
1538 | return child; | |
1539 | } | |
1540 | ||
1541 | // | |
1542 | // create invisible rect getting all events | |
1543 | // | |
1544 | function invisible_rect(w, h) { | |
1545 | var child = document.createElement('rect'); | |
1546 | child.setAttribute('width', w); | |
1547 | child.setAttribute('height', h); | |
1548 | child.setAttribute('fill', 'none'); | |
1549 | child.setAttribute('stroke', 'none'); | |
1550 | child.setAttribute('pointer-events', 'all'); | |
1551 | return child; | |
1552 | } | |
1553 | ||
1554 | // | |
1555 | // create animation | |
1556 | // | |
1557 | function media(etype, uri, w, h) { | |
1558 | var child = document.createElement(etype); | |
1559 | child.setAttributeNS(xlinkns, 'href', uri); | |
1560 | child.setAttribute('width', w); | |
1561 | child.setAttribute('height', h); | |
1562 | if (etype == 'animation') { | |
1563 | child.setAttributeNS('http://gpac.sourceforge.net/svg-extensions', 'use-as-primary', 'false'); | |
1564 | } | |
1565 | return child; | |
1566 | } | |
1567 | ||
1568 | // | |
1569 | // create use | |
1570 | // | |
1571 | function use(uri) { | |
1572 | var child = document.createElement('use'); | |
1573 | child.setAttributeNS(xlinkns, 'href', '#' + uri); | |
1574 | return child; | |
1575 | } | |
1576 | ||
1577 | // | |
1578 | // create appropriate element for media reference by the given uri | |
1579 | // | |
1580 | function appropriateElementForMedia(uri, w, h) { | |
1581 | if (uri.indexOf('#') != -1) { | |
1582 | return media('animation', uri, w, h); | |
1583 | } | |
1584 | if (endsWith(uri, '.svg')) { | |
1585 | return media('animation', uri, w, h); | |
1586 | } | |
1587 | if (endsWith(uri, '.bt')) { | |
1588 | return media('animation', uri, w, h); | |
1589 | } | |
1590 | if (endsWith(uri, '.png')) { | |
1589 | 1591 | return media('image', uri, w, h); |
1590 | 1592 | } |
1591 | ||
1592 | // | |
1593 | // substitute for the useful predefined function endsWith | |
1594 | // | |
1595 | function endsWith(s1, s2) { | |
1596 | return s1.toLowerCase().substring(s1.length - s2.length) == s2; | |
1597 | } | |
1598 | ||
1599 | // export the resize function as the resize member of iphone_wm_gui, as well as other functions | |
1600 | return { | |
1601 | resize: resize, | |
1602 | left_button: left_button, | |
1603 | right_button: right_button, | |
1604 | left_buttonW: left_buttonW, | |
1605 | right_buttonW: right_buttonW, | |
1606 | home_button: home_button, | |
1607 | on_dir_scan: on_dir_scan, | |
1608 | on_clean_up: on_clean_up, | |
1609 | on_widget_add_menu: on_widget_add_menu, | |
1610 | on_kill_widget: on_kill_widget, | |
1611 | on_get_widget: on_get_widget, | |
1612 | on_widget_remote: on_widget_remote, | |
1613 | flUpDir: flUpDir, | |
1614 | flPrevFiles: flPrevFiles, | |
1615 | flNextFiles: flNextFiles, | |
1616 | flScanDir: flScanDir | |
1617 | } | |
1618 | ||
1619 | }()); | |
1593 | if (endsWith(uri, '.jpg')) { | |
1594 | return media('image', uri, w, h); | |
1595 | } | |
1596 | if (endsWith(uri, '.gif')) { | |
1597 | return media('image', uri, w, h); | |
1598 | } | |
1599 | if (l_war <= log_level) { | |
1600 | alert("[UI] WARNING: bad suffix for an icon URI: " + uri); | |
1601 | } | |
1602 | return media('image', uri, w, h); | |
1603 | } | |
1604 | ||
1605 | // | |
1606 | // substitute for the useful predefined function endsWith | |
1607 | // | |
1608 | function endsWith(s1, s2) { | |
1609 | return s1.toLowerCase().substring(s1.length - s2.length) == s2; | |
1610 | } | |
1611 | ||
1612 | /* wrapper as a module | |
1613 | // export the resize function as the resize member of iphone_wm_gui, as well as other functions | |
1614 | return { | |
1615 | resize: resize, | |
1616 | left_button: left_button, | |
1617 | right_button: right_button, | |
1618 | left_buttonW: left_buttonW, | |
1619 | right_buttonW: right_buttonW, | |
1620 | home_button: home_button, | |
1621 | on_dir_scan: on_dir_scan, | |
1622 | on_clean_up: on_clean_up, | |
1623 | on_widget_add_menu: on_widget_add_menu, | |
1624 | on_kill_widget: on_kill_widget, | |
1625 | on_get_widget: on_get_widget, | |
1626 | on_widget_remote: on_widget_remote, | |
1627 | flUpDir: flUpDir, | |
1628 | flPrevFiles: flPrevFiles, | |
1629 | flNextFiles: flNextFiles, | |
1630 | flScanDir: flScanDir, | |
1631 | get_widget_callback2: get_widget_callback2 | |
1632 | } | |
1633 | ||
1634 | }());*/ | |
1620 | 1635 | |
1621 | 1636 | function widget_activated_and_bound(wid) { |
1622 | 1637 | WidgetManager.corein_message(wid, "activate"); |
1623 | 1638 | } |
1624 | 1639 | |
1625 | 1640 | function printAllFieldsOf(obj, printableName) { |
1626 | var details = "fields of "+printableName+":\n"; | |
1641 | var details = "fields of " + printableName + ":\n"; | |
1627 | 1642 | for (var field in obj) { |
1628 | fieldContents = obj[field]; | |
1629 | if (typeof(fieldContents) == "function") { | |
1630 | fieldContents = "(function)"; | |
1631 | } | |
1632 | details += " " + field + ": " + fieldContents + "\n"; | |
1643 | fieldContents = obj[field]; | |
1644 | if (typeof(fieldContents) == "function") { | |
1645 | fieldContents = "(function)"; | |
1646 | } | |
1647 | details += " " + field + ": " + fieldContents + "\n"; | |
1633 | 1648 | } |
1634 | 1649 | alert(details); |
1635 | 1650 | } |
481 | 481 | <text fill="black" font-family="Comic Sans MS" font-size="12" x="2" y="12">Scan</text> |
482 | 482 | <handler ev:event="click">on_dir_scan();</handler> |
483 | 483 | </g> |
484 | <g id="get" transform="translate(130, 22)"> | |
485 | <rect rx="8" ry="8" fill="rgb(140,140,50)" width="36" height="16"/> | |
486 | <text fill="black" font-family="Comic Sans MS" font-size="12" x="2" y="12">GetW</text> | |
487 | <handler ev:event="click">on_get_widget();</handler> | |
488 | </g> | |
484 | 489 | </g> |
485 | 490 | <rect id="screen" width="320" height="480" fill="white" stroke="black" x="0" y="60"/> |
486 | 491 |
1334 | 1334 | void (*on_audio_reconfig)(void *udta, u32 samplerate, u32 bits_per_sample, u32 nb_channel, u32 channel_cfg); |
1335 | 1335 | } GF_AudioListener; |
1336 | 1336 | |
1337 | /*adds a new audio listener - the on_audio_reconfig callback will be called before this function returns*/ | |
1337 | 1338 | GF_Err gf_sc_add_audio_listener(GF_Compositor *compositor, GF_AudioListener *al); |
1338 | 1339 | GF_Err gf_sc_remove_audio_listener(GF_Compositor *compositor, GF_AudioListener *al); |
1339 | 1340 |
2037 | 2037 | #define GF_ISOM_GET_FRAG_PAD(flag) ( (flag) >> 17) & 0x7 |
2038 | 2038 | #define GF_ISOM_GET_FRAG_SYNC(flag) ( ! ( ( (flag) >> 16) & 0x1)) |
2039 | 2039 | #define GF_ISOM_GET_FRAG_DEG(flag) (flag) & 0x7FFF |
2040 | ||
2041 | #define GF_ISOM_GET_FRAG_DEPEND_FLAGS(lead, depends, depended, redundant) ( (lead<<26) | (depends<<24) | (depended<<22) | (redundant<<20) ) | |
2042 | #define GF_ISOM_RESET_FRAG_DEPEND_FLAGS(flags) flags = flags & 0xFFFFF | |
2040 | 2043 | |
2041 | 2044 | GF_TrackExtendsBox *GetTrex(GF_MovieBox *moov, u32 TrackID); |
2042 | 2045 | #endif |
410 | 410 | |
411 | 411 | |
412 | 412 | #ifndef GF_EXPORT |
413 | #if defined(__GNUC__) && __GNUC__ >= 4 | |
414 | #define GF_EXPORT __attribute__((visibility("default"))) | |
415 | #else | |
413 | 416 | /*use def files for windows or let compiler decide*/ |
414 | 417 | #define GF_EXPORT |
418 | #endif | |
415 | 419 | #endif |
416 | 420 | |
417 | 421 |
61 | 61 | * SONAME versions must be digits (not strings) |
62 | 62 | */ |
63 | 63 | #define GPAC_VERSION "0.4.6-DEV" |
64 | #define GPAC_VERSION_MAJOR 1 | |
65 | #define GPAC_VERSION_MINOR 1 | |
64 | #define GPAC_VERSION_MAJOR 2 | |
65 | #define GPAC_VERSION_MINOR 0 | |
66 | 66 | #define GPAC_VERSION_MICRO 0 |
67 | 67 | |
68 | 68 | #include <gpac/version.h> |
928 | 928 | } |
929 | 929 | |
930 | 930 | #endif |
931 | #endif | |
931 | 932 | |
932 | 933 | #ifndef DONT_USE_TERMINAL_MODULE_API |
933 | 934 | |
981 | 982 | } |
982 | 983 | } |
983 | 984 | #endif |
984 | #endif |
349 | 349 | * ******************************************************************** |
350 | 350 | * interface |
351 | 351 | */ |
352 | GF_EXPORT | |
352 | 353 | const u32 *QueryInterfaces() |
353 | 354 | { |
354 | 355 | static u32 si [] = { |
358 | 359 | return si; |
359 | 360 | } |
360 | 361 | |
362 | GF_EXPORT | |
361 | 363 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
362 | 364 | { |
363 | 365 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) |
365 | 367 | return NULL; |
366 | 368 | } |
367 | 369 | |
370 | GF_EXPORT | |
368 | 371 | void ShutdownInterface(GF_BaseInterface *ifce) |
369 | 372 | { |
370 | 373 | if (ifce->InterfaceType==GF_AUDIO_OUTPUT_INTERFACE) |
303 | 303 | GF_InputService *NewAESReader(); |
304 | 304 | void DeleteAESReader(void *ifce); |
305 | 305 | |
306 | GF_EXPORT | |
306 | 307 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
307 | 308 | { |
308 | 309 | switch (InterfaceType) { |
312 | 313 | } |
313 | 314 | } |
314 | 315 | |
316 | GF_EXPORT | |
315 | 317 | void ShutdownInterface(GF_BaseInterface *ifce) |
316 | 318 | { |
317 | 319 | switch (ifce->InterfaceType) { |
322 | 322 | return si; |
323 | 323 | } |
324 | 324 | |
325 | GF_EXPORT | |
325 | 326 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
326 | 327 | { |
327 | 328 | switch (InterfaceType) { |
331 | 332 | } |
332 | 333 | } |
333 | 334 | |
335 | GF_EXPORT | |
334 | 336 | void ShutdownInterface(GF_BaseInterface *ifce) |
335 | 337 | { |
336 | 338 | switch (ifce->InterfaceType) { |
259 | 259 | * ******************************************************************** |
260 | 260 | * interface |
261 | 261 | */ |
262 | GF_EXPORT | |
262 | 263 | const u32 *QueryInterfaces() |
263 | 264 | { |
264 | 265 | static u32 si [] = { |
268 | 269 | return si; |
269 | 270 | } |
270 | 271 | |
272 | GF_EXPORT | |
271 | 273 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
272 | 274 | { |
273 | 275 | if (InterfaceType == GF_AUDIO_FILTER_INTERFACE) |
275 | 277 | return NULL; |
276 | 278 | } |
277 | 279 | |
280 | GF_EXPORT | |
278 | 281 | void ShutdownInterface(GF_BaseInterface *ifce) |
279 | 282 | { |
280 | 283 | if (ifce->InterfaceType==GF_AUDIO_FILTER_INTERFACE) |
363 | 363 | |
364 | 364 | |
365 | 365 | /*interface query*/ |
366 | GF_EXPORT | |
366 | 367 | const u32 *QueryInterfaces() |
367 | 368 | { |
368 | 369 | static u32 si [] = { |
374 | 375 | |
375 | 376 | |
376 | 377 | /*interface create*/ |
378 | GF_EXPORT | |
377 | 379 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
378 | 380 | { |
379 | 381 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return DirectFBNewVideo(); |
382 | 384 | |
383 | 385 | |
384 | 386 | /*interface destroy*/ |
387 | GF_EXPORT | |
385 | 388 | void ShutdownInterface(GF_BaseInterface *ifce) |
386 | 389 | { |
387 | 390 | switch (ifce->InterfaceType) { |
426 | 426 | gf_free(dr); |
427 | 427 | } |
428 | 428 | //---------------------------------------------------------------------- |
429 | GF_EXPORT | |
429 | 430 | const u32 *QueryInterfaces() |
430 | 431 | { |
431 | 432 | static u32 si [] = { |
435 | 436 | return si; |
436 | 437 | } |
437 | 438 | |
439 | GF_EXPORT | |
438 | 440 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
439 | 441 | { |
440 | 442 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) return NewWAVRender(); |
441 | 443 | return NULL; |
442 | 444 | } |
443 | 445 | |
446 | GF_EXPORT | |
444 | 447 | void ShutdownInterface(GF_BaseInterface *ifce) |
445 | 448 | { |
446 | 449 | switch (ifce->InterfaceType) { |
368 | 368 | }; |
369 | 369 | return si; |
370 | 370 | } |
371 | ||
371 | 372 | /*interface create*/ |
373 | GF_EXPORT | |
372 | 374 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
373 | 375 | { |
374 | 376 | if (InterfaceType == GF_INPUT_DEVICE_INTERFACE) return (GF_BaseInterface *) NewMPEGVSInputSesor(); |
375 | 377 | return NULL; |
376 | 378 | } |
379 | ||
377 | 380 | /*interface destroy*/ |
381 | GF_EXPORT | |
378 | 382 | void ShutdownInterface(GF_BaseInterface *ifce) |
379 | 383 | { |
380 | 384 | switch (ifce->InterfaceType) { |
199 | 199 | return si; |
200 | 200 | } |
201 | 201 | /*interface create*/ |
202 | GF_EXPORT | |
202 | 203 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
203 | 204 | { |
204 | 205 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return (GF_BaseInterface *) NewRawVideoOutput(); |
205 | 206 | return NULL; |
206 | 207 | } |
207 | 208 | /*interface destroy*/ |
209 | GF_EXPORT | |
208 | 210 | void ShutdownInterface(GF_BaseInterface *ifce) |
209 | 211 | { |
210 | 212 | switch (ifce->InterfaceType) { |
647 | 647 | return si; |
648 | 648 | } |
649 | 649 | /*interface create*/ |
650 | GF_EXPORT | |
650 | 651 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
651 | 652 | { |
652 | 653 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return (GF_BaseInterface *) NewRawVideoOutput(); |
653 | 654 | return NULL; |
654 | 655 | } |
655 | 656 | /*interface destroy*/ |
657 | GF_EXPORT | |
656 | 658 | void ShutdownInterface(GF_BaseInterface *ifce) |
657 | 659 | { |
658 | 660 | switch (ifce->InterfaceType) { |
720 | 720 | return si; |
721 | 721 | } |
722 | 722 | /*interface create*/ |
723 | GF_EXPORT | |
723 | 724 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
724 | 725 | { |
725 | 726 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return NewDXVideoOutput(); |
727 | 728 | return NULL; |
728 | 729 | } |
729 | 730 | /*interface destroy*/ |
731 | GF_EXPORT | |
730 | 732 | void ShutdownInterface(GF_BaseInterface *ifce) |
731 | 733 | { |
732 | 734 | switch (ifce->InterfaceType) { |
494 | 494 | }; |
495 | 495 | return si; |
496 | 496 | } |
497 | ||
497 | 498 | /*interface create*/ |
498 | 499 | GF_EXPORT |
499 | 500 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
503 | 504 | if (InterfaceType == GF_MEDIA_DECODER_INTERFACE) return (GF_BaseInterface *) EPOC_codec_new(); |
504 | 505 | return NULL; |
505 | 506 | } |
507 | ||
506 | 508 | /*interface destroy*/ |
507 | 509 | GF_EXPORT |
508 | 510 | void ShutdownInterface(GF_BaseInterface *ifce) |
1 | 1 | |
2 | 2 | vpath %.c $(SRC_PATH)/modules/ffmpeg_in |
3 | 3 | |
4 | CFLAGS=$(OPTFLAGS) -I"$(SRC_PATH)/include" $(ffmpeg_cflags) | |
4 | CFLAGS=$(OPTFLAGS) -Wno-deprecated-declarations -I"$(SRC_PATH)/include" $(ffmpeg_cflags) | |
5 | 5 | |
6 | 6 | ifeq ($(DEBUGBUILD), yes) |
7 | 7 | CFLAGS+=-g |
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | #ifdef USE_PRE_0_7 | |
480 | 481 | static int ff_url_read(void *h, unsigned char *buf, int size) |
481 | 482 | { |
482 | 483 | u32 retry = 10; |
527 | 528 | #endif |
528 | 529 | return full_size ? (int) full_size : -1; |
529 | 530 | } |
531 | #endif /*USE_PRE_0_7*/ | |
530 | 532 | |
531 | 533 | |
532 | 534 | static GF_Err FFD_ConnectService(GF_InputService *plug, GF_ClientService *serv, const char *url) |
1481 | 1481 | |
1482 | 1482 | |
1483 | 1483 | /*interface query*/ |
1484 | GF_EXPORT | |
1484 | 1485 | const u32 *QueryInterfaces() |
1485 | 1486 | { |
1486 | 1487 | static u32 si [] = { |
1489 | 1490 | }; |
1490 | 1491 | return si; |
1491 | 1492 | } |
1493 | ||
1492 | 1494 | /*interface create*/ |
1495 | GF_EXPORT | |
1493 | 1496 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
1494 | 1497 | { |
1495 | 1498 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return (GF_BaseInterface *) NewGAPIVideoOutput(); |
1496 | 1499 | return NULL; |
1497 | 1500 | } |
1501 | ||
1498 | 1502 | /*interface destroy*/ |
1503 | GF_EXPORT | |
1499 | 1504 | void ShutdownInterface(GF_BaseInterface *ifce) |
1500 | 1505 | { |
1501 | 1506 | GF_VideoOutput *dd = (GF_VideoOutput *)ifce; |
363 | 363 | extern "C" { |
364 | 364 | #endif |
365 | 365 | |
366 | GF_EXPORT | |
366 | 367 | const u32 *QueryInterfaces() |
367 | 368 | { |
368 | 369 | static u32 si [] = { |
373 | 374 | return si; |
374 | 375 | } |
375 | 376 | |
377 | GF_EXPORT | |
376 | 378 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
377 | 379 | { |
378 | 380 | if (InterfaceType==GF_FONT_READER_INTERFACE) return (GF_BaseInterface *)gdip_new_font_driver(); |
380 | 382 | return NULL; |
381 | 383 | } |
382 | 384 | |
385 | GF_EXPORT | |
383 | 386 | void ShutdownInterface(GF_BaseInterface *ifce) |
384 | 387 | { |
385 | 388 | switch (ifce->InterfaceType) { |
761 | 761 | SMJS_ARGS |
762 | 762 | GF_GPACJSExt *gjs = (GF_GPACJSExt *)JS_GetPrivate(c, obj); |
763 | 763 | if (!argc || !JSVAL_IS_OBJECT(argv[0])) return JS_FALSE; |
764 | if (JSVAL_IS_NULL(gjs->evt_fun) ) return JS_TRUE; | |
764 | ||
765 | if (! JSVAL_IS_NULL(gjs->evt_fun) ) return JS_TRUE; | |
765 | 766 | |
766 | 767 | gjs->evt_fun = argv[0]; |
767 | 768 | gjs->evt_filter_obj = obj; |
892 | 893 | /*nothing to do on unload*/ |
893 | 894 | if (unload) { |
894 | 895 | gjs->nb_loaded--; |
895 | if (!gjs->nb_loaded && gjs->evt_filter.udta) { | |
896 | /*if we destroy the script context holding the gpac event filter (only one for the time being), remove the filter*/ | |
897 | if ((gjs->c==c) && gjs->evt_filter.udta) { | |
896 | 898 | gf_term_remove_event_filter(gjs->term, &gjs->evt_filter); |
899 | gjs->evt_filter.udta = NULL; | |
897 | 900 | } |
898 | 901 | return; |
899 | 902 | } |
956 | 959 | |
957 | 960 | JS_SETUP_CLASS(gjs->anyClass, "GPACOBJECT", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub_forSetter, JS_FinalizeStub); |
958 | 961 | JS_InitClass(c, global, 0, &gjs->anyClass, 0, 0, 0, 0, 0, 0); |
962 | ||
963 | gjs->evt_fun = JSVAL_NULL; | |
959 | 964 | } |
960 | 965 | } |
961 | 966 |
1 | 1 | |
2 | 2 | vpath %.c $(SRC_PATH)/modules/jack |
3 | 3 | |
4 | CFLAGS= $(OPTFLAGS) -I"$(SRC_PATH)/include" $(OSS_CFLAGS) | |
4 | CFLAGS= $(OPTFLAGS) -I"$(SRC_PATH)/include" $(OSS_CFLAGS) -Wno-deprecated-declarations | |
5 | 5 | |
6 | 6 | ifeq ($(DEBUGBUILD), yes) |
7 | 7 | CFLAGS+=-g |
544 | 544 | * interface |
545 | 545 | */ |
546 | 546 | |
547 | GF_EXPORT | |
547 | 548 | const u32 *QueryInterfaces() |
548 | 549 | { |
549 | 550 | static u32 si [] = { |
553 | 554 | return si; |
554 | 555 | } |
555 | 556 | |
556 | GF_BaseInterface * | |
557 | LoadInterface (u32 InterfaceType) | |
557 | GF_EXPORT | |
558 | GF_BaseInterface *LoadInterface (u32 InterfaceType) | |
558 | 559 | { |
559 | 560 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) |
560 | 561 | { |
563 | 564 | return NULL; |
564 | 565 | } |
565 | 566 | |
566 | void | |
567 | ShutdownInterface (GF_BaseInterface * ifce) | |
567 | GF_EXPORT | |
568 | void ShutdownInterface (GF_BaseInterface * ifce) | |
568 | 569 | { |
569 | 570 | if (ifce->InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) |
570 | 571 | DeleteJackOutput ((GF_AudioOutput *) ifce); |
1194 | 1194 | return si; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | GF_EXPORT | |
1197 | 1198 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
1198 | 1199 | { |
1199 | 1200 | switch (InterfaceType) { |
1204 | 1205 | } |
1205 | 1206 | } |
1206 | 1207 | |
1208 | GF_EXPORT | |
1207 | 1209 | void ShutdownInterface(GF_BaseInterface *ifce) |
1208 | 1210 | { |
1209 | 1211 | switch (ifce->InterfaceType) { |
106 | 106 | } |
107 | 107 | |
108 | 108 | |
109 | GF_EXPORT | |
109 | 110 | const u32 *QueryInterfaces() |
110 | 111 | { |
111 | 112 | static u32 si [] = { |
118 | 119 | return si; |
119 | 120 | } |
120 | 121 | |
122 | GF_EXPORT | |
121 | 123 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
122 | 124 | { |
123 | 125 | #if !defined(GPAC_DISABLE_AV_PARSERS) && !defined(GPAC_DISABLE_OGG) |
127 | 129 | return NULL; |
128 | 130 | } |
129 | 131 | |
132 | GF_EXPORT | |
130 | 133 | void ShutdownInterface(GF_BaseInterface *ifce) |
131 | 134 | { |
132 | 135 | switch (ifce->InterfaceType) { |
80 | 80 | count = gf_list_count(cfg->sequenceParameterSets); |
81 | 81 | SetCommandLayer(Layer, 255, 0, &i, 0);//bufindex can be reset without pb |
82 | 82 | for (i=0; i<count; i++) { |
83 | u32 w, h, par_n, par_d; | |
83 | u32 w=0, h=0, par_n=0, par_d=0; | |
84 | 84 | GF_AVCConfigSlot *slc = gf_list_get(cfg->sequenceParameterSets, i); |
85 | 85 | |
86 | #ifndef GPAC_DISABLE_AV_PARSERS | |
86 | 87 | gf_avc_get_sps_info(slc->data, slc->size, &slc->id, &w, &h, &par_n, &par_d); |
88 | #endif | |
87 | 89 | /*by default use the base layer*/ |
88 | 90 | if (!i) { |
89 | 91 | if ((ctx->width<w) || (ctx->height<h)) { |
339 | 341 | gf_free(ifcg); |
340 | 342 | } |
341 | 343 | |
344 | GF_EXPORT | |
342 | 345 | const u32 *QueryInterfaces() |
343 | 346 | { |
344 | 347 | static u32 si [] = { |
350 | 353 | return si; |
351 | 354 | } |
352 | 355 | |
356 | GF_EXPORT | |
353 | 357 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
354 | 358 | { |
355 | 359 | #ifndef GPAC_DISABLE_AV_PARSERS |
358 | 362 | return NULL; |
359 | 363 | } |
360 | 364 | |
365 | GF_EXPORT | |
361 | 366 | void ShutdownInterface(GF_BaseInterface *ifce) |
362 | 367 | { |
363 | 368 | switch (ifce->InterfaceType) { |
256 | 256 | * ******************************************************************** |
257 | 257 | * interface |
258 | 258 | */ |
259 | GF_EXPORT | |
259 | 260 | const u32 *QueryInterfaces() |
260 | 261 | { |
261 | 262 | static u32 si [] = { |
265 | 266 | return si; |
266 | 267 | } |
267 | 268 | |
269 | GF_EXPORT | |
268 | 270 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
269 | 271 | { |
270 | 272 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) |
272 | 274 | return NULL; |
273 | 275 | } |
274 | 276 | |
277 | GF_EXPORT | |
275 | 278 | void ShutdownInterface(GF_BaseInterface *ifce) |
276 | 279 | { |
277 | 280 | if (ifce->InterfaceType==GF_AUDIO_OUTPUT_INTERFACE) |
119 | 119 | m_pAVService->SetStateVariable("AbsoluteCounterPosition", "2147483647"); // means NOT_IMPLEMENTED |
120 | 120 | |
121 | 121 | // disable indirect eventing for certain state variables |
122 | PLT_StateVariable* var; | |
123 | var = m_pAVService->FindStateVariable("RelativeTimePosition"); | |
122 | //PLT_StateVariable* var; | |
123 | //var = | |
124 | m_pAVService->FindStateVariable("RelativeTimePosition"); | |
124 | 125 | //if (var) var->DisableIndirectEventing(); |
125 | var = m_pAVService->FindStateVariable("AbsoluteTimePosition"); | |
126 | //var = | |
127 | m_pAVService->FindStateVariable("AbsoluteTimePosition"); | |
126 | 128 | //if (var) var->DisableIndirectEventing(); |
127 | var = m_pAVService->FindStateVariable("RelativeCounterPosition"); | |
129 | //var = | |
130 | m_pAVService->FindStateVariable("RelativeCounterPosition"); | |
128 | 131 | //if (var) var->DisableIndirectEventing(); |
129 | var = m_pAVService->FindStateVariable("AbsoluteCounterPosition"); | |
132 | //var = | |
133 | m_pAVService->FindStateVariable("AbsoluteCounterPosition"); | |
130 | 134 | //if (var) var->DisableIndirectEventing(); |
131 | 135 | |
132 | 136 | // GetTransportInfo |
261 | 261 | case GF_EVENT_METADATA: |
262 | 262 | if (m_pTerm->root_scene) { |
263 | 263 | char szName[1024]; |
264 | const char *artist; | |
265 | 264 | NetInfoCommand com; |
266 | 265 | memset(&com, 0, sizeof(NetInfoCommand)); |
267 | 266 | |
271 | 270 | if (com.name) { strcat(szName, com.name); strcat(szName, " "); } |
272 | 271 | if (com.album) { strcat(szName, "("); strcat(szName, com.album); strcat(szName, ")"); } |
273 | 272 | |
274 | artist = "Unknown"; | |
273 | /*const char *artist = "Unknown"; | |
275 | 274 | if (com.artist) artist = com.artist; |
276 | 275 | else if (com.writer) artist = com.writer; |
277 | 276 | else if (com.composer) artist = com.composer; |
278 | 277 | |
279 | //MRSetMediaInfo(0, szName, com.artist ? com.artist : "Unknown"); | |
278 | MRSetMediaInfo(0, szName, com.artist ? com.artist : "Unknown");*/ | |
280 | 279 | } |
281 | 280 | } |
282 | 281 | break; |
319 | 319 | * ******************************************************************** |
320 | 320 | * interface |
321 | 321 | */ |
322 | GF_EXPORT | |
322 | 323 | const u32 *QueryInterfaces(u32 InterfaceType) |
323 | 324 | { |
324 | 325 | static u32 si [] = { |
328 | 329 | return si; |
329 | 330 | } |
330 | 331 | |
331 | GF_BaseInterface * | |
332 | LoadInterface (u32 InterfaceType) | |
332 | GF_EXPORT | |
333 | GF_BaseInterface *LoadInterface (u32 InterfaceType) | |
333 | 334 | { |
334 | 335 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) |
335 | 336 | return NewPulseAudioOutput (); |
336 | 337 | return NULL; |
337 | 338 | } |
338 | 339 | |
339 | void | |
340 | ShutdownInterface (GF_BaseInterface * ifce) | |
340 | GF_EXPORT | |
341 | void ShutdownInterface (GF_BaseInterface * ifce) | |
341 | 342 | { |
342 | 343 | if (ifce->InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) |
343 | 344 | DeletePulseAudioOutput ((GF_AudioOutput *) ifce); |
151 | 151 | }; |
152 | 152 | return si; |
153 | 153 | } |
154 | ||
154 | 155 | /*interface create*/ |
156 | GF_EXPORT | |
155 | 157 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
156 | 158 | { |
157 | 159 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return (GF_BaseInterface *) NewRawVideoOutput(); |
158 | 160 | return NULL; |
159 | 161 | } |
162 | ||
160 | 163 | /*interface destroy*/ |
164 | GF_EXPORT | |
161 | 165 | void ShutdownInterface(GF_BaseInterface *ifce) |
162 | 166 | { |
163 | 167 | switch (ifce->InterfaceType) { |
415 | 415 | gf_free(ifcg); |
416 | 416 | } |
417 | 417 | |
418 | GF_EXPORT | |
418 | 419 | const u32 *QueryInterfaces() |
419 | 420 | { |
420 | 421 | static u32 si [] = { |
426 | 427 | return si; |
427 | 428 | } |
428 | 429 | |
430 | GF_EXPORT | |
429 | 431 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
430 | 432 | { |
431 | 433 | #ifndef GPAC_DISABLE_AV_PARSERS |
434 | 436 | return NULL; |
435 | 437 | } |
436 | 438 | |
439 | GF_EXPORT | |
437 | 440 | void ShutdownInterface(GF_BaseInterface *ifce) |
438 | 441 | { |
439 | 442 | switch (ifce->InterfaceType) { |
49 | 49 | |
50 | 50 | |
51 | 51 | /*interface query*/ |
52 | GF_EXPORT | |
52 | 53 | const u32 *QueryInterfaces() |
53 | 54 | { |
54 | 55 | static u32 si [] = { |
58 | 59 | }; |
59 | 60 | return si; |
60 | 61 | } |
62 | ||
61 | 63 | /*interface create*/ |
64 | GF_EXPORT | |
62 | 65 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
63 | 66 | { |
64 | 67 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return SDL_NewVideo(); |
65 | 68 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) return SDL_NewAudio(); |
66 | 69 | return NULL; |
67 | 70 | } |
71 | ||
68 | 72 | /*interface destroy*/ |
73 | GF_EXPORT | |
69 | 74 | void ShutdownInterface(GF_BaseInterface *ifce) |
70 | 75 | { |
71 | 76 | switch (ifce->InterfaceType) { |
463 | 463 | gf_free(dr); |
464 | 464 | } |
465 | 465 | |
466 | GF_EXPORT | |
466 | 467 | const u32 *QueryInterfaces() |
467 | 468 | { |
468 | 469 | static u32 si [] = { |
472 | 473 | return si; |
473 | 474 | } |
474 | 475 | |
476 | GF_EXPORT | |
475 | 477 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
476 | 478 | { |
477 | 479 | if (InterfaceType == GF_AUDIO_OUTPUT_INTERFACE) return NewWAVRender(); |
478 | 480 | return NULL; |
479 | 481 | } |
480 | 482 | |
483 | GF_EXPORT | |
481 | 484 | void ShutdownInterface(GF_BaseInterface *ifce) |
482 | 485 | { |
483 | 486 | switch (ifce->InterfaceType) { |
3 | 3 | |
4 | 4 | Copyright (C) 1998-2005 Gilles Vollant |
5 | 5 | */ |
6 | ||
7 | 6 | |
8 | 7 | #include <stdio.h> |
9 | 8 | #include <stdlib.h> |
24 | 23 | #endif |
25 | 24 | |
26 | 25 | #endif |
26 | ||
27 | //hack: prevent mozilla to redifine z functions | |
28 | #define MOZZCONF_H | |
27 | 29 | |
28 | 30 | #include "unzip.h" |
29 | 31 | #include <gpac/tools.h> |
1 | 1 | |
2 | 2 | vpath %.c $(SRC_PATH)/modules/x11_out |
3 | 3 | |
4 | CFLAGS= $(OPTFLAGS) | |
4 | CFLAGS= $(OPTFLAGS) -Wno-deprecated-declarations | |
5 | 5 | |
6 | 6 | ifeq ($(DEBUGBUILD), yes) |
7 | 7 | CFLAGS+=-g |
1439 | 1439 | /* |
1440 | 1440 | * interface query |
1441 | 1441 | */ |
1442 | GF_EXPORT | |
1442 | 1443 | const u32 *QueryInterfaces() |
1443 | 1444 | { |
1444 | 1445 | static u32 si [] = { |
1452 | 1453 | /* |
1453 | 1454 | * interface create |
1454 | 1455 | */ |
1455 | GF_BaseInterface * | |
1456 | LoadInterface (u32 InterfaceType) | |
1456 | GF_EXPORT | |
1457 | GF_BaseInterface *LoadInterface (u32 InterfaceType) | |
1457 | 1458 | { |
1458 | 1459 | if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) |
1459 | 1460 | return (GF_BaseInterface *) NewX11VideoOutput (); |
1464 | 1465 | /* |
1465 | 1466 | * interface destroy |
1466 | 1467 | */ |
1467 | void | |
1468 | ShutdownInterface (GF_BaseInterface *ifce) | |
1468 | GF_EXPORT | |
1469 | void ShutdownInterface (GF_BaseInterface *ifce) | |
1469 | 1470 | { |
1470 | 1471 | switch (ifce->InterfaceType) |
1471 | 1472 | { |
464 | 464 | |
465 | 465 | #endif /*GPAC_DISABLE_AV_PARSERS*/ |
466 | 466 | |
467 | ||
468 | GF_EXPORT | |
467 | 469 | const u32 *QueryInterfaces() |
468 | 470 | { |
469 | 471 | static u32 si [] = { |
475 | 477 | return si; |
476 | 478 | } |
477 | 479 | |
480 | GF_EXPORT | |
478 | 481 | GF_BaseInterface *LoadInterface(u32 InterfaceType) |
479 | 482 | { |
480 | 483 | #ifndef GPAC_DISABLE_AV_PARSERS |
483 | 486 | return NULL; |
484 | 487 | } |
485 | 488 | |
489 | GF_EXPORT | |
486 | 490 | void ShutdownInterface(GF_BaseInterface *ifce) |
487 | 491 | { |
488 | 492 | switch (ifce->InterfaceType) { |
99 | 99 | Shape { |
100 | 100 | appearance Appearance { |
101 | 101 | # material Material { emissiveColor 0 1 0} |
102 | texture ImageTexture { url './../auxiliary_files/logo.jpg"} | |
102 | texture ImageTexture { url "./../auxiliary_files/logo.jpg"} | |
103 | 103 | } |
104 | 104 | geometry Box { size 20 20 20} |
105 | 105 | } |
281 | 281 | while ((l = gf_list_enum(ar->audio_listeners, &k))) { |
282 | 282 | l->on_audio_reconfig(l->udta, in_freq, in_bps, in_ch, in_cfg); |
283 | 283 | } |
284 | } | |
285 | ||
284 | } | |
286 | 285 | return GF_OK; |
287 | 286 | } |
288 | ||
289 | 287 | |
290 | 288 | |
291 | 289 | static u32 gf_ar_fill_output(void *ptr, char *buffer, u32 buffer_size) |
634 | 632 | if (ar->Frozen) return ar->FreezeTime - ar->startTime; |
635 | 633 | return gf_sys_clock() - ar->startTime; |
636 | 634 | } |
635 | ||
636 | GF_EXPORT | |
637 | 637 | void gf_sc_reload_audio_filters(GF_Compositor *compositor) |
638 | 638 | { |
639 | 639 | GF_AudioRenderer *ar = compositor->audio_renderer; |
655 | 655 | |
656 | 656 | GF_Err gf_sc_add_audio_listener(GF_Compositor *compositor, GF_AudioListener *al) |
657 | 657 | { |
658 | GF_AudioMixer *mixer; | |
659 | u32 sr, ch, bps, ch_cfg; | |
658 | 660 | if (!compositor || !al || !al->on_audio_frame || !al->on_audio_reconfig) return GF_BAD_PARAM; |
659 | 661 | if (!compositor->audio_renderer) return GF_NOT_SUPPORTED; |
660 | 662 | |
661 | gf_mixer_lock(compositor->audio_renderer->mixer, 1); | |
663 | mixer = compositor->audio_renderer->mixer; | |
664 | gf_mixer_lock(mixer, 1); | |
665 | ||
662 | 666 | if (!compositor->audio_renderer->audio_listeners) compositor->audio_renderer->audio_listeners = gf_list_new(); |
663 | 667 | gf_list_add(compositor->audio_renderer->audio_listeners, al); |
664 | gf_mixer_lock(compositor->audio_renderer->mixer, 0); | |
668 | ||
669 | gf_mixer_get_config(mixer, &sr, &ch, &bps, &ch_cfg); | |
670 | ||
671 | al->on_audio_reconfig(al->udta, sr, bps, ch, ch_cfg); | |
672 | ||
673 | gf_mixer_lock(mixer, 0); | |
665 | 674 | return GF_OK; |
666 | 675 | } |
667 | 676 |
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
971 | GF_EXPORT | |
971 | 972 | GF_Err gf_sc_set_size(GF_Compositor *compositor, u32 NewWidth, u32 NewHeight) |
972 | 973 | { |
973 | 974 | Bool lock_ok; |
1278 | 1279 | gf_sc_lock(compositor, 0); |
1279 | 1280 | } |
1280 | 1281 | |
1282 | GF_EXPORT | |
1281 | 1283 | GF_Err gf_sc_set_option(GF_Compositor *compositor, u32 type, u32 value) |
1282 | 1284 | { |
1283 | 1285 | GF_Err e; |
1621 | 1623 | } |
1622 | 1624 | |
1623 | 1625 | |
1626 | GF_EXPORT | |
1624 | 1627 | GF_Err gf_sc_get_screen_buffer(GF_Compositor *compositor, GF_VideoSurface *framebuffer, u32 depth_dump_mode) |
1625 | 1628 | { |
1626 | 1629 | GF_Err e; |
1655 | 1658 | } |
1656 | 1659 | |
1657 | 1660 | |
1661 | GF_EXPORT | |
1658 | 1662 | GF_Err gf_sc_release_screen_buffer(GF_Compositor *compositor, GF_VideoSurface *framebuffer) |
1659 | 1663 | { |
1660 | 1664 | GF_Err e; |
1670 | 1674 | return e; |
1671 | 1675 | } |
1672 | 1676 | |
1677 | GF_EXPORT | |
1673 | 1678 | Double gf_sc_get_fps(GF_Compositor *compositor, Bool absoluteFPS) |
1674 | 1679 | { |
1675 | 1680 | Double fps; |
2702 | 2707 | } |
2703 | 2708 | } |
2704 | 2709 | |
2710 | GF_EXPORT | |
2705 | 2711 | void gf_sc_register_extra_graph(GF_Compositor *compositor, GF_SceneGraph *extra_scene, Bool do_remove) |
2706 | 2712 | { |
2707 | 2713 | gf_sc_lock(compositor, 1); |
1749 | 1749 | return browse_parent_for_focus(compositor, (GF_Node*)par, prev_focus); |
1750 | 1750 | } |
1751 | 1751 | |
1752 | GF_EXPORT | |
1752 | 1753 | u32 gf_sc_focus_switch_ring(GF_Compositor *compositor, Bool move_prev, GF_Node *focus, u32 force_focus) |
1753 | 1754 | { |
1754 | 1755 | Bool current_focus = 1; |
250 | 250 | DestroyTransform(n); |
251 | 251 | return; |
252 | 252 | } |
253 | if (! tr_state->camera) return; | |
253 | 254 | |
254 | 255 | /*can't cache the matrix here*/ |
255 | 256 | gf_mx_init(st->mx); |
347 | 348 | return; |
348 | 349 | } |
349 | 350 | |
350 | ||
351 | ||
352 | 351 | /*WARNING: X3D/MPEG4 NOT COMPATIBLE*/ |
353 | 352 | if (gf_node_get_tag(node) == TAG_MPEG4_LOD) { |
354 | 353 | children = ((M_LOD *) node)->level; |
365 | 364 | if (!children) return; |
366 | 365 | nb_children = gf_node_list_get_count(children); |
367 | 366 | |
368 | /*can't cache the matric here*/ | |
369 | usr = tr_state->camera->position; | |
370 | pos = center; | |
371 | gf_mx_copy(mx, tr_state->model_matrix); | |
372 | gf_mx_inverse(&mx); | |
373 | gf_mx_apply_vec(&mx, &usr); | |
374 | gf_vec_diff(pos, pos, usr); | |
375 | dist = gf_vec_len(pos); | |
376 | for (which_child=0; which_child<ranges->count; which_child++) { | |
377 | if (dist<ranges->vals[which_child]) break; | |
378 | } | |
379 | if (which_child>=nb_children) which_child = nb_children-1; | |
380 | ||
381 | /*check if we're traversing the same child or not for audio rendering*/ | |
382 | do_all = 0; | |
383 | if (gf_node_dirty_get(node)) { | |
384 | gf_node_dirty_clear(node, 0); | |
367 | if (!tr_state->camera) { | |
385 | 368 | do_all = 1; |
386 | } else if ((s32) which_child != *prev_child) { | |
387 | *prev_child = which_child; | |
388 | do_all = 1; | |
369 | which_child = 0; | |
370 | } else { | |
371 | /*can't cache the matrix here*/ | |
372 | usr = tr_state->camera->position; | |
373 | pos = center; | |
374 | gf_mx_copy(mx, tr_state->model_matrix); | |
375 | gf_mx_inverse(&mx); | |
376 | gf_mx_apply_vec(&mx, &usr); | |
377 | gf_vec_diff(pos, pos, usr); | |
378 | dist = gf_vec_len(pos); | |
379 | for (which_child=0; which_child<ranges->count; which_child++) { | |
380 | if (dist<ranges->vals[which_child]) break; | |
381 | } | |
382 | if (which_child>=nb_children) which_child = nb_children-1; | |
383 | ||
384 | /*check if we're traversing the same child or not for audio rendering*/ | |
385 | do_all = 0; | |
386 | if (gf_node_dirty_get(node)) { | |
387 | gf_node_dirty_clear(node, 0); | |
388 | do_all = 1; | |
389 | } else if ((s32) which_child != *prev_child) { | |
390 | *prev_child = which_child; | |
391 | do_all = 1; | |
392 | } | |
389 | 393 | } |
390 | 394 | |
391 | 395 | if (do_all) { |
1396 | 1396 | return NULL; |
1397 | 1397 | } |
1398 | 1398 | |
1399 | GF_EXPORT | |
1399 | 1400 | GF_SceneGraph *gf_sc_animation_get_scenegraph(GF_Node *node) |
1400 | 1401 | { |
1401 | 1402 | SVGlinkStack *stack; |
126 | 126 | return GF_OK; |
127 | 127 | } |
128 | 128 | |
129 | GF_EXPORT | |
129 | 130 | GF_RTPStreamer *gf_rtp_streamer_new_extended(u32 streamType, u32 oti, u32 timeScale, |
130 | 131 | const char *ip_dest, u16 port, u32 MTU, u8 TTL, const char *ifce_addr, |
131 | 132 | u32 flags, char *dsi, u32 dsi_len, |
455 | 456 | } |
456 | 457 | |
457 | 458 | |
459 | GF_EXPORT | |
458 | 460 | GF_RTPStreamer *gf_rtp_streamer_new(u32 streamType, u32 oti, u32 timeScale, |
459 | 461 | const char *ip_dest, u16 port, u32 MTU, u8 TTL, const char *ifce_addr, |
460 | 462 | u32 flags, char *dsi, u32 dsi_len) |
465 | 467 | |
466 | 468 | } |
467 | 469 | |
470 | GF_EXPORT | |
468 | 471 | void gf_rtp_streamer_del(GF_RTPStreamer *streamer) |
469 | 472 | { |
470 | 473 | if (streamer) { |
520 | 523 | #endif /*!defined(GPAC_DISABLE_ISOM) && !defined(GPAC_DISABLE_STREAMING)*/ |
521 | 524 | |
522 | 525 | |
526 | GF_EXPORT | |
523 | 527 | GF_Err gf_rtp_streamer_append_sdp_extended(GF_RTPStreamer *rtp, u16 ESID, char *dsi, u32 dsi_len, GF_ISOFile *isofile, u32 isotrack, char *KMS_URI, u32 width, u32 height, char **out_sdp_buffer) |
524 | 528 | { |
525 | 529 | u32 size; |
665 | 669 | return GF_OK; |
666 | 670 | } |
667 | 671 | |
672 | GF_EXPORT | |
668 | 673 | char *gf_rtp_streamer_format_sdp_header(char *app_name, char *ip_dest, char *session_name, char *iod64) |
669 | 674 | { |
670 | 675 | u64 size; |
691 | 696 | return sdp; |
692 | 697 | } |
693 | 698 | |
699 | GF_EXPORT | |
694 | 700 | GF_Err gf_rtp_streamer_append_sdp(GF_RTPStreamer *rtp, u16 ESID, char *dsi, u32 dsi_len, char *KMS_URI, char **out_sdp_buffer) |
695 | 701 | { |
696 | 702 | return gf_rtp_streamer_append_sdp_extended(rtp, ESID, dsi, dsi_len, NULL, 0, KMS_URI, 0, 0, out_sdp_buffer); |
715 | 721 | return gf_rtp_streamer_send_data(rtp, data, size, size, cts, dts, is_rap, 1, 1, 0, 0, 0); |
716 | 722 | } |
717 | 723 | |
724 | GF_EXPORT | |
718 | 725 | GF_Err gf_rtp_streamer_send_au_with_sn(GF_RTPStreamer *rtp, char *data, u32 size, u64 cts, u64 dts, Bool is_rap, u32 inc_au_sn) |
719 | 726 | { |
720 | 727 | if (inc_au_sn) rtp->packetizer->sl_header.AU_sequenceNumber += inc_au_sn; |
721 | 728 | return gf_rtp_streamer_send_data(rtp, data, size, size, cts, dts, is_rap, 1, 1, rtp->packetizer->sl_header.AU_sequenceNumber, 0, 0); |
722 | 729 | } |
723 | 730 | |
731 | GF_EXPORT | |
724 | 732 | void gf_rtp_streamer_disable_auto_rtcp(GF_RTPStreamer *streamer) |
725 | 733 | { |
726 | 734 | streamer->channel->no_auto_rtcp = 1; |
727 | 735 | } |
728 | 736 | |
737 | GF_EXPORT | |
729 | 738 | GF_Err gf_rtp_streamer_send_rtcp(GF_RTPStreamer *streamer, Bool force_ts, u32 rtp_ts) |
730 | 739 | { |
731 | 740 | if (force_ts) streamer->channel->last_pck_ts = rtp_ts; |
255 | 255 | return GF_OK; |
256 | 256 | } |
257 | 257 | |
258 | GF_EXPORT | |
258 | 259 | GF_Err gf_isom_avc_config_update(GF_ISOFile *the_file, u32 trackNumber, u32 DescriptionIndex, GF_AVCConfig *cfg) |
259 | 260 | { |
260 | 261 | return gf_isom_avc_config_update_ex(the_file, trackNumber, DescriptionIndex, cfg, 0); |
265 | 266 | return gf_isom_avc_config_update_ex(the_file, trackNumber, DescriptionIndex, cfg, is_add ? 1 : 2); |
266 | 267 | } |
267 | 268 | |
269 | GF_EXPORT | |
268 | 270 | GF_Err gf_isom_set_ipod_compatible(GF_ISOFile *the_file, u32 trackNumber) |
269 | 271 | { |
270 | 272 | static const u8 ipod_ext[][16] = { { 0x6B, 0x68, 0x40, 0xF2, 0x5F, 0x24, 0x4F, 0xC5, 0xBA, 0x39, 0xA5, 0x1B, 0xCF, 0x03, 0x23, 0xF3} }; |
3106 | 3106 | fprintf(trace, "\" "); |
3107 | 3107 | } |
3108 | 3108 | |
3109 | GF_EXPORT | |
3109 | 3110 | GF_Err gf_isom_dump_ismacryp_protection(GF_ISOFile *the_file, u32 trackNumber, FILE * trace) |
3110 | 3111 | { |
3111 | 3112 | u32 i, count; |
3138 | 3139 | return GF_OK; |
3139 | 3140 | } |
3140 | 3141 | |
3142 | GF_EXPORT | |
3141 | 3143 | GF_Err gf_isom_dump_ismacryp_sample(GF_ISOFile *the_file, u32 trackNumber, u32 SampleNum, FILE * trace) |
3142 | 3144 | { |
3143 | 3145 | GF_ISOSample *samp; |
3234 | 3236 | break; |
3235 | 3237 | default: |
3236 | 3238 | if (strcmp(name, "Unknown")) { |
3237 | if (itune->data->data[0]) { | |
3239 | if (itune->data && itune->data->data[0]) { | |
3238 | 3240 | fprintf(trace, " value=\"%s\" ", itune->data->data); |
3239 | 3241 | } else { |
3240 | 3242 | fprintf(trace, " value=\""); |
3246 | 3248 | } |
3247 | 3249 | } |
3248 | 3250 | fprintf(trace, ">\n"); |
3249 | gf_full_box_dump((GF_Box *)itune->data, trace); | |
3251 | if (itune->data) | |
3252 | gf_full_box_dump((GF_Box *)itune->data, trace); | |
3250 | 3253 | DumpBox(a, trace); |
3251 | 3254 | fprintf(trace, "</%sBox>\n", name); |
3252 | 3255 | return GF_OK; |
255 | 255 | } |
256 | 256 | |
257 | 257 | |
258 | GF_EXPORT | |
258 | 259 | GF_Err gf_isom_box_write_header(GF_Box *ptr, GF_BitStream *bs) |
259 | 260 | { |
260 | 261 | if (! bs || !ptr) return GF_BAD_PARAM; |
323 | 324 | |
324 | 325 | #endif /*GPAC_DISABLE_ISOM_WRITE*/ |
325 | 326 | |
327 | GF_EXPORT | |
326 | 328 | GF_Box *gf_isom_box_new(u32 boxType) |
327 | 329 | { |
328 | 330 | GF_Box *a; |
579 | 581 | } |
580 | 582 | |
581 | 583 | |
584 | GF_EXPORT | |
582 | 585 | void gf_isom_box_del(GF_Box *a) |
583 | 586 | { |
584 | 587 | if (!a) return; |
1062 | 1065 | |
1063 | 1066 | #ifndef GPAC_DISABLE_ISOM_WRITE |
1064 | 1067 | |
1068 | GF_EXPORT | |
1065 | 1069 | GF_Err gf_isom_box_write(GF_Box *a, GF_BitStream *bs) |
1066 | 1070 | { |
1067 | 1071 | switch (a->type) { |
1295 | 1299 | } |
1296 | 1300 | |
1297 | 1301 | |
1302 | GF_EXPORT | |
1298 | 1303 | GF_Err gf_isom_box_size(GF_Box *a) |
1299 | 1304 | { |
1300 | 1305 | switch (a->type) { |
709 | 709 | } |
710 | 710 | |
711 | 711 | //add an SDP line to the SDP container at the track level (media-specific SDP info) |
712 | GF_EXPORT | |
712 | 713 | GF_Err gf_isom_sdp_add_track_line(GF_ISOFile *the_file, u32 trackNumber, const char *text) |
713 | 714 | { |
714 | 715 | GF_TrackBox *trak; |
783 | 784 | |
784 | 785 | //add an SDP line to the SDP container at the movie level (presentation SDP info) |
785 | 786 | //NOTE: the \r\n end of line for SDP is automatically inserted |
787 | GF_EXPORT | |
786 | 788 | GF_Err gf_isom_sdp_add_line(GF_ISOFile *movie, const char *text) |
787 | 789 | { |
788 | 790 | GF_UserDataMap *map; |
844 | 846 | |
845 | 847 | |
846 | 848 | //remove all SDP info at the movie level |
849 | GF_EXPORT | |
847 | 850 | GF_Err gf_isom_sdp_clean(GF_ISOFile *movie) |
848 | 851 | { |
849 | 852 | GF_UserDataMap *map; |
332 | 332 | return GF_OK; |
333 | 333 | } |
334 | 334 | |
335 | GF_EXPORT | |
335 | 336 | GF_Err gf_isom_change_ismacryp_protection(GF_ISOFile *the_file, u32 trackNumber, u32 StreamDescriptionIndex, char *scheme_uri, char *kms_uri) |
336 | 337 | { |
337 | 338 | GF_TrackBox *trak; |
1991 | 1991 | return GF_OK; |
1992 | 1992 | } |
1993 | 1993 | |
1994 | GF_EXPORT | |
1994 | 1995 | GF_Err gf_isom_open_segment(GF_ISOFile *movie, const char *fileName, u64 start_range, u64 end_range) |
1995 | 1996 | { |
1996 | 1997 | #ifdef GPAC_DISABLE_ISOM_FRAGMENTS |
2294 | 2295 | |
2295 | 2296 | |
2296 | 2297 | /*returns total amount of media bytes in track*/ |
2298 | GF_EXPORT | |
2297 | 2299 | u64 gf_isom_get_media_data_size(GF_ISOFile *movie, u32 trackNumber) |
2298 | 2300 | { |
2299 | 2301 | u32 i, size; |
2613 | 2615 | return GF_OK; |
2614 | 2616 | } |
2615 | 2617 | |
2618 | GF_EXPORT | |
2616 | 2619 | u32 gf_isom_get_next_alternate_group_id(GF_ISOFile *movie) |
2617 | 2620 | { |
2618 | 2621 | u32 id = 0; |
2649 | 2652 | return GF_OK; |
2650 | 2653 | } |
2651 | 2654 | |
2655 | GF_EXPORT | |
2652 | 2656 | GF_Err gf_isom_get_rvc_config(GF_ISOFile *movie, u32 track, u32 sampleDescriptionIndex, u16 *rvc_predefined, char **data, u32 *size, const char **mime) |
2653 | 2657 | { |
2654 | 2658 | GF_MPEGVisualSampleEntryBox *entry; |
2695 | 2699 | return 0; |
2696 | 2700 | } |
2697 | 2701 | |
2702 | GF_EXPORT | |
2698 | 2703 | void gf_isom_reset_fragment_info(GF_ISOFile *movie) |
2699 | 2704 | { |
2700 | 2705 | u32 i; |
136 | 136 | } |
137 | 137 | |
138 | 138 | //remove the root OD |
139 | GF_EXPORT | |
139 | 140 | GF_Err gf_isom_remove_root_od(GF_ISOFile *movie) |
140 | 141 | { |
141 | 142 | GF_Err e; |
149 | 150 | } |
150 | 151 | |
151 | 152 | //remove a track to the root OD |
153 | GF_EXPORT | |
152 | 154 | GF_Err gf_isom_remove_track_from_root_od(GF_ISOFile *movie, u32 trackNumber) |
153 | 155 | { |
154 | 156 | GF_List *esds; |
231 | 233 | return GF_OK; |
232 | 234 | } |
233 | 235 | |
236 | GF_EXPORT | |
234 | 237 | GF_Err gf_isom_set_media_language(GF_ISOFile *movie, u32 trackNumber, char *three_char_code) |
235 | 238 | { |
236 | 239 | GF_Err e; |
312 | 315 | } |
313 | 316 | |
314 | 317 | |
318 | GF_EXPORT | |
315 | 319 | GF_Err gf_isom_set_timescale(GF_ISOFile *movie, u32 timeScale) |
316 | 320 | { |
317 | 321 | GF_Err e; |
324 | 328 | return GF_OK; |
325 | 329 | } |
326 | 330 | |
331 | ||
332 | GF_EXPORT | |
327 | 333 | GF_Err gf_isom_set_pl_indication(GF_ISOFile *movie, u8 PL_Code, u8 ProfileLevel) |
328 | 334 | { |
329 | 335 | GF_IsomInitialObjectDescriptor *iod; |
775 | 781 | //you must have created a StreamDescription with URL or URN specifying your referenced file |
776 | 782 | //the data offset specifies the begining of the chunk |
777 | 783 | //Use streamDescriptionIndex to specify the desired stream (if several) |
784 | GF_EXPORT | |
778 | 785 | GF_Err gf_isom_add_sample_reference(GF_ISOFile *movie, u32 trackNumber, u32 StreamDescriptionIndex, GF_ISOSample *sample, u64 dataOffset) |
779 | 786 | { |
780 | 787 | GF_TrackBox *trak; |
829 | 836 | |
830 | 837 | //set the duration of the last media sample. If not set, the duration of the last sample is the |
831 | 838 | //duration of the previous one if any, or 1000 (default value). |
839 | GF_EXPORT | |
832 | 840 | GF_Err gf_isom_set_last_sample_duration(GF_ISOFile *movie, u32 trackNumber, u32 duration) |
833 | 841 | { |
834 | 842 | GF_TrackBox *trak; |
850 | 858 | ent = (GF_SttsEntry*) &stts->entries[stts->nb_entries-1]; |
851 | 859 | |
852 | 860 | mdur -= ent->sampleDelta; |
853 | if (duration) { | |
854 | mdur += duration; | |
855 | //we only have one sample | |
856 | if (ent->sampleCount == 1) { | |
857 | ent->sampleDelta = duration; | |
858 | } else { | |
859 | if (ent->sampleDelta == duration) return GF_OK; | |
860 | ent->sampleCount -= 1; | |
861 | ||
862 | if (stts->nb_entries==stts->alloc_size) { | |
863 | stts->alloc_size++; | |
864 | stts->entries = gf_realloc(stts->entries, sizeof(GF_SttsEntry)*stts->alloc_size); | |
865 | if (!stts->entries) return GF_OUT_OF_MEM; | |
866 | } | |
867 | stts->entries[stts->nb_entries].sampleCount = 1; | |
868 | stts->entries[stts->nb_entries].sampleDelta = duration; | |
869 | stts->nb_entries++; | |
870 | //and update the write cache | |
871 | stts->w_currentSampleNum = trak->Media->information->sampleTable->SampleSize->sampleCount; | |
872 | } | |
861 | mdur += duration; | |
862 | //we only have one sample | |
863 | if (ent->sampleCount == 1) { | |
864 | ent->sampleDelta = duration; | |
865 | } else { | |
866 | if (ent->sampleDelta == duration) return GF_OK; | |
867 | ent->sampleCount -= 1; | |
868 | ||
869 | if (stts->nb_entries==stts->alloc_size) { | |
870 | stts->alloc_size++; | |
871 | stts->entries = gf_realloc(stts->entries, sizeof(GF_SttsEntry)*stts->alloc_size); | |
872 | if (!stts->entries) return GF_OUT_OF_MEM; | |
873 | } | |
874 | stts->entries[stts->nb_entries].sampleCount = 1; | |
875 | stts->entries[stts->nb_entries].sampleDelta = duration; | |
876 | stts->nb_entries++; | |
877 | //and update the write cache | |
878 | stts->w_currentSampleNum = trak->Media->information->sampleTable->SampleSize->sampleCount; | |
873 | 879 | } |
874 | 880 | trak->Media->mediaHeader->modificationTime = gf_isom_get_mp4time(); |
875 | 881 | trak->Media->mediaHeader->duration = mdur; |
943 | 949 | |
944 | 950 | |
945 | 951 | //Remove a given sample |
952 | GF_EXPORT | |
946 | 953 | GF_Err gf_isom_remove_sample(GF_ISOFile *movie, u32 trackNumber, u32 sampleNumber) |
947 | 954 | { |
948 | 955 | GF_Err e; |
998 | 1005 | } |
999 | 1006 | |
1000 | 1007 | |
1008 | GF_EXPORT | |
1001 | 1009 | GF_Err gf_isom_set_final_name(GF_ISOFile *movie, char *filename) |
1002 | 1010 | { |
1003 | 1011 | GF_Err e; |
1099 | 1107 | |
1100 | 1108 | //use carefully. Very usefull when you made a lot of changes (IPMP, IPI, OCI, ...) |
1101 | 1109 | //THIS WILL REPLACE THE WHOLE DESCRIPTOR ... |
1110 | GF_EXPORT | |
1102 | 1111 | GF_Err gf_isom_change_mpeg4_description(GF_ISOFile *movie, u32 trackNumber, u32 StreamDescriptionIndex, GF_ESD *newESD) |
1103 | 1112 | { |
1104 | 1113 | GF_Err e; |
1265 | 1274 | } |
1266 | 1275 | |
1267 | 1276 | //set the storage mode of a file (FLAT, STREAMABLE, INTERLEAVED) |
1277 | GF_EXPORT | |
1268 | 1278 | GF_Err gf_isom_set_storage_mode(GF_ISOFile *movie, u8 storageMode) |
1269 | 1279 | { |
1270 | 1280 | GF_Err e; |
1288 | 1298 | //update or insert a new edit segment in the track time line. Edits are used to modify |
1289 | 1299 | //the media normal timing. EditTime and EditDuration are expressed in Movie TimeScale |
1290 | 1300 | //If a segment with EditTime already exists, IT IS ERASED |
1301 | GF_EXPORT | |
1291 | 1302 | GF_Err gf_isom_set_edit_segment(GF_ISOFile *movie, u32 trackNumber, u64 EditTime, u64 EditDuration, u64 MediaTime, u8 EditMode) |
1292 | 1303 | { |
1293 | 1304 | GF_TrackBox *trak; |
1378 | 1389 | } |
1379 | 1390 | |
1380 | 1391 | //remove the edit segments for the whole track |
1392 | GF_EXPORT | |
1381 | 1393 | GF_Err gf_isom_remove_edit_segments(GF_ISOFile *movie, u32 trackNumber) |
1382 | 1394 | { |
1383 | 1395 | GF_Err e; |
1428 | 1440 | } |
1429 | 1441 | |
1430 | 1442 | |
1443 | GF_EXPORT | |
1431 | 1444 | GF_Err gf_isom_append_edit_segment(GF_ISOFile *movie, u32 trackNumber, u64 EditDuration, u64 MediaTime, u8 EditMode) |
1432 | 1445 | { |
1433 | 1446 | GF_Err e; |
1470 | 1483 | return SetTrackDuration(trak); |
1471 | 1484 | } |
1472 | 1485 | |
1486 | GF_EXPORT | |
1473 | 1487 | GF_Err gf_isom_modify_edit_segment(GF_ISOFile *movie, u32 trackNumber, u32 seg_index, u64 EditDuration, u64 MediaTime, u8 EditMode) |
1474 | 1488 | { |
1475 | 1489 | GF_Err e; |
1503 | 1517 | } |
1504 | 1518 | |
1505 | 1519 | //removes the desired track |
1520 | GF_EXPORT | |
1506 | 1521 | GF_Err gf_isom_remove_track(GF_ISOFile *movie, u32 trackNumber) |
1507 | 1522 | { |
1508 | 1523 | GF_Err e; |
1621 | 1636 | } |
1622 | 1637 | |
1623 | 1638 | |
1639 | GF_EXPORT | |
1624 | 1640 | GF_Err gf_isom_set_copyright(GF_ISOFile *movie, const char *threeCharCode, char *notice) |
1625 | 1641 | { |
1626 | 1642 | GF_Err e; |
1663 | 1679 | return udta_AddBox(movie->moov->udta, (GF_Box *) ptr); |
1664 | 1680 | } |
1665 | 1681 | |
1682 | GF_EXPORT | |
1666 | 1683 | GF_Err gf_isom_add_chapter(GF_ISOFile *movie, u32 trackNumber, u64 timestamp, char *name) |
1667 | 1684 | { |
1668 | 1685 | GF_Err e; |
1948 | 1965 | } |
1949 | 1966 | |
1950 | 1967 | |
1951 | ||
1968 | GF_EXPORT | |
1952 | 1969 | GF_Err gf_isom_set_brand_info(GF_ISOFile *movie, u32 MajorBrand, u32 MinorVersion) |
1953 | 1970 | { |
1954 | 1971 | u32 i, *p; |
1994 | 2011 | return GF_OK; |
1995 | 2012 | } |
1996 | 2013 | |
2014 | ||
2015 | GF_EXPORT | |
1997 | 2016 | GF_Err gf_isom_modify_alternate_brand(GF_ISOFile *movie, u32 Brand, u8 AddIt) |
1998 | 2017 | { |
1999 | 2018 | u32 i, k, *p; |
2257 | 2276 | } |
2258 | 2277 | |
2259 | 2278 | |
2279 | GF_EXPORT | |
2260 | 2280 | GF_Err gf_isom_remove_sample_fragment(GF_ISOFile *movie, u32 trackNumber, u32 sampleNumber) |
2261 | 2281 | { |
2262 | 2282 | GF_TrackBox *trak; |
2288 | 2308 | return GF_OK; |
2289 | 2309 | } |
2290 | 2310 | |
2311 | GF_EXPORT | |
2291 | 2312 | GF_Err gf_isom_clone_pl_indications(GF_ISOFile *orig, GF_ISOFile *dest) |
2292 | 2313 | { |
2293 | 2314 | GF_IsomInitialObjectDescriptor *iod_d; |
2393 | 2414 | } |
2394 | 2415 | |
2395 | 2416 | |
2396 | ||
2417 | GF_EXPORT | |
2397 | 2418 | GF_Err gf_isom_clone_track(GF_ISOFile *orig_file, u32 orig_track, GF_ISOFile *dest_file, Bool keep_data_ref, u32 *dest_track) |
2398 | 2419 | { |
2399 | 2420 | GF_TrackBox *trak, *new_tk; |
2516 | 2537 | return e; |
2517 | 2538 | } |
2518 | 2539 | |
2540 | ||
2541 | GF_EXPORT | |
2519 | 2542 | GF_Err gf_isom_clone_sample_description(GF_ISOFile *the_file, u32 trackNumber, GF_ISOFile *orig_file, u32 orig_track, u32 orig_desc_index, char *URLname, char *URNname, u32 *outDescriptionIndex) |
2520 | 2543 | { |
2521 | 2544 | GF_TrackBox *trak; |
2801 | 2824 | |
2802 | 2825 | |
2803 | 2826 | //sets a track reference |
2827 | GF_EXPORT | |
2804 | 2828 | GF_Err gf_isom_set_track_reference(GF_ISOFile *the_file, u32 trackNumber, u32 referenceType, u32 ReferencedTrackID) |
2805 | 2829 | { |
2806 | 2830 | GF_Err e; |
2831 | 2855 | } |
2832 | 2856 | |
2833 | 2857 | //removes a track reference |
2858 | GF_EXPORT | |
2834 | 2859 | GF_Err gf_isom_remove_track_reference(GF_ISOFile *the_file, u32 trackNumber, u32 referenceType, u32 ReferenceIndex) |
2835 | 2860 | { |
2836 | 2861 | GF_Err e; |
2942 | 2967 | return GF_OK; |
2943 | 2968 | } |
2944 | 2969 | |
2970 | GF_EXPORT | |
2945 | 2971 | GF_Err gf_isom_set_cts_packing(GF_ISOFile *the_file, u32 trackNumber, Bool unpack) |
2946 | 2972 | { |
2947 | 2973 | GF_Err e; |
2970 | 2996 | return GF_OK; |
2971 | 2997 | } |
2972 | 2998 | |
2999 | GF_EXPORT | |
2973 | 3000 | GF_Err gf_isom_set_track_layout_info(GF_ISOFile *the_file, u32 trackNumber, u32 width, u32 height, s32 translation_x, s32 translation_y, s16 layer) |
2974 | 3001 | { |
2975 | 3002 | GF_TrackBox *trak = gf_isom_get_track_from_file(the_file, trackNumber); |
3128 | 3155 | } |
3129 | 3156 | |
3130 | 3157 | |
3131 | ||
3158 | GF_EXPORT | |
3132 | 3159 | Bool gf_isom_is_same_sample_description(GF_ISOFile *f1, u32 tk1, u32 sdesc_index1, GF_ISOFile *f2, u32 tk2, u32 sdesc_index2) |
3133 | 3160 | { |
3134 | 3161 | u32 i, count; |
3258 | 3285 | return ret; |
3259 | 3286 | } |
3260 | 3287 | |
3288 | GF_EXPORT | |
3261 | 3289 | u64 gf_isom_estimate_size(GF_ISOFile *movie) |
3262 | 3290 | { |
3263 | 3291 | GF_Err e; |
3376 | 3404 | } |
3377 | 3405 | |
3378 | 3406 | |
3407 | GF_EXPORT | |
3379 | 3408 | GF_Err gf_isom_set_extraction_slc(GF_ISOFile *the_file, u32 trackNumber, u32 StreamDescriptionIndex, GF_SLConfig *slConfig) |
3380 | 3409 | { |
3381 | 3410 | GF_TrackBox *trak; |
3474 | 3503 | } |
3475 | 3504 | |
3476 | 3505 | |
3506 | GF_EXPORT | |
3477 | 3507 | GF_Err gf_isom_make_interleave(GF_ISOFile *file, Double TimeInSec) |
3478 | 3508 | { |
3479 | 3509 | GF_Err e; |
3484 | 3514 | } |
3485 | 3515 | |
3486 | 3516 | |
3517 | GF_EXPORT | |
3487 | 3518 | GF_Err gf_isom_set_handler_name(GF_ISOFile *the_file, u32 trackNumber, const char *nameUTF8) |
3488 | 3519 | { |
3489 | 3520 | GF_TrackBox *trak; |
3686 | 3717 | |
3687 | 3718 | /*Apple extensions*/ |
3688 | 3719 | |
3720 | GF_EXPORT | |
3689 | 3721 | GF_Err gf_isom_apple_set_tag(GF_ISOFile *mov, u32 tag, const char *data, u32 data_len) |
3690 | 3722 | { |
3691 | 3723 | GF_BitStream *bs; |
3998 | 4030 | } |
3999 | 4031 | |
4000 | 4032 | |
4033 | GF_EXPORT | |
4001 | 4034 | GF_Err gf_isom_set_rvc_config(GF_ISOFile *movie, u32 track, u32 sampleDescriptionIndex, u16 rvc_predefined, char *mime, char *data, u32 size) |
4002 | 4035 | { |
4003 | 4036 | GF_MPEGVisualSampleEntryBox *entry; |
424 | 424 | Media_GetSampleDesc(mdia, StreamDescIndex, &se, &drefIndex); |
425 | 425 | if (!drefIndex) return 0; |
426 | 426 | a = (GF_FullBox*)gf_list_get(mdia->information->dataInformation->dref->boxList, drefIndex - 1); |
427 | if (!a) { | |
428 | GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[iso file] broken file: Data reference index set to %d but no data reference entry found\n", drefIndex)); | |
429 | return 0; | |
430 | } | |
427 | 431 | if (a->flags & 1) return 1; |
428 | 432 | /*QT specific*/ |
429 | 433 | if (a->type == GF_4CC('a', 'l', 'i', 's')) return 1; |
63 | 63 | return 0; |
64 | 64 | } |
65 | 65 | |
66 | GF_EXPORT | |
66 | 67 | GF_Err gf_isom_extract_meta_xml(GF_ISOFile *file, Bool root_meta, u32 track_num, char *outName, Bool *is_binary) |
67 | 68 | { |
68 | 69 | u32 i, count; |
188 | 189 | return 0; |
189 | 190 | } |
190 | 191 | |
192 | GF_EXPORT | |
191 | 193 | GF_Err gf_isom_extract_meta_item_extended(GF_ISOFile *file, Bool root_meta, u32 track_num, u32 item_id, const char *dump_file_name, char **out_data, u32 *out_size, const char **out_mime ) |
192 | 194 | { |
193 | 195 | GF_BitStream *item_bs; |
284 | 286 | return GF_OK; |
285 | 287 | } |
286 | 288 | |
289 | GF_EXPORT | |
287 | 290 | GF_Err gf_isom_extract_meta_item(GF_ISOFile *file, Bool root_meta, u32 track_num, u32 item_id, const char *dump_file_name) |
288 | 291 | { |
289 | 292 | return gf_isom_extract_meta_item_extended(file, root_meta, track_num, item_id, dump_file_name, NULL, NULL, NULL); |
294 | 297 | return gf_isom_extract_meta_item_extended(file, root_meta, track_num, item_id, NULL, out_data, out_size, out_mime); |
295 | 298 | } |
296 | 299 | |
300 | GF_EXPORT | |
297 | 301 | u32 gf_isom_get_meta_primary_item_id(GF_ISOFile *file, Bool root_meta, u32 track_num) |
298 | 302 | { |
299 | 303 | GF_MetaBox *meta = gf_isom_get_meta(file, root_meta, track_num); |
305 | 309 | #ifndef GPAC_DISABLE_ISOM_WRITE |
306 | 310 | |
307 | 311 | |
312 | GF_EXPORT | |
308 | 313 | GF_Err gf_isom_set_meta_type(GF_ISOFile *file, Bool root_meta, u32 track_num, u32 metaType) |
309 | 314 | { |
310 | 315 | char szName[20]; |
362 | 367 | return GF_OK; |
363 | 368 | } |
364 | 369 | |
370 | GF_EXPORT | |
365 | 371 | GF_Err gf_isom_remove_meta_xml(GF_ISOFile *file, Bool root_meta, u32 track_num) |
366 | 372 | { |
367 | 373 | u32 i; |
381 | 387 | return GF_OK; |
382 | 388 | } |
383 | 389 | |
390 | GF_EXPORT | |
384 | 391 | GF_Err gf_isom_set_meta_xml(GF_ISOFile *file, Bool root_meta, u32 track_num, char *XMLFileName, Bool IsBinaryXML) |
385 | 392 | { |
386 | 393 | GF_Err e; |
613 | 620 | return GF_OK; |
614 | 621 | } |
615 | 622 | |
623 | GF_EXPORT | |
616 | 624 | GF_Err gf_isom_add_meta_item(GF_ISOFile *file, Bool root_meta, u32 track_num, Bool self_reference, char *resource_path, const char *item_name, const char *mime_type, const char *content_encoding, const char *URL, const char *URN) |
617 | 625 | { |
618 | 626 | return gf_isom_add_meta_item_extended(file, root_meta, track_num, self_reference, resource_path, item_name, mime_type, content_encoding, URL, URN, NULL, 0); |
623 | 631 | return gf_isom_add_meta_item_extended(file, root_meta, track_num, 0, NULL, item_name, mime_type, content_encoding, NULL, NULL, data, data_len); |
624 | 632 | } |
625 | 633 | |
634 | GF_EXPORT | |
626 | 635 | GF_Err gf_isom_remove_meta_item(GF_ISOFile *file, Bool root_meta, u32 track_num, u32 item_id) |
627 | 636 | { |
628 | 637 | GF_ItemInfoEntryBox *iinf; |
652 | 661 | return GF_OK; |
653 | 662 | } |
654 | 663 | |
664 | GF_EXPORT | |
655 | 665 | GF_Err gf_isom_set_meta_primary_item(GF_ISOFile *file, Bool root_meta, u32 track_num, u32 item_id) |
656 | 666 | { |
657 | 667 | GF_MetaBox *meta = gf_isom_get_meta(file, root_meta, track_num); |
874 | 874 | Bool first_frag_in_subseg; |
875 | 875 | Bool no_sidx = 0; |
876 | 876 | u32 count, idx, cur_dur, sidx_dur, sidx_idx, idx_offset, frag_count; |
877 | u64 last_top_box_pos, root_prev_offset, local_sidx_start, local_sidx_end, prev_earliest_cts, prev_earliest_dts; | |
877 | u64 last_top_box_pos, root_prev_offset, local_sidx_start, local_sidx_end, prev_earliest_cts; | |
878 | 878 | GF_TrackBox *trak = NULL; |
879 | 879 | GF_Err e; |
880 | 880 | /*number of subsegment in this segment (eg nb references in the first SIDX found)*/ |
944 | 944 | frags_per_subsidx = 0; |
945 | 945 | |
946 | 946 | prev_earliest_cts = 0; |
947 | prev_earliest_dts = ref_track_decode_time; | |
948 | 947 | |
949 | 948 | if (daisy_chain_sidx) |
950 | 949 | daisy_sidx = gf_list_new(); |
1506 | 1505 | ent->Duration = Duration; |
1507 | 1506 | ent->size = sample->dataLength; |
1508 | 1507 | ent->flags = GF_ISOM_FORMAT_FRAG_FLAGS(PaddingBits, sample->IsRAP, DegradationPriority); |
1508 | if (sample->IsRAP) { | |
1509 | ent->flags |= GF_ISOM_GET_FRAG_DEPEND_FLAGS(0, 2, 0, 0); | |
1510 | } | |
1509 | 1511 | gf_list_add(trun->entries, ent); |
1510 | 1512 | |
1511 | 1513 | trun->sample_count += 1; |
1600 | 1602 | GF_Err e; |
1601 | 1603 | GF_TrackBox *trak; |
1602 | 1604 | GF_TrackFragmentBox *traf; |
1605 | GF_TrunEntry *ent; | |
1606 | GF_TrackFragmentRunBox *trun; | |
1603 | 1607 | if (!dest->moof || !(dest->FragmentsFlags & GF_ISOM_FRAG_WRITE_READY) ) return GF_BAD_PARAM; |
1604 | 1608 | |
1605 | 1609 | traf = GetTraf(dest, TrackID); |
1607 | 1611 | |
1608 | 1612 | trak = gf_isom_get_track_from_file(orig, track); |
1609 | 1613 | if (!trak) return GF_BAD_PARAM; |
1614 | ||
1615 | /*modify depends flags*/ | |
1616 | if (trak->Media->information->sampleTable->SampleDep) { | |
1617 | u32 dependsOn, dependedOn, redundant; | |
1618 | ||
1619 | dependsOn = dependedOn = redundant = 0; | |
1620 | count = gf_list_count(traf->TrackRuns); | |
1621 | if (!count) return GF_BAD_PARAM; | |
1622 | trun = (GF_TrackFragmentRunBox *)gf_list_get(traf->TrackRuns, count-1); | |
1623 | count = gf_list_count(trun->entries); | |
1624 | if (!count) return GF_BAD_PARAM; | |
1625 | ||
1626 | ent = (GF_TrunEntry *)gf_list_get(trun->entries, count-1); | |
1627 | e = stbl_GetSampleDepType(trak->Media->information->sampleTable->SampleDep, sampleNumber, &dependsOn, &dependedOn, &redundant); | |
1628 | if (e) return e; | |
1629 | ||
1630 | GF_ISOM_RESET_FRAG_DEPEND_FLAGS(ent->flags); | |
1631 | ent->flags |= GF_ISOM_GET_FRAG_DEPEND_FLAGS(0, dependsOn, dependedOn, redundant); | |
1632 | } | |
1610 | 1633 | |
1611 | 1634 | /*copy subsample info if any*/ |
1612 | 1635 | if ( gf_isom_sample_get_subsample_entry(orig, track, sampleNumber, &sub_sample)) { |
372 | 372 | |
373 | 373 | |
374 | 374 | |
375 | ||
375 | GF_EXPORT | |
376 | 376 | GF_Err gf_isom_get_dims_description(GF_ISOFile *movie, u32 trackNumber, u32 descriptionIndex, GF_DIMSDescription *desc) |
377 | 377 | { |
378 | 378 | GF_DIMSSampleEntryBox *dims; |
305 | 305 | /* |
306 | 306 | * Output = SHA-1( file contents ) |
307 | 307 | */ |
308 | GF_EXPORT | |
308 | 309 | s32 gf_sha1_file( const char *path, u8 output[20] ) |
309 | 310 | { |
310 | 311 | FILE *f; |
392 | 392 | |
393 | 393 | static void gf_m2ts_process_ait(GF_M2TS_Demuxer *ts, GF_M2TS_AIT* ait){ |
394 | 394 | |
395 | u32 nb_app_desc,k,desc_id; | |
396 | ||
397 | u32 nb_of_app,j,i; | |
395 | u32 nb_app_desc, k, desc_id, nb_of_app, j; | |
398 | 396 | GF_M2TS_CHANNEL_APPLICATION_INFO* ChanAppInfo; |
399 | char* url_base; | |
400 | char* url_appli_path; | |
397 | char *url_base, *url_appli_path; | |
401 | 398 | |
402 | 399 | nb_of_app = gf_list_count(ait->application_decoded); |
403 | 400 | url_base = NULL; |
404 | 401 | url_appli_path = NULL; |
405 | j=0; | |
406 | i=0; | |
402 | j=0; | |
407 | 403 | |
408 | 404 | /* Link the AIT and the channel */ |
409 | 405 | ChanAppInfo = gf_m2ts_get_channel_application_info(ts->ChannelAppList,ait->service_id); |
2776 | 2776 | 2, 1, 2, 3, 3, 4, 4, 5 |
2777 | 2777 | }; |
2778 | 2778 | |
2779 | GF_EXPORT | |
2779 | 2780 | u32 gf_ac3_get_channels(u32 acmod) |
2780 | 2781 | { |
2781 | 2782 | u32 nb_ch; |
2783 | 2784 | return nb_ch; |
2784 | 2785 | } |
2785 | 2786 | |
2787 | GF_EXPORT | |
2786 | 2788 | u32 gf_ac3_get_bitrate(u32 brcode) |
2787 | 2789 | { |
2788 | 2790 | return ac3_sizecod_to_bitrate[brcode]; |
2841 | 2843 | } |
2842 | 2844 | |
2843 | 2845 | |
2846 | GF_EXPORT | |
2844 | 2847 | Bool gf_ac3_parser_bs(GF_BitStream *bs, GF_AC3Header *hdr, Bool full_parse) |
2845 | 2848 | { |
2846 | 2849 | u32 fscod, frmsizecod, bsid, ac3_mod, freq, framesize, bsmod; |
277 | 277 | } |
278 | 278 | case DOWNLOAD_DATA_BLOCK: |
279 | 279 | { |
280 | u32 data_shift,modules_count,i; | |
280 | u32 modules_count, i; | |
281 | 281 | GF_M2TS_DSMCC_DOWNLOAD_DATA_BLOCK* DownloadDataBlock; |
282 | 282 | GF_SAFEALLOC(DownloadDataBlock,GF_M2TS_DSMCC_DOWNLOAD_DATA_BLOCK); |
283 | 283 | DataMessage->dataMessagePayload = DownloadDataBlock; |
311 | 311 | return GF_CORRUPTED_DATA; |
312 | 312 | } |
313 | 313 | DownloadDataBlock->blockDataByte = (char*)gf_calloc(DownloadDataBlock->dataBlocksize,sizeof(char)); |
314 | data_shift = (u32)(gf_bs_get_position(bs)); | |
314 | *data_shift = (u32)(gf_bs_get_position(bs)); | |
315 | 315 | gf_bs_read_data(bs,DownloadDataBlock->blockDataByte,DownloadDataBlock->dataBlocksize); |
316 | 316 | memcpy(dsmcc_module->buffer+dsmcc_module->byte_sift,DownloadDataBlock->blockDataByte,DownloadDataBlock->dataBlocksize*sizeof(char)); |
317 | 317 | dsmcc_module->byte_sift += DownloadDataBlock->dataBlocksize; |
356 | 356 | |
357 | 357 | } |
358 | 358 | case DOWNLOAD_SERVER_INITIATE: |
359 | ||
360 | 359 | { |
361 | u32 localbyteshift; | |
362 | 360 | GF_Err e; |
363 | 361 | GF_M2TS_DSMCC_DOWNLOAD_SERVER_INIT* DownloadServerInit; |
364 | 362 | GF_SAFEALLOC(DownloadServerInit,GF_M2TS_DSMCC_DOWNLOAD_SERVER_INIT); |
365 | 363 | DataMessage->dataMessagePayload = DownloadServerInit; |
366 | localbyteshift = (u32)(gf_bs_get_position(bs)); | |
367 | 364 | gf_bs_read_data(bs,DownloadServerInit->serverId,20); |
368 | 365 | gf_m2ts_dsmcc_process_compatibility_descriptor(&DownloadServerInit->CompatibilityDescr,data,bs,data_shift); |
369 | 366 | DownloadServerInit->privateDataLength = gf_bs_read_int(bs,16); |
941 | 938 | GF_M2TS_DSMCC_SERVICE_GATEWAY* ServiceGateway; |
942 | 939 | GF_M2TS_DSMCC_FILE* File; |
943 | 940 | FILE* pFile; |
944 | char* FileType; | |
945 | 941 | u8* descr_tag; |
946 | 942 | |
947 | 943 | GF_SAFEALLOC(BIOP_File,GF_M2TS_DSMCC_BIOP_FILE); |
969 | 965 | switch(*descr_tag){ |
970 | 966 | case CONTENT_TYPE_DESCRIPTOR: |
971 | 967 | { |
972 | GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR* ContentTypeDescr = (GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR*)gf_list_get(BIOP_File->descriptor,0); | |
973 | FileType = strdup(ContentTypeDescr->content_type_data_byte); | |
968 | //GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR* ContentTypeDescr = (GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR*)gf_list_get(BIOP_File->descriptor,0); | |
974 | 969 | } |
975 | 970 | default: |
976 | 971 | { |
1019 | 1014 | |
1020 | 1015 | GF_M2TS_DSMCC_BIOP_DIRECTORY* BIOP_Directory; |
1021 | 1016 | GF_M2TS_DSMCC_DIR* Dir; |
1022 | char* ParentName; | |
1023 | char* FileType; | |
1024 | 1017 | u32 i; |
1025 | 1018 | GF_M2TS_DSMCC_SERVICE_GATEWAY* ServiceGateway; |
1026 | 1019 | |
1042 | 1035 | ServiceGateway->objectKey_data = BIOP_Directory->Header->objectKey_data; |
1043 | 1036 | ServiceGateway->parent = NULL; |
1044 | 1037 | ServiceGateway->name = (char*)gf_strdup(dsmcc_overlord->root_dir); |
1045 | ParentName = ServiceGateway->name; | |
1046 | 1038 | }else{ |
1047 | 1039 | /* get the dir related to the payload */ |
1048 | 1040 | Dir = dsmcc_get_directory(ServiceGateway->Dir,BIOP_Directory->Header->objectKey_data); |
1111 | 1103 | switch(*descr_tag){ |
1112 | 1104 | case CONTENT_TYPE_DESCRIPTOR: |
1113 | 1105 | { |
1114 | GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR* ContentTypeDescr = (GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR*)gf_list_get(BIOP_Directory->Name[i].descriptor ,j); | |
1115 | FileType = strdup(ContentTypeDescr->content_type_data_byte); | |
1106 | //GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR* ContentTypeDescr = (GF_M2TS_DSMCC_BIOP_CONTENT_TYPE_DESRIPTOR*)gf_list_get(BIOP_Directory->Name[i].descriptor ,j); | |
1116 | 1107 | } |
1117 | 1108 | default: |
1118 | 1109 | { |
1167 | 1158 | u32 i; |
1168 | 1159 | GF_M2TS_DSMCC_BIOP_STREAM_EVENT* BIOP_StreamEvent; |
1169 | 1160 | //GF_M2TS_DSMCC_FILE* File; |
1170 | u32 eventdata,Info_length; | |
1161 | u32 eventdata; | |
1171 | 1162 | |
1172 | 1163 | GF_SAFEALLOC(BIOP_StreamEvent,GF_M2TS_DSMCC_BIOP_STREAM_EVENT); |
1173 | 1164 | |
1200 | 1191 | } |
1201 | 1192 | } |
1202 | 1193 | |
1203 | Info_length = BIOP_StreamEvent->Header->objectInfo_length - (BIOP_StreamEvent->Info.aDescription_length + 14 + BIOP_StreamEvent->eventNames_count + eventdata); | |
1204 | ||
1205 | 1194 | BIOP_StreamEvent->serviceContextList_count = gf_bs_read_int(bs,8); |
1206 | if(BIOP_StreamEvent->serviceContextList_count){ | |
1195 | if (BIOP_StreamEvent->serviceContextList_count) { | |
1207 | 1196 | BIOP_StreamEvent->ServiceContext = (GF_M2TS_DSMCC_SERVICE_CONTEXT*)gf_calloc(BIOP_StreamEvent->serviceContextList_count,sizeof(GF_M2TS_DSMCC_SERVICE_CONTEXT)); |
1208 | 1197 | dsmcc_biop_get_context(bs,BIOP_StreamEvent->ServiceContext,BIOP_StreamEvent->serviceContextList_count); |
1209 | 1198 | } |
1211 | 1200 | BIOP_StreamEvent->messageBody_length = gf_bs_read_int(bs,32); |
1212 | 1201 | BIOP_StreamEvent->taps_count = gf_bs_read_int(bs,8); |
1213 | 1202 | BIOP_StreamEvent->Taps = (GF_M2TS_DSMCC_BIOP_TAPS*)gf_calloc(BIOP_StreamEvent->taps_count,sizeof(GF_M2TS_DSMCC_BIOP_TAPS)); |
1214 | for(i=0;i<BIOP_StreamEvent->taps_count;i++){ | |
1203 | for (i=0;i<BIOP_StreamEvent->taps_count;i++) { | |
1215 | 1204 | BIOP_StreamEvent->Taps[i].id = gf_bs_read_int(bs,16); |
1216 | 1205 | BIOP_StreamEvent->Taps[i].use = gf_bs_read_int(bs,16); |
1217 | 1206 | BIOP_StreamEvent->Taps[i].assocTag = gf_bs_read_int(bs,16); |
1240 | 1229 | static GF_Err dsmcc_process_biop_stream_message(GF_BitStream* bs,GF_M2TS_DSMCC_BIOP_HEADER* BIOP_Header,GF_M2TS_DSMCC_SERVICE_GATEWAY* ServiceGateway){ |
1241 | 1230 | |
1242 | 1231 | u32 i; |
1243 | GF_M2TS_DSMCC_BIOP_STREAM_MESSAGE* BIOP_StreamMessage; | |
1244 | u32 eventdata,Info_length; | |
1232 | GF_M2TS_DSMCC_BIOP_STREAM_MESSAGE* BIOP_StreamMessage; | |
1245 | 1233 | |
1246 | 1234 | GF_SAFEALLOC(BIOP_StreamMessage,GF_M2TS_DSMCC_BIOP_STREAM_MESSAGE); |
1247 | ||
1248 | eventdata = 0; | |
1249 | 1235 | |
1250 | 1236 | BIOP_StreamMessage->Header = BIOP_Header; |
1251 | 1237 | /* Get Info */ |
1260 | 1246 | BIOP_StreamMessage->Info.video = gf_bs_read_int(bs,8); |
1261 | 1247 | BIOP_StreamMessage->Info.data = gf_bs_read_int(bs,8); |
1262 | 1248 | |
1263 | ||
1264 | Info_length = BIOP_StreamMessage->Header->objectInfo_length - (BIOP_StreamMessage->Info.aDescription_length + 10); | |
1265 | ||
1266 | 1249 | BIOP_StreamMessage->serviceContextList_count = gf_bs_read_int(bs,8); |
1267 | 1250 | if(BIOP_StreamMessage->serviceContextList_count){ |
1268 | 1251 | BIOP_StreamMessage->ServiceContext = (GF_M2TS_DSMCC_SERVICE_CONTEXT*)gf_calloc(BIOP_StreamMessage->serviceContextList_count,sizeof(GF_M2TS_DSMCC_SERVICE_CONTEXT)); |
1856 | 1839 | gf_list_del(IOR->taggedProfile); |
1857 | 1840 | } |
1858 | 1841 | |
1859 | static void dsmcc_free_biop_descriptor(GF_List* list){ | |
1842 | static void dsmcc_free_biop_descriptor(GF_List* list) | |
1843 | { | |
1860 | 1844 | u8* descr_tag; |
1861 | u32 descr_count; | |
1862 | ||
1863 | descr_count = gf_list_count(list); | |
1864 | ||
1865 | ||
1866 | while(gf_list_count(list)){ | |
1845 | ||
1846 | while(gf_list_count(list)) { | |
1867 | 1847 | |
1868 | 1848 | descr_tag = (u8*)gf_list_get(list,0); |
1869 | 1849 | |
1870 | switch(*descr_tag){ | |
1850 | switch(*descr_tag) { | |
1871 | 1851 | |
1872 | 1852 | case CACHING_PRIORITY_DESCRIPTOR: |
1873 | 1853 | { |
424 | 424 | |
425 | 425 | Bool gf_m2ts_compare_ip(u8 rx_ip_adress[4], u8 ip_adress_bootstrap[4]) |
426 | 426 | { |
427 | Bool Boostrap_ip; | |
428 | 427 | u8 i; |
429 | for (i=0; i<sizeof(rx_ip_adress); i++) | |
428 | for (i=0; i<4; i++) | |
430 | 429 | { |
431 | 430 | if (rx_ip_adress[i] != ip_adress_bootstrap[i]) |
432 | return Boostrap_ip = 0; | |
433 | } | |
434 | return Boostrap_ip = 1; | |
435 | } | |
431 | return 0; | |
432 | } | |
433 | return 1; | |
434 | } | |
435 | ||
436 | ||
436 | 437 | u32 gf_m2ts_ipdatagram_reader(u8 *datagram,GF_M2TS_IP_Packet *ip_packet, u32 offset) |
437 | 438 | { |
438 | 439 | |
1093 | 1094 | } |
1094 | 1095 | |
1095 | 1096 | // ******************************************************** |
1096 | // Envoi des données | |
1097 | // Envoi des donn�es | |
1097 | 1098 | // ******************************************************** |
1098 | 1099 | |
1099 | 1100 | e = gf_sk_send(Sock_Struct->sock, ip_packet->data, ip_packet->u32_udp_data_size - 8); |
166 | 166 | return GF_OK; |
167 | 167 | } |
168 | 168 | |
169 | GF_EXPORT | |
169 | 170 | GF_Err gf_isom_streamer_write_sdp(GF_ISOMRTPStreamer *streamer, char*sdpfilename) |
170 | 171 | { |
171 | 172 | return gf_isom_streamer_setup_sdp(streamer, sdpfilename, NULL); |
197 | 198 | if (is_loop) streamer->timelineOrigin = 0; |
198 | 199 | } |
199 | 200 | |
201 | GF_EXPORT | |
200 | 202 | GF_Err gf_isom_streamer_send_next_packet(GF_ISOMRTPStreamer *streamer, s32 send_ahead_delay, s32 max_sleep_time) |
201 | 203 | { |
202 | 204 | GF_Err e = GF_OK; |
329 | 331 | return first_port; |
330 | 332 | } |
331 | 333 | |
334 | GF_EXPORT | |
332 | 335 | GF_ISOMRTPStreamer *gf_isom_streamer_new(const char *file_name, const char *ip_dest, u16 port, Bool loop, Bool force_mpeg4, u32 path_mtu, u32 ttl, char *ifce_addr) |
333 | 336 | { |
334 | 337 | GF_ISOMRTPStreamer *streamer; |
502 | 505 | return NULL; |
503 | 506 | } |
504 | 507 | |
508 | GF_EXPORT | |
505 | 509 | void gf_isom_streamer_del(GF_ISOMRTPStreamer *streamer) |
506 | 510 | { |
507 | 511 | GF_RTPTrack *track = streamer->stream; |
518 | 518 | } |
519 | 519 | |
520 | 520 | /* write a png file */ |
521 | GF_EXPORT | |
521 | 522 | GF_Err gf_img_png_enc(char *data, u32 width, u32 height, s32 stride, u32 pixel_format, char *dst, u32 *dst_size) |
522 | 523 | { |
523 | 524 | GFpng udta; |
608 | 608 | return GF_OK; |
609 | 609 | } |
610 | 610 | |
611 | GF_EXPORT | |
611 | 612 | GF_Err gf_media_make_psp(GF_ISOFile *mp4) |
612 | 613 | { |
613 | 614 | u32 i, count; |
713 | 714 | GF_Err e; |
714 | 715 | char sOpt[100], sKey[100]; |
715 | 716 | char szCodecs[200], szCodec[100]; |
716 | u32 cur_seg, fragment_index, nb_fragments, max_sap_type; | |
717 | u32 cur_seg, fragment_index, max_sap_type; | |
717 | 718 | GF_ISOFile *output; |
718 | 719 | GF_ISOSample *sample, *next; |
719 | 720 | GF_List *fragmenters; |
1068 | 1069 | |
1069 | 1070 | |
1070 | 1071 | max_segment_duration = 0; |
1071 | nb_fragments=0; | |
1072 | 1072 | |
1073 | 1073 | while ( (count = gf_list_count(fragmenters)) ) { |
1074 | 1074 | |
1415 | 1415 | |
1416 | 1416 | if (dash_mode) { |
1417 | 1417 | char buffer[1000]; |
1418 | u32 h, m; | |
1419 | Double s; | |
1420 | 1418 | |
1421 | 1419 | /*flush last segment*/ |
1422 | 1420 | if (!switch_segment) { |
1448 | 1446 | } |
1449 | 1447 | |
1450 | 1448 | period_duration += file_duration; |
1451 | h = (u32) (period_duration/3600); | |
1452 | m = (u32) (period_duration-h*60)/60; | |
1453 | s = period_duration - h*3600 - m*60; | |
1449 | //u32 h = (u32) (period_duration/3600); | |
1450 | //u32 m = (u32) (period_duration-h*60)/60; | |
1454 | 1451 | bandwidth = (u32) (file_size * 8 / file_duration); |
1455 | 1452 | |
1456 | 1453 | fprintf(mpd, " <Representation id=\"%d\" mimeType=\"%s/mp4\" codecs=\"%s\"", rep_idx ? rep_idx : 1, audio_only ? "audio" : "video", szCodecs); |
1564 | 1561 | |
1565 | 1562 | #endif /*GPAC_DISABLE_ISOM_FRAGMENTS*/ |
1566 | 1563 | |
1564 | GF_EXPORT | |
1567 | 1565 | GF_Err gf_media_mpd_start(char *mpd_name, char *title, Bool use_url_template, Bool single_segment, char *dash_ctx, GF_ISOFile *init_segment, Double period_duration) |
1568 | 1566 | { |
1569 | 1567 | u32 h, m; |
1626 | 1624 | return GF_OK; |
1627 | 1625 | } |
1628 | 1626 | |
1627 | GF_EXPORT | |
1629 | 1628 | GF_Err gf_media_mpd_end(char *mpd_name) |
1630 | 1629 | { |
1631 | 1630 | FILE *mpd = fopen(mpd_name, "a+t"); |
1568 | 1568 | } |
1569 | 1569 | } |
1570 | 1570 | |
1571 | GF_EXPORT | |
1571 | 1572 | GF_M2TS_Mux_Stream *gf_m2ts_program_stream_add(GF_M2TS_Mux_Program *program, struct __elementary_stream_ifce *ifce, u32 pid, Bool is_pcr, Bool force_pes) |
1572 | 1573 | { |
1573 | 1574 | GF_M2TS_Mux_Stream *stream, *st; |
1695 | 1696 | return stream; |
1696 | 1697 | } |
1697 | 1698 | |
1699 | GF_EXPORT | |
1698 | 1700 | GF_Err gf_m2ts_program_stream_update_ts_scale(GF_ESInterface *_self, u32 time_scale) |
1699 | 1701 | { |
1700 | 1702 | GF_M2TS_Mux_Stream *stream = (GF_M2TS_Mux_Stream *)_self->output_udta; |
1705 | 1707 | return GF_OK; |
1706 | 1708 | } |
1707 | 1709 | |
1708 | ||
1710 | GF_EXPORT | |
1709 | 1711 | GF_M2TS_Mux_Program *gf_m2ts_mux_program_add(GF_M2TS_Mux *muxer, u32 program_number, u32 pmt_pid, u32 pmt_refresh_rate, u32 pcr_offset, Bool mpeg4_signaling) |
1710 | 1712 | { |
1711 | 1713 | GF_M2TS_Mux_Program *program; |
1731 | 1733 | return program; |
1732 | 1734 | } |
1733 | 1735 | |
1736 | GF_EXPORT | |
1734 | 1737 | GF_M2TS_Mux *gf_m2ts_mux_new(u32 mux_rate, u32 pat_refresh_rate, Bool real_time) |
1735 | 1738 | { |
1736 | 1739 | GF_BitStream *bs; |
1803 | 1806 | gf_free(prog); |
1804 | 1807 | } |
1805 | 1808 | |
1809 | GF_EXPORT | |
1806 | 1810 | void gf_m2ts_mux_del(GF_M2TS_Mux *mux) |
1807 | 1811 | { |
1808 | 1812 | while (mux->programs) { |
1837 | 1841 | } |
1838 | 1842 | } |
1839 | 1843 | |
1844 | GF_EXPORT | |
1840 | 1845 | void gf_m2ts_mux_update_config(GF_M2TS_Mux *mux, Bool reset_time) |
1841 | 1846 | { |
1842 | 1847 | GF_M2TS_Mux_Program *prog; |
1874 | 1879 | } |
1875 | 1880 | } |
1876 | 1881 | |
1882 | GF_EXPORT | |
1877 | 1883 | u32 gf_m2ts_get_sys_clock(GF_M2TS_Mux *muxer) |
1878 | 1884 | { |
1879 | 1885 | return gf_sys_clock() - muxer->init_sys_time; |
1880 | 1886 | } |
1881 | 1887 | |
1888 | GF_EXPORT | |
1882 | 1889 | u32 gf_m2ts_get_ts_clock(GF_M2TS_Mux *muxer) |
1883 | 1890 | { |
1884 | 1891 | u32 now, init; |
1887 | 1894 | return now-init; |
1888 | 1895 | } |
1889 | 1896 | |
1897 | GF_EXPORT | |
1890 | 1898 | GF_Err gf_m2ts_mux_use_single_au_pes_mode(GF_M2TS_Mux *muxer, Bool strict_au_pes_mode) |
1891 | 1899 | { |
1892 | 1900 | if (!muxer) return GF_BAD_PARAM; |
1894 | 1902 | return GF_OK; |
1895 | 1903 | } |
1896 | 1904 | |
1905 | GF_EXPORT | |
1897 | 1906 | GF_Err gf_m2ts_mux_set_initial_pcr(GF_M2TS_Mux *muxer, u64 init_pcr_value) |
1898 | 1907 | { |
1899 | 1908 | if (!muxer) return GF_BAD_PARAM; |
1901 | 1910 | return GF_OK; |
1902 | 1911 | } |
1903 | 1912 | |
1913 | GF_EXPORT | |
1904 | 1914 | const char *gf_m2ts_mux_process(GF_M2TS_Mux *muxer, u32 *status) |
1905 | 1915 | { |
1906 | 1916 | GF_M2TS_Mux_Program *program; |
3699 | 3699 | return e; |
3700 | 3700 | } |
3701 | 3701 | |
3702 | GF_EXPORT | |
3702 | 3703 | GF_Err gf_media_avc_rewrite_samples(GF_ISOFile *file, u32 track, u32 prev_size, u32 new_size) |
3703 | 3704 | { |
3704 | 3705 | u32 i, count, di, remain, msize; |
5482 | 5483 | { |
5483 | 5484 | GF_Err e; |
5484 | 5485 | u32 sc_pos, start; |
5485 | char *data; | |
5486 | 5486 | GF_BitStream *bs; |
5487 | 5487 | GF_ISOSample *samp; |
5488 | 5488 | u32 count = gf_isom_get_sample_count(import->dest, tsimp->track); |
5492 | 5492 | sc_pos = 1; |
5493 | 5493 | start = 0; |
5494 | 5494 | bs = gf_bs_new(samp->data, samp->dataLength, GF_BITSTREAM_WRITE); |
5495 | data = samp->data; | |
5496 | 5495 | while (1) { |
5497 | 5496 | if (!samp->data[start+sc_pos] && !samp->data[start+sc_pos+1] && !samp->data[start+sc_pos+2] && (samp->data[start+sc_pos+3]==1)) { |
5498 | 5497 | gf_bs_seek(bs, start); |
158 | 158 | GF_SAFEALLOC(url, GF_MPD_BaseURL); |
159 | 159 | if (! url) return GF_OUT_OF_MEM; |
160 | 160 | e = gf_list_add(container, url); |
161 | if (e) return GF_OUT_OF_MEM; | |
161 | 162 | |
162 | 163 | i = 0; |
163 | 164 | while ( (att = gf_list_enum(node->attributes, &i))) { |
652 | 653 | return GF_OK; |
653 | 654 | } |
654 | 655 | |
655 | ||
656 | GF_EXPORT | |
656 | 657 | GF_MPD *gf_mpd_new() |
657 | 658 | { |
658 | 659 | GF_MPD *mpd; |
825 | 826 | gf_free(ptr); |
826 | 827 | } |
827 | 828 | |
829 | GF_EXPORT | |
828 | 830 | void gf_mpd_del(GF_MPD *mpd) |
829 | 831 | { |
830 | 832 | gf_mpd_del_list(mpd->program_infos, gf_mpd_prog_info_free, 0); |
837 | 839 | gf_free(mpd); |
838 | 840 | } |
839 | 841 | |
842 | GF_EXPORT | |
840 | 843 | GF_Err gf_mpd_init_from_dom(GF_XMLNode *root, GF_MPD *mpd, const char *default_base_url) |
841 | 844 | { |
842 | 845 | GF_Err e; |
890 | 893 | mpd->max_subsegment_duration = gf_mpd_parse_duration(att->value); |
891 | 894 | } |
892 | 895 | } |
896 | if (mpd->type == GF_MPD_TYPE_STATIC) | |
897 | mpd->minimum_update_period = 0; | |
893 | 898 | |
894 | 899 | child_index = 0; |
895 | 900 | while (1) { |
919 | 924 | return GF_OK; |
920 | 925 | } |
921 | 926 | |
927 | GF_EXPORT | |
922 | 928 | GF_Err gf_m3u8_to_mpd(const char *m3u8_file, const char *base_url, |
923 | 929 | const char *mpd_file, |
924 | 930 | u32 reload_count, char *mimeTypeForM3U8Segments, GF_ClientService *service, Bool do_import, Bool use_mpd_templates) |
45 | 45 | |
46 | 46 | #define DEBUG_TS_PACKET 0 |
47 | 47 | |
48 | ||
49 | GF_EXPORT | |
48 | 50 | const char *gf_m2ts_get_stream_name(u32 streamType) |
49 | 51 | { |
50 | 52 | switch (streamType) { |
2231 | 2233 | return; |
2232 | 2234 | } |
2233 | 2235 | |
2236 | GF_EXPORT | |
2234 | 2237 | GF_Err gf_m2ts_process_data(GF_M2TS_Demuxer *ts, char *data, u32 data_size) |
2235 | 2238 | { |
2236 | 2239 | u32 pos; |
2328 | 2331 | } |
2329 | 2332 | } |
2330 | 2333 | |
2334 | GF_EXPORT | |
2331 | 2335 | void gf_m2ts_reset_parsers(GF_M2TS_Demuxer *ts) |
2332 | 2336 | { |
2333 | 2337 | u32 i; |
2390 | 2394 | { |
2391 | 2395 | } |
2392 | 2396 | |
2397 | GF_EXPORT | |
2393 | 2398 | GF_Err gf_m2ts_set_pes_framing(GF_M2TS_PES *pes, u32 mode) |
2394 | 2399 | { |
2395 | 2400 | GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[MPEG-2 TS] Setting pes framing mode of PID %d to %d\n", pes->pid, mode) ); |
2451 | 2456 | return GF_OK; |
2452 | 2457 | } |
2453 | 2458 | |
2459 | GF_EXPORT | |
2454 | 2460 | GF_M2TS_Demuxer *gf_m2ts_demux_new() |
2455 | 2461 | { |
2456 | 2462 | GF_M2TS_Demuxer *ts; |
2479 | 2485 | return ts; |
2480 | 2486 | } |
2481 | 2487 | |
2488 | GF_EXPORT | |
2482 | 2489 | void gf_m2ts_demux_dmscc_init(GF_M2TS_Demuxer *ts){ |
2483 | 2490 | |
2484 | 2491 | char* temp_dir; |
2503 | 2510 | |
2504 | 2511 | } |
2505 | 2512 | |
2513 | GF_EXPORT | |
2506 | 2514 | void gf_m2ts_demux_del(GF_M2TS_Demuxer *ts) |
2507 | 2515 | { |
2508 | 2516 | u32 i; |
2907 | 2915 | return GF_OK; |
2908 | 2916 | } |
2909 | 2917 | |
2918 | GF_EXPORT | |
2910 | 2919 | u32 gf_dvb_get_freq_from_url(const char *channels_config_path, const char *url) |
2911 | 2920 | { |
2912 | 2921 | FILE *channels_config_file; |
3002 | 3011 | |
3003 | 3012 | } |
3004 | 3013 | |
3014 | GF_EXPORT | |
3005 | 3015 | GF_Err TSDemux_Demux_Setup(GF_M2TS_Demuxer *ts, const char *url, Bool loop) |
3006 | 3016 | { |
3007 | 3017 | char szURL[2048]; |
3040 | 3050 | return GF_NOT_SUPPORTED; |
3041 | 3051 | } |
3042 | 3052 | |
3053 | GF_EXPORT | |
3043 | 3054 | GF_Err TSDemux_CloseDemux(GF_M2TS_Demuxer *ts) |
3044 | 3055 | { |
3045 | 3056 | GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[TSDemux] Destroying demuxer\n")); |
3058 | 3069 | return GF_OK; |
3059 | 3070 | } |
3060 | 3071 | |
3061 | ||
3072 | GF_EXPORT | |
3062 | 3073 | GF_Err TSDemux_DemuxPlay(GF_M2TS_Demuxer *ts){ |
3063 | 3074 | |
3064 | 3075 | /*set the state variable outside the TS thread. If inside, we may get called for shutdown before the TS thread has started |
413 | 413 | GF_ISOSample *samp; |
414 | 414 | GF_StreamContext *sc; |
415 | 415 | GF_ESD *esd; |
416 | GF_MuxInfo *mux; | |
416 | 417 | #ifndef GPAC_DISABLE_BIFS_ENC |
417 | 418 | GF_BifsEncoder *bifs_enc; |
418 | 419 | #endif |
894 | 895 | /*if offset add edit list*/ |
895 | 896 | gf_sm_finalize_mux(mp4, esd, (u32) init_offset); |
896 | 897 | gf_isom_set_last_sample_duration(mp4, track, 0); |
898 | ||
899 | mux = gf_sm_get_mux_info(esd); | |
900 | if (mux && mux->duration) { | |
901 | u64 tot_dur = mux->duration * esd->slConfig->timestampResolution / 1000; | |
902 | u64 dur = gf_isom_get_media_duration(mp4, track); | |
903 | if (dur <= tot_dur) | |
904 | gf_isom_set_last_sample_duration(mp4, track, (u32) (tot_dur - dur)); | |
905 | } | |
897 | 906 | |
898 | 907 | if (delete_desc) { |
899 | 908 | gf_odf_desc_del((GF_Descriptor *) esd); |
3754 | 3754 | } |
3755 | 3755 | |
3756 | 3756 | |
3757 | ||
3757 | GF_EXPORT | |
3758 | 3758 | GF_List *gf_sm_load_bt_from_string(GF_SceneGraph *in_scene, char *node_str, Bool force_wrl) |
3759 | 3759 | { |
3760 | 3760 | GF_SceneLoader ctx; |
41 | 41 | { |
42 | 42 | } |
43 | 43 | |
44 | GF_EXPORT | |
44 | 45 | GF_SceneGraph *gf_sg_new() |
45 | 46 | { |
46 | 47 | GF_SceneGraph *tmp; |
521 | 522 | if (sg) sg->userpriv = ptr; |
522 | 523 | } |
523 | 524 | |
525 | GF_EXPORT | |
524 | 526 | void *gf_sg_get_private(GF_SceneGraph *sg) |
525 | 527 | { |
526 | 528 | return sg ? sg->userpriv : NULL; |
1976 | 1978 | return GF_BAD_PARAM; |
1977 | 1979 | } |
1978 | 1980 | |
1981 | GF_EXPORT | |
1979 | 1982 | GF_Err gf_node_get_field_by_name(GF_Node *node, char *name, GF_FieldInfo *field) |
1980 | 1983 | { |
1981 | 1984 | s32 res = -1; |
2134 | 2137 | return GF_XMLNS_UNDEFINED; |
2135 | 2138 | } |
2136 | 2139 | |
2140 | GF_EXPORT | |
2137 | 2141 | GF_Err gf_sg_add_namespace(GF_SceneGraph *sg, char *name, char *qname) |
2138 | 2142 | { |
2139 | 2143 | u32 id; |
2240 | 2244 | } |
2241 | 2245 | |
2242 | 2246 | |
2247 | GF_EXPORT | |
2243 | 2248 | char *gf_node_dump_attribute(GF_Node *n, GF_FieldInfo *info) |
2244 | 2249 | { |
2245 | 2250 | #ifndef GPAC_DISABLE_SVG |
28 | 28 | |
29 | 29 | #include <gpac/internal/laser_dev.h> |
30 | 30 | |
31 | ||
32 | GF_EXPORT | |
31 | 33 | GF_Command *gf_sg_command_new(GF_SceneGraph *graph, u32 tag) |
32 | 34 | { |
33 | 35 | GF_Command *ptr; |
871 | 873 | return GF_OK; |
872 | 874 | } |
873 | 875 | |
876 | GF_EXPORT | |
874 | 877 | GF_CommandField *gf_sg_command_field_new(GF_Command *com) |
875 | 878 | { |
876 | 879 | GF_CommandField *ptr; |
124 | 124 | return gf_list_add(evt_target->evt_list, listener); |
125 | 125 | } |
126 | 126 | |
127 | GF_EXPORT | |
127 | 128 | GF_Err gf_node_dom_listener_add(GF_Node *node, GF_Node *listener) |
128 | 129 | { |
129 | 130 | if (!node || !listener) return GF_BAD_PARAM; |
142 | 143 | return gf_sg_listener_add(listener, node->sgprivate->interact->dom_evt); |
143 | 144 | } |
144 | 145 | |
146 | GF_EXPORT | |
145 | 147 | GF_Err gf_dom_listener_del(GF_Node *listener, GF_DOMEventTarget *target) |
146 | 148 | { |
147 | 149 | GF_FieldInfo info; |
712 | 714 | gf_smil_setup_event_list(node, * (GF_List **)info.far_ptr, 0); |
713 | 715 | } |
714 | 716 | |
717 | GF_EXPORT | |
715 | 718 | void gf_dom_set_textContent(GF_Node *n, char *text) |
716 | 719 | { |
717 | 720 | GF_ParentNode *par = (GF_ParentNode *)n; |
720 | 723 | if (text) gf_dom_add_text_node(n, gf_strdup( text) ); |
721 | 724 | } |
722 | 725 | |
726 | GF_EXPORT | |
723 | 727 | GF_DOMText *gf_dom_add_text_node(GF_Node *parent, char *text_data) |
724 | 728 | { |
725 | 729 | GF_DOMText *text; |
741 | 745 | return text; |
742 | 746 | } |
743 | 747 | |
748 | GF_EXPORT | |
744 | 749 | char *gf_dom_flatten_textContent(GF_Node *n) |
745 | 750 | { |
746 | 751 | u32 len = 0; |
3273 | 3273 | GF_DOMFullNode *n; |
3274 | 3274 | GF_DOM_Event evt; |
3275 | 3275 | char *str; |
3276 | jsval readonly; | |
3276 | jsval readonly=0; | |
3277 | 3277 | if (!JS_InstanceOf(c, obj, &dom_rt->DCCIClass, NULL) ) return JS_TRUE; |
3278 | 3278 | n = (GF_DOMFullNode*) dom_get_node(c, obj); |
3279 | 3279 | if (!n) return JS_TRUE; |
37995 | 37995 | } |
37996 | 37996 | |
37997 | 37997 | |
37998 | GF_EXPORT | |
37998 | 37999 | u32 gf_node_mpeg4_type_by_class_name(const char *node_name) |
37999 | 38000 | { |
38000 | 38001 | if(!node_name) return 0; |
165 | 165 | { GF_EVENT_VP_RESIZE, "gpac_vp_changed", GF_DOM_EVENT_DOM }, |
166 | 166 | }; |
167 | 167 | |
168 | GF_EXPORT | |
168 | 169 | u32 gf_dom_event_type_by_name(const char *name) |
169 | 170 | { |
170 | 171 | u32 i, count; |
407 | 408 | { GF_KEY_RECORD, "Record" }, |
408 | 409 | { GF_KEY_BEGINPAGE, "BeginPage" } |
409 | 410 | }; |
411 | ||
412 | ||
413 | GF_EXPORT | |
410 | 414 | const char *gf_dom_get_key_name(u32 key_identifier) |
411 | 415 | { |
412 | 416 | u32 count = sizeof(predefined_key_identifiers) / sizeof(struct predef_keyid); |
3070 | 3074 | } |
3071 | 3075 | |
3072 | 3076 | /* Parse an SVG attribute */ |
3077 | GF_EXPORT | |
3073 | 3078 | GF_Err gf_svg_parse_attribute(GF_Node *n, GF_FieldInfo *info, char *attribute_content, u8 anim_value_type) |
3074 | 3079 | { |
3075 | 3080 | /* for all attributes, except strings, apply some sort of white space normalization*/ |
2421 | 2421 | static GF_Err JSScript_CreateSVGContext(GF_SceneGraph *sg) |
2422 | 2422 | { |
2423 | 2423 | GF_SVGJS *svg_js; |
2424 | Bool do_lock = gf_sg_javascript_initialized(); | |
2425 | 2424 | GF_SAFEALLOC(svg_js, GF_SVGJS); |
2426 | 2425 | |
2427 | if (do_lock) gf_sg_lock_javascript(NULL, 1); | |
2428 | 2426 | /*create new ecmascript context*/ |
2429 | 2427 | svg_js->js_ctx = gf_sg_ecmascript_new(sg); |
2430 | 2428 | if (!svg_js->js_ctx) { |
2431 | 2429 | gf_free(svg_js); |
2432 | if (do_lock) gf_sg_lock_javascript(NULL, 0); | |
2433 | 2430 | return GF_SCRIPT_ERROR; |
2434 | 2431 | } |
2432 | ||
2433 | gf_sg_lock_javascript(svg_js->js_ctx, 1); | |
2434 | ||
2435 | 2435 | if (!svg_rt) { |
2436 | 2436 | GF_SAFEALLOC(svg_rt, GF_SVGuDOM); |
2437 | 2437 | JS_SETUP_CLASS(svg_rt->svgElement, "SVGElement", JSCLASS_HAS_PRIVATE, svg_element_getProperty, svg_element_setProperty, dom_element_finalize); |
2448 | 2448 | sg->svg_js = svg_js; |
2449 | 2449 | /*load SVG & DOM APIs*/ |
2450 | 2450 | svg_init_js_api(sg); |
2451 | if (do_lock) gf_sg_lock_javascript(NULL, 0); | |
2452 | 2451 | |
2453 | 2452 | svg_js->script_execute = svg_script_execute; |
2454 | 2453 | svg_js->handler_execute = svg_script_execute_handler; |
2454 | ||
2455 | gf_sg_lock_javascript(svg_js->js_ctx, 0); | |
2456 | ||
2455 | 2457 | return GF_OK; |
2456 | 2458 | } |
2457 | 2459 |
350 | 350 | } |
351 | 351 | |
352 | 352 | |
353 | GF_EXPORT | |
353 | 354 | void gf_node_event_out(GF_Node *node, u32 FieldIndex) |
354 | 355 | { |
355 | 356 | u32 i; |
287 | 287 | return GF_OK; |
288 | 288 | } |
289 | 289 | |
290 | GF_EXPORT | |
290 | 291 | void gf_sg_script_event_in(GF_Node *node, GF_FieldInfo *in_field) |
291 | 292 | { |
292 | 293 | GF_ScriptPriv *priv = (GF_ScriptPriv *)node->sgprivate->UserPrivate; |
36 | 36 | |
37 | 37 | |
38 | 38 | /*fixes for JS > 1.8.0rc1 where GC routines have changed*/ |
39 | GF_EXPORT | |
39 | 40 | Bool gf_js_add_root(JSContext *cx, void *rp, u32 type) |
40 | 41 | { |
41 | 42 | #if (JS_VERSION>=185) |
82 | 83 | return (JS_AddNamedRoot(cx, rp, name)==JS_TRUE) ? 1 : 0; |
83 | 84 | #endif |
84 | 85 | } |
86 | ||
87 | GF_EXPORT | |
85 | 88 | Bool gf_js_remove_root(JSContext *cx, void *rp, u32 type) |
86 | 89 | { |
87 | 90 | #if (JS_VERSION>=185) |
318 | 321 | gf_sg_load_script_modules(sg); |
319 | 322 | } |
320 | 323 | js_rt->nb_inst++; |
324 | ||
325 | gf_mx_p(js_rt->mx); | |
326 | #if defined(JS_THREADSAFE) && (JS_VERSION>=185) | |
327 | if (gf_mx_get_num_locks(js_rt->mx)==1) { | |
328 | JS_SetRuntimeThread(js_rt->js_runtime); | |
329 | } | |
330 | #endif | |
331 | ||
321 | 332 | ctx = JS_NewContext(js_rt->js_runtime, STACK_CHUNK_BYTES); |
322 | 333 | JS_SetOptions(ctx, JS_GetOptions(ctx) | JSOPTION_WERROR); |
323 | 334 | |
324 | #ifdef JS_THREADSAFE | |
325 | #if (JS_VERSION>=185) | |
335 | #if defined(JS_THREADSAFE) && (JS_VERSION>=185) | |
326 | 336 | JS_ClearContextThread(ctx); |
327 | JS_ClearRuntimeThread(js_rt->js_runtime); | |
328 | #endif | |
329 | #endif | |
337 | if (gf_mx_get_num_locks(js_rt->mx)==1) { | |
338 | JS_ClearRuntimeThread(js_rt->js_runtime); | |
339 | } | |
340 | #endif | |
341 | gf_mx_v(js_rt->mx); | |
342 | ||
330 | 343 | return ctx; |
331 | 344 | } |
332 | 345 | |
354 | 367 | } |
355 | 368 | } |
356 | 369 | |
370 | ||
371 | GF_EXPORT | |
357 | 372 | #if (JS_VERSION>=185) |
358 | 373 | JSBool gf_sg_js_has_instance(JSContext *c, JSObject *obj,const jsval *val, JSBool *vp) |
359 | 374 | #else |
4420 | 4435 | return 0; |
4421 | 4436 | } |
4422 | 4437 | |
4438 | ||
4423 | 4439 | static void JSScript_LoadVRML(GF_Node *node) |
4424 | 4440 | { |
4425 | 4441 | char *str; |
4426 | 4442 | JSBool ret; |
4427 | 4443 | u32 i; |
4428 | Bool do_lock = gf_sg_javascript_initialized(); | |
4429 | 4444 | Bool local_script; |
4430 | 4445 | jsval rval, fval; |
4431 | 4446 | M_Script *script = (M_Script *)node; |
4452 | 4467 | } |
4453 | 4468 | local_script = str ? 1 : 0; |
4454 | 4469 | |
4455 | if (do_lock) gf_sg_lock_javascript(priv->js_ctx, 1); | |
4470 | /*lock runtime and set current thread before creating the context*/ | |
4456 | 4471 | priv->js_ctx = gf_sg_ecmascript_new(node->sgprivate->scenegraph); |
4457 | 4472 | if (!priv->js_ctx) { |
4458 | if (do_lock) gf_sg_lock_javascript(priv->js_ctx, 0); | |
4459 | 4473 | GF_LOG(GF_LOG_ERROR, GF_LOG_SCRIPT, ("[VRML JS] Cannot allocate ECMAScript context for node\n")); |
4460 | 4474 | return; |
4461 | 4475 | } |
4462 | 4476 | |
4463 | if (!do_lock) gf_sg_lock_javascript(priv->js_ctx, 1); | |
4477 | gf_sg_lock_javascript(priv->js_ctx, 1); | |
4464 | 4478 | |
4465 | 4479 | JS_SetContextPrivate(priv->js_ctx, node); |
4466 | 4480 | gf_sg_script_init_sm_api(priv, node); |
4743 | 4757 | |
4744 | 4758 | #ifdef GPAC_HAS_SPIDERMONKEY |
4745 | 4759 | |
4760 | GF_EXPORT | |
4746 | 4761 | GF_Node *gf_sg_js_get_node(JSContext *c, JSObject *obj) |
4747 | 4762 | { |
4748 | 4763 | #ifndef GPAC_DISABLE_VRML |
4775 | 4790 | #endif |
4776 | 4791 | } |
4777 | 4792 | |
4778 | Bool gf_sg_javascript_initialized() | |
4779 | { | |
4780 | #ifdef GPAC_HAS_SPIDERMONKEY | |
4781 | if (js_rt) return 1; | |
4782 | #endif | |
4783 | return 0; | |
4784 | } | |
4785 | 4793 | |
4786 | 4794 | #ifdef GPAC_HAS_SPIDERMONKEY |
4787 | 4795 | |
4793 | 4801 | * (mozilla doc is wrong here) |
4794 | 4802 | * |
4795 | 4803 | * */ |
4804 | GF_EXPORT | |
4796 | 4805 | void gf_sg_lock_javascript(struct JSContext *cx, Bool LockIt) |
4797 | 4806 | { |
4798 | 4807 | if (!js_rt) return; |
4799 | assert(cx); | |
4808 | ||
4800 | 4809 | if (LockIt) { |
4801 | 4810 | gf_mx_p(js_rt->mx); |
4802 | 4811 | #ifdef JS_THREADSAFE |
4812 | assert(cx); | |
4803 | 4813 | if (gf_mx_get_num_locks(js_rt->mx)==1) { |
4804 | 4814 | #if (JS_VERSION>=185) |
4805 | 4815 | JS_SetRuntimeThread(js_rt->js_runtime); |
4810 | 4820 | #endif |
4811 | 4821 | } else { |
4812 | 4822 | #ifdef JS_THREADSAFE |
4823 | assert(cx); | |
4813 | 4824 | if (gf_mx_get_num_locks(js_rt->mx)==1) { |
4814 | 4825 | JS_EndRequest(cx); |
4815 | 4826 | #if (JS_VERSION>=185) |
4822 | 4833 | } |
4823 | 4834 | } |
4824 | 4835 | |
4836 | GF_EXPORT | |
4825 | 4837 | Bool gf_sg_try_lock_javascript(struct JSContext *cx) |
4826 | 4838 | { |
4827 | 4839 | assert(cx); |
32 | 32 | #include <gpac/internal/bifs_dev.h> |
33 | 33 | |
34 | 34 | |
35 | GF_EXPORT | |
35 | 36 | Bool gf_node_in_table_by_tag(u32 tag, u32 NDTType) |
36 | 37 | { |
37 | 38 | if (!tag) return 0; |
651 | 652 | /********************************************************************* |
652 | 653 | MF Fields manipulation (alloc, gf_realloc, GetAt) |
653 | 654 | *********************************************************************/ |
655 | GF_EXPORT | |
654 | 656 | const char *gf_sg_vrml_get_event_type_name(u32 EventType, Bool forX3D) |
655 | 657 | { |
656 | 658 | switch (EventType) { |
662 | 664 | } |
663 | 665 | } |
664 | 666 | |
667 | GF_EXPORT | |
665 | 668 | const char *gf_sg_vrml_get_field_type_by_name(u32 FieldType) |
666 | 669 | { |
667 | 670 | |
752 | 755 | |
753 | 756 | void gf_sg_sfurl_del(SFURL url) { if (url.url) gf_free(url.url); } |
754 | 757 | |
758 | GF_EXPORT | |
755 | 759 | Bool gf_sg_vrml_is_sf_field(u32 FieldType) |
756 | 760 | { |
757 | 761 | return (FieldType<GF_SG_VRML_FIRST_MF); |
858 | 862 | } |
859 | 863 | } |
860 | 864 | |
865 | GF_EXPORT | |
861 | 866 | u32 gf_sg_vrml_get_sf_type(u32 FieldType) |
862 | 867 | { |
863 | 868 | switch (FieldType) { |
1037 | 1042 | return GF_OK; |
1038 | 1043 | } |
1039 | 1044 | |
1045 | GF_EXPORT | |
1040 | 1046 | GF_Err gf_sg_vrml_mf_get_item(void *mf, u32 FieldType, void **new_ptr, u32 ItemPos) |
1041 | 1047 | { |
1042 | 1048 | u32 FieldSize; |
15347 | 15347 | } |
15348 | 15348 | |
15349 | 15349 | |
15350 | GF_EXPORT | |
15350 | 15351 | u32 gf_node_x3d_type_by_class_name(const char *node_name) |
15351 | 15352 | { |
15352 | 15353 | if(!node_name) return 0; |
717 | 717 | return att; |
718 | 718 | } |
719 | 719 | |
720 | GF_EXPORT | |
720 | 721 | GF_Err gf_node_get_attribute_by_name(GF_Node *node, char *name, u32 xmlns_code, Bool create_if_not_found, Bool set_default, GF_FieldInfo *field) |
721 | 722 | { |
722 | 723 | u32 attribute_tag = gf_xml_get_attribute_tag(node, name, xmlns_code); |
74 | 74 | tmp->odm = odm; |
75 | 75 | tmp->flags = codec->flags | GF_ESM_CODEC_IS_USE; |
76 | 76 | tmp->decio = codec->decio; |
77 | tmp->process = codec->process; | |
77 | 78 | return tmp; |
78 | 79 | } |
79 | 80 |
888 | 888 | return serv; |
889 | 889 | } |
890 | 890 | |
891 | GF_EXPORT | |
891 | 892 | Bool gf_term_is_supported_url(GF_Terminal *term, const char *fileName, Bool use_parent_url, Bool no_mime_check) |
892 | 893 | { |
893 | 894 | GF_InputService *ifce; |
59 | 59 | |
60 | 60 | |
61 | 61 | /*returns top-level OD of the presentation*/ |
62 | GF_EXPORT | |
62 | 63 | GF_ObjectManager *gf_term_get_root_object(GF_Terminal *term) |
63 | 64 | { |
64 | 65 | if (!term) return NULL; |
67 | 68 | } |
68 | 69 | |
69 | 70 | /*returns number of sub-ODs in the current root. scene_od must be an inline OD*/ |
71 | GF_EXPORT | |
70 | 72 | u32 gf_term_get_object_count(GF_Terminal *term, GF_ObjectManager *scene_od) |
71 | 73 | { |
72 | 74 | if (!term || !scene_od) return 0; |
76 | 78 | } |
77 | 79 | |
78 | 80 | /*returns indexed (0-based) OD manager in the scene*/ |
81 | GF_EXPORT | |
79 | 82 | GF_ObjectManager *gf_term_get_object(GF_Terminal *term, GF_ObjectManager *scene_od, u32 index) |
80 | 83 | { |
81 | 84 | if (!term || !scene_od) return NULL; |
84 | 87 | return (GF_ObjectManager *) gf_list_get(scene_od->subscene->resources, index); |
85 | 88 | } |
86 | 89 | |
90 | GF_EXPORT | |
87 | 91 | u32 gf_term_object_subscene_type(GF_Terminal *term, GF_ObjectManager *odm) |
88 | 92 | { |
89 | 93 | if (!term || !odm) return 0; |
105 | 109 | gf_scene_select_object(term->root_scene, odm); |
106 | 110 | } |
107 | 111 | |
112 | GF_EXPORT | |
108 | 113 | u32 gf_term_get_current_service_id(GF_Terminal *term) |
109 | 114 | { |
110 | 115 | SFURL *the_url; |
130 | 135 | info->total_dec_time = dec->total_dec_time; |
131 | 136 | } |
132 | 137 | |
138 | GF_EXPORT | |
133 | 139 | GF_Err gf_term_get_object_info(GF_Terminal *term, GF_ObjectManager *odm, GF_MediaInfo *info) |
134 | 140 | { |
135 | 141 | GF_Channel *ch; |
267 | 273 | return GF_OK; |
268 | 274 | } |
269 | 275 | |
270 | ||
276 | GF_EXPORT | |
271 | 277 | Bool gf_term_get_download_info(GF_Terminal *term, GF_ObjectManager *odm, u32 *d_enum, const char **server, const char **path, u32 *bytes_done, u32 *total_bytes, u32 *bytes_per_sec) |
272 | 278 | { |
273 | 279 | GF_DownloadSession * sess; |
282 | 288 | return 1; |
283 | 289 | } |
284 | 290 | |
291 | GF_EXPORT | |
285 | 292 | Bool gf_term_get_channel_net_info(GF_Terminal *term, GF_ObjectManager *odm, u32 *d_enum, u32 *chid, NetStatCommand *netcom, GF_Err *ret_code) |
286 | 293 | { |
287 | 294 | GF_Channel *ch; |
304 | 311 | return 1; |
305 | 312 | } |
306 | 313 | |
314 | GF_EXPORT | |
307 | 315 | GF_Err gf_term_get_service_info(GF_Terminal *term, GF_ObjectManager *odm, NetInfoCommand *netinfo) |
308 | 316 | { |
309 | 317 | GF_Err e; |
316 | 324 | return e; |
317 | 325 | } |
318 | 326 | |
319 | ||
327 | GF_EXPORT | |
320 | 328 | const char *gf_term_get_world_info(GF_Terminal *term, GF_ObjectManager *scene_od, GF_List *descriptions) |
321 | 329 | { |
322 | 330 | GF_Node *info; |
350 | 358 | return "GPAC"; |
351 | 359 | } |
352 | 360 | |
353 | ||
361 | GF_EXPORT | |
354 | 362 | GF_Err gf_term_dump_scene(GF_Terminal *term, char *rad_name, char **filename, Bool xml_dump, Bool skip_protos, GF_ObjectManager *scene_od) |
355 | 363 | { |
356 | 364 | #ifndef GPAC_DISABLE_SCENE_DUMP |
283 | 283 | u32 od_type; |
284 | 284 | char *ext; |
285 | 285 | char *sub_url = (char *) service_sub_url; |
286 | GF_Terminal *term; | |
287 | 286 | GF_Descriptor *desc; |
288 | 287 | |
289 | 288 | if (odm->flags & GF_ODM_DESTROYED) { |
291 | 290 | return; |
292 | 291 | } |
293 | 292 | // assert(odm->OD==NULL); |
294 | ||
295 | term = odm->term; | |
296 | 293 | |
297 | 294 | GF_LOG(GF_LOG_DEBUG, GF_LOG_MEDIA, ("[ODM] Setting up root object for %s\n", odm->net_service->url)); |
298 | 295 | |
584 | 581 | return; |
585 | 582 | } |
586 | 583 | odm->net_service = serv; |
584 | assert(odm->OD); | |
587 | 585 | if (!odm->OD->URLString) |
588 | 586 | odm->net_service->nb_odm_users++; |
589 | 587 | } |
590 | 588 | /*if this is a remote OD, we need a new manager and a new service...*/ |
589 | assert(odm->OD); | |
591 | 590 | if (odm->OD->URLString) { |
592 | 591 | GF_ClientService *parent = odm->net_service; |
593 | 592 | char *url = odm->OD->URLString; |
1880 | 1879 | { |
1881 | 1880 | GF_Segment *desc; |
1882 | 1881 | u32 i = 0; |
1882 | if (!odm->OD) return NULL; | |
1883 | 1883 | while ( (desc = (GF_Segment *)gf_list_enum(odm->OD->OCIDescriptors, &i)) ){ |
1884 | 1884 | if (desc->tag != GF_ODF_SEGMENT_TAG) continue; |
1885 | 1885 | if (!stricmp(desc->SegmentName, descName)) return desc; |
81 | 81 | gf_term_service_media_event(scene->scene_codec->odm, type); |
82 | 82 | } |
83 | 83 | |
84 | ||
84 | GF_EXPORT | |
85 | 85 | GF_Scene *gf_scene_new(GF_Scene *parentScene) |
86 | 86 | { |
87 | 87 | GF_Scene *tmp; |
781 | 781 | gf_term_send_event(term, &evt); |
782 | 782 | } |
783 | 783 | |
784 | GF_EXPORT | |
784 | 785 | GF_Err gf_term_step_clocks(GF_Terminal * term, u32 ms_diff) |
785 | 786 | { |
786 | 787 | u32 i, j; |
1222 | 1223 | } |
1223 | 1224 | |
1224 | 1225 | /*locks media quaue*/ |
1226 | GF_EXPORT | |
1225 | 1227 | void gf_term_lock_media_queue(GF_Terminal *term, Bool LockIt) |
1226 | 1228 | { |
1227 | 1229 | if (LockIt) { |
1269 | 1271 | void gf_term_service_media_event_with_download(GF_ObjectManager *odm, u32 event_type, u64 loaded_size, u64 total_size, u32 bytes_per_sec) |
1270 | 1272 | { |
1271 | 1273 | #ifndef GPAC_DISABLE_SVG |
1272 | u32 i, count, min_buffer, min_time, transport; | |
1274 | u32 i, count, min_buffer, min_time; | |
1273 | 1275 | Bool locked; |
1274 | 1276 | GF_DOMMediaEvent media_event; |
1275 | 1277 | GF_DOM_Event evt; |
1288 | 1290 | |
1289 | 1291 | |
1290 | 1292 | memset(&media_event, 0, sizeof(GF_DOMMediaEvent)); |
1291 | transport = 0; | |
1292 | 1293 | media_event.bufferValid = 0; |
1293 | 1294 | media_event.session_name = odm->net_service->url; |
1294 | 1295 | |
1336 | 1337 | } |
1337 | 1338 | |
1338 | 1339 | /* Browses all registered relocators (ZIP-based, ISOFF-based or file-system-based to relocate a URI based on the locale */ |
1340 | GF_EXPORT | |
1339 | 1341 | Bool gf_term_relocate_url(GF_Terminal *term, const char *service_url, const char *parent_url, char *out_relocated_url, char *out_localized_url) |
1340 | 1342 | { |
1341 | 1343 | u32 i, count; |
1809 | 1811 | return e; |
1810 | 1812 | } |
1811 | 1813 | |
1814 | GF_EXPORT | |
1812 | 1815 | GF_Err gf_term_get_screen_buffer(GF_Terminal *term, GF_VideoSurface *framebuffer) |
1813 | 1816 | { |
1814 | 1817 | if (!term) return GF_BAD_PARAM; |
1815 | 1818 | return gf_sc_get_screen_buffer(term->compositor, framebuffer, 0); |
1816 | 1819 | } |
1817 | 1820 | |
1821 | GF_EXPORT | |
1818 | 1822 | GF_Err gf_term_get_offscreen_buffer(GF_Terminal *term, GF_VideoSurface *framebuffer, u32 view_idx, u32 depth_buffer_type) |
1819 | 1823 | { |
1820 | 1824 | if (!term) return GF_BAD_PARAM; |
1821 | 1825 | return gf_sc_get_offscreen_buffer(term->compositor, framebuffer, view_idx, depth_buffer_type); |
1822 | 1826 | } |
1823 | 1827 | |
1828 | GF_EXPORT | |
1824 | 1829 | GF_Err gf_term_release_screen_buffer(GF_Terminal *term, GF_VideoSurface *framebuffer) |
1825 | 1830 | { |
1826 | 1831 | if (!term) return GF_BAD_PARAM; |
1898 | 1903 | return 0; |
1899 | 1904 | } |
1900 | 1905 | |
1906 | GF_EXPORT | |
1901 | 1907 | GF_Err gf_term_add_event_filter(GF_Terminal *terminal, GF_TermEventFilter *ef) |
1902 | 1908 | { |
1903 | 1909 | GF_Err e; |
1910 | 1916 | return e; |
1911 | 1917 | } |
1912 | 1918 | |
1919 | GF_EXPORT | |
1913 | 1920 | GF_Err gf_term_remove_event_filter(GF_Terminal *terminal, GF_TermEventFilter *ef) |
1914 | 1921 | { |
1915 | 1922 | if (!terminal || !ef || !terminal->event_filters) return GF_BAD_PARAM; |
1974 | 1981 | } |
1975 | 1982 | } |
1976 | 1983 | |
1984 | GF_EXPORT | |
1977 | 1985 | void gf_term_set_speed(GF_Terminal *term, Fixed speed) |
1978 | 1986 | { |
1979 | 1987 | Double fps; |
2005 | 2013 | gf_sc_set_fps(term->compositor, fps); |
2006 | 2014 | } |
2007 | 2015 | |
2016 | GF_EXPORT | |
2008 | 2017 | void gf_term_process_shortcut(GF_Terminal *term, GF_Event *ev) |
2009 | 2018 | { |
2010 | 2019 | GF_Event evt; |
2242 | 2251 | } |
2243 | 2252 | } |
2244 | 2253 | |
2254 | GF_EXPORT | |
2245 | 2255 | void gf_term_switch_quality(GF_Terminal *term, Bool up) |
2246 | 2256 | { |
2247 | 2257 | gf_scene_switch_quality(term->root_scene, up); |
95 | 95 | #define CDECL |
96 | 96 | #endif |
97 | 97 | |
98 | #ifndef SYMBOL_EXPORT | |
99 | #if defined(__GNUC__) && __GNUC__ >= 4 | |
100 | #define SYMBOL_EXPORT __attribute__((visibility("default"))) | |
101 | #endif | |
102 | #endif | |
103 | ||
98 | 104 | #if (USE_MALLOC==DL_MALLOC) |
99 | 105 | |
100 | 106 | CDECL void * dlmalloc(size_t size); |
168 | 174 | #else |
169 | 175 | |
170 | 176 | |
171 | CDECL | |
172 | 177 | size_t gpac_allocated_memory = 0; |
173 | 178 | size_t gpac_nb_alloc_blocs = 0; |
174 | 179 | |
293 | 298 | static void (*gf_mem_free_proto)(void *ptr, char *filename, int line) = gf_mem_free_basic; |
294 | 299 | static char *(*gf_mem_strdup_proto)(const char *str, char *filename, int line) = gf_mem_strdup_basic; |
295 | 300 | |
296 | CDECL | |
301 | SYMBOL_EXPORT CDECL | |
297 | 302 | void *gf_mem_malloc(size_t size, char *filename, int line) |
298 | 303 | { |
299 | 304 | return gf_mem_malloc_proto(size, filename, line); |
300 | 305 | } |
301 | CDECL | |
306 | ||
307 | SYMBOL_EXPORT CDECL | |
302 | 308 | void *gf_mem_calloc(size_t num, size_t size_of, char *filename, int line) |
303 | 309 | { |
304 | 310 | return gf_mem_calloc_proto(num, size_of, filename, line); |
305 | 311 | } |
306 | CDECL | |
312 | ||
313 | SYMBOL_EXPORT CDECL | |
307 | 314 | void *gf_mem_realloc(void *ptr, size_t size, char *filename, int line) |
308 | 315 | { |
309 | 316 | return gf_mem_realloc_proto(ptr, size, filename, line); |
310 | 317 | } |
311 | CDECL | |
318 | ||
319 | SYMBOL_EXPORT CDECL | |
312 | 320 | void gf_mem_free(void *ptr, char *filename, int line) |
313 | 321 | { |
314 | 322 | gf_mem_free_proto(ptr, filename, line); |
315 | 323 | } |
316 | CDECL | |
324 | ||
325 | SYMBOL_EXPORT CDECL | |
317 | 326 | char *gf_mem_strdup(const char *str, char *filename, int line) |
318 | 327 | { |
319 | 328 | return gf_mem_strdup_proto(str, filename, line); |
181 | 181 | |
182 | 182 | #define ZLIB_COMPRESS_SAFE 4 |
183 | 183 | |
184 | GF_EXPORT | |
184 | 185 | GF_Err gf_gz_compress_payload(char **data, u32 data_len, u32 *max_size) |
185 | 186 | { |
186 | 187 | z_stream stream; |
223 | 224 | return GF_OK; |
224 | 225 | } |
225 | 226 | |
227 | GF_EXPORT | |
226 | 228 | GF_Err gf_gz_decompress_payload(char *data, u32 data_len, char **uncompressed_data, u32 *out_size) |
227 | 229 | { |
228 | 230 | z_stream d_stream; |
845 | 845 | |
846 | 846 | static void gf_cmx_apply_argb(GF_ColorMatrix *_this, u8 *a_, u8 *r_, u8 *g_, u8 *b_); |
847 | 847 | |
848 | //#define COLORKEY_MPEG4_STRICT | |
849 | ||
848 | 850 | GF_EXPORT |
849 | 851 | GF_Err gf_stretch_bits(GF_VideoSurface *dst, GF_VideoSurface *src, GF_Window *dst_wnd, GF_Window *src_wnd, u8 alpha, Bool flip, GF_ColorKey *key, GF_ColorMatrix *cmat) |
850 | 852 | { |
1044 | 1046 | load_line_yuva(src->video_buffer, x_off, the_row, src->pitch_y, src_w, src->height, tmp); |
1045 | 1047 | } |
1046 | 1048 | the_row = src_row - 1; |
1049 | ||
1050 | if (cmat) { | |
1051 | for (i=0; i<2*src_w; i++) { | |
1052 | u32 idx = 4*i; | |
1053 | gf_cmx_apply_argb(cmat, &tmp[idx+3], &tmp[idx], &tmp[idx+1], &tmp[idx+2]); | |
1054 | } | |
1055 | } | |
1056 | if (key) { | |
1057 | for (i=0; i<2*src_w; i++) { | |
1058 | u32 idx = 4*i; | |
1059 | s32 thres, v; | |
1060 | v = tmp[idx]-kr; thres = ABS(v); | |
1061 | v = tmp[idx+1]-kg; thres += ABS(v); | |
1062 | v = tmp[idx+2]-kb; thres += ABS(v); | |
1063 | thres/=3; | |
1064 | #ifdef COLORKEY_MPEG4_STRICT | |
1065 | if (thres < kl) tmp[idx+3] = 0; | |
1066 | else if (thres <= kh) tmp[idx+3] = (thres-kl)*ka / (kh-kl); | |
1067 | #else | |
1068 | if (thres < kh) tmp[idx+3] = 0; | |
1069 | #endif | |
1070 | else tmp[idx+3] = ka; | |
1071 | } | |
1072 | } | |
1047 | 1073 | } |
1048 | 1074 | rows = flip ? tmp : tmp + src_w * 4; |
1049 | 1075 | } else { |
1070 | 1096 | v = tmp[idx+1]-kg; thres += ABS(v); |
1071 | 1097 | v = tmp[idx+2]-kb; thres += ABS(v); |
1072 | 1098 | thres/=3; |
1073 | #if 0 | |
1099 | #ifdef COLORKEY_MPEG4_STRICT | |
1074 | 1100 | if (thres < kl) tmp[idx+3] = 0; |
1075 | 1101 | else if (thres <= kh) tmp[idx+3] = (thres-kl)*ka / (kh-kl); |
1076 | 1102 | #else |
1098 | 1124 | v = tmp[idx+1]-kg; thres += ABS(v); |
1099 | 1125 | v = tmp[idx+2]-kb; thres += ABS(v); |
1100 | 1126 | thres/=3; |
1101 | #if 0 | |
1127 | #ifdef COLORKEY_MPEG4_STRICT | |
1102 | 1128 | if (thres < kl) tmp[idx+3] = 0; |
1103 | 1129 | else if (thres <= kh) tmp[idx+3] = (thres-kl)*ka / (kh-kl); |
1104 | 1130 | #else |
585 | 585 | GF_LOG(GF_LOG_WARNING, GF_LOG_NETWORK, ("[CACHE] Cannot find URL %s, cache file won't be deleted.\n", url)); |
586 | 586 | } |
587 | 587 | |
588 | GF_EXPORT | |
588 | 589 | void gf_dm_delete_cached_file_entry_session(const GF_DownloadSession * sess, const char * url) { |
589 | 590 | if (sess && sess->dm && url) { |
590 | 591 | GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[CACHE] Requesting deletion for %s\n", url)); |
623 | 624 | gf_mx_v(sess->mx); |
624 | 625 | } |
625 | 626 | |
627 | GF_EXPORT | |
626 | 628 | void gf_dm_sess_del(GF_DownloadSession *sess) |
627 | 629 | { |
628 | 630 | GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[Downloader] gf_dm_sess_del(%p)\n", sess )); |
706 | 708 | return (sess->flags & GF_DOWNLOAD_SESSION_THREAD_DEAD) ? 1 : 0; |
707 | 709 | } |
708 | 710 | |
711 | GF_EXPORT | |
709 | 712 | GF_Err gf_dm_sess_last_error(GF_DownloadSession *sess) |
710 | 713 | { |
711 | 714 | if (!sess) return GF_BAD_PARAM; |
877 | 880 | return GF_OK; |
878 | 881 | } |
879 | 882 | |
883 | GF_EXPORT | |
880 | 884 | GF_Err gf_dm_sess_setup_from_url(GF_DownloadSession *sess, const char *url) |
881 | 885 | { |
882 | 886 | Bool socket_changed = 0; |
985 | 989 | } |
986 | 990 | |
987 | 991 | |
992 | GF_EXPORT | |
988 | 993 | GF_DownloadSession *gf_dm_sess_new_simple(GF_DownloadManager * dm, const char *url, u32 dl_flags, |
989 | 994 | gf_dm_user_io user_io, |
990 | 995 | void *usr_cbk, |
1017 | 1022 | return sess; |
1018 | 1023 | } |
1019 | 1024 | |
1025 | GF_EXPORT | |
1020 | 1026 | GF_DownloadSession *gf_dm_sess_new(GF_DownloadManager *dm, const char *url, u32 dl_flags, |
1021 | 1027 | gf_dm_user_io user_io, |
1022 | 1028 | void *usr_cbk, |
1281 | 1287 | return sess->cache_entry; |
1282 | 1288 | } |
1283 | 1289 | |
1284 | ||
1290 | GF_EXPORT | |
1285 | 1291 | const char *gf_dm_sess_mime_type(GF_DownloadSession *sess) |
1286 | 1292 | { |
1287 | 1293 | DownloadedCacheEntry entry; |
1297 | 1303 | return gf_cache_get_mime_type( sess->cache_entry ); |
1298 | 1304 | } |
1299 | 1305 | |
1306 | GF_EXPORT | |
1300 | 1307 | GF_Err gf_dm_sess_set_range(GF_DownloadSession *sess, u64 start_range, u64 end_range) |
1301 | 1308 | { |
1302 | 1309 | if (!sess) return GF_BAD_PARAM; |
1308 | 1315 | return GF_OK; |
1309 | 1316 | } |
1310 | 1317 | |
1318 | GF_EXPORT | |
1311 | 1319 | GF_Err gf_dm_sess_process(GF_DownloadSession *sess) |
1312 | 1320 | { |
1313 | 1321 | Bool go; |
1403 | 1411 | } |
1404 | 1412 | #endif |
1405 | 1413 | |
1414 | ||
1415 | GF_EXPORT | |
1406 | 1416 | GF_DownloadManager *gf_dm_new(GF_Config *cfg) |
1407 | 1417 | { |
1408 | 1418 | const char *opt; |
1473 | 1483 | } |
1474 | 1484 | } |
1475 | 1485 | |
1486 | GF_EXPORT | |
1476 | 1487 | void gf_dm_del(GF_DownloadManager *dm) |
1477 | 1488 | { |
1478 | 1489 | if (!dm) |
1733 | 1744 | return gf_cache_get_content_length(sess->cache_entry) != 0; |
1734 | 1745 | } |
1735 | 1746 | |
1747 | GF_EXPORT | |
1736 | 1748 | void gf_dm_sess_abort(GF_DownloadSession * sess) |
1737 | 1749 | { |
1738 | 1750 | assert(sess); |
2612 | 2624 | } |
2613 | 2625 | |
2614 | 2626 | |
2615 | GF_Err gf_dm_wget(const char *url, const char *filename){ | |
2627 | GF_EXPORT | |
2628 | GF_Err gf_dm_wget(const char *url, const char *filename) | |
2629 | { | |
2616 | 2630 | GF_Err e; |
2617 | 2631 | GF_DownloadManager * dm = NULL; |
2618 | 2632 | dm = gf_dm_new(NULL); |
2651 | 2665 | return e; |
2652 | 2666 | } |
2653 | 2667 | |
2668 | GF_EXPORT | |
2654 | 2669 | GF_Err gf_dm_get_file_memory(const char *url, char **out_data, u32 *out_size, char **out_mime) |
2655 | 2670 | { |
2656 | 2671 | GF_Err e; |
2708 | 2723 | return e; |
2709 | 2724 | } |
2710 | 2725 | |
2726 | GF_EXPORT | |
2711 | 2727 | const char *gf_dm_sess_get_resource_name(GF_DownloadSession *dnload) |
2712 | 2728 | { |
2713 | 2729 | return dnload ? dnload->orig_url : NULL; |
2905 | 2921 | } |
2906 | 2922 | } |
2907 | 2923 | |
2924 | GF_EXPORT | |
2908 | 2925 | u32 gf_dm_get_data_rate(GF_DownloadManager *dm) |
2909 | 2926 | { |
2910 | 2927 | return dm->limit_data_rate; |
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
482 | GF_EXPORT | |
482 | 483 | GF_Config *gf_cfg_init(const char *file, Bool *new_cfg) |
483 | 484 | { |
484 | 485 | GF_Config *cfg; |
74 | 74 | |
75 | 75 | |
76 | 76 | #ifndef WIN32 |
77 | ||
78 | GF_EXPORT | |
77 | 79 | u32 gf_sys_clock() |
78 | 80 | { |
79 | 81 | struct timeval now; |
83 | 85 | #endif |
84 | 86 | |
85 | 87 | |
88 | GF_EXPORT | |
86 | 89 | void gf_sleep(u32 ms) |
87 | 90 | { |
88 | 91 | #ifdef WIN32 |
276 | 279 | |
277 | 280 | #endif |
278 | 281 | |
282 | GF_EXPORT | |
279 | 283 | GF_Err gf_delete_file(const char *fileName) |
280 | 284 | { |
281 | 285 | #if defined(_WIN32_WCE) |
328 | 332 | #include <sys/stat.h> |
329 | 333 | #endif |
330 | 334 | |
335 | GF_EXPORT | |
331 | 336 | u64 gf_file_modification_time(const char *filename) |
332 | 337 | { |
333 | 338 | #if defined(_WIN32_WCE) |
361 | 366 | return 0; |
362 | 367 | } |
363 | 368 | |
369 | GF_EXPORT | |
364 | 370 | FILE *gf_temp_file_new() |
365 | 371 | { |
366 | 372 | #if defined(_WIN32_WCE) |
388 | 394 | #endif |
389 | 395 | } |
390 | 396 | |
391 | ||
397 | GF_EXPORT | |
392 | 398 | void gf_utc_time_since_1970(u32 *sec, u32 *msec) |
393 | 399 | { |
394 | 400 | #if defined (WIN32) && !defined(_WIN32_WCE) |
429 | 435 | |
430 | 436 | |
431 | 437 | /*enumerate directories*/ |
438 | GF_EXPORT | |
432 | 439 | GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir_fct, void *cbck, const char *filter) |
433 | 440 | { |
434 | 441 | char item_path[GF_MAX_PATH]; |
636 | 643 | |
637 | 644 | |
638 | 645 | #ifndef WIN32 |
646 | GF_EXPORT | |
639 | 647 | char * my_str_upr(char *str) |
640 | 648 | { |
641 | 649 | u32 i; |
644 | 652 | } |
645 | 653 | return str; |
646 | 654 | } |
655 | ||
656 | GF_EXPORT | |
647 | 657 | char * my_str_lwr(char *str) |
648 | 658 | { |
649 | 659 | u32 i; |
654 | 664 | } |
655 | 665 | #endif |
656 | 666 | |
667 | GF_EXPORT | |
657 | 668 | u64 gf_f64_tell(FILE *fp) |
658 | 669 | { |
659 | 670 | #if defined(_WIN32_WCE) |
671 | 682 | #endif |
672 | 683 | } |
673 | 684 | |
685 | GF_EXPORT | |
674 | 686 | u64 gf_f64_seek(FILE *fp, s64 offset, s32 whence) |
675 | 687 | { |
676 | 688 | #if defined(_WIN32_WCE) |
688 | 700 | #endif |
689 | 701 | } |
690 | 702 | |
703 | GF_EXPORT | |
691 | 704 | FILE *gf_f64_open(const char *file_name, const char *mode) |
692 | 705 | { |
693 | 706 | #if defined(WIN32) |
704 | 717 | #if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! defined(_GNU_SOURCE) |
705 | 718 | #define HAVE_STRERROR_R 1 |
706 | 719 | #endif |
720 | ||
721 | GF_EXPORT | |
707 | 722 | size_t gf_fwrite(const void *ptr, size_t size, size_t nmemb, |
708 | 723 | FILE *stream) |
709 | 724 | { |
758 | 773 | { |
759 | 774 | return kbhit(); |
760 | 775 | } |
776 | ||
761 | 777 | char gf_prompt_get_char() |
762 | 778 | { |
763 | 779 | return getchar(); |
764 | 780 | } |
781 | ||
765 | 782 | void gf_prompt_set_echo_off(Bool echo_off) |
766 | 783 | { |
767 | 784 | DWORD flags; |
808 | 825 | close_keyboard(0); |
809 | 826 | } |
810 | 827 | |
828 | GF_EXPORT | |
811 | 829 | Bool gf_prompt_has_input() |
812 | 830 | { |
813 | 831 | u8 ch; |
828 | 846 | return 0; |
829 | 847 | } |
830 | 848 | |
849 | GF_EXPORT | |
831 | 850 | char gf_prompt_get_char() |
832 | 851 | { |
833 | 852 | char ch; |
997 | 1016 | |
998 | 1017 | static u64 memory_at_gpac_startup = 0; |
999 | 1018 | |
1019 | GF_EXPORT | |
1000 | 1020 | void gf_sys_init(Bool enable_memory_tracker) |
1001 | 1021 | { |
1002 | 1022 | if (!sys_init) { |
1092 | 1112 | } |
1093 | 1113 | } |
1094 | 1114 | |
1115 | GF_EXPORT | |
1095 | 1116 | void gf_sys_close() |
1096 | 1117 | { |
1097 | 1118 | if (sys_init > 0) { |
1391 | 1412 | #include <mach/shared_memory_server.h> |
1392 | 1413 | #endif |
1393 | 1414 | #include <mach/mach_error.h> |
1394 | ||
1415 | ||
1395 | 1416 | static u64 total_physical_memory = 0; |
1396 | ||
1417 | ||
1397 | 1418 | Bool gf_sys_get_rti_os(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags) |
1398 | 1419 | { |
1399 | 1420 | size_t length; |
1674 | 1695 | |
1675 | 1696 | #endif |
1676 | 1697 | |
1677 | ||
1698 | GF_EXPORT | |
1678 | 1699 | Bool gf_sys_get_rti(u32 refresh_time_ms, GF_SystemRTInfo *rti, u32 flags) |
1679 | 1700 | { |
1680 | 1701 | Bool res = gf_sys_get_rti_os(refresh_time_ms, rti, flags); |
1700 | 1721 | } |
1701 | 1722 | |
1702 | 1723 | |
1703 | ||
1704 | ||
1724 | GF_EXPORT | |
1705 | 1725 | Bool gf_sys_get_battery_state(Bool *onBattery, u32 *onCharge, u32*level, u32 *batteryLifeTime, u32 *batteryFullLifeTime) |
1706 | 1726 | { |
1707 | 1727 | #if defined(_WIN32_WCE) |
1828 | 1848 | }; |
1829 | 1849 | #endif |
1830 | 1850 | |
1831 | ||
1851 | GF_EXPORT | |
1832 | 1852 | GF_GlobalLock * gf_global_resource_lock(const char * resourceName){ |
1833 | 1853 | #ifdef WIN32 |
1834 | 1854 | #ifdef _WIN32_WCE |
1875 | 1895 | * \param lock The resource to unlock |
1876 | 1896 | * \return GF_OK if evertything went fine |
1877 | 1897 | */ |
1898 | GF_EXPORT | |
1878 | 1899 | GF_Err gf_global_resource_unlock(GF_GlobalLock * lock){ |
1879 | 1900 | if (!lock) |
1880 | 1901 | return GF_BAD_PARAM; |
333 | 333 | inst->interfaces = gf_list_new(); |
334 | 334 | inst->plugman = pm; |
335 | 335 | inst->name = gf_strdup("gm_gpac_js.dylib"); |
336 | gf_list_add(pm->plug_list, inst); | |
336 | 337 | } |
337 | 338 | { |
338 | 339 | ModuleInstance *inst; |
402 | 403 | gf_enum_directory(pm->dir, 0, enum_modules, pm, ".dylib"); |
403 | 404 | #endif |
404 | 405 | #else |
405 | GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("Refreshing list of modules in directory %s...\n", pm->dir)); | |
406 | GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("Refreshing list of modules in directory %s...\n", pm->dir)); | |
406 | 407 | gf_enum_directory(pm->dir, 0, enum_modules, pm, ".so"); |
407 | 408 | #endif |
408 | 409 |
306 | 306 | #endif |
307 | 307 | |
308 | 308 | |
309 | GF_EXPORT | |
309 | 310 | GF_Err gf_sk_get_host_name(char *buffer) |
310 | 311 | { |
311 | 312 | s32 ret = gethostname(buffer, GF_MAX_IP_NAME_LEN); |
345 | 346 | } |
346 | 347 | |
347 | 348 | |
349 | GF_EXPORT | |
348 | 350 | GF_Socket *gf_sk_new(u32 SocketType) |
349 | 351 | { |
350 | 352 | GF_Socket *tmp; |
373 | 375 | return tmp; |
374 | 376 | } |
375 | 377 | |
378 | GF_EXPORT | |
376 | 379 | GF_Err gf_sk_set_buffer_size(GF_Socket *sock, Bool SendBuffer, u32 NewSize) |
377 | 380 | { |
378 | 381 | if (!sock || !sock->socket) return GF_BAD_PARAM; |
385 | 388 | return GF_OK; |
386 | 389 | } |
387 | 390 | |
391 | GF_EXPORT | |
388 | 392 | GF_Err gf_sk_set_block_mode(GF_Socket *sock, u32 NonBlockingOn) |
389 | 393 | { |
390 | 394 | s32 res; |
446 | 450 | } |
447 | 451 | |
448 | 452 | |
453 | GF_EXPORT | |
449 | 454 | void gf_sk_del(GF_Socket *sock) |
450 | 455 | { |
451 | 456 | assert( sock ); |
601 | 606 | |
602 | 607 | //binds the given socket to the specified port. If ReUse is true |
603 | 608 | //this will enable reuse of ports on a single machine |
609 | GF_EXPORT | |
604 | 610 | GF_Err gf_sk_bind(GF_Socket *sock, const char *local_ip, u16 port, const char *peer_name, u16 peer_port, u32 options) |
605 | 611 | { |
606 | 612 | #ifdef GPAC_HAS_IPV6 |
803 | 809 | } |
804 | 810 | |
805 | 811 | //send length bytes of a buffer |
812 | GF_EXPORT | |
806 | 813 | GF_Err gf_sk_send(GF_Socket *sock, const char *buffer, u32 length) |
807 | 814 | { |
808 | 815 | u32 count; |
865 | 872 | } |
866 | 873 | |
867 | 874 | |
875 | GF_EXPORT | |
868 | 876 | u32 gf_sk_is_multicast_address(const char *multi_IPAdd) |
869 | 877 | { |
870 | 878 | #ifdef GPAC_HAS_IPV6 |
893 | 901 | #endif |
894 | 902 | } |
895 | 903 | |
904 | GF_EXPORT | |
896 | 905 | GF_Err gf_sk_setup_multicast(GF_Socket *sock, const char *multi_IPAdd, u16 MultiPortNumber, u32 TTL, Bool NoBind, char *local_interface_ip) |
897 | 906 | { |
898 | 907 | s32 ret; |
1078 | 1087 | //fetch nb bytes on a socket and fill the buffer from startFrom |
1079 | 1088 | //length is the allocated size of the receiving buffer |
1080 | 1089 | //BytesRead is the number of bytes read from the network |
1090 | GF_EXPORT | |
1081 | 1091 | GF_Err gf_sk_receive(GF_Socket *sock, char *buffer, u32 length, u32 startFrom, u32 *BytesRead) |
1082 | 1092 | { |
1083 | 1093 | s32 res; |
102 | 102 | #endif |
103 | 103 | |
104 | 104 | |
105 | GF_EXPORT | |
105 | 106 | GF_Thread *gf_th_new(const char *name) |
106 | 107 | { |
107 | 108 | GF_Thread *tmp = gf_malloc(sizeof(GF_Thread)); |
212 | 213 | #endif |
213 | 214 | } |
214 | 215 | |
216 | GF_EXPORT | |
215 | 217 | GF_Err gf_th_run(GF_Thread *t, u32 (*Run)(void *param), void *param) |
216 | 218 | { |
217 | 219 | #ifdef WIN32 |
285 | 287 | Thread_Stop(t, 0); |
286 | 288 | } |
287 | 289 | |
290 | GF_EXPORT | |
288 | 291 | void gf_th_del(GF_Thread *t) |
289 | 292 | { |
290 | 293 | Thread_Stop(t, 0); |
371 | 374 | } |
372 | 375 | |
373 | 376 | |
377 | GF_EXPORT | |
374 | 378 | u32 gf_th_id() |
375 | 379 | { |
376 | 380 | #ifdef WIN32 |
400 | 404 | }; |
401 | 405 | |
402 | 406 | |
407 | GF_EXPORT | |
403 | 408 | GF_Mutex *gf_mx_new(const char *name) |
404 | 409 | { |
405 | 410 | #ifndef WIN32 |
435 | 440 | return tmp; |
436 | 441 | } |
437 | 442 | |
443 | GF_EXPORT | |
438 | 444 | void gf_mx_del(GF_Mutex *mx) |
439 | 445 | { |
440 | 446 | #ifdef WIN32 |
455 | 461 | gf_free(mx); |
456 | 462 | } |
457 | 463 | |
464 | GF_EXPORT | |
458 | 465 | void gf_mx_v(GF_Mutex *mx) |
459 | 466 | { |
460 | 467 | u32 caller; |
487 | 494 | } |
488 | 495 | } |
489 | 496 | |
497 | GF_EXPORT | |
490 | 498 | u32 gf_mx_p(GF_Mutex *mx) |
491 | 499 | { |
492 | 500 | #ifndef WIN32 |
545 | 553 | return -1; |
546 | 554 | } |
547 | 555 | |
556 | GF_EXPORT | |
548 | 557 | Bool gf_mx_try_lock(GF_Mutex *mx) |
549 | 558 | { |
550 | 559 | u32 caller; |
600 | 609 | #endif |
601 | 610 | }; |
602 | 611 | |
603 | ||
612 | GF_EXPORT | |
604 | 613 | GF_Semaphore *gf_sema_new(u32 MaxCount, u32 InitCount) |
605 | 614 | { |
606 | 615 | GF_Semaphore *tmp = gf_malloc(sizeof(GF_Semaphore)); |
643 | 652 | return tmp; |
644 | 653 | } |
645 | 654 | |
655 | GF_EXPORT | |
646 | 656 | void gf_sema_del(GF_Semaphore *sm) |
647 | 657 | { |
648 | 658 | #if defined(WIN32) |
659 | 669 | gf_free(sm); |
660 | 670 | } |
661 | 671 | |
672 | GF_EXPORT | |
662 | 673 | u32 gf_sema_notify(GF_Semaphore *sm, u32 NbRelease) |
663 | 674 | { |
664 | 675 | u32 prevCount; |
701 | 712 | #endif |
702 | 713 | } |
703 | 714 | |
715 | GF_EXPORT | |
704 | 716 | Bool gf_sema_wait_for(GF_Semaphore *sm, u32 TimeOut) |
705 | 717 | { |
706 | 718 | #ifdef WIN32 |
22 | 22 | */ |
23 | 23 | #include <gpac/ringbuffer.h> |
24 | 24 | |
25 | GF_EXPORT | |
25 | 26 | GF_Ringbuffer * gf_ringbuffer_new(u32 sz) |
26 | 27 | { |
27 | 28 | GF_Ringbuffer *rb; |
39 | 40 | return rb; |
40 | 41 | } |
41 | 42 | |
43 | GF_EXPORT | |
42 | 44 | void gf_ringbuffer_del(GF_Ringbuffer * ringbuffer){ |
43 | 45 | if (!ringbuffer) |
44 | 46 | return; |
70 | 72 | } |
71 | 73 | } |
72 | 74 | |
75 | GF_EXPORT | |
73 | 76 | u32 gf_ringbuffer_available_for_read (GF_Ringbuffer * rb) |
74 | 77 | { |
75 | 78 | size_t w, r; |
84 | 87 | } |
85 | 88 | } |
86 | 89 | |
90 | GF_EXPORT | |
87 | 91 | u32 gf_ringbuffer_read(GF_Ringbuffer *rb, u8 *dest, u32 szDest) |
88 | 92 | { |
89 | 93 | u32 free_sz, sz2, to_read, n1, n2; |
117 | 121 | return to_read; |
118 | 122 | } |
119 | 123 | |
124 | GF_EXPORT | |
120 | 125 | u32 gf_ringbuffer_write (GF_Ringbuffer * rb, const u8 *src, u32 sz) |
121 | 126 | { |
122 | 127 | u32 free_sz, sz2, to_write, n1, n2; |