X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fhevc.c;h=057f6517ffe7ef286bfda70adeca5f28e29190e2;hb=7abdd026df6a9a52d07d8174505b33cc89db7bf6;hp=dc45fbfe6230de54cb189aa0129a0b0446118046;hpb=ee17be3fdd37f63f4b77676820e387858908b0f4;p=ffmpeg diff --git a/libavformat/hevc.c b/libavformat/hevc.c index dc45fbfe623..057f6517ffe 100644 --- a/libavformat/hevc.c +++ b/libavformat/hevc.c @@ -18,8 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavcodec/avcodec.h" #include "libavcodec/get_bits.h" -#include "libavcodec/golomb.h" +#include "libavcodec/golomb_legacy.h" #include "libavcodec/hevc.h" #include "libavutil/intreadwrite.h" #include "avc.h" @@ -127,8 +128,8 @@ static void hvcc_parse_ptl(GetBitContext *gb, { unsigned int i; HVCCProfileTierLevel general_ptl; - uint8_t sub_layer_profile_present_flag[MAX_SUB_LAYERS]; - uint8_t sub_layer_level_present_flag[MAX_SUB_LAYERS]; + uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS]; + uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS]; general_ptl.profile_space = get_bits(gb, 2); general_ptl.tier_flag = get_bits1(gb); @@ -411,7 +412,7 @@ static void skip_scaling_list_data(GetBitContext *gb) static int parse_rps(GetBitContext *gb, unsigned int rps_idx, unsigned int num_rps, - unsigned int num_delta_pocs[MAX_SHORT_TERM_RPS_COUNT]) + unsigned int num_delta_pocs[HEVC_MAX_SHORT_TERM_RPS_COUNT]) { unsigned int i; @@ -477,7 +478,7 @@ static int hvcc_parse_sps(GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc) { unsigned int i, sps_max_sub_layers_minus1, log2_max_pic_order_cnt_lsb_minus4; - unsigned int num_short_term_ref_pic_sets, num_delta_pocs[MAX_SHORT_TERM_RPS_COUNT]; + unsigned int num_short_term_ref_pic_sets, num_delta_pocs[HEVC_MAX_SHORT_TERM_RPS_COUNT]; skip_bits(gb, 4); // sps_video_parameter_set_id @@ -547,7 +548,7 @@ static int hvcc_parse_sps(GetBitContext *gb, } num_short_term_ref_pic_sets = get_ue_golomb_long(gb); - if (num_short_term_ref_pic_sets > MAX_SHORT_TERM_RPS_COUNT) + if (num_short_term_ref_pic_sets > HEVC_MAX_SHORT_TERM_RPS_COUNT) return AVERROR_INVALIDDATA; for (i = 0; i < num_short_term_ref_pic_sets; i++) { @@ -636,7 +637,7 @@ static uint8_t *nal_unit_extract_rbsp(const uint8_t *src, uint32_t src_len, uint8_t *dst; uint32_t i, len; - dst = av_malloc(src_len); + dst = av_malloc(src_len + AV_INPUT_BUFFER_PADDING_SIZE); if (!dst) return NULL; @@ -722,7 +723,7 @@ static int hvcc_array_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size, * for all other arrays. When the sample entry name is ‘hev1’, the default * value of array_completeness is 0 for all arrays. */ - if (nal_type == NAL_VPS || nal_type == NAL_SPS || nal_type == NAL_PPS) + if (nal_type == HEVC_NAL_VPS || nal_type == HEVC_NAL_SPS || nal_type == HEVC_NAL_PPS) array->array_completeness = ps_array_completeness; return 0; @@ -756,20 +757,20 @@ static int hvcc_add_nal_unit(uint8_t *nal_buf, uint32_t nal_size, * and non-declarative SEI messages discarded? */ switch (nal_type) { - case NAL_VPS: - case NAL_SPS: - case NAL_PPS: - case NAL_SEI_PREFIX: - case NAL_SEI_SUFFIX: + case HEVC_NAL_VPS: + case HEVC_NAL_SPS: + case HEVC_NAL_PPS: + case HEVC_NAL_SEI_PREFIX: + case HEVC_NAL_SEI_SUFFIX: ret = hvcc_array_add_nal_unit(nal_buf, nal_size, nal_type, ps_array_completeness, hvcc); if (ret < 0) goto end; - else if (nal_type == NAL_VPS) + else if (nal_type == HEVC_NAL_VPS) ret = hvcc_parse_vps(&gbc, hvcc); - else if (nal_type == NAL_SPS) + else if (nal_type == HEVC_NAL_SPS) ret = hvcc_parse_sps(&gbc, hvcc); - else if (nal_type == NAL_PPS) + else if (nal_type == HEVC_NAL_PPS) ret = hvcc_parse_pps(&gbc, hvcc); if (ret < 0) goto end; @@ -799,7 +800,7 @@ static void hvcc_init(HEVCDecoderConfigurationRecord *hvcc) /* * Initialize this field with an invalid value which can be used to detect - * whether we didn't see any VUI (in wich case it should be reset to zero). + * whether we didn't see any VUI (in which case it should be reset to zero). */ hvcc->min_spatial_segmentation_idc = MAX_SPATIAL_SEGMENTATION + 1; } @@ -849,51 +850,51 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc) hvcc->avgFrameRate = 0; hvcc->constantFrameRate = 0; - av_dlog(NULL, "configurationVersion: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n", hvcc->configurationVersion); - av_dlog(NULL, "general_profile_space: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "general_profile_space: %"PRIu8"\n", hvcc->general_profile_space); - av_dlog(NULL, "general_tier_flag: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "general_tier_flag: %"PRIu8"\n", hvcc->general_tier_flag); - av_dlog(NULL, "general_profile_idc: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "general_profile_idc: %"PRIu8"\n", hvcc->general_profile_idc); - av_dlog(NULL, "general_profile_compatibility_flags: 0x%08"PRIx32"\n", + av_log(NULL, AV_LOG_TRACE, "general_profile_compatibility_flags: 0x%08"PRIx32"\n", hvcc->general_profile_compatibility_flags); - av_dlog(NULL, "general_constraint_indicator_flags: 0x%012"PRIx64"\n", + av_log(NULL, AV_LOG_TRACE, "general_constraint_indicator_flags: 0x%012"PRIx64"\n", hvcc->general_constraint_indicator_flags); - av_dlog(NULL, "general_level_idc: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "general_level_idc: %"PRIu8"\n", hvcc->general_level_idc); - av_dlog(NULL, "min_spatial_segmentation_idc: %"PRIu16"\n", + av_log(NULL, AV_LOG_TRACE, "min_spatial_segmentation_idc: %"PRIu16"\n", hvcc->min_spatial_segmentation_idc); - av_dlog(NULL, "parallelismType: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "parallelismType: %"PRIu8"\n", hvcc->parallelismType); - av_dlog(NULL, "chromaFormat: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "chromaFormat: %"PRIu8"\n", hvcc->chromaFormat); - av_dlog(NULL, "bitDepthLumaMinus8: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "bitDepthLumaMinus8: %"PRIu8"\n", hvcc->bitDepthLumaMinus8); - av_dlog(NULL, "bitDepthChromaMinus8: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "bitDepthChromaMinus8: %"PRIu8"\n", hvcc->bitDepthChromaMinus8); - av_dlog(NULL, "avgFrameRate: %"PRIu16"\n", + av_log(NULL, AV_LOG_TRACE, "avgFrameRate: %"PRIu16"\n", hvcc->avgFrameRate); - av_dlog(NULL, "constantFrameRate: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "constantFrameRate: %"PRIu8"\n", hvcc->constantFrameRate); - av_dlog(NULL, "numTemporalLayers: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "numTemporalLayers: %"PRIu8"\n", hvcc->numTemporalLayers); - av_dlog(NULL, "temporalIdNested: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "temporalIdNested: %"PRIu8"\n", hvcc->temporalIdNested); - av_dlog(NULL, "lengthSizeMinusOne: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "lengthSizeMinusOne: %"PRIu8"\n", hvcc->lengthSizeMinusOne); - av_dlog(NULL, "numOfArrays: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "numOfArrays: %"PRIu8"\n", hvcc->numOfArrays); for (i = 0; i < hvcc->numOfArrays; i++) { - av_dlog(NULL, "array_completeness[%"PRIu8"]: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "array_completeness[%"PRIu8"]: %"PRIu8"\n", i, hvcc->array[i].array_completeness); - av_dlog(NULL, "NAL_unit_type[%"PRIu8"]: %"PRIu8"\n", + av_log(NULL, AV_LOG_TRACE, "NAL_unit_type[%"PRIu8"]: %"PRIu8"\n", i, hvcc->array[i].NAL_unit_type); - av_dlog(NULL, "numNalus[%"PRIu8"]: %"PRIu16"\n", + av_log(NULL, AV_LOG_TRACE, "numNalus[%"PRIu8"]: %"PRIu16"\n", i, hvcc->array[i].numNalus); for (j = 0; j < hvcc->array[i].numNalus; j++) - av_dlog(NULL, + av_log(NULL, AV_LOG_TRACE, "nalUnitLength[%"PRIu8"][%"PRIu16"]: %"PRIu16"\n", i, j, hvcc->array[i].nalUnitLength[j]); } @@ -903,21 +904,21 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc) */ for (i = 0; i < hvcc->numOfArrays; i++) switch (hvcc->array[i].NAL_unit_type) { - case NAL_VPS: + case HEVC_NAL_VPS: vps_count += hvcc->array[i].numNalus; break; - case NAL_SPS: + case HEVC_NAL_SPS: sps_count += hvcc->array[i].numNalus; break; - case NAL_PPS: + case HEVC_NAL_PPS: pps_count += hvcc->array[i].numNalus; break; default: break; } - if (!vps_count || vps_count > MAX_VPS_COUNT || - !sps_count || sps_count > MAX_SPS_COUNT || - !pps_count || pps_count > MAX_PPS_COUNT) + if (!vps_count || vps_count > HEVC_MAX_VPS_COUNT || + !sps_count || sps_count > HEVC_MAX_SPS_COUNT || + !pps_count || pps_count > HEVC_MAX_PPS_COUNT) return AVERROR_INVALIDDATA; /* unsigned int(8) configurationVersion = 1; */ @@ -1040,9 +1041,9 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in, buf += 4; switch (type) { - case NAL_VPS: - case NAL_SPS: - case NAL_PPS: + case HEVC_NAL_VPS: + case HEVC_NAL_SPS: + case HEVC_NAL_PPS: num_ps++; break; default: @@ -1056,7 +1057,7 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in, } end: - free(start); + av_free(start); if (ps_count) *ps_count = num_ps; return ret; @@ -1066,52 +1067,15 @@ int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out, int *size, int filter_ps, int *ps_count) { AVIOContext *pb; - int num_ps = 0, ret = 0; - uint8_t *buf, *end, *start = NULL; - - if (!filter_ps) { - ret = ff_avc_parse_nal_units_buf(buf_in, buf_out, size); - goto end; - } + int ret; ret = avio_open_dyn_buf(&pb); if (ret < 0) - goto end; - - ret = ff_avc_parse_nal_units_buf(buf_in, &start, size); - if (ret < 0) - goto end; - - buf = start; - end = start + *size; - - while (end - buf > 4) { - uint32_t len = FFMIN(AV_RB32(buf), end - buf - 4); - uint8_t type = (buf[4] >> 1) & 0x3f; - - buf += 4; - - switch (type) { - case NAL_VPS: - case NAL_SPS: - case NAL_PPS: - num_ps++; - break; - default: - avio_wb32(pb, len); - avio_write(pb, buf, len); - break; - } - - buf += len; - } + return ret; + ret = ff_hevc_annexb2mp4(pb, buf_in, *size, filter_ps, ps_count); *size = avio_close_dyn_buf(pb, buf_out); -end: - free(start); - if (ps_count) - *ps_count = num_ps; return ret; } @@ -1152,11 +1116,11 @@ int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, buf += 4; switch (type) { - case NAL_VPS: - case NAL_SPS: - case NAL_PPS: - case NAL_SEI_PREFIX: - case NAL_SEI_SUFFIX: + case HEVC_NAL_VPS: + case HEVC_NAL_SPS: + case HEVC_NAL_PPS: + case HEVC_NAL_SEI_PREFIX: + case HEVC_NAL_SEI_SUFFIX: ret = hvcc_add_nal_unit(buf, len, ps_array_completeness, &hvcc); if (ret < 0) goto end;