Mercurial > libavcodec.hg
comparison cavs.c @ 3395:adccbf4a1040 libavcodec
CAVS decoder by (Stefan Gehrer stefan.gehrer gmx.de)
author | michael |
---|---|
date | Mon, 03 Jul 2006 00:16:45 +0000 |
parents | b956afdc00d9 |
children | 34d3e497e310 |
comparison
equal
deleted
inserted
replaced
3394:2b5283c15310 | 3395:adccbf4a1040 |
---|---|
74 int cbp; | 74 int cbp; |
75 | 75 |
76 /* intra prediction is done with un-deblocked samples | 76 /* intra prediction is done with un-deblocked samples |
77 they are saved here before deblocking the MB */ | 77 they are saved here before deblocking the MB */ |
78 uint8_t *top_border_y, *top_border_u, *top_border_v; | 78 uint8_t *top_border_y, *top_border_u, *top_border_v; |
79 uint8_t left_border_y[16], left_border_u[8], left_border_v[8]; | 79 uint8_t left_border_y[16], left_border_u[10], left_border_v[10]; |
80 uint8_t topleft_border_y, topleft_border_u, topleft_border_v; | 80 uint8_t topleft_border_y, topleft_border_u, topleft_border_v; |
81 | 81 |
82 void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); | 82 void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); |
83 void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); | 83 void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); |
84 uint8_t *col_type_base; | 84 uint8_t *col_type_base; |
134 alpha = alpha_tab[clip(qp_avg + h->alpha_offset,0,63)]; \ | 134 alpha = alpha_tab[clip(qp_avg + h->alpha_offset,0,63)]; \ |
135 beta = beta_tab[clip(qp_avg + h->beta_offset, 0,63)]; \ | 135 beta = beta_tab[clip(qp_avg + h->beta_offset, 0,63)]; \ |
136 tc = tc_tab[clip(qp_avg + h->alpha_offset,0,63)]; | 136 tc = tc_tab[clip(qp_avg + h->alpha_offset,0,63)]; |
137 | 137 |
138 static void filter_mb(AVSContext *h, enum mb_t mb_type) { | 138 static void filter_mb(AVSContext *h, enum mb_t mb_type) { |
139 uint8_t bs[8]; | 139 DECLARE_ALIGNED_8(uint8_t, bs[8]); |
140 int qp_avg, alpha, beta, tc; | 140 int qp_avg, alpha, beta, tc; |
141 int i; | 141 int i; |
142 | 142 |
143 /* save un-deblocked lines */ | 143 /* save un-deblocked lines */ |
144 h->topleft_border_y = h->top_border_y[h->mbx*16+15]; | 144 h->topleft_border_y = h->top_border_y[h->mbx*16+15]; |
145 h->topleft_border_u = h->top_border_u[h->mbx*8+7]; | 145 h->topleft_border_u = h->top_border_u[h->mbx*10+8]; |
146 h->topleft_border_v = h->top_border_v[h->mbx*8+7]; | 146 h->topleft_border_v = h->top_border_v[h->mbx*10+8]; |
147 memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16); | 147 memcpy(&h->top_border_y[h->mbx*16], h->cy + 15* h->l_stride,16); |
148 memcpy(&h->top_border_u[h->mbx* 8], h->cu + 7* h->c_stride,8); | 148 memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8); |
149 memcpy(&h->top_border_v[h->mbx* 8], h->cv + 7* h->c_stride,8); | 149 memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8); |
150 for(i=0;i<8;i++) { | 150 for(i=0;i<8;i++) { |
151 h->left_border_y[i*2+0] = *(h->cy + 15 + (i*2+0)*h->l_stride); | 151 h->left_border_y[i*2+0] = *(h->cy + 15 + (i*2+0)*h->l_stride); |
152 h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+1)*h->l_stride); | 152 h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+1)*h->l_stride); |
153 h->left_border_u[i] = *(h->cu + 7 + i*h->c_stride); | 153 h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride); |
154 h->left_border_v[i] = *(h->cv + 7 + i*h->c_stride); | 154 h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride); |
155 } | 155 } |
156 if(!h->loop_filter_disable) { | 156 if(!h->loop_filter_disable) { |
157 /* clear bs */ | 157 /* clear bs */ |
158 *((uint64_t *)bs) = 0; | 158 *((uint64_t *)bs) = 0; |
159 /* determine bs */ | 159 /* determine bs */ |
284 memset(&top[9],top[8],9); | 284 memset(&top[9],top[8],9); |
285 break; | 285 break; |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 static inline void load_intra_pred_chroma(uint8_t *stop, uint8_t *sleft, | |
290 uint8_t stopleft, uint8_t *dtop, | |
291 uint8_t *dleft, int stride, int flags) { | |
292 int i; | |
293 | |
294 if(flags & A_AVAIL) { | |
295 for(i=0; i<8; i++) | |
296 dleft[i+1] = sleft[i]; | |
297 dleft[0] = dleft[1]; | |
298 dleft[9] = dleft[8]; | |
299 } | |
300 if(flags & B_AVAIL) { | |
301 for(i=0; i<8; i++) | |
302 dtop[i+1] = stop[i]; | |
303 dtop[0] = dtop[1]; | |
304 dtop[9] = dtop[8]; | |
305 if(flags & A_AVAIL) | |
306 dleft[0] = dtop[0] = stopleft; | |
307 } | |
308 } | |
309 | |
310 static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) { | 289 static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) { |
311 int y; | 290 int y; |
312 uint64_t a = *((uint64_t *)(&top[1])); | 291 uint64_t a = *((uint64_t *)(&top[1])); |
313 for(y=0;y<8;y++) { | 292 for(y=0;y<8;y++) { |
314 *((uint64_t *)(d+y*stride)) = a; | 293 *((uint64_t *)(d+y*stride)) = a; |
392 d[y*stride+x] = LOWPASS(top,x+1); | 371 d[y*stride+x] = LOWPASS(top,x+1); |
393 } | 372 } |
394 | 373 |
395 #undef LOWPASS | 374 #undef LOWPASS |
396 | 375 |
397 static inline void modify_pred(const int8_t *mod_table, int *mode) { | 376 static inline void modify_pred(const int_fast8_t *mod_table, int *mode) { |
398 int newmode = mod_table[*mode]; | 377 int newmode = mod_table[*mode]; |
399 if(newmode < 0) { | 378 if(newmode < 0) { |
400 av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); | 379 av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); |
401 *mode = 0; | 380 *mode = 0; |
402 } else { | 381 } else { |
686 * | 665 * |
687 ****************************************************************************/ | 666 ****************************************************************************/ |
688 | 667 |
689 /* kth-order exponential golomb code */ | 668 /* kth-order exponential golomb code */ |
690 static inline int get_ue_code(GetBitContext *gb, int order) { | 669 static inline int get_ue_code(GetBitContext *gb, int order) { |
691 if(order) | 670 if(order) { |
692 return (get_ue_golomb(gb) << order) + get_bits(gb,order); | 671 int ret = get_ue_golomb(gb) << order; |
672 return ret + get_bits(gb,order); | |
673 } | |
693 return get_ue_golomb(gb); | 674 return get_ue_golomb(gb); |
694 } | 675 } |
695 | 676 |
696 static int decode_residual_block(AVSContext *h, GetBitContext *gb, | 677 static int decode_residual_block(AVSContext *h, GetBitContext *gb, |
697 const residual_vlc_t *r, int esc_golomb_order, | 678 const residual_vlc_t *r, int esc_golomb_order, |
728 } | 709 } |
729 level_buf[i] = level; | 710 level_buf[i] = level; |
730 run_buf[i] = run; | 711 run_buf[i] = run; |
731 } | 712 } |
732 /* inverse scan and dequantization */ | 713 /* inverse scan and dequantization */ |
733 for(i=i-1;i>=0;i--) { | 714 while(--i >= 0){ |
734 pos += 1 + run_buf[i]; | 715 pos += 1 + run_buf[i]; |
735 if(pos > 63) { | 716 if(pos > 63) { |
736 av_log(h->s.avctx, AV_LOG_ERROR, | 717 av_log(h->s.avctx, AV_LOG_ERROR, |
737 "position out of block bounds at pic %d MB(%d,%d)\n", | 718 "position out of block bounds at pic %d MB(%d,%d)\n", |
738 h->picture.poc, h->mbx, h->mby); | 719 h->picture.poc, h->mbx, h->mby); |
918 if(h->cbp & (1<<block)) | 899 if(h->cbp & (1<<block)) |
919 decode_residual_block(h,gb,intra_2dvlc,1,h->qp,d,h->l_stride); | 900 decode_residual_block(h,gb,intra_2dvlc,1,h->qp,d,h->l_stride); |
920 } | 901 } |
921 | 902 |
922 /* chroma intra prediction */ | 903 /* chroma intra prediction */ |
923 load_intra_pred_chroma(&h->top_border_u[h->mbx*8], h->left_border_u, | 904 /* extend borders by one pixel */ |
924 h->topleft_border_u, top, left, h->c_stride, h->flags); | 905 h->left_border_u[9] = h->left_border_u[8]; |
925 h->intra_pred_c[pred_mode_uv](h->cu, top, left, h->c_stride); | 906 h->left_border_v[9] = h->left_border_v[8]; |
926 load_intra_pred_chroma(&h->top_border_v[h->mbx*8], h->left_border_v, | 907 h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8]; |
927 h->topleft_border_v, top, left, h->c_stride, h->flags); | 908 h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8]; |
928 h->intra_pred_c[pred_mode_uv](h->cv, top, left, h->c_stride); | 909 if(h->mbx && h->mby) { |
910 h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u; | |
911 h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v; | |
912 } else { | |
913 h->left_border_u[0] = h->left_border_u[1]; | |
914 h->left_border_v[0] = h->left_border_v[1]; | |
915 h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1]; | |
916 h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1]; | |
917 } | |
918 h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10], | |
919 h->left_border_u, h->c_stride); | |
920 h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10], | |
921 h->left_border_v, h->c_stride); | |
929 | 922 |
930 decode_residual_chroma(h); | 923 decode_residual_chroma(h); |
931 filter_mb(h,I_8X8); | 924 filter_mb(h,I_8X8); |
932 | 925 |
933 /* mark motion vectors as intra */ | 926 /* mark motion vectors as intra */ |
1322 static void init_top_lines(AVSContext *h) { | 1315 static void init_top_lines(AVSContext *h) { |
1323 /* alloc top line of predictors */ | 1316 /* alloc top line of predictors */ |
1324 h->top_qp = av_malloc( h->mb_width); | 1317 h->top_qp = av_malloc( h->mb_width); |
1325 h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t)); | 1318 h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t)); |
1326 h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t)); | 1319 h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(vector_t)); |
1327 h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(int)); | 1320 h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y)); |
1328 h->top_border_y = av_malloc((h->mb_width+1)*16); | 1321 h->top_border_y = av_malloc((h->mb_width+1)*16); |
1329 h->top_border_u = av_malloc((h->mb_width+1)*8); | 1322 h->top_border_u = av_malloc((h->mb_width)*10); |
1330 h->top_border_v = av_malloc((h->mb_width+1)*8); | 1323 h->top_border_v = av_malloc((h->mb_width)*10); |
1331 | 1324 |
1332 /* alloc space for co-located MVs and types */ | 1325 /* alloc space for co-located MVs and types */ |
1333 h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t)); | 1326 h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t)); |
1334 h->col_type_base = av_malloc(h->mb_width*h->mb_height); | 1327 h->col_type_base = av_malloc(h->mb_width*h->mb_height); |
1335 } | 1328 } |
1336 | 1329 |
1337 static int decode_seq_header(AVSContext *h) { | 1330 static int decode_seq_header(AVSContext *h) { |
1338 MpegEncContext *s = &h->s; | 1331 MpegEncContext *s = &h->s; |
1339 extern const AVRational frame_rate_tab[]; | 1332 extern const AVRational ff_frame_rate_tab[]; |
1340 int frame_rate_code; | 1333 int frame_rate_code; |
1341 | 1334 |
1342 h->profile = get_bits(&s->gb,8); | 1335 h->profile = get_bits(&s->gb,8); |
1343 h->level = get_bits(&s->gb,8); | 1336 h->level = get_bits(&s->gb,8); |
1344 skip_bits1(&s->gb); //progressive sequence | 1337 skip_bits1(&s->gb); //progressive sequence |
1352 skip_bits1(&s->gb); //marker_bit | 1345 skip_bits1(&s->gb); //marker_bit |
1353 skip_bits(&s->gb,12);//bit_rate_upper | 1346 skip_bits(&s->gb,12);//bit_rate_upper |
1354 s->low_delay = get_bits1(&s->gb); | 1347 s->low_delay = get_bits1(&s->gb); |
1355 h->mb_width = (s->width + 15) >> 4; | 1348 h->mb_width = (s->width + 15) >> 4; |
1356 h->mb_height = (s->height + 15) >> 4; | 1349 h->mb_height = (s->height + 15) >> 4; |
1357 h->s.avctx->time_base.den = frame_rate_tab[frame_rate_code].num; | 1350 h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num; |
1358 h->s.avctx->time_base.num = frame_rate_tab[frame_rate_code].den; | 1351 h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den; |
1359 h->s.avctx->width = s->width; | 1352 h->s.avctx->width = s->width; |
1360 h->s.avctx->height = s->height; | 1353 h->s.avctx->height = s->height; |
1361 if(!h->top_qp) | 1354 if(!h->top_qp) |
1362 init_top_lines(h); | 1355 init_top_lines(h); |
1363 return 0; | 1356 return 0; |
1539 sizeof(AVSContext), | 1532 sizeof(AVSContext), |
1540 cavs_decode_init, | 1533 cavs_decode_init, |
1541 NULL, | 1534 NULL, |
1542 cavs_decode_end, | 1535 cavs_decode_end, |
1543 cavs_decode_frame, | 1536 cavs_decode_frame, |
1544 CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, //FIXME is this correct ? | 1537 CODEC_CAP_DR1 | CODEC_CAP_DELAY, |
1545 .flush= ff_cavs_flush, | 1538 .flush= ff_cavs_flush, |
1546 }; | 1539 }; |