-
Notifications
You must be signed in to change notification settings - Fork 513
/
filedump.c
4475 lines (4013 loc) · 147 KB
/
filedump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2021
* All rights reserved
*
* This file is part of GPAC / mp4box application
*
* GPAC is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GPAC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include "mp4box.h"
#if defined(GPAC_DISABLE_ISOM) || defined(GPAC_DISABLE_ISOM_WRITE)
#error "Cannot compile MP4Box if GPAC is not built with ISO File Format support"
#else
#ifndef GPAC_DISABLE_X3D
#include <gpac/nodes_x3d.h>
#endif
#ifndef GPAC_DISABLE_BIFS
#include <gpac/internal/bifs_dev.h>
#endif
#ifndef GPAC_DISABLE_VRML
#include <gpac/nodes_mpeg4.h>
#endif
#include <gpac/constants.h>
#include <gpac/avparse.h>
#include <gpac/internal/media_dev.h>
/*ISO 639 languages*/
#include <gpac/iso639.h>
#include <gpac/mpegts.h>
#ifndef GPAC_DISABLE_SMGR
#include <gpac/scene_manager.h>
#endif
#include <gpac/internal/media_dev.h>
#include <gpac/media_tools.h>
/*for built-in box printing*/
#include <gpac/internal/isomedia_dev.h>
#include <gpac/download.h>
#include <gpac/mpd.h>
extern u32 swf_flags;
extern Float swf_flatten_angle;
extern GF_FileType get_file_type_by_ext(char *inName);
extern u32 fs_dump_flags;
extern Bool dump_check_xml;
void scene_coding_log(void *cbk, GF_LOG_Level log_level, GF_LOG_Tool log_tool, const char *fmt, va_list vlist);
#ifdef GPAC_DISABLE_LOG
void mp4box_log(const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
vfprintf(stderr, fmt, vlist);
fflush(stderr);
va_end(vl);
}
#endif
u32 PrintLanguages(char *val, u32 opt)
{
u32 i=0, count = gf_lang_get_count();
fprintf(stderr, "Supported ISO 639 languages and codes:\n\n");
for (i=0; i<count; i++) {
if (gf_lang_get_2cc(i)) {
fprintf(stderr, "%s (%s - %s)\n", gf_lang_get_name(i), gf_lang_get_3cc(i), gf_lang_get_2cc(i));
}
}
return 1;
}
static const char *GetLanguage(char *lcode)
{
s32 idx = gf_lang_find(lcode);
if (idx>=0) return gf_lang_get_name(idx);
return lcode;
}
GF_Err dump_isom_cover_art(GF_ISOFile *file, char *inName, Bool is_final_name)
{
const u8 *tag;
FILE *t;
u32 tag_len;
GF_Err e = gf_isom_apple_get_tag(file, GF_ISOM_ITUNE_COVER_ART, &tag, &tag_len);
if (e!=GF_OK) {
if (e==GF_URL_ERROR) {
M4_LOG(GF_LOG_WARNING, ("No cover art found\n"));
return GF_OK;
}
return e;
}
if (inName) {
char szName[1024];
if (is_final_name) {
strcpy(szName, inName);
} else {
sprintf(szName, "%s.%s", inName, (tag_len>>31) ? "png" : "jpg");
}
t = gf_fopen(szName, "wb");
if (!t) {
M4_LOG(GF_LOG_ERROR, ("Failed to open %s for dumping\n", szName));
return GF_IO_ERR;
}
} else {
t = stdout;
}
gf_fwrite(tag, tag_len & 0x7FFFFFFF, t);
if (inName) gf_fclose(t);
return GF_OK;
}
#ifndef GPAC_DISABLE_SCENE_DUMP
GF_Err dump_isom_scene(char *file, char *inName, Bool is_final_name, GF_SceneDumpFormat dump_mode, Bool do_log, Bool no_odf_conv)
{
GF_Err e;
GF_SceneManager *ctx;
GF_SceneGraph *sg;
GF_SceneLoader load;
GF_FileType ftype;
gf_log_cbk prev_logs = NULL;
FILE *logs = NULL;
sg = gf_sg_new();
ctx = gf_sm_new(sg);
memset(&load, 0, sizeof(GF_SceneLoader));
load.fileName = file;
load.ctx = ctx;
load.swf_import_flags = swf_flags;
if (dump_mode == GF_SM_DUMP_SVG) {
load.swf_import_flags |= GF_SM_SWF_USE_SVG;
load.svgOutFile = inName;
}
load.swf_flatten_limit = swf_flatten_angle;
ftype = get_file_type_by_ext(file);
if (ftype == GF_FILE_TYPE_ISO_MEDIA) {
load.isom = gf_isom_open(file, GF_ISOM_OPEN_READ, NULL);
if (!load.isom) {
e = gf_isom_last_error(NULL);
M4_LOG(GF_LOG_ERROR, ("Error opening file: %s\n", gf_error_to_string(e)));
gf_sm_del(ctx);
gf_sg_del(sg);
return e;
}
if (no_odf_conv)
gf_isom_disable_odf_conversion(load.isom, GF_TRUE);
} else if (ftype==GF_FILE_TYPE_LSR_SAF) {
load.isom = gf_isom_open("saf_conv", GF_ISOM_WRITE_EDIT, NULL);
#ifndef GPAC_DISABLE_MEDIA_IMPORT
if (load.isom) {
GF_Fraction _frac = {0,0};
e = import_file(load.isom, file, 0, _frac, 0, NULL, NULL, NULL, 0);
} else
#else
M4_LOG(GF_LOG_WARNING, ("Warning: GPAC was compiled without Media Import support\n"));
#endif
e = gf_isom_last_error(NULL);
if (e) {
M4_LOG(GF_LOG_ERROR, ("Error importing file: %s\n", gf_error_to_string(e)));
gf_sm_del(ctx);
gf_sg_del(sg);
if (load.isom) gf_isom_delete(load.isom);
return e;
}
}
if (do_log) {
char szLog[GF_MAX_PATH];
sprintf(szLog, "%s_dec.logs", inName);
logs = gf_fopen(szLog, "wt");
gf_log_set_tool_level(GF_LOG_CODING, GF_LOG_DEBUG);
prev_logs = gf_log_set_callback(logs, scene_coding_log);
}
e = gf_sm_load_init(&load);
if (!e) e = gf_sm_load_run(&load);
gf_sm_load_done(&load);
if (logs) {
gf_log_set_tool_level(GF_LOG_CODING, GF_LOG_ERROR);
gf_log_set_callback(NULL, prev_logs);
gf_fclose(logs);
}
if (!e && dump_mode != GF_SM_DUMP_SVG) {
u32 count = gf_list_count(ctx->streams);
if (count)
fprintf(stderr, "Scene loaded - dumping %d systems streams\n", count);
else
fprintf(stderr, "Scene loaded - dumping root scene\n");
e = gf_sm_dump(ctx, inName, is_final_name, dump_mode);
}
gf_sm_del(ctx);
gf_sg_del(sg);
if (e) M4_LOG(GF_LOG_ERROR, ("Error loading scene: %s\n", gf_error_to_string(e)));
if (load.isom) gf_isom_delete(load.isom);
return e;
}
#endif
#ifndef GPAC_DISABLE_SCENE_STATS
static void dump_stats(FILE *dump, const GF_SceneStatistics *stats)
{
u32 i;
s32 created, count, draw_created, draw_count, deleted, draw_deleted;
created = count = draw_created = draw_count = deleted = draw_deleted = 0;
fprintf(dump, "<NodeStatistics>\n");
fprintf(dump, "<General NumberOfNodeTypes=\"%d\"/>\n", gf_list_count(stats->node_stats));
for (i=0; i<gf_list_count(stats->node_stats); i++) {
GF_NodeStats *ptr = gf_list_get(stats->node_stats, i);
fprintf(dump, "<NodeStat NodeName=\"%s\">\n", ptr->name);
switch (ptr->tag) {
#ifndef GPAC_DISABLE_VRML
case TAG_MPEG4_Bitmap:
case TAG_MPEG4_Background2D:
case TAG_MPEG4_Background:
case TAG_MPEG4_Box:
case TAG_MPEG4_Circle:
case TAG_MPEG4_CompositeTexture2D:
case TAG_MPEG4_CompositeTexture3D:
case TAG_MPEG4_Cylinder:
case TAG_MPEG4_Cone:
case TAG_MPEG4_Curve2D:
case TAG_MPEG4_Extrusion:
case TAG_MPEG4_ElevationGrid:
case TAG_MPEG4_IndexedFaceSet2D:
case TAG_MPEG4_IndexedFaceSet:
case TAG_MPEG4_IndexedLineSet2D:
case TAG_MPEG4_IndexedLineSet:
case TAG_MPEG4_PointSet2D:
case TAG_MPEG4_PointSet:
case TAG_MPEG4_Rectangle:
case TAG_MPEG4_Sphere:
case TAG_MPEG4_Text:
case TAG_MPEG4_Ellipse:
case TAG_MPEG4_XCurve2D:
draw_count += ptr->nb_created + ptr->nb_used - ptr->nb_del;
draw_deleted += ptr->nb_del;
draw_created += ptr->nb_created;
break;
#endif /*GPAC_DISABLE_VRML*/
}
fprintf(dump, "<Instanciation NbObjects=\"%d\" NbUse=\"%d\" NbDestroy=\"%d\"/>\n", ptr->nb_created, ptr->nb_used, ptr->nb_del);
count += ptr->nb_created + ptr->nb_used;
deleted += ptr->nb_del;
created += ptr->nb_created;
fprintf(dump, "</NodeStat>\n");
}
if (i) {
fprintf(dump, "<CumulatedStat TotalNumberOfNodes=\"%d\" ReallyAllocatedNodes=\"%d\" DeletedNodes=\"%d\" NumberOfAttributes=\"%d\"/>\n", count, created, deleted, stats->nb_svg_attributes);
fprintf(dump, "<DrawableNodesCumulatedStat TotalNumberOfNodes=\"%d\" ReallyAllocatedNodes=\"%d\" DeletedNodes=\"%d\"/>\n", draw_count, draw_created, draw_deleted);
}
fprintf(dump, "</NodeStatistics>\n");
created = count = deleted = 0;
if (gf_list_count(stats->proto_stats)) {
fprintf(dump, "<ProtoStatistics NumberOfProtoUsed=\"%d\">\n", gf_list_count(stats->proto_stats));
for (i=0; i<gf_list_count(stats->proto_stats); i++) {
GF_NodeStats *ptr = gf_list_get(stats->proto_stats, i);
fprintf(dump, "<ProtoStat ProtoName=\"%s\">\n", ptr->name);
fprintf(dump, "<Instanciation NbObjects=\"%d\" NbUse=\"%d\" NbDestroy=\"%d\"/>\n", ptr->nb_created, ptr->nb_used, ptr->nb_del);
count += ptr->nb_created + ptr->nb_used;
deleted += ptr->nb_del;
created += ptr->nb_created;
fprintf(dump, "</ProtoStat>\n");
}
if (i) fprintf(dump, "<CumulatedStat TotalNumberOfProtos=\"%d\" ReallyAllocatedProtos=\"%d\" DeletedProtos=\"%d\"/>\n", count, created, deleted);
fprintf(dump, "</ProtoStatistics>\n");
}
fprintf(dump, "<FixedValues min=\"%f\" max=\"%f\">\n", FIX2FLT( stats->min_fixed) , FIX2FLT( stats->max_fixed ));
fprintf(dump, "<Resolutions scaleIntegerPart=\"%d\" scaleFracPart=\"%d\" coordIntegerPart=\"%d\" coordFracPart=\"%d\"/>\n", stats->scale_int_res_2d, stats->scale_frac_res_2d, stats->int_res_2d, stats->frac_res_2d);
fprintf(dump, "</FixedValues>\n");
fprintf(dump, "<FieldStatistic FieldType=\"MFVec2f\">\n");
fprintf(dump, "<ParsingInfo NumParsed=\"%d\" NumRemoved=\"%d\"/>\n", stats->count_2d, stats->rem_2d);
if (stats->count_2d) {
fprintf(dump, "<ExtendInfo MinVec2f=\"%f %f\" MaxVec2f=\"%f %f\"/>\n", FIX2FLT( stats->min_2d.x) , FIX2FLT( stats->min_2d.y ), FIX2FLT( stats->max_2d.x ), FIX2FLT( stats->max_2d.y ) );
}
fprintf(dump, "</FieldStatistic>\n");
fprintf(dump, "<FieldStatistic FieldType=\"MFVec3f\">\n");
fprintf(dump, "<ParsingInfo NumParsed=\"%d\" NumRemoved=\"%d\"/>", stats->count_3d, stats->rem_3d);
if (stats->count_3d) {
fprintf(dump, "<ExtendInfo MinVec3f=\"%f %f %f\" MaxVec3f=\"%f %f %f\"/>\n", FIX2FLT( stats->min_3d.x ), FIX2FLT( stats->min_3d.y ), FIX2FLT( stats->min_3d.z ), FIX2FLT( stats->max_3d.x ), FIX2FLT( stats->max_3d.y ), FIX2FLT( stats->max_3d.z ) );
}
fprintf(dump, "</FieldStatistic>\n");
fprintf(dump, "<FieldStatistic FieldType=\"MF/SFColor\">\n");
fprintf(dump, "<ParsingInfo NumParsed=\"%d\" NumRemoved=\"%d\"/>", stats->count_color, stats->rem_color);
fprintf(dump, "</FieldStatistic>\n");
fprintf(dump, "<FieldStatistic FieldType=\"MF/SFFloat\">\n");
fprintf(dump, "<ParsingInfo NumParsed=\"%d\" NumRemoved=\"%d\"/>", stats->count_float, stats->rem_float);
fprintf(dump, "</FieldStatistic>\n");
fprintf(dump, "<FieldStatistic FieldType=\"SFVec2f\">\n");
fprintf(dump, "<ParsingInfo NumParsed=\"%d\"/>", stats->count_2f);
fprintf(dump, "</FieldStatistic>\n");
fprintf(dump, "<FieldStatistic FieldType=\"SFVec3f\">\n");
fprintf(dump, "<ParsingInfo NumParsed=\"%d\"/>", stats->count_3f);
fprintf(dump, "</FieldStatistic>\n");
}
static void ReorderAU(GF_List *sample_list, GF_AUContext *au)
{
u32 i;
for (i=0; i<gf_list_count(sample_list); i++) {
GF_AUContext *ptr = gf_list_get(sample_list, i);
if (
/*time ordered*/
(ptr->timing_sec > au->timing_sec)
/*set bifs first*/
|| ((ptr->timing_sec == au->timing_sec) && (ptr->owner->streamType < au->owner->streamType))
) {
gf_list_insert(sample_list, au, i);
return;
}
}
gf_list_add(sample_list, au);
}
void dump_isom_scene_stats(char *file, char *inName, Bool is_final_name, u32 stat_level)
{
GF_Err e;
FILE *dump;
Bool close;
u32 i, j, count;
char szBuf[1024];
GF_SceneManager *ctx;
GF_SceneLoader load;
GF_StatManager *sm;
GF_List *sample_list;
GF_SceneGraph *scene_graph;
dump = NULL;
sm = NULL;
sample_list = NULL;
close = 0;
scene_graph = gf_sg_new();
ctx = gf_sm_new(scene_graph);
memset(&load, 0, sizeof(GF_SceneLoader));
load.fileName = file;
load.ctx = ctx;
if (get_file_type_by_ext(file) == 1) {
load.isom = gf_isom_open(file, GF_ISOM_OPEN_READ, NULL);
if (!load.isom) {
M4_LOG(GF_LOG_ERROR, ("Cannot open file: %s\n", gf_error_to_string(gf_isom_last_error(NULL))));
gf_sm_del(ctx);
gf_sg_del(scene_graph);
return;
}
}
e = gf_sm_load_init(&load);
if (!e) e = gf_sm_load_run(&load);
gf_sm_load_done(&load);
if (e<0) goto exit;
if (inName) {
strcpy(szBuf, inName);
if (!is_final_name) strcat(szBuf, "_stat.xml");
dump = gf_fopen(szBuf, "wt");
if (!dump) {
M4_LOG(GF_LOG_ERROR, ("Failed to open %s for dumping\n", szBuf));
return;
}
close = 1;
} else {
dump = stdout;
close = 0;
}
fprintf(stderr, "Analysing Scene\n");
fprintf(dump, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
fprintf(dump, "<!-- Scene Graph Statistics Generated by MP4Box - GPAC ");
if (! gf_sys_is_test_mode())
fprintf(dump, "%s ", gf_gpac_version());
fprintf(dump, "-->\n");
fprintf(dump, "<SceneStatistics file=\"%s\" DumpType=\"%s\">\n", gf_file_basename(file), (stat_level==1) ? "full scene" : ((stat_level==2) ? "AccessUnit based" : "SceneGraph after each AU"));
sm = gf_sm_stats_new();
/*stat level 1: complete scene stat*/
if (stat_level == 1) {
e = gf_sm_stats_for_scene(sm, ctx);
if (!e) dump_stats(dump, gf_sm_stats_get(sm) );
goto exit;
}
/*re_order all BIFS-AUs*/
sample_list = gf_list_new();
/*configure all systems streams we're dumping*/
for (i=0; i<gf_list_count(ctx->streams); i++) {
GF_StreamContext *sc = gf_list_get(ctx->streams, i);
if (sc->streamType != GF_STREAM_SCENE) continue;
for (j=0; j<gf_list_count(sc->AUs); j++) {
GF_AUContext *au = gf_list_get(sc->AUs, j);
ReorderAU(sample_list, au);
}
}
count = gf_list_count(sample_list);
for (i=0; i<count; i++) {
GF_AUContext *au = gf_list_get(sample_list, i);
for (j=0; j<gf_list_count(au->commands); j++) {
GF_Command *com = gf_list_get(au->commands, j);
/*stat level 2 - get command stats*/
if (stat_level==2) {
e = gf_sm_stats_for_command(sm, com);
if (e) goto exit;
}
/*stat level 3 - apply command*/
if (stat_level==3) gf_sg_command_apply(scene_graph, com, 0);
}
/*stat level 3: get graph stat*/
if (stat_level==3) {
e = gf_sm_stats_for_graph(sm, scene_graph);
if (e) goto exit;
}
if (stat_level==2) {
fprintf(dump, "<AUStatistics StreamID=\"%d\" AUTime=\""LLD"\">\n", au->owner->ESID, au->timing);
} else {
fprintf(dump, "<GraphStatistics StreamID=\"%d\" AUTime=\""LLD"\">\n", au->owner->ESID, au->timing);
}
/*dump stats*/
dump_stats(dump, gf_sm_stats_get(sm) );
/*reset stats*/
gf_sm_stats_reset(sm);
if (stat_level==2) {
fprintf(dump, "</AUStatistics>\n");
} else {
fprintf(dump, "</GraphStatistics>\n");
}
gf_set_progress("Analysing AU", i+1, count);
}
exit:
if (sample_list) gf_list_del(sample_list);
if (sm) gf_sm_stats_del(sm);
gf_sm_del(ctx);
gf_sg_del(scene_graph);
if (load.isom) gf_isom_delete(load.isom);
if (e) {
M4_LOG(GF_LOG_ERROR, ("Stats error: %s\n", gf_error_to_string(e)));
} else {
fprintf(dump, "</SceneStatistics>\n");
}
if (dump && close) gf_fclose(dump);
fprintf(stderr, "done\n");
}
#endif /*GPAC_DISABLE_SCENE_STATS*/
#ifndef GPAC_DISABLE_VRML
static void PrintFixed(Fixed val, Bool add_space)
{
if (add_space) fprintf(stderr, " ");
if (val==FIX_MIN) fprintf(stderr, "-I");
else if (val==FIX_MAX) fprintf(stderr, "+I");
else fprintf(stderr, "%g", FIX2FLT(val));
}
static void PrintNodeSFField(u32 type, void *far_ptr)
{
if (!far_ptr) return;
switch (type) {
case GF_SG_VRML_SFBOOL:
fprintf(stderr, "%s", (*(SFBool *)far_ptr) ? "TRUE" : "FALSE");
break;
case GF_SG_VRML_SFINT32:
fprintf(stderr, "%d", (*(SFInt32 *)far_ptr));
break;
case GF_SG_VRML_SFFLOAT:
PrintFixed((*(SFFloat *)far_ptr), 0);
break;
case GF_SG_VRML_SFTIME:
fprintf(stderr, "%g", (*(SFTime *)far_ptr));
break;
case GF_SG_VRML_SFVEC2F:
PrintFixed(((SFVec2f *)far_ptr)->x, 0);
PrintFixed(((SFVec2f *)far_ptr)->y, 1);
break;
case GF_SG_VRML_SFVEC3F:
PrintFixed(((SFVec3f *)far_ptr)->x, 0);
PrintFixed(((SFVec3f *)far_ptr)->y, 1);
PrintFixed(((SFVec3f *)far_ptr)->z, 1);
break;
case GF_SG_VRML_SFROTATION:
PrintFixed(((SFRotation *)far_ptr)->x, 0);
PrintFixed(((SFRotation *)far_ptr)->y, 1);
PrintFixed(((SFRotation *)far_ptr)->z, 1);
PrintFixed(((SFRotation *)far_ptr)->q, 1);
break;
case GF_SG_VRML_SFCOLOR:
PrintFixed(((SFColor *)far_ptr)->red, 0);
PrintFixed(((SFColor *)far_ptr)->green, 1);
PrintFixed(((SFColor *)far_ptr)->blue, 1);
break;
case GF_SG_VRML_SFSTRING:
if (((SFString*)far_ptr)->buffer)
fprintf(stderr, "\"%s\"", ((SFString*)far_ptr)->buffer);
else
fprintf(stderr, "NULL");
break;
}
}
#endif
#ifndef GPAC_DISABLE_VRML
static void do_print_node(GF_Node *node, GF_SceneGraph *sg, const char *name, u32 graph_type, Bool is_nodefield, Bool do_cov)
{
u32 nbF, i;
GF_FieldInfo f;
#ifndef GPAC_DISABLE_BIFS
u8 qt, at;
Fixed bmin, bmax;
u32 nbBits;
#endif /*GPAC_DISABLE_BIFS*/
nbF = gf_node_get_field_count(node);
if (is_nodefield) {
char szField[1024];
u32 tfirst, tlast;
if (gf_node_get_field_by_name(node, szField, &f) != GF_OK) {
M4_LOG(GF_LOG_ERROR, ("Field %s is not a member of node %s\n", szField, name));
return;
}
fprintf(stderr, "Allowed nodes in %s.%s:\n", name, szField);
if (graph_type==1) {
tfirst = GF_NODE_RANGE_FIRST_X3D;
tlast = GF_NODE_RANGE_LAST_X3D;
} else {
tfirst = GF_NODE_RANGE_FIRST_MPEG4;
tlast = GF_NODE_RANGE_LAST_MPEG4;
}
for (i=tfirst; i<tlast; i++) {
GF_Node *tmp = gf_node_new(sg, i);
gf_node_register(tmp, NULL);
if (gf_node_in_table_by_tag(i, f.NDTtype)) {
const char *nname = gf_node_get_class_name(tmp);
if (nname && strcmp(nname, "Unknown Node")) {
fprintf(stderr, "\t%s\n", nname);
}
}
gf_node_unregister(tmp, NULL);
}
return;
}
if (do_cov) {
u32 ndt;
if (graph_type==0) {
u32 all;
gf_node_mpeg4_type_by_class_name(name);
gf_bifs_get_child_table(node);
all = gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_ALL);
for (i=0; i<all; i++) {
u32 res;
gf_sg_script_get_field_index(node, i, GF_SG_FIELD_CODING_ALL, &res);
}
gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_DEF);
gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_IN);
gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_OUT);
gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_DYN);
}
else if (graph_type==1) gf_node_x3d_type_by_class_name(name);
for (ndt=NDT_SFWorldNode; ndt<NDT_LAST; ndt++) {
gf_node_in_table_by_tag(gf_node_get_tag(node), ndt);
}
}
fprintf(stderr, "%s {\n", name);
for (i=0; i<nbF; i++) {
gf_node_get_field(node, i, &f);
if (graph_type==2) {
fprintf(stderr, "\t%s=\"...\"\n", f.name);
continue;
}
fprintf(stderr, "\t%s %s %s", gf_sg_vrml_get_event_type_name(f.eventType, 0), gf_sg_vrml_get_field_type_name(f.fieldType), f.name);
if (f.fieldType==GF_SG_VRML_SFNODE) fprintf(stderr, " NULL");
else if (f.fieldType==GF_SG_VRML_MFNODE) fprintf(stderr, " []");
else if (gf_sg_vrml_is_sf_field(f.fieldType)) {
fprintf(stderr, " ");
PrintNodeSFField(f.fieldType, f.far_ptr);
} else {
void *ptr;
u32 j, sftype;
GenMFField *mffield = (GenMFField *) f.far_ptr;
fprintf(stderr, " [");
sftype = gf_sg_vrml_get_sf_type(f.fieldType);
for (j=0; j<mffield->count; j++) {
if (j) fprintf(stderr, " ");
gf_sg_vrml_mf_get_item(f.far_ptr, f.fieldType, &ptr, j);
PrintNodeSFField(sftype, ptr);
}
fprintf(stderr, "]");
}
#ifndef GPAC_DISABLE_BIFS
if (gf_bifs_get_aq_info(node, i, &qt, &at, &bmin, &bmax, &nbBits)) {
if (qt) {
fprintf(stderr, " #QP=%d", qt);
if (qt==13) fprintf(stderr, " NbBits=%d", nbBits);
if (bmin && bmax) {
fprintf(stderr, " Bounds=[");
PrintFixed(bmin, 0);
fprintf(stderr, ",");
PrintFixed(bmax, 0);
fprintf(stderr, "]");
}
}
}
#endif /*GPAC_DISABLE_BIFS*/
fprintf(stderr, "\n");
if (do_cov) {
gf_node_get_field_by_name(node, (char *) f.name, &f);
}
}
fprintf(stderr, "}\n\n");
}
#endif
u32 PrintNode(const char *name, u32 graph_type)
{
#ifdef GPAC_DISABLE_VRML
M4_LOG(GF_LOG_ERROR, ("VRML/MPEG-4/X3D scene graph is disabled in this build of GPAC\n"));
return 2;
#else
const char *std_name;
GF_Node *node;
GF_SceneGraph *sg;
u32 tag;
#ifndef GPAC_DISABLE_BIFS
#endif /*GPAC_DISABLE_BIFS*/
Bool is_nodefield = 0;
char *sep = strchr(name, '.');
if (sep) {
sep[0] = 0;
is_nodefield = 1;
}
if (graph_type==1) {
#ifndef GPAC_DISABLE_X3D
tag = gf_node_x3d_type_by_class_name(name);
std_name = "X3D";
#else
M4_LOG(GF_LOG_ERROR, ("X3D node printing is not supported (X3D support disabled)\n"));
return 2;
#endif
} else {
tag = gf_node_mpeg4_type_by_class_name(name);
std_name = "MPEG4";
}
if (!tag) {
M4_LOG(GF_LOG_ERROR, ("Unknown %s node %s\n", std_name, name));
return 2;
}
sg = gf_sg_new();
node = gf_node_new(sg, tag);
gf_node_register(node, NULL);
name = gf_node_get_class_name(node);
if (!node) {
M4_LOG(GF_LOG_ERROR, ("Node %s not supported in current built\n", name));
return 2;
}
do_print_node(node, sg, name, graph_type, is_nodefield, GF_FALSE);
gf_node_unregister(node, NULL);
gf_sg_del(sg);
#endif /*GPAC_DISABLE_VRML*/
return 1;
}
u32 PrintBuiltInNodes(char *arg_val, u32 dump_type)
{
#if !defined(GPAC_DISABLE_VRML) && !defined(GPAC_DISABLE_X3D) && !defined(GPAC_DISABLE_SVG)
GF_SceneGraph *sg;
u32 i, nb_in, nb_not_in, start_tag, end_tag;
u32 graph_type;
Bool dump_nodes = ((dump_type==1) || (dump_type==3)) ? 1 : 0;
if (dump_type==4) graph_type = 2;
else if ((dump_type==2) || (dump_type==3)) graph_type = 1;
else graph_type = 0;
if (graph_type==1) {
#if !defined(GPAC_DISABLE_VRML) && !defined(GPAC_DISABLE_X3D)
start_tag = GF_NODE_RANGE_FIRST_X3D;
end_tag = TAG_LastImplementedX3D;
#else
M4_LOG(GF_LOG_ERROR, ("X3D scene graph disabled in this build of GPAC\n"));
return 2;
#endif
} else if (graph_type==2) {
#ifdef GPAC_DISABLE_SVG
M4_LOG(GF_LOG_ERROR, ("SVG scene graph disabled in this build of GPAC\n"));
return 2;
#else
start_tag = GF_NODE_RANGE_FIRST_SVG;
end_tag = GF_NODE_RANGE_LAST_SVG;
#endif
} else {
#ifdef GPAC_DISABLE_VRML
M4_LOG(GF_LOG_ERROR, ("VRML/MPEG-4 scene graph disabled in this build of GPAC\n"));
return 2;
#else
start_tag = GF_NODE_RANGE_FIRST_MPEG4;
end_tag = TAG_LastImplementedMPEG4;
#endif
}
nb_in = nb_not_in = 0;
sg = gf_sg_new();
if (graph_type==1) {
fprintf(stderr, "Available X3D nodes in this build (dumping):\n");
} else if (graph_type==2) {
fprintf(stderr, "Available SVG nodes in this build (dumping and LASeR coding):\n");
} else {
fprintf(stderr, "Available MPEG-4 nodes in this build (encoding/decoding/dumping):\n");
}
for (i=start_tag; i<end_tag; i++) {
GF_Node *node = gf_node_new(sg, i);
if (node) {
gf_node_register(node, NULL);
if (dump_nodes) {
do_print_node(node, sg, gf_node_get_class_name(node), graph_type, GF_FALSE, GF_TRUE);
} else {
fprintf(stderr, " %s\n", gf_node_get_class_name(node));
}
gf_node_unregister(node, NULL);
nb_in++;
} else {
if (graph_type==2)
break;
nb_not_in++;
}
}
gf_sg_del(sg);
if (graph_type==2) {
fprintf(stderr, "\n%d nodes supported\n", nb_in);
} else {
fprintf(stderr, "\n%d nodes supported - %d nodes not supported\n", nb_in, nb_not_in);
}
//coverage
if (dump_nodes) {
for (i=GF_SG_VRML_SFBOOL; i<GF_SG_VRML_SCRIPT_FUNCTION; i++) {
void *fp = gf_sg_vrml_field_pointer_new(i);
if (fp) {
if (i==GF_SG_VRML_SFSCRIPT) gf_free(fp);
else gf_sg_vrml_field_pointer_del(fp, i);
}
}
}
#else
M4_LOG(GF_LOG_ERROR, ("No scene graph enabled in this MP4Box build\n"));
#endif
return 1;
}
u32 PrintBuiltInBoxes(char *argval, u32 do_cov)
{
u32 i, count=gf_isom_get_num_supported_boxes();
fprintf(stdout, "<Boxes>\n");
//index 0 is our internal unknown box handler
for (i=1; i<count; i++) {
gf_isom_dump_supported_box(i, stdout);
if (do_cov) {
u32 btype = gf_isom_get_supported_box_type(i);
GF_Box *b=gf_isom_box_new(btype);
if (b) {
GF_Box *c=NULL;
gf_isom_clone_box(b, &c);
if (c) gf_isom_box_del(c);
gf_isom_box_del(b);
}
}
}
fprintf(stdout, "</Boxes>\n");
return 1;
}
#if !defined(GPAC_DISABLE_ISOM_HINTING) && !defined(GPAC_DISABLE_ISOM_DUMP)
void dump_isom_rtp(GF_ISOFile *file, char *inName, Bool is_final_name)
{
u32 i, j, size;
FILE *dump;
const char *sdp;
if (inName) {
char szBuf[1024];
strcpy(szBuf, inName);
if (!is_final_name) strcat(szBuf, "_rtp.xml");
dump = gf_fopen(szBuf, "wt");
if (!dump) {
M4_LOG(GF_LOG_ERROR, ("Failed to open %s\n", szBuf));
return;
}
} else {
dump = stdout;
}
fprintf(dump, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
fprintf(dump, "<!-- MP4Box RTP trace -->\n");
fprintf(dump, "<RTPFile>\n");
for (i=0; i<gf_isom_get_track_count(file); i++) {
if (gf_isom_get_media_type(file, i+1) != GF_ISOM_MEDIA_HINT) continue;
fprintf(dump, "<RTPHintTrack trackID=\"%d\">\n", gf_isom_get_track_id(file, i+1));
gf_isom_sdp_track_get(file, i+1, &sdp, &size);
fprintf(dump, "<SDPInfo>%s</SDPInfo>", sdp);
#ifndef GPAC_DISABLE_ISOM_HINTING
for (j=0; j<gf_isom_get_sample_count(file, i+1); j++) {
gf_isom_dump_hint_sample(file, i+1, j+1, dump);
}
#endif
fprintf(dump, "</RTPHintTrack>\n");
}
fprintf(dump, "</RTPFile>\n");
if (inName) gf_fclose(dump);
}
#endif
void dump_isom_timestamps(GF_ISOFile *file, char *inName, Bool is_final_name, u32 dump_mode)
{
u32 i, j, k, count;
Bool has_ctts_error, is_fragmented=GF_FALSE;
FILE *dump;
Bool skip_offset = ((dump_mode==2) || (dump_mode==4)) ? GF_TRUE : GF_FALSE;
Bool check_ts = ((dump_mode==3) || (dump_mode==4)) ? GF_TRUE : GF_FALSE;
struct _ts_info {
u64 dts;
s64 cts;
};
struct _ts_info *timings = NULL;
u32 nb_timings=0, nb_timings_alloc = 0;
if (inName) {
char szBuf[1024];
strcpy(szBuf, inName);
if (!is_final_name) strcat(szBuf, "_ts.txt");
dump = gf_fopen(szBuf, "wt");
if (!dump) {
M4_LOG(GF_LOG_ERROR, ("Failed to open %s\n", szBuf));
return;
}
} else {
dump = stdout;
}
if (gf_isom_is_fragmented(file))
is_fragmented = GF_TRUE;
has_ctts_error = GF_FALSE;
for (i=0; i<gf_isom_get_track_count(file); i++) {
s64 cts_dts_shift = gf_isom_get_cts_to_dts_shift(file, i+1);
u32 has_cts_offset = gf_isom_has_time_offset(file, i+1);
fprintf(dump, "#dumping track ID %d timing:\n", gf_isom_get_track_id(file, i + 1));
fprintf(dump, "Num\tDTS\tCTS\tSize\tRAP%s\tisLeading\tDependsOn\tDependedOn\tRedundant\tRAP-SampleGroup\tRoll-SampleGroup\tRoll-Distance", skip_offset ? "" : "\tOffset");
if (is_fragmented) {
fprintf(dump, "\tfrag_start");
}
fprintf(dump, "\n");
count = gf_isom_get_sample_count(file, i+1);
if (has_cts_offset && check_ts) {
if (nb_timings_alloc<count) {
nb_timings_alloc = count;
timings = gf_realloc(timings, sizeof (struct _ts_info) * count);
}
nb_timings = 0;
}
for (j=0; j<count; j++) {
s64 cts;
u64 dts, offset;
u32 isLeading, dependsOn, dependedOn, redundant;
Bool is_rap;
GF_ISOSampleRollType roll_type;
s32 roll_distance;
u32 index;
GF_ISOSample *samp = gf_isom_get_sample_info(file, i+1, j+1, &index, &offset);
if (!samp) {
fprintf(dump, " SAMPLE #%d IN TRACK #%d NOT THERE !!!\n", j+1, i+1);
continue;
}
gf_isom_get_sample_flags(file, i+1, j+1, &isLeading, &dependsOn, &dependedOn, &redundant);
gf_isom_get_sample_rap_roll_info(file, i+1, j+1, &is_rap, &roll_type, &roll_distance);
dts = samp->DTS;
cts = dts + (s32) samp->CTS_Offset;
fprintf(dump, "Sample %d\tDTS "LLU"\tCTS "LLD"\t%d\t%d", j+1, dts, cts, samp->dataLength, samp->IsRAP);
if (!skip_offset)
fprintf(dump, "\t"LLU, offset);
fprintf(dump, "\t%d\t%d\t%d\t%d\t%d\t%d\t%d", isLeading, dependsOn, dependedOn, redundant, is_rap, roll_type, roll_distance);
if (cts< (s64) dts) {
if (has_cts_offset==2) {
if (cts_dts_shift && (cts+cts_dts_shift < (s64) dts)) {
fprintf(dump, " #NEGATIVE CTS OFFSET!!!");
has_ctts_error = 1;
} else if (!cts_dts_shift) {
fprintf(dump, " #possible negative CTS offset (no cslg in file)");
}
} else {
fprintf(dump, " #NEGATIVE CTS OFFSET!!!");
has_ctts_error = 1;
}
}
if (has_cts_offset && check_ts) {
for (k=0; k<nb_timings; k++) {
if (timings[k].dts==dts) {
fprintf(dump, " #SAME DTS USED!!!");
has_ctts_error = 1;
}
if (timings[k].cts==cts) {
fprintf(dump, " #SAME CTS USED!!! ");
has_ctts_error = 1;
}
}
timings[nb_timings].dts = dts;
timings[nb_timings].cts = cts;
nb_timings++;
}
gf_isom_sample_del(&samp);
if (is_fragmented) {
fprintf(dump, "\t%d", gf_isom_sample_is_fragment_start(file, i+1, j+1, NULL) );
}
fprintf(dump, "\n");
gf_set_progress("Dumping track timing", j+1, count);
}
fprintf(dump, "\n\n");
gf_set_progress("Dumping track timing", count, count);
}
if (timings) gf_free(timings);
if (inName) gf_fclose(dump);
if (has_ctts_error) {
M4_LOG(GF_LOG_ERROR, ("\tFile has CTTS table errors\n"));
}
}