📄 loadcompare.c
字号:
/* * GPAC - Multimedia Framework C SDK * * Copyright (c) Cyril Concolato 2000-2006 * All rights reserved * * This file is part of GPAC / load&compare 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 <gpac/scene_manager.h>#include <zlib.h>enum { SVG = 0, XMT = 1,};typedef struct { char filename[100]; u32 size; u32 gpacxml_loadtime; u32 libxml_loadtime; u32 gz_size; u32 gpacxml_gz_loadtime; u32 libxml_gz_loadtime; u32 track_size; u32 track_loadtime; u32 decoded_size; u32 decoded_loadtime;} LoadData;typedef struct { FILE *out; u32 type; u32 nbloads; u32 verbose; Bool regenerate; Bool spread_repeat; u32 repeat_index; GF_List *data;} GF_LoadCompare;GF_Err load_mp4(GF_LoadCompare *lc, GF_ISOFile *mp4, u32 *loadtime){ GF_Err e = GF_OK; GF_SceneLoader load; GF_SceneGraph *sg; u32 i, starttime, endtime; u32 nb; if (lc->spread_repeat) nb = 1; else nb = lc->nbloads ; *loadtime = 0; for (i = 0; i< nb; i++) { memset(&load, 0, sizeof(GF_SceneLoader)); sg = gf_sg_new(); load.ctx = gf_sm_new(sg); load.isom = mp4; starttime = gf_sys_clock(); e = gf_sm_load_init(&load); if (e) { fprintf(stderr, "Error loading MP4 file\n"); } else { e = gf_sm_load_run(&load); if (e) { fprintf(stderr, "Error loading MP4 file\n"); } else { endtime = gf_sys_clock(); *loadtime += endtime-starttime; } gf_sm_load_done(&load); } gf_sm_del(load.ctx); gf_sg_del(sg); } return e;}void load_progress(void *cbk, u32 done, u32 total) { fprintf(stdout, "%d/%d\r", done, total);}GF_Err gpacctx_load_file(GF_LoadCompare *lc, char *item_path, u32 *loadtime){ GF_Err e = GF_OK; GF_SceneLoader load; GF_SceneGraph *sg; u32 i, starttime, endtime; u32 nb; if (lc->spread_repeat) nb = 1; else nb = lc->nbloads ; *loadtime = 0; for (i = 0; i<nb; i++) { memset(&load, 0, sizeof(GF_SceneLoader)); sg = gf_sg_new(); load.ctx = gf_sm_new(sg); load.OnProgress = load_progress; load.fileName = item_path; starttime = gf_sys_clock(); e = gf_sm_load_init(&load); if (e) { fprintf(stderr, "Error loading file %s\n", item_path); } else { e = gf_sm_load_run(&load); if (e) { fprintf(stderr, "Error loading file %s\n", item_path); } else { endtime = gf_sys_clock(); *loadtime += endtime-starttime; } gf_sm_load_done(&load); } gf_sm_del(load.ctx); gf_sg_del(sg); } return e;}GF_Err get_laser_track_size(GF_ISOFile *mp4, u32 *size){ GF_Err e = GF_OK; u32 j; u32 track_id, trackNum; *size = 0; track_id = gf_isom_get_track_id(mp4, 1); trackNum = gf_isom_get_track_by_id(mp4, track_id); for (j=0; j<gf_isom_get_sample_count(mp4, trackNum); j++) { GF_ISOSample *samp = gf_isom_get_sample_info(mp4, trackNum, j+1, NULL, NULL); *size += samp->dataLength; gf_isom_sample_del(&samp); } return e;}GF_Err encode_laser(GF_LoadCompare *lc, char *item_path, GF_ISOFile *mp4, GF_SMEncodeOptions *opts) { GF_Err e = GF_OK; GF_SceneLoader load; GF_SceneManager *ctx; GF_SceneGraph *sg; GF_StatManager *statsman = NULL; memset(&load, 0, sizeof(GF_SceneLoader)); sg = gf_sg_new(); ctx = gf_sm_new(sg); load.ctx = ctx; load.fileName = item_path; e = gf_sm_load_init(&load); if (e) { fprintf(stderr, "Error loading file %s\n", item_path); } else { e = gf_sm_load_run(&load); if (e) { fprintf(stderr, "Error loading file %s\n", item_path); } else { if (opts->auto_qant) { if (lc->verbose) fprintf(stdout, "Analysing Scene for Automatic Quantization\n"); statsman = gf_sm_stats_new(); e = gf_sm_stats_for_scene(statsman, ctx); if (!e) { GF_SceneStatistics *stats = gf_sm_stats_get(statsman); if (opts->resolution > (s32)stats->frac_res_2d) { if (lc->verbose) fprintf(stdout, " Given resolution %d is (unnecessarily) too high, using %d instead.\n", opts->resolution, stats->frac_res_2d); opts->resolution = stats->frac_res_2d; } else if (stats->int_res_2d + opts->resolution <= 0) { if (lc->verbose) fprintf(stdout, " Given resolution %d is too low, using %d instead.\n", opts->resolution, stats->int_res_2d - 1); opts->resolution = 1 - stats->int_res_2d; } opts->coord_bits = stats->int_res_2d + opts->resolution; if (lc->verbose) fprintf(stdout, " Coordinates & Lengths encoded using "); if (opts->resolution < 0) { if (lc->verbose) fprintf(stdout, "only the %d most significant bits (of %d).\n", opts->coord_bits, stats->int_res_2d); } else { if (lc->verbose) fprintf(stdout, "a %d.%d representation\n", stats->int_res_2d, opts->resolution); } if (lc->verbose) fprintf(stdout, " Matrix Scale & Skew Coefficients "); if (opts->coord_bits < stats->scale_int_res_2d) { opts->scale_bits = stats->scale_int_res_2d - opts->coord_bits; if (lc->verbose) fprintf(stdout, "encoded using a %d.8 representation\n", stats->scale_int_res_2d); } else { opts->scale_bits = 0; if (lc->verbose) fprintf(stdout, "not encoded.\n"); } } gf_sm_stats_del(statsman); } e = gf_sm_encode_to_file(ctx, mp4, opts); if (e) { fprintf(stderr, "Error while encoding mp4 file\n"); } else { e = gf_isom_set_brand_info(mp4, GF_ISOM_BRAND_MP42, 1); if (!e) e = gf_isom_modify_alternate_brand(mp4, GF_ISOM_BRAND_ISOM, 1); } gf_sm_load_done(&load); } } gf_sm_del(ctx); gf_sg_del(sg); return e;}GF_Err create_laser_mp4(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *size){ char mp4_path[100], *ext; GF_Err e = GF_OK; GF_ISOFile *mp4; *size = 0; strcpy(mp4_path, item_name); ext = strrchr(mp4_path, '.'); strcpy(ext, ".mp4"); mp4 = gf_isom_open(mp4_path, GF_ISOM_WRITE_EDIT, NULL); if (!mp4) { if (lc->verbose) fprintf(stdout, "Could not open file %s for writing\n", mp4_path); e = GF_IO_ERR; } else { GF_SMEncodeOptions opts; memset(&opts, 0, sizeof(GF_SMEncodeOptions)); opts.auto_qant = 1; opts.resolution = 8; e = encode_laser(lc, item_path, mp4, &opts); if (e) { if (lc->verbose) fprintf(stdout, "Could not encode MP4 file from %s\n", item_path); gf_isom_delete(mp4); } else { gf_isom_close(mp4); mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL); if (!mp4) { if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path); e = GF_IO_ERR; } else { e = get_laser_track_size(mp4, size); if (e) { if (lc->verbose) fprintf(stdout, "Could not get MP4 file size\n"); } gf_isom_close(mp4); } } } return e;}GF_Err get_mp4_loadtime(GF_LoadCompare *lc, char *item_name, char *item_path, u32 *loadtime){ char mp4_path[100], *ext; GF_Err e = GF_OK; GF_ISOFile *mp4; *loadtime = 0; strcpy(mp4_path, item_name); ext = strrchr(mp4_path, '.'); strcpy(ext, ".mp4"); mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL); if (!mp4) { if (lc->verbose) fprintf(stdout, "Could not open file %s for reading\n", mp4_path); e = GF_IO_ERR; } else { e = load_mp4(lc, mp4, loadtime); if (e) { if (lc->verbose) fprintf(stdout, "Could not get MP4 file load time\n"); } } gf_isom_close(mp4); return e;}GF_Err decode_svg(GF_LoadCompare *lc, char *item_name, char *item_path, char *svg_out_path){ GF_SceneManager *ctx; GF_SceneGraph *sg; GF_SceneLoader load; GF_ISOFile *mp4; GF_Err e = GF_OK; char mp4_path[256]; char *ext; strcpy(mp4_path, item_name); ext = strrchr(mp4_path, '.'); strcpy(ext, ".mp4"); mp4 = gf_isom_open(mp4_path, GF_ISOM_OPEN_READ, NULL); if (!mp4) { if (lc->verbose) fprintf(stdout, "Could not open file %s\n", mp4_path); e = GF_IO_ERR; } else { sg = gf_sg_new(); ctx = gf_sm_new(sg); memset(&load, 0, sizeof(GF_SceneLoader)); load.isom = mp4; load.ctx = ctx; e = gf_sm_load_init(&load); if (e) { fprintf(stderr, "Error loading MP4 file\n"); } else { e = gf_sm_load_run(&load); if (e) { fprintf(stderr, "Error loading MP4 file\n"); } else { gf_sm_load_done(&load); ext = strrchr(svg_out_path, '.'); ext[0] = 0; e = gf_sm_dump(ctx, svg_out_path, GF_SM_DUMP_SVG); if (e) { fprintf(stderr, "Error dumping SVG from MP4 file\n"); } } } gf_sm_del(ctx); gf_sg_del(sg); gf_isom_close(mp4); } return e;}GF_Err libxml_load_svg(GF_LoadCompare *lc, char *item_path, u32 *loadtime){ GF_Err e = GF_OK; GF_SceneGraph *sg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -