1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit '064698d381e1e7790f21b0199a8930ea04e2e942'

* commit '064698d381e1e7790f21b0199a8930ea04e2e942':
  Add HEVC decoder

Conflicts:
	Changelog
	libavcodec/Makefile
	libavcodec/allcodecs.c
	libavcodec/hevc.c
	libavcodec/hevc.h
	libavcodec/hevc_cabac.c
	libavcodec/hevc_filter.c
	libavcodec/hevc_mvs.c
	libavcodec/hevc_parser.c
	libavcodec/hevc_ps.c
	libavcodec/hevc_refs.c
	libavcodec/hevc_sei.c
	libavcodec/hevcdsp.c
	libavcodec/hevcdsp_template.c
	libavcodec/hevcpred.c
	libavcodec/hevcpred_template.c
	libavcodec/version.h

cosmetics from hevc.h & hevc_ps.c mostly merged, other files left as they where in ffmpeg.

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-11-01 16:14:39 +01:00
commit 5eb1704d5f
9 changed files with 225 additions and 198 deletions

View File

@ -609,6 +609,7 @@ following image formats are supported:
@item H.263+ / H.263-1998 / H.263 version 2 @tab X @tab X
@item H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 @tab E @tab X
@tab encoding supported through external library libx264
@item HEVC @tab @tab X
@item HNM version 4 @tab @tab X
@item HuffYUV @tab X @tab X
@item HuffYUV FFmpeg variant @tab X @tab X

View File

@ -277,6 +277,7 @@ enum AVCodecID {
AV_CODEC_ID_G2M_DEPRECATED,
AV_CODEC_ID_WEBP_DEPRECATED,
AV_CODEC_ID_HNM4_VIDEO,
AV_CODEC_ID_HEVC_DEPRECATED,
AV_CODEC_ID_BRENDER_PIX= MKBETAG('B','P','I','X'),
AV_CODEC_ID_Y41P = MKBETAG('Y','4','1','P'),

View File

@ -225,13 +225,6 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
.props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
},
{
.id = AV_CODEC_ID_HEVC,
.type = AVMEDIA_TYPE_VIDEO,
.name = "hevc",
.long_name = NULL_IF_CONFIG_SMALL("H.265 / HEVC"),
.props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
},
{
.id = AV_CODEC_ID_INDEO3,
.type = AVMEDIA_TYPE_VIDEO,
@ -1401,6 +1394,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("HNM 4 video"),
.props = AV_CODEC_PROP_LOSSY,
},
{
.id = AV_CODEC_ID_HEVC,
.type = AVMEDIA_TYPE_VIDEO,
.name = "hevc",
.long_name = NULL_IF_CONFIG_SMALL("H.265 / HEVC (High Efficiency Video Coding)"),
.props = AV_CODEC_PROP_LOSSY,
},
/* various PCM "codecs" */
{

View File

@ -2882,7 +2882,7 @@ static void hevc_decode_flush(AVCodecContext *avctx)
#define OFFSET(x) offsetof(HEVCContext, x)
#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
static const AVOption options[] = {
{ "strict-displaywin", "stricly apply default display window size", OFFSET(strict_def_disp_win),
{ "strict-displaywin", "stricly apply default display window size", OFFSET(apply_defdispwin),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, PAR },
{ NULL },
};

View File

@ -1,5 +1,5 @@
/*
* HEVC video Decoder
* HEVC video decoder
*
* Copyright (C) 2012 - 2013 Guillaume Martres
*
@ -88,31 +88,31 @@
* 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,
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 {
@ -347,7 +347,7 @@ typedef struct PTL {
int sub_layer_level_idc[MAX_SUB_LAYERS];
} PTL;
typedef struct VPS {
typedef struct HEVCVPS {
uint8_t vps_temporal_id_nesting_flag;
int vps_max_layers;
int vps_max_sub_layers; ///< vps_max_temporal_layers_minus1 + 1
@ -365,10 +365,11 @@ typedef struct VPS {
uint8_t vps_poc_proportional_to_timing_flag;
int vps_num_ticks_poc_diff_one; ///< vps_num_ticks_poc_diff_one_minus1 + 1
int vps_num_hrd_parameters;
} VPS;
} HEVCVPS;
typedef struct ScalingList {
// This is a little wasteful, since sizeID 0 only needs 8 coeffs, and size ID 3 only has 2 arrays, not 6.
/* This is a little wasteful, since sizeID 0 only needs 8 coeffs,
* and size ID 3 only has 2 arrays, not 6. */
uint8_t sl[4][6][64];
uint8_t sl_dc[2][6];
} ScalingList;
@ -483,8 +484,8 @@ typedef struct HEVCPPS {
uint8_t tiles_enabled_flag;
uint8_t entropy_coding_sync_enabled_flag;
int num_tile_columns; ///< num_tile_columns_minus1 + 1
int num_tile_rows; ///< num_tile_rows_minus1 + 1
int num_tile_columns; ///< num_tile_columns_minus1 + 1
int num_tile_rows; ///< num_tile_rows_minus1 + 1
uint8_t uniform_spacing_flag;
uint8_t loop_filter_across_tiles_enabled_flag;
@ -493,10 +494,10 @@ typedef struct HEVCPPS {
uint8_t deblocking_filter_control_present_flag;
uint8_t deblocking_filter_override_enabled_flag;
uint8_t disable_dbf;
int beta_offset; ///< beta_offset_div2 * 2
int tc_offset; ///< tc_offset_div2 * 2
int beta_offset; ///< beta_offset_div2 * 2
int tc_offset; ///< tc_offset_div2 * 2
int pps_scaling_list_data_present_flag;
int scaling_list_data_present_flag;
ScalingList scaling_list;
uint8_t lists_modification_present_flag;
@ -508,18 +509,18 @@ typedef struct HEVCPPS {
uint8_t pps_extension_data_flag;
// Inferred parameters
int *column_width; ///< ColumnWidth
int *row_height; ///< RowHeight
int *col_bd; ///< ColBd
int *row_bd; ///< RowBd
int *column_width; ///< ColumnWidth
int *row_height; ///< RowHeight
int *col_bd; ///< ColBd
int *row_bd; ///< RowBd
int *col_idxX;
int *ctb_addr_rs_to_ts; ///< CtbAddrRSToTS
int *ctb_addr_ts_to_rs; ///< CtbAddrTSToRS
int *tile_id; ///< TileId
int *tile_pos_rs; ///< TilePosRS
int *min_cb_addr_zs; ///< MinCbAddrZS
int *min_tb_addr_zs; ///< MinTbAddrZS
int *tile_id; ///< TileId
int *tile_pos_rs; ///< TilePosRS
int *min_cb_addr_zs; ///< MinCbAddrZS
int *min_tb_addr_zs; ///< MinTbAddrZS
} HEVCPPS;
typedef struct SliceHeader {
@ -565,8 +566,8 @@ typedef struct SliceHeader {
int slice_cb_qp_offset;
int slice_cr_qp_offset;
int beta_offset; ///< beta_offset_div2 * 2
int tc_offset; ///< tc_offset_div2 * 2
int beta_offset; ///< beta_offset_div2 * 2
int tc_offset; ///< tc_offset_div2 * 2
int max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand
@ -592,7 +593,7 @@ typedef struct SliceHeader {
int16_t luma_offset_l1[16];
int16_t chroma_offset_l1[16][2];
int slice_ctb_addr_rs;
int slice_ctb_addr_rs;
} SliceHeader;
typedef struct CodingTree {
@ -603,26 +604,26 @@ typedef struct CodingUnit {
int x;
int y;
enum PredMode pred_mode; ///< PredMode
enum PartMode part_mode; ///< PartMode
enum PredMode pred_mode; ///< PredMode
enum PartMode part_mode; ///< PartMode
uint8_t rqt_root_cbf;
uint8_t pcm_flag;
// Inferred parameters
uint8_t intra_split_flag; ///< IntraSplitFlag
uint8_t max_trafo_depth; ///< MaxTrafoDepth
uint8_t intra_split_flag; ///< IntraSplitFlag
uint8_t max_trafo_depth; ///< MaxTrafoDepth
uint8_t cu_transquant_bypass_flag;
} CodingUnit;
typedef struct Mv {
int16_t x; ///< horizontal component of motion vector
int16_t y; ///< vertical component of motion vector
int16_t x; ///< horizontal component of motion vector
int16_t y; ///< vertical component of motion vector
} Mv;
typedef struct MvField {
Mv mv[2];
Mv mv[2];
int8_t ref_idx[2];
int8_t pred_flag[2];
uint8_t is_intra;
@ -664,16 +665,16 @@ typedef struct TransformUnit {
} TransformUnit;
typedef struct SAOParams {
int offset_abs[3][4]; ///< sao_offset_abs
int offset_sign[3][4]; ///< sao_offset_sign
int offset_abs[3][4]; ///< sao_offset_abs
int offset_sign[3][4]; ///< sao_offset_sign
int band_position[3]; ///< sao_band_position
int band_position[3]; ///< sao_band_position
int eo_class[3]; ///< sao_eo_class
int eo_class[3]; ///< sao_eo_class
int offset_val[3][5]; ///<SaoOffsetVal
int offset_val[3][5]; ///<SaoOffsetVal
uint8_t type_idx[3]; ///< sao_type_idx
uint8_t type_idx[3]; ///< sao_type_idx
} SAOParams;
typedef struct DBParams {
@ -756,12 +757,12 @@ typedef struct HEVCLocalContext {
typedef struct HEVCContext {
const AVClass *c; // needed by private avoptions
AVCodecContext *avctx;
AVCodecContext *avctx;
struct HEVCContext *sList[MAX_NB_THREADS];
struct HEVCContext *sList[MAX_NB_THREADS];
HEVCLocalContext *HEVClcList[MAX_NB_THREADS];
HEVCLocalContext *HEVClc;
HEVCLocalContext *HEVClcList[MAX_NB_THREADS];
HEVCLocalContext *HEVClc;
uint8_t threads_type;
uint8_t threads_number;
@ -778,10 +779,10 @@ typedef struct HEVCContext {
AVFrame *sao_frame;
AVFrame *tmp_frame;
AVFrame *output_frame;
VPS *vps;
HEVCVPS *vps;
const HEVCSPS *sps;
HEVCPPS *pps;
VPS *vps_list[MAX_VPS_COUNT];
HEVCVPS *vps_list[MAX_VPS_COUNT];
AVBufferRef *sps_list[MAX_SPS_COUNT];
AVBufferRef *pps_list[MAX_PPS_COUNT];
@ -825,7 +826,6 @@ typedef struct HEVCContext {
// PU
uint8_t *tab_ipm;
uint8_t *cbf_luma; // cbf_luma of colocated TU
uint8_t *is_pcm;
@ -865,13 +865,13 @@ typedef struct HEVCContext {
uint8_t is_md5;
int context_initialized;
int is_nalff; ///< this flag is != 0 if bitstream is encapsulated
///< as a format defined in 14496-15
int strict_def_disp_win;
int is_nalff; ///< this flag is != 0 if bitstream is encapsulated
///< as a format defined in 14496-15
int apply_defdispwin;
int active_seq_parameter_set_id;
int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4)
int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4)
int nuh_layer_id;
int picture_struct;
@ -902,7 +902,8 @@ void ff_hevc_flush_dpb(HEVCContext *s);
*/
int ff_hevc_compute_poc(HEVCContext *s, int poc_lsb);
RefPicList* ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *frame, int x0, int y0);
RefPicList *ff_hevc_get_ref_list(HEVCContext *s, HEVCFrame *frame,
int x0, int y0);
/**
* Construct the reference picture sets for the current frame.
@ -924,9 +925,11 @@ int ff_hevc_sao_offset_sign_decode(HEVCContext *s);
int ff_hevc_sao_eo_class_decode(HEVCContext *s);
int ff_hevc_end_of_slice_flag_decode(HEVCContext *s);
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCContext *s);
int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0, int x_cb, int y_cb);
int ff_hevc_skip_flag_decode(HEVCContext *s, int x0, int y0,
int x_cb, int y_cb);
int ff_hevc_pred_mode_decode(HEVCContext *s);
int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth, int x0, int y0);
int ff_hevc_split_coding_unit_flag_decode(HEVCContext *s, int ct_depth,
int x0, int y0);
int ff_hevc_part_mode_decode(HEVCContext *s, int log2_cb_size);
int ff_hevc_pcm_flag_decode(HEVCContext *s);
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCContext *s);
@ -959,12 +962,21 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *frame, int flush);
void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags);
void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0, int nPbW, int nPbH);
void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv);
void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0, int nPbW, int nPbH, int log2_cb_size, int part_idx, int merge_idx, MvField *mv , int mvp_lx_flag, int LX);
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size);
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size,
int slice_or_tiles_up_boundary, int slice_or_tiles_left_boundary);
void ff_hevc_set_neighbour_available(HEVCContext *s, int x0, int y0,
int nPbW, int nPbH);
void ff_hevc_luma_mv_merge_mode(HEVCContext *s, int x0, int y0,
int nPbW, int nPbH, int log2_cb_size,
int part_idx, int merge_idx, MvField *mv);
void ff_hevc_luma_mv_mvp_mode(HEVCContext *s, int x0, int y0,
int nPbW, int nPbH, int log2_cb_size,
int part_idx, int merge_idx,
MvField *mv, int mvp_lx_flag, int LX);
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase,
int log2_cb_size);
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
int log2_trafo_size,
int slice_or_tiles_up_boundary,
int slice_or_tiles_left_boundary);
int ff_hevc_cu_qp_delta_sign_flag(HEVCContext *s);
int ff_hevc_cu_qp_delta_abs(HEVCContext *s);
void ff_hevc_hls_filter(HEVCContext *s, int x, int y);
@ -986,4 +998,4 @@ extern const uint8_t ff_hevc_diag_scan4x4_y[16];
extern const uint8_t ff_hevc_diag_scan8x8_x[64];
extern const uint8_t ff_hevc_diag_scan8x8_y[64];
#endif // AVCODEC_HEVC_H
#endif /* AVCODEC_HEVC_H */

View File

@ -1137,7 +1137,7 @@ void ff_hevc_hls_residual_coding(HEVCContext *s, int x0, int y0,
dc_scale = 16;
if (s->sps->scaling_list_enable_flag) {
const ScalingList *sl = s->pps->pps_scaling_list_data_present_flag ?
const ScalingList *sl = s->pps->scaling_list_data_present_flag ?
&s->pps->scaling_list : &s->sps->scaling_list;
int matrix_id = lc->cu.pred_mode != MODE_INTRA;

View File

@ -1,5 +1,5 @@
/*
* HEVC Parameter Set Decoding
* HEVC Parameter Set decoding
*
* Copyright (C) 2012 - 2103 Guillaume Martres
* Copyright (C) 2012 - 2103 Mickael Raulet
@ -23,8 +23,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "golomb.h"
#include "libavutil/imgutils.h"
#include "golomb.h"
#include "hevc.h"
static const uint8_t default_scaling_list_intra[] = {
@ -35,7 +36,7 @@ static const uint8_t default_scaling_list_intra[] = {
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29,36, 47, 65, 88, 115
24, 25, 29, 36, 47, 65, 88, 115
};
static const uint8_t default_scaling_list_inter[] = {
@ -50,8 +51,8 @@ static const uint8_t default_scaling_list_inter[] = {
};
static const AVRational vui_sar[] = {
{ 0, 1 },
{ 1, 1 },
{ 0, 1 },
{ 1, 1 },
{ 12, 11 },
{ 10, 11 },
{ 16, 11 },
@ -64,9 +65,9 @@ static const AVRational vui_sar[] = {
{ 15, 11 },
{ 64, 33 },
{ 160, 99 },
{ 4, 3 },
{ 3, 2 },
{ 2, 1 },
{ 4, 3 },
{ 3, 2 },
{ 2, 1 },
};
int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
@ -83,7 +84,7 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
GetBitContext *gb = &lc->gb;
if (rps != sps->st_rps && sps->nb_st_rps)
rps_predict = get_bits1(gb);
rps_predict = get_bits1(gb);
if (rps_predict) {
const ShortTermRPS *rps_ridx;
@ -94,9 +95,9 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
if (is_slice_header) {
int delta_idx = get_ue_golomb_long(gb) + 1;
if (delta_idx > sps->nb_st_rps) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid value of delta_idx "
"in slice header RPS: %d > %d.\n", delta_idx,
sps->nb_st_rps);
av_log(s->avctx, AV_LOG_ERROR,
"Invalid value of delta_idx in slice header RPS: %d > %d.\n",
delta_idx, sps->nb_st_rps);
return AVERROR_INVALIDDATA;
}
rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx];
@ -134,13 +135,13 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
for (i = 1; i < rps->num_delta_pocs; i++) {
delta_poc = rps->delta_poc[i];
used = rps->used[i];
for (k = i-1 ; k >= 0; k--) {
for (k = i - 1; k >= 0; k--) {
tmp = rps->delta_poc[k];
if (delta_poc < tmp ) {
rps->delta_poc[k+1] = tmp;
rps->used[k+1] = rps->used[k];
rps->delta_poc[k] = delta_poc;
rps->used[k] = used;
if (delta_poc < tmp) {
rps->delta_poc[k + 1] = tmp;
rps->used[k + 1] = rps->used[k];
rps->delta_poc[k] = delta_poc;
rps->used[k] = used;
}
}
}
@ -149,13 +150,13 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
int used;
k = rps->num_negative_pics - 1;
// flip the negative values to largest first
for (i = 0; i < rps->num_negative_pics>>1; i++) {
delta_poc = rps->delta_poc[i];
used = rps->used[i];
rps->delta_poc[i] = rps->delta_poc[k];
rps->used[i] = rps->used[k];
rps->delta_poc[k] = delta_poc;
rps->used[k] = used;
for (i = 0; i < rps->num_negative_pics >> 1; i++) {
delta_poc = rps->delta_poc[i];
used = rps->used[i];
rps->delta_poc[i] = rps->delta_poc[k];
rps->used[i] = rps->used[k];
rps->delta_poc[k] = delta_poc;
rps->used[k] = used;
k--;
}
}
@ -177,29 +178,30 @@ int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
delta_poc = get_ue_golomb_long(gb) + 1;
prev -= delta_poc;
rps->delta_poc[i] = prev;
rps->used[i] = get_bits1(gb);
rps->used[i] = get_bits1(gb);
}
prev = 0;
for (i = 0; i < nb_positive_pics; i++) {
delta_poc = get_ue_golomb_long(gb) + 1;
prev += delta_poc;
rps->delta_poc[rps->num_negative_pics + i] = prev;
rps->used[rps->num_negative_pics + i] = get_bits1(gb);
rps->used[rps->num_negative_pics + i] = get_bits1(gb);
}
}
}
return 0;
}
static int decode_profile_tier_level(HEVCContext *s, PTL *ptl, int max_num_sub_layers)
static int decode_profile_tier_level(HEVCContext *s, PTL *ptl,
int max_num_sub_layers)
{
int i, j;
HEVCLocalContext *lc = s->HEVClc;
GetBitContext *gb = &lc->gb;
int i, j;
ptl->general_profile_space = get_bits(gb, 2);
ptl->general_tier_flag = get_bits1(gb);
ptl->general_profile_idc = get_bits(gb, 5);
ptl->general_tier_flag = get_bits1(gb);
ptl->general_profile_idc = get_bits(gb, 5);
if (ptl->general_profile_idc == 1)
av_log(s->avctx, AV_LOG_DEBUG, "Main profile bitstream\n");
else if (ptl->general_profile_idc == 2)
@ -209,10 +211,10 @@ static int decode_profile_tier_level(HEVCContext *s, PTL *ptl, int max_num_sub_l
for (i = 0; i < 32; i++)
ptl->general_profile_compatibility_flag[i] = get_bits1(gb);
skip_bits1(gb);// general_progressive_source_flag
skip_bits1(gb);// general_interlaced_source_flag
skip_bits1(gb);// general_non_packed_constraint_flag
skip_bits1(gb);// general_frame_only_constraint_flag
skip_bits1(gb); // general_progressive_source_flag
skip_bits1(gb); // general_interlaced_source_flag
skip_bits1(gb); // general_non_packed_constraint_flag
skip_bits1(gb); // general_frame_only_constraint_flag
if (get_bits(gb, 16) != 0) // XXX_reserved_zero_44bits[0..15]
return -1;
if (get_bits(gb, 16) != 0) // XXX_reserved_zero_44bits[16..31]
@ -223,7 +225,7 @@ static int decode_profile_tier_level(HEVCContext *s, PTL *ptl, int max_num_sub_l
ptl->general_level_idc = get_bits(gb, 8);
for (i = 0; i < max_num_sub_layers - 1; i++) {
ptl->sub_layer_profile_present_flag[i] = get_bits1(gb);
ptl->sub_layer_level_present_flag[i] = get_bits1(gb);
ptl->sub_layer_level_present_flag[i] = get_bits1(gb);
}
if (max_num_sub_layers - 1 > 0)
for (i = max_num_sub_layers - 1; i < 8; i++)
@ -231,14 +233,14 @@ static int decode_profile_tier_level(HEVCContext *s, PTL *ptl, int max_num_sub_l
for (i = 0; i < max_num_sub_layers - 1; i++) {
if (ptl->sub_layer_profile_present_flag[i]) {
ptl->sub_layer_profile_space[i] = get_bits(gb, 2);
ptl->sub_layer_tier_flag[i] = get_bits(gb, 1);
ptl->sub_layer_profile_idc[i] = get_bits(gb, 5);
ptl->sub_layer_tier_flag[i] = get_bits(gb, 1);
ptl->sub_layer_profile_idc[i] = get_bits(gb, 5);
for (j = 0; j < 32; j++)
ptl->sub_layer_profile_compatibility_flags[i][j] = get_bits1(gb);
skip_bits1(gb);// sub_layer_progressive_source_flag
skip_bits1(gb);// sub_layer_interlaced_source_flag
skip_bits1(gb);// sub_layer_non_packed_constraint_flag
skip_bits1(gb);// sub_layer_frame_only_constraint_flag
skip_bits1(gb); // sub_layer_progressive_source_flag
skip_bits1(gb); // sub_layer_interlaced_source_flag
skip_bits1(gb); // sub_layer_non_packed_constraint_flag
skip_bits1(gb); // sub_layer_frame_only_constraint_flag
if (get_bits(gb, 16) != 0) // sub_layer_reserved_zero_44bits[0..15]
return -1;
@ -253,7 +255,8 @@ static int decode_profile_tier_level(HEVCContext *s, PTL *ptl, int max_num_sub_l
return 0;
}
static void decode_sublayer_hrd(HEVCContext *s, int nb_cpb, int subpic_params_present)
static void decode_sublayer_hrd(HEVCContext *s, int nb_cpb,
int subpic_params_present)
{
GetBitContext *gb = &s->HEVClc->gb;
int i;
@ -331,7 +334,7 @@ int ff_hevc_decode_nal_vps(HEVCContext *s)
int i,j;
GetBitContext *gb = &s->HEVClc->gb;
int vps_id = 0;
VPS *vps;
HEVCVPS *vps;
av_log(s->avctx, AV_LOG_DEBUG, "Decoding VPS\n");
@ -425,7 +428,7 @@ err:
static void decode_vui(HEVCContext *s, HEVCSPS *sps)
{
VUI *vui = &sps->vui;
VUI *vui = &sps->vui;
GetBitContext *gb = &s->HEVClc->gb;
int sar_present;
@ -440,8 +443,8 @@ static void decode_vui(HEVCContext *s, HEVCSPS *sps)
vui->sar.num = get_bits(gb, 16);
vui->sar.den = get_bits(gb, 16);
} else
av_log(s->avctx, AV_LOG_WARNING, "Unknown SAR index: %u.\n",
sar_idx);
av_log(s->avctx, AV_LOG_WARNING,
"Unknown SAR index: %u.\n", sar_idx);
}
vui->overscan_info_present_flag = get_bits1(gb);
@ -478,7 +481,7 @@ static void decode_vui(HEVCContext *s, HEVCSPS *sps)
vui->def_disp_win.top_offset = get_ue_golomb_long(gb) * 2;
vui->def_disp_win.bottom_offset = get_ue_golomb_long(gb) * 2;
if (s->strict_def_disp_win &&
if (s->apply_defdispwin &&
s->avctx->flags2 & CODEC_FLAG2_IGNORE_CROP) {
av_log(s->avctx, AV_LOG_DEBUG,
"discarding vui default display window, "
@ -551,14 +554,15 @@ static int scaling_list_data(HEVCContext *s, ScalingList *sl)
GetBitContext *gb = &s->HEVClc->gb;
uint8_t scaling_list_pred_mode_flag[4][6];
int32_t scaling_list_dc_coef[2][6];
int size_id, matrix_id, i, pos, delta;
for (size_id = 0; size_id < 4; size_id++)
for (matrix_id = 0; matrix_id < ((size_id == 3) ? 2 : 6); matrix_id++) {
for (matrix_id = 0; matrix_id < (size_id == 3 ? 2 : 6); matrix_id++) {
scaling_list_pred_mode_flag[size_id][matrix_id] = get_bits1(gb);
if (!scaling_list_pred_mode_flag[size_id][matrix_id]) {
delta = get_ue_golomb_long(gb);
// Only need to handle non-zero delta. Zero means default, which should already be in the arrays.
/* Only need to handle non-zero delta. Zero means default,
* which should already be in the arrays. */
if (delta) {
// Copy from previous array.
if (matrix_id - delta < 0) {
@ -574,12 +578,11 @@ static int scaling_list_data(HEVCContext *s, ScalingList *sl)
sl->sl_dc[size_id - 2][matrix_id] = sl->sl_dc[size_id - 2][matrix_id - delta];
}
} else {
int next_coef;
int coef_num;
int next_coef, coef_num;
int32_t scaling_list_delta_coef;
next_coef = 8;
coef_num = FFMIN(64, (1 << (4 + (size_id << 1))));
coef_num = FFMIN(64, 1 << (4 + (size_id << 1)));
if (size_id > 1) {
scaling_list_dc_coef[size_id - 2][matrix_id] = get_se_golomb(gb) + 8;
next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
@ -587,12 +590,14 @@ static int scaling_list_data(HEVCContext *s, ScalingList *sl)
}
for (i = 0; i < coef_num; i++) {
if (size_id == 0)
pos = 4 * ff_hevc_diag_scan4x4_y[i] + ff_hevc_diag_scan4x4_x[i];
pos = 4 * ff_hevc_diag_scan4x4_y[i] +
ff_hevc_diag_scan4x4_x[i];
else
pos = 8 * ff_hevc_diag_scan8x8_y[i] + ff_hevc_diag_scan8x8_x[i];
pos = 8 * ff_hevc_diag_scan8x8_y[i] +
ff_hevc_diag_scan8x8_x[i];
scaling_list_delta_coef = get_se_golomb(gb);
next_coef = (next_coef + scaling_list_delta_coef + 256 ) % 256;
next_coef = (next_coef + scaling_list_delta_coef + 256) % 256;
sl->sl[size_id][matrix_id][pos] = next_coef;
}
}
@ -653,7 +658,7 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
sps->chroma_format_idc = get_ue_golomb_long(gb);
if (sps->chroma_format_idc != 1) {
avpriv_report_missing_feature(s->avctx, "chroma_format_idc != 1\n");
ret = AVERROR_INVALIDDATA;
ret = AVERROR_PATCHWELCOME;
goto err;
}
@ -694,7 +699,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
bit_depth_chroma = get_ue_golomb_long(gb) + 8;
if (bit_depth_chroma != sps->bit_depth) {
av_log(s->avctx, AV_LOG_ERROR,
"Luma bit depth (%d) is different from chroma bit depth (%d), this is unsupported.\n",
"Luma bit depth (%d) is different from chroma bit depth (%d), "
"this is unsupported.\n",
sps->bit_depth, bit_depth_chroma);
ret = AVERROR_INVALIDDATA;
goto err;
@ -712,7 +718,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
goto err;
}
} else {
av_log(s->avctx, AV_LOG_ERROR, "non-4:2:0 support is currently unspecified.\n");
av_log(s->avctx, AV_LOG_ERROR,
"non-4:2:0 support is currently unspecified.\n");
return AVERROR_PATCHWELCOME;
}
@ -757,18 +764,19 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
}
if (!sublayer_ordering_info) {
for (i = 0; i < start; i++){
for (i = 0; i < start; i++) {
sps->temporal_layer[i].max_dec_pic_buffering = sps->temporal_layer[start].max_dec_pic_buffering;
sps->temporal_layer[i].num_reorder_pics = sps->temporal_layer[start].num_reorder_pics;
sps->temporal_layer[i].max_latency_increase = sps->temporal_layer[start].max_latency_increase;
}
}
sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3;
sps->log2_diff_max_min_coding_block_size = get_ue_golomb_long(gb);
sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2;
log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb);
sps->log2_max_trafo_size = log2_diff_max_min_transform_block_size + sps->log2_min_tb_size;
sps->log2_min_cb_size = get_ue_golomb_long(gb) + 3;
sps->log2_diff_max_min_coding_block_size = get_ue_golomb_long(gb);
sps->log2_min_tb_size = get_ue_golomb_long(gb) + 2;
log2_diff_max_min_transform_block_size = get_ue_golomb_long(gb);
sps->log2_max_trafo_size = log2_diff_max_min_transform_block_size +
sps->log2_min_tb_size;
if (sps->log2_min_tb_size >= sps->log2_min_cb_size) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid value for log2_min_tb_size");
@ -840,7 +848,7 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
decode_vui(s, sps);
skip_bits1(gb); // sps_extension_flag
if (s->strict_def_disp_win) {
if (s->apply_defdispwin) {
sps->output_window.left_offset += sps->vui.def_disp_win.left_offset;
sps->output_window.right_offset += sps->vui.def_disp_win.right_offset;
sps->output_window.top_offset += sps->vui.def_disp_win.top_offset;
@ -864,32 +872,33 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
ret = AVERROR_INVALIDDATA;
goto err;
}
av_log(s->avctx, AV_LOG_WARNING, "Displaying the whole video surface.\n");
av_log(s->avctx, AV_LOG_WARNING,
"Displaying the whole video surface.\n");
sps->pic_conf_win.left_offset =
sps->pic_conf_win.right_offset =
sps->pic_conf_win.top_offset =
sps->pic_conf_win.bottom_offset = 0;
sps->output_width = sps->width;
sps->output_height = sps->height;
sps->output_width = sps->width;
sps->output_height = sps->height;
}
// Inferred parameters
sps->log2_ctb_size = sps->log2_min_cb_size
+ sps->log2_diff_max_min_coding_block_size;
sps->log2_min_pu_size = sps->log2_min_cb_size - 1;
sps->log2_ctb_size = sps->log2_min_cb_size +
sps->log2_diff_max_min_coding_block_size;
sps->log2_min_pu_size = sps->log2_min_cb_size - 1;
sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
sps->ctb_size = sps->ctb_width * sps->ctb_height;
sps->ctb_width = (sps->width + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
sps->ctb_height = (sps->height + (1 << sps->log2_ctb_size) - 1) >> sps->log2_ctb_size;
sps->ctb_size = sps->ctb_width * sps->ctb_height;
sps->min_cb_width = sps->width >> sps->log2_min_cb_size;
sps->min_cb_height = sps->height >> sps->log2_min_cb_size;
sps->min_tb_width = sps->width >> sps->log2_min_tb_size;
sps->min_tb_height = sps->height >> sps->log2_min_tb_size;
sps->min_pu_width = sps->width >> sps->log2_min_pu_size;
sps->min_pu_height = sps->height >> sps->log2_min_pu_size;
sps->min_cb_width = sps->width >> sps->log2_min_cb_size;
sps->min_cb_height = sps->height >> sps->log2_min_cb_size;
sps->min_tb_width = sps->width >> sps->log2_min_tb_size;
sps->min_tb_height = sps->height >> sps->log2_min_tb_size;
sps->min_pu_width = sps->width >> sps->log2_min_pu_size;
sps->min_pu_height = sps->height >> sps->log2_min_pu_size;
sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
sps->qp_bd_offset = 6 * (sps->bit_depth - 8);
if (sps->width & ((1 << sps->log2_min_cb_size) - 1) ||
sps->height & ((1 << sps->log2_min_cb_size) - 1)) {
@ -912,13 +921,15 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
goto err;
}
if (sps->log2_max_trafo_size > FFMIN(sps->log2_ctb_size, 5)) {
av_log(s->avctx, AV_LOG_ERROR, "max transform block size out of range: %d\n",
av_log(s->avctx, AV_LOG_ERROR,
"max transform block size out of range: %d\n",
sps->log2_max_trafo_size);
goto err;
}
if (s->avctx->debug & FF_DEBUG_BITSTREAM) {
av_log(s->avctx, AV_LOG_DEBUG, "Parsed SPS: id %d; coded wxh: %dx%d; "
av_log(s->avctx, AV_LOG_DEBUG,
"Parsed SPS: id %d; coded wxh: %dx%d; "
"cropped wxh: %dx%d; pix_fmt: %s.\n",
sps_id, sps->width, sps->height,
sps->output_width, sps->output_height,
@ -941,8 +952,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
}
return 0;
err:
err:
av_buffer_unref(&sps_buf);
return ret;
}
@ -982,7 +993,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
if (!pps)
return AVERROR(ENOMEM);
pps_buf = av_buffer_create((uint8_t*)pps, sizeof(*pps), hevc_pps_free, NULL, 0);
pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps),
hevc_pps_free, NULL, 0);
if (!pps_buf) {
av_freep(&pps);
return AVERROR(ENOMEM);
@ -1017,7 +1029,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
ret = AVERROR_INVALIDDATA;
goto err;
}
sps = (HEVCSPS*)s->sps_list[pps->sps_id]->data;
sps = (HEVCSPS *)s->sps_list[pps->sps_id]->data;
pps->dependent_slice_segments_enabled_flag = get_bits1(gb);
pps->output_flag_present_flag = get_bits1(gb);
@ -1064,8 +1076,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
pps->entropy_coding_sync_enabled_flag = get_bits1(gb);
if (pps->tiles_enabled_flag) {
pps->num_tile_columns = get_ue_golomb_long(gb) + 1;
pps->num_tile_rows = get_ue_golomb_long(gb) + 1;
pps->num_tile_columns = get_ue_golomb_long(gb) + 1;
pps->num_tile_rows = get_ue_golomb_long(gb) + 1;
if (pps->num_tile_columns == 0 ||
pps->num_tile_columns >= sps->width) {
av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n",
@ -1093,7 +1105,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
int sum = 0;
for (i = 0; i < pps->num_tile_columns - 1; i++) {
pps->column_width[i] = get_ue_golomb_long(gb) + 1;
sum += pps->column_width[i];
sum += pps->column_width[i];
}
if (sum >= sps->ctb_width) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid tile widths.\n");
@ -1105,7 +1117,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
sum = 0;
for (i = 0; i < pps->num_tile_rows - 1; i++) {
pps->row_height[i] = get_ue_golomb_long(gb) + 1;
sum += pps->row_height[i];
sum += pps->row_height[i];
}
if (sum >= sps->ctb_height) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid tile heights.\n");
@ -1122,7 +1134,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
pps->deblocking_filter_control_present_flag = get_bits1(gb);
if (pps->deblocking_filter_control_present_flag) {
pps->deblocking_filter_override_enabled_flag = get_bits1(gb);
pps->disable_dbf = get_bits1(gb);
pps->disable_dbf = get_bits1(gb);
if (!pps->disable_dbf) {
pps->beta_offset = get_se_golomb(gb) * 2;
pps->tc_offset = get_se_golomb(gb) * 2;
@ -1141,8 +1153,8 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
}
}
pps->pps_scaling_list_data_present_flag = get_bits1(gb);
if (pps->pps_scaling_list_data_present_flag) {
pps->scaling_list_data_present_flag = get_bits1(gb);
if (pps->scaling_list_data_present_flag) {
set_default_scaling_list_data(&pps->scaling_list);
ret = scaling_list_data(s, &pps->scaling_list);
if (ret < 0)
@ -1199,9 +1211,9 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i];
for (i = 0, j = 0; i < sps->ctb_width; i++) {
if (i > pps->col_bd[j])
j++;
pps->col_idxX[i] = j;
if (i > pps->col_bd[j])
j++;
pps->col_idxX[i] = j;
}
/**
@ -1243,16 +1255,16 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
}
}
for (i = 0; i < tile_x; i++ )
for (i = 0; i < tile_x; i++)
val += pps->row_height[tile_y] * pps->column_width[i];
for (i = 0; i < tile_y; i++ )
for (i = 0; i < tile_y; i++)
val += sps->ctb_width * pps->row_height[i];
val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] +
tb_x - pps->col_bd[tile_x];
pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val;
pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs;
pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs;
}
for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++)
@ -1273,11 +1285,11 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
for (y = 0; y < sps->min_cb_height; y++) {
for (x = 0; x < sps->min_cb_width; x++) {
int tb_x = x >> sps->log2_diff_max_min_coding_block_size;
int tb_y = y >> sps->log2_diff_max_min_coding_block_size;
int tb_x = x >> sps->log2_diff_max_min_coding_block_size;
int tb_y = y >> sps->log2_diff_max_min_coding_block_size;
int ctb_addr_rs = sps->ctb_width * tb_y + tb_x;
int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
(sps->log2_diff_max_min_coding_block_size * 2);
int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
(sps->log2_diff_max_min_coding_block_size * 2);
for (i = 0; i < sps->log2_diff_max_min_coding_block_size; i++) {
int m = 1 << i;
val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
@ -1289,11 +1301,11 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
log2_diff_ctb_min_tb_size = sps->log2_ctb_size - sps->log2_min_tb_size;
for (y = 0; y < sps->min_tb_height; y++) {
for (x = 0; x < sps->min_tb_width; x++) {
int tb_x = x >> log2_diff_ctb_min_tb_size;
int tb_y = y >> log2_diff_ctb_min_tb_size;
int tb_x = x >> log2_diff_ctb_min_tb_size;
int tb_y = y >> log2_diff_ctb_min_tb_size;
int ctb_addr_rs = sps->ctb_width * tb_y + tb_x;
int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
(log2_diff_ctb_min_tb_size * 2);
int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] <<
(log2_diff_ctb_min_tb_size * 2);
for (i = 0; i < log2_diff_ctb_min_tb_size; i++) {
int m = 1 << i;
val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);

View File

@ -2606,6 +2606,7 @@ static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
case AV_CODEC_ID_ESCAPE130_DEPRECATED : return AV_CODEC_ID_ESCAPE130;
case AV_CODEC_ID_G2M_DEPRECATED : return AV_CODEC_ID_G2M;
case AV_CODEC_ID_WEBP_DEPRECATED: return AV_CODEC_ID_WEBP;
case AV_CODEC_ID_HEVC_DEPRECATED: return AV_CODEC_ID_HEVC;
default : return id;
}
}

View File

@ -30,7 +30,7 @@
#define LIBAVCODEC_VERSION_MAJOR 55
#define LIBAVCODEC_VERSION_MINOR 40
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \