PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/applications/testapps/loadcompare/loadcompare.c

https://github.com/svettom/gpac
C | 698 lines | 574 code | 94 blank | 30 comment | 164 complexity | 234abb2693e5f3e8bd5a4933d8b47414 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. /*
  2. * GPAC - Multimedia Framework C SDK
  3. *
  4. * Authors: Cyril Concolato
  5. * Copyright (c) Telecom ParisTech 2006-2012
  6. * All rights reserved
  7. *
  8. * This file is part of GPAC / load&compare application
  9. *
  10. * GPAC is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * GPAC is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; see the file COPYING. If not, write to
  22. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "../../../include/gpac/scene_manager.h"
  26. #include <zlib.h>
  27. enum {
  28. SVG = 0,
  29. XMT = 1,
  30. };
  31. typedef struct {
  32. char filename[100];
  33. u32 size;
  34. u32 gpacxml_loadtime;
  35. u32 libxml_loadtime;
  36. u32 gz_size;
  37. u32 gpacxml_gz_loadtime;
  38. u32 libxml_gz_loadtime;
  39. u32 track_size;
  40. u32 track_loadtime;
  41. u32 decoded_size;
  42. u32 decoded_loadtime;
  43. } LoadData;
  44. typedef struct {
  45. FILE *out;
  46. u32 type;
  47. u32 nbloads;
  48. u32 verbose;
  49. Bool regenerate;
  50. Bool spread_repeat;
  51. u32 repeat_index;
  52. GF_List *data;
  53. } GF_LoadCompare;
  54. GF_Err load_mp4(GF_LoadCompare *lc, GF_ISOFile *mp4, u32 *loadtime)
  55. {
  56. GF_Err e = GF_OK;
  57. GF_SceneLoader load;
  58. GF_SceneGraph *sg;
  59. u32 i, starttime, endtime;
  60. u32 nb;
  61. if (lc->spread_repeat) nb = 1;
  62. else nb = lc->nbloads ;
  63. *loadtime = 0;
  64. for (i = 0; i< nb; i++) {
  65. memset(&load, 0, sizeof(GF_SceneLoader));
  66. sg = gf_sg_new();
  67. load.ctx = gf_sm_new(sg);
  68. load.isom = mp4;
  69. starttime = gf_sys_clock();
  70. e = gf_sm_load_init(&load);
  71. if (e) {
  72. fprintf(stderr, "Error loading MP4 file\n");
  73. } else {
  74. e = gf_sm_load_run(&load);
  75. if (e) {
  76. fprintf(stderr, "Error loading MP4 file\n");
  77. } else {
  78. endtime = gf_sys_clock();
  79. *loadtime += endtime-starttime;
  80. }
  81. gf_sm_load_done(&load);
  82. }
  83. gf_sm_del(load.ctx);
  84. gf_sg_del(sg);
  85. }
  86. return e;
  87. }
  88. void load_progress(void *cbk, u32 done, u32 total) {
  89. fprintf(stdout, "%d/%d\r", done, total);
  90. }
  91. GF_Err gpacctx_load_file(GF_LoadCompare *lc, char *item_path, u32 *loadtime)
  92. {
  93. GF_Err e = GF_OK;
  94. GF_SceneLoader load;
  95. GF_SceneGraph *sg;
  96. u32 i, starttime, endtime;
  97. u32 nb;
  98. if (lc->spread_repeat) nb = 1;
  99. else nb = lc->nbloads ;
  100. *loadtime = 0;
  101. for (i = 0; i<nb; i++) {
  102. memset(&load, 0, sizeof(GF_SceneLoader));
  103. sg = gf_sg_new();
  104. load.ctx = gf_sm_new(sg);
  105. load.OnProgress = load_progress;
  106. load.fileName = item_path;
  107. starttime = gf_sys_clock();
  108. e = gf_sm_load_init(&load);
  109. if (e) {
  110. fprintf(stderr, "Error loading file %s\n", item_path);
  111. } else {
  112. e = gf_sm_load_run(&load);
  113. if (e) {
  114. fprintf(stderr, "Error loading file %s\n", item_path);
  115. } else {
  116. endtime = gf_sys_clock();
  117. *loadtime += endtime-starttime;
  118. }
  119. gf_sm_load_done(&load);
  120. }
  121. gf_sm_del(load.ctx);
  122. gf_sg_del(sg);
  123. }
  124. return e;
  125. }
  126. GF_Err get_laser_track_size(GF_ISOFile *mp4, u32 *size)
  127. {
  128. GF_Err e = GF_OK;
  129. u32 j;
  130. u32 track_id, trackNum;
  131. *size = 0;
  132. track_id = gf_isom_get_track_id(mp4, 1);
  133. trackNum = gf_isom_get_track_by_id(mp4, track_id);
  134. for (j=0; j<gf_isom_get_sample_count(mp4, trackNum); j++) {
  135. GF_ISOSample *samp = gf_isom_get_sample_info(mp4, trackNum, j+1, NULL, NULL);
  136. *size += samp->dataLength;
  137. gf_isom_sample_del(&samp);
  138. }
  139. return e;
  140. }
  141. GF_Err encode_laser(GF_LoadCompare *lc, char *item_path, GF_ISOFile *mp4, GF_SMEncodeOptions *opts)
  142. {
  143. GF_Err e = GF_OK;
  144. GF_SceneLoader load;
  145. GF_SceneManager *ctx;
  146. GF_SceneGraph *sg;
  147. GF_StatManager *statsman = NULL;
  148. memset(&load, 0, sizeof(GF_SceneLoader));
  149. sg = gf_sg_new();
  150. ctx = gf_sm_new(sg);
  151. load.ctx = ctx;
  152. load.fileName = item_path;
  153. e = gf_sm_load_init(&load);
  154. if (e) {
  155. fprintf(stderr, "Error loading file %s\n", item_path);
  156. } else {
  157. e = gf_sm_load_run(&load);
  158. if (e) {
  159. fprintf(stderr, "Error loading file %s\n", item_path);
  160. } else {
  161. if (opts->auto_qant) {
  162. if (lc->verbose) fprintf(stdout, "Analysing Scene for Automatic Quantization\n");
  163. statsman = gf_sm_stats_new();
  164. e = gf_sm_stats_for_scene(statsman, ctx);
  165. if (!e) {
  166. GF_SceneStatistics *stats = gf_sm_stats_get(statsman);
  167. if (opts->resolution > (s32)stats->frac_res_2d) {
  168. if (lc->verbose) fprintf(stdout, " Given resolution %d is (unnecessarily) too high, using %d instead.\n", opts->resolution, stats->frac_res_2d);
  169. opts->resolution = stats->frac_res_2d;
  170. } else if (stats->int_res_2d + opts->resolution <= 0) {
  171. if (lc->verbose) fprintf(stdout, " Given resolution %d is too low, using %d instead.\n", opts->resolution, stats->int_res_2d - 1);
  172. opts->resolution = 1 - stats->int_res_2d;
  173. }
  174. opts->coord_bits = stats->int_res_2d + opts->resolution;
  175. if (lc->verbose) fprintf(stdout, " Coordinates & Lengths encoded using ");
  176. if (opts->resolution < 0) {
  177. if (lc->verbose) fprintf(stdout, "only the %d most significant bits (of %d).\n", opts->coord_bits, stats->int_res_2d);
  178. } else {
  179. if (lc->verbose) fprintf(stdout, "a %d.%d representation\n", stats->int_res_2d, opts->resolution);
  180. }
  181. if (lc->verbose) fprintf(stdout, " Matrix Scale & Skew Coefficients ");
  182. if (opts->coord_bits < stats->scale_int_res_2d) {
  183. opts->scale_bits = stats->scale_int_res_2d - opts->coord_bits;
  184. if (lc->verbose) fprintf(stdout, "encoded using a %d.8 representation\n", stats->scale_int_res_2d);
  185. } else {
  186. opts->scale_bits = 0;
  187. if (lc->verbose) fprintf(stdout, "not encoded.\n");
  188. }
  189. }
  190. gf_sm_stats_del(statsman);
  191. }
  192. e = gf_sm_encode_to_file(ctx, mp4, opts);
  193. if (e) {
  194. fprintf(stderr, "Error while encoding mp4 file\n");
  195. } else {
  196. e = gf_isom_set_brand_info(mp4, GF_ISOM_BRAND_MP42, 1);
  197. if (!e) e = gf_isom_modify_alternate_brand(mp4, GF_ISOM_BRAND_ISOM, 1);
  198. }
  199. gf_sm_load_done(&load);
  200. }
  201. }
  202. gf_sm_del(ctx);
  203. gf_sg_del(sg);
  204. return e;
  205. }
  206. GF_Err create_laser_mp4(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
  207. {
  208. char mp4_path[100], *ext;
  209. GF_Err e = GF_OK;
  210. GF_ISOFile *mp4;
  211. *size = 0;
  212. strcpy(mp4_path, item_name);
  213. ext = strrchr(mp4_path, '.');
  214. strcpy(ext, ".mp4");
  215. mp4 = gf_isom_open(mp4_path, GF_ISOM_WRITE_EDIT, NULL);
  216. if (!mp4) {
  217. if (lc->verbose) fprintf(stdout, "Could not open file %s for writing\n", mp4_path);
  218. e = GF_IO_ERR;
  219. } else {
  220. GF_SMEncodeOptions opts;
  221. memset(&opts, 0, sizeof(GF_SMEncodeOptions));
  222. opts.auto_qant = 1;
  223. opts.resolution = 8;
  224. e = encode_laser(lc, item_path, mp4, &opts);
  225. if (e) {
  226. if (lc->verbose) fprintf(stdout, "Could not encode MP4 file from %s\n", item_path);
  227. gf_isom_delete(mp4);
  228. } else {
  229. gf_isom_close(mp4);
  230. mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
  231. if (!mp4) {
  232. if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path);
  233. e = GF_IO_ERR;
  234. } else {
  235. e = get_laser_track_size(mp4, size);
  236. if (e) {
  237. if (lc->verbose) fprintf(stdout, "Could not get MP4 file size\n");
  238. }
  239. gf_isom_close(mp4);
  240. }
  241. }
  242. }
  243. return e;
  244. }
  245. GF_Err get_mp4_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime)
  246. {
  247. char mp4_path[100], *ext;
  248. GF_Err e = GF_OK;
  249. GF_ISOFile *mp4;
  250. *loadtime = 0;
  251. strcpy(mp4_path, item_name);
  252. ext = strrchr(mp4_path, '.');
  253. strcpy(ext, ".mp4");
  254. mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
  255. if (!mp4) {
  256. if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path);
  257. e = GF_IO_ERR;
  258. } else {
  259. e = load_mp4(lc, mp4, loadtime);
  260. if (e) {
  261. if (lc->verbose) fprintf(stdout, "Could not get MP4 file load time\n");
  262. }
  263. }
  264. gf_isom_close(mp4);
  265. return e;
  266. }
  267. GF_Err decode_svg(GF_LoadCompare *lc, char *item_name, char *item_path, char *svg_out_path)
  268. {
  269. GF_SceneManager *ctx;
  270. GF_SceneGraph *sg;
  271. GF_SceneLoader load;
  272. GF_ISOFile *mp4;
  273. GF_Err e = GF_OK;
  274. char mp4_path[256];
  275. char *ext;
  276. strcpy(mp4_path, item_name);
  277. ext = strrchr(mp4_path, '.');
  278. strcpy(ext, ".mp4");
  279. mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
  280. if (!mp4) {
  281. if (lc->verbose) fprintf(stdout, "Could not open file %s\n", mp4_path);
  282. e = GF_IO_ERR;
  283. } else {
  284. sg = gf_sg_new();
  285. ctx = gf_sm_new(sg);
  286. memset(&load, 0, sizeof(GF_SceneLoader));
  287. load.isom = mp4;
  288. load.ctx = ctx;
  289. e = gf_sm_load_init(&load);
  290. if (e) {
  291. fprintf(stderr, "Error loading MP4 file\n");
  292. } else {
  293. e = gf_sm_load_run(&load);
  294. if (e) {
  295. fprintf(stderr, "Error loading MP4 file\n");
  296. } else {
  297. gf_sm_load_done(&load);
  298. ext = strrchr(svg_out_path, '.');
  299. ext[0] = 0;
  300. e = gf_sm_dump(ctx, svg_out_path, GF_SM_DUMP_SVG);
  301. if (e) {
  302. fprintf(stderr, "Error dumping SVG from MP4 file\n");
  303. }
  304. }
  305. }
  306. gf_sm_del(ctx);
  307. gf_sg_del(sg);
  308. gf_isom_close(mp4);
  309. }
  310. return e;
  311. }
  312. GF_Err libxml_load_svg(GF_LoadCompare *lc, char *item_path, u32 *loadtime)
  313. {
  314. GF_Err e = GF_OK;
  315. GF_SceneGraph *sg;
  316. u32 i, starttime, endtime;
  317. void *p;
  318. u32 nb;
  319. if (lc->spread_repeat) nb = 1;
  320. else nb = lc->nbloads ;
  321. *loadtime = 0;
  322. for (i = 0; i<nb; i++) {
  323. sg = gf_sg_new();
  324. starttime = gf_sys_clock();
  325. p = DANAE_NewSVGParser(item_path, sg);
  326. DANAE_SVGParser_Parse(p);
  327. DANAE_SVGParser_Terminate();
  328. endtime = gf_sys_clock();
  329. if (lc->verbose) fprintf(stdout, "LibXML single parsing: %d\n", endtime-starttime);
  330. *loadtime += endtime-starttime;
  331. gf_sg_del(sg);
  332. }
  333. return e;
  334. }
  335. GF_Err get_size(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
  336. {
  337. GF_Err e = GF_OK;
  338. FILE *file = NULL;
  339. *size = 0;
  340. file = fopen(item_path, "rt");
  341. if (!file) {
  342. if (lc->verbose) fprintf(stdout, "Could not open file %s\n", item_path);
  343. e = GF_IO_ERR;
  344. } else {
  345. fseek(file, 0, SEEK_END);
  346. *size = (u32)ftell(file);
  347. fclose(file);
  348. if (*size == 0) {
  349. if (lc->verbose) fprintf(stdout, "File %s has a size of 0\n", item_path);
  350. e = GF_IO_ERR;
  351. }
  352. }
  353. return e;
  354. }
  355. GF_Err get_decoded_svg_loadtime_and_size(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime, u32 *size)
  356. {
  357. GF_Err e = GF_OK;
  358. char svg_out_name[256];
  359. char *ext;
  360. strcpy(svg_out_name, item_name);
  361. ext = strrchr(svg_out_name, '.');
  362. strcpy(ext, "_out.svg");
  363. *size = 0;
  364. *loadtime = 0;
  365. e = decode_svg(lc, item_name, item_path, svg_out_name);
  366. if (!e) {
  367. e = get_size(lc, svg_out_name, svg_out_name, size);
  368. if (e) {
  369. return e;
  370. }
  371. e = gpacctx_load_file(lc, svg_out_name, loadtime);
  372. }
  373. return e;
  374. }
  375. GF_Err create_gz_file(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
  376. {
  377. char buffer[100];
  378. char gz_path[256];
  379. GF_Err e = GF_OK;
  380. FILE *file = NULL;
  381. void *gz = NULL;
  382. u32 read;
  383. *size = 0;
  384. strcpy(gz_path, item_name);
  385. strcat(gz_path, "z");
  386. gz = gzopen(gz_path, "wb");
  387. file = fopen(item_path, "rt");
  388. if (!gz || !file) {
  389. if (lc->verbose) fprintf(stdout, "Could not open file %s or %s\n", item_path, gz_path);
  390. e = GF_IO_ERR;
  391. } else {
  392. while ((read = fread(buffer, 1, 100, file))) gzwrite(gz, buffer, read);
  393. fclose(file);
  394. gzclose(gz);
  395. file = fopen(gz_path, "rb");
  396. fseek(file, 0, SEEK_END);
  397. *size = (u32)ftell(file);
  398. fclose(file);
  399. if (*size == 0) {
  400. if (lc->verbose) fprintf(stdout, "File %s has a size of 0\n", gz_path);
  401. e = GF_IO_ERR;
  402. }
  403. }
  404. return e;
  405. }
  406. GF_Err get_gz_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime, Bool useLibXML)
  407. {
  408. char gz_path[256];
  409. GF_Err e = GF_OK;
  410. *loadtime = 0;
  411. strcpy(gz_path, item_name);
  412. strcat(gz_path, "z");
  413. if (useLibXML) {
  414. e = libxml_load_svg(lc, gz_path, loadtime);
  415. } else {
  416. e = gpacctx_load_file(lc, gz_path, loadtime);
  417. }
  418. return e;
  419. }
  420. void print_load_data(GF_LoadCompare *lc, LoadData *ld)
  421. {
  422. if (lc->verbose) fprintf(stdout, "Processing %s\n", ld->filename);
  423. fprintf(lc->out, "%s\t", ld->filename);
  424. if (lc->verbose) fprintf(stdout, "File Size %d\n", ld->size);
  425. fprintf(lc->out, "%d\t", ld->size);
  426. if (lc->verbose) fprintf(stdout, "GPAC XML Load Time %d\n", ld->gpacxml_loadtime);
  427. fprintf(lc->out, "%d\t", ld->gpacxml_loadtime);
  428. if (lc->verbose) fprintf(stdout, "LibXML Load Time %d \n", ld->libxml_loadtime);
  429. fprintf(lc->out, "%d\t", ld->libxml_loadtime);
  430. if (lc->verbose) fprintf(stdout, "GZ Size %d\n", ld->gz_size);
  431. fprintf(lc->out, "%d\t", ld->gz_size);
  432. if (lc->verbose) fprintf(stdout, "GZ Load Time %d\n", ld->gpacxml_gz_loadtime);
  433. fprintf(lc->out, "%d\t", ld->gpacxml_gz_loadtime);
  434. if (lc->verbose) fprintf(stdout, "LibXML GZ Load Time %d\n", ld->libxml_gz_loadtime);
  435. fprintf(lc->out, "%d\t", ld->libxml_gz_loadtime);
  436. if (lc->verbose) fprintf(stdout, "MP4 Track Size %d\n", ld->track_size);
  437. fprintf(lc->out, "%d\t", ld->track_size);
  438. if (lc->verbose) fprintf(stdout, "MP4 Track Load Time %d\n", ld->track_loadtime);
  439. fprintf(lc->out, "%d\t", ld->track_loadtime);
  440. if (lc->verbose) fprintf(stdout, "Decoded Size %d\n", ld->decoded_size);
  441. fprintf(lc->out, "%d\t", ld->decoded_size);
  442. if (lc->verbose) fprintf(stdout, "Decoded Load Time %d \n", ld->decoded_loadtime);
  443. fprintf(lc->out, "%d\t", ld->decoded_loadtime);
  444. if (lc->verbose) fprintf(stdout, "Done %s\n", ld->filename);
  445. fprintf(lc->out, "\n");
  446. fflush(lc->out);
  447. }
  448. Bool loadcompare_one(void *cbck, char *item_name, char *item_path)
  449. {
  450. GF_Err e;
  451. GF_LoadCompare *lc = cbck;
  452. u32 loadtime;
  453. LoadData *ld;
  454. if (lc->repeat_index == 0) {
  455. GF_SAFEALLOC(ld, sizeof(LoadData));
  456. gf_list_add(lc->data, ld);
  457. strcpy(ld->filename, item_name);
  458. e = get_size(lc, item_name, item_path, &ld->size);
  459. if (e) return 1;
  460. e = create_gz_file(lc, item_name, item_path, &ld->gz_size);
  461. if (e) return 1;
  462. e = create_laser_mp4(lc, item_name, item_path, &ld->track_size);
  463. if (e) return 1;
  464. } else {
  465. LoadData *tmp;
  466. u32 pos = 0;
  467. ld = NULL;
  468. while (tmp = gf_list_enum(lc->data, &pos)) {
  469. if (!strcmp(tmp->filename, item_name)) {
  470. ld = tmp;
  471. break;
  472. }
  473. }
  474. if (ld == NULL) return 1;
  475. }
  476. if (lc->type == SVG) {
  477. /* GPAC XML loader */
  478. e = gpacctx_load_file(lc, item_path, &loadtime);
  479. if (e) return 1;
  480. ld->gpacxml_loadtime += loadtime;
  481. e = get_gz_loadtime(lc, item_name, item_path, &loadtime, 0);
  482. if (e) return 1;
  483. ld->gpacxml_gz_loadtime += loadtime;
  484. /* LibXML and LibXML GZ loadings */
  485. e = libxml_load_svg(lc, item_path, &loadtime);
  486. if (e) return 1;
  487. ld->libxml_loadtime += loadtime;
  488. e = get_gz_loadtime(lc, item_name, item_path, &loadtime, 1);
  489. if (e) return 1;
  490. ld->libxml_gz_loadtime += loadtime;
  491. /* MP4 Loading */
  492. e = get_mp4_loadtime(lc, item_name, item_path, &loadtime);
  493. if (e) return 1;
  494. ld->track_loadtime += loadtime;
  495. /* e = get_decoded_svg_loadtime_and_size(lc, item_name, item_path, &loadtime, &ld->decoded_size);
  496. if (e) return 1;
  497. ld->decoded_loadtime += loadtime;*/
  498. } else if (lc->type == XMT) {
  499. e = gpacctx_load_file(lc, item_path, &loadtime);
  500. if (e) return 1;
  501. ld->gpacxml_loadtime += loadtime;
  502. }
  503. if (!lc->spread_repeat) {
  504. print_load_data(lc, ld);
  505. gf_free(ld);
  506. }
  507. return 0;
  508. }
  509. void usage()
  510. {
  511. fprintf(stdout, "Compare LASeR and SVG encoding size and loading time\n");
  512. fprintf(stdout, "usage: (-out output_result) (-single input.svg | -dir dir) (-nloads X) (-verbose X)\n");
  513. fprintf(stdout, "defaults are: stdout, dir=. and X = 1");
  514. }
  515. int main(int argc, char **argv)
  516. {
  517. u32 i;
  518. char *arg;
  519. GF_LoadCompare lc;
  520. Bool single = 0;
  521. char *out = NULL;
  522. char in[256] = ".";
  523. fprintf(stdout, "LASeR and SVG Comparison tool\n");
  524. memset(&lc, 0, sizeof(GF_LoadCompare));
  525. lc.nbloads = 1;
  526. lc.out = stdout;
  527. for (i = 1; i < (u32) argc ; i++) {
  528. arg = argv[i];
  529. if (!stricmp(arg, "-out")) {
  530. out = argv[i+1];
  531. i++;
  532. } else if (!stricmp(arg, "-single")) {
  533. single = 1;
  534. strcpy(in, argv[i+1]);
  535. i++;
  536. } else if (!stricmp(arg, "-dir")) {
  537. strcpy(in, argv[i+1]);
  538. i++;
  539. } else if (!stricmp(arg, "-nloads")) {
  540. lc.nbloads = (u32)atoi(argv[i+1]);
  541. i++;
  542. } else if (!stricmp(arg, "-regenerate")) {
  543. lc.regenerate = 1;
  544. } else if (!stricmp(arg, "-xmt")) {
  545. lc.type = XMT;
  546. } else if (!stricmp(arg, "-svg")) {
  547. lc.type = SVG;
  548. } else if (!stricmp(arg, "-spread_repeat")) {
  549. lc.spread_repeat = 1;
  550. } else if (!stricmp(arg, "-verbose")) {
  551. lc.verbose = (u32)atoi(argv[i+1]);
  552. i++;
  553. } else {
  554. usage();
  555. return -1;
  556. }
  557. }
  558. gf_sys_init();
  559. if (out) lc.out = fopen(out, "wt");
  560. if (!lc.out) {
  561. fprintf(stderr, "Cannot open output file %s\n", out);
  562. return -1;
  563. }
  564. if (lc.type == SVG) {
  565. 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");
  566. } else if (lc.type == XMT) {
  567. fprintf(lc.out,"File Name\tXMT Size\tXMT Load Time\tBT Size\tBT Load Time\n");
  568. }
  569. lc.data = gf_list_new();
  570. if (single) {
  571. LoadData *ld;
  572. char *tmp = strrchr(in, GF_PATH_SEPARATOR);
  573. loadcompare_one(&lc, tmp+1, in);
  574. ld = gf_list_get(lc.data, 0);
  575. print_load_data(&lc, ld);
  576. gf_free(ld);
  577. } else {
  578. if (lc.spread_repeat) {
  579. for (lc.repeat_index = 0; lc.repeat_index < lc.nbloads; lc.repeat_index ++) {
  580. if (lc.verbose) fprintf(stdout, "Loop %d\n", lc.repeat_index);
  581. if (lc.type == SVG) {
  582. gf_enum_directory(in, 0, loadcompare_one, &lc, "svg");
  583. } else if (lc.type == XMT) {
  584. gf_enum_directory(in, 0, loadcompare_one, &lc, "xmt");
  585. }
  586. }
  587. for (i=0; i<gf_list_count(lc.data); i++) {
  588. LoadData *ld = gf_list_get(lc.data, i);
  589. print_load_data(&lc, ld);
  590. gf_free(ld);
  591. }
  592. } else {
  593. if (lc.type == SVG) {
  594. gf_enum_directory(in, 0, loadcompare_one, &lc, "svg");
  595. } else if (lc.type == XMT) {
  596. gf_enum_directory(in, 0, loadcompare_one, &lc, "xmt");
  597. }
  598. }
  599. }
  600. gf_list_del(lc.data);
  601. if (lc.out) fclose(lc.out);
  602. gf_sys_close();
  603. return 0;
  604. }