~ubuntu-branches/ubuntu/intrepid/gpac/intrepid-proposed

« back to all changes in this revision

Viewing changes to applications/testapps/loadcompare/loadcompare.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-24 23:34:57 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070124233457-zzlls8afkt0nyakj
Tags: 0.4.2~rc2-0ubuntu1
* New upstream release
  * Most notably MP4 tagging support via MP4Box -itags
* debian/patches/01_64bits.dpatch: dropped; included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *                      GPAC - Multimedia Framework C SDK
 
3
 *
 
4
 *                      Copyright (c) Cyril Concolato 2000-2006
 
5
 *                                      All rights reserved
 
6
 *
 
7
 *  This file is part of GPAC / load&compare application
 
8
 *
 
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)
 
12
 *  any later version.
 
13
 *   
 
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.
 
18
 *   
 
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. 
 
22
 *
 
23
 */
 
24
#include <gpac/scene_manager.h>
 
25
#include <zlib.h>
 
26
 
 
27
enum {
 
28
        SVG = 0,
 
29
        XMT = 1,
 
30
};
 
31
 
 
32
typedef struct {
 
33
        char filename[100];
 
34
        u32 size;
 
35
        u32 gpacxml_loadtime;
 
36
        u32 libxml_loadtime;
 
37
        u32 gz_size;
 
38
        u32 gpacxml_gz_loadtime;
 
39
        u32 libxml_gz_loadtime;
 
40
        u32 track_size;
 
41
        u32 track_loadtime;
 
42
        u32 decoded_size;
 
43
        u32 decoded_loadtime;
 
44
} LoadData;
 
45
 
 
46
typedef struct {
 
47
        FILE *out;
 
48
        u32 type;
 
49
        u32 nbloads;
 
50
        u32 verbose;
 
51
        Bool regenerate;
 
52
        Bool spread_repeat;
 
53
        u32 repeat_index;
 
54
        GF_List *data;
 
55
} GF_LoadCompare;
 
56
 
 
57
GF_Err load_mp4(GF_LoadCompare *lc, GF_ISOFile *mp4, u32 *loadtime)
 
58
{
 
59
        GF_Err e = GF_OK;
 
60
        GF_SceneLoader load;
 
61
        GF_SceneGraph *sg;
 
62
        u32 i, starttime, endtime;
 
63
        u32 nb;
 
64
        if (lc->spread_repeat) nb = 1;
 
65
        else nb = lc->nbloads ;
 
66
        
 
67
        *loadtime = 0;
 
68
        for (i = 0; i< nb; i++) {
 
69
                memset(&load, 0, sizeof(GF_SceneLoader));
 
70
                sg = gf_sg_new();
 
71
                load.ctx = gf_sm_new(sg);
 
72
 
 
73
                load.isom = mp4;
 
74
                starttime = gf_sys_clock();
 
75
 
 
76
                e = gf_sm_load_init(&load);
 
77
                if (e) {
 
78
                        fprintf(stderr, "Error loading MP4 file\n");
 
79
                } else {
 
80
                        e = gf_sm_load_run(&load);
 
81
                        if (e) {
 
82
                                fprintf(stderr, "Error loading MP4 file\n");
 
83
                        } else {
 
84
                                endtime = gf_sys_clock();
 
85
                                *loadtime += endtime-starttime;
 
86
                        }
 
87
                        gf_sm_load_done(&load);
 
88
                }               
 
89
                gf_sm_del(load.ctx);
 
90
                gf_sg_del(sg);
 
91
        }
 
92
        return e;
 
93
}
 
94
 
 
95
void load_progress(void *cbk, u32 done, u32 total) {
 
96
        fprintf(stdout, "%d/%d\r", done, total);
 
97
}
 
98
 
 
99
GF_Err gpacctx_load_file(GF_LoadCompare *lc, char *item_path, u32 *loadtime)
 
100
{
 
101
        GF_Err e = GF_OK;
 
102
        GF_SceneLoader load;
 
103
        GF_SceneGraph *sg;
 
104
        u32 i, starttime, endtime;
 
105
        
 
106
        u32 nb;
 
107
        if (lc->spread_repeat) nb = 1;
 
108
        else nb = lc->nbloads ;
 
109
 
 
110
        *loadtime = 0;
 
111
 
 
112
        for (i = 0; i<nb; i++) {
 
113
                memset(&load, 0, sizeof(GF_SceneLoader));
 
114
                sg = gf_sg_new();
 
115
                load.ctx = gf_sm_new(sg);
 
116
                load.OnProgress = load_progress;
 
117
 
 
118
                load.fileName = item_path;
 
119
                starttime = gf_sys_clock();
 
120
 
 
121
                e = gf_sm_load_init(&load);
 
122
                if (e) {
 
123
                        fprintf(stderr, "Error loading file %s\n", item_path);
 
124
                } else {
 
125
                        e = gf_sm_load_run(&load);
 
126
                        if (e) {
 
127
                                fprintf(stderr, "Error loading file %s\n", item_path);
 
128
                        } else {
 
129
                                endtime = gf_sys_clock();
 
130
                                *loadtime += endtime-starttime;
 
131
                        }
 
132
                        gf_sm_load_done(&load);
 
133
                }               
 
134
                gf_sm_del(load.ctx);
 
135
                gf_sg_del(sg);
 
136
        }
 
137
        return e;
 
138
}
 
139
 
 
140
GF_Err get_laser_track_size(GF_ISOFile *mp4, u32 *size)
 
141
{
 
142
        GF_Err e = GF_OK;
 
143
        u32 j;
 
144
        u32 track_id, trackNum;
 
145
        
 
146
        *size = 0;
 
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);
 
153
        }
 
154
        return e;
 
155
}
 
156
 
 
157
GF_Err encode_laser(GF_LoadCompare *lc, char *item_path, GF_ISOFile *mp4, GF_SMEncodeOptions *opts) 
 
158
{
 
159
        GF_Err e = GF_OK;
 
160
        GF_SceneLoader load;
 
161
        GF_SceneManager *ctx;
 
162
        GF_SceneGraph *sg;
 
163
        GF_StatManager *statsman = NULL;
 
164
 
 
165
        memset(&load, 0, sizeof(GF_SceneLoader));
 
166
        sg = gf_sg_new();
 
167
        ctx = gf_sm_new(sg);
 
168
        load.ctx = ctx;
 
169
        load.fileName = item_path;
 
170
 
 
171
        e = gf_sm_load_init(&load);
 
172
        if (e) {
 
173
                fprintf(stderr, "Error loading file %s\n", item_path);
 
174
        } else {
 
175
                e = gf_sm_load_run(&load);
 
176
                if (e) {
 
177
                        fprintf(stderr, "Error loading file %s\n", item_path);
 
178
                } else {
 
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);
 
183
                                if (!e) {
 
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;
 
191
                                        }                               
 
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);
 
196
                                        } else {
 
197
                                                if (lc->verbose) fprintf(stdout, "a %d.%d representation\n", stats->int_res_2d, opts->resolution);
 
198
                                        }
 
199
 
 
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);
 
204
                                        } else  {
 
205
                                                opts->scale_bits = 0;
 
206
                                                if (lc->verbose) fprintf(stdout, "not encoded.\n");
 
207
                                        }
 
208
                                }
 
209
                                gf_sm_stats_del(statsman);
 
210
                        }
 
211
                        
 
212
                        e = gf_sm_encode_to_file(ctx, mp4, opts);
 
213
                        if (e) {
 
214
                                fprintf(stderr, "Error while encoding mp4 file\n");
 
215
                        } else {
 
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);
 
218
                        }
 
219
 
 
220
                        gf_sm_load_done(&load);
 
221
                }               
 
222
        }
 
223
        gf_sm_del(ctx);
 
224
        gf_sg_del(sg);
 
225
 
 
226
        return e;
 
227
}
 
228
 
 
229
GF_Err create_laser_mp4(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
 
230
{
 
231
        char mp4_path[100], *ext;
 
232
        GF_Err e = GF_OK;
 
233
        GF_ISOFile *mp4;
 
234
 
 
235
        *size = 0;
 
236
 
 
237
        strcpy(mp4_path, item_name);
 
238
        ext = strrchr(mp4_path, '.');
 
239
        strcpy(ext, ".mp4");
 
240
        mp4 = gf_isom_open(mp4_path, GF_ISOM_WRITE_EDIT, NULL);
 
241
        if (!mp4) {
 
242
                if (lc->verbose) fprintf(stdout, "Could not open file %s for writing\n", mp4_path);
 
243
                e = GF_IO_ERR;
 
244
        } else {
 
245
                GF_SMEncodeOptions opts;
 
246
                memset(&opts, 0, sizeof(GF_SMEncodeOptions));
 
247
                opts.auto_qant = 1;
 
248
                opts.resolution = 8;
 
249
                e = encode_laser(lc, item_path, mp4, &opts);
 
250
                if (e) {
 
251
                        if (lc->verbose) fprintf(stdout, "Could not encode MP4 file from %s\n", item_path);
 
252
                        gf_isom_delete(mp4);
 
253
                } else {
 
254
                        gf_isom_close(mp4);
 
255
 
 
256
                        mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
 
257
                        if (!mp4) {
 
258
                                if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path);
 
259
                                e = GF_IO_ERR;
 
260
                        } else {
 
261
                                e = get_laser_track_size(mp4, size);
 
262
                                if (e) {
 
263
                                        if (lc->verbose) fprintf(stdout, "Could not get MP4 file size\n");
 
264
                                } 
 
265
                                gf_isom_close(mp4);
 
266
                        }
 
267
                }
 
268
        }
 
269
        return e;
 
270
}
 
271
 
 
272
 
 
273
GF_Err get_mp4_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime)
 
274
{
 
275
        char mp4_path[100], *ext;
 
276
        GF_Err e = GF_OK;
 
277
        GF_ISOFile *mp4;
 
278
 
 
279
        *loadtime = 0;
 
280
 
 
281
        strcpy(mp4_path, item_name);
 
282
        ext = strrchr(mp4_path, '.');
 
283
        strcpy(ext, ".mp4");
 
284
        mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
 
285
        if (!mp4) {
 
286
                if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path);
 
287
                e = GF_IO_ERR;
 
288
        } else {
 
289
                e = load_mp4(lc, mp4, loadtime);
 
290
                if (e) {
 
291
                        if (lc->verbose) fprintf(stdout, "Could not get MP4 file load time\n");
 
292
                }       
 
293
        }
 
294
        gf_isom_close(mp4);
 
295
        return e;
 
296
}
 
297
 
 
298
GF_Err decode_svg(GF_LoadCompare *lc, char *item_name, char *item_path, char *svg_out_path)
 
299
{
 
300
        GF_SceneManager *ctx;
 
301
        GF_SceneGraph *sg;
 
302
        GF_SceneLoader load;
 
303
        GF_ISOFile *mp4;
 
304
        GF_Err e = GF_OK;
 
305
        char mp4_path[256];
 
306
        char *ext;
 
307
 
 
308
        strcpy(mp4_path, item_name);
 
309
        ext = strrchr(mp4_path, '.');
 
310
        strcpy(ext, ".mp4");
 
311
        mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL);
 
312
        if (!mp4) {
 
313
                if (lc->verbose) fprintf(stdout, "Could not open file %s\n", mp4_path);
 
314
                e = GF_IO_ERR;
 
315
        } else {
 
316
                sg = gf_sg_new();
 
317
                ctx = gf_sm_new(sg);
 
318
                memset(&load, 0, sizeof(GF_SceneLoader));
 
319
                load.isom = mp4;
 
320
                load.ctx = ctx;
 
321
                e = gf_sm_load_init(&load);
 
322
                if (e) {
 
323
                        fprintf(stderr, "Error loading MP4 file\n");
 
324
                } else {                
 
325
                        e = gf_sm_load_run(&load);
 
326
                        if (e) {
 
327
                                fprintf(stderr, "Error loading MP4 file\n");
 
328
                        } else {
 
329
                                gf_sm_load_done(&load);
 
330
 
 
331
                                ext = strrchr(svg_out_path, '.');
 
332
                                ext[0] = 0;
 
333
                                e = gf_sm_dump(ctx, svg_out_path, GF_SM_DUMP_SVG);
 
334
                                if (e) {
 
335
                                        fprintf(stderr, "Error dumping SVG from MP4 file\n");
 
336
                                }
 
337
                        }
 
338
                }
 
339
                gf_sm_del(ctx);
 
340
                gf_sg_del(sg);
 
341
                gf_isom_close(mp4);
 
342
        }
 
343
        return e;
 
344
}
 
345
 
 
346
GF_Err libxml_load_svg(GF_LoadCompare *lc, char *item_path, u32 *loadtime)
 
347
{
 
348
        GF_Err e = GF_OK;
 
349
        GF_SceneGraph *sg;
 
350
        u32 i, starttime, endtime;
 
351
        void *p;
 
352
        
 
353
        u32 nb;
 
354
        if (lc->spread_repeat) nb = 1;
 
355
        else nb = lc->nbloads ;
 
356
 
 
357
        *loadtime = 0;
 
358
 
 
359
        for (i = 0; i<nb; i++) {
 
360
                sg = gf_sg_new();
 
361
 
 
362
                starttime = gf_sys_clock();
 
363
 
 
364
                p = DANAE_NewSVGParser(item_path, sg);
 
365
                DANAE_SVGParser_Parse(p);
 
366
                DANAE_SVGParser_Terminate();
 
367
 
 
368
                endtime = gf_sys_clock();
 
369
                if (lc->verbose) fprintf(stdout, "LibXML single parsing: %d\n", endtime-starttime);
 
370
                *loadtime += endtime-starttime;
 
371
 
 
372
                gf_sg_del(sg);
 
373
        }
 
374
        return e;
 
375
}
 
376
 
 
377
GF_Err get_size(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
 
378
{
 
379
        GF_Err e = GF_OK;
 
380
        FILE *file = NULL;
 
381
 
 
382
        *size = 0;
 
383
 
 
384
        file = fopen(item_path, "rt");
 
385
        if (!file) {
 
386
                if (lc->verbose) fprintf(stdout, "Could not open file %s\n", item_path);
 
387
                e = GF_IO_ERR;
 
388
        } else {
 
389
                fseek(file, 0, SEEK_END);
 
390
                *size = (u32)ftell(file);
 
391
                fclose(file);
 
392
                if (*size == 0) {
 
393
                        if (lc->verbose) fprintf(stdout, "File %s has a size of 0\n", item_path);
 
394
                        e = GF_IO_ERR;
 
395
                }               
 
396
        }
 
397
        return e;
 
398
}
 
399
 
 
400
GF_Err get_decoded_svg_loadtime_and_size(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime, u32 *size)
 
401
{
 
402
        GF_Err e = GF_OK;
 
403
        char svg_out_name[256];
 
404
        char *ext;
 
405
 
 
406
        strcpy(svg_out_name, item_name);
 
407
        ext = strrchr(svg_out_name, '.');
 
408
        strcpy(ext, "_out.svg");
 
409
 
 
410
        *size = 0;
 
411
        *loadtime = 0;
 
412
 
 
413
        e = decode_svg(lc, item_name, item_path, svg_out_name);
 
414
        if (!e) {
 
415
                e = get_size(lc, svg_out_name, svg_out_name, size);
 
416
                if (e) {
 
417
                        return e;
 
418
                }
 
419
                e = gpacctx_load_file(lc, svg_out_name, loadtime);
 
420
        }
 
421
        return e;
 
422
}
 
423
 
 
424
GF_Err create_gz_file(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size)
 
425
{
 
426
        char buffer[100];
 
427
        char gz_path[256];
 
428
        GF_Err e = GF_OK;
 
429
        FILE *file = NULL;
 
430
        void *gz = NULL;
 
431
        u32 read;
 
432
 
 
433
        *size = 0;
 
434
 
 
435
        strcpy(gz_path, item_name);
 
436
        strcat(gz_path, "z");
 
437
        gz = gzopen(gz_path, "wb");
 
438
        file = fopen(item_path, "rt");
 
439
 
 
440
        if (!gz || !file) {
 
441
                if (lc->verbose) fprintf(stdout, "Could not open file %s or %s\n", item_path, gz_path);
 
442
                e = GF_IO_ERR;
 
443
        } else {
 
444
                while ((read = fread(buffer, 1, 100, file))) gzwrite(gz, buffer, read);
 
445
                fclose(file);
 
446
                gzclose(gz);
 
447
                file = fopen(gz_path, "rb");
 
448
                fseek(file, 0, SEEK_END);
 
449
                *size = (u32)ftell(file);
 
450
                fclose(file);
 
451
                if (*size == 0) {
 
452
                        if (lc->verbose) fprintf(stdout, "File %s has a size of 0\n", gz_path);
 
453
                        e = GF_IO_ERR;
 
454
                } 
 
455
        }
 
456
        return e;
 
457
}
 
458
 
 
459
GF_Err get_gz_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime, Bool useLibXML)
 
460
{
 
461
        char gz_path[256];
 
462
        GF_Err e = GF_OK;
 
463
        *loadtime = 0;
 
464
 
 
465
        strcpy(gz_path, item_name);
 
466
        strcat(gz_path, "z");
 
467
 
 
468
        if (useLibXML) {
 
469
                e = libxml_load_svg(lc, gz_path, loadtime);
 
470
        } else {
 
471
                e = gpacctx_load_file(lc, gz_path, loadtime);
 
472
        }
 
473
        return e;
 
474
}
 
475
 
 
476
void print_load_data(GF_LoadCompare *lc, LoadData *ld)
 
477
{
 
478
        if (lc->verbose) fprintf(stdout, "Processing %s\n", ld->filename);
 
479
        fprintf(lc->out, "%s\t", ld->filename);
 
480
 
 
481
        if (lc->verbose) fprintf(stdout, "File Size %d\n", ld->size);
 
482
        fprintf(lc->out, "%d\t", ld->size);
 
483
 
 
484
        if (lc->verbose) fprintf(stdout, "GPAC XML Load Time %d\n", ld->gpacxml_loadtime);
 
485
        fprintf(lc->out, "%d\t", ld->gpacxml_loadtime);
 
486
 
 
487
        if (lc->verbose) fprintf(stdout, "LibXML Load Time %d \n", ld->libxml_loadtime);
 
488
        fprintf(lc->out, "%d\t", ld->libxml_loadtime);
 
489
 
 
490
        if (lc->verbose) fprintf(stdout, "GZ Size %d\n", ld->gz_size);
 
491
        fprintf(lc->out, "%d\t", ld->gz_size);
 
492
 
 
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);
 
495
 
 
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);
 
498
 
 
499
        if (lc->verbose) fprintf(stdout, "MP4 Track Size %d\n", ld->track_size);
 
500
        fprintf(lc->out, "%d\t", ld->track_size);
 
501
 
 
502
        if (lc->verbose) fprintf(stdout, "MP4 Track Load Time %d\n", ld->track_loadtime);
 
503
        fprintf(lc->out, "%d\t", ld->track_loadtime);
 
504
 
 
505
        if (lc->verbose) fprintf(stdout, "Decoded Size %d\n", ld->decoded_size);
 
506
        fprintf(lc->out, "%d\t", ld->decoded_size);
 
507
 
 
508
        if (lc->verbose) fprintf(stdout, "Decoded Load Time %d \n", ld->decoded_loadtime);
 
509
        fprintf(lc->out, "%d\t", ld->decoded_loadtime);
 
510
 
 
511
        if (lc->verbose) fprintf(stdout, "Done %s\n", ld->filename);
 
512
        fprintf(lc->out, "\n");
 
513
        fflush(lc->out);
 
514
}
 
515
 
 
516
Bool loadcompare_one(void *cbck, char *item_name, char *item_path)
 
517
{
 
518
        GF_Err e;
 
519
        GF_LoadCompare *lc = cbck;
 
520
        u32 loadtime;
 
521
        LoadData *ld;
 
522
 
 
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);
 
527
 
 
528
                e = get_size(lc, item_name, item_path, &ld->size);
 
529
                if (e) return 1;
 
530
 
 
531
                e = create_gz_file(lc, item_name, item_path, &ld->gz_size);
 
532
                if (e) return 1;
 
533
 
 
534
                e = create_laser_mp4(lc, item_name, item_path, &ld->track_size);
 
535
                if (e) return 1;
 
536
 
 
537
        } else {
 
538
                LoadData *tmp;
 
539
                u32 pos = 0;
 
540
                ld = NULL;
 
541
                while (tmp = gf_list_enum(lc->data, &pos)) {
 
542
                        if (!strcmp(tmp->filename, item_name)) {
 
543
                                ld = tmp;
 
544
                                break;
 
545
                        }
 
546
                }
 
547
                if (ld == NULL) return 1;
 
548
        }
 
549
 
 
550
 
 
551
        if (lc->type == SVG) {
 
552
                /* GPAC XML loader */
 
553
                e = gpacctx_load_file(lc, item_path, &loadtime);
 
554
                if (e) return 1;
 
555
                ld->gpacxml_loadtime += loadtime;
 
556
 
 
557
                e = get_gz_loadtime(lc, item_name, item_path, &loadtime, 0);
 
558
                if (e) return 1;
 
559
                ld->gpacxml_gz_loadtime += loadtime;
 
560
 
 
561
                /* LibXML and LibXML GZ loadings */
 
562
                e = libxml_load_svg(lc, item_path, &loadtime);
 
563
                if (e) return 1;
 
564
                ld->libxml_loadtime += loadtime;
 
565
 
 
566
                e = get_gz_loadtime(lc, item_name, item_path, &loadtime, 1);
 
567
                if (e) return 1;
 
568
                ld->libxml_gz_loadtime += loadtime;
 
569
 
 
570
                /* MP4 Loading */
 
571
                e = get_mp4_loadtime(lc, item_name, item_path, &loadtime);
 
572
                if (e) return 1;
 
573
                ld->track_loadtime += loadtime;
 
574
 
 
575
/*              e = get_decoded_svg_loadtime_and_size(lc, item_name, item_path, &loadtime, &ld->decoded_size);
 
576
                if (e) return 1;
 
577
                ld->decoded_loadtime += loadtime;*/
 
578
 
 
579
        } else if (lc->type == XMT) {
 
580
                e = gpacctx_load_file(lc, item_path, &loadtime);
 
581
                if (e) return 1;
 
582
                ld->gpacxml_loadtime += loadtime;
 
583
        }
 
584
 
 
585
        if (!lc->spread_repeat) {
 
586
                print_load_data(lc, ld);
 
587
                free(ld);
 
588
        }
 
589
        return 0;
 
590
}
 
591
 
 
592
void usage() 
 
593
{
 
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");
 
597
}
 
598
 
 
599
int main(int argc, char **argv)
 
600
{
 
601
        u32 i;
 
602
        char *arg;
 
603
        GF_LoadCompare lc;
 
604
        Bool single = 0;
 
605
        char *out = NULL;
 
606
        char in[256] = ".";
 
607
 
 
608
        fprintf(stdout, "LASeR and SVG Comparison tool\n");
 
609
 
 
610
        memset(&lc, 0, sizeof(GF_LoadCompare));
 
611
        lc.nbloads = 1;
 
612
        lc.out = stdout;
 
613
        
 
614
        for (i = 1; i < (u32) argc ; i++) {
 
615
                arg = argv[i];
 
616
                if (!stricmp(arg, "-out")) {
 
617
                        out = argv[i+1];
 
618
                        i++;
 
619
                } else if (!stricmp(arg, "-single")) {
 
620
                        single = 1;
 
621
                        strcpy(in, argv[i+1]);
 
622
                        i++;
 
623
                } else if (!stricmp(arg, "-dir")) {
 
624
                        strcpy(in, argv[i+1]);
 
625
                        i++;
 
626
                } else if (!stricmp(arg, "-nloads")) {
 
627
                        lc.nbloads = (u32)atoi(argv[i+1]);
 
628
                        i++;
 
629
                } else if (!stricmp(arg, "-regenerate")) {
 
630
                        lc.regenerate = 1;
 
631
                } else if (!stricmp(arg, "-xmt")) {
 
632
                        lc.type = XMT;
 
633
                } else if (!stricmp(arg, "-svg")) {
 
634
                        lc.type = 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]);
 
639
                        i++;
 
640
                } else {
 
641
                        usage();
 
642
                        return -1;
 
643
                }       
 
644
        }
 
645
 
 
646
        gf_sys_init();
 
647
        if (out) lc.out = fopen(out, "wt");
 
648
        if (!lc.out) {
 
649
                fprintf(stderr, "Cannot open output file %s\n", out);
 
650
                return -1;
 
651
        }
 
652
 
 
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");
 
657
        }
 
658
 
 
659
        lc.data = gf_list_new();
 
660
 
 
661
        if (single) {
 
662
                LoadData *ld;
 
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);
 
667
                free(ld);
 
668
        } else {
 
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");
 
676
                                }
 
677
                        }
 
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);
 
681
                                free(ld);
 
682
                        }
 
683
                } else {
 
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");
 
688
                        }
 
689
                }
 
690
        }
 
691
        gf_list_del(lc.data);
 
692
                
 
693
        if (lc.out) fclose(lc.out);
 
694
        gf_sys_close();
 
695
        return 0;
 
696
}
 
697