📄 avc_ext.c
字号:
GF_MPEGVisualSampleEntryBox *entry; trak = gf_isom_get_track_from_file(the_file, trackNumber); if (!trak || !trak->Media || !DescriptionIndex) return NULL; entry = (GF_MPEGVisualSampleEntryBox*)gf_list_get(trak->Media->information->sampleTable->SampleDescription->boxList, DescriptionIndex-1); if (!entry) return NULL; //if (entry->type != GF_ISOM_BOX_TYPE_AVC1) return NULL; if (!entry->avc_config) return NULL; return AVC_DuplicateConfig(entry->avc_config->config);}void btrt_del(GF_Box *s){ GF_MPEG4BitRateBox *ptr = (GF_MPEG4BitRateBox *)s; if (ptr) free(ptr);}GF_Err btrt_Read(GF_Box *s, GF_BitStream *bs){ GF_MPEG4BitRateBox *ptr = (GF_MPEG4BitRateBox *)s; ptr->bufferSizeDB = gf_bs_read_u32(bs); ptr->maxBitrate = gf_bs_read_u32(bs); ptr->avgBitrate = gf_bs_read_u32(bs); return GF_OK;}GF_Box *btrt_New(){ GF_MPEG4BitRateBox *tmp = (GF_MPEG4BitRateBox *) malloc(sizeof(GF_MPEG4BitRateBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_MPEG4BitRateBox)); tmp->type = GF_ISOM_BOX_TYPE_BTRT; return (GF_Box *)tmp;}#ifndef GPAC_READ_ONLYGF_Err btrt_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; GF_MPEG4BitRateBox *ptr = (GF_MPEG4BitRateBox *) s; if (!s) return GF_BAD_PARAM; e = gf_isom_box_write_header(s, bs); if (e) return e; gf_bs_write_u32(bs, ptr->bufferSizeDB); gf_bs_write_u32(bs, ptr->maxBitrate); gf_bs_write_u32(bs, ptr->avgBitrate); return GF_OK;}GF_Err btrt_Size(GF_Box *s){ GF_Err e; GF_MPEG4BitRateBox *ptr = (GF_MPEG4BitRateBox *)s; e = gf_isom_box_get_size(s); ptr->size += 12; return e;}#endifvoid m4ds_del(GF_Box *s){ GF_MPEG4ExtensionDescriptorsBox *ptr = (GF_MPEG4ExtensionDescriptorsBox *)s; gf_odf_desc_list_del(ptr->descriptors); gf_list_del(ptr->descriptors); free(ptr);}GF_Err m4ds_Read(GF_Box *s, GF_BitStream *bs){ GF_Err e; char *enc_od; GF_MPEG4ExtensionDescriptorsBox *ptr = (GF_MPEG4ExtensionDescriptorsBox *)s; u32 od_size = (u32) ptr->size; if (!od_size) return GF_OK; enc_od = (char *)malloc(sizeof(char) * od_size); gf_bs_read_data(bs, enc_od, od_size); e = gf_odf_desc_list_read((char *)enc_od, od_size, ptr->descriptors); free(enc_od); return e;}GF_Box *m4ds_New(){ GF_MPEG4ExtensionDescriptorsBox *tmp = (GF_MPEG4ExtensionDescriptorsBox *) malloc(sizeof(GF_MPEG4ExtensionDescriptorsBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_MPEG4ExtensionDescriptorsBox)); tmp->type = GF_ISOM_BOX_TYPE_M4DS; tmp->descriptors = gf_list_new(); return (GF_Box *)tmp;}#ifndef GPAC_READ_ONLYGF_Err m4ds_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; char *enc_ods; u32 enc_od_size; GF_MPEG4ExtensionDescriptorsBox *ptr = (GF_MPEG4ExtensionDescriptorsBox *) s; if (!s) return GF_BAD_PARAM; e = gf_isom_box_write_header(s, bs); if (e) return e; enc_ods = NULL; enc_od_size = 0; e = gf_odf_desc_list_write(ptr->descriptors, &enc_ods, &enc_od_size); if (e) return e; if (enc_od_size) { gf_bs_write_data(bs, enc_ods, enc_od_size); free(enc_ods); } return GF_OK;}GF_Err m4ds_Size(GF_Box *s){ GF_Err e; u32 descSize; GF_MPEG4ExtensionDescriptorsBox *ptr = (GF_MPEG4ExtensionDescriptorsBox *)s; e = gf_isom_box_get_size(s); if (!e) e = gf_odf_desc_list_size(ptr->descriptors, &descSize); ptr->size += descSize; return e;}#endifvoid avcc_del(GF_Box *s){ GF_AVCConfigurationBox *ptr = (GF_AVCConfigurationBox *)s; if (ptr->config) gf_odf_avc_cfg_del(ptr->config); free(ptr);}GF_Err avcc_Read(GF_Box *s, GF_BitStream *bs){ u32 i, count; GF_AVCConfigurationBox *ptr = (GF_AVCConfigurationBox *)s; if (ptr->config) gf_odf_avc_cfg_del(ptr->config); ptr->config = gf_odf_avc_cfg_new(); ptr->config->configurationVersion = gf_bs_read_u8(bs); ptr->config->AVCProfileIndication = gf_bs_read_u8(bs); ptr->config->profile_compatibility = gf_bs_read_u8(bs); ptr->config->AVCLevelIndication = gf_bs_read_u8(bs); gf_bs_read_int(bs, 6); ptr->config->nal_unit_size = 1 + gf_bs_read_int(bs, 2); gf_bs_read_int(bs, 3); count = gf_bs_read_int(bs, 5); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *) malloc(sizeof(GF_AVCConfigSlot)); sl->size = gf_bs_read_u16(bs); sl->data = (char *)malloc(sizeof(char) * sl->size); gf_bs_read_data(bs, sl->data, sl->size); gf_list_add(ptr->config->sequenceParameterSets, sl); } count = gf_bs_read_u8(bs); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot)); sl->size = gf_bs_read_u16(bs); sl->data = (char *)malloc(sizeof(char) * sl->size); gf_bs_read_data(bs, sl->data, sl->size); gf_list_add(ptr->config->pictureParameterSets, sl); } return GF_OK;}GF_Box *avcc_New(){ GF_AVCConfigurationBox *tmp = (GF_AVCConfigurationBox *) malloc(sizeof(GF_MPEG4BitRateBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_AVCConfigurationBox)); tmp->type = GF_ISOM_BOX_TYPE_AVCC; return (GF_Box *)tmp;}#ifndef GPAC_READ_ONLYGF_Err avcc_Write(GF_Box *s, GF_BitStream *bs){ u32 i, count; GF_Err e; GF_AVCConfigurationBox *ptr = (GF_AVCConfigurationBox *) s; if (!s) return GF_BAD_PARAM; if (!ptr->config) return GF_OK; e = gf_isom_box_write_header(s, bs); if (e) return e; gf_bs_write_u8(bs, ptr->config->configurationVersion); gf_bs_write_u8(bs, ptr->config->AVCProfileIndication); gf_bs_write_u8(bs, ptr->config->profile_compatibility); gf_bs_write_u8(bs, ptr->config->AVCLevelIndication); gf_bs_write_int(bs, 0x3F, 6); gf_bs_write_int(bs, ptr->config->nal_unit_size - 1, 2); gf_bs_write_int(bs, 0x7, 3); count = gf_list_count(ptr->config->sequenceParameterSets); gf_bs_write_int(bs, count, 5); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *) gf_list_get(ptr->config->sequenceParameterSets, i); gf_bs_write_u16(bs, sl->size); gf_bs_write_data(bs, sl->data, sl->size); } count = gf_list_count(ptr->config->pictureParameterSets); gf_bs_write_u8(bs, count); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *) gf_list_get(ptr->config->pictureParameterSets, i); gf_bs_write_u16(bs, sl->size); gf_bs_write_data(bs, sl->data, sl->size); } return GF_OK;}GF_Err avcc_Size(GF_Box *s){ GF_Err e; u32 i, count; GF_AVCConfigurationBox *ptr = (GF_AVCConfigurationBox *)s; e = gf_isom_box_get_size(s); if (e) return e; if (!ptr->config) { ptr->size = 0; return e; } ptr->size += 7; count = gf_list_count(ptr->config->sequenceParameterSets); for (i=0; i<count; i++) ptr->size += 2 + ((GF_AVCConfigSlot *)gf_list_get(ptr->config->sequenceParameterSets, i))->size; count = gf_list_count(ptr->config->pictureParameterSets); for (i=0; i<count; i++) ptr->size += 2 + ((GF_AVCConfigSlot *)gf_list_get(ptr->config->pictureParameterSets, i))->size; return GF_OK;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -