annotate rv40.c @ 5993:5dfff8f6f524 libavcodec

Intra types will be stored in int8_t array
author kostya
date Fri, 07 Dec 2007 05:50:23 +0000
parents 61f0987be684
children 625b4a680d41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
1 /*
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
2 * RV40 decoder
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
3 * Copyright (c) 2007 Konstantin Shishkov
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
4 *
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
6 *
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
11 *
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
16 *
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
20 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
21
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
22 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
23 * @file rv40.c
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
24 * RV40 decoder
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
25 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
26
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
27 #include "avcodec.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
28 #include "dsputil.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
29 #include "mpegvideo.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
30
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
31 #include "rv34.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
32 #include "rv40vlc2.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
33 #include "rv40data.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
34
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
35 static VLC aic_top_vlc;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
36 static VLC aic_mode1_vlc[AIC_MODE1_NUM], aic_mode2_vlc[AIC_MODE2_NUM];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
37 static VLC ptype_vlc[NUM_PTYPE_VLCS], btype_vlc[NUM_BTYPE_VLCS];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
38
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
39 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
40 * Initialize all tables.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
41 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
42 static void rv40_init_tables()
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
43 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
44 int i;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
45
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
46 init_vlc(&aic_top_vlc, AIC_TOP_BITS, AIC_TOP_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
47 rv40_aic_top_vlc_bits, 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
48 rv40_aic_top_vlc_codes, 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
49 for(i = 0; i < AIC_MODE1_NUM; i++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
50 // Every tenth VLC table is empty
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
51 if((i % 10) == 9) continue;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
52 init_vlc(&aic_mode1_vlc[i], AIC_MODE1_BITS, AIC_MODE1_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
53 aic_mode1_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
54 aic_mode1_vlc_codes[i], 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
55 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
56 for(i = 0; i < AIC_MODE2_NUM; i++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
57 init_vlc(&aic_mode2_vlc[i], AIC_MODE2_BITS, AIC_MODE2_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
58 aic_mode2_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
59 aic_mode2_vlc_codes[i], 2, 2, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
60 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
61 for(i = 0; i < NUM_PTYPE_VLCS; i++)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
62 init_vlc_sparse(&ptype_vlc[i], PTYPE_VLC_BITS, PTYPE_VLC_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
63 ptype_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
64 ptype_vlc_codes[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
65 ptype_vlc_syms, 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
66 for(i = 0; i < NUM_BTYPE_VLCS; i++)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
67 init_vlc_sparse(&btype_vlc[i], BTYPE_VLC_BITS, BTYPE_VLC_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
68 btype_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
69 btype_vlc_codes[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
70 btype_vlc_syms, 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
71 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
72
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
73 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
74 * Get stored dimension from bitstream.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
75 *
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
76 * If the width/height is the standard one then it's coded as a 3-bit index.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
77 * Otherwise it is coded as escaped 8-bit portions.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
78 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
79 static int get_dimension(GetBitContext *gb, const int *dim)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
80 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
81 int t = get_bits(gb, 3);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
82 int val = dim[t];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
83 if(val < 0)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
84 val = dim[get_bits1(gb) - val];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
85 if(!val){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
86 do{
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
87 t = get_bits(gb, 8);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
88 val += t << 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
89 }while(t == 0xFF);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
90 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
91 return val;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
92 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
93
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
94 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
95 * Get encoded picture size - usually this is called from rv40_parse_slice_header.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
96 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
97 static void rv40_parse_picture_size(GetBitContext *gb, int *w, int *h)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
98 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
99 *w = get_dimension(gb, rv40_standard_widths);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
100 *h = get_dimension(gb, rv40_standard_heights);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
101 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
102
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
103 static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
104 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
105 int t, mb_bits;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
106 int w = r->s.width, h = r->s.height;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
107 int mb_size;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
108
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
109 memset(si, 0, sizeof(SliceInfo));
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
110 if(get_bits1(gb))
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
111 return -1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
112 si->type = get_bits(gb, 2);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
113 if(si->type == 1) si->type = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
114 si->quant = get_bits(gb, 5);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
115 if(get_bits(gb, 2))
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
116 return -1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
117 si->vlc_set = get_bits(gb, 2);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
118 skip_bits1(gb);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
119 t = get_bits(gb, 13); /// ???
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
120 if(!si->type || !get_bits1(gb))
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
121 rv40_parse_picture_size(gb, &w, &h);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
122 si->width = w;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
123 si->height = h;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
124 mb_size = ((w + 15) >> 4) * ((h + 15) >> 4);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
125 mb_bits = ff_rv34_get_start_offset(gb, mb_size);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
126 si->start = get_bits(gb, mb_bits);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
127
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
128 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
129 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
130
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
131 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
132 * Decode 4x4 intra types array.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
133 */
5993
5dfff8f6f524 Intra types will be stored in int8_t array
kostya
parents: 5992
diff changeset
134 static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst)
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
135 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
136 MpegEncContext *s = &r->s;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
137 int i, j, k, v;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
138 int A, B, C;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
139 int pattern;
5993
5dfff8f6f524 Intra types will be stored in int8_t array
kostya
parents: 5992
diff changeset
140 int8_t *ptr;
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
141
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
142 for(i = 0; i < 4; i++, dst += s->b4_stride){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
143 if(!i && s->first_slice_line){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
144 pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
145 dst[0] = (pattern >> 2) & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
146 dst[1] = (pattern >> 1) & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
147 dst[2] = pattern & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
148 dst[3] = (pattern << 1) & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
149 continue;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
150 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
151 ptr = dst;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
152 for(j = 0; j < 4; j++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
153 /* Coefficients are read using VLC chosen by the prediction pattern
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
154 * The first one (used for retrieving a pair of coefficients) is
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
155 * constructed from the top, top right and left coefficients
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
156 * The second one (used for retrieving only one coefficient) is
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
157 * top + 10 * left.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
158 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
159 A = ptr[-s->b4_stride + 1]; // it won't be used for the last coefficient in a row
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
160 B = ptr[-s->b4_stride];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
161 C = ptr[-1];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
162 pattern = A + (B << 4) + (C << 8);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
163 for(k = 0; k < MODE2_PATTERNS_NUM; k++)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
164 if(pattern == rv40_aic_table_index[k])
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
165 break;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
166 if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
167 v = get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
168 *ptr++ = v/9;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
169 *ptr++ = v%9;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
170 j++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
171 }else{
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
172 if(B != -1 && C != -1)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
173 v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
174 else{ // tricky decoding
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
175 v = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
176 switch(C){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
177 case -1: // code 0 -> 1, 1 -> 0
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
178 if(B < 2)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
179 v = get_bits1(gb) ^ 1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
180 break;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
181 case 0:
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
182 case 2: // code 0 -> 2, 1 -> 0
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
183 v = (get_bits1(gb) ^ 1) << 1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
184 break;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
185 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
186 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
187 *ptr++ = v;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
188 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
189 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
190 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
191 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
192 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
193
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
194 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
195 * Decode macroblock information.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
196 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
197 static int rv40_decode_mb_info(RV34DecContext *r)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
198 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
199 MpegEncContext *s = &r->s;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
200 GetBitContext *gb = &s->gb;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
201 int q, i;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
202 int prev_type = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
203 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
204 int blocks[RV34_MB_TYPES] = {0};
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
205 int count = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
206
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
207 if(!r->s.mb_skip_run)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
208 r->s.mb_skip_run = ff_rv34_get_gamma(gb);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
209
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
210 if(--r->s.mb_skip_run)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
211 return RV34_MB_SKIP;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
212
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
213 if(r->avail[0])
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
214 blocks[r->mb_type[mb_pos - 1]]++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
215 if(r->avail[1]){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
216 blocks[r->mb_type[mb_pos - s->mb_stride]]++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
217 if(r->avail[2])
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
218 blocks[r->mb_type[mb_pos - s->mb_stride + 1]]++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
219 if(r->avail[3])
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
220 blocks[r->mb_type[mb_pos - s->mb_stride - 1]]++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
221 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
222
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
223 for(i = 0; i < RV34_MB_TYPES; i++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
224 if(blocks[i] > count){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
225 count = blocks[i];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
226 prev_type = i;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
227 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
228 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
229 if(s->pict_type == P_TYPE){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
230 prev_type = block_num_to_ptype_vlc_num[prev_type];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
231 q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
232 if(q < PBTYPE_ESCAPE)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
233 return q;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
234 q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
235 av_log(s->avctx, AV_LOG_ERROR, "Dquant for P-frame\n");
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
236 }else{
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
237 prev_type = block_num_to_btype_vlc_num[prev_type];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
238 q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
239 if(q < PBTYPE_ESCAPE)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
240 return q;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
241 q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
242 av_log(s->avctx, AV_LOG_ERROR, "Dquant for B-frame\n");
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
243 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
244 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
245 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
246
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
247 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
248 * Initialize decoder.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
249 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
250 static int rv40_decode_init(AVCodecContext *avctx)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
251 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
252 RV34DecContext *r = avctx->priv_data;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
253
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
254 r->rv30 = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
255 ff_rv34_decode_init(avctx);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
256 if(!aic_top_vlc.bits)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
257 rv40_init_tables();
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
258 r->parse_slice_header = rv40_parse_slice_header;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
259 r->decode_intra_types = rv40_decode_intra_types;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
260 r->decode_mb_info = rv40_decode_mb_info;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
261 r->luma_dc_quant_i = rv40_luma_dc_quant[0];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
262 r->luma_dc_quant_p = rv40_luma_dc_quant[1];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
263 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
264 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
265
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
266 AVCodec rv40_decoder = {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
267 "rv40",
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
268 CODEC_TYPE_VIDEO,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
269 CODEC_ID_RV40,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
270 sizeof(RV34DecContext),
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
271 rv40_decode_init,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
272 NULL,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
273 ff_rv34_decode_end,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
274 ff_rv34_decode_frame,
5992
61f0987be684 Add decoder flags
kostya
parents: 5983
diff changeset
275 CODEC_CAP_DR1 | CODEC_CAP_DELAY,
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
276 };