Commit 5a41999d authored by Mickaël Raulet's avatar Mickaël Raulet Committed by Michael Niedermayer

hevc/rext: basic infrastructure for supporting range extension

- support for 4:2:2 and 4:4:4 up to 12 bits
- add a new profile for range extension
(cherry picked from commit d3c067fa65bbc871758d28aa07f54123430ca346)
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 250430bf
...@@ -2866,6 +2866,7 @@ typedef struct AVCodecContext { ...@@ -2866,6 +2866,7 @@ typedef struct AVCodecContext {
#define FF_PROFILE_HEVC_MAIN 1 #define FF_PROFILE_HEVC_MAIN 1
#define FF_PROFILE_HEVC_MAIN_10 2 #define FF_PROFILE_HEVC_MAIN_10 2
#define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3 #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE 3
#define FF_PROFILE_HEVC_REXT 4
/** /**
* level * level
......
This diff is collapsed.
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
#define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)]) #define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)])
#define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)]) #define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)])
#define SAMPLE_CBF(tab, x, y) ((tab)[((y) & ((1<<log2_trafo_size)-1)) * MAX_CU_SIZE + ((x) & ((1<<log2_trafo_size)-1))]) #define SAMPLE_CBF(tab, x, y) ((tab)[((y) & ((1<<log2_trafo_size)-1)) * MAX_CU_SIZE + ((x) & ((1<<log2_trafo_size)-1))])
#define SAMPLE_CBF2(tab, x, y) ((tab)[(y) * MAX_CU_SIZE + (x)])
#define IS_IDR(s) ((s)->nal_unit_type == NAL_IDR_W_RADL || (s)->nal_unit_type == NAL_IDR_N_LP) #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 || \ #define IS_BLA(s) ((s)->nal_unit_type == NAL_BLA_W_RADL || (s)->nal_unit_type == NAL_BLA_W_LP || \
...@@ -457,6 +458,13 @@ typedef struct HEVCSPS { ...@@ -457,6 +458,13 @@ typedef struct HEVCSPS {
int max_transform_hierarchy_depth_inter; int max_transform_hierarchy_depth_inter;
int max_transform_hierarchy_depth_intra; int max_transform_hierarchy_depth_intra;
int transform_skip_rotation_enabled_flag;
int transform_skip_context_enabled_flag;
int implicit_rdpcm_enabled_flag;
int explicit_rdpcm_enabled_flag;
int intra_smoothing_disabled_flag;
int persistent_rice_adaptation_enabled_flag;
///< coded frame dimension in various units ///< coded frame dimension in various units
int width; int width;
int height; int height;
...@@ -526,6 +534,15 @@ typedef struct HEVCPPS { ...@@ -526,6 +534,15 @@ typedef struct HEVCPPS {
int log2_parallel_merge_level; ///< log2_parallel_merge_level_minus2 + 2 int log2_parallel_merge_level; ///< log2_parallel_merge_level_minus2 + 2
int num_extra_slice_header_bits; int num_extra_slice_header_bits;
uint8_t slice_header_extension_present_flag; uint8_t slice_header_extension_present_flag;
uint8_t log2_max_transform_skip_block_size;
uint8_t cross_component_prediction_enabled_flag;
uint8_t chroma_qp_offset_list_enabled_flag;
uint8_t diff_cu_chroma_qp_offset_depth;
uint8_t chroma_qp_offset_list_len_minus1;
int8_t cb_qp_offset_list[5];
int8_t cr_qp_offset_list[5];
uint8_t log2_sao_offset_scale_luma;
uint8_t log2_sao_offset_scale_chroma;
// Inferred parameters // Inferred parameters
unsigned int *column_width; ///< ColumnWidth unsigned int *column_width; ///< ColumnWidth
...@@ -661,7 +678,8 @@ typedef struct PredictionUnit { ...@@ -661,7 +678,8 @@ typedef struct PredictionUnit {
uint8_t intra_pred_mode[4]; uint8_t intra_pred_mode[4];
Mv mvd; Mv mvd;
uint8_t merge_flag; uint8_t merge_flag;
uint8_t intra_pred_mode_c; uint8_t intra_pred_mode_c[4];
uint8_t chroma_mode_c[4];
} PredictionUnit; } PredictionUnit;
typedef struct TransformTree { typedef struct TransformTree {
...@@ -677,7 +695,9 @@ typedef struct TransformUnit { ...@@ -677,7 +695,9 @@ typedef struct TransformUnit {
int cu_qp_delta; int cu_qp_delta;
// Inferred parameters; // Inferred parameters;
int cur_intra_pred_mode; int intra_pred_mode;
int intra_pred_mode_c;
int chroma_mode_c;
uint8_t is_cu_qp_delta_coded; uint8_t is_cu_qp_delta_coded;
} TransformUnit; } TransformUnit;
...@@ -968,7 +988,6 @@ int ff_hevc_no_residual_syntax_flag_decode(HEVCContext *s); ...@@ -968,7 +988,6 @@ int ff_hevc_no_residual_syntax_flag_decode(HEVCContext *s);
int ff_hevc_split_transform_flag_decode(HEVCContext *s, int log2_trafo_size); int ff_hevc_split_transform_flag_decode(HEVCContext *s, int log2_trafo_size);
int ff_hevc_cbf_cb_cr_decode(HEVCContext *s, int trafo_depth); int ff_hevc_cbf_cb_cr_decode(HEVCContext *s, int trafo_depth);
int ff_hevc_cbf_luma_decode(HEVCContext *s, int trafo_depth); int ff_hevc_cbf_luma_decode(HEVCContext *s, int trafo_depth);
int ff_hevc_transform_skip_flag_decode(HEVCContext *s, int c_idx);
/** /**
* Get the number of candidate references for the current frame. * Get the number of candidate references for the current frame.
......
...@@ -894,7 +894,7 @@ int ff_hevc_cbf_luma_decode(HEVCContext *s, int trafo_depth) ...@@ -894,7 +894,7 @@ int ff_hevc_cbf_luma_decode(HEVCContext *s, int trafo_depth)
return GET_CABAC(elem_offset[CBF_LUMA] + !trafo_depth); return GET_CABAC(elem_offset[CBF_LUMA] + !trafo_depth);
} }
int ff_hevc_transform_skip_flag_decode(HEVCContext *s, int c_idx) static int ff_hevc_transform_skip_flag_decode(HEVCContext *s, int c_idx)
{ {
return GET_CABAC(elem_offset[TRANSFORM_SKIP_FLAG] + !!c_idx); return GET_CABAC(elem_offset[TRANSFORM_SKIP_FLAG] + !!c_idx);
} }
...@@ -1093,16 +1093,18 @@ void ff_hevc_hls_residual_coding(HEVCContext *s, int x0, int y0, ...@@ -1093,16 +1093,18 @@ void ff_hevc_hls_residual_coding(HEVCContext *s, int x0, int y0,
// Derive QP for dequant // Derive QP for dequant
if (!lc->cu.cu_transquant_bypass_flag) { if (!lc->cu.cu_transquant_bypass_flag) {
static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 }; static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
static const uint8_t rem6[51 + 2 * 6 + 1] = { static const uint8_t rem6[51 + 4 * 6 + 1] = {
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2,
3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5,
0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
4, 5, 0, 1, 2, 3, 4, 5, 0, 1
}; };
static const uint8_t div6[51 + 2 * 6 + 1] = { static const uint8_t div6[51 + 4 * 6 + 1] = {
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3,
3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
10, 10, 11, 11, 11, 11, 11, 11, 12, 12
}; };
int qp_y = lc->qp_y; int qp_y = lc->qp_y;
......
...@@ -61,12 +61,16 @@ static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset) ...@@ -61,12 +61,16 @@ static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset)
offset = s->pps->cr_qp_offset; offset = s->pps->cr_qp_offset;
qp_i = av_clip(qp_y + offset, 0, 57); qp_i = av_clip(qp_y + offset, 0, 57);
if (qp_i < 30) if (s->sps->chroma_format_idc == 1) {
qp = qp_i; if (qp_i < 30)
else if (qp_i > 43) qp = qp_i;
qp = qp_i - 6; else if (qp_i > 43)
else qp = qp_i - 6;
qp = qp_c[qp_i - 30]; else
qp = qp_c[qp_i - 30];
} else {
qp = av_clip(qp_i, 0, 51);
}
idxt = av_clip(qp + DEFAULT_INTRA_TC_OFFSET + tc_offset, 0, 53); idxt = av_clip(qp + DEFAULT_INTRA_TC_OFFSET + tc_offset, 0, 53);
return tctable[idxt]; return tctable[idxt];
...@@ -327,6 +331,9 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) ...@@ -327,6 +331,9 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
if (x0) { if (x0) {
left_tc_offset = s->deblock[ctb - 1].tc_offset; left_tc_offset = s->deblock[ctb - 1].tc_offset;
left_beta_offset = s->deblock[ctb - 1].beta_offset; left_beta_offset = s->deblock[ctb - 1].beta_offset;
} else {
left_tc_offset = 0;
left_beta_offset = 0;
} }
x_end = x0 + ctb_size; x_end = x0 + ctb_size;
...@@ -371,22 +378,25 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) ...@@ -371,22 +378,25 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
// vertical filtering chroma // vertical filtering chroma
for (chroma = 1; chroma <= 2; chroma++) { for (chroma = 1; chroma <= 2; chroma++) {
for (y = y0; y < y_end; y += 16) { int h = 1 << s->sps->hshift[chroma];
for (x = x0 ? x0 : 16; x < x_end; x += 16) { int v = 1 << s->sps->vshift[chroma];
const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width]; for (y = y0; y < y_end; y += (8 * v)) {
const int bs1 = s->vertical_bs[(x >> 3) + ((y + 8) >> 2) * s->bs_width]; for (x = x0 ? x0 : 8 * h; x < x_end; x += (8 * h)) {
const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
const int bs1 = s->vertical_bs[(x >> 3) + ((y + (4 * v)) >> 2) * s->bs_width];
if ((bs0 == 2) || (bs1 == 2)) { if ((bs0 == 2) || (bs1 == 2)) {
const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1; const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
const int qp1 = (get_qPy(s, x - 1, y + 8) + get_qPy(s, x, y + 8) + 1) >> 1; const int qp1 = (get_qPy(s, x - 1, y + (4 * v)) + get_qPy(s, x, y + (4 * v)) + 1) >> 1;
c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0; c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0;
src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; src = &s->frame->data[chroma][(y >> s->sps->vshift[chroma]) * s->frame->linesize[chroma] + ((x >> s->sps->hshift[chroma]) << s->sps->pixel_shift)];
if (pcmf) { if (pcmf) {
no_p[0] = get_pcm(s, x - 1, y); no_p[0] = get_pcm(s, x - 1, y);
no_p[1] = get_pcm(s, x - 1, y + 8); no_p[1] = get_pcm(s, x - 1, y + (4 * v));
no_q[0] = get_pcm(s, x, y); no_q[0] = get_pcm(s, x, y);
no_q[1] = get_pcm(s, x, y + 8); no_q[1] = get_pcm(s, x, y + (4 * v));
s->hevcdsp.hevc_v_loop_filter_chroma_c(src, s->hevcdsp.hevc_v_loop_filter_chroma_c(src,
s->frame->linesize[chroma], s->frame->linesize[chroma],
c_tc, no_p, no_q); c_tc, no_p, no_q);
...@@ -436,35 +446,37 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) ...@@ -436,35 +446,37 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
// horizontal filtering chroma // horizontal filtering chroma
for (chroma = 1; chroma <= 2; chroma++) { for (chroma = 1; chroma <= 2; chroma++) {
for (y = y0 ? y0 : 16; y < y_end; y += 16) { int h = 1 << s->sps->hshift[chroma];
for (x = x0 - 8; x < x_end; x += 16) { int v = 1 << s->sps->vshift[chroma];
for (y = y0 ? y0 : 8 * v; y < y_end; y += (8 * v)) {
for (x = x0 - 8; x < x_end; x += (8 * h)) {
int bs0, bs1; int bs0, bs1;
// to make sure no memory access over boundary when x = -8 // to make sure no memory access over boundary when x = -8
// TODO: simplify with row based deblocking // TODO: simplify with row based deblocking
if (x < 0) { if (x < 0) {
bs0 = 0; bs0 = 0;
bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2]; bs1 = s->horizontal_bs[(x + (4 * h) + y * s->bs_width) >> 2];
} else if (x >= x_end - 8) { } else if (x >= x_end - 4 * h) {
bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
bs1 = 0; bs1 = 0;
} else { } else {
bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2]; bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2]; bs1 = s->horizontal_bs[(x + (4 * h) + y * s->bs_width) >> 2];
} }
if ((bs0 == 2) || (bs1 == 2)) { if ((bs0 == 2) || (bs1 == 2)) {
const int qp0 = bs0 == 2 ? (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1 : 0; const int qp0 = bs0 == 2 ? (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1 : 0;
const int qp1 = bs1 == 2 ? (get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1 : 0; const int qp1 = bs1 == 2 ? (get_qPy(s, x + (4 * h), y - 1) + get_qPy(s, x + (4 * h), y) + 1) >> 1 : 0;
tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset; tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
c_tc[0] = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset) : 0; c_tc[0] = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
c_tc[1] = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0; c_tc[1] = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
src = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)]; src = &s->frame->data[chroma][(y >> s->sps->vshift[1]) * s->frame->linesize[chroma] + ((x >> s->sps->hshift[1]) << s->sps->pixel_shift)];
if (pcmf) { if (pcmf) {
no_p[0] = get_pcm(s, x, y - 1); no_p[0] = get_pcm(s, x, y - 1);
no_p[1] = get_pcm(s, x + 8, y - 1); no_p[1] = get_pcm(s, x + (4 * h), y - 1);
no_q[0] = get_pcm(s, x, y); no_q[0] = get_pcm(s, x, y);
no_q[1] = get_pcm(s, x + 8, y); no_q[1] = get_pcm(s, x + (4 * h), y);
s->hevcdsp.hevc_h_loop_filter_chroma_c(src, s->hevcdsp.hevc_h_loop_filter_chroma_c(src,
s->frame->linesize[chroma], s->frame->linesize[chroma],
c_tc, no_p, no_q); c_tc, no_p, no_q);
......
...@@ -207,6 +207,8 @@ static void decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl) ...@@ -207,6 +207,8 @@ static void decode_profile_tier_level(HEVCContext *s, PTLCommon *ptl)
av_log(s->avctx, AV_LOG_DEBUG, "Main 10 profile bitstream\n"); av_log(s->avctx, AV_LOG_DEBUG, "Main 10 profile bitstream\n");
else if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN_STILL_PICTURE) else if (ptl->profile_idc == FF_PROFILE_HEVC_MAIN_STILL_PICTURE)
av_log(s->avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n"); av_log(s->avctx, AV_LOG_DEBUG, "Main Still Picture profile bitstream\n");
else if (ptl->profile_idc == FF_PROFILE_HEVC_REXT)
av_log(s->avctx, AV_LOG_DEBUG, "Range Extension profile bitstream\n");
else else
av_log(s->avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", ptl->profile_idc); av_log(s->avctx, AV_LOG_WARNING, "Unknown HEVC profile: %d\n", ptl->profile_idc);
...@@ -668,8 +670,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) ...@@ -668,8 +670,8 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
} }
sps->chroma_format_idc = get_ue_golomb_long(gb); sps->chroma_format_idc = get_ue_golomb_long(gb);
if (sps->chroma_format_idc != 1) { if (!(sps->chroma_format_idc == 1 || sps->chroma_format_idc == 2 || sps->chroma_format_idc == 3)) {
avpriv_report_missing_feature(s->avctx, "chroma_format_idc != 1\n"); avpriv_report_missing_feature(s->avctx, "chroma_format_idc != {1, 2, 3}\n");
ret = AVERROR_PATCHWELCOME; ret = AVERROR_PATCHWELCOME;
goto err; goto err;
} }
...@@ -677,6 +679,9 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) ...@@ -677,6 +679,9 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
if (sps->chroma_format_idc == 3) if (sps->chroma_format_idc == 3)
sps->separate_colour_plane_flag = get_bits1(gb); sps->separate_colour_plane_flag = get_bits1(gb);
if (sps->separate_colour_plane_flag)
sps->chroma_format_idc = 0;
sps->width = get_ue_golomb_long(gb); sps->width = get_ue_golomb_long(gb);
sps->height = get_ue_golomb_long(gb); sps->height = get_ue_golomb_long(gb);
if ((ret = av_image_check_size(sps->width, if ((ret = av_image_check_size(sps->width,
...@@ -718,20 +723,30 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) ...@@ -718,20 +723,30 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
goto err; goto err;
} }
if (sps->chroma_format_idc == 1) { switch (sps->bit_depth) {
switch (sps->bit_depth) { case 8:
case 8: sps->pix_fmt = AV_PIX_FMT_YUV420P; break; if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P;
case 9: sps->pix_fmt = AV_PIX_FMT_YUV420P9; break; if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P;
case 10: sps->pix_fmt = AV_PIX_FMT_YUV420P10; break; if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P;
default: break;
av_log(s->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", case 9:
sps->bit_depth); if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P9;
ret = AVERROR_PATCHWELCOME; if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P9;
goto err; if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P9;
} break;
} else { case 10:
if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P10;
if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P10;
if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P10;
break;
case 12:
if (sps->chroma_format_idc == 1) sps->pix_fmt = AV_PIX_FMT_YUV420P12;
if (sps->chroma_format_idc == 2) sps->pix_fmt = AV_PIX_FMT_YUV422P12;
if (sps->chroma_format_idc == 3) sps->pix_fmt = AV_PIX_FMT_YUV444P12;
break;
default:
av_log(s->avctx, AV_LOG_ERROR, av_log(s->avctx, AV_LOG_ERROR,
"non-4:2:0 support is currently unspecified.\n"); "4:2:0, 4:2:2, 4:4:4 supports are currently specified for 8, 10 and 12 bits.\n");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
...@@ -862,8 +877,42 @@ int ff_hevc_decode_nal_sps(HEVCContext *s) ...@@ -862,8 +877,42 @@ int ff_hevc_decode_nal_sps(HEVCContext *s)
vui_present = get_bits1(gb); vui_present = get_bits1(gb);
if (vui_present) if (vui_present)
decode_vui(s, sps); decode_vui(s, sps);
skip_bits1(gb); // sps_extension_flag
if (get_bits1(gb)) { // sps_extension_flag
int sps_extension_flag[1];
for (i = 0; i < 1; i++)
sps_extension_flag[i] = get_bits1(gb);
skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
if (sps_extension_flag[0]) {
int extended_precision_processing_flag;
int high_precision_offsets_enabled_flag;
int cabac_bypass_alignment_enabled_flag;
sps->transform_skip_rotation_enabled_flag = get_bits1(gb);
sps->transform_skip_context_enabled_flag = get_bits1(gb);
sps->implicit_rdpcm_enabled_flag = get_bits1(gb);
sps->explicit_rdpcm_enabled_flag = get_bits1(gb);
extended_precision_processing_flag = get_bits1(gb);
if (extended_precision_processing_flag)
av_log(s->avctx, AV_LOG_WARNING,
"extended_precision_processing_flag not yet implemented\n");
sps->intra_smoothing_disabled_flag = get_bits1(gb);
high_precision_offsets_enabled_flag = get_bits1(gb);
if (high_precision_offsets_enabled_flag)
av_log(s->avctx, AV_LOG_WARNING,
"high_precision_offsets_enabled_flag not yet implemented\n");
sps->persistent_rice_adaptation_enabled_flag = get_bits1(gb);
cabac_bypass_alignment_enabled_flag = get_bits1(gb);
if (cabac_bypass_alignment_enabled_flag)
av_log(s->avctx, AV_LOG_WARNING,
"cabac_bypass_alignment_enabled_flag not yet implemented\n");
}
}
if (s->apply_defdispwin) { if (s->apply_defdispwin) {
sps->output_window.left_offset += sps->vui.def_disp_win.left_offset; 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.right_offset += sps->vui.def_disp_win.right_offset;
...@@ -997,6 +1046,46 @@ static void hevc_pps_free(void *opaque, uint8_t *data) ...@@ -997,6 +1046,46 @@ static void hevc_pps_free(void *opaque, uint8_t *data)
av_freep(&pps); av_freep(&pps);
} }
static int pps_range_extensions(HEVCContext *s, HEVCPPS *pps, HEVCSPS *sps) {
GetBitContext *gb = &s->HEVClc->gb;
int i;
if (pps->transform_skip_enabled_flag) {
pps->log2_max_transform_skip_block_size = get_ue_golomb_long(gb) + 2;
}
pps->cross_component_prediction_enabled_flag = get_bits1(gb);
if (pps->cross_component_prediction_enabled_flag) {
av_log(s->avctx, AV_LOG_WARNING,
"cross_component_prediction_enabled_flag is not yet implemented.\n");
}
pps->chroma_qp_offset_list_enabled_flag = get_bits1(gb);
if (pps->chroma_qp_offset_list_enabled_flag) {
pps->diff_cu_chroma_qp_offset_depth = get_ue_golomb_long(gb);
pps->chroma_qp_offset_list_len_minus1 = get_ue_golomb_long(gb);
if (pps->chroma_qp_offset_list_len_minus1 && pps->chroma_qp_offset_list_len_minus1 >= 5) {
av_log(s->avctx, AV_LOG_ERROR,
"chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
return AVERROR_INVALIDDATA;
}
for (i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
pps->cb_qp_offset_list[i] = get_se_golomb_long(gb);
if (pps->cb_qp_offset_list[i]) {
av_log(s->avctx, AV_LOG_WARNING,
"cb_qp_offset_list not tested yet.\n");
}
pps->cr_qp_offset_list[i] = get_se_golomb_long(gb);
if (pps->cr_qp_offset_list[i]) {
av_log(s->avctx, AV_LOG_WARNING,
"cb_qp_offset_list not tested yet.\n");
}
}
}
pps->log2_sao_offset_scale_luma = get_ue_golomb_long(gb);
pps->log2_sao_offset_scale_chroma = get_ue_golomb_long(gb);
return(0);
}
int ff_hevc_decode_nal_pps(HEVCContext *s) int ff_hevc_decode_nal_pps(HEVCContext *s)
{ {
GetBitContext *gb = &s->HEVClc->gb; GetBitContext *gb = &s->HEVClc->gb;
...@@ -1030,6 +1119,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) ...@@ -1030,6 +1119,7 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
pps->disable_dbf = 0; pps->disable_dbf = 0;
pps->beta_offset = 0; pps->beta_offset = 0;
pps->tc_offset = 0; pps->tc_offset = 0;
pps->log2_max_transform_skip_block_size = 2;
// Coded parameters // Coded parameters
pps_id = get_ue_golomb_long(gb); pps_id = get_ue_golomb_long(gb);
...@@ -1190,7 +1280,16 @@ int ff_hevc_decode_nal_pps(HEVCContext *s) ...@@ -1190,7 +1280,16 @@ int ff_hevc_decode_nal_pps(HEVCContext *s)
} }
pps->slice_header_extension_present_flag = get_bits1(gb); pps->slice_header_extension_present_flag = get_bits1(gb);
skip_bits1(gb); // pps_extension_flag
if (get_bits1(gb)) { // pps_extension_present_flag
int pps_range_extensions_flag = get_bits1(gb);
/* int pps_extension_7bits = */ get_bits(gb, 7);
if (sps->ptl.general_ptl.profile_idc == FF_PROFILE_HEVC_REXT && pps_range_extensions_flag) {
av_log(s->avctx, AV_LOG_ERROR,
"PPS extension flag is partially implemented.\n");
pps_range_extensions(s, pps, sps);
}
}
// Inferred parameters // Inferred parameters
pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd)); pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd));
......
...@@ -119,6 +119,10 @@ DECLARE_ALIGNED(16, const int8_t, ff_hevc_qpel_filters[3][16]) = { ...@@ -119,6 +119,10 @@ DECLARE_ALIGNED(16, const int8_t, ff_hevc_qpel_filters[3][16]) = {
#include "hevcdsp_template.c" #include "hevcdsp_template.c"
#undef BIT_DEPTH #undef BIT_DEPTH
#define BIT_DEPTH 12
#include "hevcdsp_template.c"
#undef BIT_DEPTH
void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth) void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
{ {
#undef FUNC #undef FUNC
...@@ -235,6 +239,9 @@ int i = 0; ...@@ -235,6 +239,9 @@ int i = 0;
case 10: case 10:
HEVC_DSP(10); HEVC_DSP(10);
break; break;
case 12:
HEVC_DSP(12);
break;
default: default:
HEVC_DSP(8); HEVC_DSP(8);
break; break;
......
...@@ -41,8 +41,8 @@ typedef struct SAOParams { ...@@ -41,8 +41,8 @@ typedef struct SAOParams {
} SAOParams; } SAOParams;
typedef struct HEVCDSPContext { typedef struct HEVCDSPContext {
void (*put_pcm)(uint8_t *dst, ptrdiff_t stride, int size, void (*put_pcm)(uint8_t *_dst, ptrdiff_t _stride, int width, int height,
GetBitContext *gb, int pcm_bit_depth); struct GetBitContext *gb, int pcm_bit_depth);
void (*transform_add[4])(uint8_t *_dst, int16_t *coeffs, ptrdiff_t _stride); void (*transform_add[4])(uint8_t *_dst, int16_t *coeffs, ptrdiff_t _stride);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "hevcdsp.h" #include "hevcdsp.h"
static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int size, static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int width, int height,
GetBitContext *gb, int pcm_bit_depth) GetBitContext *gb, int pcm_bit_depth)
{ {
int x, y; int x, y;
...@@ -35,8 +35,8 @@ static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int size, ...@@ -35,8 +35,8 @@ static void FUNC(put_pcm)(uint8_t *_dst, ptrdiff_t stride, int size,
stride /= sizeof(pixel); stride /= sizeof(pixel);
for (y = 0; y < size; y++) { for (y = 0; y < height; y++) {
for (x = 0; x < size; x++) for (x = 0; x < width; x++)
dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth); dst[x] = get_bits(gb, pcm_bit_depth) << (BIT_DEPTH - pcm_bit_depth);
dst += stride; dst += stride;
} }
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
#include "hevcpred_template.c" #include "hevcpred_template.c"
#undef BIT_DEPTH #undef BIT_DEPTH
#define BIT_DEPTH 12
#include "hevcpred_template.c"
#undef BIT_DEPTH
void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth) void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth)
{ {
#undef FUNC #undef FUNC
...@@ -63,6 +67,9 @@ void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth) ...@@ -63,6 +67,9 @@ void ff_hevc_pred_init(HEVCPredContext *hpc, int bit_depth)
case 10: case 10:
HEVC_PRED(10); HEVC_PRED(10);
break; break;
case 12:
HEVC_PRED(12);
break;
default: default:
HEVC_PRED(8); HEVC_PRED(8);
break; break;
......
...@@ -91,8 +91,8 @@ do { \ ...@@ -91,8 +91,8 @@ do { \
int min_pu_width = s->sps->min_pu_width; int min_pu_width = s->sps->min_pu_width;
enum IntraPredMode mode = c_idx ? lc->pu.intra_pred_mode_c : enum IntraPredMode mode = c_idx ? lc->tu.intra_pred_mode_c :
lc->tu.cur_intra_pred_mode; lc->tu.intra_pred_mode;
pixel4 a; pixel4 a;
pixel left_array[2 * MAX_TB_SIZE + 1]; pixel left_array[2 * MAX_TB_SIZE + 1];
pixel filtered_left_array[2 * MAX_TB_SIZE + 1]; pixel filtered_left_array[2 * MAX_TB_SIZE + 1];
...@@ -207,7 +207,6 @@ do { \ ...@@ -207,7 +207,6 @@ do { \
j++; j++;
EXTEND_LEFT_CIP(top, j, j + 1); EXTEND_LEFT_CIP(top, j, j + 1);
left[-1] = top[-1]; left[-1] = top[-1];
j = 0;
} }
} else { } else {
j = 0; j = 0;
...@@ -221,7 +220,6 @@ do { \ ...@@ -221,7 +220,6 @@ do { \
top[-1] = top[0]; top[-1] = top[0];
} }
left[-1] = top[-1]; left[-1] = top[-1];
j = 0;
} }
left[-1] = top[-1]; left[-1] = top[-1];
if (cand_bottom_left || cand_left) { if (cand_bottom_left || cand_left) {
...@@ -238,7 +236,6 @@ do { \ ...@@ -238,7 +236,6 @@ do { \
if (!IS_INTRA(-1, - 1)) if (!IS_INTRA(-1, - 1))
left[-1] = left[0]; left[-1] = left[0];
} else if (x0 == 0) { } else if (x0 == 0) {
a = PIXEL_SPLAT_X4(left[size_max_y - 1]);
EXTEND(left, 0, size_max_y); EXTEND(left, 0, size_max_y);
} else { } else {
a = PIXEL_SPLAT_X4(left[size_max_y - 1]); a = PIXEL_SPLAT_X4(left[size_max_y - 1]);
...@@ -290,7 +287,7 @@ do { \ ...@@ -290,7 +287,7 @@ do { \
top[-1] = left[-1]; top[-1] = left[-1];
// Filtering process // Filtering process
if (c_idx == 0) { if (!s->sps->intra_smoothing_disabled_flag && (c_idx == 0 || s->sps->chroma_format_idc == 3)) {
if (mode != INTRA_DC && size != 4){ if (mode != INTRA_DC && size != 4){
int intra_hor_ver_dist_thresh[] = { 7, 1, 0 }; int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)), int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment