annotate rv40.c @ 8006:c7c1e85d14bc libavcodec

Rename variables to clarify the channel coupling element and corresponding target channel element. Patch by Alex Converse (alex converse gmail com)
author superdump
date Mon, 06 Oct 2008 16:22:11 +0000
parents e943e1409077
children 4a92ea42a8bc
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"
5995
a33699306850 Use existing function for VLC reading
kostya
parents: 5994
diff changeset
30 #include "golomb.h"
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
31
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
32 #include "rv34.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
33 #include "rv40vlc2.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
34 #include "rv40data.h"
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
35
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
36 static VLC aic_top_vlc;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
37 static VLC aic_mode1_vlc[AIC_MODE1_NUM], aic_mode2_vlc[AIC_MODE2_NUM];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
38 static VLC ptype_vlc[NUM_PTYPE_VLCS], btype_vlc[NUM_BTYPE_VLCS];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
39
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
40 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
41 * Initialize all tables.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
42 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6481
diff changeset
43 static av_cold void rv40_init_tables()
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
44 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
45 int i;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
46
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
47 init_vlc(&aic_top_vlc, AIC_TOP_BITS, AIC_TOP_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
48 rv40_aic_top_vlc_bits, 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
49 rv40_aic_top_vlc_codes, 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
50 for(i = 0; i < AIC_MODE1_NUM; i++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
51 // Every tenth VLC table is empty
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
52 if((i % 10) == 9) continue;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
53 init_vlc(&aic_mode1_vlc[i], AIC_MODE1_BITS, AIC_MODE1_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
54 aic_mode1_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
55 aic_mode1_vlc_codes[i], 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
56 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
57 for(i = 0; i < AIC_MODE2_NUM; i++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
58 init_vlc(&aic_mode2_vlc[i], AIC_MODE2_BITS, AIC_MODE2_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
59 aic_mode2_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
60 aic_mode2_vlc_codes[i], 2, 2, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
61 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
62 for(i = 0; i < NUM_PTYPE_VLCS; i++)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
63 init_vlc_sparse(&ptype_vlc[i], PTYPE_VLC_BITS, PTYPE_VLC_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
64 ptype_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
65 ptype_vlc_codes[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
66 ptype_vlc_syms, 1, 1, INIT_VLC_USE_STATIC);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
67 for(i = 0; i < NUM_BTYPE_VLCS; i++)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
68 init_vlc_sparse(&btype_vlc[i], BTYPE_VLC_BITS, BTYPE_VLC_SIZE,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
69 btype_vlc_bits[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
70 btype_vlc_codes[i], 1, 1,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
71 btype_vlc_syms, 1, 1, INIT_VLC_USE_STATIC);
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 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
75 * Get stored dimension from bitstream.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
76 *
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
77 * 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
78 * Otherwise it is coded as escaped 8-bit portions.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
79 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
80 static int get_dimension(GetBitContext *gb, const int *dim)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
81 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
82 int t = get_bits(gb, 3);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
83 int val = dim[t];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
84 if(val < 0)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
85 val = dim[get_bits1(gb) - val];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
86 if(!val){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
87 do{
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
88 t = get_bits(gb, 8);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
89 val += t << 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
90 }while(t == 0xFF);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
91 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
92 return val;
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 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
96 * Get encoded picture size - usually this is called from rv40_parse_slice_header.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
97 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
98 static void rv40_parse_picture_size(GetBitContext *gb, int *w, int *h)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
99 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
100 *w = get_dimension(gb, rv40_standard_widths);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
101 *h = get_dimension(gb, rv40_standard_heights);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
102 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
103
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
104 static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
105 {
6714
05c3a4b419e9 Calculate motion vector information based on PTS provided in slice header
kostya
parents: 6712
diff changeset
106 int mb_bits;
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
107 int w = r->s.width, h = r->s.height;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
108 int mb_size;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
109
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
110 memset(si, 0, sizeof(SliceInfo));
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
111 if(get_bits1(gb))
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
112 return -1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
113 si->type = get_bits(gb, 2);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
114 if(si->type == 1) si->type = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
115 si->quant = get_bits(gb, 5);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
116 if(get_bits(gb, 2))
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
117 return -1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
118 si->vlc_set = get_bits(gb, 2);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
119 skip_bits1(gb);
6714
05c3a4b419e9 Calculate motion vector information based on PTS provided in slice header
kostya
parents: 6712
diff changeset
120 si->pts = get_bits(gb, 13);
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
121 if(!si->type || !get_bits1(gb))
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
122 rv40_parse_picture_size(gb, &w, &h);
5994
625b4a680d41 Check decoded dimensions for validity
kostya
parents: 5993
diff changeset
123 if(avcodec_check_dimensions(r->s.avctx, w, h) < 0)
625b4a680d41 Check decoded dimensions for validity
kostya
parents: 5993
diff changeset
124 return -1;
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
125 si->width = w;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
126 si->height = h;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
127 mb_size = ((w + 15) >> 4) * ((h + 15) >> 4);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
128 mb_bits = ff_rv34_get_start_offset(gb, mb_size);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
129 si->start = get_bits(gb, mb_bits);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
130
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
131 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
132 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
133
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
134 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
135 * Decode 4x4 intra types array.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
136 */
5993
5dfff8f6f524 Intra types will be stored in int8_t array
kostya
parents: 5992
diff changeset
137 static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst)
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
138 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
139 MpegEncContext *s = &r->s;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
140 int i, j, k, v;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
141 int A, B, C;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
142 int pattern;
5993
5dfff8f6f524 Intra types will be stored in int8_t array
kostya
parents: 5992
diff changeset
143 int8_t *ptr;
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
144
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
145 for(i = 0; i < 4; i++, dst += s->b4_stride){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
146 if(!i && s->first_slice_line){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
147 pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
148 dst[0] = (pattern >> 2) & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
149 dst[1] = (pattern >> 1) & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
150 dst[2] = pattern & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
151 dst[3] = (pattern << 1) & 2;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
152 continue;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
153 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
154 ptr = dst;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
155 for(j = 0; j < 4; j++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
156 /* Coefficients are read using VLC chosen by the prediction pattern
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
157 * The first one (used for retrieving a pair of coefficients) is
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
158 * constructed from the top, top right and left coefficients
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
159 * The second one (used for retrieving only one coefficient) is
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
160 * top + 10 * left.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
161 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
162 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
163 B = ptr[-s->b4_stride];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
164 C = ptr[-1];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
165 pattern = A + (B << 4) + (C << 8);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
166 for(k = 0; k < MODE2_PATTERNS_NUM; k++)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
167 if(pattern == rv40_aic_table_index[k])
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
168 break;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
169 if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
170 v = get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
171 *ptr++ = v/9;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
172 *ptr++ = v%9;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
173 j++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
174 }else{
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
175 if(B != -1 && C != -1)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
176 v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
177 else{ // tricky decoding
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
178 v = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
179 switch(C){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
180 case -1: // code 0 -> 1, 1 -> 0
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
181 if(B < 2)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
182 v = get_bits1(gb) ^ 1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
183 break;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
184 case 0:
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
185 case 2: // code 0 -> 2, 1 -> 0
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
186 v = (get_bits1(gb) ^ 1) << 1;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
187 break;
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 *ptr++ = v;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
191 }
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 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
195 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
196
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
197 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
198 * Decode macroblock information.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
199 */
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
200 static int rv40_decode_mb_info(RV34DecContext *r)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
201 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
202 MpegEncContext *s = &r->s;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
203 GetBitContext *gb = &s->gb;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
204 int q, i;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
205 int prev_type = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
206 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
207 int blocks[RV34_MB_TYPES] = {0};
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
208 int count = 0;
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)
5995
a33699306850 Use existing function for VLC reading
kostya
parents: 5994
diff changeset
211 r->s.mb_skip_run = svq3_get_ue_golomb(gb) + 1;
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
212
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
213 if(--r->s.mb_skip_run)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
214 return RV34_MB_SKIP;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
215
6027
d1b9b395b1db RV40 decoder should use availability cache
kostya
parents: 5995
diff changeset
216 if(r->avail_cache[5-1])
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
217 blocks[r->mb_type[mb_pos - 1]]++;
6027
d1b9b395b1db RV40 decoder should use availability cache
kostya
parents: 5995
diff changeset
218 if(r->avail_cache[5-4]){
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
219 blocks[r->mb_type[mb_pos - s->mb_stride]]++;
6027
d1b9b395b1db RV40 decoder should use availability cache
kostya
parents: 5995
diff changeset
220 if(r->avail_cache[5-2])
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
221 blocks[r->mb_type[mb_pos - s->mb_stride + 1]]++;
6027
d1b9b395b1db RV40 decoder should use availability cache
kostya
parents: 5995
diff changeset
222 if(r->avail_cache[5-5])
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
223 blocks[r->mb_type[mb_pos - s->mb_stride - 1]]++;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
224 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
225
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
226 for(i = 0; i < RV34_MB_TYPES; i++){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
227 if(blocks[i] > count){
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
228 count = blocks[i];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
229 prev_type = i;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
230 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
231 }
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 6027
diff changeset
232 if(s->pict_type == FF_P_TYPE){
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
233 prev_type = block_num_to_ptype_vlc_num[prev_type];
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 if(q < PBTYPE_ESCAPE)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
236 return q;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
237 q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
238 av_log(s->avctx, AV_LOG_ERROR, "Dquant for P-frame\n");
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
239 }else{
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
240 prev_type = block_num_to_btype_vlc_num[prev_type];
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 if(q < PBTYPE_ESCAPE)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
243 return q;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
244 q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
245 av_log(s->avctx, AV_LOG_ERROR, "Dquant for B-frame\n");
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
246 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
247 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
248 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
249
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
250 /**
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
251 * Initialize decoder.
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
252 */
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6481
diff changeset
253 static av_cold int rv40_decode_init(AVCodecContext *avctx)
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
254 {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
255 RV34DecContext *r = avctx->priv_data;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
256
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
257 r->rv30 = 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
258 ff_rv34_decode_init(avctx);
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
259 if(!aic_top_vlc.bits)
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
260 rv40_init_tables();
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
261 r->parse_slice_header = rv40_parse_slice_header;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
262 r->decode_intra_types = rv40_decode_intra_types;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
263 r->decode_mb_info = rv40_decode_mb_info;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
264 r->luma_dc_quant_i = rv40_luma_dc_quant[0];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
265 r->luma_dc_quant_p = rv40_luma_dc_quant[1];
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
266 return 0;
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
267 }
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
268
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
269 AVCodec rv40_decoder = {
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
270 "rv40",
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
271 CODEC_TYPE_VIDEO,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
272 CODEC_ID_RV40,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
273 sizeof(RV34DecContext),
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
274 rv40_decode_init,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
275 NULL,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
276 ff_rv34_decode_end,
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
277 ff_rv34_decode_frame,
5992
61f0987be684 Add decoder flags
kostya
parents: 5983
diff changeset
278 CODEC_CAP_DR1 | CODEC_CAP_DELAY,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6714
diff changeset
279 .long_name = NULL_IF_CONFIG_SMALL("RealVideo 4.0"),
5983
f0ae240d8349 RV40 decoder specific functions
kostya
parents:
diff changeset
280 };