2
* GPAC - Multimedia Framework C SDK
4
* Copyright (c) Cyril Concolato 2000-2006
7
* This file is part of GPAC / load&compare application
9
* GPAC is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* GPAC is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; see the file COPYING. If not, write to
21
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
#include <gpac/scene_manager.h>
38
u32 gpacxml_gz_loadtime;
39
u32 libxml_gz_loadtime;
57
GF_Err load_mp4(GF_LoadCompare *lc, GF_ISOFile *mp4, u32 *loadtime)
62
u32 i, starttime, endtime;
64
if (lc->spread_repeat) nb = 1;
65
else nb = lc->nbloads ;
68
for (i = 0; i< nb; i++) {
69
memset(&load, 0, sizeof(GF_SceneLoader));
71
load.ctx = gf_sm_new(sg);
74
starttime = gf_sys_clock();
76
e = gf_sm_load_init(&load);
78
fprintf(stderr, "Error loading MP4 file\n");
80
e = gf_sm_load_run(&load);
82
fprintf(stderr, "Error loading MP4 file\n");
84
endtime = gf_sys_clock();
85
*loadtime += endtime-starttime;
87
gf_sm_load_done(&load);
95
void load_progress(void *cbk, u32 done, u32 total) {
96
fprintf(stdout, "%d/%d\r", done, total);
99
GF_Err gpacctx_load_file(GF_LoadCompare *lc, char *item_path, u32 *loadtime)
104
u32 i, starttime, endtime;
107
if (lc->spread_repeat) nb = 1;
108
else nb = lc->nbloads ;
112
for (i = 0; i<nb; i++) {
113
memset(&load, 0, sizeof(GF_SceneLoader));
115
load.ctx = gf_sm_new(sg);
116
load.OnProgress = load_progress;
118
load.fileName = item_path;
119
starttime = gf_sys_clock();
121
e = gf_sm_load_init(&load);
123
fprintf(stderr, "Error loading file %s\n", item_path);
125
e = gf_sm_load_run(&load);
127
fprintf(stderr, "Error loading file %s\n", item_path);
129
endtime = gf_sys_clock();
130
*loadtime += endtime-starttime;
132
gf_sm_load_done(&load);
140
GF_Err get_laser_track_size(GF_ISOFile *mp4, u32 *size)
144
u32 track_id, trackNum;
147
track_id = gf_isom_get_track_id(mp4, 1);
148
trackNum = gf_isom_get_track_by_id(mp4, track_id);
149
for (j=0; j<gf_isom_get_sample_count(mp4, trackNum); j++) {
150
GF_ISOSample *samp = gf_isom_get_sample_info(mp4, trackNum, j+1, NULL, NULL);
151
*size += samp->dataLength;
152
gf_isom_sample_del(&samp);
157
GF_Err encode_laser(GF_LoadCompare *lc, char *item_path, GF_ISOFile *mp4, GF_SMEncodeOptions *opts)
161
GF_SceneManager *ctx;
163
GF_StatManager *statsman = NULL;
165
memset(&load, 0, sizeof(GF_SceneLoader));
169
load.fileName = item_path;
171
e = gf_sm_load_init(&load);
173
fprintf(stderr, "Error loading file %s\n", item_path);
175
e = gf_sm_load_run(&load);
177
fprintf(stderr, "Error loading file %s\n", item_path);
179
if (opts->auto_qant) {
180
if (lc->verbose) fprintf(stdout, "Analysing Scene for Automatic Quantization\n");
181
statsman = gf_sm_stats_new();
182
e = gf_sm_stats_for_scene(statsman, ctx);
184
GF_SceneStatistics *stats = gf_sm_stats_get(statsman);
185
if (opts->resolution > (s32)stats->frac_res_2d) {
186
if (lc->verbose) fprintf(stdout, " Given resolution %d is (unnecessarily) too high, using %d instead.\n", opts->resolution, stats->frac_res_2d);
187
opts->resolution = stats->frac_res_2d;
188
} else if (stats->int_res_2d + opts->resolution <= 0) {
189
if (lc->verbose) fprintf(stdout, " Given resolution %d is too low, using %d instead.\n", opts->resolution, stats->int_res_2d - 1);
190
opts->resolution = 1 - stats->int_res_2d;
192
opts->coord_bits = stats->int_res_2d + opts->resolution;
193
if (lc->verbose) fprintf(stdout, " Coordinates & Lengths encoded using ");
194
if (opts->resolution < 0) {
195
if (lc->verbose) fprintf(stdout, "only the %d most significant bits (of %d).\n", opts->coord_bits, stats->int_res_2d);
197
if (lc->verbose) fprintf(stdout, "a %d.%d representation\n", stats->int_res_2d, opts->resolution);
200
if (lc->verbose) fprintf(stdout, " Matrix Scale & Skew Coefficients ");
201
if (opts->coord_bits < stats->scale_int_res_2d) {
202
opts->scale_bits = stats->scale_int_res_2d - opts->coord_bits;
203
if (lc->verbose) fprintf(stdout, "encoded using a %d.8 representation\n", stats->scale_int_res_2d);
205
opts->scale_bits = 0;
206
if (lc->verbose) fprintf(stdout, "not encoded.\n");
209
gf_sm_stats_del(statsman);
212
e = gf_sm_encode_to_file(ctx, mp4, opts);
214
fprintf(stderr, "Error while encoding mp4 file\n");
216
e = gf_isom_set_brand_info(mp4, GF_ISOM_BRAND_MP42, 1);
217
if (!e) e = gf_isom_modify_alternate_brand(mp4, GF_ISOM_BRAND_ISOM, 1);
220
gf_sm_load_done(&load);
229
GF_Err create_laser_mp4(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
231
char mp4_path[100], *ext;
237
strcpy(mp4_path, item_name);
238
ext = strrchr(mp4_path, '.');
240
mp4 = gf_isom_open(mp4_path, GF_ISOM_WRITE_EDIT, NULL);
242
if (lc->verbose) fprintf(stdout, "Could not open file %s for writing\n", mp4_path);
245
GF_SMEncodeOptions opts;
246
memset(&opts, 0, sizeof(GF_SMEncodeOptions));
249
e = encode_laser(lc, item_path, mp4, &opts);
251
if (lc->verbose) fprintf(stdout, "Could not encode MP4 file from %s\n", item_path);
256
mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
258
if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path);
261
e = get_laser_track_size(mp4, size);
263
if (lc->verbose) fprintf(stdout, "Could not get MP4 file size\n");
273
GF_Err get_mp4_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime)
275
char mp4_path[100], *ext;
281
strcpy(mp4_path, item_name);
282
ext = strrchr(mp4_path, '.');
284
mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
286
if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path);
289
e = load_mp4(lc, mp4, loadtime);
291
if (lc->verbose) fprintf(stdout, "Could not get MP4 file load time\n");
298
GF_Err decode_svg(GF_LoadCompare *lc, char *item_name, char *item_path, char *svg_out_path)
300
GF_SceneManager *ctx;
308
strcpy(mp4_path, item_name);
309
ext = strrchr(mp4_path, '.');
311
mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
313
if (lc->verbose) fprintf(stdout, "Could not open file %s\n", mp4_path);
318
memset(&load, 0, sizeof(GF_SceneLoader));
321
e = gf_sm_load_init(&load);
323
fprintf(stderr, "Error loading MP4 file\n");
325
e = gf_sm_load_run(&load);
327
fprintf(stderr, "Error loading MP4 file\n");
329
gf_sm_load_done(&load);
331
ext = strrchr(svg_out_path, '.');
333
e = gf_sm_dump(ctx, svg_out_path, GF_SM_DUMP_SVG);
335
fprintf(stderr, "Error dumping SVG from MP4 file\n");
346
GF_Err libxml_load_svg(GF_LoadCompare *lc, char *item_path, u32 *loadtime)
350
u32 i, starttime, endtime;
354
if (lc->spread_repeat) nb = 1;
355
else nb = lc->nbloads ;
359
for (i = 0; i<nb; i++) {
362
starttime = gf_sys_clock();
364
p = DANAE_NewSVGParser(item_path, sg);
365
DANAE_SVGParser_Parse(p);
366
DANAE_SVGParser_Terminate();
368
endtime = gf_sys_clock();
369
if (lc->verbose) fprintf(stdout, "LibXML single parsing: %d\n", endtime-starttime);
370
*loadtime += endtime-starttime;
377
GF_Err get_size(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
384
file = fopen(item_path, "rt");
386
if (lc->verbose) fprintf(stdout, "Could not open file %s\n", item_path);
389
fseek(file, 0, SEEK_END);
390
*size = (u32)ftell(file);
393
if (lc->verbose) fprintf(stdout, "File %s has a size of 0\n", item_path);
400
GF_Err get_decoded_svg_loadtime_and_size(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime, u32 *size)
403
char svg_out_name[256];
406
strcpy(svg_out_name, item_name);
407
ext = strrchr(svg_out_name, '.');
408
strcpy(ext, "_out.svg");
413
e = decode_svg(lc, item_name, item_path, svg_out_name);
415
e = get_size(lc, svg_out_name, svg_out_name, size);
419
e = gpacctx_load_file(lc, svg_out_name, loadtime);
424
GF_Err create_gz_file(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
435
strcpy(gz_path, item_name);
436
strcat(gz_path, "z");
437
gz = gzopen(gz_path, "wb");
438
file = fopen(item_path, "rt");
441
if (lc->verbose) fprintf(stdout, "Could not open file %s or %s\n", item_path, gz_path);
444
while ((read = fread(buffer, 1, 100, file))) gzwrite(gz, buffer, read);
447
file = fopen(gz_path, "rb");
448
fseek(file, 0, SEEK_END);
449
*size = (u32)ftell(file);
452
if (lc->verbose) fprintf(stdout, "File %s has a size of 0\n", gz_path);
459
GF_Err get_gz_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime, Bool useLibXML)
465
strcpy(gz_path, item_name);
466
strcat(gz_path, "z");
469
e = libxml_load_svg(lc, gz_path, loadtime);
471
e = gpacctx_load_file(lc, gz_path, loadtime);
476
void print_load_data(GF_LoadCompare *lc, LoadData *ld)
478
if (lc->verbose) fprintf(stdout, "Processing %s\n", ld->filename);
479
fprintf(lc->out, "%s\t", ld->filename);
481
if (lc->verbose) fprintf(stdout, "File Size %d\n", ld->size);
482
fprintf(lc->out, "%d\t", ld->size);
484
if (lc->verbose) fprintf(stdout, "GPAC XML Load Time %d\n", ld->gpacxml_loadtime);
485
fprintf(lc->out, "%d\t", ld->gpacxml_loadtime);
487
if (lc->verbose) fprintf(stdout, "LibXML Load Time %d \n", ld->libxml_loadtime);
488
fprintf(lc->out, "%d\t", ld->libxml_loadtime);
490
if (lc->verbose) fprintf(stdout, "GZ Size %d\n", ld->gz_size);
491
fprintf(lc->out, "%d\t", ld->gz_size);
493
if (lc->verbose) fprintf(stdout, "GZ Load Time %d\n", ld->gpacxml_gz_loadtime);
494
fprintf(lc->out, "%d\t", ld->gpacxml_gz_loadtime);
496
if (lc->verbose) fprintf(stdout, "LibXML GZ Load Time %d\n", ld->libxml_gz_loadtime);
497
fprintf(lc->out, "%d\t", ld->libxml_gz_loadtime);
499
if (lc->verbose) fprintf(stdout, "MP4 Track Size %d\n", ld->track_size);
500
fprintf(lc->out, "%d\t", ld->track_size);
502
if (lc->verbose) fprintf(stdout, "MP4 Track Load Time %d\n", ld->track_loadtime);
503
fprintf(lc->out, "%d\t", ld->track_loadtime);
505
if (lc->verbose) fprintf(stdout, "Decoded Size %d\n", ld->decoded_size);
506
fprintf(lc->out, "%d\t", ld->decoded_size);
508
if (lc->verbose) fprintf(stdout, "Decoded Load Time %d \n", ld->decoded_loadtime);
509
fprintf(lc->out, "%d\t", ld->decoded_loadtime);
511
if (lc->verbose) fprintf(stdout, "Done %s\n", ld->filename);
512
fprintf(lc->out, "\n");
516
Bool loadcompare_one(void *cbck, char *item_name, char *item_path)
519
GF_LoadCompare *lc = cbck;
523
if (lc->repeat_index == 0) {
524
GF_SAFEALLOC(ld, sizeof(LoadData));
525
gf_list_add(lc->data, ld);
526
strcpy(ld->filename, item_name);
528
e = get_size(lc, item_name, item_path, &ld->size);
531
e = create_gz_file(lc, item_name, item_path, &ld->gz_size);
534
e = create_laser_mp4(lc, item_name, item_path, &ld->track_size);
541
while (tmp = gf_list_enum(lc->data, &pos)) {
542
if (!strcmp(tmp->filename, item_name)) {
547
if (ld == NULL) return 1;
551
if (lc->type == SVG) {
552
/* GPAC XML loader */
553
e = gpacctx_load_file(lc, item_path, &loadtime);
555
ld->gpacxml_loadtime += loadtime;
557
e = get_gz_loadtime(lc, item_name, item_path, &loadtime, 0);
559
ld->gpacxml_gz_loadtime += loadtime;
561
/* LibXML and LibXML GZ loadings */
562
e = libxml_load_svg(lc, item_path, &loadtime);
564
ld->libxml_loadtime += loadtime;
566
e = get_gz_loadtime(lc, item_name, item_path, &loadtime, 1);
568
ld->libxml_gz_loadtime += loadtime;
571
e = get_mp4_loadtime(lc, item_name, item_path, &loadtime);
573
ld->track_loadtime += loadtime;
575
/* e = get_decoded_svg_loadtime_and_size(lc, item_name, item_path, &loadtime, &ld->decoded_size);
577
ld->decoded_loadtime += loadtime;*/
579
} else if (lc->type == XMT) {
580
e = gpacctx_load_file(lc, item_path, &loadtime);
582
ld->gpacxml_loadtime += loadtime;
585
if (!lc->spread_repeat) {
586
print_load_data(lc, ld);
594
fprintf(stdout, "Compare LASeR and SVG encoding size and loading time\n");
595
fprintf(stdout, "usage: (-out output_result) (-single input.svg | -dir dir) (-nloads X) (-verbose X)\n");
596
fprintf(stdout, "defaults are: stdout, dir=. and X = 1");
599
int main(int argc, char **argv)
608
fprintf(stdout, "LASeR and SVG Comparison tool\n");
610
memset(&lc, 0, sizeof(GF_LoadCompare));
614
for (i = 1; i < (u32) argc ; i++) {
616
if (!stricmp(arg, "-out")) {
619
} else if (!stricmp(arg, "-single")) {
621
strcpy(in, argv[i+1]);
623
} else if (!stricmp(arg, "-dir")) {
624
strcpy(in, argv[i+1]);
626
} else if (!stricmp(arg, "-nloads")) {
627
lc.nbloads = (u32)atoi(argv[i+1]);
629
} else if (!stricmp(arg, "-regenerate")) {
631
} else if (!stricmp(arg, "-xmt")) {
633
} else if (!stricmp(arg, "-svg")) {
635
} else if (!stricmp(arg, "-spread_repeat")) {
636
lc.spread_repeat = 1;
637
} else if (!stricmp(arg, "-verbose")) {
638
lc.verbose = (u32)atoi(argv[i+1]);
647
if (out) lc.out = fopen(out, "wt");
649
fprintf(stderr, "Cannot open output file %s\n", out);
653
if (lc.type == SVG) {
654
fprintf(lc.out,"File Name\tSVG Size\tSVG Load Time\tLibXML Load Time\tSVGZ Size\tSVGZ Load Time\tLibXML GZ Load Time\tMP4 Size\tMP4 Load Time\tDecoded SVG Size\tDecoded SVG Load Time\n");
655
} else if (lc.type == XMT) {
656
fprintf(lc.out,"File Name\tXMT Size\tXMT Load Time\tBT Size\tBT Load Time\n");
659
lc.data = gf_list_new();
663
char *tmp = strrchr(in, GF_PATH_SEPARATOR);
664
loadcompare_one(&lc, tmp+1, in);
665
ld = gf_list_get(lc.data, 0);
666
print_load_data(&lc, ld);
669
if (lc.spread_repeat) {
670
for (lc.repeat_index = 0; lc.repeat_index < lc.nbloads; lc.repeat_index ++) {
671
if (lc.verbose) fprintf(stdout, "Loop %d\n", lc.repeat_index);
672
if (lc.type == SVG) {
673
gf_enum_directory(in, 0, loadcompare_one, &lc, "svg");
674
} else if (lc.type == XMT) {
675
gf_enum_directory(in, 0, loadcompare_one, &lc, "xmt");
678
for (i=0; i<gf_list_count(lc.data); i++) {
679
LoadData *ld = gf_list_get(lc.data, i);
680
print_load_data(&lc, ld);
684
if (lc.type == SVG) {
685
gf_enum_directory(in, 0, loadcompare_one, &lc, "svg");
686
} else if (lc.type == XMT) {
687
gf_enum_directory(in, 0, loadcompare_one, &lc, "xmt");
691
gf_list_del(lc.data);
693
if (lc.out) fclose(lc.out);