Revision 5d2b15b8

View differences:

libavcodec/cavs.c
143 143
 *
144 144
 ****************************************************************************/
145 145

  
146
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top,
147
                                        uint8_t **left, int block) {
148
    int i;
149

  
150
    switch(block) {
151
    case 0:
152
        *left = h->left_border_y;
153
        h->left_border_y[0] = h->left_border_y[1];
154
        memset(&h->left_border_y[17],h->left_border_y[16],9);
155
        memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
156
        top[17] = top[16];
157
        top[0] = top[1];
158
        if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
159
            h->left_border_y[0] = top[0] = h->topleft_border_y;
160
        break;
161
    case 1:
162
        *left = h->intern_border_y;
163
        for(i=0;i<8;i++)
164
            h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
165
        memset(&h->intern_border_y[9],h->intern_border_y[8],9);
166
        h->intern_border_y[0] = h->intern_border_y[1];
167
        memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
168
        if(h->flags & C_AVAIL)
169
            memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
170
        else
171
            memset(&top[9],top[8],9);
172
        top[17] = top[16];
173
        top[0] = top[1];
174
        if(h->flags & B_AVAIL)
175
            h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
176
        break;
177
    case 2:
178
        *left = &h->left_border_y[8];
179
        memcpy(&top[1],h->cy + 7*h->l_stride,16);
180
        top[17] = top[16];
181
        top[0] = top[1];
182
        if(h->flags & A_AVAIL)
183
            top[0] = h->left_border_y[8];
184
        break;
185
    case 3:
186
        *left = &h->intern_border_y[8];
187
        for(i=0;i<8;i++)
188
            h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
189
        memset(&h->intern_border_y[17],h->intern_border_y[16],9);
190
        memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
191
        memset(&top[9],top[8],9);
192
        break;
193
    }
194
}
195

  
196
void ff_cavs_load_intra_pred_chroma(AVSContext *h) {
197
    /* extend borders by one pixel */
198
    h->left_border_u[9] = h->left_border_u[8];
199
    h->left_border_v[9] = h->left_border_v[8];
200
    h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
201
    h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
202
    if(h->mbx && h->mby) {
203
        h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
204
        h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
205
    } else {
206
        h->left_border_u[0] = h->left_border_u[1];
207
        h->left_border_v[0] = h->left_border_v[1];
208
        h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
209
        h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
210
    }
211
}
212

  
146 213
static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) {
147 214
    int y;
148 215
    uint64_t a = unaligned64(&top[1]);
......
230 297

  
231 298
#undef LOWPASS
232 299

  
300
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) {
301
    /* save pred modes before they get modified */
302
    h->pred_mode_Y[3] =  h->pred_mode_Y[5];
303
    h->pred_mode_Y[6] =  h->pred_mode_Y[8];
304
    h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
305
    h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
306

  
307
    /* modify pred modes according to availability of neighbour samples */
308
    if(!(h->flags & A_AVAIL)) {
309
        modify_pred(ff_left_modifier_l, &h->pred_mode_Y[4] );
310
        modify_pred(ff_left_modifier_l, &h->pred_mode_Y[7] );
311
        modify_pred(ff_left_modifier_c, pred_mode_uv );
312
    }
313
    if(!(h->flags & B_AVAIL)) {
314
        modify_pred(ff_top_modifier_l, &h->pred_mode_Y[4] );
315
        modify_pred(ff_top_modifier_l, &h->pred_mode_Y[5] );
316
        modify_pred(ff_top_modifier_c, pred_mode_uv );
317
    }
318
}
319

  
233 320
/*****************************************************************************
234 321
 *
235 322
 * motion compensation
......
438 525

  
439 526
/*****************************************************************************
440 527
 *
528
 * macroblock level
529
 *
530
 ****************************************************************************/
531

  
532
/**
533
 * initialise predictors for motion vectors and intra prediction
534
 */
535
void ff_cavs_init_mb(AVSContext *h) {
536
    int i;
537

  
538
    /* copy predictors from top line (MB B and C) into cache */
539
    for(i=0;i<3;i++) {
540
        h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
541
        h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
542
    }
543
    h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
544
    h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
545
    /* clear top predictors if MB B is not available */
546
    if(!(h->flags & B_AVAIL)) {
547
        h->mv[MV_FWD_B2] = ff_cavs_un_mv;
548
        h->mv[MV_FWD_B3] = ff_cavs_un_mv;
549
        h->mv[MV_BWD_B2] = ff_cavs_un_mv;
550
        h->mv[MV_BWD_B3] = ff_cavs_un_mv;
551
        h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
552
        h->flags &= ~(C_AVAIL|D_AVAIL);
553
    } else if(h->mbx) {
554
        h->flags |= D_AVAIL;
555
    }
556
    if(h->mbx == h->mb_width-1) //MB C not available
557
        h->flags &= ~C_AVAIL;
558
    /* clear top-right predictors if MB C is not available */
559
    if(!(h->flags & C_AVAIL)) {
560
        h->mv[MV_FWD_C2] = ff_cavs_un_mv;
561
        h->mv[MV_BWD_C2] = ff_cavs_un_mv;
562
    }
563
    /* clear top-left predictors if MB D is not available */
564
    if(!(h->flags & D_AVAIL)) {
565
        h->mv[MV_FWD_D3] = ff_cavs_un_mv;
566
        h->mv[MV_BWD_D3] = ff_cavs_un_mv;
567
    }
568
    /* set pointer for co-located macroblock type */
569
    h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
570
}
571

  
572
/**
573
 * save predictors for later macroblocks and increase
574
 * macroblock address
575
 * @returns 0 if end of frame is reached, 1 otherwise
576
 */
577
int ff_cavs_next_mb(AVSContext *h) {
578
    int i;
579

  
580
    h->flags |= A_AVAIL;
581
    h->cy += 16;
582
    h->cu += 8;
583
    h->cv += 8;
584
    /* copy mvs as predictors to the left */
585
    for(i=0;i<=20;i+=4)
586
        h->mv[i] = h->mv[i+2];
587
    /* copy bottom mvs from cache to top line */
588
    h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
589
    h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
590
    h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
591
    h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
592
    /* next MB address */
593
    h->mbx++;
594
    if(h->mbx == h->mb_width) { //new mb line
595
        h->flags = B_AVAIL|C_AVAIL;
596
        /* clear left pred_modes */
597
        h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
598
        /* clear left mv predictors */
599
        for(i=0;i<=20;i+=4)
600
            h->mv[i] = ff_cavs_un_mv;
601
        h->mbx = 0;
602
        h->mby++;
603
        /* re-calculate sample pointers */
604
        h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
605
        h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
606
        h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
607
        if(h->mby == h->mb_height) { //frame end
608
            return 0;
609
        } else {
610
            //check_for_slice(h);
611
        }
612
    }
613
    return 1;
614
}
615

  
616
/*****************************************************************************
617
 *
441 618
 * frame level
442 619
 *
443 620
 ****************************************************************************/
libavcodec/cavs.h
240 240
extern const vector_t ff_cavs_un_mv;
241 241
extern const vector_t ff_cavs_dir_mv;
242 242

  
243
static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top,
244
                                        uint8_t **left, int block) {
245
    int i;
246

  
247
    switch(block) {
248
    case 0:
249
        *left = h->left_border_y;
250
        h->left_border_y[0] = h->left_border_y[1];
251
        memset(&h->left_border_y[17],h->left_border_y[16],9);
252
        memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
253
        top[17] = top[16];
254
        top[0] = top[1];
255
        if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
256
            h->left_border_y[0] = top[0] = h->topleft_border_y;
257
        break;
258
    case 1:
259
        *left = h->intern_border_y;
260
        for(i=0;i<8;i++)
261
            h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
262
        memset(&h->intern_border_y[9],h->intern_border_y[8],9);
263
        h->intern_border_y[0] = h->intern_border_y[1];
264
        memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
265
        if(h->flags & C_AVAIL)
266
            memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
267
        else
268
            memset(&top[9],top[8],9);
269
        top[17] = top[16];
270
        top[0] = top[1];
271
        if(h->flags & B_AVAIL)
272
            h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
273
        break;
274
    case 2:
275
        *left = &h->left_border_y[8];
276
        memcpy(&top[1],h->cy + 7*h->l_stride,16);
277
        top[17] = top[16];
278
        top[0] = top[1];
279
        if(h->flags & A_AVAIL)
280
            top[0] = h->left_border_y[8];
281
        break;
282
    case 3:
283
        *left = &h->intern_border_y[8];
284
        for(i=0;i<8;i++)
285
            h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
286
        memset(&h->intern_border_y[17],h->intern_border_y[16],9);
287
        memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
288
        memset(&top[9],top[8],9);
289
        break;
290
    }
291
}
292

  
293
static inline void load_intra_pred_chroma(AVSContext *h) {
294
    /* extend borders by one pixel */
295
    h->left_border_u[9] = h->left_border_u[8];
296
    h->left_border_v[9] = h->left_border_v[8];
297
    h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8];
298
    h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8];
299
    if(h->mbx && h->mby) {
300
        h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u;
301
        h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v;
302
    } else {
303
        h->left_border_u[0] = h->left_border_u[1];
304
        h->left_border_v[0] = h->left_border_v[1];
305
        h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1];
306
        h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1];
307
    }
308
}
309

  
310 243
static inline void modify_pred(const int_fast8_t *mod_table, int *mode) {
311 244
    *mode = mod_table[*mode];
312 245
    if(*mode < 0) {
......
315 248
    }
316 249
}
317 250

  
318
static inline void modify_mb_i(AVSContext *h, int *pred_mode_uv) {
319
    /* save pred modes before they get modified */
320
    h->pred_mode_Y[3] =  h->pred_mode_Y[5];
321
    h->pred_mode_Y[6] =  h->pred_mode_Y[8];
322
    h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7];
323
    h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8];
324

  
325
    /* modify pred modes according to availability of neighbour samples */
326
    if(!(h->flags & A_AVAIL)) {
327
        modify_pred(ff_left_modifier_l, &h->pred_mode_Y[4] );
328
        modify_pred(ff_left_modifier_l, &h->pred_mode_Y[7] );
329
        modify_pred(ff_left_modifier_c, pred_mode_uv );
330
    }
331
    if(!(h->flags & B_AVAIL)) {
332
        modify_pred(ff_top_modifier_l, &h->pred_mode_Y[4] );
333
        modify_pred(ff_top_modifier_l, &h->pred_mode_Y[5] );
334
        modify_pred(ff_top_modifier_c, pred_mode_uv );
335
    }
336
}
337

  
338 251
static inline void set_intra_mode_default(AVSContext *h) {
339 252
    h->pred_mode_Y[3] =  h->pred_mode_Y[6] = INTRA_L_LP;
340 253
    h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP;
......
363 276
        *h->col_type = I_8X8;
364 277
}
365 278

  
366

  
367
/**
368
 * initialise predictors for motion vectors and intra prediction
369
 */
370
static inline void init_mb(AVSContext *h) {
371
    int i;
372

  
373
    /* copy predictors from top line (MB B and C) into cache */
374
    for(i=0;i<3;i++) {
375
        h->mv[MV_FWD_B2+i] = h->top_mv[0][h->mbx*2+i];
376
        h->mv[MV_BWD_B2+i] = h->top_mv[1][h->mbx*2+i];
377
    }
378
    h->pred_mode_Y[1] = h->top_pred_Y[h->mbx*2+0];
379
    h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1];
380
    /* clear top predictors if MB B is not available */
381
    if(!(h->flags & B_AVAIL)) {
382
        h->mv[MV_FWD_B2] = ff_cavs_un_mv;
383
        h->mv[MV_FWD_B3] = ff_cavs_un_mv;
384
        h->mv[MV_BWD_B2] = ff_cavs_un_mv;
385
        h->mv[MV_BWD_B3] = ff_cavs_un_mv;
386
        h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL;
387
        h->flags &= ~(C_AVAIL|D_AVAIL);
388
    } else if(h->mbx) {
389
        h->flags |= D_AVAIL;
390
    }
391
    if(h->mbx == h->mb_width-1) //MB C not available
392
        h->flags &= ~C_AVAIL;
393
    /* clear top-right predictors if MB C is not available */
394
    if(!(h->flags & C_AVAIL)) {
395
        h->mv[MV_FWD_C2] = ff_cavs_un_mv;
396
        h->mv[MV_BWD_C2] = ff_cavs_un_mv;
397
    }
398
    /* clear top-left predictors if MB D is not available */
399
    if(!(h->flags & D_AVAIL)) {
400
        h->mv[MV_FWD_D3] = ff_cavs_un_mv;
401
        h->mv[MV_BWD_D3] = ff_cavs_un_mv;
402
    }
403
    /* set pointer for co-located macroblock type */
404
    h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx];
405
}
406

  
407
/**
408
 * save predictors for later macroblocks and increase
409
 * macroblock address
410
 * @returns 0 if end of frame is reached, 1 otherwise
411
 */
412
static inline int next_mb(AVSContext *h) {
413
    int i;
414

  
415
    h->flags |= A_AVAIL;
416
    h->cy += 16;
417
    h->cu += 8;
418
    h->cv += 8;
419
    /* copy mvs as predictors to the left */
420
    for(i=0;i<=20;i+=4)
421
        h->mv[i] = h->mv[i+2];
422
    /* copy bottom mvs from cache to top line */
423
    h->top_mv[0][h->mbx*2+0] = h->mv[MV_FWD_X2];
424
    h->top_mv[0][h->mbx*2+1] = h->mv[MV_FWD_X3];
425
    h->top_mv[1][h->mbx*2+0] = h->mv[MV_BWD_X2];
426
    h->top_mv[1][h->mbx*2+1] = h->mv[MV_BWD_X3];
427
    /* next MB address */
428
    h->mbx++;
429
    if(h->mbx == h->mb_width) { //new mb line
430
        h->flags = B_AVAIL|C_AVAIL;
431
        /* clear left pred_modes */
432
        h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
433
        /* clear left mv predictors */
434
        for(i=0;i<=20;i+=4)
435
            h->mv[i] = ff_cavs_un_mv;
436
        h->mbx = 0;
437
        h->mby++;
438
        /* re-calculate sample pointers */
439
        h->cy = h->picture.data[0] + h->mby*16*h->l_stride;
440
        h->cu = h->picture.data[1] + h->mby*8*h->c_stride;
441
        h->cv = h->picture.data[2] + h->mby*8*h->c_stride;
442
        if(h->mby == h->mb_height) { //frame end
443
            return 0;
444
        } else {
445
            //check_for_slice(h);
446
        }
447
    }
448
    return 1;
449
}
450

  
451 279
static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf,
452 280
                          DCTELEM *dst, int mul, int shift, int coeff_num) {
453 281
    int round = 1 << (shift - 1);
......
469 297
}
470 298

  
471 299
void ff_cavs_filter(AVSContext *h, enum mb_t mb_type);
300
void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left,
301
                                  int block);
302
void ff_cavs_load_intra_pred_chroma(AVSContext *h);
303
void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv);
472 304
void ff_cavs_inter(AVSContext *h, enum mb_t mb_type);
473 305
void ff_cavs_mv(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC,
474 306
                enum mv_pred_t mode, enum block_t size, int ref);
307
void ff_cavs_init_mb(AVSContext *h);
308
int  ff_cavs_next_mb(AVSContext *h);
475 309
void ff_cavs_init_pic(AVSContext *h);
476 310
void ff_cavs_init_top_lines(AVSContext *h);
477 311
int ff_cavs_init(AVCodecContext *avctx);
libavcodec/cavsdec.c
193 193
    uint8_t *left = NULL;
194 194
    uint8_t *d;
195 195

  
196
    init_mb(h);
196
    ff_cavs_init_mb(h);
197 197

  
198 198
    /* get intra prediction modes from stream */
199 199
    for(block=0;block<4;block++) {
......
216 216
        av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
217 217
        return -1;
218 218
    }
219
    modify_mb_i(h, &pred_mode_uv);
219
    ff_cavs_modify_mb_i(h, &pred_mode_uv);
220 220

  
221 221
    /* get coded block pattern */
222 222
    if(h->pic_type == FF_I_TYPE)
......
232 232
    /* luma intra prediction interleaved with residual decode/transform/add */
233 233
    for(block=0;block<4;block++) {
234 234
        d = h->cy + h->luma_scan[block];
235
        load_intra_pred_luma(h, top, &left, block);
235
        ff_cavs_load_intra_pred_luma(h, top, &left, block);
236 236
        h->intra_pred_l[h->pred_mode_Y[ff_cavs_scan3x3[block]]]
237 237
            (d, top, left, h->l_stride);
238 238
        if(h->cbp & (1<<block))
......
240 240
    }
241 241

  
242 242
    /* chroma intra prediction */
243
    load_intra_pred_chroma(h);
243
    ff_cavs_load_intra_pred_chroma(h);
244 244
    h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10],
245 245
                                  h->left_border_u, h->c_stride);
246 246
    h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10],
......
256 256
    GetBitContext *gb = &h->s.gb;
257 257
    int ref[4];
258 258

  
259
    init_mb(h);
259
    ff_cavs_init_mb(h);
260 260
    switch(mb_type) {
261 261
    case P_SKIP:
262 262
        ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP,  BLK_16X16, 0);
......
301 301
    enum sub_mb_t sub_type[4];
302 302
    int flags;
303 303

  
304
    init_mb(h);
304
    ff_cavs_init_mb(h);
305 305

  
306 306
    /* reset all MVs */
307 307
    h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
......
527 527
    if(h->pic_type == FF_I_TYPE) {
528 528
        do {
529 529
            decode_mb_i(h, 0);
530
        } while(next_mb(h));
530
        } while(ff_cavs_next_mb(h));
531 531
    } else if(h->pic_type == FF_P_TYPE) {
532 532
        do {
533 533
            if(h->skip_mode_flag) {
534 534
                skip_count = get_ue_golomb(&s->gb);
535 535
                while(skip_count--) {
536 536
                    decode_mb_p(h,P_SKIP);
537
                    if(!next_mb(h))
537
                    if(!ff_cavs_next_mb(h))
538 538
                        goto done;
539 539
                }
540 540
                mb_type = get_ue_golomb(&s->gb) + P_16X16;
......
544 544
                decode_mb_i(h, mb_type - P_8X8 - 1);
545 545
            } else
546 546
                decode_mb_p(h,mb_type);
547
        } while(next_mb(h));
547
        } while(ff_cavs_next_mb(h));
548 548
    } else { /* FF_B_TYPE */
549 549
        do {
550 550
            if(h->skip_mode_flag) {
551 551
                skip_count = get_ue_golomb(&s->gb);
552 552
                while(skip_count--) {
553 553
                    decode_mb_b(h,B_SKIP);
554
                    if(!next_mb(h))
554
                    if(!ff_cavs_next_mb(h))
555 555
                        goto done;
556 556
                }
557 557
                mb_type = get_ue_golomb(&s->gb) + B_DIRECT;
......
561 561
                decode_mb_i(h, mb_type - B_8X8 - 1);
562 562
            } else
563 563
                decode_mb_b(h,mb_type);
564
        } while(next_mb(h));
564
        } while(ff_cavs_next_mb(h));
565 565
    }
566 566
 done:
567 567
    if(h->pic_type != FF_B_TYPE) {

Also available in: Unified diff