📄 av_parsers.c
字号:
/*done*/ if (hasVOP) { go = 0; break; } if (firstObj) { *start = m4v->current_object_start; firstObj = 0; } hasVOP = 1; /*coding type*/ *frame_type = gf_bs_read_int(m4v->bs, 2); /*modulo time base*/ secs = 0; while (gf_bs_read_int(m4v->bs, 1) != 0) secs ++; /*no support for B frames in parsing*/ secs += (dsi.enh_layer || *frame_type!=2) ? m4v->tc_dec : m4v->tc_disp; /*marker*/ gf_bs_read_int(m4v->bs, 1); /*vop_time_inc*/ if (dsi.NumBitsTimeIncrement) vop_inc = gf_bs_read_int(m4v->bs, dsi.NumBitsTimeIncrement); m4v->prev_tc_dec = m4v->tc_dec; m4v->prev_tc_disp = m4v->tc_disp; if (dsi.enh_layer || *frame_type!=2) { m4v->tc_disp = m4v->tc_dec; m4v->tc_dec = secs; } *time_inc = secs * dsi.clock_rate + vop_inc; /*marker*/ gf_bs_read_int(m4v->bs, 1); /*coded*/ *is_coded = gf_bs_read_int(m4v->bs, 1); gf_bs_align(m4v->bs); break; case M4V_GOV_START_CODE: if (firstObj) { *start = m4v->current_object_start; firstObj = 0; } if (hasVOP) go = 0; break; case M4V_VOS_START_CODE: case M4V_VOL_START_CODE: if (hasVOP) { go = 0; } else if (firstObj) { *start = m4v->current_object_start; firstObj = 0; } break; case M4V_VO_START_CODE: default: break; case -1: *size = (u32) gf_bs_get_position(m4v->bs) - *start; return GF_EOS; } } *size = m4v->current_object_start - *start; return GF_OK;}GF_EXPORTGF_Err gf_m4v_parse_frame(GF_M4VParser *m4v, GF_M4VDecSpecInfo dsi, u8 *frame_type, u32 *time_inc, u32 *size, u32 *start, Bool *is_coded){ if (m4v->mpeg12) { return gf_m4v_parse_frame_mpeg12(m4v, dsi, frame_type, time_inc, size, start, is_coded); } else { return gf_m4v_parse_frame_mpeg4(m4v, dsi, frame_type, time_inc, size, start, is_coded); }}GF_Err gf_m4v_rewrite_par(char **o_data, u32 *o_dataLen, s32 par_n, s32 par_d){ u32 start, end, size; GF_BitStream *mod; GF_M4VParser *m4v; Bool go = 1; m4v = gf_m4v_parser_new(*o_data, *o_dataLen, 0); mod = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); end = start = 0; while (go) { u32 type = M4V_LoadObject(m4v); end = (u32) gf_bs_get_position(m4v->bs) - 4; size = end - start; /*store previous object*/ if (size) { if (size) gf_bs_write_data(mod, *o_data + start, size); start = end; } switch (type) { case M4V_VOL_START_CODE: gf_bs_write_int(mod, 0, 8); gf_bs_write_int(mod, 0, 8); gf_bs_write_int(mod, 1, 8); gf_bs_write_int(mod, M4V_VOL_START_CODE, 8); gf_bs_write_int(mod, gf_bs_read_int(m4v->bs, 1), 1); gf_bs_write_int(mod, gf_bs_read_int(m4v->bs, 8), 8); start = gf_bs_read_int(m4v->bs, 1); gf_bs_write_int(mod, start, 1); if (start) { gf_bs_write_int(mod, gf_bs_read_int(m4v->bs, 7), 7); } start = gf_bs_read_int(m4v->bs, 4); if (start == 0xF) { gf_bs_read_int(m4v->bs, 8); gf_bs_read_int(m4v->bs, 8); } if ((par_n>=0) && (par_d>=0)) { u8 par = m4v_get_sar_idx(par_n, par_d); gf_bs_write_int(mod, par, 4); if (par==0xF) { gf_bs_write_int(mod, par_n, 8); gf_bs_write_int(mod, par_d, 8); } } else { gf_bs_write_int(mod, 0x0, 4); } case -1: go = 0; break; default: break; } } while (gf_bs_bits_available(m4v->bs)) { u32 b = gf_bs_read_int(m4v->bs, 1); gf_bs_write_int(mod, b, 1); } gf_m4v_parser_del(m4v); free(*o_data); gf_bs_get_content(mod, o_data, o_dataLen); gf_bs_del(mod); return GF_OK;}GF_EXPORTu32 gf_m4v_get_object_start(GF_M4VParser *m4v){ return m4v->current_object_start;}GF_EXPORTBool gf_m4v_is_valid_object_type(GF_M4VParser *m4v){ return ((s32) m4v->current_object_type==-1) ? 0 : 1;}GF_EXPORTGF_Err gf_m4v_get_config(char *rawdsi, u32 rawdsi_size, GF_M4VDecSpecInfo *dsi){ GF_Err e; GF_M4VParser *vparse; if (!rawdsi || !rawdsi_size) return GF_NON_COMPLIANT_BITSTREAM; vparse = gf_m4v_parser_new(rawdsi, rawdsi_size, 0); e = gf_m4v_parse_config(vparse, dsi); gf_m4v_parser_del(vparse); return e;}/* AAC parser*/GF_EXPORTconst char *gf_m4a_object_type_name(u32 objectType){ switch (objectType) { case 0: return "Reserved"; case 1: return "AAC Main"; case 2: return "AAC LC"; case 3: return "AAC SSR"; case 4: return "AAC LTP"; case 5: return "SBR"; case 6: return "AAC Scalable"; case 7: return "TwinVQ"; case 8: return "CELP"; case 9: return "HVXC"; case 10: return "Reserved"; case 11: return "Reserved"; case 12: return "TTSI"; case 13: return "Main synthetic"; case 14: return "Wavetable synthesis"; case 15: return "General MIDI"; case 16: return "Algorithmic Synthesis and Audio FX"; case 17: return "ER AAC LC"; case 18: return "Reserved"; case 19: return "ER AAC LTP"; case 20: return "ER AAC scalable"; case 21: return "ER TwinVQ"; case 22: return "ER BSAC"; case 23: return "ER AAC LD"; case 24: return "ER CELP"; case 25: return "ER HVXC"; case 26: return "ER HILN"; case 27: return "ER Parametric"; case 28: return "SSC"; case 29: return "ParametricStereo"; case 30: return "(Reserved)"; case 31: return "(Reserved)"; case 32: return "Layer-1"; case 33: return "Layer-2"; case 34: return "Layer-3"; case 35: return "DST"; case 36: return "ALS"; default: return "Unknown"; }}GF_EXPORTconst char *gf_m4a_get_profile_name(u8 audio_pl){ switch (audio_pl) { case 0x00: return "ISO Reserved (0x00)"; case 0x01: return "Main Audio Profile @ Level 1"; case 0x02: return "Main Audio Profile @ Level 2"; case 0x03: return "Main Audio Profile @ Level 3"; case 0x04: return "Main Audio Profile @ Level 4"; case 0x05: return "Scalable Audio Profile @ Level 1"; case 0x06: return "Scalable Audio Profile @ Level 2"; case 0x07: return "Scalable Audio Profile @ Level 3"; case 0x08: return "Scalable Audio Profile @ Level 4"; case 0x09: return "Speech Audio Profile @ Level 1"; case 0x0A: return "Speech Audio Profile @ Level 2"; case 0x0B: return "Synthetic Audio Profile @ Level 1"; case 0x0C: return "Synthetic Audio Profile @ Level 2"; case 0x0D: return "Synthetic Audio Profile @ Level 3"; case 0x0E: return "High Quality Audio Profile @ Level 1"; case 0x0F: return "High Quality Audio Profile @ Level 2"; case 0x10: return "High Quality Audio Profile @ Level 3"; case 0x11: return "High Quality Audio Profile @ Level 4"; case 0x12: return "High Quality Audio Profile @ Level 5"; case 0x13: return "High Quality Audio Profile @ Level 6"; case 0x14: return "High Quality Audio Profile @ Level 7"; case 0x15: return "High Quality Audio Profile @ Level 8"; case 0x16: return "Low Delay Audio Profile @ Level 1"; case 0x17: return "Low Delay Audio Profile @ Level 2"; case 0x18: return "Low Delay Audio Profile @ Level 3"; case 0x19: return "Low Delay Audio Profile @ Level 4"; case 0x1A: return "Low Delay Audio Profile @ Level 5"; case 0x1B: return "Low Delay Audio Profile @ Level 6"; case 0x1C: return "Low Delay Audio Profile @ Level 7"; case 0x1D: return "Low Delay Audio Profile @ Level 8"; case 0x1E: return "Natural Audio Profile @ Level 1"; case 0x1F: return "Natural Audio Profile @ Level 2"; case 0x20: return "Natural Audio Profile @ Level 3"; case 0x21: return "Natural Audio Profile @ Level 4"; case 0x22: return "Mobile Audio Internetworking Profile @ Level 1"; case 0x23: return "Mobile Audio Internetworking Profile @ Level 2"; case 0x24: return "Mobile Audio Internetworking Profile @ Level 3"; case 0x25: return "Mobile Audio Internetworking Profile @ Level 4"; case 0x26: return "Mobile Audio Internetworking Profile @ Level 5"; case 0x27: return "Mobile Audio Internetworking Profile @ Level 6"; case 0x28: return "AAC Profile @ Level 1"; case 0x29: return "AAC Profile @ Level 2"; case 0x2A: return "AAC Profile @ Level 4"; case 0x2B: return "AAC Profile @ Level 5"; case 0x2C: return "High Efficiency AAC Profile @ Level 2"; case 0x2D: return "High Efficiency AAC Profile @ Level 3"; case 0x2E: return "High Efficiency AAC Profile @ Level 4"; case 0x2F: return "High Efficiency AAC Profile @ Level 5"; case 0xFE: return "Not part of MPEG-4 audio profiles"; case 0xFF: return "No audio capability required"; default: return "ISO Reserved / User Private"; }}u32 gf_m4a_get_profile(GF_M4ADecSpecInfo *cfg){ switch (cfg->base_object_type) { case 2: /*AAC LC*/ if (cfg->nb_chan<=2) return (cfg->base_sr<=24000) ? 0x28 : 0x29; /*LC@L1 or LC@L2*/ return (cfg->base_sr<=48000) ? 0x2A : 0x2B; /*LC@L4 or LC@L5*/ case 5: /*HE-AAC*/ if (cfg->nb_chan<=2) return (cfg->base_sr<=24000) ? 0x2C : 0x2D; /*HE@L2 or HE@L3*/ return (cfg->base_sr<=48000) ? 0x2E : 0x2F; /*HE@L4 or HE@L5*/ /*default to HQ*/ default: if (cfg->nb_chan<=2) return (cfg->base_sr<24000) ? 0x0E : 0x0F; /*HQ@L1 or HQ@L2*/ return 0x10; /*HQ@L3*/ }}GF_EXPORTGF_Err gf_m4a_get_config(char *dsi, u32 dsi_size, GF_M4ADecSpecInfo *cfg){ GF_BitStream *bs; memset(cfg, 0, sizeof(GF_M4ADecSpecInfo)); if (!dsi || !dsi_size || (dsi_size<2) ) return GF_NON_COMPLIANT_BITSTREAM; bs = gf_bs_new(dsi, dsi_size, GF_BITSTREAM_READ); cfg->base_object_type = gf_bs_read_int(bs, 5); /*extended object type*/ if (cfg->base_object_type==31) { cfg->base_object_type = 32 + gf_bs_read_int(bs, 6); } cfg->base_sr_index = gf_bs_read_int(bs, 4); if (cfg->base_sr_index == 0x0F) { cfg->base_sr = gf_bs_read_int(bs, 24); } else { cfg->base_sr = GF_M4ASampleRates[cfg->base_sr_index]; } cfg->nb_chan = gf_bs_read_int(bs, 4); /*this is 7+1 channels*/ if (cfg->nb_chan==7) cfg->nb_chan=8; if (cfg->base_object_type==5) { cfg->has_sbr = 1; cfg->sbr_sr_index = gf_bs_read_int(bs, 4); if (cfg->sbr_sr_index == 0x0F) { cfg->sbr_sr = gf_bs_read_int(bs, 24); } else { cfg->sbr_sr = GF_M4ASampleRates[cfg->sbr_sr_index]; } cfg->sbr_object_type = gf_bs_read_int(bs, 5); } gf_bs_align(bs); if (gf_bs_available(bs)>=2) { u32 sync = gf_bs_read_int(bs, 11); if (sync==0x2b7) { cfg->sbr_object_type = gf_bs_read_int(bs, 5); cfg->has_sbr = gf_bs_read_int(bs, 1); if (cfg->has_sbr) { cfg->sbr_sr_index = gf_bs_read_int(bs, 4); if (cfg->sbr_sr_index == 0x0F) { cfg->sbr_sr = gf_bs_read_int(bs, 24); } else { cfg->sbr_sr = GF_M4ASampleRates[cfg->sbr_sr_index]; } } } } cfg->audioPL = gf_m4a_get_profile(cfg); gf_bs_del(bs); return GF_OK;}/* MP3 parser credits go to CISCO - MPEG4IP*/GF_EXPORTu8 gf_mp3_version(u32 hdr){ return ((hdr >> 19) & 0x3); }static u8 MP3_GetLayerV(u32 hdr){ return ((hdr >> 17) & 0x3); }GF_EXPORTu8 gf_mp3_layer(u32 hdr){ return 4 - (((hdr >> 17) & 0x3));}GF_EXPORTu8 gf_mp3_num_channels(u32 hdr){ if (((hdr >> 6) & 0x3) == 3) return 1; return 2;}static GFINLINE u32 get_MP3SamplingRates(u32 version, u32 idx) { switch (version) { case 0: switch (idx) { case 0: return 11025; case 1: return 12000; case 2: return 8000; default: return 0; } break; case 1: return 0; case 2: switch (idx) { case 0: return 22050; case 1: return 24000; case 2: return 16000; default: return 0; } break; case 3: switch (idx) { case 0: return 44100; case 1: return 48000; case 2: return 32000; default: return 0; } break; } return 0;}GF_EXPORTu16 gf_mp3_sampling_rate(u32 hdr){ /* extract the necessary fields from the MP3 header */ u8 version = gf_mp3_version(hdr); u8 sampleRateIndex = (hdr >> 10) & 0x3; return get_MP3SamplingRates(version, sampleRateIndex);}GF_EXPORTu16 gf_mp3_window_size(u32 hdr){ u8 version = gf_mp3_version(hdr); u8 layer = MP3_GetLayerV(hdr); if (layer == 1) { if (version == 3) return 1152; return 576; } if (layer == 2) return 1152; return 384;}GF_EXPORTu8 gf_mp3_object_type_indication(u32 hdr){ switch (gf_mp3_version(hdr)) { case 3: return 0x6B; break; case 2: case 0: return 0x69; default: return 0x00; }}GF_EXPORTconst char *gf_mp3_version_name(u32 hdr){ u32 v = gf_mp3_version(hdr); switch (v) { case 0: return "MPEG-2.5"; case 1: return "Reserved"; case 2: return "MPEG-2"; case 3: return "MPEG-1"; default: return "Unknown"; }}static GFINLINE u32 get_MP3BitRates(u32 idx1, u32 idx2) { switch (idx1) { /* MPEG-1, Layer III */ case 0: switch (idx2) { case 0: return 32; case 1: return 40; case 2: return 48; case 3: return 56; case 4: return 64; case 5: return 80; case 6: return 96; case 7: return 112; case 8: return 128; case 9: return 160; case 10: return 192; case 11: return 224; case 12: return 256; case 13: return 320; default: return 0; } break; /* MPEG-1, Layer II */ case 1: switch (idx2) { case 0: return 32; case 1: return 48; case 2: return 56; case 3: return 64; case 4: return 80; case 5: return 96; case 6: return 112; case 7: return 128; case 8: return 160; case 9: return 192; case 10: return 224; case 11: return 256;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -