00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avcodec.h"
00028 #include "dsputil.h"
00029 #include "mpegvideo.h"
00030 #include "golomb.h"
00031
00032 #include "rv34.h"
00033 #include "rv30data.h"
00034
00035
00036 static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si)
00037 {
00038 int mb_bits;
00039 int w = r->s.width, h = r->s.height;
00040 int mb_size;
00041
00042 memset(si, 0, sizeof(SliceInfo));
00043 skip_bits(gb, 3);
00044 si->type = get_bits(gb, 2);
00045 if(si->type == 1) si->type = 0;
00046 if(get_bits1(gb))
00047 return -1;
00048 si->quant = get_bits(gb, 5);
00049 skip_bits1(gb);
00050 skip_bits(gb, 13);
00051 skip_bits(gb, r->rpr);
00052 si->width = w;
00053 si->height = h;
00054 mb_size = ((w + 15) >> 4) * ((h + 15) >> 4);
00055 mb_bits = ff_rv34_get_start_offset(gb, mb_size);
00056 si->start = get_bits(gb, mb_bits);
00057 skip_bits1(gb);
00058 return 0;
00059 }
00060
00064 static int rv30_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst)
00065 {
00066 int i, j, k;
00067
00068 for(i = 0; i < 4; i++, dst += r->s.b4_stride - 4){
00069 for(j = 0; j < 4; j+= 2){
00070 int code = svq3_get_ue_golomb(gb) << 1;
00071 if(code >= 81*2){
00072 av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction code\n");
00073 return -1;
00074 }
00075 for(k = 0; k < 2; k++){
00076 int A = dst[-r->s.b4_stride] + 1;
00077 int B = dst[-1] + 1;
00078 *dst++ = rv30_itype_from_context[A * 90 + B * 9 + rv30_itype_code[code + k]];
00079 if(dst[-1] == 9){
00080 av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction mode\n");
00081 return -1;
00082 }
00083 }
00084 }
00085 }
00086 return 0;
00087 }
00088
00092 static int rv30_decode_mb_info(RV34DecContext *r)
00093 {
00094 static const int rv30_p_types[6] = { RV34_MB_SKIP, RV34_MB_P_16x16, RV34_MB_P_8x8, -1, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
00095 static const int rv30_b_types[6] = { RV34_MB_SKIP, RV34_MB_B_DIRECT, RV34_MB_B_FORWARD, RV34_MB_B_BACKWARD, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
00096 MpegEncContext *s = &r->s;
00097 GetBitContext *gb = &s->gb;
00098 int code = svq3_get_ue_golomb(gb);
00099
00100 if(code > 11){
00101 av_log(s->avctx, AV_LOG_ERROR, "Incorrect MB type code\n");
00102 return -1;
00103 }
00104 if(code > 5){
00105 av_log(s->avctx, AV_LOG_ERROR, "dquant needed\n");
00106 code -= 6;
00107 }
00108 if(s->pict_type != B_TYPE)
00109 return rv30_p_types[code];
00110 else
00111 return rv30_b_types[code];
00112 }
00113
00117 static int rv30_decode_init(AVCodecContext *avctx)
00118 {
00119 RV34DecContext *r = avctx->priv_data;
00120
00121 r->rv30 = 1;
00122 ff_rv34_decode_init(avctx);
00123 if(avctx->extradata_size < 2){
00124 av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n");
00125 return -1;
00126 }
00127 r->rpr = (avctx->extradata[1] & 7) >> 1;
00128 r->rpr = FFMIN(r->rpr + 1, 3);
00129 r->parse_slice_header = rv30_parse_slice_header;
00130 r->decode_intra_types = rv30_decode_intra_types;
00131 r->decode_mb_info = rv30_decode_mb_info;
00132 r->luma_dc_quant_i = rv30_luma_dc_quant;
00133 r->luma_dc_quant_p = rv30_luma_dc_quant;
00134 return 0;
00135 }
00136
00137 AVCodec rv30_decoder = {
00138 "rv30",
00139 CODEC_TYPE_VIDEO,
00140 CODEC_ID_RV30,
00141 sizeof(RV34DecContext),
00142 rv30_decode_init,
00143 NULL,
00144 ff_rv34_decode_end,
00145 ff_rv34_decode_frame,
00146 CODEC_CAP_DR1 | CODEC_CAP_DELAY,
00147 };