~ubuntu-branches/ubuntu/vivid/libav/vivid

« back to all changes in this revision

Viewing changes to libavcodec/cavs.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2013-10-22 23:24:08 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: package-import@ubuntu.com-20131022232408-b8tvvn4pyzri9mi3
Tags: 6:9.10-1ubuntu1
* Build all -extra flavors from this source package, as libav got demoted
  from main to universe, cf LP: #1243235
* Simplify debian/rules to follow exactly the code that debian executes
* New upstream (LP: #1180288) fixes lots of security issues (LP: #1242802)
* Merge from unstable, remaining changes:
  - build-depend on libtiff5-dev rather than libtiff4-dev,
    avoids FTBFS caused by imlib
  - follow the regular debian codepaths

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "golomb.h"
31
31
#include "mathops.h"
32
32
#include "cavs.h"
33
 
#include "cavsdata.h"
 
33
 
 
34
static const uint8_t alpha_tab[64] = {
 
35
   0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  2,  2,  2,  3,  3,
 
36
   4,  4,  5,  5,  6,  7,  8,  9, 10, 11, 12, 13, 15, 16, 18, 20,
 
37
  22, 24, 26, 28, 30, 33, 33, 35, 35, 36, 37, 37, 39, 39, 42, 44,
 
38
  46, 48, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
 
39
};
 
40
 
 
41
static const uint8_t beta_tab[64] = {
 
42
   0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,
 
43
   2,  2,  3,  3,  3,  3,  4,  4,  4,  4,  5,  5,  5,  5,  6,  6,
 
44
   6,  7,  7,  7,  8,  8,  8,  9,  9, 10, 10, 11, 11, 12, 13, 14,
 
45
  15, 16, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, 25, 26, 27
 
46
};
 
47
 
 
48
static const uint8_t tc_tab[64] = {
 
49
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
50
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
 
51
  2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
 
52
  5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9
 
53
};
 
54
 
 
55
/** mark block as unavailable, i.e. out of picture
 
56
    or not yet decoded */
 
57
static const cavs_vector un_mv = { 0, 0, 1, NOT_AVAIL };
 
58
 
 
59
static const int8_t left_modifier_l[8] = {  0, -1,  6, -1, -1, 7, 6, 7 };
 
60
static const int8_t top_modifier_l[8]  = { -1,  1,  5, -1, -1, 5, 7, 7 };
 
61
static const int8_t left_modifier_c[7] = {  5, -1,  2, -1,  6, 5, 6 };
 
62
static const int8_t top_modifier_c[7]  = {  4,  1, -1, -1,  4, 6, 6 };
34
63
 
35
64
/*****************************************************************************
36
65
 *
38
67
 *
39
68
 ****************************************************************************/
40
69
 
41
 
static inline int get_bs(cavs_vector *mvP, cavs_vector *mvQ, int b) {
42
 
    if((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
 
70
static inline int get_bs(cavs_vector *mvP, cavs_vector *mvQ, int b)
 
71
{
 
72
    if ((mvP->ref == REF_INTRA) || (mvQ->ref == REF_INTRA))
43
73
        return 2;
44
 
    if( (abs(mvP->x - mvQ->x) >= 4) ||  (abs(mvP->y - mvQ->y) >= 4) )
 
74
    if ((abs(mvP->x - mvQ->x) >= 4) || (abs(mvP->y - mvQ->y) >= 4))
45
75
        return 1;
46
 
    if(b){
 
76
    if (b) {
47
77
        mvP += MV_BWD_OFFS;
48
78
        mvQ += MV_BWD_OFFS;
49
 
        if( (abs(mvP->x - mvQ->x) >= 4) ||  (abs(mvP->y - mvQ->y) >= 4) )
 
79
        if ((abs(mvP->x - mvQ->x) >= 4) ||  (abs(mvP->y - mvQ->y) >= 4))
50
80
            return 1;
51
 
    }else{
52
 
        if(mvP->ref != mvQ->ref)
 
81
    } else {
 
82
        if (mvP->ref != mvQ->ref)
53
83
            return 1;
54
84
    }
55
85
    return 0;
56
86
}
57
87
 
58
 
#define SET_PARAMS                                            \
59
 
    alpha = alpha_tab[av_clip(qp_avg + h->alpha_offset,0,63)];   \
60
 
    beta  =  beta_tab[av_clip(qp_avg + h->beta_offset, 0,63)];   \
61
 
    tc    =    tc_tab[av_clip(qp_avg + h->alpha_offset,0,63)];
 
88
#define SET_PARAMS                                                \
 
89
    alpha = alpha_tab[av_clip(qp_avg + h->alpha_offset, 0, 63)];  \
 
90
    beta  =  beta_tab[av_clip(qp_avg + h->beta_offset,  0, 63)];  \
 
91
    tc    =    tc_tab[av_clip(qp_avg + h->alpha_offset, 0, 63)];
62
92
 
63
93
/**
64
94
 * in-loop deblocking filter for a single macroblock
72
102
 * ---------
73
103
 *
74
104
 */
75
 
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) {
 
105
void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type)
 
106
{
76
107
    uint8_t bs[8];
77
108
    int qp_avg, alpha, beta, tc;
78
109
    int i;
79
110
 
80
111
    /* save un-deblocked lines */
81
 
    h->topleft_border_y = h->top_border_y[h->mbx*16+15];
82
 
    h->topleft_border_u = h->top_border_u[h->mbx*10+8];
83
 
    h->topleft_border_v = h->top_border_v[h->mbx*10+8];
84
 
    memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16);
85
 
    memcpy(&h->top_border_u[h->mbx*10+1], h->cu +  7* h->c_stride,8);
86
 
    memcpy(&h->top_border_v[h->mbx*10+1], h->cv +  7* h->c_stride,8);
87
 
    for(i=0;i<8;i++) {
88
 
        h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+0)*h->l_stride);
89
 
        h->left_border_y[i*2+2] = *(h->cy + 15 + (i*2+1)*h->l_stride);
90
 
        h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
91
 
        h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
 
112
    h->topleft_border_y = h->top_border_y[h->mbx * 16 + 15];
 
113
    h->topleft_border_u = h->top_border_u[h->mbx * 10 + 8];
 
114
    h->topleft_border_v = h->top_border_v[h->mbx * 10 + 8];
 
115
    memcpy(&h->top_border_y[h->mbx * 16],     h->cy + 15 * h->l_stride, 16);
 
116
    memcpy(&h->top_border_u[h->mbx * 10 + 1], h->cu +  7 * h->c_stride, 8);
 
117
    memcpy(&h->top_border_v[h->mbx * 10 + 1], h->cv +  7 * h->c_stride, 8);
 
118
    for (i = 0; i < 8; i++) {
 
119
        h->left_border_y[i * 2 + 1] = *(h->cy + 15 + (i * 2 + 0) * h->l_stride);
 
120
        h->left_border_y[i * 2 + 2] = *(h->cy + 15 + (i * 2 + 1) * h->l_stride);
 
121
        h->left_border_u[i + 1]     = *(h->cu + 7  +  i          * h->c_stride);
 
122
        h->left_border_v[i + 1]     = *(h->cv + 7  +  i          * h->c_stride);
92
123
    }
93
 
    if(!h->loop_filter_disable) {
 
124
    if (!h->loop_filter_disable) {
94
125
        /* determine bs */
95
 
        if(mb_type == I_8X8)
96
 
            memset(bs,2,8);
 
126
        if (mb_type == I_8X8)
 
127
            memset(bs, 2, 8);
97
128
        else{
98
 
            memset(bs,0,8);
99
 
            if(ff_cavs_partition_flags[mb_type] & SPLITV){
 
129
            memset(bs, 0, 8);
 
130
            if (ff_cavs_partition_flags[mb_type] & SPLITV) {
100
131
                bs[2] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1], mb_type > P_8X8);
101
132
                bs[3] = get_bs(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3], mb_type > P_8X8);
102
133
            }
103
 
            if(ff_cavs_partition_flags[mb_type] & SPLITH){
 
134
            if (ff_cavs_partition_flags[mb_type] & SPLITH) {
104
135
                bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8);
105
136
                bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8);
106
137
            }
109
140
            bs[4] = get_bs(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0], mb_type > P_8X8);
110
141
            bs[5] = get_bs(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1], mb_type > P_8X8);
111
142
        }
112
 
        if(AV_RN64(bs)) {
113
 
            if(h->flags & A_AVAIL) {
 
143
        if (AV_RN64(bs)) {
 
144
            if (h->flags & A_AVAIL) {
114
145
                qp_avg = (h->qp + h->left_qp + 1) >> 1;
115
146
                SET_PARAMS;
116
 
                h->cdsp.cavs_filter_lv(h->cy,h->l_stride,alpha,beta,tc,bs[0],bs[1]);
117
 
                h->cdsp.cavs_filter_cv(h->cu,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
118
 
                h->cdsp.cavs_filter_cv(h->cv,h->c_stride,alpha,beta,tc,bs[0],bs[1]);
 
147
                h->cdsp.cavs_filter_lv(h->cy, h->l_stride, alpha, beta, tc, bs[0], bs[1]);
 
148
                h->cdsp.cavs_filter_cv(h->cu, h->c_stride, alpha, beta, tc, bs[0], bs[1]);
 
149
                h->cdsp.cavs_filter_cv(h->cv, h->c_stride, alpha, beta, tc, bs[0], bs[1]);
119
150
            }
120
151
            qp_avg = h->qp;
121
152
            SET_PARAMS;
122
 
            h->cdsp.cavs_filter_lv(h->cy + 8,h->l_stride,alpha,beta,tc,bs[2],bs[3]);
123
 
            h->cdsp.cavs_filter_lh(h->cy + 8*h->l_stride,h->l_stride,alpha,beta,tc,
124
 
                           bs[6],bs[7]);
 
153
            h->cdsp.cavs_filter_lv(h->cy + 8,               h->l_stride, alpha, beta, tc, bs[2], bs[3]);
 
154
            h->cdsp.cavs_filter_lh(h->cy + 8 * h->l_stride, h->l_stride, alpha, beta, tc, bs[6], bs[7]);
125
155
 
126
 
            if(h->flags & B_AVAIL) {
 
156
            if (h->flags & B_AVAIL) {
127
157
                qp_avg = (h->qp + h->top_qp[h->mbx] + 1) >> 1;
128
158
                SET_PARAMS;
129
 
                h->cdsp.cavs_filter_lh(h->cy,h->l_stride,alpha,beta,tc,bs[4],bs[5]);
130
 
                h->cdsp.cavs_filter_ch(h->cu,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
131
 
                h->cdsp.cavs_filter_ch(h->cv,h->c_stride,alpha,beta,tc,bs[4],bs[5]);
 
159
                h->cdsp.cavs_filter_lh(h->cy, h->l_stride, alpha, beta, tc, bs[4], bs[5]);
 
160
                h->cdsp.cavs_filter_ch(h->cu, h->c_stride, alpha, beta, tc, bs[4], bs[5]);
 
161
                h->cdsp.cavs_filter_ch(h->cv, h->c_stride, alpha, beta, tc, bs[4], bs[5]);
132
162
            }
133
163
        }
134
164
    }
135
 
    h->left_qp = h->qp;
 
165
    h->left_qp        = h->qp;
136
166
    h->top_qp[h->mbx] = h->qp;
137
167
}
138
168
 
145
175
 ****************************************************************************/
146
176
 
147
177
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top,
148
 
                                        uint8_t **left, int block) {
 
178
                                  uint8_t **left, int block)
 
179
{
149
180
    int i;
150
181
 
151
 
    switch(block) {
 
182
    switch (block) {
152
183
    case 0:
153
 
        *left = h->left_border_y;
 
184
        *left               = h->left_border_y;
154
185
        h->left_border_y[0] = h->left_border_y[1];
155
 
        memset(&h->left_border_y[17],h->left_border_y[16],9);
156
 
        memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
 
186
        memset(&h->left_border_y[17], h->left_border_y[16], 9);
 
187
        memcpy(&top[1], &h->top_border_y[h->mbx * 16], 16);
157
188
        top[17] = top[16];
158
 
        top[0] = top[1];
159
 
        if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
 
189
        top[0]  = top[1];
 
190
        if ((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
160
191
            h->left_border_y[0] = top[0] = h->topleft_border_y;
161
192
        break;
162
193
    case 1:
163
194
        *left = h->intern_border_y;
164
 
        for(i=0;i<8;i++)
165
 
            h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
166
 
        memset(&h->intern_border_y[9],h->intern_border_y[8],9);
 
195
        for (i = 0; i < 8; i++)
 
196
            h->intern_border_y[i + 1] = *(h->cy + 7 + i * h->l_stride);
 
197
        memset(&h->intern_border_y[9], h->intern_border_y[8], 9);
167
198
        h->intern_border_y[0] = h->intern_border_y[1];
168
 
        memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
169
 
        if(h->flags & C_AVAIL)
170
 
            memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
 
199
        memcpy(&top[1], &h->top_border_y[h->mbx * 16 + 8], 8);
 
200
        if (h->flags & C_AVAIL)
 
201
            memcpy(&top[9], &h->top_border_y[(h->mbx + 1) * 16], 8);
171
202
        else
172
 
            memset(&top[9],top[8],9);
 
203
            memset(&top[9], top[8], 9);
173
204
        top[17] = top[16];
174
 
        top[0] = top[1];
175
 
        if(h->flags & B_AVAIL)
176
 
            h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
 
205
        top[0]  = top[1];
 
206
        if (h->flags & B_AVAIL)
 
207
            h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx * 16 + 7];
177
208
        break;
178
209
    case 2:
179
210
        *left = &h->left_border_y[8];
180
 
        memcpy(&top[1],h->cy + 7*h->l_stride,16);
 
211
        memcpy(&top[1], h->cy + 7 * h->l_stride, 16);
181
212
        top[17] = top[16];
182
 
        top[0] = top[1];
183
 
        if(h->flags & A_AVAIL)
 
213
        top[0]  = top[1];
 
214
        if (h->flags & A_AVAIL)
184
215
            top[0] = h->left_border_y[8];
185
216
        break;
186
217
    case 3:
187
218
        *left = &h->intern_border_y[8];
188
 
        for(i=0;i<8;i++)
189
 
            h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
190
 
        memset(&h->intern_border_y[17],h->intern_border_y[16],9);
191
 
        memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
192
 
        memset(&top[9],top[8],9);
 
219
        for (i = 0; i < 8; i++)
 
220
            h->intern_border_y[i + 9] = *(h->cy + 7 + (i + 8) * h->l_stride);
 
221
        memset(&h->intern_border_y[17], h->intern_border_y[16], 9);
 
222
        memcpy(&top[0], h->cy + 7 + 7 * h->l_stride, 9);
 
223
        memset(&top[9], top[8], 9);
193
224
        break;
194
225
    }
195
226
}
196
227
 
197
 
void ff_cavs_load_intra_pred_chroma(AVSContext *h) {
 
228
void ff_cavs_load_intra_pred_chroma(AVSContext *h)
 
229
{
198
230
    /* extend borders by one pixel */
199
231
    h->left_border_u[9] = h->left_border_u[8];
200
232
    h->left_border_v[9] = h->left_border_v[8];
201
 
    h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
202
 
    h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
203
 
    if(h->mbx && h->mby) {
204
 
        h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
205
 
        h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
 
233
    h->top_border_u[h->mbx * 10 + 9] = h->top_border_u[h->mbx * 10 + 8];
 
234
    h->top_border_v[h->mbx * 10 + 9] = h->top_border_v[h->mbx * 10 + 8];
 
235
    if (h->mbx && h->mby) {
 
236
        h->top_border_u[h->mbx * 10] = h->left_border_u[0] = h->topleft_border_u;
 
237
        h->top_border_v[h->mbx * 10] = h->left_border_v[0] = h->topleft_border_v;
206
238
    } else {
207
239
        h->left_border_u[0] = h->left_border_u[1];
208
240
        h->left_border_v[0] = h->left_border_v[1];
209
 
        h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
210
 
        h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
 
241
        h->top_border_u[h->mbx * 10] = h->top_border_u[h->mbx * 10 + 1];
 
242
        h->top_border_v[h->mbx * 10] = h->top_border_v[h->mbx * 10 + 1];
211
243
    }
212
244
}
213
245
 
214
 
static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
 
246
static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
247
{
215
248
    int y;
216
249
    uint64_t a = AV_RN64(&top[1]);
217
 
    for(y=0;y<8;y++) {
218
 
        *((uint64_t *)(d+y*stride)) = a;
 
250
    for (y = 0; y < 8; y++) {
 
251
        *((uint64_t *)(d + y * stride)) = a;
219
252
    }
220
253
}
221
254
 
222
 
static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
 
255
static void intra_pred_horiz(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
256
{
223
257
    int y;
224
258
    uint64_t a;
225
 
    for(y=0;y<8;y++) {
226
 
        a = left[y+1] * 0x0101010101010101ULL;
227
 
        *((uint64_t *)(d+y*stride)) = a;
 
259
    for (y = 0; y < 8; y++) {
 
260
        a = left[y + 1] * 0x0101010101010101ULL;
 
261
        *((uint64_t *)(d + y * stride)) = a;
228
262
    }
229
263
}
230
264
 
231
 
static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
 
265
static void intra_pred_dc_128(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
266
{
232
267
    int y;
233
268
    uint64_t a = 0x8080808080808080ULL;
234
 
    for(y=0;y<8;y++)
235
 
        *((uint64_t *)(d+y*stride)) = a;
 
269
    for (y = 0; y < 8; y++)
 
270
        *((uint64_t *)(d + y * stride)) = a;
236
271
}
237
272
 
238
 
static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
239
 
    int x,y,ia;
 
273
static void intra_pred_plane(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
274
{
 
275
    int x, y, ia;
240
276
    int ih = 0;
241
277
    int iv = 0;
242
278
    uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
243
279
 
244
 
    for(x=0; x<4; x++) {
245
 
        ih += (x+1)*(top[5+x]-top[3-x]);
246
 
        iv += (x+1)*(left[5+x]-left[3-x]);
 
280
    for (x = 0; x < 4; x++) {
 
281
        ih += (x + 1) * (top [5 + x] - top [3 - x]);
 
282
        iv += (x + 1) * (left[5 + x] - left[3 - x]);
247
283
    }
248
 
    ia = (top[8]+left[8])<<4;
249
 
    ih = (17*ih+16)>>5;
250
 
    iv = (17*iv+16)>>5;
251
 
    for(y=0; y<8; y++)
252
 
        for(x=0; x<8; x++)
253
 
            d[y*stride+x] = cm[(ia+(x-3)*ih+(y-3)*iv+16)>>5];
 
284
    ia = (top[8] + left[8]) << 4;
 
285
    ih = (17 * ih + 16) >> 5;
 
286
    iv = (17 * iv + 16) >> 5;
 
287
    for (y = 0; y < 8; y++)
 
288
        for (x = 0; x < 8; x++)
 
289
            d[y * stride + x] = cm[(ia + (x - 3) * ih + (y - 3) * iv + 16) >> 5];
254
290
}
255
291
 
256
292
#define LOWPASS(ARRAY,INDEX)                                            \
257
 
    (( ARRAY[(INDEX)-1] + 2*ARRAY[(INDEX)] + ARRAY[(INDEX)+1] + 2) >> 2)
258
 
 
259
 
static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
260
 
    int x,y;
261
 
    for(y=0; y<8; y++)
262
 
        for(x=0; x<8; x++)
263
 
            d[y*stride+x] = (LOWPASS(top,x+1) + LOWPASS(left,y+1)) >> 1;
264
 
}
265
 
 
266
 
static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
267
 
    int x,y;
268
 
    for(y=0; y<8; y++)
269
 
        for(x=0; x<8; x++)
270
 
            d[y*stride+x] = (LOWPASS(top,x+y+2) + LOWPASS(left,x+y+2)) >> 1;
271
 
}
272
 
 
273
 
static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
274
 
    int x,y;
275
 
    for(y=0; y<8; y++)
276
 
        for(x=0; x<8; x++)
277
 
            if(x==y)
278
 
                d[y*stride+x] = (left[1]+2*top[0]+top[1]+2)>>2;
279
 
            else if(x>y)
280
 
                d[y*stride+x] = LOWPASS(top,x-y);
 
293
    ((ARRAY[(INDEX) - 1] + 2 * ARRAY[(INDEX)] + ARRAY[(INDEX) + 1] + 2) >> 2)
 
294
 
 
295
static void intra_pred_lp(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
296
{
 
297
    int x, y;
 
298
    for (y = 0; y < 8; y++)
 
299
        for (x = 0; x < 8; x++)
 
300
            d[y * stride + x] = (LOWPASS(top, x + 1) + LOWPASS(left, y + 1)) >> 1;
 
301
}
 
302
 
 
303
static void intra_pred_down_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
304
{
 
305
    int x, y;
 
306
    for (y = 0; y < 8; y++)
 
307
        for (x = 0; x < 8; x++)
 
308
            d[y * stride + x] = (LOWPASS(top, x + y + 2) + LOWPASS(left, x + y + 2)) >> 1;
 
309
}
 
310
 
 
311
static void intra_pred_down_right(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
312
{
 
313
    int x, y;
 
314
    for (y = 0; y < 8; y++)
 
315
        for (x = 0; x < 8; x++)
 
316
            if (x == y)
 
317
                d[y * stride + x] = (left[1] + 2 * top[0] + top[1] + 2) >> 2;
 
318
            else if (x > y)
 
319
                d[y * stride + x] = LOWPASS(top, x - y);
281
320
            else
282
 
                d[y*stride+x] = LOWPASS(left,y-x);
283
 
}
284
 
 
285
 
static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
286
 
    int x,y;
287
 
    for(y=0; y<8; y++)
288
 
        for(x=0; x<8; x++)
289
 
            d[y*stride+x] = LOWPASS(left,y+1);
290
 
}
291
 
 
292
 
static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
293
 
    int x,y;
294
 
    for(y=0; y<8; y++)
295
 
        for(x=0; x<8; x++)
296
 
            d[y*stride+x] = LOWPASS(top,x+1);
 
321
                d[y * stride + x] = LOWPASS(left, y - x);
 
322
}
 
323
 
 
324
static void intra_pred_lp_left(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
325
{
 
326
    int x, y;
 
327
    for (y = 0; y < 8; y++)
 
328
        for (x = 0; x < 8; x++)
 
329
            d[y * stride + x] = LOWPASS(left, y + 1);
 
330
}
 
331
 
 
332
static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride)
 
333
{
 
334
    int x, y;
 
335
    for (y = 0; y < 8; y++)
 
336
        for (x = 0; x < 8; x++)
 
337
            d[y * stride + x] = LOWPASS(top, x + 1);
297
338
}
298
339
 
299
340
#undef LOWPASS
300
341
 
301
 
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) {
 
342
static inline void modify_pred(const int8_t *mod_table, int *mode)
 
343
{
 
344
    *mode = mod_table[*mode];
 
345
    if (*mode < 0) {
 
346
        av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n");
 
347
        *mode = 0;
 
348
    }
 
349
}
 
350
 
 
351
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv)
 
352
{
302
353
    /* save pred modes before they get modified */
303
354
    h->pred_mode_Y[3] =  h->pred_mode_Y[5];
304
355
    h->pred_mode_Y[6] =  h->pred_mode_Y[8];
305
 
    h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
306
 
    h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
 
356
    h->top_pred_Y[h->mbx * 2 + 0] = h->pred_mode_Y[7];
 
357
    h->top_pred_Y[h->mbx * 2 + 1] = h->pred_mode_Y[8];
307
358
 
308
359
    /* modify pred modes according to availability of neighbour samples */
309
 
    if(!(h->flags & A_AVAIL)) {
310
 
        modify_pred(ff_left_modifier_l, &h->pred_mode_Y[4] );
311
 
        modify_pred(ff_left_modifier_l, &h->pred_mode_Y[7] );
312
 
        modify_pred(ff_left_modifier_c, pred_mode_uv );
 
360
    if (!(h->flags & A_AVAIL)) {
 
361
        modify_pred(left_modifier_l, &h->pred_mode_Y[4]);
 
362
        modify_pred(left_modifier_l, &h->pred_mode_Y[7]);
 
363
        modify_pred(left_modifier_c, pred_mode_uv);
313
364
    }
314
 
    if(!(h->flags & B_AVAIL)) {
315
 
        modify_pred(ff_top_modifier_l, &h->pred_mode_Y[4] );
316
 
        modify_pred(ff_top_modifier_l, &h->pred_mode_Y[5] );
317
 
        modify_pred(ff_top_modifier_c, pred_mode_uv );
 
365
    if (!(h->flags & B_AVAIL)) {
 
366
        modify_pred(top_modifier_l, &h->pred_mode_Y[4]);
 
367
        modify_pred(top_modifier_l, &h->pred_mode_Y[5]);
 
368
        modify_pred(top_modifier_c, pred_mode_uv);
318
369
    }
319
370
}
320
371
 
324
375
 *
325
376
 ****************************************************************************/
326
377
 
327
 
static inline void mc_dir_part(AVSContext *h,Picture *pic,int square,
328
 
                        int chroma_height,int delta,int list,uint8_t *dest_y,
329
 
                        uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
330
 
                        int src_y_offset,qpel_mc_func *qpix_op,
331
 
                        h264_chroma_mc_func chroma_op,cavs_vector *mv){
332
 
    MpegEncContext * const s = &h->s;
 
378
static inline void mc_dir_part(AVSContext *h, AVFrame *pic,
 
379
                               int chroma_height,int delta,int list,uint8_t *dest_y,
 
380
                               uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,
 
381
                               int src_y_offset,qpel_mc_func *qpix_op,
 
382
                               h264_chroma_mc_func chroma_op,cavs_vector *mv)
 
383
{
333
384
    const int mx= mv->x + src_x_offset*8;
334
385
    const int my= mv->y + src_y_offset*8;
335
386
    const int luma_xy= (mx&3) + ((my&3)<<2);
336
 
    uint8_t * src_y  = pic->f.data[0] + (mx >> 2) + (my >> 2) * h->l_stride;
337
 
    uint8_t * src_cb = pic->f.data[1] + (mx >> 3) + (my >> 3) * h->c_stride;
338
 
    uint8_t * src_cr = pic->f.data[2] + (mx >> 3) + (my >> 3) * h->c_stride;
339
 
    int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
 
387
    uint8_t * src_y  = pic->data[0] + (mx >> 2) + (my >> 2) * h->l_stride;
 
388
    uint8_t * src_cb = pic->data[1] + (mx >> 3) + (my >> 3) * h->c_stride;
 
389
    uint8_t * src_cr = pic->data[2] + (mx >> 3) + (my >> 3) * h->c_stride;
 
390
    int extra_width = 0;
340
391
    int extra_height= extra_width;
341
392
    int emu=0;
342
393
    const int full_mx= mx>>2;
344
395
    const int pic_width  = 16*h->mb_width;
345
396
    const int pic_height = 16*h->mb_height;
346
397
 
347
 
    if(!pic->f.data[0])
 
398
    if (!pic->data[0])
348
399
        return;
349
400
    if(mx&7) extra_width -= 3;
350
401
    if(my&7) extra_height -= 3;
353
404
          || full_my < 0-extra_height
354
405
          || full_mx + 16/*FIXME*/ > pic_width + extra_width
355
406
          || full_my + 16/*FIXME*/ > pic_height + extra_height){
356
 
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
 
407
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,
357
408
                            16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
358
 
        src_y= s->edge_emu_buffer + 2 + 2*h->l_stride;
 
409
        src_y= h->edge_emu_buffer + 2 + 2*h->l_stride;
359
410
        emu=1;
360
411
    }
361
412
 
362
413
    qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
363
 
    if(!square){
364
 
        qpix_op[luma_xy](dest_y + delta, src_y + delta, h->l_stride);
365
 
    }
366
414
 
367
415
    if(emu){
368
 
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->c_stride,
 
416
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb, h->c_stride,
369
417
                            9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
370
 
        src_cb= s->edge_emu_buffer;
 
418
        src_cb= h->edge_emu_buffer;
371
419
    }
372
420
    chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
373
421
 
374
422
    if(emu){
375
 
        s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr, h->c_stride,
 
423
        h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr, h->c_stride,
376
424
                            9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
377
 
        src_cr= s->edge_emu_buffer;
 
425
        src_cr= h->edge_emu_buffer;
378
426
    }
379
427
    chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);
380
428
}
381
429
 
382
 
static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int delta,
383
 
                        uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
384
 
                        int x_offset, int y_offset,qpel_mc_func *qpix_put,
385
 
                        h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
386
 
                        h264_chroma_mc_func chroma_avg, cavs_vector *mv){
 
430
static inline void mc_part_std(AVSContext *h,int chroma_height,int delta,
 
431
                               uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,
 
432
                               int x_offset, int y_offset,qpel_mc_func *qpix_put,
 
433
                               h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,
 
434
                               h264_chroma_mc_func chroma_avg, cavs_vector *mv)
 
435
{
387
436
    qpel_mc_func *qpix_op=  qpix_put;
388
437
    h264_chroma_mc_func chroma_op= chroma_put;
389
438
 
394
443
    y_offset += 8*h->mby;
395
444
 
396
445
    if(mv->ref >= 0){
397
 
        Picture *ref= &h->DPB[mv->ref];
398
 
        mc_dir_part(h, ref, square, chroma_height, delta, 0,
 
446
        AVFrame *ref = h->DPB[mv->ref].f;
 
447
        mc_dir_part(h, ref, chroma_height, delta, 0,
399
448
                    dest_y, dest_cb, dest_cr, x_offset, y_offset,
400
449
                    qpix_op, chroma_op, mv);
401
450
 
404
453
    }
405
454
 
406
455
    if((mv+MV_BWD_OFFS)->ref >= 0){
407
 
        Picture *ref= &h->DPB[0];
408
 
        mc_dir_part(h, ref, square, chroma_height, delta, 1,
 
456
        AVFrame *ref = h->DPB[0].f;
 
457
        mc_dir_part(h, ref, chroma_height, delta, 1,
409
458
                    dest_y, dest_cb, dest_cr, x_offset, y_offset,
410
459
                    qpix_op, chroma_op, mv+MV_BWD_OFFS);
411
460
    }
413
462
 
414
463
void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) {
415
464
    if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16
416
 
        mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0,
 
465
        mc_part_std(h, 8, 0, h->cy, h->cu, h->cv, 0, 0,
417
466
                h->cdsp.put_cavs_qpel_pixels_tab[0],
418
 
                h->s.dsp.put_h264_chroma_pixels_tab[0],
 
467
                h->dsp.put_h264_chroma_pixels_tab[0],
419
468
                h->cdsp.avg_cavs_qpel_pixels_tab[0],
420
 
                h->s.dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]);
 
469
                h->dsp.avg_h264_chroma_pixels_tab[0],&h->mv[MV_FWD_X0]);
421
470
    }else{
422
 
        mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 0,
423
 
                h->cdsp.put_cavs_qpel_pixels_tab[1],
424
 
                h->s.dsp.put_h264_chroma_pixels_tab[1],
425
 
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
426
 
                h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
427
 
        mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 0,
428
 
                h->cdsp.put_cavs_qpel_pixels_tab[1],
429
 
                h->s.dsp.put_h264_chroma_pixels_tab[1],
430
 
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
431
 
                h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
432
 
        mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 0, 4,
433
 
                h->cdsp.put_cavs_qpel_pixels_tab[1],
434
 
                h->s.dsp.put_h264_chroma_pixels_tab[1],
435
 
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
436
 
                h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
437
 
        mc_part_std(h, 1, 4, 0, h->cy, h->cu, h->cv, 4, 4,
438
 
                h->cdsp.put_cavs_qpel_pixels_tab[1],
439
 
                h->s.dsp.put_h264_chroma_pixels_tab[1],
440
 
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
441
 
                h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
 
471
        mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 0,
 
472
                h->cdsp.put_cavs_qpel_pixels_tab[1],
 
473
                h->dsp.put_h264_chroma_pixels_tab[1],
 
474
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
 
475
                h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X0]);
 
476
        mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 0,
 
477
                h->cdsp.put_cavs_qpel_pixels_tab[1],
 
478
                h->dsp.put_h264_chroma_pixels_tab[1],
 
479
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
 
480
                h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X1]);
 
481
        mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 4,
 
482
                h->cdsp.put_cavs_qpel_pixels_tab[1],
 
483
                h->dsp.put_h264_chroma_pixels_tab[1],
 
484
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
 
485
                h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X2]);
 
486
        mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 4,
 
487
                h->cdsp.put_cavs_qpel_pixels_tab[1],
 
488
                h->dsp.put_h264_chroma_pixels_tab[1],
 
489
                h->cdsp.avg_cavs_qpel_pixels_tab[1],
 
490
                h->dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]);
442
491
    }
443
492
}
444
493
 
497
546
       ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) ||
498
547
           ((mvA->x | mvA->y | mvA->ref) == 0)  ||
499
548
           ((mvB->x | mvB->y | mvB->ref) == 0) )) {
500
 
        mvP2 = &ff_cavs_un_mv;
 
549
        mvP2 = &un_mv;
501
550
    /* if there is only one suitable candidate, take it */
502
551
    } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) {
503
552
        mvP2= mvA;
519
568
        mv_pred_median(h, mvP, mvA, mvB, mvC);
520
569
 
521
570
    if(mode < MV_PRED_PSKIP) {
522
 
        mvP->x += get_se_golomb(&h->s.gb);
523
 
        mvP->y += get_se_golomb(&h->s.gb);
 
571
        mvP->x += get_se_golomb(&h->gb);
 
572
        mvP->y += get_se_golomb(&h->gb);
524
573
    }
525
574
    set_mvs(mvP,size);
526
575
}
546
595
    h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
547
596
    /* clear top predictors if MB B is not available */
548
597
    if(!(h->flags & B_AVAIL)) {
549
 
        h->mv[MV_FWD_B2] = ff_cavs_un_mv;
550
 
        h->mv[MV_FWD_B3] = ff_cavs_un_mv;
551
 
        h->mv[MV_BWD_B2] = ff_cavs_un_mv;
552
 
        h->mv[MV_BWD_B3] = ff_cavs_un_mv;
 
598
        h->mv[MV_FWD_B2] = un_mv;
 
599
        h->mv[MV_FWD_B3] = un_mv;
 
600
        h->mv[MV_BWD_B2] = un_mv;
 
601
        h->mv[MV_BWD_B3] = un_mv;
553
602
        h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
554
603
        h->flags &= ~(C_AVAIL|D_AVAIL);
555
604
    } else if(h->mbx) {
559
608
        h->flags &= ~C_AVAIL;
560
609
    /* clear top-right predictors if MB C is not available */
561
610
    if(!(h->flags & C_AVAIL)) {
562
 
        h->mv[MV_FWD_C2] = ff_cavs_un_mv;
563
 
        h->mv[MV_BWD_C2] = ff_cavs_un_mv;
 
611
        h->mv[MV_FWD_C2] = un_mv;
 
612
        h->mv[MV_BWD_C2] = un_mv;
564
613
    }
565
614
    /* clear top-left predictors if MB D is not available */
566
615
    if(!(h->flags & D_AVAIL)) {
567
 
        h->mv[MV_FWD_D3] = ff_cavs_un_mv;
568
 
        h->mv[MV_BWD_D3] = ff_cavs_un_mv;
 
616
        h->mv[MV_FWD_D3] = un_mv;
 
617
        h->mv[MV_BWD_D3] = un_mv;
569
618
    }
570
619
}
571
620
 
598
647
        h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
599
648
        /* clear left mv predictors */
600
649
        for(i=0;i<=20;i+=4)
601
 
            h->mv[i] = ff_cavs_un_mv;
 
650
            h->mv[i] = un_mv;
602
651
        h->mbx = 0;
603
652
        h->mby++;
604
653
        /* re-calculate sample pointers */
605
 
        h->cy = h->picture.f.data[0] + h->mby * 16 * h->l_stride;
606
 
        h->cu = h->picture.f.data[1] + h->mby *  8 * h->c_stride;
607
 
        h->cv = h->picture.f.data[2] + h->mby *  8 * h->c_stride;
 
654
        h->cy = h->cur.f->data[0] + h->mby * 16 * h->l_stride;
 
655
        h->cu = h->cur.f->data[1] + h->mby *  8 * h->c_stride;
 
656
        h->cv = h->cur.f->data[2] + h->mby *  8 * h->c_stride;
608
657
        if(h->mby == h->mb_height) { //frame end
609
658
            return 0;
610
659
        }
623
672
 
624
673
    /* clear some predictors */
625
674
    for(i=0;i<=20;i+=4)
626
 
        h->mv[i] = ff_cavs_un_mv;
 
675
        h->mv[i] = un_mv;
627
676
    h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
628
677
    set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
629
678
    h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
630
679
    set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
631
680
    h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
632
 
    h->cy           = h->picture.f.data[0];
633
 
    h->cu           = h->picture.f.data[1];
634
 
    h->cv           = h->picture.f.data[2];
635
 
    h->l_stride     = h->picture.f.linesize[0];
636
 
    h->c_stride     = h->picture.f.linesize[1];
 
681
    h->cy           = h->cur.f->data[0];
 
682
    h->cu           = h->cur.f->data[1];
 
683
    h->cv           = h->cur.f->data[2];
 
684
    h->l_stride     = h->cur.f->linesize[0];
 
685
    h->c_stride     = h->cur.f->linesize[1];
637
686
    h->luma_scan[2] = 8*h->l_stride;
638
687
    h->luma_scan[3] = 8*h->l_stride+8;
639
688
    h->mbx = h->mby = h->mbidx = 0;
653
702
 */
654
703
void ff_cavs_init_top_lines(AVSContext *h) {
655
704
    /* alloc top line of predictors */
656
 
    h->top_qp       = av_malloc( h->mb_width);
657
 
    h->top_mv[0]    = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector));
658
 
    h->top_mv[1]    = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector));
659
 
    h->top_pred_Y   = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y));
660
 
    h->top_border_y = av_malloc((h->mb_width+1)*16);
661
 
    h->top_border_u = av_malloc( h->mb_width * 10);
662
 
    h->top_border_v = av_malloc( h->mb_width * 10);
 
705
    h->top_qp       = av_mallocz( h->mb_width);
 
706
    h->top_mv[0]    = av_mallocz((h->mb_width*2+1)*sizeof(cavs_vector));
 
707
    h->top_mv[1]    = av_mallocz((h->mb_width*2+1)*sizeof(cavs_vector));
 
708
    h->top_pred_Y   = av_mallocz( h->mb_width*2*sizeof(*h->top_pred_Y));
 
709
    h->top_border_y = av_mallocz((h->mb_width+1)*16);
 
710
    h->top_border_u = av_mallocz( h->mb_width * 10);
 
711
    h->top_border_v = av_mallocz( h->mb_width * 10);
663
712
 
664
713
    /* alloc space for co-located MVs and types */
665
 
    h->col_mv       = av_malloc( h->mb_width*h->mb_height*4*sizeof(cavs_vector));
666
 
    h->col_type_base = av_malloc(h->mb_width*h->mb_height);
 
714
    h->col_mv       = av_mallocz( h->mb_width*h->mb_height*4*sizeof(cavs_vector));
 
715
    h->col_type_base = av_mallocz(h->mb_width*h->mb_height);
667
716
    h->block        = av_mallocz(64*sizeof(DCTELEM));
668
717
}
669
718
 
670
719
av_cold int ff_cavs_init(AVCodecContext *avctx) {
671
720
    AVSContext *h = avctx->priv_data;
672
 
    MpegEncContext * const s = &h->s;
673
721
 
674
 
    MPV_decode_defaults(s);
 
722
    ff_dsputil_init(&h->dsp, avctx);
 
723
    ff_videodsp_init(&h->vdsp, 8);
675
724
    ff_cavsdsp_init(&h->cdsp, avctx);
676
 
    s->avctx = avctx;
677
 
 
678
 
    avctx->pix_fmt= PIX_FMT_YUV420P;
 
725
    ff_init_scantable_permutation(h->dsp.idct_permutation,
 
726
                                  h->cdsp.idct_perm);
 
727
    ff_init_scantable(h->dsp.idct_permutation, &h->scantable, ff_zigzag_direct);
 
728
 
 
729
    h->avctx = avctx;
 
730
    avctx->pix_fmt= AV_PIX_FMT_YUV420P;
 
731
 
 
732
    h->cur.f    = avcodec_alloc_frame();
 
733
    h->DPB[0].f = avcodec_alloc_frame();
 
734
    h->DPB[1].f = avcodec_alloc_frame();
 
735
    if (!h->cur.f || !h->DPB[0].f || !h->DPB[1].f) {
 
736
        ff_cavs_end(avctx);
 
737
        return AVERROR(ENOMEM);
 
738
    }
679
739
 
680
740
    h->luma_scan[0] = 0;
681
741
    h->luma_scan[1] = 8;
694
754
    h->intra_pred_c[   INTRA_C_LP_LEFT] = intra_pred_lp_left;
695
755
    h->intra_pred_c[    INTRA_C_LP_TOP] = intra_pred_lp_top;
696
756
    h->intra_pred_c[    INTRA_C_DC_128] = intra_pred_dc_128;
697
 
    h->mv[ 7] = ff_cavs_un_mv;
698
 
    h->mv[19] = ff_cavs_un_mv;
 
757
    h->mv[ 7] = un_mv;
 
758
    h->mv[19] = un_mv;
699
759
    return 0;
700
760
}
701
761
 
702
762
av_cold int ff_cavs_end(AVCodecContext *avctx) {
703
763
    AVSContext *h = avctx->priv_data;
704
764
 
 
765
    if (h->cur.f->data[0])
 
766
        avctx->release_buffer(avctx, h->cur.f);
 
767
    if (h->DPB[0].f->data[0])
 
768
        avctx->release_buffer(avctx, h->DPB[0].f);
 
769
    if (h->DPB[1].f->data[0])
 
770
        avctx->release_buffer(avctx, h->DPB[1].f);
 
771
    avcodec_free_frame(&h->cur.f);
 
772
    avcodec_free_frame(&h->DPB[0].f);
 
773
    avcodec_free_frame(&h->DPB[1].f);
 
774
 
705
775
    av_free(h->top_qp);
706
776
    av_free(h->top_mv[0]);
707
777
    av_free(h->top_mv[1]);
712
782
    av_free(h->col_mv);
713
783
    av_free(h->col_type_base);
714
784
    av_free(h->block);
 
785
    av_freep(&h->edge_emu_buffer);
715
786
    return 0;
716
787
}