• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/vp56.c

Go to the documentation of this file.
00001 
00024 #include "avcodec.h"
00025 #include "bytestream.h"
00026 
00027 #include "vp56.h"
00028 #include "vp56data.h"
00029 
00030 
00031 void vp56_init_dequant(VP56Context *s, int quantizer)
00032 {
00033     s->quantizer = quantizer;
00034     s->dequant_dc = vp56_dc_dequant[quantizer] << 2;
00035     s->dequant_ac = vp56_ac_dequant[quantizer] << 2;
00036 }
00037 
00038 static int vp56_get_vectors_predictors(VP56Context *s, int row, int col,
00039                                        VP56Frame ref_frame)
00040 {
00041     int nb_pred = 0;
00042     VP56mv vect[2] = {{0,0}, {0,0}};
00043     int pos, offset;
00044     VP56mv mvp;
00045 
00046     for (pos=0; pos<12; pos++) {
00047         mvp.x = col + vp56_candidate_predictor_pos[pos][0];
00048         mvp.y = row + vp56_candidate_predictor_pos[pos][1];
00049         if (mvp.x < 0 || mvp.x >= s->mb_width ||
00050             mvp.y < 0 || mvp.y >= s->mb_height)
00051             continue;
00052         offset = mvp.x + s->mb_width*mvp.y;
00053 
00054         if (vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
00055             continue;
00056         if ((s->macroblocks[offset].mv.x == vect[0].x &&
00057              s->macroblocks[offset].mv.y == vect[0].y) ||
00058             (s->macroblocks[offset].mv.x == 0 &&
00059              s->macroblocks[offset].mv.y == 0))
00060             continue;
00061 
00062         vect[nb_pred++] = s->macroblocks[offset].mv;
00063         if (nb_pred > 1) {
00064             nb_pred = -1;
00065             break;
00066         }
00067         s->vector_candidate_pos = pos;
00068     }
00069 
00070     s->vector_candidate[0] = vect[0];
00071     s->vector_candidate[1] = vect[1];
00072 
00073     return nb_pred+1;
00074 }
00075 
00076 static void vp56_parse_mb_type_models(VP56Context *s)
00077 {
00078     VP56RangeCoder *c = &s->c;
00079     VP56Model *model = s->modelp;
00080     int i, ctx, type;
00081 
00082     for (ctx=0; ctx<3; ctx++) {
00083         if (vp56_rac_get_prob(c, 174)) {
00084             int idx = vp56_rac_gets(c, 4);
00085             memcpy(model->mb_types_stats[ctx],
00086                    vp56_pre_def_mb_type_stats[idx][ctx],
00087                    sizeof(model->mb_types_stats[ctx]));
00088         }
00089         if (vp56_rac_get_prob(c, 254)) {
00090             for (type=0; type<10; type++) {
00091                 for(i=0; i<2; i++) {
00092                     if (vp56_rac_get_prob(c, 205)) {
00093                         int delta, sign = vp56_rac_get(c);
00094 
00095                         delta = vp56_rac_get_tree(c, vp56_pmbtm_tree,
00096                                                   vp56_mb_type_model_model);
00097                         if (!delta)
00098                             delta = 4 * vp56_rac_gets(c, 7);
00099                         model->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
00100                     }
00101                 }
00102             }
00103         }
00104     }
00105 
00106     /* compute MB type probability tables based on previous MB type */
00107     for (ctx=0; ctx<3; ctx++) {
00108         int p[10];
00109 
00110         for (type=0; type<10; type++)
00111             p[type] = 100 * model->mb_types_stats[ctx][type][1];
00112 
00113         for (type=0; type<10; type++) {
00114             int p02, p34, p0234, p17, p56, p89, p5689, p156789;
00115 
00116             /* conservative MB type probability */
00117             model->mb_type[ctx][type][0] = 255 - (255 * model->mb_types_stats[ctx][type][0]) / (1 + model->mb_types_stats[ctx][type][0] + model->mb_types_stats[ctx][type][1]);
00118 
00119             p[type] = 0;    /* same MB type => weight is null */
00120 
00121             /* binary tree parsing probabilities */
00122             p02 = p[0] + p[2];
00123             p34 = p[3] + p[4];
00124             p0234 = p02 + p34;
00125             p17 = p[1] + p[7];
00126             p56 = p[5] + p[6];
00127             p89 = p[8] + p[9];
00128             p5689 = p56 + p89;
00129             p156789 = p17 + p5689;
00130 
00131             model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
00132             model->mb_type[ctx][type][2] = 1 + 255 * p02  / (1+p0234);
00133             model->mb_type[ctx][type][3] = 1 + 255 * p17  / (1+p156789);
00134             model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
00135             model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
00136             model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
00137             model->mb_type[ctx][type][7] = 1 + 255 * p56  / (1+p5689);
00138             model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
00139             model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
00140 
00141             /* restore initial value */
00142             p[type] = 100 * model->mb_types_stats[ctx][type][1];
00143         }
00144     }
00145 }
00146 
00147 static VP56mb vp56_parse_mb_type(VP56Context *s,
00148                                  VP56mb prev_type, int ctx)
00149 {
00150     uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
00151     VP56RangeCoder *c = &s->c;
00152 
00153     if (vp56_rac_get_prob(c, mb_type_model[0]))
00154         return prev_type;
00155     else
00156         return vp56_rac_get_tree(c, vp56_pmbt_tree, mb_type_model);
00157 }
00158 
00159 static void vp56_decode_4mv(VP56Context *s, int row, int col)
00160 {
00161     VP56mv mv = {0,0};
00162     int type[4];
00163     int b;
00164 
00165     /* parse each block type */
00166     for (b=0; b<4; b++) {
00167         type[b] = vp56_rac_gets(&s->c, 2);
00168         if (type[b])
00169             type[b]++;  /* only returns 0, 2, 3 or 4 (all INTER_PF) */
00170     }
00171 
00172     /* get vectors */
00173     for (b=0; b<4; b++) {
00174         switch (type[b]) {
00175             case VP56_MB_INTER_NOVEC_PF:
00176                 s->mv[b] = (VP56mv) {0,0};
00177                 break;
00178             case VP56_MB_INTER_DELTA_PF:
00179                 s->parse_vector_adjustment(s, &s->mv[b]);
00180                 break;
00181             case VP56_MB_INTER_V1_PF:
00182                 s->mv[b] = s->vector_candidate[0];
00183                 break;
00184             case VP56_MB_INTER_V2_PF:
00185                 s->mv[b] = s->vector_candidate[1];
00186                 break;
00187         }
00188         mv.x += s->mv[b].x;
00189         mv.y += s->mv[b].y;
00190     }
00191 
00192     /* this is the one selected for the whole MB for prediction */
00193     s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
00194 
00195     /* chroma vectors are average luma vectors */
00196     if (s->avctx->codec->id == CODEC_ID_VP5) {
00197         s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
00198         s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
00199     } else {
00200         s->mv[4] = s->mv[5] = (VP56mv) {mv.x/4, mv.y/4};
00201     }
00202 }
00203 
00204 static VP56mb vp56_decode_mv(VP56Context *s, int row, int col)
00205 {
00206     VP56mv *mv, vect = {0,0};
00207     int ctx, b;
00208 
00209     ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
00210     s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
00211     s->macroblocks[row * s->mb_width + col].type = s->mb_type;
00212 
00213     switch (s->mb_type) {
00214         case VP56_MB_INTER_V1_PF:
00215             mv = &s->vector_candidate[0];
00216             break;
00217 
00218         case VP56_MB_INTER_V2_PF:
00219             mv = &s->vector_candidate[1];
00220             break;
00221 
00222         case VP56_MB_INTER_V1_GF:
00223             vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
00224             mv = &s->vector_candidate[0];
00225             break;
00226 
00227         case VP56_MB_INTER_V2_GF:
00228             vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
00229             mv = &s->vector_candidate[1];
00230             break;
00231 
00232         case VP56_MB_INTER_DELTA_PF:
00233             s->parse_vector_adjustment(s, &vect);
00234             mv = &vect;
00235             break;
00236 
00237         case VP56_MB_INTER_DELTA_GF:
00238             vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
00239             s->parse_vector_adjustment(s, &vect);
00240             mv = &vect;
00241             break;
00242 
00243         case VP56_MB_INTER_4V:
00244             vp56_decode_4mv(s, row, col);
00245             return s->mb_type;
00246 
00247         default:
00248             mv = &vect;
00249             break;
00250     }
00251 
00252     s->macroblocks[row*s->mb_width + col].mv = *mv;
00253 
00254     /* same vector for all blocks */
00255     for (b=0; b<6; b++)
00256         s->mv[b] = *mv;
00257 
00258     return s->mb_type;
00259 }
00260 
00261 static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame)
00262 {
00263     int idx = s->scantable.permutated[0];
00264     int b;
00265 
00266     for (b=0; b<6; b++) {
00267         VP56RefDc *ab = &s->above_blocks[s->above_block_idx[b]];
00268         VP56RefDc *lb = &s->left_block[vp56_b6to4[b]];
00269         int count = 0;
00270         int dc = 0;
00271         int i;
00272 
00273         if (ref_frame == lb->ref_frame) {
00274             dc += lb->dc_coeff;
00275             count++;
00276         }
00277         if (ref_frame == ab->ref_frame) {
00278             dc += ab->dc_coeff;
00279             count++;
00280         }
00281         if (s->avctx->codec->id == CODEC_ID_VP5)
00282             for (i=0; i<2; i++)
00283                 if (count < 2 && ref_frame == ab[-1+2*i].ref_frame) {
00284                     dc += ab[-1+2*i].dc_coeff;
00285                     count++;
00286                 }
00287         if (count == 0)
00288             dc = s->prev_dc[vp56_b2p[b]][ref_frame];
00289         else if (count == 2)
00290             dc /= 2;
00291 
00292         s->block_coeff[b][idx] += dc;
00293         s->prev_dc[vp56_b2p[b]][ref_frame] = s->block_coeff[b][idx];
00294         ab->dc_coeff = s->block_coeff[b][idx];
00295         ab->ref_frame = ref_frame;
00296         lb->dc_coeff = s->block_coeff[b][idx];
00297         lb->ref_frame = ref_frame;
00298         s->block_coeff[b][idx] *= s->dequant_dc;
00299     }
00300 }
00301 
00302 static void vp56_edge_filter(VP56Context *s, uint8_t *yuv,
00303                              int pix_inc, int line_inc, int t)
00304 {
00305     int pix2_inc = 2 * pix_inc;
00306     int i, v;
00307 
00308     for (i=0; i<12; i++) {
00309         v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4) >>3;
00310         v = s->adjust(v, t);
00311         yuv[-pix_inc] = av_clip_uint8(yuv[-pix_inc] + v);
00312         yuv[0] = av_clip_uint8(yuv[0] - v);
00313         yuv += line_inc;
00314     }
00315 }
00316 
00317 static void vp56_deblock_filter(VP56Context *s, uint8_t *yuv,
00318                                 int stride, int dx, int dy)
00319 {
00320     int t = vp56_filter_threshold[s->quantizer];
00321     if (dx)  vp56_edge_filter(s, yuv +         10-dx ,      1, stride, t);
00322     if (dy)  vp56_edge_filter(s, yuv + stride*(10-dy), stride,      1, t);
00323 }
00324 
00325 static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
00326                     int stride, int x, int y)
00327 {
00328     uint8_t *dst=s->framep[VP56_FRAME_CURRENT]->data[plane]+s->block_offset[b];
00329     uint8_t *src_block;
00330     int src_offset;
00331     int overlap_offset = 0;
00332     int mask = s->vp56_coord_div[b] - 1;
00333     int deblock_filtering = s->deblock_filtering;
00334     int dx;
00335     int dy;
00336 
00337     if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
00338         (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
00339          && !s->framep[VP56_FRAME_CURRENT]->key_frame))
00340         deblock_filtering = 0;
00341 
00342     dx = s->mv[b].x / s->vp56_coord_div[b];
00343     dy = s->mv[b].y / s->vp56_coord_div[b];
00344 
00345     if (b >= 4) {
00346         x /= 2;
00347         y /= 2;
00348     }
00349     x += dx - 2;
00350     y += dy - 2;
00351 
00352     if (x<0 || x+12>=s->plane_width[plane] ||
00353         y<0 || y+12>=s->plane_height[plane]) {
00354         ff_emulated_edge_mc(s->edge_emu_buffer,
00355                             src + s->block_offset[b] + (dy-2)*stride + (dx-2),
00356                             stride, 12, 12, x, y,
00357                             s->plane_width[plane],
00358                             s->plane_height[plane]);
00359         src_block = s->edge_emu_buffer;
00360         src_offset = 2 + 2*stride;
00361     } else if (deblock_filtering) {
00362         /* only need a 12x12 block, but there is no such dsp function, */
00363         /* so copy a 16x12 block */
00364         s->dsp.put_pixels_tab[0][0](s->edge_emu_buffer,
00365                                     src + s->block_offset[b] + (dy-2)*stride + (dx-2),
00366                                     stride, 12);
00367         src_block = s->edge_emu_buffer;
00368         src_offset = 2 + 2*stride;
00369     } else {
00370         src_block = src;
00371         src_offset = s->block_offset[b] + dy*stride + dx;
00372     }
00373 
00374     if (deblock_filtering)
00375         vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
00376 
00377     if (s->mv[b].x & mask)
00378         overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
00379     if (s->mv[b].y & mask)
00380         overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
00381 
00382     if (overlap_offset) {
00383         if (s->filter)
00384             s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
00385                       stride, s->mv[b], mask, s->filter_selection, b<4);
00386         else
00387             s->dsp.put_no_rnd_pixels_l2[1](dst, src_block+src_offset,
00388                                            src_block+src_offset+overlap_offset,
00389                                            stride, 8);
00390     } else {
00391         s->dsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
00392     }
00393 }
00394 
00395 static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
00396 {
00397     AVFrame *frame_current, *frame_ref;
00398     VP56mb mb_type;
00399     VP56Frame ref_frame;
00400     int b, ab, b_max, plane, off;
00401 
00402     if (s->framep[VP56_FRAME_CURRENT]->key_frame)
00403         mb_type = VP56_MB_INTRA;
00404     else
00405         mb_type = vp56_decode_mv(s, row, col);
00406     ref_frame = vp56_reference_frame[mb_type];
00407 
00408     s->dsp.clear_blocks(*s->block_coeff);
00409 
00410     s->parse_coeff(s);
00411 
00412     vp56_add_predictors_dc(s, ref_frame);
00413 
00414     frame_current = s->framep[VP56_FRAME_CURRENT];
00415     frame_ref = s->framep[ref_frame];
00416 
00417     ab = 6*is_alpha;
00418     b_max = 6 - 2*is_alpha;
00419 
00420     switch (mb_type) {
00421         case VP56_MB_INTRA:
00422             for (b=0; b<b_max; b++) {
00423                 plane = vp56_b2p[b+ab];
00424                 s->dsp.idct_put(frame_current->data[plane] + s->block_offset[b],
00425                                 s->stride[plane], s->block_coeff[b]);
00426             }
00427             break;
00428 
00429         case VP56_MB_INTER_NOVEC_PF:
00430         case VP56_MB_INTER_NOVEC_GF:
00431             for (b=0; b<b_max; b++) {
00432                 plane = vp56_b2p[b+ab];
00433                 off = s->block_offset[b];
00434                 s->dsp.put_pixels_tab[1][0](frame_current->data[plane] + off,
00435                                             frame_ref->data[plane] + off,
00436                                             s->stride[plane], 8);
00437                 s->dsp.idct_add(frame_current->data[plane] + off,
00438                                 s->stride[plane], s->block_coeff[b]);
00439             }
00440             break;
00441 
00442         case VP56_MB_INTER_DELTA_PF:
00443         case VP56_MB_INTER_V1_PF:
00444         case VP56_MB_INTER_V2_PF:
00445         case VP56_MB_INTER_DELTA_GF:
00446         case VP56_MB_INTER_4V:
00447         case VP56_MB_INTER_V1_GF:
00448         case VP56_MB_INTER_V2_GF:
00449             for (b=0; b<b_max; b++) {
00450                 int x_off = b==1 || b==3 ? 8 : 0;
00451                 int y_off = b==2 || b==3 ? 8 : 0;
00452                 plane = vp56_b2p[b+ab];
00453                 vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane],
00454                         16*col+x_off, 16*row+y_off);
00455                 s->dsp.idct_add(frame_current->data[plane] + s->block_offset[b],
00456                                 s->stride[plane], s->block_coeff[b]);
00457             }
00458             break;
00459     }
00460 }
00461 
00462 static int vp56_size_changed(AVCodecContext *avctx)
00463 {
00464     VP56Context *s = avctx->priv_data;
00465     int stride = s->framep[VP56_FRAME_CURRENT]->linesize[0];
00466     int i;
00467 
00468     s->plane_width[0]  = s->plane_width[3]  = avctx->coded_width;
00469     s->plane_width[1]  = s->plane_width[2]  = avctx->coded_width/2;
00470     s->plane_height[0] = s->plane_height[3] = avctx->coded_height;
00471     s->plane_height[1] = s->plane_height[2] = avctx->coded_height/2;
00472 
00473     for (i=0; i<4; i++)
00474         s->stride[i] = s->flip * s->framep[VP56_FRAME_CURRENT]->linesize[i];
00475 
00476     s->mb_width  = (avctx->coded_width +15) / 16;
00477     s->mb_height = (avctx->coded_height+15) / 16;
00478 
00479     if (s->mb_width > 1000 || s->mb_height > 1000) {
00480         av_log(avctx, AV_LOG_ERROR, "picture too big\n");
00481         return -1;
00482     }
00483 
00484     s->above_blocks = av_realloc(s->above_blocks,
00485                                  (4*s->mb_width+6) * sizeof(*s->above_blocks));
00486     s->macroblocks = av_realloc(s->macroblocks,
00487                                 s->mb_width*s->mb_height*sizeof(*s->macroblocks));
00488     av_free(s->edge_emu_buffer_alloc);
00489     s->edge_emu_buffer_alloc = av_malloc(16*stride);
00490     s->edge_emu_buffer = s->edge_emu_buffer_alloc;
00491     if (s->flip < 0)
00492         s->edge_emu_buffer += 15 * stride;
00493 
00494     return 0;
00495 }
00496 
00497 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00498                       const uint8_t *buf, int buf_size)
00499 {
00500     VP56Context *s = avctx->priv_data;
00501     AVFrame *const p = s->framep[VP56_FRAME_CURRENT];
00502     int remaining_buf_size = buf_size;
00503     int is_alpha, av_uninit(alpha_offset);
00504 
00505     if (s->has_alpha) {
00506         alpha_offset = bytestream_get_be24(&buf);
00507         remaining_buf_size -= 3;
00508     }
00509 
00510     for (is_alpha=0; is_alpha < 1+s->has_alpha; is_alpha++) {
00511         int mb_row, mb_col, mb_row_flip, mb_offset = 0;
00512         int block, y, uv, stride_y, stride_uv;
00513         int golden_frame = 0;
00514         int res;
00515 
00516         s->modelp = &s->models[is_alpha];
00517 
00518         res = s->parse_header(s, buf, remaining_buf_size, &golden_frame);
00519         if (!res) {
00520             int i;
00521             for (i = 0; i < 4; i++) {
00522                 if (s->frames[i].data[0])
00523                     avctx->release_buffer(avctx, &s->frames[i]);
00524             }
00525             return res;
00526         }
00527 
00528         if (!is_alpha) {
00529             p->reference = 1;
00530             if (avctx->get_buffer(avctx, p) < 0) {
00531                 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00532                 return -1;
00533             }
00534 
00535             if (res == 2)
00536                 if (vp56_size_changed(avctx)) {
00537                     avctx->release_buffer(avctx, p);
00538                     return -1;
00539                 }
00540         }
00541 
00542         if (p->key_frame) {
00543             p->pict_type = FF_I_TYPE;
00544             s->default_models_init(s);
00545             for (block=0; block<s->mb_height*s->mb_width; block++)
00546                 s->macroblocks[block].type = VP56_MB_INTRA;
00547         } else {
00548             p->pict_type = FF_P_TYPE;
00549             vp56_parse_mb_type_models(s);
00550             s->parse_vector_models(s);
00551             s->mb_type = VP56_MB_INTER_NOVEC_PF;
00552         }
00553 
00554         s->parse_coeff_models(s);
00555 
00556         memset(s->prev_dc, 0, sizeof(s->prev_dc));
00557         s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
00558         s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
00559 
00560         for (block=0; block < 4*s->mb_width+6; block++) {
00561             s->above_blocks[block].ref_frame = VP56_FRAME_NONE;
00562             s->above_blocks[block].dc_coeff = 0;
00563             s->above_blocks[block].not_null_dc = 0;
00564         }
00565         s->above_blocks[2*s->mb_width + 2].ref_frame = VP56_FRAME_CURRENT;
00566         s->above_blocks[3*s->mb_width + 4].ref_frame = VP56_FRAME_CURRENT;
00567 
00568         stride_y  = p->linesize[0];
00569         stride_uv = p->linesize[1];
00570 
00571         if (s->flip < 0)
00572             mb_offset = 7;
00573 
00574         /* main macroblocks loop */
00575         for (mb_row=0; mb_row<s->mb_height; mb_row++) {
00576             if (s->flip < 0)
00577                 mb_row_flip = s->mb_height - mb_row - 1;
00578             else
00579                 mb_row_flip = mb_row;
00580 
00581             for (block=0; block<4; block++) {
00582                 s->left_block[block].ref_frame = VP56_FRAME_NONE;
00583                 s->left_block[block].dc_coeff = 0;
00584                 s->left_block[block].not_null_dc = 0;
00585             }
00586             memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx));
00587             memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
00588 
00589             s->above_block_idx[0] = 1;
00590             s->above_block_idx[1] = 2;
00591             s->above_block_idx[2] = 1;
00592             s->above_block_idx[3] = 2;
00593             s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
00594             s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
00595 
00596             s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
00597             s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
00598             s->block_offset[1] = s->block_offset[0] + 8;
00599             s->block_offset[3] = s->block_offset[2] + 8;
00600             s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
00601             s->block_offset[5] = s->block_offset[4];
00602 
00603             for (mb_col=0; mb_col<s->mb_width; mb_col++) {
00604                 vp56_decode_mb(s, mb_row, mb_col, is_alpha);
00605 
00606                 for (y=0; y<4; y++) {
00607                     s->above_block_idx[y] += 2;
00608                     s->block_offset[y] += 16;
00609                 }
00610 
00611                 for (uv=4; uv<6; uv++) {
00612                     s->above_block_idx[uv] += 1;
00613                     s->block_offset[uv] += 8;
00614                 }
00615             }
00616         }
00617 
00618         if (p->key_frame || golden_frame) {
00619             if (s->framep[VP56_FRAME_GOLDEN]->data[0] &&
00620                 s->framep[VP56_FRAME_GOLDEN] != s->framep[VP56_FRAME_GOLDEN2])
00621                 avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
00622             s->framep[VP56_FRAME_GOLDEN] = p;
00623         }
00624 
00625         if (s->has_alpha) {
00626             FFSWAP(AVFrame *, s->framep[VP56_FRAME_GOLDEN],
00627                               s->framep[VP56_FRAME_GOLDEN2]);
00628             buf += alpha_offset;
00629             remaining_buf_size -= alpha_offset;
00630         }
00631     }
00632 
00633     if (s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN] ||
00634         s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN2]) {
00635         if (s->framep[VP56_FRAME_UNUSED] != s->framep[VP56_FRAME_GOLDEN] &&
00636             s->framep[VP56_FRAME_UNUSED] != s->framep[VP56_FRAME_GOLDEN2])
00637             FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS],
00638                               s->framep[VP56_FRAME_UNUSED]);
00639         else
00640             FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS],
00641                               s->framep[VP56_FRAME_UNUSED2]);
00642     } else if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
00643         avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
00644     FFSWAP(AVFrame *, s->framep[VP56_FRAME_CURRENT],
00645                       s->framep[VP56_FRAME_PREVIOUS]);
00646 
00647     *(AVFrame*)data = *p;
00648     *data_size = sizeof(AVFrame);
00649 
00650     return buf_size;
00651 }
00652 
00653 av_cold void vp56_init(AVCodecContext *avctx, int flip, int has_alpha)
00654 {
00655     VP56Context *s = avctx->priv_data;
00656     int i;
00657 
00658     s->avctx = avctx;
00659     avctx->pix_fmt = has_alpha ? PIX_FMT_YUVA420P : PIX_FMT_YUV420P;
00660 
00661     if (avctx->idct_algo == FF_IDCT_AUTO)
00662         avctx->idct_algo = FF_IDCT_VP3;
00663     dsputil_init(&s->dsp, avctx);
00664     ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct);
00665 
00666     for (i=0; i<4; i++)
00667         s->framep[i] = &s->frames[i];
00668     s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN];
00669     s->framep[VP56_FRAME_UNUSED2] = s->framep[VP56_FRAME_GOLDEN2];
00670     s->edge_emu_buffer_alloc = NULL;
00671 
00672     s->above_blocks = NULL;
00673     s->macroblocks = NULL;
00674     s->quantizer = -1;
00675     s->deblock_filtering = 1;
00676 
00677     s->filter = NULL;
00678 
00679     s->has_alpha = has_alpha;
00680     if (flip) {
00681         s->flip = -1;
00682         s->frbi = 2;
00683         s->srbi = 0;
00684     } else {
00685         s->flip = 1;
00686         s->frbi = 0;
00687         s->srbi = 2;
00688     }
00689 }
00690 
00691 av_cold int vp56_free(AVCodecContext *avctx)
00692 {
00693     VP56Context *s = avctx->priv_data;
00694     int pt;
00695 
00696     av_free(s->above_blocks);
00697     av_free(s->macroblocks);
00698     av_free(s->edge_emu_buffer_alloc);
00699     if (s->framep[VP56_FRAME_GOLDEN]->data[0])
00700         avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
00701     if (s->framep[VP56_FRAME_GOLDEN2]->data[0])
00702         avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN2]);
00703     if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
00704         avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
00705 
00706     for (pt=0; pt < 2; pt++) {
00707         int ct, cg;
00708         free_vlc(&s->dccv_vlc[pt]);
00709         free_vlc(&s->runv_vlc[pt]);
00710         for (ct=0; ct<3; ct++)
00711             for (cg = 0; cg < 6; cg++)
00712                 free_vlc(&s->ract_vlc[pt][ct][cg]);
00713     }
00714 
00715     return 0;
00716 }

Generated on Sat Feb 16 2013 09:23:14 for ffmpeg by  doxygen 1.7.1