bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0467-media-rpivid-Only-create-aux-entries-for-H265-if-nee.patch
1 From 9b0eddfd7341525e0e3074a7f6202f5ccd431b05 Mon Sep 17 00:00:00 2001
2 From: John Cox <jc@kynesim.co.uk>
3 Date: Thu, 6 May 2021 13:48:05 +0100
4 Subject: [PATCH] media: rpivid: Only create aux entries for H265 if
5 needed
6
7 Only create aux entries of mv info for frames where that info might
8 be used by a later frame. This saves some memory bandwidth and
9 potentially some memory.
10
11 Signed-off-by: John Cox <jc@kynesim.co.uk>
12 ---
13 drivers/staging/media/rpivid/rpivid_h265.c | 38 +++++++++++++---------
14 1 file changed, 23 insertions(+), 15 deletions(-)
15
16 --- a/drivers/staging/media/rpivid/rpivid_h265.c
17 +++ b/drivers/staging/media/rpivid/rpivid_h265.c
18 @@ -246,6 +246,8 @@ struct rpivid_dec_state {
19 // Slice vars
20 unsigned int slice_idx;
21 bool slice_temporal_mvp; /* Slice flag but constant for frame */
22 + bool use_aux;
23 + bool mk_aux;
24
25 // Temp vars per run - don't actually need to persist
26 u8 *src_buf;
27 @@ -1657,7 +1659,7 @@ static u32 mk_config2(const struct rpivi
28 c |= BIT(13);
29 if (sps->flags & V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED)
30 c |= BIT(14);
31 - if (sps->flags & V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED)
32 + if (s->mk_aux)
33 c |= BIT(15); /* Write motion vectors to external memory */
34 c |= (pps->log2_parallel_merge_level_minus2 + 2) << 16;
35 if (s->slice_temporal_mvp)
36 @@ -1669,6 +1671,14 @@ static u32 mk_config2(const struct rpivi
37 return c;
38 }
39
40 +static inline bool is_ref_unit_type(const unsigned int nal_unit_type)
41 +{
42 + /* From Table 7-1
43 + * True for 1, 3, 5, 7, 9, 11, 13, 15
44 + */
45 + return (nal_unit_type & ~0xe) != 0;
46 +}
47 +
48 static void rpivid_h265_setup(struct rpivid_ctx *ctx, struct rpivid_run *run)
49 {
50 struct rpivid_dev *const dev = ctx->dev;
51 @@ -1685,7 +1695,6 @@ static void rpivid_h265_setup(struct rpi
52 struct rpivid_dec_env *de = ctx->dec0;
53 unsigned int prev_rs;
54 unsigned int i;
55 - int use_aux;
56 int rv;
57 bool slice_temporal_mvp;
58 bool frame_end;
59 @@ -1828,6 +1837,16 @@ static void rpivid_h265_setup(struct rpi
60 */
61 s->slice_temporal_mvp = slice_temporal_mvp;
62
63 + /*
64 + * Need Aux ents for all (ref) DPB ents if temporal MV could
65 + * be enabled for any pic
66 + */
67 + s->use_aux = ((s->sps.flags &
68 + V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED) != 0);
69 + s->mk_aux = s->use_aux &&
70 + (s->sps.sps_max_sub_layers_minus1 >= sh0->nuh_temporal_id_plus1 ||
71 + is_ref_unit_type(sh0->nal_unit_type));
72 +
73 // Phase 2 reg pre-calc
74 de->rpi_config2 = mk_config2(s);
75 de->rpi_framesize = (s->sps.pic_height_in_luma_samples << 16) |
76 @@ -1952,15 +1971,6 @@ static void rpivid_h265_setup(struct rpi
77 // Frame end
78 memset(dpb_q_aux, 0,
79 sizeof(*dpb_q_aux) * V4L2_HEVC_DPB_ENTRIES_NUM_MAX);
80 - /*
81 - * Need Aux ents for all (ref) DPB ents if temporal MV could
82 - * be enabled for any pic
83 - * ** At the moment we create aux ents for all pics whether or not
84 - * they are ref - they should then be discarded by the DPB-aux
85 - * garbage collection code
86 - */
87 - use_aux = ((s->sps.flags &
88 - V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED) != 0);
89
90 // Locate ref frames
91 // At least in the current implementation this is constant across all
92 @@ -1994,7 +2004,7 @@ static void rpivid_h265_setup(struct rpi
93 continue;
94 }
95
96 - if (use_aux) {
97 + if (s->use_aux) {
98 dpb_q_aux[i] = aux_q_ref_idx(ctx, buffer_index);
99 if (!dpb_q_aux[i])
100 v4l2_warn(&dev->v4l2_dev,
101 @@ -2016,9 +2026,7 @@ static void rpivid_h265_setup(struct rpi
102 // now
103 aux_q_release(ctx, &s->frame_aux);
104
105 - if (use_aux) {
106 - // New frame so new aux ent
107 - // ??? Do we need this if non-ref ??? can we tell
108 + if (s->mk_aux) {
109 s->frame_aux = aux_q_new(ctx, run->dst->vb2_buf.index);
110
111 if (!s->frame_aux) {