From c359d624d3efc3fd1d83210d78c4152bd329b765 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 21 Aug 2016 17:35:28 +0200 Subject: hevcdec: move decoder-independent declarations into a separate header This way they can be reused by other code without including the whole decoder-specific hevcdec.h Also, add the HEVC_ prefix to them, since similarly named values exist for H.264 as well and are sometimes used in the same code. --- libavcodec/hevc.h | 65 +++++++++++++++++++++++++++++++++ libavcodec/hevc_mp4toannexb_bsf.c | 6 +-- libavcodec/hevc_parser.c | 51 +++++++++++++------------- libavcodec/hevc_ps.c | 16 ++++---- libavcodec/hevc_refs.c | 7 ++-- libavcodec/hevc_sei.c | 2 +- libavcodec/hevcdec.c | 77 ++++++++++++++++++++------------------- libavcodec/hevcdec.h | 74 +++++++++---------------------------- libavcodec/qsvenc_hevc.c | 11 +++--- libavcodec/vaapi_encode_h265.c | 22 +++++------ 10 files changed, 180 insertions(+), 151 deletions(-) create mode 100644 libavcodec/hevc.h (limited to 'libavcodec') diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h new file mode 100644 index 0000000000..66816b8409 --- /dev/null +++ b/libavcodec/hevc.h @@ -0,0 +1,65 @@ +/* + * HEVC shared code + * + * This file is part of Libav. + * + * Libav 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.1 of the License, or (at your option) any later version. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_HEVC_H +#define AVCODEC_HEVC_H + +/** + * Table 7-3: NAL unit type codes + */ +enum HEVCNALUnitType { + HEVC_NAL_TRAIL_N = 0, + HEVC_NAL_TRAIL_R = 1, + HEVC_NAL_TSA_N = 2, + HEVC_NAL_TSA_R = 3, + HEVC_NAL_STSA_N = 4, + HEVC_NAL_STSA_R = 5, + HEVC_NAL_RADL_N = 6, + HEVC_NAL_RADL_R = 7, + HEVC_NAL_RASL_N = 8, + HEVC_NAL_RASL_R = 9, + HEVC_NAL_BLA_W_LP = 16, + HEVC_NAL_BLA_W_RADL = 17, + HEVC_NAL_BLA_N_LP = 18, + HEVC_NAL_IDR_W_RADL = 19, + HEVC_NAL_IDR_N_LP = 20, + HEVC_NAL_CRA_NUT = 21, + HEVC_NAL_VPS = 32, + HEVC_NAL_SPS = 33, + HEVC_NAL_PPS = 34, + HEVC_NAL_AUD = 35, + HEVC_NAL_EOS_NUT = 36, + HEVC_NAL_EOB_NUT = 37, + HEVC_NAL_FD_NUT = 38, + HEVC_NAL_SEI_PREFIX = 39, + HEVC_NAL_SEI_SUFFIX = 40, +}; + +/** + * 7.4.2.1 + */ +#define HEVC_MAX_SUB_LAYERS 7 +#define HEVC_MAX_VPS_COUNT 16 +#define HEVC_MAX_SPS_COUNT 32 +#define HEVC_MAX_PPS_COUNT 256 +#define HEVC_MAX_SHORT_TERM_RPS_COUNT 64 +#define HEVC_MAX_CU_SIZE 128 + +#endif /* AVCODEC_HEVC_H */ diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index f364fbd161..d6b1f00047 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -27,7 +27,7 @@ #include "avcodec.h" #include "bsf.h" #include "bytestream.h" -#include "hevcdec.h" +#include "hevc.h" #define MIN_HEVCC_LENGTH 23 @@ -55,8 +55,8 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) int type = bytestream2_get_byte(&gb) & 0x3f; int cnt = bytestream2_get_be16(&gb); - if (!(type == NAL_VPS || type == NAL_SPS || type == NAL_PPS || - type == NAL_SEI_PREFIX || type == NAL_SEI_SUFFIX)) { + if (!(type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS || + type == HEVC_NAL_SEI_PREFIX || type == HEVC_NAL_SEI_SUFFIX)) { av_log(ctx, AV_LOG_ERROR, "Invalid NAL unit type in extradata: %d\n", type); ret = AVERROR_INVALIDDATA; diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index b68ceb985e..49e712269b 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -23,6 +23,7 @@ #include "libavutil/common.h" #include "golomb.h" +#include "hevc.h" #include "hevcdec.h" #include "h2645_parse.h" #include "parser.h" @@ -55,7 +56,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, get_bits1(gb); // no output of prior pics pps_id = get_ue_golomb_long(gb); - if (pps_id >= MAX_PPS_COUNT || !ctx->ps.pps_list[pps_id]) { + if (pps_id >= HEVC_MAX_PPS_COUNT || !ctx->ps.pps_list[pps_id]) { av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); return AVERROR_INVALIDDATA; } @@ -92,25 +93,25 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, /* ignore everything except parameter sets and VCL NALUs */ switch (nal->type) { - case NAL_VPS: ff_hevc_decode_nal_vps(&nal->gb, avctx, &ctx->ps); break; - case NAL_SPS: ff_hevc_decode_nal_sps(&nal->gb, avctx, &ctx->ps, 1); break; - case NAL_PPS: ff_hevc_decode_nal_pps(&nal->gb, avctx, &ctx->ps); break; - case NAL_TRAIL_R: - case NAL_TRAIL_N: - case NAL_TSA_N: - case NAL_TSA_R: - case NAL_STSA_N: - case NAL_STSA_R: - case NAL_BLA_W_LP: - case NAL_BLA_W_RADL: - case NAL_BLA_N_LP: - case NAL_IDR_W_RADL: - case NAL_IDR_N_LP: - case NAL_CRA_NUT: - case NAL_RADL_N: - case NAL_RADL_R: - case NAL_RASL_N: - case NAL_RASL_R: hevc_parse_slice_header(s, nal, avctx); break; + case HEVC_NAL_VPS: ff_hevc_decode_nal_vps(&nal->gb, avctx, &ctx->ps); break; + case HEVC_NAL_SPS: ff_hevc_decode_nal_sps(&nal->gb, avctx, &ctx->ps, 1); break; + case HEVC_NAL_PPS: ff_hevc_decode_nal_pps(&nal->gb, avctx, &ctx->ps); break; + case HEVC_NAL_TRAIL_R: + case HEVC_NAL_TRAIL_N: + case HEVC_NAL_TSA_N: + case HEVC_NAL_TSA_R: + case HEVC_NAL_STSA_N: + case HEVC_NAL_STSA_R: + case HEVC_NAL_BLA_W_LP: + case HEVC_NAL_BLA_W_RADL: + case HEVC_NAL_BLA_N_LP: + case HEVC_NAL_IDR_W_RADL: + case HEVC_NAL_IDR_N_LP: + case HEVC_NAL_CRA_NUT: + case HEVC_NAL_RADL_N: + case HEVC_NAL_RADL_R: + case HEVC_NAL_RASL_N: + case HEVC_NAL_RASL_R: hevc_parse_slice_header(s, nal, avctx); break; } } @@ -138,19 +139,19 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, nut = (pc->state64 >> 2 * 8 + 1) & 0x3F; // Beginning of access unit - if ((nut >= NAL_VPS && nut <= NAL_AUD) || nut == NAL_SEI_PREFIX || + if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_AUD) || nut == HEVC_NAL_SEI_PREFIX || (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) { if (pc->frame_start_found) { pc->frame_start_found = 0; return i - 5; } - } else if (nut <= NAL_RASL_R || - (nut >= NAL_BLA_W_LP && nut <= NAL_CRA_NUT)) { + } else if (nut <= HEVC_NAL_RASL_R || + (nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) { int first_slice_segment_in_pic_flag = buf[i] >> 7; if (first_slice_segment_in_pic_flag) { if (!pc->frame_start_found) { pc->frame_start_found = 1; - s->key_frame = nut >= NAL_BLA_W_LP && nut <= NAL_CRA_NUT; + s->key_frame = nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT; } else { // First slice of next frame found pc->frame_start_found = 0; return i - 5; @@ -205,7 +206,7 @@ static int hevc_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size) state = (state << 8) | buf[i]; if (((state >> 8) & 0xFFFFFF) == START_CODE) { int nut = (state >> 1) & 0x3F; - if (nut >= NAL_VPS && nut <= NAL_PPS) + if (nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_PPS) has_ps = 1; else if (has_ps) return i - 3; diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index b7b2ea9251..520017bc6e 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -370,7 +370,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); vps_id = get_bits(gb, 4); - if (vps_id >= MAX_VPS_COUNT) { + if (vps_id >= HEVC_MAX_VPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", vps_id); goto err; } @@ -389,7 +389,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, goto err; } - if (vps->vps_max_sub_layers > MAX_SUB_LAYERS) { + if (vps->vps_max_sub_layers > HEVC_MAX_SUB_LAYERS) { av_log(avctx, AV_LOG_ERROR, "vps_max_sub_layers out of range: %d\n", vps->vps_max_sub_layers); goto err; @@ -690,7 +690,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, // Coded parameters sps->vps_id = get_bits(gb, 4); - if (sps->vps_id >= MAX_VPS_COUNT) { + if (sps->vps_id >= HEVC_MAX_VPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "VPS id out of range: %d\n", sps->vps_id); ret = AVERROR_INVALIDDATA; goto err; @@ -704,7 +704,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, } sps->max_sub_layers = get_bits(gb, 3) + 1; - if (sps->max_sub_layers > MAX_SUB_LAYERS) { + if (sps->max_sub_layers > HEVC_MAX_SUB_LAYERS) { av_log(avctx, AV_LOG_ERROR, "sps_max_sub_layers out of range: %d\n", sps->max_sub_layers); ret = AVERROR_INVALIDDATA; @@ -716,7 +716,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, parse_ptl(gb, avctx, &sps->ptl, sps->max_sub_layers); *sps_id = get_ue_golomb_long(gb); - if (*sps_id >= MAX_SPS_COUNT) { + if (*sps_id >= HEVC_MAX_SPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", *sps_id); ret = AVERROR_INVALIDDATA; goto err; @@ -867,7 +867,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, } sps->nb_st_rps = get_ue_golomb_long(gb); - if (sps->nb_st_rps > MAX_SHORT_TERM_RPS_COUNT) { + if (sps->nb_st_rps > HEVC_MAX_SHORT_TERM_RPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "Too many short term RPS: %d.\n", sps->nb_st_rps); ret = AVERROR_INVALIDDATA; @@ -1205,13 +1205,13 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, // Coded parameters pps_id = get_ue_golomb_long(gb); - if (pps_id >= MAX_PPS_COUNT) { + if (pps_id >= HEVC_MAX_PPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); ret = AVERROR_INVALIDDATA; goto err; } pps->sps_id = get_ue_golomb_long(gb); - if (pps->sps_id >= MAX_SPS_COUNT) { + if (pps->sps_id >= HEVC_MAX_SPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index 3e056da0a9..82a1157887 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -26,6 +26,7 @@ #include "internal.h" #include "thread.h" +#include "hevc.h" #include "hevcdec.h" void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) @@ -477,9 +478,9 @@ int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb) poc_msb = prev_poc_msb; // For BLA picture types, POCmsb is set to 0. - if (s->nal_unit_type == NAL_BLA_W_LP || - s->nal_unit_type == NAL_BLA_W_RADL || - s->nal_unit_type == NAL_BLA_N_LP) + if (s->nal_unit_type == HEVC_NAL_BLA_W_LP || + s->nal_unit_type == HEVC_NAL_BLA_W_RADL || + s->nal_unit_type == HEVC_NAL_BLA_N_LP) poc_msb = 0; return poc_msb + poc_lsb; diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index 37c80647d6..8865cecded 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -168,7 +168,7 @@ static int decode_nal_sei_message(HEVCContext *s) byte = get_bits(gb, 8); payload_size += byte; } - if (s->nal_unit_type == NAL_SEI_PREFIX) { + if (s->nal_unit_type == HEVC_NAL_SEI_PREFIX) { return decode_nal_sei_prefix(s, payload_type, payload_size); } else { /* nal_unit_type == NAL_SEI_SUFFIX */ return decode_nal_sei_suffix(s, payload_type, payload_size); diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 2afd638723..1da43344a4 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -36,6 +36,7 @@ #include "bytestream.h" #include "cabac_functions.h" #include "golomb.h" +#include "hevc.h" #include "hevcdec.h" #include "profiles.h" @@ -461,7 +462,7 @@ static int hls_slice_header(HEVCContext *s) sh->no_output_of_prior_pics_flag = get_bits1(gb); sh->pps_id = get_ue_golomb_long(gb); - if (sh->pps_id >= MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) { + if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) { av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", sh->pps_id); return AVERROR_INVALIDDATA; } @@ -594,13 +595,13 @@ static int hls_slice_header(HEVCContext *s) /* 8.3.1 */ if (s->temporal_id == 0 && - s->nal_unit_type != NAL_TRAIL_N && - s->nal_unit_type != NAL_TSA_N && - s->nal_unit_type != NAL_STSA_N && - s->nal_unit_type != NAL_RADL_N && - s->nal_unit_type != NAL_RADL_R && - s->nal_unit_type != NAL_RASL_N && - s->nal_unit_type != NAL_RASL_R) + s->nal_unit_type != HEVC_NAL_TRAIL_N && + s->nal_unit_type != HEVC_NAL_TSA_N && + s->nal_unit_type != HEVC_NAL_STSA_N && + s->nal_unit_type != HEVC_NAL_RADL_N && + s->nal_unit_type != HEVC_NAL_RADL_R && + s->nal_unit_type != HEVC_NAL_RASL_N && + s->nal_unit_type != HEVC_NAL_RASL_R) s->pocTid0 = s->poc; if (s->ps.sps->sao_enabled) { @@ -2455,50 +2456,50 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) s->temporal_id = nal->temporal_id; switch (s->nal_unit_type) { - case NAL_VPS: + case HEVC_NAL_VPS: ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps); if (ret < 0) goto fail; break; - case NAL_SPS: + case HEVC_NAL_SPS: ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps, s->apply_defdispwin); if (ret < 0) goto fail; break; - case NAL_PPS: + case HEVC_NAL_PPS: ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps); if (ret < 0) goto fail; break; - case NAL_SEI_PREFIX: - case NAL_SEI_SUFFIX: + case HEVC_NAL_SEI_PREFIX: + case HEVC_NAL_SEI_SUFFIX: ret = ff_hevc_decode_nal_sei(s); if (ret < 0) goto fail; break; - case NAL_TRAIL_R: - case NAL_TRAIL_N: - case NAL_TSA_N: - case NAL_TSA_R: - case NAL_STSA_N: - case NAL_STSA_R: - case NAL_BLA_W_LP: - case NAL_BLA_W_RADL: - case NAL_BLA_N_LP: - case NAL_IDR_W_RADL: - case NAL_IDR_N_LP: - case NAL_CRA_NUT: - case NAL_RADL_N: - case NAL_RADL_R: - case NAL_RASL_N: - case NAL_RASL_R: + case HEVC_NAL_TRAIL_R: + case HEVC_NAL_TRAIL_N: + case HEVC_NAL_TSA_N: + case HEVC_NAL_TSA_R: + case HEVC_NAL_STSA_N: + case HEVC_NAL_STSA_R: + case HEVC_NAL_BLA_W_LP: + case HEVC_NAL_BLA_W_RADL: + case HEVC_NAL_BLA_N_LP: + case HEVC_NAL_IDR_W_RADL: + case HEVC_NAL_IDR_N_LP: + case HEVC_NAL_CRA_NUT: + case HEVC_NAL_RADL_N: + case HEVC_NAL_RADL_R: + case HEVC_NAL_RASL_N: + case HEVC_NAL_RASL_R: ret = hls_slice_header(s); if (ret < 0) return ret; if (s->max_ra == INT_MAX) { - if (s->nal_unit_type == NAL_CRA_NUT || IS_BLA(s)) { + if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) { s->max_ra = s->poc; } else { if (IS_IDR(s)) @@ -2506,12 +2507,12 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) } } - if ((s->nal_unit_type == NAL_RASL_R || s->nal_unit_type == NAL_RASL_N) && + if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && s->poc <= s->max_ra) { s->is_decoded = 0; break; } else { - if (s->nal_unit_type == NAL_RASL_R && s->poc > s->max_ra) + if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra) s->max_ra = INT_MIN; } @@ -2567,13 +2568,13 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) } } break; - case NAL_EOS_NUT: - case NAL_EOB_NUT: + case HEVC_NAL_EOS_NUT: + case HEVC_NAL_EOB_NUT: s->seq_decode = (s->seq_decode + 1) & 0xff; s->max_ra = INT_MAX; break; - case NAL_AUD: - case NAL_FD_NUT: + case HEVC_NAL_AUD: + case HEVC_NAL_FD_NUT: break; default: av_log(s->avctx, AV_LOG_INFO, @@ -2605,8 +2606,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) } for (i = 0; i < s->pkt.nb_nals; i++) { - if (s->pkt.nals[i].type == NAL_EOB_NUT || - s->pkt.nals[i].type == NAL_EOS_NUT) + if (s->pkt.nals[i].type == HEVC_NAL_EOB_NUT || + s->pkt.nals[i].type == HEVC_NAL_EOS_NUT) s->eos = 1; } diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index ba261e6fec..df81e55ed8 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -34,6 +34,7 @@ #include "cabac.h" #include "get_bits.h" #include "h2645_parse.h" +#include "hevc.h" #include "hevcdsp.h" #include "internal.h" #include "thread.h" @@ -42,16 +43,6 @@ #define MAX_DPB_SIZE 16 // A.4.1 #define MAX_REFS 16 -/** - * 7.4.2.1 - */ -#define MAX_SUB_LAYERS 7 -#define MAX_VPS_COUNT 16 -#define MAX_SPS_COUNT 32 -#define MAX_PPS_COUNT 256 -#define MAX_SHORT_TERM_RPS_COUNT 64 -#define MAX_CU_SIZE 128 - //TODO: check if this is really the maximum #define MAX_TRANSFORM_DEPTH 5 @@ -80,45 +71,14 @@ #define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)]) #define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)]) -#define IS_IDR(s) (s->nal_unit_type == NAL_IDR_W_RADL || s->nal_unit_type == NAL_IDR_N_LP) -#define IS_BLA(s) (s->nal_unit_type == NAL_BLA_W_RADL || s->nal_unit_type == NAL_BLA_W_LP || \ - s->nal_unit_type == NAL_BLA_N_LP) +#define IS_IDR(s) (s->nal_unit_type == HEVC_NAL_IDR_W_RADL || s->nal_unit_type == HEVC_NAL_IDR_N_LP) +#define IS_BLA(s) (s->nal_unit_type == HEVC_NAL_BLA_W_RADL || s->nal_unit_type == HEVC_NAL_BLA_W_LP || \ + s->nal_unit_type == HEVC_NAL_BLA_N_LP) #define IS_IRAP(s) (s->nal_unit_type >= 16 && s->nal_unit_type <= 23) #define FFUDIV(a,b) (((a) > 0 ? (a) : (a) - (b) + 1) / (b)) #define FFUMOD(a,b) ((a) - (b) * FFUDIV(a,b)) -/** - * Table 7-3: NAL unit type codes - */ -enum NALUnitType { - NAL_TRAIL_N = 0, - NAL_TRAIL_R = 1, - NAL_TSA_N = 2, - NAL_TSA_R = 3, - NAL_STSA_N = 4, - NAL_STSA_R = 5, - NAL_RADL_N = 6, - NAL_RADL_R = 7, - NAL_RASL_N = 8, - NAL_RASL_R = 9, - NAL_BLA_W_LP = 16, - NAL_BLA_W_RADL = 17, - NAL_BLA_N_LP = 18, - NAL_IDR_W_RADL = 19, - NAL_IDR_N_LP = 20, - NAL_CRA_NUT = 21, - NAL_VPS = 32, - NAL_SPS = 33, - NAL_PPS = 34, - NAL_AUD = 35, - NAL_EOS_NUT = 36, - NAL_EOB_NUT = 37, - NAL_FD_NUT = 38, - NAL_SEI_PREFIX = 39, - NAL_SEI_SUFFIX = 40, -}; - enum RPSType { ST_CURR_BEF = 0, ST_CURR_AFT, @@ -349,10 +309,10 @@ typedef struct PTLCommon { typedef struct PTL { PTLCommon general_ptl; - PTLCommon sub_layer_ptl[MAX_SUB_LAYERS]; + PTLCommon sub_layer_ptl[HEVC_MAX_SUB_LAYERS]; - 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]; } PTL; typedef struct HEVCVPS { @@ -362,9 +322,9 @@ typedef struct HEVCVPS { PTL ptl; int vps_sub_layer_ordering_info_present_flag; - unsigned int vps_max_dec_pic_buffering[MAX_SUB_LAYERS]; - unsigned int vps_num_reorder_pics[MAX_SUB_LAYERS]; - unsigned int vps_max_latency_increase[MAX_SUB_LAYERS]; + unsigned int vps_max_dec_pic_buffering[HEVC_MAX_SUB_LAYERS]; + unsigned int vps_num_reorder_pics[HEVC_MAX_SUB_LAYERS]; + unsigned int vps_max_latency_increase[HEVC_MAX_SUB_LAYERS]; int vps_max_layer_id; int vps_num_layer_sets; ///< vps_num_layer_sets_minus1 + 1 uint8_t vps_timing_info_present_flag; @@ -405,7 +365,7 @@ typedef struct HEVCSPS { int max_dec_pic_buffering; int num_reorder_pics; int max_latency_increase; - } temporal_layer[MAX_SUB_LAYERS]; + } temporal_layer[HEVC_MAX_SUB_LAYERS]; VUI vui; PTL ptl; @@ -414,7 +374,7 @@ typedef struct HEVCSPS { ScalingList scaling_list; unsigned int nb_st_rps; - ShortTermRPS st_rps[MAX_SHORT_TERM_RPS_COUNT]; + ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT]; uint8_t amp_enabled_flag; uint8_t sao_enabled; @@ -528,9 +488,9 @@ typedef struct HEVCPPS { } HEVCPPS; typedef struct HEVCParamSets { - AVBufferRef *vps_list[MAX_VPS_COUNT]; - AVBufferRef *sps_list[MAX_SPS_COUNT]; - AVBufferRef *pps_list[MAX_PPS_COUNT]; + AVBufferRef *vps_list[HEVC_MAX_VPS_COUNT]; + AVBufferRef *sps_list[HEVC_MAX_SPS_COUNT]; + AVBufferRef *pps_list[HEVC_MAX_PPS_COUNT]; /* currently active parameter sets */ const HEVCVPS *vps; @@ -783,7 +743,7 @@ typedef struct HEVCContext { SliceHeader sh; SAOParams *sao; DBParams *deblock; - enum NALUnitType nal_unit_type; + enum HEVCNALUnitType nal_unit_type; int temporal_id; ///< temporal_id_plus1 - 1 HEVCFrame *ref; HEVCFrame DPB[32]; @@ -832,7 +792,7 @@ typedef struct HEVCContext { H2645Packet pkt; // type of the first VCL NAL of the current frame - enum NALUnitType first_nal_type; + enum HEVCNALUnitType first_nal_type; // for checking the frame checksums struct AVMD5 *md5_ctx; diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index 24af82c8c5..c51309f9c6 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -30,6 +30,7 @@ #include "avcodec.h" #include "bytestream.h" #include "get_bits.h" +#include "hevc.h" #include "hevcdec.h" #include "h2645_parse.h" #include "internal.h" @@ -83,7 +84,7 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) get_bits(&gb, 1); type = get_bits(&gb, 6); - if (type != NAL_SPS) { + if (type != HEVC_NAL_SPS) { av_log(avctx, AV_LOG_ERROR, "Unexpected NAL type in the extradata: %d\n", type); av_freep(&sps_nal.rbsp_buffer); @@ -103,7 +104,7 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) vps.vps_max_sub_layers = sps.max_sub_layers; memcpy(&vps.ptl, &sps.ptl, sizeof(vps.ptl)); vps.vps_sub_layer_ordering_info_present_flag = 1; - for (i = 0; i < MAX_SUB_LAYERS; i++) { + for (i = 0; i < HEVC_MAX_SUB_LAYERS; i++) { vps.vps_max_dec_pic_buffering[i] = sps.temporal_layer[i].max_dec_pic_buffering; vps.vps_num_reorder_pics[i] = sps.temporal_layer[i].num_reorder_pics; vps.vps_max_latency_increase[i] = sps.temporal_layer[i].max_latency_increase; @@ -127,9 +128,9 @@ static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx) bytestream2_init(&gbc, vps_rbsp_buf, ret); bytestream2_init_writer(&pbc, vps_buf, sizeof(vps_buf)); - bytestream2_put_be32(&pbc, 1); // startcode - bytestream2_put_byte(&pbc, NAL_VPS << 1); // NAL - bytestream2_put_byte(&pbc, 1); // header + bytestream2_put_be32(&pbc, 1); // startcode + bytestream2_put_byte(&pbc, HEVC_NAL_VPS << 1); // NAL + bytestream2_put_byte(&pbc, 1); // header while (bytestream2_get_bytes_left(&gbc)) { uint32_t b = bytestream2_peek_be24(&gbc); diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 4853a5bbeb..776c228dd8 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -25,7 +25,7 @@ #include "libavutil/pixfmt.h" #include "avcodec.h" -#include "hevcdec.h" +#include "hevc.h" #include "internal.h" #include "put_bits.h" #include "vaapi_encode.h" @@ -275,7 +275,7 @@ static void vaapi_encode_h265_write_vps(PutBitContext *pbc, VAAPIEncodeH265MiscSequenceParams *mseq = &priv->misc_sequence_params; int i, j; - vaapi_encode_h265_write_nal_unit_header(pbc, NAL_VPS); + vaapi_encode_h265_write_nal_unit_header(pbc, HEVC_NAL_VPS); u(4, mseq->video_parameter_set_id, vps_video_parameter_set_id); @@ -395,7 +395,7 @@ static void vaapi_encode_h265_write_sps(PutBitContext *pbc, VAAPIEncodeH265MiscSequenceParams *mseq = &priv->misc_sequence_params; int i; - vaapi_encode_h265_write_nal_unit_header(pbc, NAL_SPS); + vaapi_encode_h265_write_nal_unit_header(pbc, HEVC_NAL_SPS); u(4, mseq->video_parameter_set_id, sps_video_parameter_set_id); @@ -491,7 +491,7 @@ static void vaapi_encode_h265_write_pps(PutBitContext *pbc, VAAPIEncodeH265MiscSequenceParams *mseq = &priv->misc_sequence_params; int i; - vaapi_encode_h265_write_nal_unit_header(pbc, NAL_PPS); + vaapi_encode_h265_write_nal_unit_header(pbc, HEVC_NAL_PPS); ue(vpic->slice_pic_parameter_set_id, pps_pic_parameter_set_id); ue(mseq->seq_parameter_set_id, pps_seq_parameter_set_id); @@ -576,7 +576,7 @@ static void vaapi_encode_h265_write_slice_header2(PutBitContext *pbc, vaapi_encode_h265_write_nal_unit_header(pbc, vpic->nal_unit_type); u(1, mslice_var(first_slice_segment_in_pic_flag)); - if (vpic->nal_unit_type >= NAL_BLA_W_LP && + if (vpic->nal_unit_type >= HEVC_NAL_BLA_W_LP && vpic->nal_unit_type <= 23) u(1, mslice_var(no_output_of_prior_pics_flag)); @@ -597,8 +597,8 @@ static void vaapi_encode_h265_write_slice_header2(PutBitContext *pbc, u(1, 1, pic_output_flag); if (vseq->seq_fields.bits.separate_colour_plane_flag) u(2, vslice_field(colour_plane_id)); - if (vpic->nal_unit_type != NAL_IDR_W_RADL && - vpic->nal_unit_type != NAL_IDR_N_LP) { + if (vpic->nal_unit_type != HEVC_NAL_IDR_W_RADL && + vpic->nal_unit_type != HEVC_NAL_IDR_N_LP) { u(4 + mseq->log2_max_pic_order_cnt_lsb_minus4, (pslice->pic_order_cnt & ((1 << (mseq->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1)), @@ -998,25 +998,25 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, switch (pic->type) { case PICTURE_TYPE_IDR: - vpic->nal_unit_type = NAL_IDR_W_RADL; + vpic->nal_unit_type = HEVC_NAL_IDR_W_RADL; vpic->pic_fields.bits.idr_pic_flag = 1; vpic->pic_fields.bits.coding_type = 1; vpic->pic_fields.bits.reference_pic_flag = 1; break; case PICTURE_TYPE_I: - vpic->nal_unit_type = NAL_TRAIL_R; + vpic->nal_unit_type = HEVC_NAL_TRAIL_R; vpic->pic_fields.bits.idr_pic_flag = 0; vpic->pic_fields.bits.coding_type = 1; vpic->pic_fields.bits.reference_pic_flag = 1; break; case PICTURE_TYPE_P: - vpic->nal_unit_type = NAL_TRAIL_R; + vpic->nal_unit_type = HEVC_NAL_TRAIL_R; vpic->pic_fields.bits.idr_pic_flag = 0; vpic->pic_fields.bits.coding_type = 2; vpic->pic_fields.bits.reference_pic_flag = 1; break; case PICTURE_TYPE_B: - vpic->nal_unit_type = NAL_TRAIL_R; + vpic->nal_unit_type = HEVC_NAL_TRAIL_R; vpic->pic_fields.bits.idr_pic_flag = 0; vpic->pic_fields.bits.coding_type = 3; vpic->pic_fields.bits.reference_pic_flag = 0; -- cgit v1.2.3