* [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free()
@ 2024-06-07 13:00 Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 02/39] lavc/hevcdec: simplify condition Anton Khirnov
` (37 more replies)
0 siblings, 38 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:00 UTC (permalink / raw)
To: ffmpeg-devel
SliceHeader.{entry_point_offset,size,offset} are not derived from frame
size and do not need to be freed here.
---
libavcodec/hevc/hevcdec.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 4e0df4d033..d317c1471a 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -84,10 +84,6 @@ static void pic_arrays_free(HEVCContext *s)
av_freep(&s->horizontal_bs);
av_freep(&s->vertical_bs);
- av_freep(&s->sh.entry_point_offset);
- av_freep(&s->sh.size);
- av_freep(&s->sh.offset);
-
ff_refstruct_pool_uninit(&s->tab_mvf_pool);
ff_refstruct_pool_uninit(&s->rpl_tab_pool);
}
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 02/39] lavc/hevcdec: simplify condition
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
@ 2024-06-07 13:00 ` Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 03/39] lavc/hevcdec: drop a redundant assignment in hevc_decode_frame() Anton Khirnov
` (36 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:00 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/hevc/hevcdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d317c1471a..43cbc45062 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3115,7 +3115,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
ctb_addr_ts = hls_slice_data_wpp(s, nal);
else
ctb_addr_ts = hls_decode_entry(s, &gb);
- if (ctb_addr_ts >= (s->ps.sps->ctb_width * s->ps.sps->ctb_height)) {
+ if (ctb_addr_ts >= s->cur_frame->ctb_count) {
ret = hevc_frame_end(s);
if (ret < 0)
goto fail;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 03/39] lavc/hevcdec: drop a redundant assignment in hevc_decode_frame()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 02/39] lavc/hevcdec: simplify condition Anton Khirnov
@ 2024-06-07 13:00 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 04/39] lavc/hevc_ps: make PPS hold a reference to its SPS Anton Khirnov
` (35 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:00 UTC (permalink / raw)
To: ffmpeg-devel
The exact same code is executed at the beginning of decode_nal_units()
---
libavcodec/hevc/hevcdec.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 43cbc45062..46db7923fe 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3369,7 +3369,6 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
old, s->dovi_ctx.cfg.dv_profile);
}
- s->cur_frame = s->collocated_ref = NULL;
ret = decode_nal_units(s, avpkt->data, avpkt->size);
if (ret < 0)
return ret;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 04/39] lavc/hevc_ps: make PPS hold a reference to its SPS
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 02/39] lavc/hevcdec: simplify condition Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 03/39] lavc/hevcdec: drop a redundant assignment in hevc_decode_frame() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 05/39] lavc/hevc_ps: make SPS hold a reference to its VPS Anton Khirnov
` (34 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
PPS depends on, and is parsed for, specific SPS data.
This will be useful in following commits.
---
libavcodec/hevc/hevcdec.c | 4 ++--
libavcodec/hevc/parser.c | 8 ++------
libavcodec/hevc/ps.c | 4 ++++
libavcodec/hevc/ps.h | 2 ++
4 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 46db7923fe..ae4a5888e5 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -625,8 +625,8 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
sh->no_output_of_prior_pics_flag = 1;
- if (s->ps.sps != s->ps.sps_list[s->ps.pps->sps_id]) {
- const HEVCSPS *sps = s->ps.sps_list[s->ps.pps->sps_id];
+ if (s->ps.sps != s->ps.pps->sps) {
+ const HEVCSPS *sps = s->ps.pps->sps;
enum AVPixelFormat pix_fmt;
ff_hevc_clear_refs(s);
diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index 056e1b4aa4..d0d5e7fbc2 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -80,12 +80,8 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
}
ps->pps = ps->pps_list[pps_id];
- if (ps->pps->sps_id >= HEVC_MAX_SPS_COUNT || !ps->sps_list[ps->pps->sps_id]) {
- av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", ps->pps->sps_id);
- return AVERROR_INVALIDDATA;
- }
- if (ps->sps != ps->sps_list[ps->pps->sps_id]) {
- ps->sps = ps->sps_list[ps->pps->sps_id];
+ if (ps->sps != ps->pps->sps) {
+ ps->sps = ps->pps->sps;
ps->vps = ps->vps_list[ps->sps->vps_id];
}
ow = &ps->sps->output_window;
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 2dd4f834a4..98217e337b 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -1363,6 +1363,8 @@ static void hevc_pps_free(FFRefStructOpaque unused, void *obj)
{
HEVCPPS *pps = obj;
+ ff_refstruct_unref(&pps->sps);
+
av_freep(&pps->column_width);
av_freep(&pps->row_height);
av_freep(&pps->col_bd);
@@ -1828,6 +1830,8 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
sps = ps->sps_list[pps->sps_id];
vps = ps->vps_list[sps->vps_id];
+ pps->sps = ff_refstruct_ref_c(sps);
+
pps->dependent_slice_segments_enabled_flag = get_bits1(gb);
pps->output_flag_present_flag = get_bits1(gb);
pps->num_extra_slice_header_bits = get_bits(gb, 3);
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 99d70cefd2..7c9aacf057 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -437,6 +437,8 @@ typedef struct HEVCPPS {
uint8_t *data;
int data_size;
+
+ const HEVCSPS *sps; ///< RefStruct reference
} HEVCPPS;
typedef struct HEVCParamSets {
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 05/39] lavc/hevc_ps: make SPS hold a reference to its VPS
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (2 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 04/39] lavc/hevc_ps: make PPS hold a reference to its SPS Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 06/39] lavc/hevc/parser: stop using HEVCParamSets.[psv]ps Anton Khirnov
` (33 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
SPS and its dependent PPSes depend on, and are parsed for, specific VPS data.
This will be useful in following commits.
---
libavcodec/hevc/hevcdec.c | 5 ++---
libavcodec/hevc/parser.c | 2 +-
libavcodec/hevc/ps.c | 13 +++++++++----
libavcodec/hevc/ps.h | 2 ++
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index ae4a5888e5..16c46997a8 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -319,8 +319,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
{
AVCodecContext *avctx = s->avctx;
- const HEVCParamSets *ps = &s->ps;
- const HEVCVPS *vps = ps->vps_list[sps->vps_id];
+ const HEVCVPS *vps = sps->vps;
const HEVCWindow *ow = &sps->output_window;
unsigned int num = 0, den = 0;
@@ -575,7 +574,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
}
s->ps.sps = sps;
- s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id];
+ s->ps.vps = sps->vps;
return 0;
diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index d0d5e7fbc2..49f7bccdfa 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -82,7 +82,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
if (ps->sps != ps->pps->sps) {
ps->sps = ps->pps->sps;
- ps->vps = ps->vps_list[ps->sps->vps_id];
+ ps->vps = ps->sps->vps;
}
ow = &ps->sps->output_window;
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 98217e337b..eabed69b94 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -889,10 +889,13 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
sps->vps_id = get_bits(gb, 4);
- if (vps_list && !vps_list[sps->vps_id]) {
- av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
- sps->vps_id);
- return AVERROR_INVALIDDATA;
+ if (vps_list) {
+ if (!vps_list[sps->vps_id]) {
+ av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
+ sps->vps_id);
+ return AVERROR_INVALIDDATA;
+ }
+ sps->vps = ff_refstruct_ref_c(vps_list[sps->vps_id]);
}
sps->max_sub_layers = get_bits(gb, 3) + 1;
@@ -1298,6 +1301,8 @@ static void hevc_sps_free(FFRefStructOpaque opaque, void *obj)
{
HEVCSPS *sps = obj;
+ ff_refstruct_unref(&sps->vps);
+
av_freep(&sps->data);
}
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 7c9aacf057..fc10876756 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -302,6 +302,8 @@ typedef struct HEVCSPS {
uint8_t *data;
int data_size;
+
+ const HEVCVPS *vps; ///< RefStruct reference
} HEVCSPS;
typedef struct HEVCPPS {
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 06/39] lavc/hevc/parser: stop using HEVCParamSets.[psv]ps
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (3 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 05/39] lavc/hevc_ps: make SPS hold a reference to its VPS Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 07/39] lavc/hevc/mvs: stop accessing parameter sets through HEVCParamSets Anton Khirnov
` (32 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
The parser does not need to preserve these between frames.
---
libavcodec/hevc/parser.c | 55 ++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index 49f7bccdfa..f4e6e3c36d 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -58,6 +58,8 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
HEVCParamSets *ps = &ctx->ps;
HEVCSEI *sei = &ctx->sei;
GetBitContext *gb = &nal->gb;
+ const HEVCPPS *pps;
+ const HEVCSPS *sps;
const HEVCWindow *ow;
int i, num = 0, den = 0;
@@ -78,28 +80,25 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
return AVERROR_INVALIDDATA;
}
- ps->pps = ps->pps_list[pps_id];
+ pps = ps->pps_list[pps_id];
+ sps = pps->sps;
- if (ps->sps != ps->pps->sps) {
- ps->sps = ps->pps->sps;
- ps->vps = ps->sps->vps;
- }
- ow = &ps->sps->output_window;
+ ow = &sps->output_window;
- s->coded_width = ps->sps->width;
- s->coded_height = ps->sps->height;
- s->width = ps->sps->width - ow->left_offset - ow->right_offset;
- s->height = ps->sps->height - ow->top_offset - ow->bottom_offset;
- s->format = ps->sps->pix_fmt;
- avctx->profile = ps->sps->ptl.general_ptl.profile_idc;
- avctx->level = ps->sps->ptl.general_ptl.level_idc;
+ s->coded_width = sps->width;
+ s->coded_height = sps->height;
+ s->width = sps->width - ow->left_offset - ow->right_offset;
+ s->height = sps->height - ow->top_offset - ow->bottom_offset;
+ s->format = sps->pix_fmt;
+ avctx->profile = sps->ptl.general_ptl.profile_idc;
+ avctx->level = sps->ptl.general_ptl.level_idc;
- if (ps->vps->vps_timing_info_present_flag) {
- num = ps->vps->vps_num_units_in_tick;
- den = ps->vps->vps_time_scale;
- } else if (ps->sps->vui.vui_timing_info_present_flag) {
- num = ps->sps->vui.vui_num_units_in_tick;
- den = ps->sps->vui.vui_time_scale;
+ if (sps->vps->vps_timing_info_present_flag) {
+ num = sps->vps->vps_num_units_in_tick;
+ den = sps->vps->vps_time_scale;
+ } else if (sps->vui.vui_timing_info_present_flag) {
+ num = sps->vui.vui_num_units_in_tick;
+ den = sps->vui.vui_time_scale;
}
if (num != 0 && den != 0)
@@ -110,15 +109,15 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
unsigned int slice_segment_addr;
int slice_address_length;
- if (ps->pps->dependent_slice_segments_enabled_flag)
+ if (pps->dependent_slice_segments_enabled_flag)
dependent_slice_segment_flag = get_bits1(gb);
else
dependent_slice_segment_flag = 0;
- slice_address_length = av_ceil_log2_c(ps->sps->ctb_width *
- ps->sps->ctb_height);
+ slice_address_length = av_ceil_log2_c(sps->ctb_width *
+ sps->ctb_height);
slice_segment_addr = get_bitsz(gb, slice_address_length);
- if (slice_segment_addr >= ps->sps->ctb_width * ps->sps->ctb_height) {
+ if (slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n",
slice_segment_addr);
return AVERROR_INVALIDDATA;
@@ -129,7 +128,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
if (dependent_slice_segment_flag)
return 0; /* break; */
- for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++)
+ for (i = 0; i < pps->num_extra_slice_header_bits; i++)
skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
slice_type = get_ue_golomb_31(gb);
@@ -143,16 +142,16 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
slice_type == HEVC_SLICE_P ? AV_PICTURE_TYPE_P :
AV_PICTURE_TYPE_I;
- if (ps->pps->output_flag_present_flag)
+ if (pps->output_flag_present_flag)
skip_bits1(gb); // pic_output_flag
- if (ps->sps->separate_colour_plane)
+ if (sps->separate_colour_plane)
skip_bits(gb, 2); // colour_plane_id
if (!IS_IDR_NAL(nal)) {
- int pic_order_cnt_lsb = get_bits(gb, ps->sps->log2_max_poc_lsb);
+ int pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
s->output_picture_number = ctx->poc =
- ff_hevc_compute_poc(ps->sps, ctx->pocTid0, pic_order_cnt_lsb, nal->type);
+ ff_hevc_compute_poc(sps, ctx->pocTid0, pic_order_cnt_lsb, nal->type);
} else
s->output_picture_number = ctx->poc = 0;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 07/39] lavc/hevc/mvs: stop accessing parameter sets through HEVCParamSets
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (4 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 06/39] lavc/hevc/parser: stop using HEVCParamSets.[psv]ps Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 08/39] lavc/hevc/filter: " Anton Khirnov
` (31 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Instead, accept PPS as a function argument and retrieve SPS through it.
Makes the code shorter and significantly reduces diff in future commits.
---
libavcodec/hevc/hevcdec.c | 28 +++++----
libavcodec/hevc/hevcdec.h | 8 ++-
libavcodec/hevc/mvs.c | 126 ++++++++++++++++++++------------------
3 files changed, 87 insertions(+), 75 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 16c46997a8..5de229f78d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1158,7 +1158,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.pred_mode == MODE_INTRA) {
int trafo_size = 1 << log2_trafo_size;
- ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size);
+ ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size - 2](lc, x0, y0, 0);
}
@@ -1245,7 +1245,8 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
}
for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
- ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c), trafo_size_h, trafo_size_v);
+ ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 1);
}
if (cbf_cb[i])
@@ -1275,7 +1276,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
- trafo_size_h, trafo_size_v);
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 2);
}
if (cbf_cr[i])
@@ -1304,7 +1305,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
- trafo_size_h, trafo_size_v);
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 1);
}
if (cbf_cb[i])
@@ -1314,7 +1315,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
- trafo_size_h, trafo_size_v);
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 2);
}
if (cbf_cr[i])
@@ -1326,12 +1327,13 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) {
int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
- ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v);
+ ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
+ s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 1);
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 2);
if (s->ps.sps->chroma_format_idc == 2) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
- trafo_size_h, trafo_size_v);
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (1 << log2_trafo_size_c), 1);
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (1 << log2_trafo_size_c), 2);
}
@@ -1339,12 +1341,12 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
int trafo_size_h = 1 << (log2_trafo_size + 1);
int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
ff_hevc_set_neighbour_available(lc, xBase, yBase,
- trafo_size_h, trafo_size_v);
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase, 1);
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase, 2);
if (s->ps.sps->chroma_format_idc == 2) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
- trafo_size_h, trafo_size_v);
+ trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (1 << log2_trafo_size), 1);
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (1 << log2_trafo_size), 2);
}
@@ -1880,7 +1882,7 @@ static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW
enum InterPredIdc inter_pred_idc = PRED_L0;
int mvp_flag;
- ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH);
+ ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, s->ps.sps->log2_ctb_size);
mv->pred_flag = 0;
if (s->sh.slice_type == HEVC_SLICE_B)
inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
@@ -1892,7 +1894,7 @@ static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW
mv->pred_flag = PF_L0;
ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
- ff_hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_luma_mv_mvp_mode(lc, s->ps.pps, x0, y0, nPbW, nPbH, log2_cb_size,
part_idx, merge_idx, mv, mvp_flag, 0);
mv->mv[0].x += lc->pu.mvd.x;
mv->mv[0].y += lc->pu.mvd.y;
@@ -1910,7 +1912,7 @@ static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW
mv->pred_flag += PF_L1;
mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
- ff_hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_luma_mv_mvp_mode(lc, s->ps.pps, x0, y0, nPbW, nPbH, log2_cb_size,
part_idx, merge_idx, mv, mvp_flag, 1);
mv->mv[1].x += lc->pu.mvd.x;
mv->mv[1].y += lc->pu.mvd.y;
@@ -1955,7 +1957,7 @@ static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
else
merge_idx = 0;
- ff_hevc_luma_mv_merge_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_luma_mv_merge_mode(lc, s->ps.pps, x0, y0, nPbW, nPbH, log2_cb_size,
partIdx, merge_idx, ¤t_mv);
} else {
hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size,
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 33ad4ac0aa..eef7d66204 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -645,11 +645,13 @@ void ff_hevc_bump_frame(HEVCContext *s);
void ff_hevc_unref_frame(HEVCFrame *frame, int flags);
void ff_hevc_set_neighbour_available(HEVCLocalContext *lc, int x0, int y0,
- int nPbW, int nPbH);
-void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, int x0, int y0,
+ int nPbW, int nPbH, int log2_ctb_size);
+void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, const HEVCPPS *pps,
+ 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(HEVCLocalContext *lc, int x0, int y0,
+void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps,
+ 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);
diff --git a/libavcodec/hevc/mvs.c b/libavcodec/hevc/mvs.c
index b56f0bece5..3fd7be5b32 100644
--- a/libavcodec/hevc/mvs.c
+++ b/libavcodec/hevc/mvs.c
@@ -41,17 +41,16 @@ static const uint8_t l0_l1_cand_idx[12][2] = {
};
void ff_hevc_set_neighbour_available(HEVCLocalContext *lc, int x0, int y0,
- int nPbW, int nPbH)
+ int nPbW, int nPbH, int log2_ctb_size)
{
- const HEVCContext *const s = lc->parent;
- int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
- int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
+ int x0b = av_mod_uintp2(x0, log2_ctb_size);
+ int y0b = av_mod_uintp2(y0, log2_ctb_size);
lc->na.cand_up = (lc->ctb_up_flag || y0b);
lc->na.cand_left = (lc->ctb_left_flag || x0b);
lc->na.cand_up_left = (x0b || y0b) ? lc->na.cand_left && lc->na.cand_up : lc->ctb_up_left_flag;
lc->na.cand_up_right_sap =
- (x0b + nPbW == 1 << s->ps.sps->log2_ctb_size) ?
+ (x0b + nPbW == 1 << log2_ctb_size) ?
lc->ctb_up_right_flag && !y0b : lc->na.cand_up;
lc->na.cand_up_right =
lc->na.cand_up_right_sap
@@ -62,31 +61,32 @@ void ff_hevc_set_neighbour_available(HEVCLocalContext *lc, int x0, int y0,
/*
* 6.4.1 Derivation process for z-scan order block availability
*/
-static av_always_inline int z_scan_block_avail(const HEVCContext *s, int xCurr, int yCurr,
- int xN, int yN)
+static av_always_inline int
+z_scan_block_avail(const HEVCPPS *pps, const HEVCSPS *sps,
+ int xCurr, int yCurr, int xN, int yN)
{
#define MIN_TB_ADDR_ZS(x, y) \
- s->ps.pps->min_tb_addr_zs[(y) * (s->ps.sps->tb_mask+2) + (x)]
+ pps->min_tb_addr_zs[(y) * (sps->tb_mask+2) + (x)]
- int xCurr_ctb = xCurr >> s->ps.sps->log2_ctb_size;
- int yCurr_ctb = yCurr >> s->ps.sps->log2_ctb_size;
- int xN_ctb = xN >> s->ps.sps->log2_ctb_size;
- int yN_ctb = yN >> s->ps.sps->log2_ctb_size;
+ int xCurr_ctb = xCurr >> sps->log2_ctb_size;
+ int yCurr_ctb = yCurr >> sps->log2_ctb_size;
+ int xN_ctb = xN >> sps->log2_ctb_size;
+ int yN_ctb = yN >> sps->log2_ctb_size;
if( yN_ctb < yCurr_ctb || xN_ctb < xCurr_ctb )
return 1;
else {
- int Curr = MIN_TB_ADDR_ZS((xCurr >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask,
- (yCurr >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask);
- int N = MIN_TB_ADDR_ZS((xN >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask,
- (yN >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask);
+ int Curr = MIN_TB_ADDR_ZS((xCurr >> sps->log2_min_tb_size) & sps->tb_mask,
+ (yCurr >> sps->log2_min_tb_size) & sps->tb_mask);
+ int N = MIN_TB_ADDR_ZS((xN >> sps->log2_min_tb_size) & sps->tb_mask,
+ (yN >> sps->log2_min_tb_size) & sps->tb_mask);
return N <= Curr;
}
}
//check if the two luma locations belong to the same motion estimation region
-static av_always_inline int is_diff_mer(const HEVCContext *s, int xN, int yN, int xP, int yP)
+static av_always_inline int is_diff_mer(const HEVCPPS *pps, int xN, int yN, int xP, int yP)
{
- uint8_t plevel = s->ps.pps->log2_parallel_merge_level;
+ uint8_t plevel = pps->log2_parallel_merge_level;
return xN >> plevel == xP >> plevel &&
yN >> plevel == yP >> plevel;
@@ -205,8 +205,8 @@ static int derive_temporal_colocated_mvs(const HEVCContext *s, MvField temp_col,
tab_mvf[(y) * min_pu_width + x]
#define TAB_MVF_PU(v) \
- TAB_MVF(((x ## v) >> s->ps.sps->log2_min_pu_size), \
- ((y ## v) >> s->ps.sps->log2_min_pu_size))
+ TAB_MVF(((x ## v) >> sps->log2_min_pu_size), \
+ ((y ## v) >> sps->log2_min_pu_size))
#define DERIVE_TEMPORAL_COLOCATED_MVS \
derive_temporal_colocated_mvs(s, temp_col, \
@@ -216,14 +216,15 @@ static int derive_temporal_colocated_mvs(const HEVCContext *s, MvField temp_col,
/*
* 8.5.3.1.7 temporal luma motion vector prediction
*/
-static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0,
+static int temporal_luma_motion_vector(const HEVCContext *s, const HEVCSPS *sps,
+ int x0, int y0,
int nPbW, int nPbH, int refIdxLx,
Mv *mvLXCol, int X)
{
const MvField *tab_mvf;
MvField temp_col;
int x, y, x_pu, y_pu;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
int availableFlagLXCol = 0;
int colPic;
@@ -242,15 +243,15 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0,
y = y0 + nPbH;
if (tab_mvf &&
- (y0 >> s->ps.sps->log2_ctb_size) == (y >> s->ps.sps->log2_ctb_size) &&
- y < s->ps.sps->height &&
- x < s->ps.sps->width) {
+ (y0 >> sps->log2_ctb_size) == (y >> sps->log2_ctb_size) &&
+ y < sps->height &&
+ x < sps->width) {
x &= ~15;
y &= ~15;
if (s->threads_type == FF_THREAD_FRAME)
ff_progress_frame_await(&ref->tf, y);
- x_pu = x >> s->ps.sps->log2_min_pu_size;
- y_pu = y >> s->ps.sps->log2_min_pu_size;
+ x_pu = x >> sps->log2_min_pu_size;
+ y_pu = y >> sps->log2_min_pu_size;
temp_col = TAB_MVF(x_pu, y_pu);
availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS;
}
@@ -263,8 +264,8 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0,
y &= ~15;
if (s->threads_type == FF_THREAD_FRAME)
ff_progress_frame_await(&ref->tf, y);
- x_pu = x >> s->ps.sps->log2_min_pu_size;
- y_pu = y >> s->ps.sps->log2_min_pu_size;
+ x_pu = x >> sps->log2_min_pu_size;
+ y_pu = y >> sps->log2_min_pu_size;
temp_col = TAB_MVF(x_pu, y_pu);
availableFlagLXCol = DERIVE_TEMPORAL_COLOCATED_MVS;
}
@@ -275,7 +276,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0,
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
#define PRED_BLOCK_AVAILABLE(v) \
- z_scan_block_avail(s, x0, y0, x ## v, y ## v)
+ z_scan_block_avail(pps, sps, x0, y0, x ## v, y ## v)
#define COMPARE_MV_REFIDX(a, b) \
compare_mv_ref_idx(TAB_MVF_PU(a), TAB_MVF_PU(b))
@@ -284,6 +285,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0,
* 8.5.3.1.2 Derivation process for spatial merging candidates
*/
static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCContext *s,
+ const HEVCPPS *pps, const HEVCSPS *sps,
int x0, int y0,
int nPbW, int nPbH,
int log2_cb_size,
@@ -294,7 +296,7 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
const RefPicList *refPicList = s->cur_frame->refPicList;
const MvField *tab_mvf = s->cur_frame->tab_mvf;
- const int min_pu_width = s->ps.sps->min_pu_width;
+ const int min_pu_width = sps->min_pu_width;
const int cand_bottom_left = lc->na.cand_bottom_left;
const int cand_left = lc->na.cand_left;
@@ -336,7 +338,7 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
(lc->cu.part_mode == PART_Nx2N ||
lc->cu.part_mode == PART_nLx2N ||
lc->cu.part_mode == PART_nRx2N) ||
- is_diff_mer(s, xA1, yA1, x0, y0)) {
+ is_diff_mer(pps, xA1, yA1, x0, y0)) {
is_available_a1 = 0;
} else {
is_available_a1 = AVAILABLE(cand_left, A1);
@@ -352,7 +354,7 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
(lc->cu.part_mode == PART_2NxN ||
lc->cu.part_mode == PART_2NxnU ||
lc->cu.part_mode == PART_2NxnD) ||
- is_diff_mer(s, xB1, yB1, x0, y0)) {
+ is_diff_mer(pps, xB1, yB1, x0, y0)) {
is_available_b1 = 0;
} else {
is_available_b1 = AVAILABLE(cand_up, B1);
@@ -367,9 +369,9 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
// above right spatial merge candidate
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
- xB0 < s->ps.sps->width &&
+ xB0 < sps->width &&
PRED_BLOCK_AVAILABLE(B0) &&
- !is_diff_mer(s, xB0, yB0, x0, y0);
+ !is_diff_mer(pps, xB0, yB0, x0, y0);
if (is_available_b0 &&
!(is_available_b1 && COMPARE_MV_REFIDX(B0, B1))) {
@@ -381,9 +383,9 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
// left bottom spatial merge candidate
is_available_a0 = AVAILABLE(cand_bottom_left, A0) &&
- yA0 < s->ps.sps->height &&
+ yA0 < sps->height &&
PRED_BLOCK_AVAILABLE(A0) &&
- !is_diff_mer(s, xA0, yA0, x0, y0);
+ !is_diff_mer(pps, xA0, yA0, x0, y0);
if (is_available_a0 &&
!(is_available_a1 && COMPARE_MV_REFIDX(A0, A1))) {
@@ -395,7 +397,7 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
// above left spatial merge candidate
is_available_b2 = AVAILABLE(cand_up_left, B2) &&
- !is_diff_mer(s, xB2, yB2, x0, y0);
+ !is_diff_mer(pps, xB2, yB2, x0, y0);
if (is_available_b2 &&
!(is_available_a1 && COMPARE_MV_REFIDX(B2, A1)) &&
@@ -411,10 +413,10 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
if (s->sh.slice_temporal_mvp_enabled_flag &&
nb_merge_cand < s->sh.max_num_merge_cand) {
Mv mv_l0_col = { 0 }, mv_l1_col = { 0 };
- int available_l0 = temporal_luma_motion_vector(s, x0, y0, nPbW, nPbH,
+ int available_l0 = temporal_luma_motion_vector(s, sps, x0, y0, nPbW, nPbH,
0, &mv_l0_col, 0);
int available_l1 = (s->sh.slice_type == HEVC_SLICE_B) ?
- temporal_luma_motion_vector(s, x0, y0, nPbW, nPbH,
+ temporal_luma_motion_vector(s, sps, x0, y0, nPbW, nPbH,
0, &mv_l1_col, 1) : 0;
if (available_l0 || available_l1) {
@@ -477,10 +479,12 @@ static void derive_spatial_merge_candidates(HEVCLocalContext *lc, const HEVCCont
/*
* 8.5.3.1.1 Derivation process of luma Mvs for merge mode
*/
-void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
+void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0, int nPbW,
int nPbH, int log2_cb_size, int part_idx,
int merge_idx, MvField *mv)
{
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
int singleMCLFlag = 0;
int nCS = 1 << log2_cb_size;
@@ -488,7 +492,7 @@ void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
int nPbW2 = nPbW;
int nPbH2 = nPbH;
- if (s->ps.pps->log2_parallel_merge_level > 2 && nCS == 8) {
+ if (pps->log2_parallel_merge_level > 2 && nCS == 8) {
singleMCLFlag = 1;
x0 = lc->cu.x;
y0 = lc->cu.y;
@@ -497,8 +501,8 @@ void ff_hevc_luma_mv_merge_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
part_idx = 0;
}
- ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH);
- derive_spatial_merge_candidates(lc, s, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
+ derive_spatial_merge_candidates(lc, s, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
singleMCLFlag, part_idx,
merge_idx, mergecand_list);
@@ -527,11 +531,12 @@ static av_always_inline void dist_scale(const HEVCContext *s, Mv *mv,
}
}
-static int mv_mp_mode_mx(const HEVCContext *s, int x, int y, int pred_flag_index,
+static int mv_mp_mode_mx(const HEVCContext *s, const HEVCSPS *sps,
+ int x, int y, int pred_flag_index,
Mv *mv, int ref_idx_curr, int ref_idx)
{
const MvField *tab_mvf = s->cur_frame->tab_mvf;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
const RefPicList *refPicList = s->cur_frame->refPicList;
@@ -543,11 +548,12 @@ static int mv_mp_mode_mx(const HEVCContext *s, int x, int y, int pred_flag_index
return 0;
}
-static int mv_mp_mode_mx_lt(const HEVCContext *s, int x, int y, int pred_flag_index,
+static int mv_mp_mode_mx_lt(const HEVCContext *s, const HEVCSPS *sps,
+ int x, int y, int pred_flag_index,
Mv *mv, int ref_idx_curr, int ref_idx)
{
const MvField *tab_mvf = s->cur_frame->tab_mvf;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
const RefPicList *refPicList = s->cur_frame->refPicList;
@@ -569,29 +575,31 @@ static int mv_mp_mode_mx_lt(const HEVCContext *s, int x, int y, int pred_flag_in
}
#define MP_MX(v, pred, mx) \
- mv_mp_mode_mx(s, \
- (x ## v) >> s->ps.sps->log2_min_pu_size, \
- (y ## v) >> s->ps.sps->log2_min_pu_size, \
+ mv_mp_mode_mx(s, sps, \
+ (x ## v) >> sps->log2_min_pu_size, \
+ (y ## v) >> sps->log2_min_pu_size, \
pred, &mx, ref_idx_curr, ref_idx)
#define MP_MX_LT(v, pred, mx) \
- mv_mp_mode_mx_lt(s, \
- (x ## v) >> s->ps.sps->log2_min_pu_size, \
- (y ## v) >> s->ps.sps->log2_min_pu_size, \
+ mv_mp_mode_mx_lt(s, sps, \
+ (x ## v) >> sps->log2_min_pu_size, \
+ (y ## v) >> sps->log2_min_pu_size, \
pred, &mx, ref_idx_curr, ref_idx)
-void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
+void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps,
+ 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)
{
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
const MvField *const tab_mvf = s->cur_frame->tab_mvf;
int isScaledFlag_L0 = 0;
int availableFlagLXA0 = 1;
int availableFlagLXB0 = 1;
int numMVPCandLX = 0;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
int xA0, yA0;
int is_available_a0;
@@ -627,7 +635,7 @@ void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
yA0 = y0 + nPbH;
is_available_a0 = AVAILABLE(cand_bottom_left, A0) &&
- yA0 < s->ps.sps->height &&
+ yA0 < sps->height &&
PRED_BLOCK_AVAILABLE(A0);
//left spatial merge candidate
@@ -682,7 +690,7 @@ b_candidates:
yB0 = y0 - 1;
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
- xB0 < s->ps.sps->width &&
+ xB0 < sps->width &&
PRED_BLOCK_AVAILABLE(B0);
// above spatial merge candidate
@@ -764,7 +772,7 @@ scalef:
if (numMVPCandLX < 2 && s->sh.slice_temporal_mvp_enabled_flag &&
mvp_lx_flag == numMVPCandLX) {
Mv mv_col;
- int available_col = temporal_luma_motion_vector(s, x0, y0, nPbW,
+ int available_col = temporal_luma_motion_vector(s, sps, x0, y0, nPbW,
nPbH, ref_idx,
&mv_col, LX);
if (available_col)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 08/39] lavc/hevc/filter: stop accessing parameter sets through HEVCParamSets
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (5 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 07/39] lavc/hevc/mvs: stop accessing parameter sets through HEVCParamSets Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 09/39] lavc/hevc/cabac: " Anton Khirnov
` (30 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Instead, accept PPS as a function argument and retrieve SPS through it.
Makes the code shorter and significantly reduces diff in future commits.
---
libavcodec/hevc/filter.c | 311 ++++++++++++++++++++------------------
libavcodec/hevc/hevcdec.c | 20 +--
libavcodec/hevc/hevcdec.h | 14 +-
3 files changed, 186 insertions(+), 159 deletions(-)
diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c
index db7525170d..081b3a3898 100644
--- a/libavcodec/hevc/filter.c
+++ b/libavcodec/hevc/filter.c
@@ -44,7 +44,8 @@ static const uint8_t betatable[52] = {
38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 // QP 38...51
};
-static int chroma_tc(const HEVCContext *s, int qp_y, int c_idx, int tc_offset)
+static int chroma_tc(const HEVCPPS *pps, const HEVCSPS *sps,
+ int qp_y, int c_idx, int tc_offset)
{
static const int qp_c[] = {
29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
@@ -53,12 +54,12 @@ static int chroma_tc(const HEVCContext *s, int qp_y, int c_idx, int tc_offset)
// slice qp offset is not used for deblocking
if (c_idx == 1)
- offset = s->ps.pps->cb_qp_offset;
+ offset = pps->cb_qp_offset;
else
- offset = s->ps.pps->cr_qp_offset;
+ offset = pps->cr_qp_offset;
qp_i = av_clip(qp_y + offset, 0, 57);
- if (s->ps.sps->chroma_format_idc == 1) {
+ if (sps->chroma_format_idc == 1) {
if (qp_i < 30)
qp = qp_i;
else if (qp_i > 43)
@@ -74,16 +75,17 @@ static int chroma_tc(const HEVCContext *s, int qp_y, int c_idx, int tc_offset)
}
static int get_qPy_pred(HEVCLocalContext *lc, const HEVCContext *s,
+ const HEVCPPS *pps, const HEVCSPS *sps,
int xBase, int yBase, int log2_cb_size)
{
- int ctb_size_mask = (1 << s->ps.sps->log2_ctb_size) - 1;
- int MinCuQpDeltaSizeMask = (1 << (s->ps.sps->log2_ctb_size -
- s->ps.pps->diff_cu_qp_delta_depth)) - 1;
+ int ctb_size_mask = (1 << sps->log2_ctb_size) - 1;
+ int MinCuQpDeltaSizeMask = (1 << (sps->log2_ctb_size -
+ pps->diff_cu_qp_delta_depth)) - 1;
int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
- int min_cb_width = s->ps.sps->min_cb_width;
- int x_cb = xQgBase >> s->ps.sps->log2_min_cb_size;
- int y_cb = yQgBase >> s->ps.sps->log2_min_cb_size;
+ int min_cb_width = sps->min_cb_width;
+ int x_cb = xQgBase >> sps->log2_min_cb_size;
+ int y_cb = yQgBase >> sps->log2_min_cb_size;
int availableA = (xBase & ctb_size_mask) &&
(xQgBase & ctb_size_mask);
int availableB = (yBase & ctb_size_mask) &&
@@ -110,31 +112,33 @@ static int get_qPy_pred(HEVCLocalContext *lc, const HEVCContext *s,
else
qPy_b = s->qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
- av_assert2(qPy_a >= -s->ps.sps->qp_bd_offset && qPy_a < 52);
- av_assert2(qPy_b >= -s->ps.sps->qp_bd_offset && qPy_b < 52);
+ av_assert2(qPy_a >= -sps->qp_bd_offset && qPy_a < 52);
+ av_assert2(qPy_b >= -sps->qp_bd_offset && qPy_b < 52);
return (qPy_a + qPy_b + 1) >> 1;
}
-void ff_hevc_set_qPy(HEVCLocalContext *lc, int xBase, int yBase, int log2_cb_size)
+void ff_hevc_set_qPy(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int xBase, int yBase, int log2_cb_size)
{
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
- int qp_y = get_qPy_pred(lc, s, xBase, yBase, log2_cb_size);
+ int qp_y = get_qPy_pred(lc, s, pps, sps, xBase, yBase, log2_cb_size);
if (lc->tu.cu_qp_delta != 0) {
- int off = s->ps.sps->qp_bd_offset;
+ int off = sps->qp_bd_offset;
lc->qp_y = FFUMOD(qp_y + lc->tu.cu_qp_delta + 52 + 2 * off,
52 + off) - off;
} else
lc->qp_y = qp_y;
}
-static int get_qPy(const HEVCContext *s, int xC, int yC)
+static int get_qPy(const HEVCSPS *sps, const int8_t *qp_y_tab, int xC, int yC)
{
- int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
+ int log2_min_cb_size = sps->log2_min_cb_size;
int x = xC >> log2_min_cb_size;
int y = yC >> log2_min_cb_size;
- return s->qp_y_tab[x + y * s->ps.sps->min_cb_width];
+ return qp_y_tab[x + y * sps->min_cb_width];
}
static void copy_CTB(uint8_t *dst, const uint8_t *src, int width, int height,
@@ -198,13 +202,14 @@ static void copy_vert(uint8_t *dst, const uint8_t *src,
}
}
-static void copy_CTB_to_hv(const HEVCContext *s, const uint8_t *src,
+static void copy_CTB_to_hv(const HEVCContext *s, const HEVCSPS *sps,
+ const uint8_t *src,
ptrdiff_t stride_src, int x, int y, int width, int height,
int c_idx, int x_ctb, int y_ctb)
{
- int sh = s->ps.sps->pixel_shift;
- int w = s->ps.sps->width >> s->ps.sps->hshift[c_idx];
- int h = s->ps.sps->height >> s->ps.sps->vshift[c_idx];
+ int sh = sps->pixel_shift;
+ int w = sps->width >> sps->hshift[c_idx];
+ int h = sps->height >> sps->vshift[c_idx];
/* copy horizontal edges */
memcpy(s->sao_pixel_buffer_h[c_idx] + (((2 * y_ctb) * w + x) << sh),
@@ -219,27 +224,33 @@ static void copy_CTB_to_hv(const HEVCContext *s, const uint8_t *src,
}
static void restore_tqb_pixels(const HEVCContext *s,
+ const HEVCPPS *pps, const HEVCSPS *sps,
uint8_t *src1, const uint8_t *dst1,
ptrdiff_t stride_src, ptrdiff_t stride_dst,
int x0, int y0, int width, int height, int c_idx)
{
- if ( s->ps.pps->transquant_bypass_enable_flag ||
- (s->ps.sps->pcm_loop_filter_disabled && s->ps.sps->pcm_enabled)) {
+ if (pps->transquant_bypass_enable_flag ||
+ (sps->pcm_loop_filter_disabled && sps->pcm_enabled)) {
int x, y;
- int min_pu_size = 1 << s->ps.sps->log2_min_pu_size;
- int hshift = s->ps.sps->hshift[c_idx];
- int vshift = s->ps.sps->vshift[c_idx];
- int x_min = ((x0 ) >> s->ps.sps->log2_min_pu_size);
- int y_min = ((y0 ) >> s->ps.sps->log2_min_pu_size);
- int x_max = ((x0 + width ) >> s->ps.sps->log2_min_pu_size);
- int y_max = ((y0 + height) >> s->ps.sps->log2_min_pu_size);
- int len = (min_pu_size >> hshift) << s->ps.sps->pixel_shift;
+ int min_pu_size = 1 << sps->log2_min_pu_size;
+ int hshift = sps->hshift[c_idx];
+ int vshift = sps->vshift[c_idx];
+ int x_min = ((x0 ) >> sps->log2_min_pu_size);
+ int y_min = ((y0 ) >> sps->log2_min_pu_size);
+ int x_max = ((x0 + width ) >> sps->log2_min_pu_size);
+ int y_max = ((y0 + height) >> sps->log2_min_pu_size);
+ int len = (min_pu_size >> hshift) << sps->pixel_shift;
for (y = y_min; y < y_max; y++) {
for (x = x_min; x < x_max; x++) {
- if (s->is_pcm[y * s->ps.sps->min_pu_width + x]) {
+ if (s->is_pcm[y * sps->min_pu_width + x]) {
int n;
- uint8_t *src = src1 + (((y << s->ps.sps->log2_min_pu_size) - y0) >> vshift) * stride_src + ((((x << s->ps.sps->log2_min_pu_size) - x0) >> hshift) << s->ps.sps->pixel_shift);
- const uint8_t *dst = dst1 + (((y << s->ps.sps->log2_min_pu_size) - y0) >> vshift) * stride_dst + ((((x << s->ps.sps->log2_min_pu_size) - x0) >> hshift) << s->ps.sps->pixel_shift);
+ uint8_t *src = src1 +
+ (((y << sps->log2_min_pu_size) - y0) >> vshift) * stride_src +
+ ((((x << sps->log2_min_pu_size) - x0) >> hshift) << sps->pixel_shift);
+ const uint8_t *dst = dst1 +
+ (((y << sps->log2_min_pu_size) - y0) >> vshift) * stride_dst +
+ ((((x << sps->log2_min_pu_size) - x0) >> hshift) << sps->pixel_shift);
+
for (n = 0; n < (min_pu_size >> vshift); n++) {
memcpy(src, dst, len);
src += stride_src;
@@ -251,25 +262,27 @@ static void restore_tqb_pixels(const HEVCContext *s,
}
}
-#define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
+#define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
-static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, int y)
+static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x, int y)
{
static const uint8_t sao_tab[8] = { 0, 1, 2, 2, 3, 3, 4, 4 };
int c_idx;
int edges[4]; // 0 left 1 top 2 right 3 bottom
- int x_ctb = x >> s->ps.sps->log2_ctb_size;
- int y_ctb = y >> s->ps.sps->log2_ctb_size;
- int ctb_addr_rs = y_ctb * s->ps.sps->ctb_width + x_ctb;
- int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
+ int x_ctb = x >> sps->log2_ctb_size;
+ int y_ctb = y >> sps->log2_ctb_size;
+ int ctb_addr_rs = y_ctb * sps->ctb_width + x_ctb;
+ int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
SAOParams *sao = &CTB(s->sao, x_ctb, y_ctb);
// flags indicating unfilterable edges
uint8_t vert_edge[] = { 0, 0 };
uint8_t horiz_edge[] = { 0, 0 };
uint8_t diag_edge[] = { 0, 0, 0, 0 };
uint8_t lfase = CTB(s->filter_slice_edges, x_ctb, y_ctb);
- uint8_t no_tile_filter = s->ps.pps->tiles_enabled_flag &&
- !s->ps.pps->loop_filter_across_tiles_enabled_flag;
+ uint8_t no_tile_filter = pps->tiles_enabled_flag &&
+ !pps->loop_filter_across_tiles_enabled_flag;
uint8_t restore = no_tile_filter || !lfase;
uint8_t left_tile_edge = 0;
uint8_t right_tile_edge = 0;
@@ -278,24 +291,24 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, in
edges[0] = x_ctb == 0;
edges[1] = y_ctb == 0;
- edges[2] = x_ctb == s->ps.sps->ctb_width - 1;
- edges[3] = y_ctb == s->ps.sps->ctb_height - 1;
+ edges[2] = x_ctb == sps->ctb_width - 1;
+ edges[3] = y_ctb == sps->ctb_height - 1;
if (restore) {
if (!edges[0]) {
- left_tile_edge = no_tile_filter && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1]];
+ left_tile_edge = no_tile_filter && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs-1]];
vert_edge[0] = (!lfase && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb - 1, y_ctb)) || left_tile_edge;
}
if (!edges[2]) {
- right_tile_edge = no_tile_filter && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1]];
+ right_tile_edge = no_tile_filter && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs+1]];
vert_edge[1] = (!lfase && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb + 1, y_ctb)) || right_tile_edge;
}
if (!edges[1]) {
- up_tile_edge = no_tile_filter && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]];
+ up_tile_edge = no_tile_filter && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - sps->ctb_width]];
horiz_edge[0] = (!lfase && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) || up_tile_edge;
}
if (!edges[3]) {
- bottom_tile_edge = no_tile_filter && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs + s->ps.sps->ctb_width]];
+ bottom_tile_edge = no_tile_filter && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs + sps->ctb_width]];
horiz_edge[1] = (!lfase && CTB(s->tab_slice_address, x_ctb, y_ctb) != CTB(s->tab_slice_address, x_ctb, y_ctb + 1)) || bottom_tile_edge;
}
if (!edges[0] && !edges[1]) {
@@ -312,32 +325,32 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, in
}
}
- for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
- int x0 = x >> s->ps.sps->hshift[c_idx];
- int y0 = y >> s->ps.sps->vshift[c_idx];
+ for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
+ int x0 = x >> sps->hshift[c_idx];
+ int y0 = y >> sps->vshift[c_idx];
ptrdiff_t stride_src = s->cur_frame->f->linesize[c_idx];
- int ctb_size_h = (1 << (s->ps.sps->log2_ctb_size)) >> s->ps.sps->hshift[c_idx];
- int ctb_size_v = (1 << (s->ps.sps->log2_ctb_size)) >> s->ps.sps->vshift[c_idx];
- int width = FFMIN(ctb_size_h, (s->ps.sps->width >> s->ps.sps->hshift[c_idx]) - x0);
- int height = FFMIN(ctb_size_v, (s->ps.sps->height >> s->ps.sps->vshift[c_idx]) - y0);
+ int ctb_size_h = (1 << (sps->log2_ctb_size)) >> sps->hshift[c_idx];
+ int ctb_size_v = (1 << (sps->log2_ctb_size)) >> sps->vshift[c_idx];
+ int width = FFMIN(ctb_size_h, (sps->width >> sps->hshift[c_idx]) - x0);
+ int height = FFMIN(ctb_size_v, (sps->height >> sps->vshift[c_idx]) - y0);
int tab = sao_tab[(FFALIGN(width, 8) >> 3) - 1];
- uint8_t *src = &s->cur_frame->f->data[c_idx][y0 * stride_src + (x0 << s->ps.sps->pixel_shift)];
+ uint8_t *src = &s->cur_frame->f->data[c_idx][y0 * stride_src + (x0 << sps->pixel_shift)];
ptrdiff_t stride_dst;
uint8_t *dst;
switch (sao->type_idx[c_idx]) {
case SAO_BAND:
- copy_CTB_to_hv(s, src, stride_src, x0, y0, width, height, c_idx,
+ copy_CTB_to_hv(s, sps, src, stride_src, x0, y0, width, height, c_idx,
x_ctb, y_ctb);
- if (s->ps.pps->transquant_bypass_enable_flag ||
- (s->ps.sps->pcm_loop_filter_disabled && s->ps.sps->pcm_enabled)) {
+ if (pps->transquant_bypass_enable_flag ||
+ (sps->pcm_loop_filter_disabled && sps->pcm_enabled)) {
dst = lc->edge_emu_buffer;
stride_dst = 2*MAX_PB_SIZE;
- copy_CTB(dst, src, width << s->ps.sps->pixel_shift, height, stride_dst, stride_src);
+ copy_CTB(dst, src, width << sps->pixel_shift, height, stride_dst, stride_src);
s->hevcdsp.sao_band_filter[tab](src, dst, stride_src, stride_dst,
sao->offset_val[c_idx], sao->band_position[c_idx],
width, height);
- restore_tqb_pixels(s, src, dst, stride_src, stride_dst,
+ restore_tqb_pixels(s, pps, sps, src, dst, stride_src, stride_dst,
x, y, width, height, c_idx);
} else {
s->hevcdsp.sao_band_filter[tab](src, src, stride_src, stride_src,
@@ -348,13 +361,13 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, in
break;
case SAO_EDGE:
{
- int w = s->ps.sps->width >> s->ps.sps->hshift[c_idx];
- int h = s->ps.sps->height >> s->ps.sps->vshift[c_idx];
+ int w = sps->width >> sps->hshift[c_idx];
+ int h = sps->height >> sps->vshift[c_idx];
int left_edge = edges[0];
int top_edge = edges[1];
int right_edge = edges[2];
int bottom_edge = edges[3];
- int sh = s->ps.sps->pixel_shift;
+ int sh = sps->pixel_shift;
int left_pixels, right_pixels;
stride_dst = 2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE;
@@ -440,7 +453,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, in
(width + left_pixels + right_pixels) << sh,
height, stride_dst, stride_src);
- copy_CTB_to_hv(s, src, stride_src, x0, y0, width, height, c_idx,
+ copy_CTB_to_hv(s, sps, src, stride_src, x0, y0, width, height, c_idx,
x_ctb, y_ctb);
s->hevcdsp.sao_edge_filter[tab](src, dst, stride_src, sao->offset_val[c_idx],
sao->eo_class[c_idx], width, height);
@@ -452,7 +465,7 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, in
vert_edge,
horiz_edge,
diag_edge);
- restore_tqb_pixels(s, src, dst, stride_src, stride_dst,
+ restore_tqb_pixels(s, pps, sps, src, dst, stride_src, stride_dst,
x, y, width, height, c_idx);
sao->type_idx[c_idx] = SAO_APPLIED;
break;
@@ -461,9 +474,9 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const HEVCContext *s, int x, in
}
}
-static int get_pcm(const HEVCContext *s, int x, int y)
+static int get_pcm(const HEVCSPS *sps, const uint8_t *is_pcm, int x, int y)
{
- int log2_min_pu_size = s->ps.sps->log2_min_pu_size;
+ int log2_min_pu_size = sps->log2_min_pu_size;
int x_pu, y_pu;
if (x < 0 || y < 0)
@@ -472,9 +485,9 @@ static int get_pcm(const HEVCContext *s, int x, int y)
x_pu = x >> log2_min_pu_size;
y_pu = y >> log2_min_pu_size;
- if (x_pu >= s->ps.sps->min_pu_width || y_pu >= s->ps.sps->min_pu_height)
+ if (x_pu >= sps->min_pu_width || y_pu >= sps->min_pu_height)
return 2;
- return s->is_pcm[y_pu * s->ps.sps->min_pu_width + x_pu];
+ return is_pcm[y_pu * sps->min_pu_width + x_pu];
}
#define TC_CALC(qp, bs) \
@@ -482,7 +495,9 @@ static int get_pcm(const HEVCContext *s, int x, int y)
(tc_offset & -2), \
0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
-static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
+static void deblocking_filter_CTB(const HEVCContext *s,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0)
{
uint8_t **data = s->cur_frame->f->data;
int *linesize = s->cur_frame->f->linesize;
@@ -494,18 +509,18 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
uint8_t no_p[2] = { 0 };
uint8_t no_q[2] = { 0 };
- int log2_ctb_size = s->ps.sps->log2_ctb_size;
+ int log2_ctb_size = sps->log2_ctb_size;
int x_end, x_end2, y_end;
int ctb_size = 1 << log2_ctb_size;
int ctb = (x0 >> log2_ctb_size) +
- (y0 >> log2_ctb_size) * s->ps.sps->ctb_width;
+ (y0 >> log2_ctb_size) * sps->ctb_width;
int cur_tc_offset = s->deblock[ctb].tc_offset;
int cur_beta_offset = s->deblock[ctb].beta_offset;
int left_tc_offset, left_beta_offset;
int tc_offset, beta_offset;
- int pcmf = (s->ps.sps->pcm_enabled &&
- s->ps.sps->pcm_loop_filter_disabled) ||
- s->ps.pps->transquant_bypass_enable_flag;
+ int pcmf = (sps->pcm_enabled &&
+ sps->pcm_loop_filter_disabled) ||
+ pps->transquant_bypass_enable_flag;
if (x0) {
left_tc_offset = s->deblock[ctb - 1].tc_offset;
@@ -516,17 +531,17 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
}
x_end = x0 + ctb_size;
- if (x_end > s->ps.sps->width)
- x_end = s->ps.sps->width;
+ if (x_end > sps->width)
+ x_end = sps->width;
y_end = y0 + ctb_size;
- if (y_end > s->ps.sps->height)
- y_end = s->ps.sps->height;
+ if (y_end > sps->height)
+ y_end = sps->height;
tc_offset = cur_tc_offset;
beta_offset = cur_beta_offset;
x_end2 = x_end;
- if (x_end2 != s->ps.sps->width)
+ if (x_end2 != sps->width)
x_end2 -= 8;
for (y = y0; y < y_end; y += 8) {
// vertical filtering luma
@@ -534,18 +549,19 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
const int bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2];
const int bs1 = s->vertical_bs[(x + (y + 4) * s->bs_width) >> 2];
if (bs0 || bs1) {
- const int qp = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
+ const int qp = (get_qPy(sps, s->qp_y_tab, x - 1, y) +
+ get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1;
beta = betatable[av_clip(qp + beta_offset, 0, MAX_QP)];
tc[0] = bs0 ? TC_CALC(qp, bs0) : 0;
tc[1] = bs1 ? TC_CALC(qp, bs1) : 0;
- src = &data[LUMA][y * linesize[LUMA] + (x << s->ps.sps->pixel_shift)];
+ src = &data[LUMA][y * linesize[LUMA] + (x << sps->pixel_shift)];
if (pcmf) {
- no_p[0] = get_pcm(s, x - 1, y);
- no_p[1] = get_pcm(s, x - 1, y + 4);
- no_q[0] = get_pcm(s, x, y);
- no_q[1] = get_pcm(s, x, y + 4);
+ no_p[0] = get_pcm(sps, s->is_pcm, x - 1, y);
+ no_p[1] = get_pcm(sps, s->is_pcm, x - 1, y + 4);
+ no_q[0] = get_pcm(sps, s->is_pcm, x, y);
+ no_q[1] = get_pcm(sps, s->is_pcm, x, y + 4);
s->hevcdsp.hevc_v_loop_filter_luma_c(src, linesize[LUMA],
beta, tc, no_p, no_q);
} else
@@ -562,7 +578,8 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2];
const int bs1 = s->horizontal_bs[((x + 4) + y * s->bs_width) >> 2];
if (bs0 || bs1) {
- const int qp = (get_qPy(s, x, y - 1) + get_qPy(s, x, y) + 1) >> 1;
+ const int qp = (get_qPy(sps, s->qp_y_tab, x, y - 1) +
+ get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1;
tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
@@ -570,12 +587,12 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
beta = betatable[av_clip(qp + beta_offset, 0, MAX_QP)];
tc[0] = bs0 ? TC_CALC(qp, bs0) : 0;
tc[1] = bs1 ? TC_CALC(qp, bs1) : 0;
- src = &data[LUMA][y * linesize[LUMA] + (x << s->ps.sps->pixel_shift)];
+ src = &data[LUMA][y * linesize[LUMA] + (x << sps->pixel_shift)];
if (pcmf) {
- no_p[0] = get_pcm(s, x, y - 1);
- no_p[1] = get_pcm(s, x + 4, y - 1);
- no_q[0] = get_pcm(s, x, y);
- no_q[1] = get_pcm(s, x + 4, y);
+ no_p[0] = get_pcm(sps, s->is_pcm, x, y - 1);
+ no_p[1] = get_pcm(sps, s->is_pcm, x + 4, y - 1);
+ no_q[0] = get_pcm(sps, s->is_pcm, x, y);
+ no_q[1] = get_pcm(sps, s->is_pcm, x + 4, y);
s->hevcdsp.hevc_h_loop_filter_luma_c(src, linesize[LUMA],
beta, tc, no_p, no_q);
} else
@@ -585,10 +602,10 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
}
}
- if (s->ps.sps->chroma_format_idc) {
+ if (sps->chroma_format_idc) {
for (chroma = 1; chroma <= 2; chroma++) {
- int h = 1 << s->ps.sps->hshift[chroma];
- int v = 1 << s->ps.sps->vshift[chroma];
+ int h = 1 << sps->hshift[chroma];
+ int v = 1 << sps->vshift[chroma];
// vertical filtering chroma
for (y = y0; y < y_end; y += (8 * v)) {
@@ -597,17 +614,19 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
const int bs1 = s->vertical_bs[(x + (y + (4 * v)) * s->bs_width) >> 2];
if ((bs0 == 2) || (bs1 == 2)) {
- 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 + (4 * v)) + get_qPy(s, x, y + (4 * v)) + 1) >> 1;
+ const int qp0 = (get_qPy(sps, s->qp_y_tab, x - 1, y) +
+ get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1;
+ const int qp1 = (get_qPy(sps, s->qp_y_tab, x - 1, y + (4 * v)) +
+ get_qPy(sps, s->qp_y_tab, x, y + (4 * v)) + 1) >> 1;
- 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;
- src = &data[chroma][(y >> s->ps.sps->vshift[chroma]) * linesize[chroma] + ((x >> s->ps.sps->hshift[chroma]) << s->ps.sps->pixel_shift)];
+ c_tc[0] = (bs0 == 2) ? chroma_tc(pps, sps, qp0, chroma, tc_offset) : 0;
+ c_tc[1] = (bs1 == 2) ? chroma_tc(pps, sps, qp1, chroma, tc_offset) : 0;
+ src = &data[chroma][(y >> sps->vshift[chroma]) * linesize[chroma] + ((x >> sps->hshift[chroma]) << sps->pixel_shift)];
if (pcmf) {
- no_p[0] = get_pcm(s, x - 1, y);
- no_p[1] = get_pcm(s, x - 1, y + (4 * v));
- no_q[0] = get_pcm(s, x, y);
- no_q[1] = get_pcm(s, x, y + (4 * v));
+ no_p[0] = get_pcm(sps, s->is_pcm, x - 1, y);
+ no_p[1] = get_pcm(sps, s->is_pcm, x - 1, y + (4 * v));
+ no_q[0] = get_pcm(sps, s->is_pcm, x, y);
+ no_q[1] = get_pcm(sps, s->is_pcm, x, y + (4 * v));
s->hevcdsp.hevc_v_loop_filter_chroma_c(src, linesize[chroma],
c_tc, no_p, no_q);
} else
@@ -622,23 +641,25 @@ static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
// horizontal filtering chroma
tc_offset = x0 ? left_tc_offset : cur_tc_offset;
x_end2 = x_end;
- if (x_end != s->ps.sps->width)
+ if (x_end != sps->width)
x_end2 = x_end - 8 * h;
for (x = x0 ? x0 - 8 * h : 0; x < x_end2; x += (8 * h)) {
const int bs0 = s->horizontal_bs[( x + y * s->bs_width) >> 2];
const int bs1 = s->horizontal_bs[((x + 4 * h) + y * s->bs_width) >> 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 qp1 = bs1 == 2 ? (get_qPy(s, x + (4 * h), y - 1) + get_qPy(s, x + (4 * h), y) + 1) >> 1 : 0;
+ const int qp0 = bs0 == 2 ? (get_qPy(sps, s->qp_y_tab, x, y - 1) +
+ get_qPy(sps, s->qp_y_tab, x, y) + 1) >> 1 : 0;
+ const int qp1 = bs1 == 2 ? (get_qPy(sps, s->qp_y_tab, x + (4 * h), y - 1) +
+ get_qPy(sps, s->qp_y_tab, x + (4 * h), y) + 1) >> 1 : 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;
- src = &data[chroma][(y >> s->ps.sps->vshift[1]) * linesize[chroma] + ((x >> s->ps.sps->hshift[1]) << s->ps.sps->pixel_shift)];
+ c_tc[0] = bs0 == 2 ? chroma_tc(pps, sps, qp0, chroma, tc_offset) : 0;
+ c_tc[1] = bs1 == 2 ? chroma_tc(pps, sps, qp1, chroma, cur_tc_offset) : 0;
+ src = &data[chroma][(y >> sps->vshift[1]) * linesize[chroma] + ((x >> sps->hshift[1]) << sps->pixel_shift)];
if (pcmf) {
- no_p[0] = get_pcm(s, x, y - 1);
- no_p[1] = get_pcm(s, x + (4 * h), y - 1);
- no_q[0] = get_pcm(s, x, y);
- no_q[1] = get_pcm(s, x + (4 * h), y);
+ no_p[0] = get_pcm(sps, s->is_pcm, x, y - 1);
+ no_p[1] = get_pcm(sps, s->is_pcm, x + (4 * h), y - 1);
+ no_q[0] = get_pcm(sps, s->is_pcm, x, y);
+ no_q[1] = get_pcm(sps, s->is_pcm, x + (4 * h), y);
s->hevcdsp.hevc_h_loop_filter_chroma_c(src, linesize[chroma],
c_tc, no_p, no_q);
} else
@@ -715,15 +736,16 @@ static int boundary_strength(const HEVCContext *s, const MvField *curr, const Mv
return 1;
}
-void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
- int log2_trafo_size)
+void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0, int log2_trafo_size)
{
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *s = lc->parent;
const MvField *tab_mvf = s->cur_frame->tab_mvf;
- int log2_min_pu_size = s->ps.sps->log2_min_pu_size;
- int log2_min_tu_size = s->ps.sps->log2_min_tb_size;
- int min_pu_width = s->ps.sps->min_pu_width;
- int min_tu_width = s->ps.sps->min_tb_width;
+ int log2_min_pu_size = sps->log2_min_pu_size;
+ int log2_min_tu_size = sps->log2_min_tb_size;
+ int min_pu_width = sps->min_pu_width;
+ int min_tu_width = sps->min_tb_width;
int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
(x0 >> log2_min_pu_size)].pred_flag == PF_INTRA;
int boundary_upper, boundary_left;
@@ -733,10 +755,10 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
if (boundary_upper &&
((!s->sh.slice_loop_filter_across_slices_enabled_flag &&
lc->boundary_flags & BOUNDARY_UPPER_SLICE &&
- (y0 % (1 << s->ps.sps->log2_ctb_size)) == 0) ||
- (!s->ps.pps->loop_filter_across_tiles_enabled_flag &&
+ (y0 % (1 << sps->log2_ctb_size)) == 0) ||
+ (!pps->loop_filter_across_tiles_enabled_flag &&
lc->boundary_flags & BOUNDARY_UPPER_TILE &&
- (y0 % (1 << s->ps.sps->log2_ctb_size)) == 0)))
+ (y0 % (1 << sps->log2_ctb_size)) == 0)))
boundary_upper = 0;
if (boundary_upper) {
@@ -771,10 +793,10 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
if (boundary_left &&
((!s->sh.slice_loop_filter_across_slices_enabled_flag &&
lc->boundary_flags & BOUNDARY_LEFT_SLICE &&
- (x0 % (1 << s->ps.sps->log2_ctb_size)) == 0) ||
- (!s->ps.pps->loop_filter_across_tiles_enabled_flag &&
+ (x0 % (1 << sps->log2_ctb_size)) == 0) ||
+ (!pps->loop_filter_across_tiles_enabled_flag &&
lc->boundary_flags & BOUNDARY_LEFT_TILE &&
- (x0 % (1 << s->ps.sps->log2_ctb_size)) == 0)))
+ (x0 % (1 << sps->log2_ctb_size)) == 0)))
boundary_left = 0;
if (boundary_left) {
@@ -843,10 +865,12 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
#undef CB
#undef CR
-void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size)
+void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x, int y, int ctb_size)
{
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
- int x_end = x >= s->ps.sps->width - ctb_size;
+ int x_end = x >= sps->width - ctb_size;
int skip = 0;
if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && !IS_IDR(s)) ||
@@ -859,20 +883,20 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size)
skip = 1;
if (!skip)
- deblocking_filter_CTB(s, x, y);
- if (s->ps.sps->sao_enabled && !skip) {
- int y_end = y >= s->ps.sps->height - ctb_size;
+ deblocking_filter_CTB(s, pps, sps, x, y);
+ if (sps->sao_enabled && !skip) {
+ int y_end = y >= sps->height - ctb_size;
if (y && x)
- sao_filter_CTB(lc, s, x - ctb_size, y - ctb_size);
+ sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y - ctb_size);
if (x && y_end)
- sao_filter_CTB(lc, s, x - ctb_size, y);
+ sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y);
if (y && x_end) {
- sao_filter_CTB(lc, s, x, y - ctb_size);
+ sao_filter_CTB(lc, s, pps, sps, x, y - ctb_size);
if (s->threads_type & FF_THREAD_FRAME )
ff_progress_frame_report(&s->cur_frame->tf, y);
}
if (x_end && y_end) {
- sao_filter_CTB(lc, s, x , y);
+ sao_filter_CTB(lc, s, pps, sps, x , y);
if (s->threads_type & FF_THREAD_FRAME )
ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size);
}
@@ -880,14 +904,15 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size)
ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size - 4);
}
-void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size)
+void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x_ctb, int y_ctb, int ctb_size)
{
- int x_end = x_ctb >= lc->parent->ps.sps->width - ctb_size;
- int y_end = y_ctb >= lc->parent->ps.sps->height - ctb_size;
+ int x_end = x_ctb >= pps->sps->width - ctb_size;
+ int y_end = y_ctb >= pps->sps->height - ctb_size;
if (y_ctb && x_ctb)
- ff_hevc_hls_filter(lc, x_ctb - ctb_size, y_ctb - ctb_size, ctb_size);
+ ff_hevc_hls_filter(lc, pps, x_ctb - ctb_size, y_ctb - ctb_size, ctb_size);
if (y_ctb && x_end)
- ff_hevc_hls_filter(lc, x_ctb, y_ctb - ctb_size, ctb_size);
+ ff_hevc_hls_filter(lc, pps, x_ctb, y_ctb - ctb_size, ctb_size);
if (x_ctb && y_end)
- ff_hevc_hls_filter(lc, x_ctb - ctb_size, y_ctb, ctb_size);
+ ff_hevc_hls_filter(lc, pps, x_ctb - ctb_size, y_ctb, ctb_size);
}
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5de229f78d..eeeaae6e3a 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1189,7 +1189,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
return AVERROR_INVALIDDATA;
}
- ff_hevc_set_qPy(lc, cb_xBase, cb_yBase, log2_cb_size);
+ ff_hevc_set_qPy(lc, s->ps.pps, cb_xBase, cb_yBase, log2_cb_size);
}
if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
@@ -1485,7 +1485,7 @@ do {
}
}
if (!s->sh.disable_deblocking_filter_flag) {
- ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_trafo_size);
+ ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_trafo_size);
if (s->ps.pps->transquant_bypass_enable_flag &&
lc->cu.cu_transquant_bypass_flag)
set_deblocking_bypass(s, x0, y0, log2_trafo_size);
@@ -1514,7 +1514,7 @@ static int hls_pcm_sample(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size
int ret;
if (!s->sh.disable_deblocking_filter_flag)
- ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size);
+ ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_cb_size);
ret = init_get_bits(&gb, pcm, length);
if (ret < 0)
@@ -2284,7 +2284,7 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size);
if (!s->sh.disable_deblocking_filter_flag)
- ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size);
+ ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_cb_size);
} else {
int pcm_flag = 0;
@@ -2372,13 +2372,13 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
return ret;
} else {
if (!s->sh.disable_deblocking_filter_flag)
- ff_hevc_deblocking_boundary_strengths(lc, x0, y0, log2_cb_size);
+ ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_cb_size);
}
}
}
if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
- ff_hevc_set_qPy(lc, x0, y0, log2_cb_size);
+ ff_hevc_set_qPy(lc, s->ps.pps, x0, y0, log2_cb_size);
x = y_cb * min_cb_width + x_cb;
for (y = 0; y < length; y++) {
@@ -2583,12 +2583,12 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
ctb_addr_ts++;
ff_hevc_save_states(lc, ctb_addr_ts);
- ff_hevc_hls_filters(lc, x_ctb, y_ctb, ctb_size);
+ ff_hevc_hls_filters(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
}
if (x_ctb + ctb_size >= s->ps.sps->width &&
y_ctb + ctb_size >= s->ps.sps->height)
- ff_hevc_hls_filter(lc, x_ctb, y_ctb, ctb_size);
+ ff_hevc_hls_filter(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
return ctb_addr_ts;
}
@@ -2644,7 +2644,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
ff_hevc_save_states(lc, ctb_addr_ts);
ff_thread_report_progress2(s->avctx, ctb_row, thread, 1);
- ff_hevc_hls_filters(lc, x_ctb, y_ctb, ctb_size);
+ ff_hevc_hls_filters(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) {
/* Casting const away here is safe, because it is an atomic operation. */
@@ -2654,7 +2654,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
}
if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) {
- ff_hevc_hls_filter(lc, x_ctb, y_ctb, ctb_size);
+ ff_hevc_hls_filter(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP);
return ctb_addr_ts;
}
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index eef7d66204..8816ebe1f4 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -655,12 +655,14 @@ void ff_hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, const HEVCPPS *pps,
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_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size);
-void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size);
-void ff_hevc_set_qPy(HEVCLocalContext *lc, int xBase, int yBase,
- int log2_cb_size);
-void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, int x0, int y0,
- int log2_trafo_size);
+void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x, int y, int ctb_size);
+void ff_hevc_hls_filters(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x_ctb, int y_ctb, int ctb_size);
+void ff_hevc_set_qPy(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int xBase, int yBase, int log2_cb_size);
+void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0, int log2_trafo_size);
int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc);
int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc);
int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc);
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 09/39] lavc/hevc/cabac: stop accessing parameter sets through HEVCParamSets
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (6 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 08/39] lavc/hevc/filter: " Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 10/39] lavc/hevc/pred: " Anton Khirnov
` (29 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Instead, accept PPS/SPS as function arguments.
Makes the code shorter and significantly reduces diff in future commits.
---
libavcodec/hevc/cabac.c | 145 +++++++++++++++++++-------------------
libavcodec/hevc/hevcdec.c | 31 ++++----
libavcodec/hevc/hevcdec.h | 22 +++---
3 files changed, 102 insertions(+), 96 deletions(-)
diff --git a/libavcodec/hevc/cabac.c b/libavcodec/hevc/cabac.c
index 37f144758a..8708efc248 100644
--- a/libavcodec/hevc/cabac.c
+++ b/libavcodec/hevc/cabac.c
@@ -399,25 +399,25 @@ static const uint8_t diag_scan8x8_inv[8][8] = {
{ 28, 36, 43, 49, 54, 58, 61, 63, },
};
-void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts)
+void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int ctb_addr_ts)
{
- const HEVCContext *const s = lc->parent;
-
- if (s->ps.pps->entropy_coding_sync_enabled_flag &&
- (ctb_addr_ts % s->ps.sps->ctb_width == 2 ||
- (s->ps.sps->ctb_width == 2 &&
- ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
+ const HEVCSPS *const sps = pps->sps;
+ if (pps->entropy_coding_sync_enabled_flag &&
+ (ctb_addr_ts % sps->ctb_width == 2 ||
+ (sps->ctb_width == 2 &&
+ ctb_addr_ts % sps->ctb_width == 0))) {
memcpy(lc->common_cabac_state->state, lc->cabac_state, HEVC_CONTEXTS);
- if (s->ps.sps->persistent_rice_adaptation_enabled) {
+ if (sps->persistent_rice_adaptation_enabled) {
memcpy(lc->common_cabac_state->stat_coeff, lc->stat_coeff, HEVC_STAT_COEFFS);
}
}
}
-static void load_states(HEVCLocalContext *lc, const HEVCContext *s)
+static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
{
memcpy(lc->cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS);
- if (s->ps.sps->persistent_rice_adaptation_enabled) {
+ if (sps->persistent_rice_adaptation_enabled) {
memcpy(lc->stat_coeff, lc->common_cabac_state->stat_coeff, HEVC_STAT_COEFFS);
}
}
@@ -451,32 +451,33 @@ static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
lc->stat_coeff[i] = 0;
}
-int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts,
- const uint8_t *data, size_t size)
+int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int ctb_addr_ts, const uint8_t *data, size_t size)
{
const HEVCContext *const s = lc->parent;
+ const HEVCSPS *const sps = pps->sps;
- if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
+ if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
int ret = ff_init_cabac_decoder(&lc->cc, data, size);
if (ret < 0)
return ret;
if (s->sh.dependent_slice_segment_flag == 0 ||
- (s->ps.pps->tiles_enabled_flag &&
- s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]))
+ (pps->tiles_enabled_flag &&
+ pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]))
cabac_init_state(lc, s);
if (!s->sh.first_slice_in_pic_flag &&
- s->ps.pps->entropy_coding_sync_enabled_flag) {
- if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
- if (s->ps.sps->ctb_width == 1)
+ pps->entropy_coding_sync_enabled_flag) {
+ if (ctb_addr_ts % sps->ctb_width == 0) {
+ if (sps->ctb_width == 1)
cabac_init_state(lc, s);
else if (s->sh.dependent_slice_segment_flag == 1)
- load_states(lc, s);
+ load_states(lc, sps);
}
}
} else {
- if (s->ps.pps->tiles_enabled_flag &&
- s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) {
+ if (pps->tiles_enabled_flag &&
+ pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
int ret;
if (s->threads_number == 1)
ret = cabac_reinit(lc);
@@ -487,8 +488,8 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts,
return ret;
cabac_init_state(lc, s);
}
- if (s->ps.pps->entropy_coding_sync_enabled_flag) {
- if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
+ if (pps->entropy_coding_sync_enabled_flag) {
+ if (ctb_addr_ts % sps->ctb_width == 0) {
int ret;
get_cabac_terminate(&lc->cc);
if (s->threads_number == 1)
@@ -499,10 +500,10 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts,
if (ret < 0)
return ret;
- if (s->ps.sps->ctb_width == 1)
+ if (sps->ctb_width == 1)
cabac_init_state(lc, s);
else
- load_states(lc, s);
+ load_states(lc, sps);
}
}
}
@@ -536,10 +537,10 @@ int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc)
return value;
}
-int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc)
+int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth)
{
int i = 0;
- int length = (1 << (FFMIN(lc->parent->ps.sps->bit_depth, 10) - 5)) - 1;
+ int length = (1 << (FFMIN(bit_depth, 10) - 5)) - 1;
while (i < length && get_cabac_bypass(&lc->cc))
i++;
@@ -568,17 +569,15 @@ int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc)
return GET_CABAC(CU_TRANSQUANT_BYPASS_FLAG_OFFSET);
}
-int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0, int x_cb, int y_cb)
+int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0,
+ int x_cb, int y_cb, int min_cb_width)
{
const HEVCContext *const s = lc->parent;
- int min_cb_width = s->ps.sps->min_cb_width;
int inc = 0;
- int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
- int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
- if (lc->ctb_left_flag || x0b)
+ if (lc->ctb_left_flag || x0)
inc = !!SAMPLE_CTB(s->skip_flag, x_cb - 1, y_cb);
- if (lc->ctb_up_flag || y0b)
+ if (lc->ctb_up_flag || y0)
inc += !!SAMPLE_CTB(s->skip_flag, x_cb, y_cb - 1);
return GET_CABAC(SKIP_FLAG_OFFSET + inc);
@@ -621,9 +620,9 @@ int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc)
return GET_CABAC(CU_CHROMA_QP_OFFSET_FLAG_OFFSET);
}
-int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc)
+int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1)
{
- int c_max= FFMAX(5, lc->parent->ps.pps->chroma_qp_offset_list_len_minus1);
+ int c_max= FFMAX(5, chroma_qp_offset_list_len_minus1);
int i = 0;
while (i < c_max && GET_CABAC(CU_CHROMA_QP_OFFSET_IDX_OFFSET))
@@ -637,10 +636,10 @@ int ff_hevc_pred_mode_decode(HEVCLocalContext *lc)
return GET_CABAC(PRED_MODE_FLAG_OFFSET);
}
-int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth, int x0, int y0)
+int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, const HEVCSPS *sps,
+ int ct_depth, int x0, int y0)
{
const HEVCContext *const s = lc->parent;
- const HEVCSPS *const sps = s->ps.sps;
int inc = 0, depth_left = 0, depth_top = 0;
int x0b = av_mod_uintp2(x0, sps->log2_ctb_size);
int y0b = av_mod_uintp2(y0, sps->log2_ctb_size);
@@ -658,11 +657,11 @@ int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth, in
return GET_CABAC(SPLIT_CODING_UNIT_FLAG_OFFSET + inc);
}
-int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size)
+int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size)
{
if (GET_CABAC(PART_MODE_OFFSET)) // 1
return PART_2Nx2N;
- if (log2_cb_size == lc->parent->ps.sps->log2_min_cb_size) {
+ if (log2_cb_size == sps->log2_min_cb_size) {
if (lc->cu.pred_mode == MODE_INTRA) // 0
return PART_NxN;
if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
@@ -674,7 +673,7 @@ int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size)
return PART_NxN; // 000
}
- if (!lc->parent->ps.sps->amp_enabled) {
+ if (!sps->amp_enabled) {
if (GET_CABAC(PART_MODE_OFFSET + 1)) // 01
return PART_2NxN;
return PART_Nx2N;
@@ -979,7 +978,8 @@ static av_always_inline int coeff_sign_flag_decode(HEVCLocalContext *lc, uint8_t
return ret;
}
-void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
+void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0,
int log2_trafo_size, enum ScanType scan_idx,
int c_idx)
{
@@ -989,6 +989,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
y_c = (y_cg << 2) + scan_y_off[n]; \
} while (0)
const HEVCContext *const s = lc->parent;
+ const HEVCSPS *const sps = pps->sps;
int transform_skip_flag = 0;
int last_significant_coeff_x, last_significant_coeff_y;
@@ -1003,10 +1004,10 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
ptrdiff_t stride = s->cur_frame->f->linesize[c_idx];
- int hshift = s->ps.sps->hshift[c_idx];
- int vshift = s->ps.sps->vshift[c_idx];
+ int hshift = sps->hshift[c_idx];
+ int vshift = sps->vshift[c_idx];
uint8_t *dst = &s->cur_frame->f->data[c_idx][(y0 >> vshift) * stride +
- ((x0 >> hshift) << s->ps.sps->pixel_shift)];
+ ((x0 >> hshift) << sps->pixel_shift)];
int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : lc->edge_emu_buffer);
uint8_t significant_coeff_group_flag[8][8] = {{0}};
int explicit_rdpcm_flag = 0;
@@ -1041,25 +1042,25 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
};
int qp_y = lc->qp_y;
- if (s->ps.pps->transform_skip_enabled_flag &&
- log2_trafo_size <= s->ps.pps->log2_max_transform_skip_block_size) {
+ if (pps->transform_skip_enabled_flag &&
+ log2_trafo_size <= pps->log2_max_transform_skip_block_size) {
transform_skip_flag = hevc_transform_skip_flag_decode(lc, c_idx);
}
if (c_idx == 0) {
- qp = qp_y + s->ps.sps->qp_bd_offset;
+ qp = qp_y + sps->qp_bd_offset;
} else {
int qp_i, offset;
if (c_idx == 1)
- offset = s->ps.pps->cb_qp_offset + s->sh.slice_cb_qp_offset +
+ offset = pps->cb_qp_offset + s->sh.slice_cb_qp_offset +
lc->tu.cu_qp_offset_cb;
else
- offset = s->ps.pps->cr_qp_offset + s->sh.slice_cr_qp_offset +
+ offset = pps->cr_qp_offset + s->sh.slice_cr_qp_offset +
lc->tu.cu_qp_offset_cr;
- qp_i = av_clip(qp_y + offset, - s->ps.sps->qp_bd_offset, 57);
- if (s->ps.sps->chroma_format_idc == 1) {
+ qp_i = av_clip(qp_y + offset, - sps->qp_bd_offset, 57);
+ if (sps->chroma_format_idc == 1) {
if (qp_i < 30)
qp = qp_i;
else if (qp_i > 43)
@@ -1073,18 +1074,18 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
qp = qp_i;
}
- qp += s->ps.sps->qp_bd_offset;
+ qp += sps->qp_bd_offset;
}
- shift = s->ps.sps->bit_depth + log2_trafo_size - 5;
+ shift = sps->bit_depth + log2_trafo_size - 5;
add = 1 << (shift-1);
scale = level_scale[rem6[qp]] << (div6[qp]);
scale_m = 16; // default when no custom scaling lists.
dc_scale = 16;
- if (s->ps.sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
- const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ?
- &s->ps.pps->scaling_list : &s->ps.sps->scaling_list;
+ if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
+ const ScalingList *sl = pps->scaling_list_data_present_flag ?
+ &pps->scaling_list : &sps->scaling_list;
int matrix_id = lc->cu.pred_mode != MODE_INTRA;
matrix_id = 3 * matrix_id + c_idx;
@@ -1100,7 +1101,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
dc_scale = 0;
}
- if (lc->cu.pred_mode == MODE_INTER && s->ps.sps->explicit_rdpcm_enabled &&
+ if (lc->cu.pred_mode == MODE_INTER && sps->explicit_rdpcm_enabled &&
(transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
explicit_rdpcm_flag = explicit_rdpcm_flag_decode(lc, c_idx);
if (explicit_rdpcm_flag) {
@@ -1231,7 +1232,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
};
const uint8_t *ctx_idx_map_p;
int scf_offset = 0;
- if (s->ps.sps->transform_skip_context_enabled &&
+ if (sps->transform_skip_context_enabled &&
(transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
ctx_idx_map_p = &ctx_idx_map[4 * 16];
if (c_idx == 0) {
@@ -1272,7 +1273,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
}
}
if (implicit_non_zero_coeff == 0) {
- if (s->ps.sps->transform_skip_context_enabled &&
+ if (sps->transform_skip_context_enabled &&
(transform_skip_flag || lc->cu.cu_transquant_bypass_flag)) {
if (c_idx == 0) {
scf_offset = 42;
@@ -1317,7 +1318,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
// initialize first elem of coeff_bas_level_greater1_flag
int ctx_set = (i > 0 && c_idx == 0) ? 2 : 0;
- if (s->ps.sps->persistent_rice_adaptation_enabled) {
+ if (sps->persistent_rice_adaptation_enabled) {
if (!transform_skip_flag && !lc->cu.cu_transquant_bypass_flag)
sb_type = 2 * (c_idx == 0 ? 1 : 0);
else
@@ -1346,7 +1347,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.cu_transquant_bypass_flag ||
(lc->cu.pred_mode == MODE_INTRA &&
- s->ps.sps->implicit_rdpcm_enabled && transform_skip_flag &&
+ sps->implicit_rdpcm_enabled && transform_skip_flag &&
(pred_mode_intra == 10 || pred_mode_intra == 26 )) ||
explicit_rdpcm_flag)
sign_hidden = 0;
@@ -1356,7 +1357,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
if (first_greater1_coeff_idx != -1) {
coeff_abs_level_greater1_flag[first_greater1_coeff_idx] += coeff_abs_level_greater2_flag_decode(lc, c_idx, ctx_set);
}
- if (!s->ps.pps->sign_data_hiding_flag || !sign_hidden ) {
+ if (!pps->sign_data_hiding_flag || !sign_hidden ) {
coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag) << (16 - nb_significant_coeff_flag);
} else {
coeff_sign_flag = coeff_sign_flag_decode(lc, nb_significant_coeff_flag - 1) << (16 - (nb_significant_coeff_flag - 1));
@@ -1372,8 +1373,8 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
trans_coeff_level += last_coeff_abs_level_remaining;
if (trans_coeff_level > (3 << c_rice_param))
- c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
- if (s->ps.sps->persistent_rice_adaptation_enabled && !rice_init) {
+ c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
+ if (sps->persistent_rice_adaptation_enabled && !rice_init) {
int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
lc->stat_coeff[sb_type]++;
@@ -1388,8 +1389,8 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
trans_coeff_level = 1 + last_coeff_abs_level_remaining;
if (trans_coeff_level > (3 << c_rice_param))
- c_rice_param = s->ps.sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
- if (s->ps.sps->persistent_rice_adaptation_enabled && !rice_init) {
+ c_rice_param = sps->persistent_rice_adaptation_enabled ? c_rice_param + 1 : FFMIN(c_rice_param + 1, 4);
+ if (sps->persistent_rice_adaptation_enabled && !rice_init) {
int c_rice_p_init = lc->stat_coeff[sb_type] / 4;
if (last_coeff_abs_level_remaining >= (3 << c_rice_p_init))
lc->stat_coeff[sb_type]++;
@@ -1399,7 +1400,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
rice_init = 1;
}
}
- if (s->ps.pps->sign_data_hiding_flag && sign_hidden) {
+ if (pps->sign_data_hiding_flag && sign_hidden) {
sum_abs += trans_coeff_level;
if (n == first_nz_pos_in_cg && (sum_abs&1))
trans_coeff_level = -trans_coeff_level;
@@ -1408,7 +1409,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
trans_coeff_level = -trans_coeff_level;
coeff_sign_flag <<= 1;
if(!lc->cu.cu_transquant_bypass_flag) {
- if (s->ps.sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
+ if (sps->scaling_list_enabled && !(transform_skip_flag && log2_trafo_size > 2)) {
if(y_c || x_c || log2_trafo_size < 4) {
switch(log2_trafo_size) {
case 3: pos = (y_c << 3) + x_c; break;
@@ -1436,15 +1437,15 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
}
if (lc->cu.cu_transquant_bypass_flag) {
- if (explicit_rdpcm_flag || (s->ps.sps->implicit_rdpcm_enabled &&
+ if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
(pred_mode_intra == 10 || pred_mode_intra == 26))) {
- int mode = s->ps.sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
+ int mode = sps->implicit_rdpcm_enabled ? (pred_mode_intra == 26) : explicit_rdpcm_dir_flag;
s->hevcdsp.transform_rdpcm(coeffs, log2_trafo_size, mode);
}
} else {
if (transform_skip_flag) {
- int rot = s->ps.sps->transform_skip_rotation_enabled &&
+ int rot = sps->transform_skip_rotation_enabled &&
log2_trafo_size == 2 &&
lc->cu.pred_mode == MODE_INTRA;
if (rot) {
@@ -1454,7 +1455,7 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
s->hevcdsp.dequant(coeffs, log2_trafo_size);
- if (explicit_rdpcm_flag || (s->ps.sps->implicit_rdpcm_enabled &&
+ if (explicit_rdpcm_flag || (sps->implicit_rdpcm_enabled &&
lc->cu.pred_mode == MODE_INTRA &&
(pred_mode_intra == 10 || pred_mode_intra == 26))) {
int mode = explicit_rdpcm_flag ? explicit_rdpcm_dir_flag : (pred_mode_intra == 26);
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index eeeaae6e3a..cf972ed560 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1097,7 +1097,7 @@ static void hls_sao_param(HEVCLocalContext *lc, int rx, int ry)
continue;
for (i = 0; i < 4; i++)
- SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc));
+ SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, s->ps.sps->bit_depth));
if (sao->type_idx[c_idx] == SAO_BAND) {
for (i = 0; i < 4; i++) {
@@ -1198,7 +1198,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (cu_chroma_qp_offset_flag) {
int cu_chroma_qp_offset_idx = 0;
if (s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
- cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc);
+ cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, s->ps.pps->chroma_qp_offset_list_len_minus1);
av_log(s->avctx, AV_LOG_ERROR,
"cu_chroma_qp_offset_idx not yet tested.\n");
}
@@ -1232,7 +1232,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
lc->tu.cross_pf = 0;
if (cbf_luma)
- ff_hevc_hls_residual_coding(lc, x0, y0, log2_trafo_size, scan_idx, 0);
+ ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0, log2_trafo_size, scan_idx, 0);
if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
@@ -1250,7 +1250,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 1);
}
if (cbf_cb[i])
- ff_hevc_hls_residual_coding(lc, x0, y0 + (i << log2_trafo_size_c),
+ ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c),
log2_trafo_size_c, scan_idx_c, 1);
else
if (lc->tu.cross_pf) {
@@ -1280,7 +1280,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 2);
}
if (cbf_cr[i])
- ff_hevc_hls_residual_coding(lc, x0, y0 + (i << log2_trafo_size_c),
+ ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c),
log2_trafo_size_c, scan_idx_c, 2);
else
if (lc->tu.cross_pf) {
@@ -1309,7 +1309,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 1);
}
if (cbf_cb[i])
- ff_hevc_hls_residual_coding(lc, xBase, yBase + (i << log2_trafo_size),
+ ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size),
log2_trafo_size, scan_idx_c, 1);
}
for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
@@ -1319,7 +1319,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 2);
}
if (cbf_cr[i])
- ff_hevc_hls_residual_coding(lc, xBase, yBase + (i << log2_trafo_size),
+ ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size),
log2_trafo_size, scan_idx_c, 2);
}
}
@@ -2263,7 +2263,10 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
lc->cu.cu_transquant_bypass_flag = 0;
if (s->sh.slice_type != HEVC_SLICE_I) {
- uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, x0, y0, x_cb, y_cb);
+ const int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
+ const int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
+ uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, x0b, y0b, x_cb, y_cb,
+ min_cb_width);
x = y_cb * min_cb_width + x_cb;
for (y = 0; y < length; y++) {
@@ -2292,7 +2295,7 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc);
if (lc->cu.pred_mode != MODE_INTRA ||
log2_cb_size == s->ps.sps->log2_min_cb_size) {
- lc->cu.part_mode = ff_hevc_part_mode_decode(lc, log2_cb_size);
+ lc->cu.part_mode = ff_hevc_part_mode_decode(lc, s->ps.sps, log2_cb_size);
lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
lc->cu.pred_mode == MODE_INTRA;
}
@@ -2408,7 +2411,7 @@ static int hls_coding_quadtree(HEVCLocalContext *lc, int x0, int y0,
if (x0 + cb_size <= s->ps.sps->width &&
y0 + cb_size <= s->ps.sps->height &&
log2_cb_size > s->ps.sps->log2_min_cb_size) {
- split_cu = ff_hevc_split_coding_unit_flag_decode(lc, cb_depth, x0, y0);
+ split_cu = ff_hevc_split_coding_unit_flag_decode(lc, s->ps.sps, cb_depth, x0, y0);
} else {
split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size);
}
@@ -2562,7 +2565,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
hls_decode_neighbour(lc, x_ctb, y_ctb, ctb_addr_ts);
- ret = ff_hevc_cabac_init(lc, ctb_addr_ts, slice_data, slice_size);
+ ret = ff_hevc_cabac_init(lc, s->ps.pps, ctb_addr_ts, slice_data, slice_size);
if (ret < 0) {
s->tab_slice_address[ctb_addr_rs] = -1;
return ret;
@@ -2582,7 +2585,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
ctb_addr_ts++;
- ff_hevc_save_states(lc, ctb_addr_ts);
+ ff_hevc_save_states(lc, s->ps.pps, ctb_addr_ts);
ff_hevc_hls_filters(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
}
@@ -2629,7 +2632,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
return 0;
}
- ret = ff_hevc_cabac_init(lc, ctb_addr_ts, data, data_size);
+ ret = ff_hevc_cabac_init(lc, s->ps.pps, ctb_addr_ts, data, data_size);
if (ret < 0)
goto error;
hls_sao_param(lc, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
@@ -2642,7 +2645,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
ctb_addr_ts++;
- ff_hevc_save_states(lc, ctb_addr_ts);
+ ff_hevc_save_states(lc, s->ps.pps, ctb_addr_ts);
ff_thread_report_progress2(s->avctx, ctb_row, thread, 1);
ff_hevc_hls_filters(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 8816ebe1f4..3d1a36ecd4 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -576,23 +576,24 @@ int ff_hevc_frame_rps(HEVCContext *s);
*/
int ff_hevc_slice_rpl(HEVCContext *s);
-void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts);
-int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts,
- const uint8_t *data, size_t size);
+void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int ctb_addr_ts);
+int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int ctb_addr_ts, const uint8_t *data, size_t size);
int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc);
int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc);
int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc);
-int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc);
+int ff_hevc_sao_offset_abs_decode(HEVCLocalContext *lc, int bit_depth);
int ff_hevc_sao_offset_sign_decode(HEVCLocalContext *lc);
int ff_hevc_sao_eo_class_decode(HEVCLocalContext *lc);
int ff_hevc_end_of_slice_flag_decode(HEVCLocalContext *lc);
int ff_hevc_cu_transquant_bypass_flag_decode(HEVCLocalContext *lc);
int ff_hevc_skip_flag_decode(HEVCLocalContext *lc, int x0, int y0,
- int x_cb, int y_cb);
+ int x_cb, int y_cb, int min_cb_width);
int ff_hevc_pred_mode_decode(HEVCLocalContext *lc);
-int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, int ct_depth,
- int x0, int y0);
-int ff_hevc_part_mode_decode(HEVCLocalContext *lc, int log2_cb_size);
+int ff_hevc_split_coding_unit_flag_decode(HEVCLocalContext *lc, const HEVCSPS *sps,
+ int ct_depth, int x0, int y0);
+int ff_hevc_part_mode_decode(HEVCLocalContext *lc, const HEVCSPS *sps, int log2_cb_size);
int ff_hevc_pcm_flag_decode(HEVCLocalContext *lc);
int ff_hevc_prev_intra_luma_pred_flag_decode(HEVCLocalContext *lc);
int ff_hevc_mpm_idx_decode(HEVCLocalContext *lc);
@@ -666,8 +667,9 @@ void ff_hevc_deblocking_boundary_strengths(HEVCLocalContext *lc, const HEVCPPS *
int ff_hevc_cu_qp_delta_sign_flag(HEVCLocalContext *lc);
int ff_hevc_cu_qp_delta_abs(HEVCLocalContext *lc);
int ff_hevc_cu_chroma_qp_offset_flag(HEVCLocalContext *lc);
-int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc);
-void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, int x0, int y0,
+int ff_hevc_cu_chroma_qp_offset_idx(HEVCLocalContext *lc, int chroma_qp_offset_list_len_minus1);
+void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0,
int log2_trafo_size, enum ScanType scan_idx,
int c_idx);
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 10/39] lavc/hevc/pred: stop accessing parameter sets through HEVCParamSets
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (7 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 09/39] lavc/hevc/cabac: " Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 11/39] lavc/hevcdec: " Anton Khirnov
` (28 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Instead, accept PPS/SPS as function arguments.
Makes the code shorter and significantly reduces diff in future commits.
---
libavcodec/hevc/hevcdec.c | 26 +--
libavcodec/hevc/pred.h | 4 +-
libavcodec/hevc/pred_template.c | 74 ++++----
libavcodec/mips/hevcpred_mips.h | 4 +-
libavcodec/mips/hevcpred_msa.c | 291 ++++++++++++++++----------------
5 files changed, 202 insertions(+), 197 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index cf972ed560..5e4e5776e0 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1160,7 +1160,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
int trafo_size = 1 << log2_trafo_size;
ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, x0, y0, 0);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, x0, y0, 0);
}
if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
@@ -1247,7 +1247,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 1);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c), 1);
}
if (cbf_cb[i])
ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c),
@@ -1277,7 +1277,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i << log2_trafo_size_c), 2);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c), 2);
}
if (cbf_cr[i])
ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c),
@@ -1306,7 +1306,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 1);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size), 1);
}
if (cbf_cb[i])
ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size),
@@ -1316,7 +1316,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (i << log2_trafo_size), 2);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size), 2);
}
if (cbf_cr[i])
ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size),
@@ -1329,26 +1329,26 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 1);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 2);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0, 1);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0, 2);
if (s->ps.sps->chroma_format_idc == 2) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (1 << log2_trafo_size_c), 1);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (1 << log2_trafo_size_c), 2);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (1 << log2_trafo_size_c), 1);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (1 << log2_trafo_size_c), 2);
}
} else if (blk_idx == 3) {
int trafo_size_h = 1 << (log2_trafo_size + 1);
int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
ff_hevc_set_neighbour_available(lc, xBase, yBase,
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase, 1);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase, 2);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase, 1);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase, 2);
if (s->ps.sps->chroma_format_idc == 2) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (1 << log2_trafo_size), 1);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + (1 << log2_trafo_size), 2);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (1 << log2_trafo_size), 1);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (1 << log2_trafo_size), 2);
}
}
}
diff --git a/libavcodec/hevc/pred.h b/libavcodec/hevc/pred.h
index b60d8176ae..1ac8f9666b 100644
--- a/libavcodec/hevc/pred.h
+++ b/libavcodec/hevc/pred.h
@@ -27,9 +27,11 @@
#include <stdint.h>
struct HEVCLocalContext;
+struct HEVCPPS;
typedef struct HEVCPredContext {
- void (*intra_pred[4])(struct HEVCLocalContext *lc, int x0, int y0, int c_idx);
+ void (*intra_pred[4])(struct HEVCLocalContext *lc,
+ const struct HEVCPPS *pps, int x0, int y0, int c_idx);
void (*pred_planar[4])(uint8_t *src, const uint8_t *top,
const uint8_t *left, ptrdiff_t stride);
diff --git a/libavcodec/hevc/pred_template.c b/libavcodec/hevc/pred_template.c
index fe9a22614a..ca21774f75 100644
--- a/libavcodec/hevc/pred_template.c
+++ b/libavcodec/hevc/pred_template.c
@@ -27,11 +27,13 @@
#define POS(x, y) src[(x) + stride * (y)]
-static av_always_inline void FUNC(intra_pred)(HEVCLocalContext *lc, int x0, int y0,
+static av_always_inline void FUNC(intra_pred)(HEVCLocalContext *lc,
+ const HEVCPPS *pps,
+ int x0, int y0,
int log2_size, int c_idx)
{
#define PU(x) \
- ((x) >> s->ps.sps->log2_min_pu_size)
+ ((x) >> sps->log2_min_pu_size)
#define MVF(x, y) \
(s->cur_frame->tab_mvf[(x) + (y) * min_pu_width])
#define MVF_PU(x, y) \
@@ -39,7 +41,7 @@ static av_always_inline void FUNC(intra_pred)(HEVCLocalContext *lc, int x0, int
#define IS_INTRA(x, y) \
(MVF_PU(x, y).pred_flag == PF_INTRA)
#define MIN_TB_ADDR_ZS(x, y) \
- s->ps.pps->min_tb_addr_zs[(y) * (s->ps.sps->tb_mask+2) + (x)]
+ pps->min_tb_addr_zs[(y) * (sps->tb_mask+2) + (x)]
#define EXTEND(ptr, val, len) \
do { \
pixel4 pix = PIXEL_SPLAT_X4(val); \
@@ -70,27 +72,28 @@ do { \
else \
a = PIXEL_SPLAT_X4(ptr[i + 3])
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
int i;
- int hshift = s->ps.sps->hshift[c_idx];
- int vshift = s->ps.sps->vshift[c_idx];
+ int hshift = sps->hshift[c_idx];
+ int vshift = sps->vshift[c_idx];
int size = (1 << log2_size);
int size_in_luma_h = size << hshift;
- int size_in_tbs_h = size_in_luma_h >> s->ps.sps->log2_min_tb_size;
+ int size_in_tbs_h = size_in_luma_h >> sps->log2_min_tb_size;
int size_in_luma_v = size << vshift;
- int size_in_tbs_v = size_in_luma_v >> s->ps.sps->log2_min_tb_size;
+ int size_in_tbs_v = size_in_luma_v >> sps->log2_min_tb_size;
int x = x0 >> hshift;
int y = y0 >> vshift;
- int x_tb = (x0 >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask;
- int y_tb = (y0 >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask;
- int spin = c_idx && !size_in_tbs_v && ((2 * y0) & (1 << s->ps.sps->log2_min_tb_size));
+ int x_tb = (x0 >> sps->log2_min_tb_size) & sps->tb_mask;
+ int y_tb = (y0 >> sps->log2_min_tb_size) & sps->tb_mask;
+ int spin = c_idx && !size_in_tbs_v && ((2 * y0) & (1 << sps->log2_min_tb_size));
int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb);
ptrdiff_t stride = s->cur_frame->f->linesize[c_idx] / sizeof(pixel);
pixel *src = (pixel*)s->cur_frame->f->data[c_idx] + x + y * stride;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
enum IntraPredMode mode = c_idx ? lc->tu.intra_pred_mode_c :
lc->tu.intra_pred_mode;
@@ -104,28 +107,28 @@ do { \
pixel *top = top_array + 1;
pixel *filtered_left = filtered_left_array + 1;
pixel *filtered_top = filtered_top_array + 1;
- int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS( x_tb - 1, (y_tb + size_in_tbs_v + spin) & s->ps.sps->tb_mask);
+ int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS( x_tb - 1, (y_tb + size_in_tbs_v + spin) & sps->tb_mask);
int cand_left = lc->na.cand_left;
int cand_up_left = lc->na.cand_up_left;
int cand_up = lc->na.cand_up;
- int cand_up_right = lc->na.cand_up_right && !spin && cur_tb_addr > MIN_TB_ADDR_ZS((x_tb + size_in_tbs_h) & s->ps.sps->tb_mask, y_tb - 1);
+ int cand_up_right = lc->na.cand_up_right && !spin && cur_tb_addr > MIN_TB_ADDR_ZS((x_tb + size_in_tbs_h) & sps->tb_mask, y_tb - 1);
- int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma_v, s->ps.sps->height) -
+ int bottom_left_size = (FFMIN(y0 + 2 * size_in_luma_v, sps->height) -
(y0 + size_in_luma_v)) >> vshift;
- int top_right_size = (FFMIN(x0 + 2 * size_in_luma_h, s->ps.sps->width) -
+ int top_right_size = (FFMIN(x0 + 2 * size_in_luma_h, sps->width) -
(x0 + size_in_luma_h)) >> hshift;
- if (s->ps.pps->constrained_intra_pred_flag == 1) {
+ if (pps->constrained_intra_pred_flag == 1) {
int size_in_luma_pu_v = PU(size_in_luma_v);
int size_in_luma_pu_h = PU(size_in_luma_h);
- int on_pu_edge_x = !av_mod_uintp2(x0, s->ps.sps->log2_min_pu_size);
- int on_pu_edge_y = !av_mod_uintp2(y0, s->ps.sps->log2_min_pu_size);
+ int on_pu_edge_x = !av_mod_uintp2(x0, sps->log2_min_pu_size);
+ int on_pu_edge_y = !av_mod_uintp2(y0, sps->log2_min_pu_size);
if (!size_in_luma_pu_h)
size_in_luma_pu_h++;
if (cand_bottom_left == 1 && on_pu_edge_x) {
int x_left_pu = PU(x0 - 1);
int y_bottom_pu = PU(y0 + size_in_luma_v);
- int max = FFMIN(size_in_luma_pu_v, s->ps.sps->min_pu_height - y_bottom_pu);
+ int max = FFMIN(size_in_luma_pu_v, sps->min_pu_height - y_bottom_pu);
cand_bottom_left = 0;
for (i = 0; i < max; i += 2)
cand_bottom_left |= (MVF(x_left_pu, y_bottom_pu + i).pred_flag == PF_INTRA);
@@ -133,7 +136,7 @@ do { \
if (cand_left == 1 && on_pu_edge_x) {
int x_left_pu = PU(x0 - 1);
int y_left_pu = PU(y0);
- int max = FFMIN(size_in_luma_pu_v, s->ps.sps->min_pu_height - y_left_pu);
+ int max = FFMIN(size_in_luma_pu_v, sps->min_pu_height - y_left_pu);
cand_left = 0;
for (i = 0; i < max; i += 2)
cand_left |= (MVF(x_left_pu, y_left_pu + i).pred_flag == PF_INTRA);
@@ -146,7 +149,7 @@ do { \
if (cand_up == 1 && on_pu_edge_y) {
int x_top_pu = PU(x0);
int y_top_pu = PU(y0 - 1);
- int max = FFMIN(size_in_luma_pu_h, s->ps.sps->min_pu_width - x_top_pu);
+ int max = FFMIN(size_in_luma_pu_h, sps->min_pu_width - x_top_pu);
cand_up = 0;
for (i = 0; i < max; i += 2)
cand_up |= (MVF(x_top_pu + i, y_top_pu).pred_flag == PF_INTRA);
@@ -154,7 +157,7 @@ do { \
if (cand_up_right == 1 && on_pu_edge_y) {
int y_top_pu = PU(y0 - 1);
int x_right_pu = PU(x0 + size_in_luma_h);
- int max = FFMIN(size_in_luma_pu_h, s->ps.sps->min_pu_width - x_right_pu);
+ int max = FFMIN(size_in_luma_pu_h, sps->min_pu_width - x_right_pu);
cand_up_right = 0;
for (i = 0; i < max; i += 2)
cand_up_right |= (MVF(x_right_pu + i, y_top_pu).pred_flag == PF_INTRA);
@@ -184,20 +187,20 @@ do { \
size - bottom_left_size);
}
- if (s->ps.pps->constrained_intra_pred_flag == 1) {
+ if (pps->constrained_intra_pred_flag == 1) {
if (cand_bottom_left || cand_left || cand_up_left || cand_up || cand_up_right) {
- int size_max_x = x0 + ((2 * size) << hshift) < s->ps.sps->width ?
- 2 * size : (s->ps.sps->width - x0) >> hshift;
- int size_max_y = y0 + ((2 * size) << vshift) < s->ps.sps->height ?
- 2 * size : (s->ps.sps->height - y0) >> vshift;
+ int size_max_x = x0 + ((2 * size) << hshift) < sps->width ?
+ 2 * size : (sps->width - x0) >> hshift;
+ int size_max_y = y0 + ((2 * size) << vshift) < sps->height ?
+ 2 * size : (sps->height - y0) >> vshift;
int j = size + (cand_bottom_left? bottom_left_size: 0) -1;
if (!cand_up_right) {
- size_max_x = x0 + ((size) << hshift) < s->ps.sps->width ?
- size : (s->ps.sps->width - x0) >> hshift;
+ size_max_x = x0 + ((size) << hshift) < sps->width ?
+ size : (sps->width - x0) >> hshift;
}
if (!cand_bottom_left) {
- size_max_y = y0 + (( size) << vshift) < s->ps.sps->height ?
- size : (s->ps.sps->height - y0) >> vshift;
+ size_max_y = y0 + (( size) << vshift) < sps->height ?
+ size : (sps->height - y0) >> vshift;
}
if (cand_bottom_left || cand_left || cand_up_left) {
while (j > -1 && !IS_INTRA(-1, j))
@@ -285,14 +288,14 @@ do { \
top[-1] = left[-1];
// Filtering process
- if (!s->ps.sps->intra_smoothing_disabled && (c_idx == 0 || s->ps.sps->chroma_format_idc == 3)) {
+ if (!sps->intra_smoothing_disabled && (c_idx == 0 || sps->chroma_format_idc == 3)) {
if (mode != INTRA_DC && size != 4){
int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)),
FFABS((int)(mode - 10U)));
if (min_dist_vert_hor > intra_hor_ver_dist_thresh[log2_size - 3]) {
int threshold = 1 << (BIT_DEPTH - 5);
- if (s->ps.sps->strong_intra_smoothing_enabled && c_idx == 0 &&
+ if (sps->strong_intra_smoothing_enabled && c_idx == 0 &&
log2_size == 5 &&
FFABS(top[-1] + top[63] - 2 * top[31]) < threshold &&
FFABS(left[-1] + left[63] - 2 * left[31]) < threshold) {
@@ -343,9 +346,10 @@ do { \
}
#define INTRA_PRED(size) \
-static void FUNC(intra_pred_ ## size)(HEVCLocalContext *lc, int x0, int y0, int c_idx) \
+static void FUNC(intra_pred_ ## size)(HEVCLocalContext *lc, const HEVCPPS *pps, \
+ int x0, int y0, int c_idx) \
{ \
- FUNC(intra_pred)(lc, x0, y0, size, c_idx); \
+ FUNC(intra_pred)(lc, pps, x0, y0, size, c_idx); \
}
INTRA_PRED(2)
diff --git a/libavcodec/mips/hevcpred_mips.h b/libavcodec/mips/hevcpred_mips.h
index 220ab307af..692a162151 100644
--- a/libavcodec/mips/hevcpred_mips.h
+++ b/libavcodec/mips/hevcpred_mips.h
@@ -67,7 +67,7 @@ void ff_pred_intra_pred_angular_3_msa(uint8_t *dst,
const uint8_t *src_left,
ptrdiff_t stride, int c_idx, int mode);
-void ff_intra_pred_8_16x16_msa(struct HEVCLocalContext *s, int x0, int y0, int c_idx);
-void ff_intra_pred_8_32x32_msa(struct HEVCLocalContext *s, int x0, int y0, int c_idx);
+void ff_intra_pred_8_16x16_msa(struct HEVCLocalContext *s, const struct HEVCPPS *pps, int x0, int y0, int c_idx);
+void ff_intra_pred_8_32x32_msa(struct HEVCLocalContext *s, const struct HEVCPPS *pps, int x0, int y0, int c_idx);
#endif // #ifndef AVCODEC_MIPS_HEVCPRED_MIPS_H
diff --git a/libavcodec/mips/hevcpred_msa.c b/libavcodec/mips/hevcpred_msa.c
index ef70d6b2e5..a6824712a2 100644
--- a/libavcodec/mips/hevcpred_msa.c
+++ b/libavcodec/mips/hevcpred_msa.c
@@ -1903,29 +1903,31 @@ void ff_pred_intra_pred_angular_3_msa(uint8_t *dst,
}
}
-void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
+void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0, int c_idx)
{
v16u8 vec0;
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
int i;
- int hshift = s->ps.sps->hshift[c_idx];
- int vshift = s->ps.sps->vshift[c_idx];
+ int hshift = sps->hshift[c_idx];
+ int vshift = sps->vshift[c_idx];
int size_in_luma_h = 16 << hshift;
- int size_in_tbs_h = size_in_luma_h >> s->ps.sps->log2_min_tb_size;
+ int size_in_tbs_h = size_in_luma_h >> sps->log2_min_tb_size;
int size_in_luma_v = 16 << vshift;
- int size_in_tbs_v = size_in_luma_v >> s->ps.sps->log2_min_tb_size;
+ int size_in_tbs_v = size_in_luma_v >> sps->log2_min_tb_size;
int x = x0 >> hshift;
int y = y0 >> vshift;
- int x_tb = (x0 >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask;
- int y_tb = (y0 >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask;
+ int x_tb = (x0 >> sps->log2_min_tb_size) & sps->tb_mask;
+ int y_tb = (y0 >> sps->log2_min_tb_size) & sps->tb_mask;
int cur_tb_addr =
- s->ps.pps->min_tb_addr_zs[(y_tb) * (s->ps.sps->tb_mask + 2) + (x_tb)];
+ pps->min_tb_addr_zs[(y_tb) * (sps->tb_mask + 2) + (x_tb)];
ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(uint8_t);
uint8_t *src = (uint8_t *) s->frame->data[c_idx] + x + y * stride;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
enum IntraPredMode mode = c_idx ? lc->tu.intra_pred_mode_c :
lc->tu.intra_pred_mode;
@@ -1941,41 +1943,41 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
uint8_t *filtered_top = filtered_top_array + 1;
int cand_bottom_left = lc->na.cand_bottom_left
&& cur_tb_addr >
- s->ps.pps->min_tb_addr_zs[((y_tb + size_in_tbs_v) & s->ps.sps->tb_mask) *
- (s->ps.sps->tb_mask + 2) + (x_tb - 1)];
+ pps->min_tb_addr_zs[((y_tb + size_in_tbs_v) & sps->tb_mask) *
+ (sps->tb_mask + 2) + (x_tb - 1)];
int cand_left = lc->na.cand_left;
int cand_up_left = lc->na.cand_up_left;
int cand_up = lc->na.cand_up;
int cand_up_right = lc->na.cand_up_right
&& cur_tb_addr >
- s->ps.pps->min_tb_addr_zs[(y_tb - 1) * (s->ps.sps->tb_mask + 2) +
- ((x_tb + size_in_tbs_h) & s->ps.sps->tb_mask)];
+ pps->min_tb_addr_zs[(y_tb - 1) * (sps->tb_mask + 2) +
+ ((x_tb + size_in_tbs_h) & sps->tb_mask)];
int bottom_left_size =
(((y0 + 2 * size_in_luma_v) >
- (s->ps.sps->height) ? (s->ps.sps->height) : (y0 +
+ (sps->height) ? (sps->height) : (y0 +
2 * size_in_luma_v)) -
(y0 + size_in_luma_v)) >> vshift;
int top_right_size =
(((x0 + 2 * size_in_luma_h) >
- (s->ps.sps->width) ? (s->ps.sps->width) : (x0 + 2 * size_in_luma_h)) -
+ (sps->width) ? (sps->width) : (x0 + 2 * size_in_luma_h)) -
(x0 + size_in_luma_h)) >> hshift;
- if (s->ps.pps->constrained_intra_pred_flag == 1) {
- int size_in_luma_pu_v = ((size_in_luma_v) >> s->ps.sps->log2_min_pu_size);
- int size_in_luma_pu_h = ((size_in_luma_h) >> s->ps.sps->log2_min_pu_size);
- int on_pu_edge_x = !(x0 & ((1 << s->ps.sps->log2_min_pu_size) - 1));
- int on_pu_edge_y = !(y0 & ((1 << s->ps.sps->log2_min_pu_size) - 1));
+ if (pps->constrained_intra_pred_flag == 1) {
+ int size_in_luma_pu_v = ((size_in_luma_v) >> sps->log2_min_pu_size);
+ int size_in_luma_pu_h = ((size_in_luma_h) >> sps->log2_min_pu_size);
+ int on_pu_edge_x = !(x0 & ((1 << sps->log2_min_pu_size) - 1));
+ int on_pu_edge_y = !(y0 & ((1 << sps->log2_min_pu_size) - 1));
if (!size_in_luma_pu_h)
size_in_luma_pu_h++;
if (cand_bottom_left == 1 && on_pu_edge_x) {
- int x_left_pu = ((x0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int x_left_pu = ((x0 - 1) >> sps->log2_min_pu_size);
int y_bottom_pu =
- ((y0 + size_in_luma_v) >> s->ps.sps->log2_min_pu_size);
+ ((y0 + size_in_luma_v) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_v) >
- (s->ps.sps->min_pu_height -
- y_bottom_pu) ? (s->ps.sps->min_pu_height -
+ (sps->min_pu_height -
+ y_bottom_pu) ? (sps->min_pu_height -
y_bottom_pu) : (size_in_luma_pu_v));
cand_bottom_left = 0;
for (i = 0; i < max; i += 2)
@@ -1986,12 +1988,12 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
PF_INTRA);
}
if (cand_left == 1 && on_pu_edge_x) {
- int x_left_pu = ((x0 - 1) >> s->ps.sps->log2_min_pu_size);
- int y_left_pu = ((y0) >> s->ps.sps->log2_min_pu_size);
+ int x_left_pu = ((x0 - 1) >> sps->log2_min_pu_size);
+ int y_left_pu = ((y0) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_v) >
- (s->ps.sps->min_pu_height -
- y_left_pu) ? (s->ps.sps->min_pu_height -
+ (sps->min_pu_height -
+ y_left_pu) ? (sps->min_pu_height -
y_left_pu) : (size_in_luma_pu_v));
cand_left = 0;
for (i = 0; i < max; i += 2)
@@ -2002,20 +2004,20 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
PF_INTRA);
}
if (cand_up_left == 1) {
- int x_left_pu = ((x0 - 1) >> s->ps.sps->log2_min_pu_size);
- int y_top_pu = ((y0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int x_left_pu = ((x0 - 1) >> sps->log2_min_pu_size);
+ int y_top_pu = ((y0 - 1) >> sps->log2_min_pu_size);
cand_up_left =
(s->cur_frame->tab_mvf[(x_left_pu) +
(y_top_pu) * min_pu_width]).pred_flag ==
PF_INTRA;
}
if (cand_up == 1 && on_pu_edge_y) {
- int x_top_pu = ((x0) >> s->ps.sps->log2_min_pu_size);
- int y_top_pu = ((y0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int x_top_pu = ((x0) >> sps->log2_min_pu_size);
+ int y_top_pu = ((y0 - 1) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_h) >
- (s->ps.sps->min_pu_width -
- x_top_pu) ? (s->ps.sps->min_pu_width -
+ (sps->min_pu_width -
+ x_top_pu) ? (sps->min_pu_width -
x_top_pu) : (size_in_luma_pu_h));
cand_up = 0;
for (i = 0; i < max; i += 2)
@@ -2025,13 +2027,13 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
min_pu_width]).pred_flag == PF_INTRA);
}
if (cand_up_right == 1 && on_pu_edge_y) {
- int y_top_pu = ((y0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int y_top_pu = ((y0 - 1) >> sps->log2_min_pu_size);
int x_right_pu =
- ((x0 + size_in_luma_h) >> s->ps.sps->log2_min_pu_size);
+ ((x0 + size_in_luma_h) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_h) >
- (s->ps.sps->min_pu_width -
- x_right_pu) ? (s->ps.sps->min_pu_width -
+ (sps->min_pu_width -
+ x_right_pu) ? (sps->min_pu_width -
x_right_pu) : (size_in_luma_pu_h));
cand_up_right = 0;
for (i = 0; i < max; i += 2)
@@ -2086,56 +2088,55 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
} while (0);
}
- if (s->ps.pps->constrained_intra_pred_flag == 1) {
+ if (pps->constrained_intra_pred_flag == 1) {
if (cand_bottom_left || cand_left || cand_up_left || cand_up
|| cand_up_right) {
int size_max_x =
x0 + ((2 * 16) << hshift) <
- s->ps.sps->width ? 2 * 16 : (s->ps.sps->width - x0) >> hshift;
+ sps->width ? 2 * 16 : (sps->width - x0) >> hshift;
int size_max_y =
y0 + ((2 * 16) << vshift) <
- s->ps.sps->height ? 2 * 16 : (s->ps.sps->height - y0) >> vshift;
+ sps->height ? 2 * 16 : (sps->height - y0) >> vshift;
int j = 16 + (cand_bottom_left ? bottom_left_size : 0) - 1;
if (!cand_up_right) {
- size_max_x = x0 + ((16) << hshift) < s->ps.sps->width ?
- 16 : (s->ps.sps->width - x0) >> hshift;
+ size_max_x = x0 + ((16) << hshift) < sps->width ?
+ 16 : (sps->width - x0) >> hshift;
}
if (!cand_bottom_left) {
- size_max_y = y0 + ((16) << vshift) < s->ps.sps->height ?
- 16 : (s->ps.sps->height - y0) >> vshift;
+ size_max_y = y0 + ((16) << vshift) < sps->height ?
+ 16 : (sps->height - y0) >> vshift;
}
if (cand_bottom_left || cand_left || cand_up_left) {
while (j > -1
&&
!((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((j) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
j--;
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((j)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag == PF_INTRA)) {
j = 0;
while (j < size_max_x
&&
!((s->cur_frame->tab_mvf[(((x0 +
- ((j) << hshift)) >> s->ps.sps->
+ ((j) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((-1) <<
vshift))
- >> s->
- ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2144,12 +2145,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
if (!
((s->cur_frame->tab_mvf[(((x0 +
((i -
- 1) << hshift)) >> s->ps.sps->
+ 1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((-1) <<
vshift))
- >> s->
- ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2161,11 +2161,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
while (j < size_max_x
&&
!((s->cur_frame->tab_mvf[(((x0 +
- ((j) << hshift)) >> s->ps.sps->
+ ((j) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((-1)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2177,11 +2177,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
((s->cur_frame->tab_mvf[(((x0 +
((i -
1) << hshift)) >>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
+ (((y0 + ((-1)
<< vshift))
>>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
*
min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2192,11 +2192,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
((s->cur_frame->tab_mvf[(((x0 +
((i -
1) << hshift)) >>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
+ (((y0 + ((-1)
<< vshift))
>>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
*
min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2211,11 +2211,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
for (i = 0; i < (0) + (size_max_y); i += 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((i) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2240,12 +2240,12 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
i > (size_max_y - 1) - (size_max_y); i -= 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((i -
3) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2254,11 +2254,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
a = ((left[i - 3]) * 0x01010101U);
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((-1)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag == PF_INTRA))
left[-1] = left[0];
@@ -2274,12 +2274,12 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
i > (size_max_y - 1) - (size_max_y); i -= 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((i -
3) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2293,11 +2293,11 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
for (i = 0; i < (0) + (size_max_x); i += 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((i) << hshift)) >> s->ps.sps->
+ ((i) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((-1)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2369,8 +2369,8 @@ void ff_intra_pred_8_16x16_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
top[-1] = left[-1];
- if (!s->ps.sps->intra_smoothing_disabled
- && (c_idx == 0 || s->ps.sps->chroma_format_idc == 3)) {
+ if (!sps->intra_smoothing_disabled
+ && (c_idx == 0 || sps->chroma_format_idc == 3)) {
if (mode != INTRA_DC && 16 != 4) {
int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
int min_dist_vert_hor =
@@ -2423,26 +2423,27 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
v8i16 res0, res1, res2, res3;
v8i16 mul_val0 = { 63, 62, 61, 60, 59, 58, 57, 56 };
v8i16 mul_val1 = { 1, 2, 3, 4, 5, 6, 7, 8 };
+ const HEVCSPS *const sps = pps->sps;
const HEVCContext *const s = lc->parent;
int i;
- int hshift = s->ps.sps->hshift[c_idx];
- int vshift = s->ps.sps->vshift[c_idx];
+ int hshift = sps->hshift[c_idx];
+ int vshift = sps->vshift[c_idx];
int size_in_luma_h = 32 << hshift;
- int size_in_tbs_h = size_in_luma_h >> s->ps.sps->log2_min_tb_size;
+ int size_in_tbs_h = size_in_luma_h >> sps->log2_min_tb_size;
int size_in_luma_v = 32 << vshift;
- int size_in_tbs_v = size_in_luma_v >> s->ps.sps->log2_min_tb_size;
+ int size_in_tbs_v = size_in_luma_v >> sps->log2_min_tb_size;
int x = x0 >> hshift;
int y = y0 >> vshift;
- int x_tb = (x0 >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask;
- int y_tb = (y0 >> s->ps.sps->log2_min_tb_size) & s->ps.sps->tb_mask;
+ int x_tb = (x0 >> sps->log2_min_tb_size) & sps->tb_mask;
+ int y_tb = (y0 >> sps->log2_min_tb_size) & sps->tb_mask;
int cur_tb_addr =
- s->ps.pps->min_tb_addr_zs[(y_tb) * (s->ps.sps->tb_mask + 2) + (x_tb)];
+ pps->min_tb_addr_zs[(y_tb) * (sps->tb_mask + 2) + (x_tb)];
ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(uint8_t);
uint8_t *src = (uint8_t *) s->frame->data[c_idx] + x + y * stride;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
enum IntraPredMode mode = c_idx ? lc->tu.intra_pred_mode_c :
lc->tu.intra_pred_mode;
@@ -2458,41 +2459,41 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
uint8_t *filtered_top = filtered_top_array + 1;
int cand_bottom_left = lc->na.cand_bottom_left
&& cur_tb_addr >
- s->ps.pps->min_tb_addr_zs[((y_tb + size_in_tbs_v) & s->ps.sps->tb_mask) *
- (s->ps.sps->tb_mask + 2) + (x_tb - 1)];
+ pps->min_tb_addr_zs[((y_tb + size_in_tbs_v) & sps->tb_mask) *
+ (sps->tb_mask + 2) + (x_tb - 1)];
int cand_left = lc->na.cand_left;
int cand_up_left = lc->na.cand_up_left;
int cand_up = lc->na.cand_up;
int cand_up_right = lc->na.cand_up_right
&& cur_tb_addr >
- s->ps.pps->min_tb_addr_zs[(y_tb - 1) * (s->ps.sps->tb_mask + 2) +
- ((x_tb + size_in_tbs_h) & s->ps.sps->tb_mask)];
+ pps->min_tb_addr_zs[(y_tb - 1) * (sps->tb_mask + 2) +
+ ((x_tb + size_in_tbs_h) & sps->tb_mask)];
int bottom_left_size =
(((y0 + 2 * size_in_luma_v) >
- (s->ps.sps->height) ? (s->ps.sps->height) : (y0 +
+ (sps->height) ? (sps->height) : (y0 +
2 * size_in_luma_v)) -
(y0 + size_in_luma_v)) >> vshift;
int top_right_size =
(((x0 + 2 * size_in_luma_h) >
- (s->ps.sps->width) ? (s->ps.sps->width) : (x0 + 2 * size_in_luma_h)) -
+ (sps->width) ? (sps->width) : (x0 + 2 * size_in_luma_h)) -
(x0 + size_in_luma_h)) >> hshift;
- if (s->ps.pps->constrained_intra_pred_flag == 1) {
- int size_in_luma_pu_v = ((size_in_luma_v) >> s->ps.sps->log2_min_pu_size);
- int size_in_luma_pu_h = ((size_in_luma_h) >> s->ps.sps->log2_min_pu_size);
- int on_pu_edge_x = !(x0 & ((1 << s->ps.sps->log2_min_pu_size) - 1));
- int on_pu_edge_y = !(y0 & ((1 << s->ps.sps->log2_min_pu_size) - 1));
+ if (pps->constrained_intra_pred_flag == 1) {
+ int size_in_luma_pu_v = ((size_in_luma_v) >> sps->log2_min_pu_size);
+ int size_in_luma_pu_h = ((size_in_luma_h) >> sps->log2_min_pu_size);
+ int on_pu_edge_x = !(x0 & ((1 << sps->log2_min_pu_size) - 1));
+ int on_pu_edge_y = !(y0 & ((1 << sps->log2_min_pu_size) - 1));
if (!size_in_luma_pu_h)
size_in_luma_pu_h++;
if (cand_bottom_left == 1 && on_pu_edge_x) {
- int x_left_pu = ((x0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int x_left_pu = ((x0 - 1) >> sps->log2_min_pu_size);
int y_bottom_pu =
- ((y0 + size_in_luma_v) >> s->ps.sps->log2_min_pu_size);
+ ((y0 + size_in_luma_v) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_v) >
- (s->ps.sps->min_pu_height -
- y_bottom_pu) ? (s->ps.sps->min_pu_height -
+ (sps->min_pu_height -
+ y_bottom_pu) ? (sps->min_pu_height -
y_bottom_pu) : (size_in_luma_pu_v));
cand_bottom_left = 0;
for (i = 0; i < max; i += 2)
@@ -2503,12 +2504,12 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
PF_INTRA);
}
if (cand_left == 1 && on_pu_edge_x) {
- int x_left_pu = ((x0 - 1) >> s->ps.sps->log2_min_pu_size);
- int y_left_pu = ((y0) >> s->ps.sps->log2_min_pu_size);
+ int x_left_pu = ((x0 - 1) >> sps->log2_min_pu_size);
+ int y_left_pu = ((y0) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_v) >
- (s->ps.sps->min_pu_height -
- y_left_pu) ? (s->ps.sps->min_pu_height -
+ (sps->min_pu_height -
+ y_left_pu) ? (sps->min_pu_height -
y_left_pu) : (size_in_luma_pu_v));
cand_left = 0;
for (i = 0; i < max; i += 2)
@@ -2519,20 +2520,20 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
PF_INTRA);
}
if (cand_up_left == 1) {
- int x_left_pu = ((x0 - 1) >> s->ps.sps->log2_min_pu_size);
- int y_top_pu = ((y0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int x_left_pu = ((x0 - 1) >> sps->log2_min_pu_size);
+ int y_top_pu = ((y0 - 1) >> sps->log2_min_pu_size);
cand_up_left =
(s->cur_frame->tab_mvf[(x_left_pu) +
(y_top_pu) * min_pu_width]).pred_flag ==
PF_INTRA;
}
if (cand_up == 1 && on_pu_edge_y) {
- int x_top_pu = ((x0) >> s->ps.sps->log2_min_pu_size);
- int y_top_pu = ((y0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int x_top_pu = ((x0) >> sps->log2_min_pu_size);
+ int y_top_pu = ((y0 - 1) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_h) >
- (s->ps.sps->min_pu_width -
- x_top_pu) ? (s->ps.sps->min_pu_width -
+ (sps->min_pu_width -
+ x_top_pu) ? (sps->min_pu_width -
x_top_pu) : (size_in_luma_pu_h));
cand_up = 0;
for (i = 0; i < max; i += 2)
@@ -2542,13 +2543,13 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
min_pu_width]).pred_flag == PF_INTRA);
}
if (cand_up_right == 1 && on_pu_edge_y) {
- int y_top_pu = ((y0 - 1) >> s->ps.sps->log2_min_pu_size);
+ int y_top_pu = ((y0 - 1) >> sps->log2_min_pu_size);
int x_right_pu =
- ((x0 + size_in_luma_h) >> s->ps.sps->log2_min_pu_size);
+ ((x0 + size_in_luma_h) >> sps->log2_min_pu_size);
int max =
((size_in_luma_pu_h) >
- (s->ps.sps->min_pu_width -
- x_right_pu) ? (s->ps.sps->min_pu_width -
+ (sps->min_pu_width -
+ x_right_pu) ? (sps->min_pu_width -
x_right_pu) : (size_in_luma_pu_h));
cand_up_right = 0;
for (i = 0; i < max; i += 2)
@@ -2601,56 +2602,55 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
} while (0);
}
- if (s->ps.pps->constrained_intra_pred_flag == 1) {
+ if (pps->constrained_intra_pred_flag == 1) {
if (cand_bottom_left || cand_left || cand_up_left || cand_up
|| cand_up_right) {
int size_max_x =
x0 + ((2 * 32) << hshift) <
- s->ps.sps->width ? 2 * 32 : (s->ps.sps->width - x0) >> hshift;
+ sps->width ? 2 * 32 : (sps->width - x0) >> hshift;
int size_max_y =
y0 + ((2 * 32) << vshift) <
- s->ps.sps->height ? 2 * 32 : (s->ps.sps->height - y0) >> vshift;
+ sps->height ? 2 * 32 : (sps->height - y0) >> vshift;
int j = 32 + (cand_bottom_left ? bottom_left_size : 0) - 1;
if (!cand_up_right) {
- size_max_x = x0 + ((32) << hshift) < s->ps.sps->width ?
- 32 : (s->ps.sps->width - x0) >> hshift;
+ size_max_x = x0 + ((32) << hshift) < sps->width ?
+ 32 : (sps->width - x0) >> hshift;
}
if (!cand_bottom_left) {
- size_max_y = y0 + ((32) << vshift) < s->ps.sps->height ?
- 32 : (s->ps.sps->height - y0) >> vshift;
+ size_max_y = y0 + ((32) << vshift) < sps->height ?
+ 32 : (sps->height - y0) >> vshift;
}
if (cand_bottom_left || cand_left || cand_up_left) {
while (j > -1
&&
!((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((j) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
j--;
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((j)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag == PF_INTRA)) {
j = 0;
while (j < size_max_x
&&
!((s->cur_frame->tab_mvf[(((x0 +
- ((j) << hshift)) >> s->ps.sps->
+ ((j) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((-1) <<
vshift))
- >> s->
- ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2659,12 +2659,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
if (!
((s->cur_frame->tab_mvf[(((x0 +
((i -
- 1) << hshift)) >> s->ps.sps->
+ 1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((-1) <<
vshift))
- >> s->
- ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2676,11 +2675,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
while (j < size_max_x
&&
!((s->cur_frame->tab_mvf[(((x0 +
- ((j) << hshift)) >> s->ps.sps->
+ ((j) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((-1)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2692,11 +2691,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
((s->cur_frame->tab_mvf[(((x0 +
((i -
1) << hshift)) >>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
+ (((y0 + ((-1)
<< vshift))
>>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
*
min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2707,11 +2706,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
((s->cur_frame->tab_mvf[(((x0 +
((i -
1) << hshift)) >>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
+ (((y0 + ((-1)
<< vshift))
>>
- s->ps.sps->log2_min_pu_size))
+ sps->log2_min_pu_size))
*
min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2726,11 +2725,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
for (i = 0; i < (0) + (size_max_y); i += 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((i) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2754,12 +2753,12 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
i > (size_max_y - 1) - (size_max_y); i -= 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((i -
3) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2768,11 +2767,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
a = ((left[i - 3]) * 0x01010101U);
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((-1)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag == PF_INTRA))
left[-1] = left[0];
@@ -2788,12 +2787,12 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
i > (size_max_y - 1) - (size_max_y); i -= 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((-1) << hshift)) >> s->ps.sps->
+ ((-1) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 +
((i -
3) <<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2807,11 +2806,11 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
for (i = 0; i < (0) + (size_max_x); i += 4)
if (!
((s->cur_frame->tab_mvf[(((x0 +
- ((i) << hshift)) >> s->ps.sps->
+ ((i) << hshift)) >> sps->
log2_min_pu_size)) + (((y0 + ((-1)
<<
vshift))
- >> s->ps.sps->
+ >> sps->
log2_min_pu_size))
* min_pu_width]).pred_flag ==
PF_INTRA))
@@ -2886,8 +2885,8 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
top[-1] = left[-1];
- if (!s->ps.sps->intra_smoothing_disabled
- && (c_idx == 0 || s->ps.sps->chroma_format_idc == 3)) {
+ if (!sps->intra_smoothing_disabled
+ && (c_idx == 0 || sps->chroma_format_idc == 3)) {
if (mode != INTRA_DC && 32 != 4) {
int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
int min_dist_vert_hor =
@@ -2901,7 +2900,7 @@ void ff_intra_pred_8_32x32_msa(HEVCLocalContext *lc, int x0, int y0, int c_idx)
0 ? ((int) (mode - 26U)) : (-((int) (mode - 26U))))));
if (min_dist_vert_hor > intra_hor_ver_dist_thresh[5 - 3]) {
int threshold = 1 << (8 - 5);
- if (s->ps.sps->strong_intra_smoothing_enabled
+ if (sps->strong_intra_smoothing_enabled
&& c_idx == 0
&& ((top[-1] + top[63] - 2 * top[31]) >=
0 ? (top[-1] + top[63] -
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 11/39] lavc/hevcdec: stop accessing parameter sets through HEVCParamSets
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (8 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 10/39] lavc/hevc/pred: " Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 12/39] lavc/hevcdec: move active PPS from HEVCParamSets to HEVCContext Anton Khirnov
` (27 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Instead, accept PPS/SPS as function arguments.
Makes the code shorter and significantly reduces diff in future commits.
---
libavcodec/hevc/hevcdec.c | 876 ++++++++++++++++++++------------------
1 file changed, 469 insertions(+), 407 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5e4e5776e0..14b9a2a844 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -143,7 +143,7 @@ fail:
return AVERROR(ENOMEM);
}
-static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
+static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *gb)
{
int i = 0;
int j = 0;
@@ -159,7 +159,7 @@ static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
- if (s->ps.sps->chroma_format_idc != 0) {
+ if (sps->chroma_format_idc != 0) {
int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
@@ -175,7 +175,7 @@ static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
s->sh.luma_offset_l0[i] = 0;
}
}
- if (s->ps.sps->chroma_format_idc != 0) {
+ if (sps->chroma_format_idc != 0) {
for (i = 0; i < s->sh.nb_refs[L0]; i++)
chroma_weight_l0_flag[i] = get_bits1(gb);
} else {
@@ -219,7 +219,7 @@ static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
s->sh.luma_offset_l1[i] = 0;
}
}
- if (s->ps.sps->chroma_format_idc != 0) {
+ if (sps->chroma_format_idc != 0) {
for (i = 0; i < s->sh.nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = get_bits1(gb);
} else {
@@ -259,9 +259,9 @@ static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
return 0;
}
-static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
+static int decode_lt_rps(HEVCContext *s, const HEVCSPS *sps, LongTermRPS *rps,
+ GetBitContext *gb)
{
- const HEVCSPS *sps = s->ps.sps;
int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
int prev_delta_msb = 0;
unsigned int nb_sps = 0, nb_sh;
@@ -591,6 +591,8 @@ fail:
static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
{
SliceHeader *sh = &s->sh;
+ const HEVCPPS *pps;
+ const HEVCSPS *sps;
int i, ret;
// Coded parameters
@@ -621,11 +623,13 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
s->ps.pps = s->ps.pps_list[sh->pps_id];
+ pps = s->ps.pps;
+ sps = pps->sps;
+
if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
sh->no_output_of_prior_pics_flag = 1;
- if (s->ps.sps != s->ps.pps->sps) {
- const HEVCSPS *sps = s->ps.pps->sps;
+ if (s->ps.sps != sps) {
enum AVPixelFormat pix_fmt;
ff_hevc_clear_refs(s);
@@ -651,13 +655,13 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (!sh->first_slice_in_pic_flag) {
int slice_address_length;
- if (s->ps.pps->dependent_slice_segments_enabled_flag)
+ if (pps->dependent_slice_segments_enabled_flag)
sh->dependent_slice_segment_flag = get_bits1(gb);
- slice_address_length = av_ceil_log2(s->ps.sps->ctb_width *
- s->ps.sps->ctb_height);
+ slice_address_length = av_ceil_log2(sps->ctb_width *
+ sps->ctb_height);
sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
- if (sh->slice_segment_addr >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
+ if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
av_log(s->avctx, AV_LOG_ERROR,
"Invalid slice segment address: %u.\n",
sh->slice_segment_addr);
@@ -677,7 +681,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (!sh->dependent_slice_segment_flag) {
s->slice_initialized = 0;
- for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++)
+ for (i = 0; i < pps->num_extra_slice_header_bits; i++)
skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
sh->slice_type = get_ue_golomb_long(gb);
@@ -689,24 +693,24 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
- !s->ps.pps->pps_curr_pic_ref_enabled_flag) {
+ !pps->pps_curr_pic_ref_enabled_flag) {
av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
return AVERROR_INVALIDDATA;
}
// when flag is not present, picture is inferred to be output
sh->pic_output_flag = 1;
- if (s->ps.pps->output_flag_present_flag)
+ if (pps->output_flag_present_flag)
sh->pic_output_flag = get_bits1(gb);
- if (s->ps.sps->separate_colour_plane)
+ if (sps->separate_colour_plane)
sh->colour_plane_id = get_bits(gb, 2);
if (!IS_IDR(s)) {
int poc, pos;
- sh->pic_order_cnt_lsb = get_bits(gb, s->ps.sps->log2_max_poc_lsb);
- poc = ff_hevc_compute_poc(s->ps.sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
+ sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
+ poc = ff_hevc_compute_poc(sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
if (!sh->first_slice_in_pic_flag && poc != s->poc) {
av_log(s->avctx, AV_LOG_WARNING,
"Ignoring POC change between slices: %d -> %d\n", s->poc, poc);
@@ -719,7 +723,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
pos = get_bits_left(gb);
if (!sh->short_term_ref_pic_set_sps_flag) {
- ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, s->ps.sps, 1);
+ ret = ff_hevc_decode_short_term_rps(gb, s->avctx, &sh->slice_rps, sps, 1);
if (ret < 0)
return ret;
@@ -727,19 +731,19 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
} else {
int numbits, rps_idx;
- if (!s->ps.sps->nb_st_rps) {
+ if (!sps->nb_st_rps) {
av_log(s->avctx, AV_LOG_ERROR, "No ref lists in the SPS.\n");
return AVERROR_INVALIDDATA;
}
- numbits = av_ceil_log2(s->ps.sps->nb_st_rps);
+ numbits = av_ceil_log2(sps->nb_st_rps);
rps_idx = numbits > 0 ? get_bits(gb, numbits) : 0;
- sh->short_term_rps = &s->ps.sps->st_rps[rps_idx];
+ sh->short_term_rps = &sps->st_rps[rps_idx];
}
sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
pos = get_bits_left(gb);
- ret = decode_lt_rps(s, &sh->long_term_rps, gb);
+ ret = decode_lt_rps(s, sps, &sh->long_term_rps, gb);
if (ret < 0) {
av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
@@ -747,7 +751,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
}
sh->long_term_ref_pic_set_size = pos - get_bits_left(gb);
- if (s->ps.sps->temporal_mvp_enabled)
+ if (sps->temporal_mvp_enabled)
sh->slice_temporal_mvp_enabled_flag = get_bits1(gb);
else
sh->slice_temporal_mvp_enabled_flag = 0;
@@ -772,9 +776,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
s->nal_unit_type != HEVC_NAL_RASL_R)
s->pocTid0 = s->poc;
- if (s->ps.sps->sao_enabled) {
+ if (sps->sao_enabled) {
sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
- if (s->ps.sps->chroma_format_idc) {
+ if (sps->chroma_format_idc) {
sh->slice_sample_adaptive_offset_flag[1] =
sh->slice_sample_adaptive_offset_flag[2] = get_bits1(gb);
}
@@ -788,9 +792,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (sh->slice_type == HEVC_SLICE_P || sh->slice_type == HEVC_SLICE_B) {
int nb_refs;
- sh->nb_refs[L0] = s->ps.pps->num_ref_idx_l0_default_active;
+ sh->nb_refs[L0] = pps->num_ref_idx_l0_default_active;
if (sh->slice_type == HEVC_SLICE_B)
- sh->nb_refs[L1] = s->ps.pps->num_ref_idx_l1_default_active;
+ sh->nb_refs[L1] = pps->num_ref_idx_l1_default_active;
if (get_bits1(gb)) { // num_ref_idx_active_override_flag
sh->nb_refs[L0] = get_ue_golomb_31(gb) + 1;
@@ -811,7 +815,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
- if (s->ps.pps->lists_modification_present_flag && nb_refs > 1) {
+ if (pps->lists_modification_present_flag && nb_refs > 1) {
sh->rpl_modification_flag[0] = get_bits1(gb);
if (sh->rpl_modification_flag[0]) {
for (i = 0; i < sh->nb_refs[L0]; i++)
@@ -829,7 +833,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (sh->slice_type == HEVC_SLICE_B)
sh->mvd_l1_zero_flag = get_bits1(gb);
- if (s->ps.pps->cabac_init_present_flag)
+ if (pps->cabac_init_present_flag)
sh->cabac_init_flag = get_bits1(gb);
else
sh->cabac_init_flag = 0;
@@ -851,9 +855,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
}
}
- if ((s->ps.pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
- (s->ps.pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
- int ret = pred_weight_table(s, gb);
+ if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
+ (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
+ int ret = pred_weight_table(s, sps, gb);
if (ret < 0)
return ret;
}
@@ -867,17 +871,17 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
}
// Syntax in 7.3.6.1
- if (s->ps.sps->motion_vector_resolution_control_idc == 2)
+ if (sps->motion_vector_resolution_control_idc == 2)
sh->use_integer_mv_flag = get_bits1(gb);
else
// Inferred to be equal to motion_vector_resolution_control_idc if not present
- sh->use_integer_mv_flag = s->ps.sps->motion_vector_resolution_control_idc;
+ sh->use_integer_mv_flag = sps->motion_vector_resolution_control_idc;
}
sh->slice_qp_delta = get_se_golomb(gb);
- if (s->ps.pps->pic_slice_level_chroma_qp_offsets_present_flag) {
+ if (pps->pic_slice_level_chroma_qp_offsets_present_flag) {
sh->slice_cb_qp_offset = get_se_golomb(gb);
sh->slice_cr_qp_offset = get_se_golomb(gb);
if (sh->slice_cb_qp_offset < -12 || sh->slice_cb_qp_offset > 12 ||
@@ -890,21 +894,21 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->slice_cr_qp_offset = 0;
}
- if (s->ps.pps->pps_slice_act_qp_offsets_present_flag) {
+ if (pps->pps_slice_act_qp_offsets_present_flag) {
sh->slice_act_y_qp_offset = get_se_golomb(gb);
sh->slice_act_cb_qp_offset = get_se_golomb(gb);
sh->slice_act_cr_qp_offset = get_se_golomb(gb);
}
- if (s->ps.pps->chroma_qp_offset_list_enabled_flag)
+ if (pps->chroma_qp_offset_list_enabled_flag)
sh->cu_chroma_qp_offset_enabled_flag = get_bits1(gb);
else
sh->cu_chroma_qp_offset_enabled_flag = 0;
- if (s->ps.pps->deblocking_filter_control_present_flag) {
+ if (pps->deblocking_filter_control_present_flag) {
int deblocking_filter_override_flag = 0;
- if (s->ps.pps->deblocking_filter_override_enabled_flag)
+ if (pps->deblocking_filter_override_enabled_flag)
deblocking_filter_override_flag = get_bits1(gb);
if (deblocking_filter_override_flag) {
@@ -923,9 +927,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->tc_offset = tc_offset_div2 * 2;
}
} else {
- sh->disable_deblocking_filter_flag = s->ps.pps->disable_dbf;
- sh->beta_offset = s->ps.pps->beta_offset;
- sh->tc_offset = s->ps.pps->tc_offset;
+ sh->disable_deblocking_filter_flag = pps->disable_dbf;
+ sh->beta_offset = pps->beta_offset;
+ sh->tc_offset = pps->tc_offset;
}
} else {
sh->disable_deblocking_filter_flag = 0;
@@ -933,13 +937,13 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->tc_offset = 0;
}
- if (s->ps.pps->seq_loop_filter_across_slices_enabled_flag &&
+ if (pps->seq_loop_filter_across_slices_enabled_flag &&
(sh->slice_sample_adaptive_offset_flag[0] ||
sh->slice_sample_adaptive_offset_flag[1] ||
!sh->disable_deblocking_filter_flag)) {
sh->slice_loop_filter_across_slices_enabled_flag = get_bits1(gb);
} else {
- sh->slice_loop_filter_across_slices_enabled_flag = s->ps.pps->seq_loop_filter_across_slices_enabled_flag;
+ sh->slice_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag;
}
} else if (!s->slice_initialized) {
av_log(s->avctx, AV_LOG_ERROR, "Independent slice segment missing.\n");
@@ -947,7 +951,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
}
sh->num_entry_point_offsets = 0;
- if (s->ps.pps->tiles_enabled_flag || s->ps.pps->entropy_coding_sync_enabled_flag) {
+ if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
unsigned num_entry_point_offsets = get_ue_golomb_long(gb);
// It would be possible to bound this tighter but this here is simpler
if (num_entry_point_offsets > get_bits_left(gb)) {
@@ -980,7 +984,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
unsigned val = get_bits_long(gb, offset_len);
sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
}
- if (s->threads_number > 1 && (s->ps.pps->num_tile_rows > 1 || s->ps.pps->num_tile_columns > 1)) {
+ if (s->threads_number > 1 && (pps->num_tile_rows > 1 || pps->num_tile_columns > 1)) {
s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here
s->threads_number = 1;
} else
@@ -989,7 +993,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
s->enable_parallel_tiles = 0;
}
- if (s->ps.pps->slice_header_extension_present_flag) {
+ if (pps->slice_header_extension_present_flag) {
unsigned int length = get_ue_golomb_long(gb);
if (length*8LL > get_bits_left(gb)) {
av_log(s->avctx, AV_LOG_ERROR, "too many slice_header_extension_data_bytes\n");
@@ -1007,14 +1011,14 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->data_offset = align_get_bits(gb) - gb->buffer;
// Inferred parameters
- sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta;
+ sh->slice_qp = 26U + pps->pic_init_qp_minus26 + sh->slice_qp_delta;
if (sh->slice_qp > 51 ||
- sh->slice_qp < -s->ps.sps->qp_bd_offset) {
+ sh->slice_qp < -sps->qp_bd_offset) {
av_log(s->avctx, AV_LOG_ERROR,
"The slice_qp %d is outside the valid range "
"[%d, 51].\n",
sh->slice_qp,
- -s->ps.sps->qp_bd_offset);
+ -sps->qp_bd_offset);
return AVERROR_INVALIDDATA;
}
@@ -1033,7 +1037,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
- if (!s->ps.pps->cu_qp_delta_enabled_flag)
+ if (!pps->cu_qp_delta_enabled_flag)
s->local_ctx[0].qp_y = s->sh.slice_qp;
s->slice_initialized = 1;
@@ -1043,7 +1047,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return 0;
}
-#define CTB(tab, x, y) ((tab)[(y) * s->ps.sps->ctb_width + (x)])
+#define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
#define SET_SAO(elem, value) \
do { \
@@ -1057,7 +1061,9 @@ do { \
sao->elem = 0; \
} while (0)
-static void hls_sao_param(HEVCLocalContext *lc, int rx, int ry)
+static void hls_sao_param(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int rx, int ry)
{
const HEVCContext *const s = lc->parent;
int sao_merge_left_flag = 0;
@@ -1077,9 +1083,9 @@ static void hls_sao_param(HEVCLocalContext *lc, int rx, int ry)
}
}
- for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
- int log2_sao_offset_scale = c_idx == 0 ? s->ps.pps->log2_sao_offset_scale_luma :
- s->ps.pps->log2_sao_offset_scale_chroma;
+ for (c_idx = 0; c_idx < (sps->chroma_format_idc ? 3 : 1); c_idx++) {
+ int log2_sao_offset_scale = c_idx == 0 ? pps->log2_sao_offset_scale_luma :
+ pps->log2_sao_offset_scale_chroma;
if (!s->sh.slice_sample_adaptive_offset_flag[c_idx]) {
sao->type_idx[c_idx] = SAO_NOT_APPLIED;
@@ -1097,7 +1103,7 @@ static void hls_sao_param(HEVCLocalContext *lc, int rx, int ry)
continue;
for (i = 0; i < 4; i++)
- SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, s->ps.sps->bit_depth));
+ SET_SAO(offset_abs[c_idx][i], ff_hevc_sao_offset_abs_decode(lc, sps->bit_depth));
if (sao->type_idx[c_idx] == SAO_BAND) {
for (i = 0; i < 4; i++) {
@@ -1147,49 +1153,51 @@ static int hls_cross_component_pred(HEVCLocalContext *lc, int idx)
return 0;
}
-static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
+static int hls_transform_unit(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0,
int xBase, int yBase, int cb_xBase, int cb_yBase,
int log2_cb_size, int log2_trafo_size,
int blk_idx, int cbf_luma, int *cbf_cb, int *cbf_cr)
{
const HEVCContext *const s = lc->parent;
- const int log2_trafo_size_c = log2_trafo_size - s->ps.sps->hshift[1];
+ const int log2_trafo_size_c = log2_trafo_size - sps->hshift[1];
int i;
if (lc->cu.pred_mode == MODE_INTRA) {
int trafo_size = 1 << log2_trafo_size;
- ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, s->ps.sps->log2_ctb_size);
+ ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, x0, y0, 0);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, x0, y0, 0);
}
if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
- (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
+ (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
int scan_idx = SCAN_DIAG;
int scan_idx_c = SCAN_DIAG;
int cbf_chroma = cbf_cb[0] || cbf_cr[0] ||
- (s->ps.sps->chroma_format_idc == 2 &&
+ (sps->chroma_format_idc == 2 &&
(cbf_cb[1] || cbf_cr[1]));
- if (s->ps.pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
+ if (pps->cu_qp_delta_enabled_flag && !lc->tu.is_cu_qp_delta_coded) {
lc->tu.cu_qp_delta = ff_hevc_cu_qp_delta_abs(lc);
if (lc->tu.cu_qp_delta != 0)
if (ff_hevc_cu_qp_delta_sign_flag(lc) == 1)
lc->tu.cu_qp_delta = -lc->tu.cu_qp_delta;
lc->tu.is_cu_qp_delta_coded = 1;
- if (lc->tu.cu_qp_delta < -(26 + s->ps.sps->qp_bd_offset / 2) ||
- lc->tu.cu_qp_delta > (25 + s->ps.sps->qp_bd_offset / 2)) {
+ if (lc->tu.cu_qp_delta < -(26 + sps->qp_bd_offset / 2) ||
+ lc->tu.cu_qp_delta > (25 + sps->qp_bd_offset / 2)) {
av_log(s->avctx, AV_LOG_ERROR,
"The cu_qp_delta %d is outside the valid range "
"[%d, %d].\n",
lc->tu.cu_qp_delta,
- -(26 + s->ps.sps->qp_bd_offset / 2),
- (25 + s->ps.sps->qp_bd_offset / 2));
+ -(26 + sps->qp_bd_offset / 2),
+ (25 + sps->qp_bd_offset / 2));
return AVERROR_INVALIDDATA;
}
- ff_hevc_set_qPy(lc, s->ps.pps, cb_xBase, cb_yBase, log2_cb_size);
+ ff_hevc_set_qPy(lc, pps, cb_xBase, cb_yBase, log2_cb_size);
}
if (s->sh.cu_chroma_qp_offset_enabled_flag && cbf_chroma &&
@@ -1197,13 +1205,13 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
int cu_chroma_qp_offset_flag = ff_hevc_cu_chroma_qp_offset_flag(lc);
if (cu_chroma_qp_offset_flag) {
int cu_chroma_qp_offset_idx = 0;
- if (s->ps.pps->chroma_qp_offset_list_len_minus1 > 0) {
- cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, s->ps.pps->chroma_qp_offset_list_len_minus1);
+ if (pps->chroma_qp_offset_list_len_minus1 > 0) {
+ cu_chroma_qp_offset_idx = ff_hevc_cu_chroma_qp_offset_idx(lc, pps->chroma_qp_offset_list_len_minus1);
av_log(s->avctx, AV_LOG_ERROR,
"cu_chroma_qp_offset_idx not yet tested.\n");
}
- lc->tu.cu_qp_offset_cb = s->ps.pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
- lc->tu.cu_qp_offset_cr = s->ps.pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
+ lc->tu.cu_qp_offset_cb = pps->cb_qp_offset_list[cu_chroma_qp_offset_idx];
+ lc->tu.cu_qp_offset_cr = pps->cr_qp_offset_list[cu_chroma_qp_offset_idx];
} else {
lc->tu.cu_qp_offset_cb = 0;
lc->tu.cu_qp_offset_cr = 0;
@@ -1232,37 +1240,37 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
lc->tu.cross_pf = 0;
if (cbf_luma)
- ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0, log2_trafo_size, scan_idx, 0);
- if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
- int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
- int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
- lc->tu.cross_pf = (s->ps.pps->cross_component_prediction_enabled_flag && cbf_luma &&
+ ff_hevc_hls_residual_coding(lc, pps, x0, y0, log2_trafo_size, scan_idx, 0);
+ if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
+ int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
+ int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
+ lc->tu.cross_pf = (pps->cross_component_prediction_enabled_flag && cbf_luma &&
(lc->cu.pred_mode == MODE_INTER ||
(lc->tu.chroma_mode_c == 4)));
if (lc->tu.cross_pf) {
hls_cross_component_pred(lc, 0);
}
- for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
+ for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c), 1);
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 1);
}
if (cbf_cb[i])
- ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c),
+ ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
log2_trafo_size_c, scan_idx_c, 1);
else
if (lc->tu.cross_pf) {
ptrdiff_t stride = s->cur_frame->f->linesize[1];
- int hshift = s->ps.sps->hshift[1];
- int vshift = s->ps.sps->vshift[1];
+ int hshift = sps->hshift[1];
+ int vshift = sps->vshift[1];
const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
int size = 1 << log2_trafo_size_c;
uint8_t *dst = &s->cur_frame->f->data[1][(y0 >> vshift) * stride +
- ((x0 >> hshift) << s->ps.sps->pixel_shift)];
+ ((x0 >> hshift) << sps->pixel_shift)];
for (i = 0; i < (size * size); i++) {
coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
}
@@ -1273,82 +1281,82 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
if (lc->tu.cross_pf) {
hls_cross_component_pred(lc, 1);
}
- for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
+ for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (i << log2_trafo_size_c),
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c), 2);
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (i << log2_trafo_size_c), 2);
}
if (cbf_cr[i])
- ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << log2_trafo_size_c),
+ ff_hevc_hls_residual_coding(lc, pps, x0, y0 + (i << log2_trafo_size_c),
log2_trafo_size_c, scan_idx_c, 2);
else
if (lc->tu.cross_pf) {
ptrdiff_t stride = s->cur_frame->f->linesize[2];
- int hshift = s->ps.sps->hshift[2];
- int vshift = s->ps.sps->vshift[2];
+ int hshift = sps->hshift[2];
+ int vshift = sps->vshift[2];
const int16_t *coeffs_y = (int16_t*)lc->edge_emu_buffer;
int16_t *coeffs = (int16_t*)lc->edge_emu_buffer2;
int size = 1 << log2_trafo_size_c;
uint8_t *dst = &s->cur_frame->f->data[2][(y0 >> vshift) * stride +
- ((x0 >> hshift) << s->ps.sps->pixel_shift)];
+ ((x0 >> hshift) << sps->pixel_shift)];
for (i = 0; i < (size * size); i++) {
coeffs[i] = ((lc->tu.res_scale_val * coeffs_y[i]) >> 3);
}
s->hevcdsp.add_residual[log2_trafo_size_c-2](dst, coeffs, stride);
}
}
- } else if (s->ps.sps->chroma_format_idc && blk_idx == 3) {
+ } else if (sps->chroma_format_idc && blk_idx == 3) {
int trafo_size_h = 1 << (log2_trafo_size + 1);
- int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
- for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
+ int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
+ for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size), 1);
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 1);
}
if (cbf_cb[i])
- ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size),
+ ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
log2_trafo_size, scan_idx_c, 1);
}
- for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
+ for (i = 0; i < (sps->chroma_format_idc == 2 ? 2 : 1); i++) {
if (lc->cu.pred_mode == MODE_INTRA) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << log2_trafo_size),
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size), 2);
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (i << log2_trafo_size), 2);
}
if (cbf_cr[i])
- ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + (i << log2_trafo_size),
+ ff_hevc_hls_residual_coding(lc, pps, xBase, yBase + (i << log2_trafo_size),
log2_trafo_size, scan_idx_c, 2);
}
}
- } else if (s->ps.sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
- if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) {
- int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
- int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
+ } else if (sps->chroma_format_idc && lc->cu.pred_mode == MODE_INTRA) {
+ if (log2_trafo_size > 2 || sps->chroma_format_idc == 3) {
+ int trafo_size_h = 1 << (log2_trafo_size_c + sps->hshift[1]);
+ int trafo_size_v = 1 << (log2_trafo_size_c + sps->vshift[1]);
ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, trafo_size_v,
- s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0, 1);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0, 2);
- if (s->ps.sps->chroma_format_idc == 2) {
+ sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 1);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0, 2);
+ if (sps->chroma_format_idc == 2) {
ff_hevc_set_neighbour_available(lc, x0, y0 + (1 << log2_trafo_size_c),
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (1 << log2_trafo_size_c), 1);
- s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, x0, y0 + (1 << log2_trafo_size_c), 2);
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 1);
+ s->hpc.intra_pred[log2_trafo_size_c - 2](lc, pps, x0, y0 + (1 << log2_trafo_size_c), 2);
}
} else if (blk_idx == 3) {
int trafo_size_h = 1 << (log2_trafo_size + 1);
- int trafo_size_v = 1 << (log2_trafo_size + s->ps.sps->vshift[1]);
+ int trafo_size_v = 1 << (log2_trafo_size + sps->vshift[1]);
ff_hevc_set_neighbour_available(lc, xBase, yBase,
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase, 1);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase, 2);
- if (s->ps.sps->chroma_format_idc == 2) {
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 1);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase, 2);
+ if (sps->chroma_format_idc == 2) {
ff_hevc_set_neighbour_available(lc, xBase, yBase + (1 << log2_trafo_size),
- trafo_size_h, trafo_size_v, s->ps.sps->log2_ctb_size);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (1 << log2_trafo_size), 1);
- s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, xBase, yBase + (1 << log2_trafo_size), 2);
+ trafo_size_h, trafo_size_v, sps->log2_ctb_size);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 1);
+ s->hpc.intra_pred[log2_trafo_size - 2](lc, pps, xBase, yBase + (1 << log2_trafo_size), 2);
}
}
}
@@ -1356,14 +1364,15 @@ static int hls_transform_unit(HEVCLocalContext *lc, int x0, int y0,
return 0;
}
-static void set_deblocking_bypass(const HEVCContext *s, int x0, int y0, int log2_cb_size)
+static void set_deblocking_bypass(const HEVCContext *s, const HEVCSPS *sps,
+ int x0, int y0, int log2_cb_size)
{
int cb_size = 1 << log2_cb_size;
- int log2_min_pu_size = s->ps.sps->log2_min_pu_size;
+ int log2_min_pu_size = sps->log2_min_pu_size;
- int min_pu_width = s->ps.sps->min_pu_width;
- int x_end = FFMIN(x0 + cb_size, s->ps.sps->width);
- int y_end = FFMIN(y0 + cb_size, s->ps.sps->height);
+ int min_pu_width = sps->min_pu_width;
+ int x_end = FFMIN(x0 + cb_size, sps->width);
+ int y_end = FFMIN(y0 + cb_size, sps->height);
int i, j;
for (j = (y0 >> log2_min_pu_size); j < (y_end >> log2_min_pu_size); j++)
@@ -1371,7 +1380,9 @@ static void set_deblocking_bypass(const HEVCContext *s, int x0, int y0, int log2
s->is_pcm[i + j * min_pu_width] = 2;
}
-static int hls_transform_tree(HEVCLocalContext *lc, int x0, int y0,
+static int hls_transform_tree(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0,
int xBase, int yBase, int cb_xBase, int cb_yBase,
int log2_cb_size, int log2_trafo_size,
int trafo_depth, int blk_idx,
@@ -1391,7 +1402,7 @@ static int hls_transform_tree(HEVCLocalContext *lc, int x0, int y0,
if (lc->cu.intra_split_flag) {
if (trafo_depth == 1) {
lc->tu.intra_pred_mode = lc->pu.intra_pred_mode[blk_idx];
- if (s->ps.sps->chroma_format_idc == 3) {
+ if (sps->chroma_format_idc == 3) {
lc->tu.intra_pred_mode_c = lc->pu.intra_pred_mode_c[blk_idx];
lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[blk_idx];
} else {
@@ -1405,33 +1416,33 @@ static int hls_transform_tree(HEVCLocalContext *lc, int x0, int y0,
lc->tu.chroma_mode_c = lc->pu.chroma_mode_c[0];
}
- if (log2_trafo_size <= s->ps.sps->log2_max_trafo_size &&
- log2_trafo_size > s->ps.sps->log2_min_tb_size &&
+ if (log2_trafo_size <= sps->log2_max_trafo_size &&
+ log2_trafo_size > sps->log2_min_tb_size &&
trafo_depth < lc->cu.max_trafo_depth &&
!(lc->cu.intra_split_flag && trafo_depth == 0)) {
split_transform_flag = ff_hevc_split_transform_flag_decode(lc, log2_trafo_size);
} else {
- int inter_split = s->ps.sps->max_transform_hierarchy_depth_inter == 0 &&
+ int inter_split = sps->max_transform_hierarchy_depth_inter == 0 &&
lc->cu.pred_mode == MODE_INTER &&
lc->cu.part_mode != PART_2Nx2N &&
trafo_depth == 0;
- split_transform_flag = log2_trafo_size > s->ps.sps->log2_max_trafo_size ||
+ split_transform_flag = log2_trafo_size > sps->log2_max_trafo_size ||
(lc->cu.intra_split_flag && trafo_depth == 0) ||
inter_split;
}
- if (s->ps.sps->chroma_format_idc && (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3)) {
+ if (sps->chroma_format_idc && (log2_trafo_size > 2 || sps->chroma_format_idc == 3)) {
if (trafo_depth == 0 || cbf_cb[0]) {
cbf_cb[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
- if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
+ if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
cbf_cb[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
}
}
if (trafo_depth == 0 || cbf_cr[0]) {
cbf_cr[0] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
- if (s->ps.sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
+ if (sps->chroma_format_idc == 2 && (!split_transform_flag || log2_trafo_size == 3)) {
cbf_cr[1] = ff_hevc_cbf_cb_cr_decode(lc, trafo_depth);
}
}
@@ -1444,7 +1455,8 @@ static int hls_transform_tree(HEVCLocalContext *lc, int x0, int y0,
#define SUBDIVIDE(x, y, idx) \
do { \
- ret = hls_transform_tree(lc, x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size,\
+ ret = hls_transform_tree(lc, pps, sps, \
+ x, y, x0, y0, cb_xBase, cb_yBase, log2_cb_size, \
log2_trafo_size - 1, trafo_depth + 1, idx, \
cbf_cb, cbf_cr); \
if (ret < 0) \
@@ -1458,18 +1470,19 @@ do {
#undef SUBDIVIDE
} else {
- int min_tu_size = 1 << s->ps.sps->log2_min_tb_size;
- int log2_min_tu_size = s->ps.sps->log2_min_tb_size;
- int min_tu_width = s->ps.sps->min_tb_width;
+ int min_tu_size = 1 << sps->log2_min_tb_size;
+ int log2_min_tu_size = sps->log2_min_tb_size;
+ int min_tu_width = sps->min_tb_width;
int cbf_luma = 1;
if (lc->cu.pred_mode == MODE_INTRA || trafo_depth != 0 ||
cbf_cb[0] || cbf_cr[0] ||
- (s->ps.sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
+ (sps->chroma_format_idc == 2 && (cbf_cb[1] || cbf_cr[1]))) {
cbf_luma = ff_hevc_cbf_luma_decode(lc, trafo_depth);
}
- ret = hls_transform_unit(lc, x0, y0, xBase, yBase, cb_xBase, cb_yBase,
+ ret = hls_transform_unit(lc, pps, sps,
+ x0, y0, xBase, yBase, cb_xBase, cb_yBase,
log2_cb_size, log2_trafo_size,
blk_idx, cbf_luma, cbf_cb, cbf_cr);
if (ret < 0)
@@ -1485,51 +1498,53 @@ do {
}
}
if (!s->sh.disable_deblocking_filter_flag) {
- ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_trafo_size);
- if (s->ps.pps->transquant_bypass_enable_flag &&
+ ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_trafo_size);
+ if (pps->transquant_bypass_enable_flag &&
lc->cu.cu_transquant_bypass_flag)
- set_deblocking_bypass(s, x0, y0, log2_trafo_size);
+ set_deblocking_bypass(s, sps, x0, y0, log2_trafo_size);
}
}
return 0;
}
-static int hls_pcm_sample(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size)
+static int hls_pcm_sample(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int x0, int y0, int log2_cb_size)
{
const HEVCContext *const s = lc->parent;
+ const HEVCSPS *const sps = pps->sps;
GetBitContext gb;
int cb_size = 1 << log2_cb_size;
ptrdiff_t stride0 = s->cur_frame->f->linesize[0];
ptrdiff_t stride1 = s->cur_frame->f->linesize[1];
ptrdiff_t stride2 = s->cur_frame->f->linesize[2];
- uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << s->ps.sps->pixel_shift)];
- uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> s->ps.sps->vshift[1]) * stride1 + ((x0 >> s->ps.sps->hshift[1]) << s->ps.sps->pixel_shift)];
- uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> s->ps.sps->vshift[2]) * stride2 + ((x0 >> s->ps.sps->hshift[2]) << s->ps.sps->pixel_shift)];
+ uint8_t *dst0 = &s->cur_frame->f->data[0][y0 * stride0 + (x0 << sps->pixel_shift)];
+ uint8_t *dst1 = &s->cur_frame->f->data[1][(y0 >> sps->vshift[1]) * stride1 + ((x0 >> sps->hshift[1]) << sps->pixel_shift)];
+ uint8_t *dst2 = &s->cur_frame->f->data[2][(y0 >> sps->vshift[2]) * stride2 + ((x0 >> sps->hshift[2]) << sps->pixel_shift)];
- int length = cb_size * cb_size * s->ps.sps->pcm.bit_depth +
- (((cb_size >> s->ps.sps->hshift[1]) * (cb_size >> s->ps.sps->vshift[1])) +
- ((cb_size >> s->ps.sps->hshift[2]) * (cb_size >> s->ps.sps->vshift[2]))) *
- s->ps.sps->pcm.bit_depth_chroma;
+ int length = cb_size * cb_size * sps->pcm.bit_depth +
+ (((cb_size >> sps->hshift[1]) * (cb_size >> sps->vshift[1])) +
+ ((cb_size >> sps->hshift[2]) * (cb_size >> sps->vshift[2]))) *
+ sps->pcm.bit_depth_chroma;
const uint8_t *pcm = skip_bytes(&lc->cc, (length + 7) >> 3);
int ret;
if (!s->sh.disable_deblocking_filter_flag)
- ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_cb_size);
+ ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size);
ret = init_get_bits(&gb, pcm, length);
if (ret < 0)
return ret;
- s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, s->ps.sps->pcm.bit_depth);
- if (s->ps.sps->chroma_format_idc) {
+ s->hevcdsp.put_pcm(dst0, stride0, cb_size, cb_size, &gb, sps->pcm.bit_depth);
+ if (sps->chroma_format_idc) {
s->hevcdsp.put_pcm(dst1, stride1,
- cb_size >> s->ps.sps->hshift[1],
- cb_size >> s->ps.sps->vshift[1],
- &gb, s->ps.sps->pcm.bit_depth_chroma);
+ cb_size >> sps->hshift[1],
+ cb_size >> sps->vshift[1],
+ &gb, sps->pcm.bit_depth_chroma);
s->hevcdsp.put_pcm(dst2, stride2,
- cb_size >> s->ps.sps->hshift[2],
- cb_size >> s->ps.sps->vshift[2],
- &gb, s->ps.sps->pcm.bit_depth_chroma);
+ cb_size >> sps->hshift[2],
+ cb_size >> sps->vshift[2],
+ &gb, sps->pcm.bit_depth_chroma);
}
return 0;
@@ -1551,32 +1566,34 @@ static int hls_pcm_sample(HEVCLocalContext *lc, int x0, int y0, int log2_cb_size
* @param luma_offset additive offset applied to the luma prediction value
*/
-static void luma_mc_uni(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride,
+static void luma_mc_uni(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ uint8_t *dst, ptrdiff_t dststride,
const AVFrame *ref, const Mv *mv, int x_off, int y_off,
int block_w, int block_h, int luma_weight, int luma_offset)
{
const HEVCContext *const s = lc->parent;
const uint8_t *src = ref->data[0];
ptrdiff_t srcstride = ref->linesize[0];
- int pic_width = s->ps.sps->width;
- int pic_height = s->ps.sps->height;
+ int pic_width = sps->width;
+ int pic_height = sps->height;
int mx = mv->x & 3;
int my = mv->y & 3;
- int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
- (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
+ int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
+ (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
int idx = hevc_pel_weight[block_w];
x_off += mv->x >> 2;
y_off += mv->y >> 2;
- src += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
+ src += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
if (x_off < QPEL_EXTRA_BEFORE || y_off < QPEL_EXTRA_AFTER ||
x_off >= pic_width - block_w - QPEL_EXTRA_AFTER ||
y_off >= pic_height - block_h - QPEL_EXTRA_AFTER ||
ref == s->cur_frame->f) {
- const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
- int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
- int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
+ const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
+ int offset = QPEL_EXTRA_BEFORE * srcstride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
+ int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src - offset,
edge_emu_stride, srcstride,
@@ -1613,7 +1630,9 @@ static void luma_mc_uni(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride,
* @param mv1 motion vector1 (relative to block position) to get pixel data from
* @param current_mv current motion vector structure
*/
- static void luma_mc_bi(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride,
+static void luma_mc_bi(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ uint8_t *dst, ptrdiff_t dststride,
const AVFrame *ref0, const Mv *mv0, int x_off, int y_off,
int block_w, int block_h, const AVFrame *ref1,
const Mv *mv1, struct MvField *current_mv)
@@ -1621,29 +1640,29 @@ static void luma_mc_uni(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride,
const HEVCContext *const s = lc->parent;
ptrdiff_t src0stride = ref0->linesize[0];
ptrdiff_t src1stride = ref1->linesize[0];
- int pic_width = s->ps.sps->width;
- int pic_height = s->ps.sps->height;
+ int pic_width = sps->width;
+ int pic_height = sps->height;
int mx0 = mv0->x & 3;
int my0 = mv0->y & 3;
int mx1 = mv1->x & 3;
int my1 = mv1->y & 3;
- int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
- (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
+ int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
+ (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
int x_off0 = x_off + (mv0->x >> 2);
int y_off0 = y_off + (mv0->y >> 2);
int x_off1 = x_off + (mv1->x >> 2);
int y_off1 = y_off + (mv1->y >> 2);
int idx = hevc_pel_weight[block_w];
- const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift);
- const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift);
+ const uint8_t *src0 = ref0->data[0] + y_off0 * src0stride + (int)((unsigned)x_off0 << sps->pixel_shift);
+ const uint8_t *src1 = ref1->data[0] + y_off1 * src1stride + (int)((unsigned)x_off1 << sps->pixel_shift);
if (x_off0 < QPEL_EXTRA_BEFORE || y_off0 < QPEL_EXTRA_AFTER ||
x_off0 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
y_off0 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
- const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
- int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
- int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
+ const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
+ int offset = QPEL_EXTRA_BEFORE * src0stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
+ int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset,
edge_emu_stride, src0stride,
@@ -1658,9 +1677,9 @@ static void luma_mc_uni(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride,
if (x_off1 < QPEL_EXTRA_BEFORE || y_off1 < QPEL_EXTRA_AFTER ||
x_off1 >= pic_width - block_w - QPEL_EXTRA_AFTER ||
y_off1 >= pic_height - block_h - QPEL_EXTRA_AFTER) {
- const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
- int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
- int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << s->ps.sps->pixel_shift);
+ const ptrdiff_t edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
+ int offset = QPEL_EXTRA_BEFORE * src1stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
+ int buf_offset = QPEL_EXTRA_BEFORE * edge_emu_stride + (QPEL_EXTRA_BEFORE << sps->pixel_shift);
s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src1 - offset,
edge_emu_stride, src1stride,
@@ -1705,20 +1724,22 @@ static void luma_mc_uni(HEVCLocalContext *lc, uint8_t *dst, ptrdiff_t dststride,
* @param chroma_offset additive offset applied to the chroma prediction value
*/
-static void chroma_mc_uni(HEVCLocalContext *lc, uint8_t *dst0,
+static void chroma_mc_uni(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ uint8_t *dst0,
ptrdiff_t dststride, const uint8_t *src0, ptrdiff_t srcstride, int reflist,
int x_off, int y_off, int block_w, int block_h,
const struct MvField *current_mv, int chroma_weight, int chroma_offset)
{
const HEVCContext *const s = lc->parent;
- int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1];
- int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1];
+ int pic_width = sps->width >> sps->hshift[1];
+ int pic_height = sps->height >> sps->vshift[1];
const Mv *mv = ¤t_mv->mv[reflist];
- int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
- (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
+ int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
+ (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
int idx = hevc_pel_weight[block_w];
- int hshift = s->ps.sps->hshift[1];
- int vshift = s->ps.sps->vshift[1];
+ int hshift = sps->hshift[1];
+ int vshift = sps->vshift[1];
intptr_t mx = av_mod_uintp2(mv->x, 2 + hshift);
intptr_t my = av_mod_uintp2(mv->y, 2 + vshift);
intptr_t _mx = mx << (1 - hshift);
@@ -1727,16 +1748,16 @@ static void chroma_mc_uni(HEVCLocalContext *lc, uint8_t *dst0,
x_off += mv->x >> (2 + hshift);
y_off += mv->y >> (2 + vshift);
- src0 += y_off * srcstride + (x_off * (1 << s->ps.sps->pixel_shift));
+ src0 += y_off * srcstride + (x_off * (1 << sps->pixel_shift));
if (x_off < EPEL_EXTRA_BEFORE || y_off < EPEL_EXTRA_AFTER ||
x_off >= pic_width - block_w - EPEL_EXTRA_AFTER ||
y_off >= pic_height - block_h - EPEL_EXTRA_AFTER ||
emu) {
- const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
- int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << s->ps.sps->pixel_shift));
+ const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
+ int offset0 = EPEL_EXTRA_BEFORE * (srcstride + (1 << sps->pixel_shift));
int buf_offset0 = EPEL_EXTRA_BEFORE *
- (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
+ (edge_emu_stride + (1 << sps->pixel_shift));
s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src0 - offset0,
edge_emu_stride, srcstride,
block_w + EPEL_EXTRA, block_h + EPEL_EXTRA,
@@ -1773,7 +1794,9 @@ static void chroma_mc_uni(HEVCLocalContext *lc, uint8_t *dst0,
* @param current_mv current motion vector structure
* @param cidx chroma component(cb, cr)
*/
-static void chroma_mc_bi(HEVCLocalContext *lc, uint8_t *dst0, ptrdiff_t dststride,
+static void chroma_mc_bi(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ uint8_t *dst0, ptrdiff_t dststride,
const AVFrame *ref0, const AVFrame *ref1,
int x_off, int y_off, int block_w, int block_h, const MvField *current_mv, int cidx)
{
@@ -1782,14 +1805,14 @@ static void chroma_mc_bi(HEVCLocalContext *lc, uint8_t *dst0, ptrdiff_t dststrid
const uint8_t *src2 = ref1->data[cidx+1];
ptrdiff_t src1stride = ref0->linesize[cidx+1];
ptrdiff_t src2stride = ref1->linesize[cidx+1];
- int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && s->ps.pps->weighted_pred_flag) ||
- (s->sh.slice_type == HEVC_SLICE_B && s->ps.pps->weighted_bipred_flag);
- int pic_width = s->ps.sps->width >> s->ps.sps->hshift[1];
- int pic_height = s->ps.sps->height >> s->ps.sps->vshift[1];
+ int weight_flag = (s->sh.slice_type == HEVC_SLICE_P && pps->weighted_pred_flag) ||
+ (s->sh.slice_type == HEVC_SLICE_B && pps->weighted_bipred_flag);
+ int pic_width = sps->width >> sps->hshift[1];
+ int pic_height = sps->height >> sps->vshift[1];
const Mv *const mv0 = ¤t_mv->mv[0];
const Mv *const mv1 = ¤t_mv->mv[1];
- int hshift = s->ps.sps->hshift[1];
- int vshift = s->ps.sps->vshift[1];
+ int hshift = sps->hshift[1];
+ int vshift = sps->vshift[1];
intptr_t mx0 = av_mod_uintp2(mv0->x, 2 + hshift);
intptr_t my0 = av_mod_uintp2(mv0->y, 2 + vshift);
@@ -1805,16 +1828,16 @@ static void chroma_mc_bi(HEVCLocalContext *lc, uint8_t *dst0, ptrdiff_t dststrid
int x_off1 = x_off + (mv1->x >> (2 + hshift));
int y_off1 = y_off + (mv1->y >> (2 + vshift));
int idx = hevc_pel_weight[block_w];
- src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << s->ps.sps->pixel_shift);
- src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << s->ps.sps->pixel_shift);
+ src1 += y_off0 * src1stride + (int)((unsigned)x_off0 << sps->pixel_shift);
+ src2 += y_off1 * src2stride + (int)((unsigned)x_off1 << sps->pixel_shift);
if (x_off0 < EPEL_EXTRA_BEFORE || y_off0 < EPEL_EXTRA_AFTER ||
x_off0 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
y_off0 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
- const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
- int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << s->ps.sps->pixel_shift));
+ const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
+ int offset1 = EPEL_EXTRA_BEFORE * (src1stride + (1 << sps->pixel_shift));
int buf_offset1 = EPEL_EXTRA_BEFORE *
- (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
+ (edge_emu_stride + (1 << sps->pixel_shift));
s->vdsp.emulated_edge_mc(lc->edge_emu_buffer, src1 - offset1,
edge_emu_stride, src1stride,
@@ -1830,10 +1853,10 @@ static void chroma_mc_bi(HEVCLocalContext *lc, uint8_t *dst0, ptrdiff_t dststrid
if (x_off1 < EPEL_EXTRA_BEFORE || y_off1 < EPEL_EXTRA_AFTER ||
x_off1 >= pic_width - block_w - EPEL_EXTRA_AFTER ||
y_off1 >= pic_height - block_h - EPEL_EXTRA_AFTER) {
- const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << s->ps.sps->pixel_shift;
- int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << s->ps.sps->pixel_shift));
+ const int edge_emu_stride = EDGE_EMU_BUFFER_STRIDE << sps->pixel_shift;
+ int offset1 = EPEL_EXTRA_BEFORE * (src2stride + (1 << sps->pixel_shift));
int buf_offset1 = EPEL_EXTRA_BEFORE *
- (edge_emu_stride + (1 << s->ps.sps->pixel_shift));
+ (edge_emu_stride + (1 << sps->pixel_shift));
s->vdsp.emulated_edge_mc(lc->edge_emu_buffer2, src2 - offset1,
edge_emu_stride, src2stride,
@@ -1874,7 +1897,9 @@ static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
}
}
-static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW,
+static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0, int nPbW,
int nPbH, int log2_cb_size, int part_idx,
int merge_idx, MvField *mv)
{
@@ -1882,7 +1907,7 @@ static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW
enum InterPredIdc inter_pred_idc = PRED_L0;
int mvp_flag;
- ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, s->ps.sps->log2_ctb_size);
+ ff_hevc_set_neighbour_available(lc, x0, y0, nPbW, nPbH, sps->log2_ctb_size);
mv->pred_flag = 0;
if (s->sh.slice_type == HEVC_SLICE_B)
inter_pred_idc = ff_hevc_inter_pred_idc_decode(lc, nPbW, nPbH);
@@ -1894,7 +1919,7 @@ static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW
mv->pred_flag = PF_L0;
ff_hevc_hls_mvd_coding(lc, x0, y0, 0);
mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
- ff_hevc_luma_mv_mvp_mode(lc, s->ps.pps, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
part_idx, merge_idx, mv, mvp_flag, 0);
mv->mv[0].x += lc->pu.mvd.x;
mv->mv[0].y += lc->pu.mvd.y;
@@ -1912,25 +1937,26 @@ static void hevc_luma_mv_mvp_mode(HEVCLocalContext *lc, int x0, int y0, int nPbW
mv->pred_flag += PF_L1;
mvp_flag = ff_hevc_mvp_lx_flag_decode(lc);
- ff_hevc_luma_mv_mvp_mode(lc, s->ps.pps, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_luma_mv_mvp_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
part_idx, merge_idx, mv, mvp_flag, 1);
mv->mv[1].x += lc->pu.mvd.x;
mv->mv[1].y += lc->pu.mvd.y;
}
}
-static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
- int nPbW, int nPbH,
+static void hls_prediction_unit(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0, int nPbW, int nPbH,
int log2_cb_size, int partIdx, int idx)
{
#define POS(c_idx, x, y) \
- &s->cur_frame->f->data[c_idx][((y) >> s->ps.sps->vshift[c_idx]) * linesize[c_idx] + \
- (((x) >> s->ps.sps->hshift[c_idx]) << s->ps.sps->pixel_shift)]
+ &s->cur_frame->f->data[c_idx][((y) >> sps->vshift[c_idx]) * linesize[c_idx] + \
+ (((x) >> sps->hshift[c_idx]) << sps->pixel_shift)]
const HEVCContext *const s = lc->parent;
int merge_idx = 0;
struct MvField current_mv = {{{ 0 }}};
- int min_pu_width = s->ps.sps->min_pu_width;
+ int min_pu_width = sps->min_pu_width;
MvField *tab_mvf = s->cur_frame->tab_mvf;
const RefPicList *refPicList = s->cur_frame->refPicList;
@@ -1939,8 +1965,8 @@ static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
uint8_t *dst0 = POS(0, x0, y0);
uint8_t *dst1 = POS(1, x0, y0);
uint8_t *dst2 = POS(2, x0, y0);
- int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
- int min_cb_width = s->ps.sps->min_cb_width;
+ int log2_min_cb_size = sps->log2_min_cb_size;
+ int min_cb_width = sps->min_cb_width;
int x_cb = x0 >> log2_min_cb_size;
int y_cb = y0 >> log2_min_cb_size;
int x_pu, y_pu;
@@ -1957,18 +1983,18 @@ static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
else
merge_idx = 0;
- ff_hevc_luma_mv_merge_mode(lc, s->ps.pps, x0, y0, nPbW, nPbH, log2_cb_size,
+ ff_hevc_luma_mv_merge_mode(lc, pps, x0, y0, nPbW, nPbH, log2_cb_size,
partIdx, merge_idx, ¤t_mv);
} else {
- hevc_luma_mv_mvp_mode(lc, x0, y0, nPbW, nPbH, log2_cb_size,
+ hevc_luma_mv_mvp_mode(lc, pps, sps, x0, y0, nPbW, nPbH, log2_cb_size,
partIdx, merge_idx, ¤t_mv);
}
- x_pu = x0 >> s->ps.sps->log2_min_pu_size;
- y_pu = y0 >> s->ps.sps->log2_min_pu_size;
+ x_pu = x0 >> sps->log2_min_pu_size;
+ y_pu = y0 >> sps->log2_min_pu_size;
- for (j = 0; j < nPbH >> s->ps.sps->log2_min_pu_size; j++)
- for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++)
+ for (j = 0; j < nPbH >> sps->log2_min_pu_size; j++)
+ for (i = 0; i < nPbW >> sps->log2_min_pu_size; i++)
tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv;
if (current_mv.pred_flag & PF_L0) {
@@ -1985,59 +2011,59 @@ static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
}
if (current_mv.pred_flag == PF_L0) {
- int x0_c = x0 >> s->ps.sps->hshift[1];
- int y0_c = y0 >> s->ps.sps->vshift[1];
- int nPbW_c = nPbW >> s->ps.sps->hshift[1];
- int nPbH_c = nPbH >> s->ps.sps->vshift[1];
+ int x0_c = x0 >> sps->hshift[1];
+ int y0_c = y0 >> sps->vshift[1];
+ int nPbW_c = nPbW >> sps->hshift[1];
+ int nPbH_c = nPbH >> sps->vshift[1];
- luma_mc_uni(lc, dst0, linesize[0], ref0->f,
+ luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref0->f,
¤t_mv.mv[0], x0, y0, nPbW, nPbH,
s->sh.luma_weight_l0[current_mv.ref_idx[0]],
s->sh.luma_offset_l0[current_mv.ref_idx[0]]);
- if (s->ps.sps->chroma_format_idc) {
- chroma_mc_uni(lc, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1],
+ if (sps->chroma_format_idc) {
+ chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref0->f->data[1], ref0->f->linesize[1],
0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
s->sh.chroma_weight_l0[current_mv.ref_idx[0]][0], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][0]);
- chroma_mc_uni(lc, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2],
+ chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref0->f->data[2], ref0->f->linesize[2],
0, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
s->sh.chroma_weight_l0[current_mv.ref_idx[0]][1], s->sh.chroma_offset_l0[current_mv.ref_idx[0]][1]);
}
} else if (current_mv.pred_flag == PF_L1) {
- int x0_c = x0 >> s->ps.sps->hshift[1];
- int y0_c = y0 >> s->ps.sps->vshift[1];
- int nPbW_c = nPbW >> s->ps.sps->hshift[1];
- int nPbH_c = nPbH >> s->ps.sps->vshift[1];
+ int x0_c = x0 >> sps->hshift[1];
+ int y0_c = y0 >> sps->vshift[1];
+ int nPbW_c = nPbW >> sps->hshift[1];
+ int nPbH_c = nPbH >> sps->vshift[1];
- luma_mc_uni(lc, dst0, linesize[0], ref1->f,
+ luma_mc_uni(lc, pps, sps, dst0, linesize[0], ref1->f,
¤t_mv.mv[1], x0, y0, nPbW, nPbH,
s->sh.luma_weight_l1[current_mv.ref_idx[1]],
s->sh.luma_offset_l1[current_mv.ref_idx[1]]);
- if (s->ps.sps->chroma_format_idc) {
- chroma_mc_uni(lc, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1],
+ if (sps->chroma_format_idc) {
+ chroma_mc_uni(lc, pps, sps, dst1, linesize[1], ref1->f->data[1], ref1->f->linesize[1],
1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
s->sh.chroma_weight_l1[current_mv.ref_idx[1]][0], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][0]);
- chroma_mc_uni(lc, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2],
+ chroma_mc_uni(lc, pps, sps, dst2, linesize[2], ref1->f->data[2], ref1->f->linesize[2],
1, x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv,
s->sh.chroma_weight_l1[current_mv.ref_idx[1]][1], s->sh.chroma_offset_l1[current_mv.ref_idx[1]][1]);
}
} else if (current_mv.pred_flag == PF_BI) {
- int x0_c = x0 >> s->ps.sps->hshift[1];
- int y0_c = y0 >> s->ps.sps->vshift[1];
- int nPbW_c = nPbW >> s->ps.sps->hshift[1];
- int nPbH_c = nPbH >> s->ps.sps->vshift[1];
+ int x0_c = x0 >> sps->hshift[1];
+ int y0_c = y0 >> sps->vshift[1];
+ int nPbW_c = nPbW >> sps->hshift[1];
+ int nPbH_c = nPbH >> sps->vshift[1];
- luma_mc_bi(lc, dst0, linesize[0], ref0->f,
+ luma_mc_bi(lc, pps, sps, dst0, linesize[0], ref0->f,
¤t_mv.mv[0], x0, y0, nPbW, nPbH,
ref1->f, ¤t_mv.mv[1], ¤t_mv);
- if (s->ps.sps->chroma_format_idc) {
- chroma_mc_bi(lc, dst1, linesize[1], ref0->f, ref1->f,
+ if (sps->chroma_format_idc) {
+ chroma_mc_bi(lc, pps, sps, dst1, linesize[1], ref0->f, ref1->f,
x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 0);
- chroma_mc_bi(lc, dst2, linesize[2], ref0->f, ref1->f,
+ chroma_mc_bi(lc, pps, sps, dst2, linesize[2], ref0->f, ref1->f,
x0_c, y0_c, nPbW_c, nPbH_c, ¤t_mv, 1);
}
}
@@ -2046,23 +2072,24 @@ static void hls_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
/**
* 8.4.1
*/
-static int luma_intra_pred_mode(HEVCLocalContext *lc, int x0, int y0, int pu_size,
+static int luma_intra_pred_mode(HEVCLocalContext *lc, const HEVCSPS *sps,
+ int x0, int y0, int pu_size,
int prev_intra_luma_pred_flag)
{
const HEVCContext *const s = lc->parent;
- int x_pu = x0 >> s->ps.sps->log2_min_pu_size;
- int y_pu = y0 >> s->ps.sps->log2_min_pu_size;
- int min_pu_width = s->ps.sps->min_pu_width;
- int size_in_pus = pu_size >> s->ps.sps->log2_min_pu_size;
- int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
- int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
+ int x_pu = x0 >> sps->log2_min_pu_size;
+ int y_pu = y0 >> sps->log2_min_pu_size;
+ int min_pu_width = sps->min_pu_width;
+ int size_in_pus = pu_size >> sps->log2_min_pu_size;
+ int x0b = av_mod_uintp2(x0, sps->log2_ctb_size);
+ int y0b = av_mod_uintp2(y0, sps->log2_ctb_size);
int cand_up = (lc->ctb_up_flag || y0b) ?
s->tab_ipm[(y_pu - 1) * min_pu_width + x_pu] : INTRA_DC;
int cand_left = (lc->ctb_left_flag || x0b) ?
s->tab_ipm[y_pu * min_pu_width + x_pu - 1] : INTRA_DC;
- int y_ctb = (y0 >> (s->ps.sps->log2_ctb_size)) << (s->ps.sps->log2_ctb_size);
+ int y_ctb = (y0 >> (sps->log2_ctb_size)) << (sps->log2_ctb_size);
MvField *tab_mvf = s->cur_frame->tab_mvf;
int intra_pred_mode;
@@ -2126,16 +2153,17 @@ static int luma_intra_pred_mode(HEVCLocalContext *lc, int x0, int y0, int pu_siz
return intra_pred_mode;
}
-static av_always_inline void set_ct_depth(const HEVCContext *s, int x0, int y0,
+static av_always_inline void set_ct_depth(const HEVCSPS *sps, uint8_t *tab_ct_depth,
+ int x0, int y0,
int log2_cb_size, int ct_depth)
{
- int length = (1 << log2_cb_size) >> s->ps.sps->log2_min_cb_size;
- int x_cb = x0 >> s->ps.sps->log2_min_cb_size;
- int y_cb = y0 >> s->ps.sps->log2_min_cb_size;
+ int length = (1 << log2_cb_size) >> sps->log2_min_cb_size;
+ int x_cb = x0 >> sps->log2_min_cb_size;
+ int y_cb = y0 >> sps->log2_min_cb_size;
int y;
for (y = 0; y < length; y++)
- memset(&s->tab_ct_depth[(y_cb + y) * s->ps.sps->min_cb_width + x_cb],
+ memset(&tab_ct_depth[(y_cb + y) * sps->min_cb_width + x_cb],
ct_depth, length);
}
@@ -2143,10 +2171,10 @@ static const uint8_t tab_mode_idx[] = {
0, 1, 2, 2, 2, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 19, 20,
21, 22, 23, 23, 24, 24, 25, 25, 26, 27, 27, 28, 28, 29, 29, 30, 31};
-static void intra_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
+static void intra_prediction_unit(HEVCLocalContext *lc, const HEVCSPS *sps,
+ int x0, int y0,
int log2_cb_size)
{
- const HEVCContext *const s = lc->parent;
static const uint8_t intra_chroma_table[4] = { 0, 26, 10, 1 };
uint8_t prev_intra_luma_pred_flag[4];
int split = lc->cu.part_mode == PART_NxN;
@@ -2167,12 +2195,12 @@ static void intra_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
lc->pu.rem_intra_luma_pred_mode = ff_hevc_rem_intra_luma_pred_mode_decode(lc);
lc->pu.intra_pred_mode[2 * i + j] =
- luma_intra_pred_mode(lc, x0 + pb_size * j, y0 + pb_size * i, pb_size,
+ luma_intra_pred_mode(lc, sps, x0 + pb_size * j, y0 + pb_size * i, pb_size,
prev_intra_luma_pred_flag[2 * i + j]);
}
}
- if (s->ps.sps->chroma_format_idc == 3) {
+ if (sps->chroma_format_idc == 3) {
for (i = 0; i < side; i++) {
for (j = 0; j < side; j++) {
lc->pu.chroma_mode_c[2 * i + j] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
@@ -2186,7 +2214,7 @@ static void intra_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
}
}
}
- } else if (s->ps.sps->chroma_format_idc == 2) {
+ } else if (sps->chroma_format_idc == 2) {
int mode_idx;
lc->pu.chroma_mode_c[0] = chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
if (chroma_mode != 4) {
@@ -2198,7 +2226,7 @@ static void intra_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
mode_idx = lc->pu.intra_pred_mode[0];
}
lc->pu.intra_pred_mode_c[0] = tab_mode_idx[mode_idx];
- } else if (s->ps.sps->chroma_format_idc != 0) {
+ } else if (sps->chroma_format_idc != 0) {
chroma_mode = ff_hevc_intra_chroma_pred_mode_decode(lc);
if (chroma_mode != 4) {
if (lc->pu.intra_pred_mode[0] == intra_chroma_table[chroma_mode])
@@ -2212,16 +2240,17 @@ static void intra_prediction_unit(HEVCLocalContext *lc, int x0, int y0,
}
static void intra_prediction_unit_default_value(HEVCLocalContext *lc,
+ const HEVCSPS *sps,
int x0, int y0,
int log2_cb_size)
{
const HEVCContext *const s = lc->parent;
int pb_size = 1 << log2_cb_size;
- int size_in_pus = pb_size >> s->ps.sps->log2_min_pu_size;
- int min_pu_width = s->ps.sps->min_pu_width;
+ int size_in_pus = pb_size >> sps->log2_min_pu_size;
+ int min_pu_width = sps->min_pu_width;
MvField *tab_mvf = s->cur_frame->tab_mvf;
- int x_pu = x0 >> s->ps.sps->log2_min_pu_size;
- int y_pu = y0 >> s->ps.sps->log2_min_pu_size;
+ int x_pu = x0 >> sps->log2_min_pu_size;
+ int y_pu = y0 >> sps->log2_min_pu_size;
int j, k;
if (size_in_pus == 0)
@@ -2234,16 +2263,18 @@ static void intra_prediction_unit_default_value(HEVCLocalContext *lc,
tab_mvf[(y_pu + j) * min_pu_width + x_pu + k].pred_flag = PF_INTRA;
}
-static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, int y0, int log2_cb_size)
+static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0, int log2_cb_size)
{
int cb_size = 1 << log2_cb_size;
- int log2_min_cb_size = s->ps.sps->log2_min_cb_size;
+ int log2_min_cb_size = sps->log2_min_cb_size;
int length = cb_size >> log2_min_cb_size;
- int min_cb_width = s->ps.sps->min_cb_width;
+ int min_cb_width = sps->min_cb_width;
int x_cb = x0 >> log2_min_cb_size;
int y_cb = y0 >> log2_min_cb_size;
int idx = log2_cb_size - 2;
- int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1;
+ int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
int x, y, ret;
lc->cu.x = x0;
@@ -2255,16 +2286,16 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
SAMPLE_CTB(s->skip_flag, x_cb, y_cb) = 0;
for (x = 0; x < 4; x++)
lc->pu.intra_pred_mode[x] = 1;
- if (s->ps.pps->transquant_bypass_enable_flag) {
+ if (pps->transquant_bypass_enable_flag) {
lc->cu.cu_transquant_bypass_flag = ff_hevc_cu_transquant_bypass_flag_decode(lc);
if (lc->cu.cu_transquant_bypass_flag)
- set_deblocking_bypass(s, x0, y0, log2_cb_size);
+ set_deblocking_bypass(s, sps, x0, y0, log2_cb_size);
} else
lc->cu.cu_transquant_bypass_flag = 0;
if (s->sh.slice_type != HEVC_SLICE_I) {
- const int x0b = av_mod_uintp2(x0, s->ps.sps->log2_ctb_size);
- const int y0b = av_mod_uintp2(y0, s->ps.sps->log2_ctb_size);
+ const int x0b = av_mod_uintp2(x0, sps->log2_ctb_size);
+ const int y0b = av_mod_uintp2(y0, sps->log2_ctb_size);
uint8_t skip_flag = ff_hevc_skip_flag_decode(lc, x0b, y0b, x_cb, y_cb,
min_cb_width);
@@ -2283,75 +2314,93 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
}
if (SAMPLE_CTB(s->skip_flag, x_cb, y_cb)) {
- hls_prediction_unit(lc, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
- intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
+ intra_prediction_unit_default_value(lc, sps, x0, y0, log2_cb_size);
if (!s->sh.disable_deblocking_filter_flag)
- ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_cb_size);
+ ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size);
} else {
int pcm_flag = 0;
if (s->sh.slice_type != HEVC_SLICE_I)
lc->cu.pred_mode = ff_hevc_pred_mode_decode(lc);
if (lc->cu.pred_mode != MODE_INTRA ||
- log2_cb_size == s->ps.sps->log2_min_cb_size) {
- lc->cu.part_mode = ff_hevc_part_mode_decode(lc, s->ps.sps, log2_cb_size);
+ log2_cb_size == sps->log2_min_cb_size) {
+ lc->cu.part_mode = ff_hevc_part_mode_decode(lc, sps, log2_cb_size);
lc->cu.intra_split_flag = lc->cu.part_mode == PART_NxN &&
lc->cu.pred_mode == MODE_INTRA;
}
if (lc->cu.pred_mode == MODE_INTRA) {
- if (lc->cu.part_mode == PART_2Nx2N && s->ps.sps->pcm_enabled &&
- log2_cb_size >= s->ps.sps->pcm.log2_min_pcm_cb_size &&
- log2_cb_size <= s->ps.sps->pcm.log2_max_pcm_cb_size) {
+ if (lc->cu.part_mode == PART_2Nx2N && sps->pcm_enabled &&
+ log2_cb_size >= sps->pcm.log2_min_pcm_cb_size &&
+ log2_cb_size <= sps->pcm.log2_max_pcm_cb_size) {
pcm_flag = ff_hevc_pcm_flag_decode(lc);
}
if (pcm_flag) {
- intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size);
- ret = hls_pcm_sample(lc, x0, y0, log2_cb_size);
- if (s->ps.sps->pcm_loop_filter_disabled)
- set_deblocking_bypass(s, x0, y0, log2_cb_size);
+ intra_prediction_unit_default_value(lc, sps, x0, y0, log2_cb_size);
+ ret = hls_pcm_sample(lc, pps, x0, y0, log2_cb_size);
+ if (sps->pcm_loop_filter_disabled)
+ set_deblocking_bypass(s, sps, x0, y0, log2_cb_size);
if (ret < 0)
return ret;
} else {
- intra_prediction_unit(lc, x0, y0, log2_cb_size);
+ intra_prediction_unit(lc, sps, x0, y0, log2_cb_size);
}
} else {
- intra_prediction_unit_default_value(lc, x0, y0, log2_cb_size);
+ intra_prediction_unit_default_value(lc, sps, x0, y0, log2_cb_size);
switch (lc->cu.part_mode) {
case PART_2Nx2N:
- hls_prediction_unit(lc, x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size, cb_size, log2_cb_size, 0, idx);
break;
case PART_2NxN:
- hls_prediction_unit(lc, x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
- hls_prediction_unit(lc, x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size, cb_size / 2, log2_cb_size, 0, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0 + cb_size / 2, cb_size, cb_size / 2, log2_cb_size, 1, idx);
break;
case PART_Nx2N:
- hls_prediction_unit(lc, x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
- hls_prediction_unit(lc, x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size / 2, cb_size, log2_cb_size, 0, idx - 1);
+ hls_prediction_unit(lc, pps, sps,
+ x0 + cb_size / 2, y0, cb_size / 2, cb_size, log2_cb_size, 1, idx - 1);
break;
case PART_2NxnU:
- hls_prediction_unit(lc, x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
- hls_prediction_unit(lc, x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size, cb_size / 4, log2_cb_size, 0, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0 + cb_size / 4, cb_size, cb_size * 3 / 4, log2_cb_size, 1, idx);
break;
case PART_2NxnD:
- hls_prediction_unit(lc, x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
- hls_prediction_unit(lc, x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size, cb_size * 3 / 4, log2_cb_size, 0, idx);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0 + cb_size * 3 / 4, cb_size, cb_size / 4, log2_cb_size, 1, idx);
break;
case PART_nLx2N:
- hls_prediction_unit(lc, x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
- hls_prediction_unit(lc, x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size / 4, cb_size, log2_cb_size, 0, idx - 2);
+ hls_prediction_unit(lc, pps, sps,
+ x0 + cb_size / 4, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 1, idx - 2);
break;
case PART_nRx2N:
- hls_prediction_unit(lc, x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
- hls_prediction_unit(lc, x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size * 3 / 4, cb_size, log2_cb_size, 0, idx - 2);
+ hls_prediction_unit(lc, pps, sps,
+ x0 + cb_size * 3 / 4, y0, cb_size / 4, cb_size, log2_cb_size, 1, idx - 2);
break;
case PART_NxN:
- hls_prediction_unit(lc, x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
- hls_prediction_unit(lc, x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
- hls_prediction_unit(lc, x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
- hls_prediction_unit(lc, x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0, cb_size / 2, cb_size / 2, log2_cb_size, 0, idx - 1);
+ hls_prediction_unit(lc, pps, sps,
+ x0 + cb_size / 2, y0, cb_size / 2, cb_size / 2, log2_cb_size, 1, idx - 1);
+ hls_prediction_unit(lc, pps, sps,
+ x0, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 2, idx - 1);
+ hls_prediction_unit(lc, pps, sps,
+ x0 + cb_size / 2, y0 + cb_size / 2, cb_size / 2, cb_size / 2, log2_cb_size, 3, idx - 1);
break;
}
}
@@ -2366,22 +2415,22 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
if (rqt_root_cbf) {
const static int cbf[2] = { 0 };
lc->cu.max_trafo_depth = lc->cu.pred_mode == MODE_INTRA ?
- s->ps.sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
- s->ps.sps->max_transform_hierarchy_depth_inter;
- ret = hls_transform_tree(lc, x0, y0, x0, y0, x0, y0,
+ sps->max_transform_hierarchy_depth_intra + lc->cu.intra_split_flag :
+ sps->max_transform_hierarchy_depth_inter;
+ ret = hls_transform_tree(lc, pps, sps, x0, y0, x0, y0, x0, y0,
log2_cb_size,
log2_cb_size, 0, 0, cbf, cbf);
if (ret < 0)
return ret;
} else {
if (!s->sh.disable_deblocking_filter_flag)
- ff_hevc_deblocking_boundary_strengths(lc, s->ps.pps, x0, y0, log2_cb_size);
+ ff_hevc_deblocking_boundary_strengths(lc, pps, x0, y0, log2_cb_size);
}
}
}
- if (s->ps.pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
- ff_hevc_set_qPy(lc, s->ps.pps, x0, y0, log2_cb_size);
+ if (pps->cu_qp_delta_enabled_flag && lc->tu.is_cu_qp_delta_coded == 0)
+ ff_hevc_set_qPy(lc, pps, x0, y0, log2_cb_size);
x = y_cb * min_cb_width + x_cb;
for (y = 0; y < length; y++) {
@@ -2394,12 +2443,14 @@ static int hls_coding_unit(HEVCLocalContext *lc, const HEVCContext *s, int x0, i
lc->qPy_pred = lc->qp_y;
}
- set_ct_depth(s, x0, y0, log2_cb_size, lc->ct_depth);
+ set_ct_depth(sps, s->tab_ct_depth, x0, y0, log2_cb_size, lc->ct_depth);
return 0;
}
-static int hls_coding_quadtree(HEVCLocalContext *lc, int x0, int y0,
+static int hls_coding_quadtree(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x0, int y0,
int log2_cb_size, int cb_depth)
{
const HEVCContext *const s = lc->parent;
@@ -2408,49 +2459,49 @@ static int hls_coding_quadtree(HEVCLocalContext *lc, int x0, int y0,
int split_cu;
lc->ct_depth = cb_depth;
- if (x0 + cb_size <= s->ps.sps->width &&
- y0 + cb_size <= s->ps.sps->height &&
- log2_cb_size > s->ps.sps->log2_min_cb_size) {
- split_cu = ff_hevc_split_coding_unit_flag_decode(lc, s->ps.sps, cb_depth, x0, y0);
+ if (x0 + cb_size <= sps->width &&
+ y0 + cb_size <= sps->height &&
+ log2_cb_size > sps->log2_min_cb_size) {
+ split_cu = ff_hevc_split_coding_unit_flag_decode(lc, sps, cb_depth, x0, y0);
} else {
- split_cu = (log2_cb_size > s->ps.sps->log2_min_cb_size);
+ split_cu = (log2_cb_size > sps->log2_min_cb_size);
}
- if (s->ps.pps->cu_qp_delta_enabled_flag &&
- log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth) {
+ if (pps->cu_qp_delta_enabled_flag &&
+ log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_qp_delta_depth) {
lc->tu.is_cu_qp_delta_coded = 0;
lc->tu.cu_qp_delta = 0;
}
if (s->sh.cu_chroma_qp_offset_enabled_flag &&
- log2_cb_size >= s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_chroma_qp_offset_depth) {
+ log2_cb_size >= sps->log2_ctb_size - pps->diff_cu_chroma_qp_offset_depth) {
lc->tu.is_cu_chroma_qp_offset_coded = 0;
}
if (split_cu) {
- int qp_block_mask = (1<<(s->ps.sps->log2_ctb_size - s->ps.pps->diff_cu_qp_delta_depth)) - 1;
+ int qp_block_mask = (1 << (sps->log2_ctb_size - pps->diff_cu_qp_delta_depth)) - 1;
const int cb_size_split = cb_size >> 1;
const int x1 = x0 + cb_size_split;
const int y1 = y0 + cb_size_split;
int more_data = 0;
- more_data = hls_coding_quadtree(lc, x0, y0, log2_cb_size - 1, cb_depth + 1);
+ more_data = hls_coding_quadtree(lc, pps, sps, x0, y0, log2_cb_size - 1, cb_depth + 1);
if (more_data < 0)
return more_data;
- if (more_data && x1 < s->ps.sps->width) {
- more_data = hls_coding_quadtree(lc, x1, y0, log2_cb_size - 1, cb_depth + 1);
+ if (more_data && x1 < sps->width) {
+ more_data = hls_coding_quadtree(lc, pps, sps, x1, y0, log2_cb_size - 1, cb_depth + 1);
if (more_data < 0)
return more_data;
}
- if (more_data && y1 < s->ps.sps->height) {
- more_data = hls_coding_quadtree(lc, x0, y1, log2_cb_size - 1, cb_depth + 1);
+ if (more_data && y1 < sps->height) {
+ more_data = hls_coding_quadtree(lc, pps, sps, x0, y1, log2_cb_size - 1, cb_depth + 1);
if (more_data < 0)
return more_data;
}
- if (more_data && x1 < s->ps.sps->width &&
- y1 < s->ps.sps->height) {
- more_data = hls_coding_quadtree(lc, x1, y1, log2_cb_size - 1, cb_depth + 1);
+ if (more_data && x1 < sps->width &&
+ y1 < sps->height) {
+ more_data = hls_coding_quadtree(lc, pps, sps, x1, y1, log2_cb_size - 1, cb_depth + 1);
if (more_data < 0)
return more_data;
}
@@ -2460,20 +2511,20 @@ static int hls_coding_quadtree(HEVCLocalContext *lc, int x0, int y0,
lc->qPy_pred = lc->qp_y;
if (more_data)
- return ((x1 + cb_size_split) < s->ps.sps->width ||
- (y1 + cb_size_split) < s->ps.sps->height);
+ return ((x1 + cb_size_split) < sps->width ||
+ (y1 + cb_size_split) < sps->height);
else
return 0;
} else {
- ret = hls_coding_unit(lc, s, x0, y0, log2_cb_size);
+ ret = hls_coding_unit(lc, s, pps, sps, x0, y0, log2_cb_size);
if (ret < 0)
return ret;
if ((!((x0 + cb_size) %
- (1 << (s->ps.sps->log2_ctb_size))) ||
- (x0 + cb_size >= s->ps.sps->width)) &&
+ (1 << (sps->log2_ctb_size))) ||
+ (x0 + cb_size >= sps->width)) &&
(!((y0 + cb_size) %
- (1 << (s->ps.sps->log2_ctb_size))) ||
- (y0 + cb_size >= s->ps.sps->height))) {
+ (1 << (sps->log2_ctb_size))) ||
+ (y0 + cb_size >= sps->height))) {
int end_of_slice_flag = ff_hevc_end_of_slice_flag_decode(lc);
return !end_of_slice_flag;
} else {
@@ -2484,65 +2535,68 @@ static int hls_coding_quadtree(HEVCLocalContext *lc, int x0, int y0,
return 0;
}
-static void hls_decode_neighbour(HEVCLocalContext *lc, int x_ctb, int y_ctb,
- int ctb_addr_ts)
+static void hls_decode_neighbour(HEVCLocalContext *lc,
+ const HEVCPPS *pps, const HEVCSPS *sps,
+ int x_ctb, int y_ctb, int ctb_addr_ts)
{
const HEVCContext *const s = lc->parent;
- int ctb_size = 1 << s->ps.sps->log2_ctb_size;
- int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
+ int ctb_size = 1 << sps->log2_ctb_size;
+ int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
int ctb_addr_in_slice = ctb_addr_rs - s->sh.slice_addr;
s->tab_slice_address[ctb_addr_rs] = s->sh.slice_addr;
- if (s->ps.pps->entropy_coding_sync_enabled_flag) {
+ if (pps->entropy_coding_sync_enabled_flag) {
if (x_ctb == 0 && (y_ctb & (ctb_size - 1)) == 0)
lc->first_qp_group = 1;
- lc->end_of_tiles_x = s->ps.sps->width;
- } else if (s->ps.pps->tiles_enabled_flag) {
- if (ctb_addr_ts && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts - 1]) {
- int idxX = s->ps.pps->col_idxX[x_ctb >> s->ps.sps->log2_ctb_size];
- lc->end_of_tiles_x = x_ctb + (s->ps.pps->column_width[idxX] << s->ps.sps->log2_ctb_size);
+ lc->end_of_tiles_x = sps->width;
+ } else if (pps->tiles_enabled_flag) {
+ if (ctb_addr_ts && pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
+ int idxX = pps->col_idxX[x_ctb >> sps->log2_ctb_size];
+ lc->end_of_tiles_x = x_ctb + (pps->column_width[idxX] << sps->log2_ctb_size);
lc->first_qp_group = 1;
}
} else {
- lc->end_of_tiles_x = s->ps.sps->width;
+ lc->end_of_tiles_x = sps->width;
}
- lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, s->ps.sps->height);
+ lc->end_of_tiles_y = FFMIN(y_ctb + ctb_size, sps->height);
lc->boundary_flags = 0;
- if (s->ps.pps->tiles_enabled_flag) {
- if (x_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
+ if (pps->tiles_enabled_flag) {
+ if (x_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - 1]])
lc->boundary_flags |= BOUNDARY_LEFT_TILE;
if (x_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - 1])
lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
- if (y_ctb > 0 && s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs - s->ps.sps->ctb_width]])
+ if (y_ctb > 0 && pps->tile_id[ctb_addr_ts] != pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs - sps->ctb_width]])
lc->boundary_flags |= BOUNDARY_UPPER_TILE;
- if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - s->ps.sps->ctb_width])
+ if (y_ctb > 0 && s->tab_slice_address[ctb_addr_rs] != s->tab_slice_address[ctb_addr_rs - sps->ctb_width])
lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
} else {
if (ctb_addr_in_slice <= 0)
lc->boundary_flags |= BOUNDARY_LEFT_SLICE;
- if (ctb_addr_in_slice < s->ps.sps->ctb_width)
+ if (ctb_addr_in_slice < sps->ctb_width)
lc->boundary_flags |= BOUNDARY_UPPER_SLICE;
}
lc->ctb_left_flag = ((x_ctb > 0) && (ctb_addr_in_slice > 0) && !(lc->boundary_flags & BOUNDARY_LEFT_TILE));
- lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= s->ps.sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
- lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - s->ps.sps->ctb_width]]));
- lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && (s->ps.pps->tile_id[ctb_addr_ts] == s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - s->ps.sps->ctb_width]]));
+ lc->ctb_up_flag = ((y_ctb > 0) && (ctb_addr_in_slice >= sps->ctb_width) && !(lc->boundary_flags & BOUNDARY_UPPER_TILE));
+ lc->ctb_up_right_flag = ((y_ctb > 0) && (ctb_addr_in_slice+1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs+1 - sps->ctb_width]]));
+ lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0) && (ctb_addr_in_slice-1 >= sps->ctb_width) && (pps->tile_id[ctb_addr_ts] == pps->tile_id[pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - sps->ctb_width]]));
}
static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
{
HEVCLocalContext *const lc = &s->local_ctx[0];
+ const HEVCPPS *const pps = s->ps.pps;
+ const HEVCSPS *const sps = pps->sps;
const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
const size_t slice_size = gb->buffer_end - gb->buffer - s->sh.data_offset;
- int ctb_size = 1 << s->ps.sps->log2_ctb_size;
+ int ctb_size = 1 << sps->log2_ctb_size;
int more_data = 1;
int x_ctb = 0;
int y_ctb = 0;
- int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
+ int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
int ret;
if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) {
@@ -2551,33 +2605,34 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
}
if (s->sh.dependent_slice_segment_flag) {
- int prev_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
+ int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
return AVERROR_INVALIDDATA;
}
}
- while (more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
- int ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
+ while (more_data && ctb_addr_ts < sps->ctb_size) {
+ int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
- x_ctb = (ctb_addr_rs % ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
- y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
- hls_decode_neighbour(lc, x_ctb, y_ctb, ctb_addr_ts);
+ x_ctb = (ctb_addr_rs % ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
+ y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
+ hls_decode_neighbour(lc, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
- ret = ff_hevc_cabac_init(lc, s->ps.pps, ctb_addr_ts, slice_data, slice_size);
+ ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size);
if (ret < 0) {
s->tab_slice_address[ctb_addr_rs] = -1;
return ret;
}
- hls_sao_param(lc, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
+ hls_sao_param(lc, pps, sps,
+ x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
s->deblock[ctb_addr_rs].beta_offset = s->sh.beta_offset;
s->deblock[ctb_addr_rs].tc_offset = s->sh.tc_offset;
s->filter_slice_edges[ctb_addr_rs] = s->sh.slice_loop_filter_across_slices_enabled_flag;
- more_data = hls_coding_quadtree(lc, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);
+ more_data = hls_coding_quadtree(lc, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
if (more_data < 0) {
s->tab_slice_address[ctb_addr_rs] = -1;
return more_data;
@@ -2585,13 +2640,13 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
ctb_addr_ts++;
- ff_hevc_save_states(lc, s->ps.pps, ctb_addr_ts);
- ff_hevc_hls_filters(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
+ ff_hevc_save_states(lc, pps, ctb_addr_ts);
+ ff_hevc_hls_filters(lc, pps, x_ctb, y_ctb, ctb_size);
}
- if (x_ctb + ctb_size >= s->ps.sps->width &&
- y_ctb + ctb_size >= s->ps.sps->height)
- ff_hevc_hls_filter(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
+ if (x_ctb + ctb_size >= sps->width &&
+ y_ctb + ctb_size >= sps->height)
+ ff_hevc_hls_filter(lc, pps, x_ctb, y_ctb, ctb_size);
return ctb_addr_ts;
}
@@ -2601,11 +2656,13 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
{
HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id];
const HEVCContext *const s = lc->parent;
- int ctb_size = 1 << s->ps.sps->log2_ctb_size;
+ const HEVCPPS *const pps = s->ps.pps;
+ const HEVCSPS *const sps = pps->sps;
+ int ctb_size = 1 << sps->log2_ctb_size;
int more_data = 1;
int ctb_row = job;
- int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((s->ps.sps->width + ctb_size - 1) >> s->ps.sps->log2_ctb_size);
- int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs];
+ int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size);
+ int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
int thread = ctb_row % s->threads_number;
const uint8_t *data = s->data + s->sh.offset[ctb_row];
@@ -2616,11 +2673,11 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
if (ctb_row)
ff_init_cabac_decoder(&lc->cc, data, data_size);
- while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
- int x_ctb = (ctb_addr_rs % s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size;
- int y_ctb = (ctb_addr_rs / s->ps.sps->ctb_width) << s->ps.sps->log2_ctb_size;
+ while(more_data && ctb_addr_ts < sps->ctb_size) {
+ int x_ctb = (ctb_addr_rs % sps->ctb_width) << sps->log2_ctb_size;
+ int y_ctb = (ctb_addr_rs / sps->ctb_width) << sps->log2_ctb_size;
- hls_decode_neighbour(lc, x_ctb, y_ctb, ctb_addr_ts);
+ hls_decode_neighbour(lc, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
ff_thread_await_progress2(s->avctx, ctb_row, thread, SHIFT_CTB_WPP);
@@ -2632,11 +2689,12 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
return 0;
}
- ret = ff_hevc_cabac_init(lc, s->ps.pps, ctb_addr_ts, data, data_size);
+ ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size);
if (ret < 0)
goto error;
- hls_sao_param(lc, x_ctb >> s->ps.sps->log2_ctb_size, y_ctb >> s->ps.sps->log2_ctb_size);
- more_data = hls_coding_quadtree(lc, x_ctb, y_ctb, s->ps.sps->log2_ctb_size, 0);
+ hls_sao_param(lc, pps, sps,
+ x_ctb >> sps->log2_ctb_size, y_ctb >> sps->log2_ctb_size);
+ more_data = hls_coding_quadtree(lc, pps, sps, x_ctb, y_ctb, sps->log2_ctb_size, 0);
if (more_data < 0) {
ret = more_data;
@@ -2645,26 +2703,26 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
ctb_addr_ts++;
- ff_hevc_save_states(lc, s->ps.pps, ctb_addr_ts);
+ ff_hevc_save_states(lc, pps, ctb_addr_ts);
ff_thread_report_progress2(s->avctx, ctb_row, thread, 1);
- ff_hevc_hls_filters(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
+ ff_hevc_hls_filters(lc, pps, x_ctb, y_ctb, ctb_size);
- if (!more_data && (x_ctb+ctb_size) < s->ps.sps->width && ctb_row != s->sh.num_entry_point_offsets) {
+ if (!more_data && (x_ctb+ctb_size) < sps->width && ctb_row != s->sh.num_entry_point_offsets) {
/* Casting const away here is safe, because it is an atomic operation. */
atomic_store((atomic_int*)&s->wpp_err, 1);
ff_thread_report_progress2(s->avctx, ctb_row ,thread, SHIFT_CTB_WPP);
return 0;
}
- if ((x_ctb+ctb_size) >= s->ps.sps->width && (y_ctb+ctb_size) >= s->ps.sps->height ) {
- ff_hevc_hls_filter(lc, s->ps.pps, x_ctb, y_ctb, ctb_size);
+ if ((x_ctb+ctb_size) >= sps->width && (y_ctb+ctb_size) >= sps->height ) {
+ ff_hevc_hls_filter(lc, pps, x_ctb, y_ctb, ctb_size);
ff_thread_report_progress2(s->avctx, ctb_row , thread, SHIFT_CTB_WPP);
return ctb_addr_ts;
}
- ctb_addr_rs = s->ps.pps->ctb_addr_ts_to_rs[ctb_addr_ts];
+ ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
x_ctb+=ctb_size;
- if(x_ctb >= s->ps.sps->width) {
+ if(x_ctb >= sps->width) {
break;
}
}
@@ -2681,6 +2739,8 @@ error:
static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
{
+ const HEVCPPS *const pps = s->ps.pps;
+ const HEVCSPS *const sps = pps->sps;
const uint8_t *data = nal->data;
int length = nal->size;
int *ret;
@@ -2688,10 +2748,10 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
int64_t startheader, cmpt = 0;
int i, j, res = 0;
- if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * s->ps.sps->ctb_width >= s->ps.sps->ctb_width * s->ps.sps->ctb_height) {
+ if (s->sh.slice_ctb_addr_rs + s->sh.num_entry_point_offsets * sps->ctb_width >= sps->ctb_width * sps->ctb_height) {
av_log(s->avctx, AV_LOG_ERROR, "WPP ctb addresses are wrong (%d %d %d %d)\n",
s->sh.slice_ctb_addr_rs, s->sh.num_entry_point_offsets,
- s->ps.sps->ctb_width, s->ps.sps->ctb_height
+ sps->ctb_width, sps->ctb_height
);
return AVERROR_INVALIDDATA;
}
@@ -2769,7 +2829,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
if (!ret)
return AVERROR(ENOMEM);
- if (s->ps.pps->entropy_coding_sync_enabled_flag)
+ if (pps->entropy_coding_sync_enabled_flag)
s->avctx->execute2(s->avctx, hls_decode_entry_wpp, s->local_ctx, ret, s->sh.num_entry_point_offsets + 1);
for (i = 0; i <= s->sh.num_entry_point_offsets; i++)
@@ -2868,14 +2928,16 @@ static int set_side_data(HEVCContext *s)
static int hevc_frame_start(HEVCContext *s)
{
- int pic_size_in_ctb = ((s->ps.sps->width >> s->ps.sps->log2_min_cb_size) + 1) *
- ((s->ps.sps->height >> s->ps.sps->log2_min_cb_size) + 1);
+ const HEVCPPS *const pps = s->ps.pps;
+ const HEVCSPS *const sps = pps->sps;
+ int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
+ ((sps->height >> sps->log2_min_cb_size) + 1);
int ret;
memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
memset(s->vertical_bs, 0, s->bs_width * s->bs_height);
- memset(s->cbf_luma, 0, s->ps.sps->min_tb_width * s->ps.sps->min_tb_height);
- memset(s->is_pcm, 0, (s->ps.sps->min_pu_width + 1) * (s->ps.sps->min_pu_height + 1));
+ memset(s->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
+ memset(s->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address));
s->is_decoded = 0;
@@ -2883,8 +2945,8 @@ static int hevc_frame_start(HEVCContext *s)
s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
- if (s->ps.pps->tiles_enabled_flag)
- s->local_ctx[0].end_of_tiles_x = s->ps.pps->column_width[0] << s->ps.sps->log2_ctb_size;
+ if (pps->tiles_enabled_flag)
+ s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
ret = ff_hevc_set_new_ref(s, s->poc);
if (ret < 0)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 12/39] lavc/hevcdec: move active PPS from HEVCParamSets to HEVCContext
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (9 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 11/39] lavc/hevcdec: " Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 13/39] lavc/hevcdec: drop an always-zero variable Anton Khirnov
` (26 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
"Currently active PPS" is a property of the decoding process, not of the
list of available parameter sets.
---
libavcodec/dxva2_hevc.c | 8 ++++----
libavcodec/hevc/hevcdec.c | 19 ++++++++++++-------
libavcodec/hevc/hevcdec.h | 1 +
libavcodec/hevc/ps.c | 12 ++----------
libavcodec/hevc/ps.h | 1 -
libavcodec/hevc/refs.c | 12 ++++++------
libavcodec/nvdec_hevc.c | 10 +++++-----
libavcodec/vaapi_hevc.c | 12 ++++++------
libavcodec/vdpau_hevc.c | 4 ++--
libavcodec/videotoolbox.c | 6 +++---
libavcodec/vulkan_hevc.c | 8 ++++----
11 files changed, 45 insertions(+), 48 deletions(-)
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 2f4073edd6..bd2c6f72a4 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -62,8 +62,8 @@ void ff_dxva2_hevc_fill_picture_parameters(const AVCodecContext *avctx, AVDXVACo
{
const HEVCContext *h = avctx->priv_data;
const HEVCFrame *current_picture = h->cur_frame;
- const HEVCSPS *sps = h->ps.sps;
- const HEVCPPS *pps = h->ps.pps;
+ const HEVCPPS *pps = h->pps;
+ const HEVCSPS *sps = pps->sps;
int i, j;
memset(pp, 0, sizeof(*pp));
@@ -205,8 +205,8 @@ void ff_dxva2_hevc_fill_scaling_lists(const AVCodecContext *avctx, AVDXVAContext
{
const HEVCContext *h = avctx->priv_data;
unsigned i, j, pos;
- const ScalingList *sl = h->ps.pps->scaling_list_data_present_flag ?
- &h->ps.pps->scaling_list : &h->ps.sps->scaling_list;
+ const ScalingList *sl = h->pps->scaling_list_data_present_flag ?
+ &h->pps->scaling_list : &h->pps->sps->scaling_list;
memset(qm, 0, sizeof(*qm));
for (i = 0; i < 6; i++) {
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 14b9a2a844..6dda923df5 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -618,12 +618,12 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
if (!sh->first_slice_in_pic_flag &&
- s->ps.pps != s->ps.pps_list[sh->pps_id]) {
+ s->pps != s->ps.pps_list[sh->pps_id]) {
av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
return AVERROR_INVALIDDATA;
}
- s->ps.pps = s->ps.pps_list[sh->pps_id];
- pps = s->ps.pps;
+ ff_refstruct_replace(&s->pps, s->ps.pps_list[sh->pps_id]);
+ pps = s->pps;
sps = pps->sps;
if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
@@ -2588,7 +2588,7 @@ static void hls_decode_neighbour(HEVCLocalContext *lc,
static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
{
HEVCLocalContext *const lc = &s->local_ctx[0];
- const HEVCPPS *const pps = s->ps.pps;
+ const HEVCPPS *const pps = s->pps;
const HEVCSPS *const sps = pps->sps;
const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
const size_t slice_size = gb->buffer_end - gb->buffer - s->sh.data_offset;
@@ -2656,7 +2656,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
{
HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id];
const HEVCContext *const s = lc->parent;
- const HEVCPPS *const pps = s->ps.pps;
+ const HEVCPPS *const pps = s->pps;
const HEVCSPS *const sps = pps->sps;
int ctb_size = 1 << sps->log2_ctb_size;
int more_data = 1;
@@ -2739,7 +2739,7 @@ error:
static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
{
- const HEVCPPS *const pps = s->ps.pps;
+ const HEVCPPS *const pps = s->pps;
const HEVCSPS *const sps = pps->sps;
const uint8_t *data = nal->data;
int length = nal->size;
@@ -2928,7 +2928,7 @@ static int set_side_data(HEVCContext *s)
static int hevc_frame_start(HEVCContext *s)
{
- const HEVCPPS *const pps = s->ps.pps;
+ const HEVCPPS *const pps = s->pps;
const HEVCSPS *const sps = pps->sps;
int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
((sps->height >> sps->log2_min_cb_size) + 1);
@@ -3510,6 +3510,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
pic_arrays_free(s);
+ ff_refstruct_unref(&s->pps);
+
ff_dovi_ctx_unref(&s->dovi_ctx);
av_buffer_unref(&s->rpu_buf);
@@ -3611,6 +3613,9 @@ static int hevc_update_thread_context(AVCodecContext *dst,
for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++)
ff_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]);
+ // PPS do not persist between frames
+ ff_refstruct_unref(&s->pps);
+
if (s->ps.sps != s0->ps.sps)
if ((ret = set_sps(s, s0->ps.sps, src->pix_fmt)) < 0)
return ret;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 3d1a36ecd4..3b7442e5c1 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -473,6 +473,7 @@ typedef struct HEVCContext {
///< candidate references for the current frame
RefPicList rps[5];
+ const HEVCPPS *pps; ///< RefStruct reference
SliceHeader sh;
SAOParams *sao;
DBParams *deblock;
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index eabed69b94..c02fc8b6c3 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -61,13 +61,6 @@ static const uint8_t hevc_sub_height_c[] = {
1, 2, 1, 1
};
-static void remove_pps(HEVCParamSets *s, int id)
-{
- if (s->pps == s->pps_list[id])
- s->pps = NULL;
- ff_refstruct_unref(&s->pps_list[id]);
-}
-
static void remove_sps(HEVCParamSets *s, int id)
{
int i;
@@ -78,7 +71,7 @@ static void remove_sps(HEVCParamSets *s, int id)
/* drop all PPS that depend on this SPS */
for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++)
if (s->pps_list[i] && s->pps_list[i]->sps_id == id)
- remove_pps(s, i);
+ ff_refstruct_unref(&s->pps_list[i]);
av_assert0(!(s->sps_list[id] && s->sps == s->sps_list[id]));
ff_refstruct_unref(&s->sps_list[id]);
@@ -2035,7 +2028,7 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
"Overread PPS by %d bits\n", -get_bits_left(gb));
}
- remove_pps(ps, pps_id);
+ ff_refstruct_unref(&ps->pps_list[pps_id]);
ps->pps_list[pps_id] = pps;
return 0;
@@ -2057,7 +2050,6 @@ void ff_hevc_ps_uninit(HEVCParamSets *ps)
ff_refstruct_unref(&ps->pps_list[i]);
ps->sps = NULL;
- ps->pps = NULL;
ps->vps = NULL;
}
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index fc10876756..17395c5510 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -451,7 +451,6 @@ typedef struct HEVCParamSets {
/* currently active parameter sets */
const HEVCVPS *vps;
const HEVCSPS *sps;
- const HEVCPPS *pps;
} HEVCParamSets;
/**
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index 39ce70ca39..31fcd49d69 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -54,7 +54,7 @@ const RefPicList *ff_hevc_get_ref_list(const HEVCContext *s,
int x_cb = x0 >> s->ps.sps->log2_ctb_size;
int y_cb = y0 >> s->ps.sps->log2_ctb_size;
int pic_width_cb = s->ps.sps->ctb_width;
- int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
+ int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[y_cb * pic_width_cb + x_cb];
return &ref->rpl_tab[ctb_addr_ts]->refPicList[0];
}
@@ -283,7 +283,7 @@ static int init_slice_rpl(HEVCContext *s)
{
HEVCFrame *frame = s->cur_frame;
int ctb_count = frame->ctb_count;
- int ctb_addr_ts = s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
+ int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[s->sh.slice_segment_addr];
int i;
if (s->slice_idx >= frame->nb_rpl_elems)
@@ -310,7 +310,7 @@ int ff_hevc_slice_rpl(HEVCContext *s)
return ret;
if (!(s->rps[ST_CURR_BEF].nb_refs + s->rps[ST_CURR_AFT].nb_refs +
- s->rps[LT_CURR].nb_refs) && !s->ps.pps->pps_curr_pic_ref_enabled_flag) {
+ s->rps[LT_CURR].nb_refs) && !s->pps->pps_curr_pic_ref_enabled_flag) {
av_log(s->avctx, AV_LOG_ERROR, "Zero refs in the frame RPS.\n");
return AVERROR_INVALIDDATA;
}
@@ -338,7 +338,7 @@ int ff_hevc_slice_rpl(HEVCContext *s)
}
}
// Construct RefPicList0, RefPicList1 (8-8, 8-10)
- if (s->ps.pps->pps_curr_pic_ref_enabled_flag && rpl_tmp.nb_refs < HEVC_MAX_REFS) {
+ if (s->pps->pps_curr_pic_ref_enabled_flag && rpl_tmp.nb_refs < HEVC_MAX_REFS) {
rpl_tmp.list[rpl_tmp.nb_refs] = s->cur_frame->poc;
rpl_tmp.ref[rpl_tmp.nb_refs] = s->cur_frame;
rpl_tmp.isLongTerm[rpl_tmp.nb_refs] = 1;
@@ -367,7 +367,7 @@ int ff_hevc_slice_rpl(HEVCContext *s)
}
// 8-9
- if (s->ps.pps->pps_curr_pic_ref_enabled_flag &&
+ if (s->pps->pps_curr_pic_ref_enabled_flag &&
!sh->rpl_modification_flag[list_idx] &&
rpl_tmp.nb_refs > sh->nb_refs[L0]) {
rpl->list[sh->nb_refs[L0] - 1] = s->cur_frame->poc;
@@ -545,7 +545,7 @@ int ff_hevc_frame_nb_refs(const HEVCContext *s)
ret += !!long_rps->used[i];
}
- if (s->ps.pps->pps_curr_pic_ref_enabled_flag)
+ if (s->pps->pps_curr_pic_ref_enabled_flag)
ret++;
return ret;
diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c
index 1d23f2ab56..0bebca7568 100644
--- a/libavcodec/nvdec_hevc.c
+++ b/libavcodec/nvdec_hevc.c
@@ -44,8 +44,8 @@ static void dpb_add(CUVIDHEVCPICPARAMS *pp, int idx, const HEVCFrame *src)
static void fill_scaling_lists(CUVIDHEVCPICPARAMS *ppc, const HEVCContext *s)
{
- const ScalingList *sl = s->ps.pps->scaling_list_data_present_flag ?
- &s->ps.pps->scaling_list : &s->ps.sps->scaling_list;
+ const ScalingList *sl = s->pps->scaling_list_data_present_flag ?
+ &s->pps->scaling_list : &s->pps->sps->scaling_list;
int i, j, pos;
for (i = 0; i < 6; i++) {
@@ -73,8 +73,8 @@ static int nvdec_hevc_start_frame(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
const HEVCContext *s = avctx->priv_data;
- const HEVCPPS *pps = s->ps.pps;
- const HEVCSPS *sps = s->ps.sps;
+ const HEVCPPS *pps = s->pps;
+ const HEVCSPS *sps = pps->sps;
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
CUVIDPICPARAMS *pp = &ctx->pic_params;
@@ -300,7 +300,7 @@ static int nvdec_hevc_frame_params(AVCodecContext *avctx,
AVBufferRef *hw_frames_ctx)
{
const HEVCContext *s = avctx->priv_data;
- const HEVCSPS *sps = s->ps.sps;
+ const HEVCSPS *sps = s->pps->sps;
return ff_nvdec_frame_params(avctx, hw_frames_ctx, sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering + 1, 1);
}
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 051762bfef..ad4cd35b26 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -90,7 +90,7 @@ static int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
return VA_PICTURE_HEVC_RPS_LT_CURR;
}
- if (h->ps.pps->pps_curr_pic_ref_enabled_flag && current_picture->poc == pic->poc)
+ if (h->pps->pps_curr_pic_ref_enabled_flag && current_picture->poc == pic->poc)
return VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
return 0;
@@ -105,7 +105,7 @@ static void fill_vaapi_reference_frames(const HEVCContext *h, VAPictureParameter
const HEVCFrame *frame = NULL;
while (!frame && j < FF_ARRAY_ELEMS(h->DPB)) {
- if ((&h->DPB[j] != current_picture || h->ps.pps->pps_curr_pic_ref_enabled_flag) &&
+ if ((&h->DPB[j] != current_picture || h->pps->pps_curr_pic_ref_enabled_flag) &&
(h->DPB[j].flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF)))
frame = &h->DPB[j];
j++;
@@ -126,8 +126,8 @@ static int vaapi_hevc_start_frame(AVCodecContext *avctx,
{
const HEVCContext *h = avctx->priv_data;
VAAPIDecodePictureHEVC *pic = h->cur_frame->hwaccel_picture_private;
- const HEVCSPS *sps = h->ps.sps;
- const HEVCPPS *pps = h->ps.pps;
+ const HEVCPPS *pps = h->pps;
+ const HEVCSPS *sps = pps->sps;
const ScalingList *scaling_list = NULL;
int pic_param_size, err, i;
@@ -399,8 +399,8 @@ static void fill_pred_weight_table(AVCodecContext *avctx,
slice_param->luma_log2_weight_denom = 0;
if (sh->slice_type == HEVC_SLICE_I ||
- (sh->slice_type == HEVC_SLICE_P && !h->ps.pps->weighted_pred_flag) ||
- (sh->slice_type == HEVC_SLICE_B && !h->ps.pps->weighted_bipred_flag))
+ (sh->slice_type == HEVC_SLICE_P && !h->pps->weighted_pred_flag) ||
+ (sh->slice_type == HEVC_SLICE_B && !h->pps->weighted_bipred_flag))
return;
slice_param->luma_log2_weight_denom = sh->luma_log2_weight_denom;
diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c
index f7cf1bd9c0..3db7ec156a 100644
--- a/libavcodec/vdpau_hevc.c
+++ b/libavcodec/vdpau_hevc.c
@@ -43,8 +43,8 @@ static int vdpau_hevc_start_frame(AVCodecContext *avctx,
VdpPictureInfoHEVC444 *info2 = &pic_ctx->info.hevc_444;
#endif
- const HEVCSPS *sps = h->ps.sps;
- const HEVCPPS *pps = h->ps.pps;
+ const HEVCPPS *pps = h->pps;
+ const HEVCSPS *sps = pps->sps;
const SliceHeader *sh = &h->sh;
const ScalingList *sl = pps->scaling_list_data_present_flag ?
&pps->scaling_list : &sps->scaling_list;
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index dcaddf944e..8e50bbb422 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -233,9 +233,9 @@ CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx)
{
HEVCContext *h = avctx->priv_data;
int i, num_vps = 0, num_sps = 0, num_pps = 0;
- const HEVCVPS *vps = h->ps.vps;
- const HEVCSPS *sps = h->ps.sps;
- const HEVCPPS *pps = h->ps.pps;
+ const HEVCPPS *pps = h->pps;
+ const HEVCSPS *sps = pps->sps;
+ const HEVCVPS *vps = sps->vps;
PTLCommon ptlc = vps->ptl.general_ptl;
VUI vui = sps->vui;
uint8_t parallelismType;
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index aa721493b0..33a6326297 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -735,8 +735,8 @@ static int vk_hevc_start_frame(AVCodecContext *avctx,
FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
FFVulkanDecodePicture *vp = &hp->vp;
- const HEVCSPS *sps = h->ps.sps;
- const HEVCPPS *pps = h->ps.pps;
+ const HEVCPPS *pps = h->pps;
+ const HEVCSPS *sps = pps->sps;
int nb_refs = 0;
if (!dec->session_params) {
@@ -878,8 +878,8 @@ static int vk_hevc_end_frame(AVCodecContext *avctx)
return 0;
if (!dec->session_params) {
- const HEVCSPS *sps = h->ps.sps;
- const HEVCPPS *pps = h->ps.pps;
+ const HEVCPPS *pps = h->pps;
+ const HEVCSPS *sps = pps->sps;
if (!pps) {
unsigned int pps_id = h->sh.pps_id;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 13/39] lavc/hevcdec: drop an always-zero variable
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (10 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 12/39] lavc/hevcdec: move active PPS from HEVCParamSets to HEVCContext Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 14/39] lavc/hevcdec: only ignore INVALIDDATA in decode_nal_unit() Anton Khirnov
` (25 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/hevc/hevcdec.c | 9 ++-------
libavcodec/hevc/hevcdec.h | 1 -
2 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 6dda923df5..d599373c9d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -984,13 +984,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
unsigned val = get_bits_long(gb, offset_len);
sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
}
- if (s->threads_number > 1 && (pps->num_tile_rows > 1 || pps->num_tile_columns > 1)) {
- s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here
+ if (s->threads_number > 1 && (pps->num_tile_rows > 1 || pps->num_tile_columns > 1))
s->threads_number = 1;
- } else
- s->enable_parallel_tiles = 0;
- } else
- s->enable_parallel_tiles = 0;
+ }
}
if (pps->slice_header_extension_present_flag) {
@@ -3697,7 +3693,6 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
if (ret < 0)
return ret;
- s->enable_parallel_tiles = 0;
s->sei.picture_timing.picture_struct = 0;
s->eos = 1;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 3b7442e5c1..c58ce05639 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -532,7 +532,6 @@ typedef struct HEVCContext {
/** The target for the common_cabac_state of the local contexts. */
HEVCCABACState cabac;
- int enable_parallel_tiles;
atomic_int wpp_err;
const uint8_t *data;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 14/39] lavc/hevcdec: only ignore INVALIDDATA in decode_nal_unit()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (11 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 13/39] lavc/hevcdec: drop an always-zero variable Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 15/39] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table() Anton Khirnov
` (24 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
All other errors should cause a failure, regardless of the value of
err_recognition. Also, print a warning message when skipping invalid NAL
units.
---
libavcodec/hevc/hevcdec.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d599373c9d..2c26d397df 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3206,9 +3206,13 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
return 0;
fail:
- if (s->avctx->err_recognition & AV_EF_EXPLODE)
- return ret;
- return 0;
+ if (ret == AVERROR_INVALIDDATA &&
+ !(s->avctx->err_recognition & AV_EF_EXPLODE)) {
+ av_log(s->avctx, AV_LOG_WARNING,
+ "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
+ return 0;
+ }
+ return ret;
}
static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 15/39] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (12 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 14/39] lavc/hevcdec: only ignore INVALIDDATA in decode_nal_unit() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 16/39] lavc/hevcdec: do not pass HEVCContext to decode_lt_rps() Anton Khirnov
` (23 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
And replace the HEVCContext* parameter by void *logctx.
Makes it clear that only SliceHeader is modified by this function.
---
libavcodec/hevc/hevcdec.c | 75 ++++++++++++++++++++-------------------
1 file changed, 38 insertions(+), 37 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 2c26d397df..6a9de79dcd 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -143,7 +143,8 @@ fail:
return AVERROR(ENOMEM);
}
-static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *gb)
+static int pred_weight_table(SliceHeader *sh, void *logctx,
+ const HEVCSPS *sps, GetBitContext *gb)
{
int i = 0;
int j = 0;
@@ -155,40 +156,40 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *
luma_log2_weight_denom = get_ue_golomb_long(gb);
if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
- av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
+ av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
return AVERROR_INVALIDDATA;
}
- s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
+ sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
if (sps->chroma_format_idc != 0) {
int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
- av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
+ av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
return AVERROR_INVALIDDATA;
}
- s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom;
+ sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
}
- for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+ for (i = 0; i < sh->nb_refs[L0]; i++) {
luma_weight_l0_flag[i] = get_bits1(gb);
if (!luma_weight_l0_flag[i]) {
- s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom;
- s->sh.luma_offset_l0[i] = 0;
+ sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
+ sh->luma_offset_l0[i] = 0;
}
}
if (sps->chroma_format_idc != 0) {
- for (i = 0; i < s->sh.nb_refs[L0]; i++)
+ for (i = 0; i < sh->nb_refs[L0]; i++)
chroma_weight_l0_flag[i] = get_bits1(gb);
} else {
- for (i = 0; i < s->sh.nb_refs[L0]; i++)
+ for (i = 0; i < sh->nb_refs[L0]; i++)
chroma_weight_l0_flag[i] = 0;
}
- for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+ for (i = 0; i < sh->nb_refs[L0]; i++) {
if (luma_weight_l0_flag[i]) {
int delta_luma_weight_l0 = get_se_golomb(gb);
if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
return AVERROR_INVALIDDATA;
- s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0;
- s->sh.luma_offset_l0[i] = get_se_golomb(gb);
+ sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
+ sh->luma_offset_l0[i] = get_se_golomb(gb);
}
if (chroma_weight_l0_flag[i]) {
for (j = 0; j < 2; j++) {
@@ -200,39 +201,39 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *
return AVERROR_INVALIDDATA;
}
- s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
- s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j])
- >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+ sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
+ sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
+ >> sh->chroma_log2_weight_denom) + 128), -128, 127);
}
} else {
- s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom;
- s->sh.chroma_offset_l0[i][0] = 0;
- s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom;
- s->sh.chroma_offset_l0[i][1] = 0;
+ sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
+ sh->chroma_offset_l0[i][0] = 0;
+ sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
+ sh->chroma_offset_l0[i][1] = 0;
}
}
- if (s->sh.slice_type == HEVC_SLICE_B) {
- for (i = 0; i < s->sh.nb_refs[L1]; i++) {
+ if (sh->slice_type == HEVC_SLICE_B) {
+ for (i = 0; i < sh->nb_refs[L1]; i++) {
luma_weight_l1_flag[i] = get_bits1(gb);
if (!luma_weight_l1_flag[i]) {
- s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom;
- s->sh.luma_offset_l1[i] = 0;
+ sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
+ sh->luma_offset_l1[i] = 0;
}
}
if (sps->chroma_format_idc != 0) {
- for (i = 0; i < s->sh.nb_refs[L1]; i++)
+ for (i = 0; i < sh->nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = get_bits1(gb);
} else {
- for (i = 0; i < s->sh.nb_refs[L1]; i++)
+ for (i = 0; i < sh->nb_refs[L1]; i++)
chroma_weight_l1_flag[i] = 0;
}
- for (i = 0; i < s->sh.nb_refs[L1]; i++) {
+ for (i = 0; i < sh->nb_refs[L1]; i++) {
if (luma_weight_l1_flag[i]) {
int delta_luma_weight_l1 = get_se_golomb(gb);
if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
return AVERROR_INVALIDDATA;
- s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1;
- s->sh.luma_offset_l1[i] = get_se_golomb(gb);
+ sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
+ sh->luma_offset_l1[i] = get_se_golomb(gb);
}
if (chroma_weight_l1_flag[i]) {
for (j = 0; j < 2; j++) {
@@ -244,15 +245,15 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *
return AVERROR_INVALIDDATA;
}
- s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
- s->sh.chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j])
- >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+ sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
+ sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
+ >> sh->chroma_log2_weight_denom) + 128), -128, 127);
}
} else {
- s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom;
- s->sh.chroma_offset_l1[i][0] = 0;
- s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom;
- s->sh.chroma_offset_l1[i][1] = 0;
+ sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
+ sh->chroma_offset_l1[i][0] = 0;
+ sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
+ sh->chroma_offset_l1[i][1] = 0;
}
}
}
@@ -857,7 +858,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if ((pps->weighted_pred_flag && sh->slice_type == HEVC_SLICE_P) ||
(pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
- int ret = pred_weight_table(s, sps, gb);
+ int ret = pred_weight_table(sh, s->avctx, sps, gb);
if (ret < 0)
return ret;
}
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 16/39] lavc/hevcdec: do not pass HEVCContext to decode_lt_rps()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (13 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 15/39] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 17/39] lavc/hevcdec: move pocTid0 computation to hevc_frame_start() Anton Khirnov
` (22 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Pass the two numbers needed from it explicitly.
Makes it clear that HEVCContext is not modified by this function.
---
libavcodec/hevc/hevcdec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 6a9de79dcd..960a06c773 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -260,8 +260,8 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
return 0;
}
-static int decode_lt_rps(HEVCContext *s, const HEVCSPS *sps, LongTermRPS *rps,
- GetBitContext *gb)
+static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
+ GetBitContext *gb, int cur_poc, int poc_lsb)
{
int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
int prev_delta_msb = 0;
@@ -306,7 +306,7 @@ static int decode_lt_rps(HEVCContext *s, const HEVCSPS *sps, LongTermRPS *rps,
if (i && i != nb_sps)
delta += prev_delta_msb;
- poc = rps->poc[i] + s->poc - delta * max_poc_lsb - s->sh.pic_order_cnt_lsb;
+ poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
if (poc != (int32_t)poc)
return AVERROR_INVALIDDATA;
rps->poc[i] = poc;
@@ -744,7 +744,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
pos = get_bits_left(gb);
- ret = decode_lt_rps(s, sps, &sh->long_term_rps, gb);
+ ret = decode_lt_rps(sps, &sh->long_term_rps, gb, s->poc, sh->pic_order_cnt_lsb);
if (ret < 0) {
av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 17/39] lavc/hevcdec: move pocTid0 computation to hevc_frame_start()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (14 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 16/39] lavc/hevcdec: do not pass HEVCContext to decode_lt_rps() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 18/39] lavc/hevcdec: only call export_stream_params_from_sei() once per frame Anton Khirnov
` (21 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
It is only done once per frame. Also, rename the variable to poc_tid0 to
be consistent with our naming conventions.
---
libavcodec/hevc/hevcdec.c | 26 +++++++++++++-------------
libavcodec/hevc/hevcdec.h | 2 +-
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 960a06c773..dd3c188418 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -711,7 +711,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
int poc, pos;
sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
- poc = ff_hevc_compute_poc(sps, s->pocTid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
+ poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
if (!sh->first_slice_in_pic_flag && poc != s->poc) {
av_log(s->avctx, AV_LOG_WARNING,
"Ignoring POC change between slices: %d -> %d\n", s->poc, poc);
@@ -766,17 +766,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->slice_temporal_mvp_enabled_flag = 0;
}
- /* 8.3.1 */
- if (sh->first_slice_in_pic_flag && s->temporal_id == 0 &&
- 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 (sps->sao_enabled) {
sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
if (sps->chroma_format_idc) {
@@ -2942,6 +2931,17 @@ static int hevc_frame_start(HEVCContext *s)
s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
+ /* 8.3.1 */
+ if (s->temporal_id == 0 &&
+ 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->poc_tid0 = s->poc;
+
if (pps->tiles_enabled_flag)
s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size;
@@ -3623,7 +3623,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
s->seq_decode = s0->seq_decode;
s->seq_output = s0->seq_output;
- s->pocTid0 = s0->pocTid0;
+ s->poc_tid0 = s0->poc_tid0;
s->max_ra = s0->max_ra;
s->eos = s0->eos;
s->no_rasl_output_flag = s0->no_rasl_output_flag;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index c58ce05639..4b28494366 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -483,7 +483,7 @@ typedef struct HEVCContext {
HEVCFrame *collocated_ref;
HEVCFrame DPB[32];
int poc;
- int pocTid0;
+ int poc_tid0;
int slice_idx; ///< number of the slice being currently decoded
int eos; ///< current packet contains an EOS/EOB NAL
int last_eos; ///< last packet contains an EOS/EOB NAL
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 18/39] lavc/hevcdec: only call export_stream_params_from_sei() once per frame
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (15 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 17/39] lavc/hevcdec: move pocTid0 computation to hevc_frame_start() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 19/39] lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs() Anton Khirnov
` (20 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Not once per each slice header, as it makes no sense and may cause races
with frame threading.
---
libavcodec/hevc/hevcdec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index dd3c188418..bf6e93ba1b 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -648,10 +648,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
s->max_ra = INT_MAX;
}
- ret = export_stream_params_from_sei(s);
- if (ret < 0)
- return ret;
-
sh->dependent_slice_segment_flag = 0;
if (!sh->first_slice_in_pic_flag) {
int slice_address_length;
@@ -2965,6 +2961,10 @@ static int hevc_frame_start(HEVCContext *s)
!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
!s->avctx->hwaccel;
+ ret = export_stream_params_from_sei(s);
+ if (ret < 0)
+ return ret;
+
ret = set_side_data(s);
if (ret < 0)
goto fail;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 19/39] lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (16 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 18/39] lavc/hevcdec: only call export_stream_params_from_sei() once per frame Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 20/39] lavc/hevcdec: only set no_rasl_output_flag for IRAP frames Anton Khirnov
` (19 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Pass the only things required from it - slice header and PPS -
explicitly.
Will be useful in the following commits to avoid mofiying HEVCContext in
hls_slice_header().
---
libavcodec/hevc/hevcdec.c | 2 +-
libavcodec/hevc/hevcdec.h | 2 +-
libavcodec/hevc/refs.c | 8 ++++----
libavcodec/nvdec_hevc.c | 2 +-
libavcodec/vdpau_hevc.c | 2 +-
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index bf6e93ba1b..585a066426 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -795,7 +795,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->rpl_modification_flag[0] = 0;
sh->rpl_modification_flag[1] = 0;
- nb_refs = ff_hevc_frame_nb_refs(s);
+ nb_refs = ff_hevc_frame_nb_refs(sh, pps);
if (!nb_refs) {
av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P or B slices.\n");
return AVERROR_INVALIDDATA;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 4b28494366..5eaebd3584 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -614,7 +614,7 @@ int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int idx);
/**
* Get the number of candidate references for the current frame.
*/
-int ff_hevc_frame_nb_refs(const HEVCContext *s);
+int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps);
int ff_hevc_set_new_ref(HEVCContext *s, int poc);
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index 31fcd49d69..5bd5eab9f1 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -526,12 +526,12 @@ fail:
return ret;
}
-int ff_hevc_frame_nb_refs(const HEVCContext *s)
+int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps)
{
int ret = 0;
int i;
- const ShortTermRPS *rps = s->sh.short_term_rps;
- const LongTermRPS *long_rps = &s->sh.long_term_rps;
+ const ShortTermRPS *rps = sh->short_term_rps;
+ const LongTermRPS *long_rps = &sh->long_term_rps;
if (rps) {
for (i = 0; i < rps->num_negative_pics; i++)
@@ -545,7 +545,7 @@ int ff_hevc_frame_nb_refs(const HEVCContext *s)
ret += !!long_rps->used[i];
}
- if (s->pps->pps_curr_pic_ref_enabled_flag)
+ if (pps->pps_curr_pic_ref_enabled_flag)
ret++;
return ret;
diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c
index 0bebca7568..ce66ddcfb7 100644
--- a/libavcodec/nvdec_hevc.c
+++ b/libavcodec/nvdec_hevc.c
@@ -187,7 +187,7 @@ static int nvdec_hevc_start_frame(AVCodecContext *avctx,
.NumBitsForShortTermRPSInSlice = s->sh.short_term_rps ? s->sh.short_term_ref_pic_set_size : 0,
.NumDeltaPocsOfRefRpsIdx = s->sh.short_term_rps ? s->sh.short_term_rps->rps_idx_num_delta_pocs : 0,
- .NumPocTotalCurr = ff_hevc_frame_nb_refs(s),
+ .NumPocTotalCurr = ff_hevc_frame_nb_refs(&s->sh, pps),
.NumPocStCurrBefore = s->rps[ST_CURR_BEF].nb_refs,
.NumPocStCurrAfter = s->rps[ST_CURR_AFT].nb_refs,
.NumPocLtCurr = s->rps[LT_CURR].nb_refs,
diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c
index 3db7ec156a..b9e922ecfc 100644
--- a/libavcodec/vdpau_hevc.c
+++ b/libavcodec/vdpau_hevc.c
@@ -205,7 +205,7 @@ static int vdpau_hevc_start_frame(AVCodecContext *avctx,
}
}
/* See section 7.4.7.2 of the specification. */
- info->NumPocTotalCurr = ff_hevc_frame_nb_refs(h);
+ info->NumPocTotalCurr = ff_hevc_frame_nb_refs(&h->sh, pps);
if (sh->short_term_ref_pic_set_sps_flag == 0 && sh->short_term_rps) {
/* Corresponds to specification field, NumDeltaPocs[RefRpsIdx].
Only applicable when short_term_ref_pic_set_sps_flag == 0.
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 20/39] lavc/hevcdec: only set no_rasl_output_flag for IRAP frames
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (17 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 19/39] lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 21/39] lavc/hevcdec: output RASL frames based on the value of no_rasl_output_flag Anton Khirnov
` (18 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Its meaning is only specified for IRAP frames.
As it's currently never used otherwise, this should not change decoder
behaviour, but will be useful in future commits.
---
libavcodec/hevc/hevcdec.c | 4 +++-
libavcodec/hevc/hevcdec.h | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 585a066426..d444ea93f7 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2925,7 +2925,9 @@ static int hevc_frame_start(HEVCContext *s)
s->is_decoded = 0;
s->first_nal_type = s->nal_unit_type;
- s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
+ if (IS_IRAP(s))
+ s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
+ (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos);
/* 8.3.1 */
if (s->temporal_id == 0 &&
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 5eaebd3584..fa7caf9cf7 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -493,6 +493,7 @@ typedef struct HEVCContext {
int overlap;
int is_decoded;
+ // NoRaslOutputFlag associated with the last IRAP frame
int no_rasl_output_flag;
HEVCPredContext hpc;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 21/39] lavc/hevcdec: output RASL frames based on the value of no_rasl_output_flag
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (18 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 20/39] lavc/hevcdec: only set no_rasl_output_flag for IRAP frames Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number Anton Khirnov
` (17 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Instead of an ad-hoc scheme. Also, combine skipping RASL frames with
skip_frame handling - current code seems flawed as it only executes for
the first slice of a RASL frame and unnecessarily unsets is_decoded,
which should not be set at this point anyway..
Some RASL frames in fate-hevc-afd-tc-sei that were previously discarded
are now output.
---
libavcodec/hevc/hevcdec.c | 33 ++++---------------------------
libavcodec/hevc/hevcdec.h | 1 -
tests/ref/fate/hevc-afd-tc-sei | 36 ++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d444ea93f7..a57fa4e539 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -605,7 +605,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
- s->max_ra = INT_MAX;
if (IS_IDR(s))
ff_hevc_clear_refs(s);
}
@@ -645,7 +644,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
s->avctx->pix_fmt = pix_fmt;
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
- s->max_ra = INT_MAX;
}
sh->dependent_slice_segment_flag = 0;
@@ -3106,32 +3104,15 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
}
- if (
- (s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
+ if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
- (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s))) {
+ (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
+ ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
+ s->no_rasl_output_flag)) {
break;
}
if (s->sh.first_slice_in_pic_flag) {
- if (s->max_ra == INT_MAX) {
- if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) {
- s->max_ra = s->poc;
- } else {
- if (IS_IDR(s))
- s->max_ra = INT_MIN;
- }
- }
-
- 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 == HEVC_NAL_RASL_R && s->poc > s->max_ra)
- s->max_ra = INT_MIN;
- }
-
s->overlap ++;
ret = hevc_frame_start(s);
if (ret < 0)
@@ -3196,7 +3177,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
case HEVC_NAL_EOS_NUT:
case HEVC_NAL_EOB_NUT:
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
- s->max_ra = INT_MAX;
break;
case HEVC_NAL_AUD:
case HEVC_NAL_FD_NUT:
@@ -3572,8 +3552,6 @@ static av_cold int hevc_init_context(AVCodecContext *avctx)
return AVERROR(ENOMEM);
}
- s->max_ra = INT_MAX;
-
s->md5_ctx = av_md5_alloc();
if (!s->md5_ctx)
return AVERROR(ENOMEM);
@@ -3626,7 +3604,6 @@ static int hevc_update_thread_context(AVCodecContext *dst,
s->seq_decode = s0->seq_decode;
s->seq_output = s0->seq_output;
s->poc_tid0 = s0->poc_tid0;
- s->max_ra = s0->max_ra;
s->eos = s0->eos;
s->no_rasl_output_flag = s0->no_rasl_output_flag;
@@ -3640,7 +3617,6 @@ static int hevc_update_thread_context(AVCodecContext *dst,
if (s0->eos) {
s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
- s->max_ra = INT_MAX;
}
ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common);
@@ -3734,7 +3710,6 @@ static void hevc_decode_flush(AVCodecContext *avctx)
ff_hevc_reset_sei(&s->sei);
ff_dovi_ctx_flush(&s->dovi_ctx);
av_buffer_unref(&s->rpu_buf);
- s->max_ra = INT_MAX;
s->eos = 1;
if (FF_HW_HAS_CB(avctx, flush))
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index fa7caf9cf7..04eacca76d 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -487,7 +487,6 @@ typedef struct HEVCContext {
int slice_idx; ///< number of the slice being currently decoded
int eos; ///< current packet contains an EOS/EOB NAL
int last_eos; ///< last packet contains an EOS/EOB NAL
- int max_ra;
int bs_width;
int bs_height;
int overlap;
diff --git a/tests/ref/fate/hevc-afd-tc-sei b/tests/ref/fate/hevc-afd-tc-sei
index 27eb3fc8d7..735226745b 100644
--- a/tests/ref/fate/hevc-afd-tc-sei
+++ b/tests/ref/fate/hevc-afd-tc-sei
@@ -202,3 +202,39 @@ value=00:00:00:00
[/TIMECODE]
[/SIDE_DATA]
[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Active format description
+active_format=8
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=SMPTE 12-1 timecode
+[TIMECODE]
+value=00:00:00:00
+[/TIMECODE]
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Active format description
+active_format=8
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=SMPTE 12-1 timecode
+[TIMECODE]
+value=00:00:00:00
+[/TIMECODE]
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Active format description
+active_format=8
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=SMPTE 12-1 timecode
+[TIMECODE]
+value=00:00:00:00
+[/TIMECODE]
+[/SIDE_DATA]
+[/FRAME]
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (19 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 21/39] lavc/hevcdec: output RASL frames based on the value of no_rasl_output_flag Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-08 7:02 ` Christophe Gisquet
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number} Anton Khirnov
` (16 subsequent siblings)
37 siblings, 1 reply; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Pass this information explicitly instead.
---
libavcodec/hevc/cabac.c | 7 ++++---
libavcodec/hevc/hevcdec.c | 4 ++--
libavcodec/hevc/hevcdec.h | 3 ++-
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/hevc/cabac.c b/libavcodec/hevc/cabac.c
index 8708efc248..39ca7c0135 100644
--- a/libavcodec/hevc/cabac.c
+++ b/libavcodec/hevc/cabac.c
@@ -452,7 +452,8 @@ static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
}
int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
- int ctb_addr_ts, const uint8_t *data, size_t size)
+ int ctb_addr_ts, const uint8_t *data, size_t size,
+ int is_wpp)
{
const HEVCContext *const s = lc->parent;
const HEVCSPS *const sps = pps->sps;
@@ -479,7 +480,7 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
if (pps->tiles_enabled_flag &&
pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
int ret;
- if (s->threads_number == 1)
+ if (!is_wpp)
ret = cabac_reinit(lc);
else {
ret = ff_init_cabac_decoder(&lc->cc, data, size);
@@ -492,7 +493,7 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
if (ctb_addr_ts % sps->ctb_width == 0) {
int ret;
get_cabac_terminate(&lc->cc);
- if (s->threads_number == 1)
+ if (!is_wpp)
ret = cabac_reinit(lc);
else {
ret = ff_init_cabac_decoder(&lc->cc, data, size);
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a57fa4e539..e3773a6147 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2599,7 +2599,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> sps->log2_ctb_size)) << sps->log2_ctb_size;
hls_decode_neighbour(lc, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
- ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size);
+ ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 0);
if (ret < 0) {
s->tab_slice_address[ctb_addr_rs] = -1;
return ret;
@@ -2669,7 +2669,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
return 0;
}
- ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size);
+ ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
if (ret < 0)
goto error;
hls_sao_param(lc, pps, sps,
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 04eacca76d..22367602aa 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -579,7 +579,8 @@ int ff_hevc_slice_rpl(HEVCContext *s);
void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
int ctb_addr_ts);
int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
- int ctb_addr_ts, const uint8_t *data, size_t size);
+ int ctb_addr_ts, const uint8_t *data, size_t size,
+ int is_wpp);
int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc);
int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc);
int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc);
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number}
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (20 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-08 7:08 ` Christophe Gisquet
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 24/39] lavc/hevcdec: store slice header POC in SliceHeader Anton Khirnov
` (15 subsequent siblings)
37 siblings, 1 reply; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
They are useless duplicates of corresponding AVCodecContext fields.
---
libavcodec/hevc/filter.c | 6 +++---
libavcodec/hevc/hevcdec.c | 36 +++++++++++++-----------------------
libavcodec/hevc/hevcdec.h | 3 ---
libavcodec/hevc/mvs.c | 4 ++--
libavcodec/hevc/refs.c | 2 +-
5 files changed, 19 insertions(+), 32 deletions(-)
diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c
index 081b3a3898..56e354b486 100644
--- a/libavcodec/hevc/filter.c
+++ b/libavcodec/hevc/filter.c
@@ -892,15 +892,15 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, const HEVCPPS *pps,
sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y);
if (y && x_end) {
sao_filter_CTB(lc, s, pps, sps, x, y - ctb_size);
- if (s->threads_type & FF_THREAD_FRAME )
+ if (s->avctx->active_thread_type & FF_THREAD_FRAME )
ff_progress_frame_report(&s->cur_frame->tf, y);
}
if (x_end && y_end) {
sao_filter_CTB(lc, s, pps, sps, x , y);
- if (s->threads_type & FF_THREAD_FRAME )
+ if (s->avctx->active_thread_type & FF_THREAD_FRAME )
ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size);
}
- } else if (s->threads_type & FF_THREAD_FRAME && x_end)
+ } else if (s->avctx->active_thread_type & FF_THREAD_FRAME && x_end)
ff_progress_frame_report(&s->cur_frame->tf, y + ctb_size - 4);
}
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e3773a6147..f867fdbea5 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -968,8 +968,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
unsigned val = get_bits_long(gb, offset_len);
sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
}
- if (s->threads_number > 1 && (pps->num_tile_rows > 1 || pps->num_tile_columns > 1))
- s->threads_number = 1;
}
}
@@ -1870,7 +1868,7 @@ static void chroma_mc_bi(HEVCLocalContext *lc,
static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
const Mv *mv, int y0, int height)
{
- if (s->threads_type == FF_THREAD_FRAME ) {
+ if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
ff_progress_frame_await(&ref->tf, y);
@@ -2631,7 +2629,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
return ctb_addr_ts;
}
-static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
+static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist,
int job, int self_id)
{
HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id];
@@ -2643,7 +2641,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
int ctb_row = job;
int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + ctb_size - 1) >> sps->log2_ctb_size);
int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
- int thread = ctb_row % s->threads_number;
+ int thread = ctb_row % avctx->thread_count;
const uint8_t *data = s->data + s->sh.offset[ctb_row];
const size_t data_size = s->sh.size[ctb_row];
@@ -2736,8 +2734,8 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
return AVERROR_INVALIDDATA;
}
- if (s->threads_number > s->nb_local_ctx) {
- HEVCLocalContext *tmp = av_malloc_array(s->threads_number, sizeof(*s->local_ctx));
+ if (s->avctx->thread_count > s->nb_local_ctx) {
+ HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, sizeof(*s->local_ctx));
if (!tmp)
return AVERROR(ENOMEM);
@@ -2746,7 +2744,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
av_free(s->local_ctx);
s->local_ctx = tmp;
- for (unsigned i = s->nb_local_ctx; i < s->threads_number; i++) {
+ for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) {
tmp = &s->local_ctx[i];
memset(tmp, 0, sizeof(*tmp));
@@ -2756,7 +2754,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
tmp->common_cabac_state = &s->cabac;
}
- s->nb_local_ctx = s->threads_number;
+ s->nb_local_ctx = s->avctx->thread_count;
}
offset = s->sh.data_offset;
@@ -2795,7 +2793,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
s->data = data;
- for (i = 1; i < s->threads_number; i++) {
+ for (i = 1; i < s->nb_local_ctx; i++) {
s->local_ctx[i].first_qp_group = 1;
s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
}
@@ -3157,7 +3155,9 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
goto fail;
}
- if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0)
+ if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
+ s->sh.num_entry_point_offsets > 0 &&
+ s->pps->num_tile_rows == 1 && s->pps->num_tile_columns == 1)
ctb_addr_ts = hls_slice_data_wpp(s, nal);
else
ctb_addr_ts = hls_decode_entry(s, &gb);
@@ -3282,7 +3282,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
}
fail:
- if (s->cur_frame && s->threads_type == FF_THREAD_FRAME)
+ if (s->cur_frame && s->avctx->active_thread_type == FF_THREAD_FRAME)
ff_progress_frame_report(&s->cur_frame->tf, INT_MAX);
return ret;
@@ -3610,9 +3610,6 @@ static int hevc_update_thread_context(AVCodecContext *dst,
s->is_nalff = s0->is_nalff;
s->nal_length_size = s0->nal_length_size;
- s->threads_number = s0->threads_number;
- s->threads_type = s0->threads_type;
-
s->film_grain_warning_shown = s0->film_grain_warning_shown;
if (s0->eos) {
@@ -3660,17 +3657,10 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
int ret;
if (avctx->active_thread_type & FF_THREAD_SLICE) {
- s->threads_number = avctx->thread_count;
ret = ff_slice_thread_init_progress(avctx);
if (ret < 0)
return ret;
- } else
- s->threads_number = 1;
-
- if((avctx->active_thread_type & FF_THREAD_FRAME) && avctx->thread_count > 1)
- s->threads_type = FF_THREAD_FRAME;
- else
- s->threads_type = FF_THREAD_SLICE;
+ }
ret = hevc_init_context(avctx);
if (ret < 0)
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 22367602aa..75026a8deb 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -453,9 +453,6 @@ typedef struct HEVCContext {
HEVCLocalContext *local_ctx;
unsigned nb_local_ctx;
- uint8_t threads_type;
- uint8_t threads_number;
-
/** 1 if the independent slice segment header was successfully parsed */
uint8_t slice_initialized;
diff --git a/libavcodec/hevc/mvs.c b/libavcodec/hevc/mvs.c
index 3fd7be5b32..772fedceeb 100644
--- a/libavcodec/hevc/mvs.c
+++ b/libavcodec/hevc/mvs.c
@@ -248,7 +248,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, const HEVCSPS *sps,
x < sps->width) {
x &= ~15;
y &= ~15;
- if (s->threads_type == FF_THREAD_FRAME)
+ if (s->avctx->active_thread_type == FF_THREAD_FRAME)
ff_progress_frame_await(&ref->tf, y);
x_pu = x >> sps->log2_min_pu_size;
y_pu = y >> sps->log2_min_pu_size;
@@ -262,7 +262,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, const HEVCSPS *sps,
y = y0 + (nPbH >> 1);
x &= ~15;
y &= ~15;
- if (s->threads_type == FF_THREAD_FRAME)
+ if (s->avctx->active_thread_type == FF_THREAD_FRAME)
ff_progress_frame_await(&ref->tf, y);
x_pu = x >> sps->log2_min_pu_size;
y_pu = y >> sps->log2_min_pu_size;
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index 5bd5eab9f1..48fc4d27da 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -435,7 +435,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc)
frame->sequence = HEVC_SEQUENCE_COUNTER_INVALID;
frame->flags = 0;
- if (s->threads_type == FF_THREAD_FRAME)
+ if (s->avctx->active_thread_type == FF_THREAD_FRAME)
ff_progress_frame_report(&frame->tf, INT_MAX);
return frame;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 24/39] lavc/hevcdec: store slice header POC in SliceHeader
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (21 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number} Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 25/39] lavc/hevcdec: move a slice segment sanity check to hls_slice_header() Anton Khirnov
` (14 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Rather than decoding directly into HEVCContext.poc.
This is a step towards constifying HEVCContext in hls_slice_header().
---
libavcodec/hevc/hevcdec.c | 13 +++++++------
libavcodec/hevc/hevcdec.h | 1 +
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index f867fdbea5..df6d1565bc 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -706,14 +706,14 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
- if (!sh->first_slice_in_pic_flag && poc != s->poc) {
+ if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
av_log(s->avctx, AV_LOG_WARNING,
- "Ignoring POC change between slices: %d -> %d\n", s->poc, poc);
+ "Ignoring POC change between slices: %d -> %d\n", poc, sh->poc);
if (s->avctx->err_recognition & AV_EF_EXPLODE)
return AVERROR_INVALIDDATA;
- poc = s->poc;
+ poc = sh->poc;
}
- s->poc = poc;
+ sh->poc = poc;
sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
pos = get_bits_left(gb);
@@ -738,7 +738,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
pos = get_bits_left(gb);
- ret = decode_lt_rps(sps, &sh->long_term_rps, gb, s->poc, sh->pic_order_cnt_lsb);
+ ret = decode_lt_rps(sps, &sh->long_term_rps, gb, sh->poc, sh->pic_order_cnt_lsb);
if (ret < 0) {
av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
if (s->avctx->err_recognition & AV_EF_EXPLODE)
@@ -751,7 +751,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
else
sh->slice_temporal_mvp_enabled_flag = 0;
} else {
- s->poc = 0;
+ sh->poc = 0;
sh->pic_order_cnt_lsb = 0;
sh->short_term_ref_pic_set_sps_flag = 0;
sh->short_term_ref_pic_set_size = 0;
@@ -2920,6 +2920,7 @@ static int hevc_frame_start(HEVCContext *s)
s->is_decoded = 0;
s->first_nal_type = s->nal_unit_type;
+ s->poc = s->sh.poc;
if (IS_IRAP(s))
s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 75026a8deb..e47a7107c8 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -209,6 +209,7 @@ typedef struct SliceHeader {
enum HEVCSliceType slice_type;
int pic_order_cnt_lsb;
+ int poc;
uint8_t first_slice_in_pic_flag;
uint8_t dependent_slice_segment_flag;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 25/39] lavc/hevcdec: move a slice segment sanity check to hls_slice_header()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (22 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 24/39] lavc/hevcdec: store slice header POC in SliceHeader Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 26/39] lavc/hevcdec: move slice decoding dispatch to its own function Anton Khirnov
` (13 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Combine it with an existing similar check.
---
libavcodec/hevc/hevcdec.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index df6d1565bc..9c1d879953 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1002,7 +1002,8 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
sh->slice_ctb_addr_rs = sh->slice_segment_addr;
- if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) {
+ if (sh->dependent_slice_segment_flag &&
+ (!sh->slice_ctb_addr_rs || !pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) {
av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
return AVERROR_INVALIDDATA;
}
@@ -2577,11 +2578,6 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
int ret;
- if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) {
- av_log(s->avctx, AV_LOG_ERROR, "Impossible initial tile.\n");
- return AVERROR_INVALIDDATA;
- }
-
if (s->sh.dependent_slice_segment_flag) {
int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 26/39] lavc/hevcdec: move slice decoding dispatch to its own function
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (23 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 25/39] lavc/hevcdec: move a slice segment sanity check to hls_slice_header() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 27/39] lavc/hevcdec: move per-slice local_ctx setup out of hls_slice_header() Anton Khirnov
` (12 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Also move there a sanity check from hls_decode_entry() that should also
be performed when WPP is active (note that the check is not moved to
hls_slice_header() because it requires the HEVCContext.tab_slice_address
to be set up).
---
libavcodec/hevc/hevcdec.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 9c1d879953..bbcaa350c7 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2578,14 +2578,6 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
int ret;
- if (s->sh.dependent_slice_segment_flag) {
- int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
- if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
- av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
- return AVERROR_INVALIDDATA;
- }
- }
-
while (more_data && ctb_addr_ts < sps->ctb_size) {
int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
@@ -2813,6 +2805,27 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
return res;
}
+static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
+{
+ const HEVCPPS *pps = s->pps;
+
+ if (s->sh.dependent_slice_segment_flag) {
+ int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
+ int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
+ if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
+ av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
+ s->sh.num_entry_point_offsets > 0 &&
+ pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
+ return hls_slice_data_wpp(s, nal);
+
+ return hls_decode_entry(s, gb);
+}
+
static int set_side_data(HEVCContext *s)
{
AVFrame *out = s->cur_frame->f;
@@ -3152,12 +3165,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
goto fail;
}
- if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
- s->sh.num_entry_point_offsets > 0 &&
- s->pps->num_tile_rows == 1 && s->pps->num_tile_columns == 1)
- ctb_addr_ts = hls_slice_data_wpp(s, nal);
- else
- ctb_addr_ts = hls_decode_entry(s, &gb);
+ ctb_addr_ts = decode_slice_data(s, nal, &gb);
if (ctb_addr_ts >= s->cur_frame->ctb_count) {
ret = hevc_frame_end(s);
if (ret < 0)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 27/39] lavc/hevcdec: move per-slice local_ctx setup out of hls_slice_header()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (24 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 26/39] lavc/hevcdec: move slice decoding dispatch to its own function Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 28/39] lavc/hevcdec: move calling hwaccel start_frame to hevc_frame_start() Anton Khirnov
` (11 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Into decode_slice_data(). This is a step towards constifying
HEVCContext in hls_slice_header().
---
libavcodec/hevc/hevcdec.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index bbcaa350c7..cda52e05ef 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1014,14 +1014,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
- s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
-
- if (!pps->cu_qp_delta_enabled_flag)
- s->local_ctx[0].qp_y = s->sh.slice_qp;
-
s->slice_initialized = 1;
- s->local_ctx[0].tu.cu_qp_offset_cb = 0;
- s->local_ctx[0].tu.cu_qp_offset_cr = 0;
return 0;
}
@@ -2818,6 +2811,14 @@ static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext
}
}
+ s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
+
+ if (!pps->cu_qp_delta_enabled_flag)
+ s->local_ctx[0].qp_y = s->sh.slice_qp;
+
+ s->local_ctx[0].tu.cu_qp_offset_cb = 0;
+ s->local_ctx[0].tu.cu_qp_offset_cr = 0;
+
if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
s->sh.num_entry_point_offsets > 0 &&
pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 28/39] lavc/hevcdec: move calling hwaccel start_frame to hevc_frame_start()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (25 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 27/39] lavc/hevcdec: move per-slice local_ctx setup out of hls_slice_header() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 29/39] lavc/hevcdec: move calling hwaccel decode_slice to decode_slice_data() Anton Khirnov
` (10 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
From decode_nal_unit(), as that is a more appropriate place for it.
---
libavcodec/hevc/hevcdec.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index cda52e05ef..0bf68ea45c 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3006,7 +3006,11 @@ static int hevc_frame_start(HEVCContext *s)
if (ret < 0)
goto fail;
- if (!s->avctx->hwaccel)
+ if (s->avctx->hwaccel) {
+ ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
+ if (ret < 0)
+ goto fail;
+ } else
ff_thread_finish_setup(s->avctx);
return 0;
@@ -3148,12 +3152,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
}
}
- if (s->sh.first_slice_in_pic_flag && s->avctx->hwaccel) {
- ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
- if (ret < 0)
- goto fail;
- }
-
if (s->avctx->hwaccel) {
ret = FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
if (ret < 0)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 29/39] lavc/hevcdec: move calling hwaccel decode_slice to decode_slice_data()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (26 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 28/39] lavc/hevcdec: move calling hwaccel start_frame to hevc_frame_start() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 30/39] lavc/hevcdec: move constructing slice RPL " Anton Khirnov
` (9 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
From decode_nal_unit(), as that is a more appropriate place for it.
---
libavcodec/hevc/hevcdec.c | 38 +++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 0bf68ea45c..c148244361 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2811,6 +2811,15 @@ static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext
}
}
+ if (s->avctx->hwaccel)
+ return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
+
+ if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "SCC profile is not yet implemented in hevc native decoder.\n");
+ return AVERROR_PATCHWELCOME;
+ }
+
s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
if (!pps->cu_qp_delta_enabled_flag)
@@ -3152,30 +3161,17 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
}
}
- if (s->avctx->hwaccel) {
- ret = FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
+ ctb_addr_ts = decode_slice_data(s, nal, &gb);
+ if (ctb_addr_ts >= s->cur_frame->ctb_count) {
+ ret = hevc_frame_end(s);
if (ret < 0)
goto fail;
- } else {
- if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
- av_log(s->avctx, AV_LOG_ERROR,
- "SCC profile is not yet implemented in hevc native decoder.\n");
- ret = AVERROR_PATCHWELCOME;
- goto fail;
- }
+ s->is_decoded = 1;
+ }
- ctb_addr_ts = decode_slice_data(s, nal, &gb);
- if (ctb_addr_ts >= s->cur_frame->ctb_count) {
- ret = hevc_frame_end(s);
- if (ret < 0)
- goto fail;
- s->is_decoded = 1;
- }
-
- if (ctb_addr_ts < 0) {
- ret = ctb_addr_ts;
- goto fail;
- }
+ if (ctb_addr_ts < 0) {
+ ret = ctb_addr_ts;
+ goto fail;
}
break;
case HEVC_NAL_EOS_NUT:
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 30/39] lavc/hevcdec: move constructing slice RPL to decode_slice_data()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (27 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 29/39] lavc/hevcdec: move calling hwaccel decode_slice to decode_slice_data() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 31/39] lavc/hevcdec: set active PPS/SPS in hevc_frame_start() Anton Khirnov
` (8 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/hevc/hevcdec.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index c148244361..804cceac3e 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -665,11 +665,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (!sh->dependent_slice_segment_flag) {
sh->slice_addr = sh->slice_segment_addr;
- s->slice_idx++;
}
} else {
sh->slice_segment_addr = sh->slice_addr = 0;
- s->slice_idx = 0;
s->slice_initialized = 0;
}
@@ -2801,6 +2799,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
{
const HEVCPPS *pps = s->pps;
+ int ret;
if (s->sh.dependent_slice_segment_flag) {
int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
@@ -2811,6 +2810,15 @@ static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext
}
}
+ if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != HEVC_SLICE_I) {
+ ret = ff_hevc_slice_rpl(s);
+ if (ret < 0) {
+ av_log(s->avctx, AV_LOG_WARNING,
+ "Error constructing the reference lists for the current slice.\n");
+ return ret;
+ }
+ }
+
if (s->avctx->hwaccel)
return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
@@ -2828,6 +2836,8 @@ static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext
s->local_ctx[0].tu.cu_qp_offset_cb = 0;
s->local_ctx[0].tu.cu_qp_offset_cr = 0;
+ s->slice_idx += !s->sh.dependent_slice_segment_flag;
+
if (s->avctx->active_thread_type == FF_THREAD_SLICE &&
s->sh.num_entry_point_offsets > 0 &&
pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
@@ -2938,6 +2948,7 @@ static int hevc_frame_start(HEVCContext *s)
memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address));
s->is_decoded = 0;
+ s->slice_idx = 0;
s->first_nal_type = s->nal_unit_type;
s->poc = s->sh.poc;
@@ -3151,16 +3162,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
return AVERROR_INVALIDDATA;
}
- if (!s->sh.dependent_slice_segment_flag &&
- s->sh.slice_type != HEVC_SLICE_I) {
- ret = ff_hevc_slice_rpl(s);
- if (ret < 0) {
- av_log(s->avctx, AV_LOG_WARNING,
- "Error constructing the reference lists for the current slice.\n");
- goto fail;
- }
- }
-
ctb_addr_ts = decode_slice_data(s, nal, &gb);
if (ctb_addr_ts >= s->cur_frame->ctb_count) {
ret = hevc_frame_end(s);
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 31/39] lavc/hevcdec: set active PPS/SPS in hevc_frame_start()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (28 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 30/39] lavc/hevcdec: move constructing slice RPL " Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 32/39] lavc/hevcdec: move sequence increment/IDR handling to hevc_frame_start() Anton Khirnov
` (7 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Not in hls_slice_header(), as it should only be done once per frame.
---
libavcodec/hevc/hevcdec.c | 52 ++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 804cceac3e..9abae3260d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -594,6 +594,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
SliceHeader *sh = &s->sh;
const HEVCPPS *pps;
const HEVCSPS *sps;
+ unsigned pps_id;
int i, ret;
// Coded parameters
@@ -612,40 +613,23 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
if (IS_IRAP(s))
sh->no_output_of_prior_pics_flag = get_bits1(gb);
- sh->pps_id = get_ue_golomb_long(gb);
- 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);
+ pps_id = get_ue_golomb_long(gb);
+ if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
+ av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
return AVERROR_INVALIDDATA;
}
- if (!sh->first_slice_in_pic_flag &&
- s->pps != s->ps.pps_list[sh->pps_id]) {
+ if (!sh->first_slice_in_pic_flag && pps_id != sh->pps_id) {
av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
return AVERROR_INVALIDDATA;
}
- ff_refstruct_replace(&s->pps, s->ps.pps_list[sh->pps_id]);
- pps = s->pps;
+ sh->pps_id = pps_id;
+
+ pps = s->ps.pps_list[pps_id];
sps = pps->sps;
if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
sh->no_output_of_prior_pics_flag = 1;
- if (s->ps.sps != sps) {
- enum AVPixelFormat pix_fmt;
-
- ff_hevc_clear_refs(s);
-
- ret = set_sps(s, sps, sps->pix_fmt);
- if (ret < 0)
- return ret;
-
- pix_fmt = get_format(s, sps);
- if (pix_fmt < 0)
- return pix_fmt;
- s->avctx->pix_fmt = pix_fmt;
-
- s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
- }
-
sh->dependent_slice_segment_flag = 0;
if (!sh->first_slice_in_pic_flag) {
int slice_address_length;
@@ -2935,12 +2919,30 @@ static int set_side_data(HEVCContext *s)
static int hevc_frame_start(HEVCContext *s)
{
- const HEVCPPS *const pps = s->pps;
+ const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
const HEVCSPS *const sps = pps->sps;
int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) *
((sps->height >> sps->log2_min_cb_size) + 1);
int ret;
+ ff_refstruct_replace(&s->pps, pps);
+ if (s->ps.sps != sps) {
+ enum AVPixelFormat pix_fmt;
+
+ ff_hevc_clear_refs(s);
+
+ ret = set_sps(s, sps, sps->pix_fmt);
+ if (ret < 0)
+ return ret;
+
+ pix_fmt = get_format(s, sps);
+ if (pix_fmt < 0)
+ return pix_fmt;
+ s->avctx->pix_fmt = pix_fmt;
+
+ s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
+ }
+
memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
memset(s->vertical_bs, 0, s->bs_width * s->bs_height);
memset(s->cbf_luma, 0, sps->min_tb_width * sps->min_tb_height);
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 32/39] lavc/hevcdec: move sequence increment/IDR handling to hevc_frame_start()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (29 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 31/39] lavc/hevcdec: set active PPS/SPS in hevc_frame_start() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 33/39] lavc/hevcdec: move setting slice_initialized out of hls_slice_header() Anton Khirnov
` (6 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
From hls_slice_header(). It is only done once per frame, so that is a
more appropriate place for this code.
---
libavcodec/hevc/hevcdec.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 9abae3260d..b13e3e06a3 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -604,11 +604,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return 1; // This slice will be skipped later, do not corrupt state
}
- if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
- s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
- if (IS_IDR(s))
- ff_hevc_clear_refs(s);
- }
sh->no_output_of_prior_pics_flag = 0;
if (IS_IRAP(s))
sh->no_output_of_prior_pics_flag = get_bits1(gb);
@@ -2949,6 +2944,12 @@ static int hevc_frame_start(HEVCContext *s)
memset(s->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1));
memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address));
+ if ((IS_IDR(s) || IS_BLA(s))) {
+ s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
+ if (IS_IDR(s))
+ ff_hevc_clear_refs(s);
+ }
+
s->is_decoded = 0;
s->slice_idx = 0;
s->first_nal_type = s->nal_unit_type;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 33/39] lavc/hevcdec: move setting slice_initialized out of hls_slice_header()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (30 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 32/39] lavc/hevcdec: move sequence increment/IDR handling to hevc_frame_start() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 34/39] lavc/hevcdec: move the check for multiple frames in a packet Anton Khirnov
` (5 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
hls_slice_header() no longer modifies anything in HEVCContext besides
SliceHeader.
---
libavcodec/hevc/hevcdec.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index b13e3e06a3..2809e1e61d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -589,9 +589,8 @@ fail:
return ret;
}
-static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
+static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext *gb)
{
- SliceHeader *sh = &s->sh;
const HEVCPPS *pps;
const HEVCSPS *sps;
unsigned pps_id;
@@ -647,12 +646,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
}
} else {
sh->slice_segment_addr = sh->slice_addr = 0;
- s->slice_initialized = 0;
}
if (!sh->dependent_slice_segment_flag) {
- s->slice_initialized = 0;
-
for (i = 0; i < pps->num_extra_slice_header_bits; i++)
skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
@@ -991,8 +987,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
return AVERROR_INVALIDDATA;
}
- s->slice_initialized = 1;
-
return 0;
}
@@ -2798,6 +2792,8 @@ static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext
}
}
+ s->slice_initialized = 1;
+
if (s->avctx->hwaccel)
return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, nal->raw_size);
@@ -3042,6 +3038,7 @@ fail:
if (s->cur_frame)
ff_hevc_unref_frame(s->cur_frame, ~0);
s->cur_frame = s->collocated_ref = NULL;
+ s->slice_initialized = 0;
return ret;
}
@@ -3131,7 +3128,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
case HEVC_NAL_RADL_R:
case HEVC_NAL_RASL_N:
case HEVC_NAL_RASL_R:
- ret = hls_slice_header(s, &gb);
+ ret = hls_slice_header(&s->sh, s, &gb);
if (ret < 0)
return ret;
if (ret == 1) {
@@ -3139,7 +3136,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
goto fail;
}
-
if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
(s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
@@ -3211,6 +3207,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
s->last_eos = s->eos;
s->eos = 0;
s->overlap = 0;
+ s->slice_initialized = 0;
/* split the input packet into NAL units, so we know the upper bound on the
* number of slices in the frame */
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 34/39] lavc/hevcdec: move the check for multiple frames in a packet
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (31 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 33/39] lavc/hevcdec: move setting slice_initialized out of hls_slice_header() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 35/39] lavc/hevcdec: drop a redundant multiple-frame-per-packet check Anton Khirnov
` (4 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Do not do it in hls_slice_header(), which is the wrong place for it.
Avoids special magic return value of 1 in that function. The comment
mentioning potential corrupted state is no longer relevant, as
hls_slice_header() modifies no state beyond SliceHeader, which will only
get used for a valid frame.
---
libavcodec/hevc/hevcdec.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 2809e1e61d..a241e25196 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -598,10 +598,6 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext
// Coded parameters
sh->first_slice_in_pic_flag = get_bits1(gb);
- if (s->cur_frame && sh->first_slice_in_pic_flag) {
- av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
- return 1; // This slice will be skipped later, do not corrupt state
- }
sh->no_output_of_prior_pics_flag = 0;
if (IS_IRAP(s))
@@ -3131,10 +3127,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
ret = hls_slice_header(&s->sh, s, &gb);
if (ret < 0)
return ret;
- if (ret == 1) {
- ret = AVERROR_INVALIDDATA;
- goto fail;
- }
if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
@@ -3145,6 +3137,12 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
}
if (s->sh.first_slice_in_pic_flag) {
+ if (s->cur_frame) {
+ av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+
s->overlap ++;
ret = hevc_frame_start(s);
if (ret < 0)
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 35/39] lavc/hevcdec: drop a redundant multiple-frame-per-packet check
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (32 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 34/39] lavc/hevcdec: move the check for multiple frames in a packet Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 36/39] lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit() Anton Khirnov
` (3 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/hevc/hevcdec.c | 4 ----
libavcodec/hevc/hevcdec.h | 1 -
2 files changed, 5 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a241e25196..b9aea45edb 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3143,7 +3143,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
goto fail;
}
- s->overlap ++;
ret = hevc_frame_start(s);
if (ret < 0)
return ret;
@@ -3204,7 +3203,6 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
s->cur_frame = s->collocated_ref = NULL;
s->last_eos = s->eos;
s->eos = 0;
- s->overlap = 0;
s->slice_initialized = 0;
/* split the input packet into NAL units, so we know the upper bound on the
@@ -3271,8 +3269,6 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
continue;
ret = decode_nal_unit(s, nal);
- if (ret >= 0 && s->overlap > 2)
- ret = AVERROR_INVALIDDATA;
if (ret < 0) {
av_log(s->avctx, AV_LOG_WARNING,
"Error parsing NAL unit #%d.\n", i);
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index e47a7107c8..f0443b3ab9 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -487,7 +487,6 @@ typedef struct HEVCContext {
int last_eos; ///< last packet contains an EOS/EOB NAL
int bs_width;
int bs_height;
- int overlap;
int is_decoded;
// NoRaslOutputFlag associated with the last IRAP frame
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 36/39] lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (33 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 35/39] lavc/hevcdec: drop a redundant multiple-frame-per-packet check Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: move some frame-end code to hevc_frame_end() Anton Khirnov
` (2 subsequent siblings)
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/hevc/hevcdec.c | 97 +++++++++++++++++++++------------------
1 file changed, 52 insertions(+), 45 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index b9aea45edb..7263b80a24 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3065,10 +3065,60 @@ static int hevc_frame_end(HEVCContext *s)
return 0;
}
+static int decode_slice(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
+{
+ int ret;
+
+ ret = hls_slice_header(&s->sh, s, gb);
+ if (ret < 0)
+ return ret;
+
+ if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
+ (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
+ (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
+ ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
+ s->no_rasl_output_flag)) {
+ return 0;
+ }
+
+ if (s->sh.first_slice_in_pic_flag) {
+ if (s->cur_frame) {
+ av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ ret = hevc_frame_start(s);
+ if (ret < 0)
+ return ret;
+ } else if (!s->cur_frame) {
+ av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (s->nal_unit_type != s->first_nal_type) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Non-matching NAL types of the VCL NALUs: %d %d\n",
+ s->first_nal_type, s->nal_unit_type);
+ return AVERROR_INVALIDDATA;
+ }
+
+ ret = decode_slice_data(s, nal, gb);
+ if (ret < 0)
+ return ret;
+ if (ret >= s->cur_frame->ctb_count) {
+ ret = hevc_frame_end(s);
+ if (ret < 0)
+ return ret;
+ s->is_decoded = 1;
+ }
+
+ return 0;
+}
+
static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
{
GetBitContext gb = nal->gb;
- int ctb_addr_ts, ret;
+ int ret;
s->nal_unit_type = nal->type;
s->temporal_id = nal->temporal_id;
@@ -3124,52 +3174,9 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
case HEVC_NAL_RADL_R:
case HEVC_NAL_RASL_N:
case HEVC_NAL_RASL_R:
- ret = hls_slice_header(&s->sh, s, &gb);
+ ret = decode_slice(s, nal, &gb);
if (ret < 0)
- return ret;
-
- if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == HEVC_SLICE_B) ||
- (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != HEVC_SLICE_I) ||
- (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
- ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&
- s->no_rasl_output_flag)) {
- break;
- }
-
- if (s->sh.first_slice_in_pic_flag) {
- if (s->cur_frame) {
- av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first in the same frame.\n");
- ret = AVERROR_INVALIDDATA;
- goto fail;
- }
-
- ret = hevc_frame_start(s);
- if (ret < 0)
- return ret;
- } else if (!s->cur_frame) {
- av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
goto fail;
- }
-
- if (s->nal_unit_type != s->first_nal_type) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Non-matching NAL types of the VCL NALUs: %d %d\n",
- s->first_nal_type, s->nal_unit_type);
- return AVERROR_INVALIDDATA;
- }
-
- ctb_addr_ts = decode_slice_data(s, nal, &gb);
- if (ctb_addr_ts >= s->cur_frame->ctb_count) {
- ret = hevc_frame_end(s);
- if (ret < 0)
- goto fail;
- s->is_decoded = 1;
- }
-
- if (ctb_addr_ts < 0) {
- ret = ctb_addr_ts;
- goto fail;
- }
break;
case HEVC_NAL_EOS_NUT:
case HEVC_NAL_EOB_NUT:
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: move some frame-end code to hevc_frame_end()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (34 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 36/39] lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-13 5:55 ` Wang, Fei W
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 38/39] lavc/hevcdec: do not unref current frame on frame_end() failure Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: constify source frame in hevc_ref_frame() Anton Khirnov
37 siblings, 1 reply; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
Specifically, calling hwaccel end_frame, verifying frame checksum,
and printing the frame-was-decoded message.
---
libavcodec/hevc/hevcdec.c | 187 +++++++++++++++++++-------------------
libavcodec/hevc/hevcdec.h | 1 -
2 files changed, 91 insertions(+), 97 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 7263b80a24..a8c2172674 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2942,7 +2942,6 @@ static int hevc_frame_start(HEVCContext *s)
ff_hevc_clear_refs(s);
}
- s->is_decoded = 0;
s->slice_idx = 0;
s->first_nal_type = s->nal_unit_type;
s->poc = s->sh.poc;
@@ -3038,6 +3037,75 @@ fail:
return ret;
}
+static int verify_md5(HEVCContext *s, AVFrame *frame)
+{
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+ char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
+ int pixel_shift;
+ int err = 0;
+ int i, j;
+
+ if (!desc)
+ return AVERROR(EINVAL);
+
+ pixel_shift = desc->comp[0].depth > 8;
+
+ /* the checksums are LE, so we have to byteswap for >8bpp formats
+ * on BE arches */
+#if HAVE_BIGENDIAN
+ if (pixel_shift && !s->checksum_buf) {
+ av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
+ FFMAX3(frame->linesize[0], frame->linesize[1],
+ frame->linesize[2]));
+ if (!s->checksum_buf)
+ return AVERROR(ENOMEM);
+ }
+#endif
+
+ msg_buf[0] = '\0';
+ for (i = 0; frame->data[i]; i++) {
+ int width = s->avctx->coded_width;
+ int height = s->avctx->coded_height;
+ int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
+ int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
+ uint8_t md5[16];
+
+ av_md5_init(s->md5_ctx);
+ for (j = 0; j < h; j++) {
+ const uint8_t *src = frame->data[i] + j * frame->linesize[i];
+#if HAVE_BIGENDIAN
+ if (pixel_shift) {
+ s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
+ (const uint16_t *) src, w);
+ src = s->checksum_buf;
+ }
+#endif
+ av_md5_update(s->md5_ctx, src, w << pixel_shift);
+ }
+ av_md5_final(s->md5_ctx, md5);
+
+#define MD5_PRI "%016" PRIx64 "%016" PRIx64
+#define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
+
+ if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
+ av_strlcatf(msg_buf, sizeof(msg_buf),
+ "plane %d - correct " MD5_PRI "; ",
+ i, MD5_PRI_ARG(md5));
+ } else {
+ av_strlcatf(msg_buf, sizeof(msg_buf),
+ "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
+ i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
+ err = AVERROR_INVALIDDATA;
+ }
+ }
+
+ av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
+ "Verifying checksum for frame with POC %d: %s\n",
+ s->poc, msg_buf);
+
+ return err;
+ }
+
static int hevc_frame_end(HEVCContext *s)
{
HEVCFrame *out = s->cur_frame;
@@ -3062,6 +3130,28 @@ static int hevc_frame_end(HEVCContext *s)
av_assert1(ret >= 0);
}
+ if (s->avctx->hwaccel) {
+ ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
+ if (ret < 0) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "hardware accelerator failed to decode picture\n");
+ ff_hevc_unref_frame(s->cur_frame, ~0);
+ return ret;
+ }
+ } else {
+ if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
+ s->sei.picture_hash.is_md5) {
+ ret = verify_md5(s, s->cur_frame->f);
+ if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) {
+ ff_hevc_unref_frame(s->cur_frame, ~0);
+ return ret;
+ }
+ }
+ }
+ s->sei.picture_hash.is_md5 = 0;
+
+ av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n", s->poc);
+
return 0;
}
@@ -3109,7 +3199,6 @@ static int decode_slice(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
ret = hevc_frame_end(s);
if (ret < 0)
return ret;
- s->is_decoded = 1;
}
return 0;
@@ -3290,75 +3379,6 @@ fail:
return ret;
}
-static int verify_md5(HEVCContext *s, AVFrame *frame)
-{
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
- char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
- int pixel_shift;
- int err = 0;
- int i, j;
-
- if (!desc)
- return AVERROR(EINVAL);
-
- pixel_shift = desc->comp[0].depth > 8;
-
- /* the checksums are LE, so we have to byteswap for >8bpp formats
- * on BE arches */
-#if HAVE_BIGENDIAN
- if (pixel_shift && !s->checksum_buf) {
- av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
- FFMAX3(frame->linesize[0], frame->linesize[1],
- frame->linesize[2]));
- if (!s->checksum_buf)
- return AVERROR(ENOMEM);
- }
-#endif
-
- msg_buf[0] = '\0';
- for (i = 0; frame->data[i]; i++) {
- int width = s->avctx->coded_width;
- int height = s->avctx->coded_height;
- int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w) : width;
- int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
- uint8_t md5[16];
-
- av_md5_init(s->md5_ctx);
- for (j = 0; j < h; j++) {
- const uint8_t *src = frame->data[i] + j * frame->linesize[i];
-#if HAVE_BIGENDIAN
- if (pixel_shift) {
- s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
- (const uint16_t *) src, w);
- src = s->checksum_buf;
- }
-#endif
- av_md5_update(s->md5_ctx, src, w << pixel_shift);
- }
- av_md5_final(s->md5_ctx, md5);
-
-#define MD5_PRI "%016" PRIx64 "%016" PRIx64
-#define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
-
- if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
- av_strlcatf(msg_buf, sizeof(msg_buf),
- "plane %d - correct " MD5_PRI "; ",
- i, MD5_PRI_ARG(md5));
- } else {
- av_strlcatf(msg_buf, sizeof(msg_buf),
- "mismatching checksum of plane %d - " MD5_PRI " != " MD5_PRI "; ",
- i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
- err = AVERROR_INVALIDDATA;
- }
- }
-
- av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
- "Verifying checksum for frame with POC %d: %s\n",
- s->poc, msg_buf);
-
- return err;
-}
-
static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int first)
{
int ret, i;
@@ -3424,31 +3444,6 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
if (ret < 0)
return ret;
- if (avctx->hwaccel) {
- if (s->cur_frame && (ret = FF_HW_SIMPLE_CALL(avctx, end_frame)) < 0) {
- av_log(avctx, AV_LOG_ERROR,
- "hardware accelerator failed to decode picture\n");
- ff_hevc_unref_frame(s->cur_frame, ~0);
- return ret;
- }
- } else {
- /* verify the SEI checksum */
- if (avctx->err_recognition & AV_EF_CRCCHECK && s->cur_frame && s->is_decoded &&
- s->sei.picture_hash.is_md5) {
- ret = verify_md5(s, s->cur_frame->f);
- if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
- ff_hevc_unref_frame(s->cur_frame, ~0);
- return ret;
- }
- }
- }
- s->sei.picture_hash.is_md5 = 0;
-
- if (s->is_decoded) {
- av_log(avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n", s->poc);
- s->is_decoded = 0;
- }
-
if (s->output_frame->buf[0]) {
av_frame_move_ref(rframe, s->output_frame);
*got_output = 1;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index f0443b3ab9..da4d83e661 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -488,7 +488,6 @@ typedef struct HEVCContext {
int bs_width;
int bs_height;
- int is_decoded;
// NoRaslOutputFlag associated with the last IRAP frame
int no_rasl_output_flag;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 38/39] lavc/hevcdec: do not unref current frame on frame_end() failure
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (35 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: move some frame-end code to hevc_frame_end() Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: constify source frame in hevc_ref_frame() Anton Khirnov
37 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
It's a race with frame threading.
---
libavcodec/hevc/hevcdec.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a8c2172674..5fc55d5de9 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3135,17 +3135,14 @@ static int hevc_frame_end(HEVCContext *s)
if (ret < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"hardware accelerator failed to decode picture\n");
- ff_hevc_unref_frame(s->cur_frame, ~0);
return ret;
}
} else {
if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
s->sei.picture_hash.is_md5) {
ret = verify_md5(s, s->cur_frame->f);
- if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) {
- ff_hevc_unref_frame(s->cur_frame, ~0);
+ if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
return ret;
- }
}
}
s->sei.picture_hash.is_md5 = 0;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: constify source frame in hevc_ref_frame()
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
` (36 preceding siblings ...)
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 38/39] lavc/hevcdec: do not unref current frame on frame_end() failure Anton Khirnov
@ 2024-06-07 13:01 ` Anton Khirnov
2024-06-08 12:48 ` Vittorio Giovara
37 siblings, 1 reply; 45+ messages in thread
From: Anton Khirnov @ 2024-06-07 13:01 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/hevc/hevcdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5fc55d5de9..88f2bcecad 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3449,7 +3449,7 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
return avpkt->size;
}
-static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src)
+static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
{
int ret;
--
2.43.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number Anton Khirnov
@ 2024-06-08 7:02 ` Christophe Gisquet
2024-06-08 13:06 ` Anton Khirnov
0 siblings, 1 reply; 45+ messages in thread
From: Christophe Gisquet @ 2024-06-08 7:02 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Le ven. 7 juin 2024, 15:07, Anton Khirnov <anton@khirnov.net> a écrit :
> if (pps->tiles_enabled_flag &&
> pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
> int ret;
> - if (s->threads_number == 1)
> + if (!is_wpp)
> ret = cabac_reinit(lc);
> else {
> ret = ff_init_cabac_decoder(&lc->cc, data, size);
>
I have 2 things to say about this. First is that IIRC, tiles and WPP are
mutually exclusive, so I would have expected your change to introduce dead
code. It might have been changed for a later profile, but I think ffmpeg's
decoder doesn't support this or these profiles. Anyway, I wonder what the
intent of that code was.
Which leads me to the second. FFmpeg decoder does not support tile
threading (the one it's based off does/did) so maybe this code never
mattered for FFmpeg.
Hesitant LGTM, as I find this fishy and wondering if I'm missing something
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number}
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number} Anton Khirnov
@ 2024-06-08 7:08 ` Christophe Gisquet
2024-06-08 13:07 ` Anton Khirnov
0 siblings, 1 reply; 45+ messages in thread
From: Christophe Gisquet @ 2024-06-08 7:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Le ven. 7 juin 2024, 15:05, Anton Khirnov <anton@khirnov.net> a écrit :
> They are useless duplicates of corresponding AVCodecContext fields.
>
FYI, the intent of one field was to be a bit field to simultaneously
indicate/use frame threading and one of tile, WPP or slice threading, as
that was also supported in the original decoder. And I kind of remember the
second to have been supplemented, like dav1d separated number of tile and
frame threads at one point.
But LGTM in the context of FFmpeg.
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: constify source frame in hevc_ref_frame()
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: constify source frame in hevc_ref_frame() Anton Khirnov
@ 2024-06-08 12:48 ` Vittorio Giovara
0 siblings, 0 replies; 45+ messages in thread
From: Vittorio Giovara @ 2024-06-08 12:48 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, Jun 7, 2024 at 3:19 PM Anton Khirnov <anton@khirnov.net> wrote:
> ---
> libavcodec/hevc/hevcdec.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
> index 5fc55d5de9..88f2bcecad 100644
> --- a/libavcodec/hevc/hevcdec.c
> +++ b/libavcodec/hevc/hevcdec.c
> @@ -3449,7 +3449,7 @@ static int hevc_decode_frame(AVCodecContext *avctx,
> AVFrame *rframe,
> return avpkt->size;
> }
>
> -static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src)
> +static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
> {
> int ret;
>
Set overall ok
--
Vittorio
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number
2024-06-08 7:02 ` Christophe Gisquet
@ 2024-06-08 13:06 ` Anton Khirnov
0 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-08 13:06 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Christophe Gisquet (2024-06-08 09:02:04)
> Le ven. 7 juin 2024, 15:07, Anton Khirnov <anton@khirnov.net> a écrit :
>
> > if (pps->tiles_enabled_flag &&
> > pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
> > int ret;
> > - if (s->threads_number == 1)
> > + if (!is_wpp)
> > ret = cabac_reinit(lc);
> > else {
> > ret = ff_init_cabac_decoder(&lc->cc, data, size);
> >
>
> I have 2 things to say about this. First is that IIRC, tiles and WPP are
> mutually exclusive, so I would have expected your change to introduce dead
> code. It might have been changed for a later profile, but I think ffmpeg's
> decoder doesn't support this or these profiles. Anyway, I wonder what the
> intent of that code was.
>
> Which leads me to the second. FFmpeg decoder does not support tile
> threading (the one it's based off does/did) so maybe this code never
> mattered for FFmpeg.
>
> Hesitant LGTM, as I find this fishy and wondering if I'm missing something
You are correct, tiles and WPP are mutually exclusive and we do not
support tile threading. However, I'm not _introducing_ dead code, as the
code in question is already there and already dead. I've considered
removing it, but decided against it
1) to keep it consistent with the similar branch below.
2) since I don't really understand how it works
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number}
2024-06-08 7:08 ` Christophe Gisquet
@ 2024-06-08 13:07 ` Anton Khirnov
0 siblings, 0 replies; 45+ messages in thread
From: Anton Khirnov @ 2024-06-08 13:07 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Christophe Gisquet (2024-06-08 09:08:01)
> Le ven. 7 juin 2024, 15:05, Anton Khirnov <anton@khirnov.net> a écrit :
>
> > They are useless duplicates of corresponding AVCodecContext fields.
> >
>
> FYI, the intent of one field was to be a bit field to simultaneously
> indicate/use frame threading and one of tile, WPP or slice threading, as
> that was also supported in the original decoder. And I kind of remember the
> second to have been supplemented, like dav1d separated number of tile and
> frame threads at one point.
I get that, but IMO that should be implemented in the generic layer, not
inside individual decoders.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
* Re: [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: move some frame-end code to hevc_frame_end()
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: move some frame-end code to hevc_frame_end() Anton Khirnov
@ 2024-06-13 5:55 ` Wang, Fei W
0 siblings, 0 replies; 45+ messages in thread
From: Wang, Fei W @ 2024-06-13 5:55 UTC (permalink / raw)
To: ffmpeg-devel
On Fri, 2024-06-07 at 15:01 +0200, Anton Khirnov wrote:
> Specifically, calling hwaccel end_frame, verifying frame checksum,
> and printing the frame-was-decoded message.
> ---
> libavcodec/hevc/hevcdec.c | 187 +++++++++++++++++++-----------------
> --
> libavcodec/hevc/hevcdec.h | 1 -
> 2 files changed, 91 insertions(+), 97 deletions(-)
>
> diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
> index 7263b80a24..a8c2172674 100644
> --- a/libavcodec/hevc/hevcdec.c
> +++ b/libavcodec/hevc/hevcdec.c
> @@ -2942,7 +2942,6 @@ static int hevc_frame_start(HEVCContext *s)
> ff_hevc_clear_refs(s);
> }
>
> - s->is_decoded = 0;
> s->slice_idx = 0;
> s->first_nal_type = s->nal_unit_type;
> s->poc = s->sh.poc;
> @@ -3038,6 +3037,75 @@ fail:
> return ret;
> }
>
> +static int verify_md5(HEVCContext *s, AVFrame *frame)
> +{
> + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame-
> >format);
> + char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
> + int pixel_shift;
> + int err = 0;
> + int i, j;
> +
> + if (!desc)
> + return AVERROR(EINVAL);
> +
> + pixel_shift = desc->comp[0].depth > 8;
> +
> + /* the checksums are LE, so we have to byteswap for >8bpp
> formats
> + * on BE arches */
> +#if HAVE_BIGENDIAN
> + if (pixel_shift && !s->checksum_buf) {
> + av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
> + FFMAX3(frame->linesize[0], frame-
> >linesize[1],
> + frame->linesize[2]));
> + if (!s->checksum_buf)
> + return AVERROR(ENOMEM);
> + }
> +#endif
> +
> + msg_buf[0] = '\0';
> + for (i = 0; frame->data[i]; i++) {
> + int width = s->avctx->coded_width;
> + int height = s->avctx->coded_height;
> + int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w)
> : width;
> + int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h)
> : height;
> + uint8_t md5[16];
> +
> + av_md5_init(s->md5_ctx);
> + for (j = 0; j < h; j++) {
> + const uint8_t *src = frame->data[i] + j * frame-
> >linesize[i];
> +#if HAVE_BIGENDIAN
> + if (pixel_shift) {
> + s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
> + (const uint16_t *) src, w);
> + src = s->checksum_buf;
> + }
> +#endif
> + av_md5_update(s->md5_ctx, src, w << pixel_shift);
> + }
> + av_md5_final(s->md5_ctx, md5);
> +
> +#define MD5_PRI "%016" PRIx64 "%016" PRIx64
> +#define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf)
> + 8)
> +
> + if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
> + av_strlcatf(msg_buf, sizeof(msg_buf),
> + "plane %d - correct " MD5_PRI "; ",
> + i, MD5_PRI_ARG(md5));
> + } else {
> + av_strlcatf(msg_buf, sizeof(msg_buf),
> + "mismatching checksum of plane %d - " MD5_PRI
> " != " MD5_PRI "; ",
> + i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s-
> >sei.picture_hash.md5[i]));
> + err = AVERROR_INVALIDDATA;
> + }
> + }
> +
> + av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
> + "Verifying checksum for frame with POC %d: %s\n",
> + s->poc, msg_buf);
> +
> + return err;
> + }
> +
> static int hevc_frame_end(HEVCContext *s)
> {
> HEVCFrame *out = s->cur_frame;
> @@ -3062,6 +3130,28 @@ static int hevc_frame_end(HEVCContext *s)
> av_assert1(ret >= 0);
> }
>
> + if (s->avctx->hwaccel) {
> + ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
Hwaccel will not decode slice data to get ctb count, frame_end will be
always missed for hwaccel. Maybe better to keep hwaccel frame_end in
its original location.
Thanks
Fei
> + if (ret < 0) {
> + av_log(s->avctx, AV_LOG_ERROR,
> + "hardware accelerator failed to decode
> picture\n");
> + ff_hevc_unref_frame(s->cur_frame, ~0);
> + return ret;
> + }
> + } else {
> + if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
> + s->sei.picture_hash.is_md5) {
> + ret = verify_md5(s, s->cur_frame->f);
> + if (ret < 0 && s->avctx->err_recognition &
> AV_EF_EXPLODE) {
> + ff_hevc_unref_frame(s->cur_frame, ~0);
> + return ret;
> + }
> + }
> + }
> + s->sei.picture_hash.is_md5 = 0;
> +
> + av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n",
> s->poc);
> +
> return 0;
> }
>
> @@ -3109,7 +3199,6 @@ static int decode_slice(HEVCContext *s, const
> H2645NAL *nal, GetBitContext *gb)
> ret = hevc_frame_end(s);
> if (ret < 0)
> return ret;
> - s->is_decoded = 1;
> }
>
> return 0;
> @@ -3290,75 +3379,6 @@ fail:
> return ret;
> }
>
> -static int verify_md5(HEVCContext *s, AVFrame *frame)
> -{
> - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame-
> >format);
> - char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
> - int pixel_shift;
> - int err = 0;
> - int i, j;
> -
> - if (!desc)
> - return AVERROR(EINVAL);
> -
> - pixel_shift = desc->comp[0].depth > 8;
> -
> - /* the checksums are LE, so we have to byteswap for >8bpp
> formats
> - * on BE arches */
> -#if HAVE_BIGENDIAN
> - if (pixel_shift && !s->checksum_buf) {
> - av_fast_malloc(&s->checksum_buf, &s->checksum_buf_size,
> - FFMAX3(frame->linesize[0], frame-
> >linesize[1],
> - frame->linesize[2]));
> - if (!s->checksum_buf)
> - return AVERROR(ENOMEM);
> - }
> -#endif
> -
> - msg_buf[0] = '\0';
> - for (i = 0; frame->data[i]; i++) {
> - int width = s->avctx->coded_width;
> - int height = s->avctx->coded_height;
> - int w = (i == 1 || i == 2) ? (width >> desc->log2_chroma_w)
> : width;
> - int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h)
> : height;
> - uint8_t md5[16];
> -
> - av_md5_init(s->md5_ctx);
> - for (j = 0; j < h; j++) {
> - const uint8_t *src = frame->data[i] + j * frame-
> >linesize[i];
> -#if HAVE_BIGENDIAN
> - if (pixel_shift) {
> - s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
> - (const uint16_t *) src, w);
> - src = s->checksum_buf;
> - }
> -#endif
> - av_md5_update(s->md5_ctx, src, w << pixel_shift);
> - }
> - av_md5_final(s->md5_ctx, md5);
> -
> -#define MD5_PRI "%016" PRIx64 "%016" PRIx64
> -#define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf)
> + 8)
> -
> - if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
> - av_strlcatf(msg_buf, sizeof(msg_buf),
> - "plane %d - correct " MD5_PRI "; ",
> - i, MD5_PRI_ARG(md5));
> - } else {
> - av_strlcatf(msg_buf, sizeof(msg_buf),
> - "mismatching checksum of plane %d - " MD5_PRI
> " != " MD5_PRI "; ",
> - i, MD5_PRI_ARG(md5), MD5_PRI_ARG(s-
> >sei.picture_hash.md5[i]));
> - err = AVERROR_INVALIDDATA;
> - }
> - }
> -
> - av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
> - "Verifying checksum for frame with POC %d: %s\n",
> - s->poc, msg_buf);
> -
> - return err;
> -}
> -
> static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int
> length, int first)
> {
> int ret, i;
> @@ -3424,31 +3444,6 @@ static int hevc_decode_frame(AVCodecContext
> *avctx, AVFrame *rframe,
> if (ret < 0)
> return ret;
>
> - if (avctx->hwaccel) {
> - if (s->cur_frame && (ret = FF_HW_SIMPLE_CALL(avctx,
> end_frame)) < 0) {
> - av_log(avctx, AV_LOG_ERROR,
> - "hardware accelerator failed to decode
> picture\n");
> - ff_hevc_unref_frame(s->cur_frame, ~0);
> - return ret;
> - }
> - } else {
> - /* verify the SEI checksum */
> - if (avctx->err_recognition & AV_EF_CRCCHECK && s->cur_frame
> && s->is_decoded &&
> - s->sei.picture_hash.is_md5) {
> - ret = verify_md5(s, s->cur_frame->f);
> - if (ret < 0 && avctx->err_recognition & AV_EF_EXPLODE) {
> - ff_hevc_unref_frame(s->cur_frame, ~0);
> - return ret;
> - }
> - }
> - }
> - s->sei.picture_hash.is_md5 = 0;
> -
> - if (s->is_decoded) {
> - av_log(avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n",
> s->poc);
> - s->is_decoded = 0;
> - }
> -
> if (s->output_frame->buf[0]) {
> av_frame_move_ref(rframe, s->output_frame);
> *got_output = 1;
> diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
> index f0443b3ab9..da4d83e661 100644
> --- a/libavcodec/hevc/hevcdec.h
> +++ b/libavcodec/hevc/hevcdec.h
> @@ -488,7 +488,6 @@ typedef struct HEVCContext {
> int bs_width;
> int bs_height;
>
> - int is_decoded;
> // NoRaslOutputFlag associated with the last IRAP frame
> int no_rasl_output_flag;
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 45+ messages in thread
end of thread, other threads:[~2024-06-13 5:56 UTC | newest]
Thread overview: 45+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-07 13:00 [FFmpeg-devel] [PATCH 01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 02/39] lavc/hevcdec: simplify condition Anton Khirnov
2024-06-07 13:00 ` [FFmpeg-devel] [PATCH 03/39] lavc/hevcdec: drop a redundant assignment in hevc_decode_frame() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 04/39] lavc/hevc_ps: make PPS hold a reference to its SPS Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 05/39] lavc/hevc_ps: make SPS hold a reference to its VPS Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 06/39] lavc/hevc/parser: stop using HEVCParamSets.[psv]ps Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 07/39] lavc/hevc/mvs: stop accessing parameter sets through HEVCParamSets Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 08/39] lavc/hevc/filter: " Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 09/39] lavc/hevc/cabac: " Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 10/39] lavc/hevc/pred: " Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 11/39] lavc/hevcdec: " Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 12/39] lavc/hevcdec: move active PPS from HEVCParamSets to HEVCContext Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 13/39] lavc/hevcdec: drop an always-zero variable Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 14/39] lavc/hevcdec: only ignore INVALIDDATA in decode_nal_unit() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 15/39] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 16/39] lavc/hevcdec: do not pass HEVCContext to decode_lt_rps() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 17/39] lavc/hevcdec: move pocTid0 computation to hevc_frame_start() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 18/39] lavc/hevcdec: only call export_stream_params_from_sei() once per frame Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 19/39] lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 20/39] lavc/hevcdec: only set no_rasl_output_flag for IRAP frames Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 21/39] lavc/hevcdec: output RASL frames based on the value of no_rasl_output_flag Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 22/39] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number Anton Khirnov
2024-06-08 7:02 ` Christophe Gisquet
2024-06-08 13:06 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 23/39] lavc/hevcdec: drop redundant HEVCContext.threads_{type, number} Anton Khirnov
2024-06-08 7:08 ` Christophe Gisquet
2024-06-08 13:07 ` Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 24/39] lavc/hevcdec: store slice header POC in SliceHeader Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 25/39] lavc/hevcdec: move a slice segment sanity check to hls_slice_header() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 26/39] lavc/hevcdec: move slice decoding dispatch to its own function Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 27/39] lavc/hevcdec: move per-slice local_ctx setup out of hls_slice_header() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 28/39] lavc/hevcdec: move calling hwaccel start_frame to hevc_frame_start() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 29/39] lavc/hevcdec: move calling hwaccel decode_slice to decode_slice_data() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 30/39] lavc/hevcdec: move constructing slice RPL " Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 31/39] lavc/hevcdec: set active PPS/SPS in hevc_frame_start() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 32/39] lavc/hevcdec: move sequence increment/IDR handling to hevc_frame_start() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 33/39] lavc/hevcdec: move setting slice_initialized out of hls_slice_header() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 34/39] lavc/hevcdec: move the check for multiple frames in a packet Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 35/39] lavc/hevcdec: drop a redundant multiple-frame-per-packet check Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 36/39] lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit() Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: move some frame-end code to hevc_frame_end() Anton Khirnov
2024-06-13 5:55 ` Wang, Fei W
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 38/39] lavc/hevcdec: do not unref current frame on frame_end() failure Anton Khirnov
2024-06-07 13:01 ` [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: constify source frame in hevc_ref_frame() Anton Khirnov
2024-06-08 12:48 ` Vittorio Giovara
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git