hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <string.h>
#include "vp9d_codec.h"
#include "vp9d_parser.h"
#include "vp9d_syntax.h"
 
#define TRANS_TO_HW_STYLE(uv_mode)                          \
do{                                                         \
    RK_U8 *uv_ptr = NULL;                                   \
    RK_U8 uv_mode_prob[10][9];                              \
    for (i = 0; i < 10; i++) {                              \
        if (i == 0) {                                       \
            uv_ptr = uv_mode[2];                            \
        } else if ( i == 1) {                               \
            uv_ptr = uv_mode[0];                            \
        }  else if ( i == 2) {                              \
            uv_ptr = uv_mode[1];                            \
        }  else if ( i == 7) {                              \
            uv_ptr = uv_mode[8];                            \
        } else if (i == 8) {                                \
            uv_ptr = uv_mode[7];                            \
        } else {                                            \
            uv_ptr = uv_mode[i];                            \
        }                                                   \
        memcpy(&uv_mode_prob[i], uv_ptr, 9);                \
    }                                                       \
    memcpy(uv_mode, uv_mode_prob, sizeof(uv_mode_prob));    \
}while(0)
 
static int vp9d_fill_segmentation(VP9Context *s, DXVA_segmentation_VP9 *seg)
{
    int i;
 
    seg->enabled = s->segmentation.enabled;
    seg->update_map = s->segmentation.update_map;
    seg->temporal_update = s->segmentation.temporal;
    seg->abs_delta = s->segmentation.absolute_vals;
    seg->ReservedSegmentFlags4Bits = 0;
 
    for (i = 0; i < 7; i++) {
        seg->tree_probs[i] = s->prob.seg[i];
    }
 
    seg->pred_probs[0] = s->prob.segpred[0];
    seg->pred_probs[1] = s->prob.segpred[1];
    seg->pred_probs[2] = s->prob.segpred[2];
 
    for (i = 0; i < 8; i++) {
        seg->feature_data[i][0] = s->segmentation.feat[i].q_val;
        seg->feature_data[i][1] = s->segmentation.feat[i].lf_val;
        seg->feature_data[i][2] = s->segmentation.feat[i].ref_val;
        seg->feature_data[i][3] = s->segmentation.feat[i].skip_enabled;
        seg->feature_mask[i] = s->segmentation.feat[i].q_enabled
                               | (s->segmentation.feat[i].lf_enabled << 1)
                               | (s->segmentation.feat[i].ref_enabled << 2)
                               | (s->segmentation.feat[i].skip_enabled << 3);
#if 0
        mpp_log("seg->feature_data[%d][0] = 0x%x", i, seg->feature_data[i][0]);
 
        mpp_log("seg->feature_data[%d][1] = 0x%x", i, seg->feature_data[i][0]);
 
        mpp_log("seg->feature_data[%d][2] = 0x%x", i, seg->feature_data[i][0]);
 
        mpp_log("seg->feature_data[%d][3] = 0x%x", i, seg->feature_data[i][0]);
        mpp_log("seg->feature_mask[%d] = 0x%x", i, seg->feature_mask[i]);
#endif
    }
 
    return 0;
}
 
static int vp9d_fill_picparams(Vp9CodecContext *ctx, DXVA_PicParams_VP9 *pic)
{
    VP9Context *s = ctx->priv_data;
    RK_U8 partition_probs[16][3];
    RK_U8 partition_probs_flag[16][3];
    RK_U8 partition_probs_delata[16][3];
    DXVA_prob_vp9* prob_flag = &pic->prob_flag_delta.p_flag;
    DXVA_prob_vp9* prob_delta = &pic->prob_flag_delta.p_delta;
    int i;
 
    pic->profile = ctx->profile;
    pic->show_existing_frame = s->show_existing_frame;
    pic->frame_type = !s->keyframe;
    pic->show_frame = !s->invisible;
    pic->error_resilient_mode =  s->errorres;
    pic->subsampling_x = s->ss_h;
    pic->subsampling_y = s->ss_v;
    pic->extra_plane = s->extra_plane;
    pic->refresh_frame_context = s->refreshctx;
    pic->intra_only = s->intraonly;
    pic->frame_context_idx = s->framectxid;
    pic->reset_frame_context = s->resetctx;
    pic->allow_high_precision_mv = s->highprecisionmvs;
    pic->parallelmode = s->parallelmode;
    pic->width = ctx->width;
    pic->height = ctx->height;
    pic->BitDepthMinus8Luma = s->bpp - 8;
    pic->BitDepthMinus8Chroma = s->bpp - 8;
    pic->interp_filter = s->filtermode;
    pic->CurrPic.Index7Bits = s->frames[CUR_FRAME].slot_index;
 
    for (i = 0; i < 8; i++) {
        pic->ref_frame_map[i].Index7Bits = s->refs[i].slot_index;
        pic->ref_frame_coded_width[i] = mpp_frame_get_width(s->refs[i].f);
        pic->ref_frame_coded_height[i] = mpp_frame_get_height(s->refs[i].f);
    }
    pic->frame_refs[0].Index7Bits =  s->refidx[0];
    pic->frame_refs[1].Index7Bits =  s->refidx[1];
    pic->frame_refs[2].Index7Bits =  s->refidx[2];
    pic->ref_frame_sign_bias[1] = s->signbias[0];
    pic->ref_frame_sign_bias[2] = s->signbias[1];
    pic->ref_frame_sign_bias[3] = s->signbias[2];
    pic->filter_level = s->filter.level;
    pic->sharpness_level = s->filter.sharpness;
    pic->mode_ref_delta_enabled = s->lf_delta.enabled;
    pic->mode_ref_delta_update = s->lf_delta.update;
    pic->use_prev_in_find_mv_refs = s->use_last_frame_mvs;
    pic->ref_deltas[0] = s->lf_delta.ref[0];
    pic->ref_deltas[1] = s->lf_delta.ref[1];
    pic->ref_deltas[2] = s->lf_delta.ref[2];
    pic->ref_deltas[3] = s->lf_delta.ref[3];
    pic->mode_deltas[0] = s->lf_delta.mode[0];
    pic->mode_deltas[1] = s->lf_delta.mode[1];
    pic->base_qindex = s->yac_qi;
    pic->y_dc_delta_q = s->ydc_qdelta;
    pic->uv_dc_delta_q = s->uvdc_qdelta;
    pic->uv_ac_delta_q = s->uvac_qdelta;
    pic->txmode = s->txfmmode;
    pic->refmode = s->comppredmode;
    vp9d_fill_segmentation(s, &pic->stVP9Segments);
    pic->log2_tile_cols = s->tiling.log2_tile_cols;
    pic->log2_tile_rows = s->tiling.log2_tile_rows;
    pic->first_partition_size = s->first_partition_size;
    memcpy(pic->mvscale, s->mvscale, sizeof(s->mvscale));
    memcpy(&pic->prob, &s->prob, sizeof(pic->prob));
    memcpy(&pic->prob_flag_delta, &s->prob_flag_delta, sizeof(pic->prob_flag_delta));
    {
        /*change partition to hardware need style*/
        /*
              hardware            syntax
          *+++++8x8+++++*     *++++64x64++++*
          *+++++16x16+++*     *++++32x32++++*
          *+++++32x32+++*     *++++16x16++++*
          *+++++64x64+++*     *++++8x8++++++*
        */
        RK_U32 m = 0;
        RK_U32 len = sizeof(pic->prob.partition[0]);
        RK_U32 step = len / sizeof(partition_probs[0]);
 
        for (i = MPP_ARRAY_ELEMS(pic->prob.partition) - 1; i >= 0; i--) {
            memcpy(&partition_probs[m][0], &pic->prob.partition[i][0][0], len);
            memcpy(&partition_probs_flag[m][0], &prob_flag->partition[i][0][0], len);
            memcpy(&partition_probs_delata[m][0], &prob_delta->partition[i][0][0], len);
            m += step;
        }
        memcpy(pic->prob.partition, partition_probs, sizeof(partition_probs));
        memcpy(prob_flag->partition, partition_probs_flag, sizeof(partition_probs_flag));
        memcpy(prob_delta->partition, partition_probs_delata, sizeof(partition_probs_delata));
 
        /*change uv_mode to hardware need style*/
        /*
            hardware              syntax
         *+++++ dc  ++++*     *++++ v   ++++*
         *+++++ v   ++++*     *++++ h   ++++*
         *+++++ h   ++++*     *++++ dc  ++++*
         *+++++ d45 ++++*     *++++ d45 ++++*
         *+++++ d135++++*     *++++ d135++++*
         *+++++ d117++++*     *++++ d117++++*
         *+++++ d153++++*     *++++ d153++++*
         *+++++ d207++++*     *++++ d63 ++++*
         *+++++ d63 ++++*     *++++ d207++++*
         *+++++ tm  ++++*     *++++ tm  ++++*
        */
 
        TRANS_TO_HW_STYLE(pic->prob.uv_mode);
        TRANS_TO_HW_STYLE(prob_flag->uv_mode);
        TRANS_TO_HW_STYLE(prob_delta->uv_mode);
    }
    return 0;
}
 
void vp9d_fill_counts(Vp9CodecContext *ctx)
{
    VP9Context *s = ctx->priv_data;
    memcpy(&ctx->pic_params.counts, &s->counts, sizeof(s->counts));
}
 
RK_S32 vp9d_parser2_syntax(Vp9CodecContext *ctx)
{
    vp9d_fill_picparams(ctx, &ctx->pic_params);
    return 0;
}