Mercurial > libavcodec.hg
annotate svq3.c @ 8195:cfe339a90018 libavcodec
cosmetics: consistent function declarations
author | diego |
---|---|
date | Sat, 22 Nov 2008 16:03:20 +0000 |
parents | f48a0ed93396 |
children | 2717c68de07f |
rev | line source |
---|---|
1234 | 1 /* |
2 * Copyright (c) 2003 The FFmpeg Project. | |
3 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
1234 | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
1234 | 10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
1234 | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Lesser General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
5215 | 19 */ |
20 | |
21 /* | |
1234 | 22 * How to use this decoder: |
23 * SVQ3 data is transported within Apple Quicktime files. Quicktime files | |
1235
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
24 * have stsd atoms to describe media trak properties. A stsd atom for a |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
25 * video trak contains 1 or more ImageDescription atoms. These atoms begin |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
26 * with the 4-byte length of the atom followed by the codec fourcc. Some |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
27 * decoders need information in this atom to operate correctly. Such |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
28 * is the case with SVQ3. In order to get the best use out of this decoder, |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
29 * the calling app must make the SVQ3 ImageDescription atom available |
1234 | 30 * via the AVCodecContext's extradata[_size] field: |
31 * | |
2967 | 32 * AVCodecContext.extradata = pointer to ImageDescription, first characters |
1235
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
33 * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length |
2967 | 34 * AVCodecContext.extradata_size = size of ImageDescription atom memory |
35 * buffer (which will be the same as the ImageDescription atom size field | |
1235
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
36 * from the QT file, minus 4 bytes since the length is missing) |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
37 * |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
38 * You will know you have these parameters passed correctly when the decoder |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
39 * correctly decodes this file: |
8bb75c3c2f21
change the way the ImageDescription is passed to the decoder
tmmm
parents:
1234
diff
changeset
|
40 * ftp://ftp.mplayerhq.hu/MPlayer/samples/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov |
1234 | 41 */ |
2967 | 42 |
8067 | 43 #ifdef CONFIG_ZLIB |
44 #include <zlib.h> | |
45 #endif | |
46 | |
8080
847bcb16028a
Add the function declaration of ff_svq1_packet_checksum to svq1.h and include
diego
parents:
8067
diff
changeset
|
47 #include "svq1.h" |
847bcb16028a
Add the function declaration of ff_svq1_packet_checksum to svq1.h and include
diego
parents:
8067
diff
changeset
|
48 |
1234 | 49 /** |
50 * @file svq3.c | |
51 * svq3 decoder. | |
52 */ | |
53 | |
2967 | 54 #define FULLPEL_MODE 1 |
55 #define HALFPEL_MODE 2 | |
1265 | 56 #define THIRDPEL_MODE 3 |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
57 #define PREDICT_MODE 4 |
2967 | 58 |
1252 | 59 /* dual scan (from some older h264 draft) |
60 o-->o-->o o | |
61 | /| | |
62 o o o / o | |
63 | / | |/ | | |
64 o o o o | |
2967 | 65 / |
1252 | 66 o-->o-->o-->o |
67 */ | |
1234 | 68 static const uint8_t svq3_scan[16]={ |
69 0+0*4, 1+0*4, 2+0*4, 2+1*4, | |
70 2+2*4, 3+0*4, 3+1*4, 3+2*4, | |
71 0+1*4, 0+2*4, 1+1*4, 1+2*4, | |
72 0+3*4, 1+3*4, 2+3*4, 3+3*4, | |
73 }; | |
74 | |
75 static const uint8_t svq3_pred_0[25][2] = { | |
76 { 0, 0 }, | |
77 { 1, 0 }, { 0, 1 }, | |
78 { 0, 2 }, { 1, 1 }, { 2, 0 }, | |
79 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 }, | |
80 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 }, | |
81 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 }, | |
82 { 2, 4 }, { 3, 3 }, { 4, 2 }, | |
83 { 4, 3 }, { 3, 4 }, | |
84 { 4, 4 } | |
85 }; | |
86 | |
87 static const int8_t svq3_pred_1[6][6][5] = { | |
88 { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, | |
89 { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } }, | |
90 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 }, | |
91 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } }, | |
92 { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 }, | |
93 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } }, | |
94 { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 }, | |
95 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } }, | |
96 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 }, | |
97 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } }, | |
98 { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 }, | |
99 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } }, | |
100 }; | |
101 | |
102 static const struct { uint8_t run; uint8_t level; } svq3_dct_tables[2][16] = { | |
103 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 }, | |
104 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } }, | |
105 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 }, | |
106 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } } | |
107 }; | |
108 | |
109 static const uint32_t svq3_dequant_coeff[32] = { | |
110 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718, | |
111 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873, | |
112 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683, | |
113 61694, 68745, 77615, 89113,100253,109366,126635,141533 | |
114 }; | |
115 | |
116 | |
8195 | 117 static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp) |
118 { | |
1234 | 119 const int qmul= svq3_dequant_coeff[qp]; |
120 #define stride 16 | |
121 int i; | |
122 int temp[16]; | |
123 static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride}; | |
124 static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride}; | |
125 | |
126 for(i=0; i<4; i++){ | |
127 const int offset= y_offset[i]; | |
128 const int z0= 13*(block[offset+stride*0] + block[offset+stride*4]); | |
129 const int z1= 13*(block[offset+stride*0] - block[offset+stride*4]); | |
130 const int z2= 7* block[offset+stride*1] - 17*block[offset+stride*5]; | |
131 const int z3= 17* block[offset+stride*1] + 7*block[offset+stride*5]; | |
132 | |
133 temp[4*i+0]= z0+z3; | |
134 temp[4*i+1]= z1+z2; | |
135 temp[4*i+2]= z1-z2; | |
136 temp[4*i+3]= z0-z3; | |
137 } | |
138 | |
139 for(i=0; i<4; i++){ | |
140 const int offset= x_offset[i]; | |
141 const int z0= 13*(temp[4*0+i] + temp[4*2+i]); | |
142 const int z1= 13*(temp[4*0+i] - temp[4*2+i]); | |
143 const int z2= 7* temp[4*1+i] - 17*temp[4*3+i]; | |
144 const int z3= 17* temp[4*1+i] + 7*temp[4*3+i]; | |
145 | |
146 block[stride*0 +offset]= ((z0 + z3)*qmul + 0x80000)>>20; | |
147 block[stride*2 +offset]= ((z1 + z2)*qmul + 0x80000)>>20; | |
148 block[stride*8 +offset]= ((z1 - z2)*qmul + 0x80000)>>20; | |
149 block[stride*10+offset]= ((z0 - z3)*qmul + 0x80000)>>20; | |
150 } | |
151 } | |
152 #undef stride | |
153 | |
8195 | 154 static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc) |
155 { | |
1234 | 156 const int qmul= svq3_dequant_coeff[qp]; |
157 int i; | |
4176 | 158 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; |
1234 | 159 |
160 if (dc) { | |
161 dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2)); | |
162 block[0] = 0; | |
163 } | |
164 | |
165 for (i=0; i < 4; i++) { | |
166 const int z0= 13*(block[0 + 4*i] + block[2 + 4*i]); | |
167 const int z1= 13*(block[0 + 4*i] - block[2 + 4*i]); | |
168 const int z2= 7* block[1 + 4*i] - 17*block[3 + 4*i]; | |
169 const int z3= 17* block[1 + 4*i] + 7*block[3 + 4*i]; | |
170 | |
171 block[0 + 4*i]= z0 + z3; | |
172 block[1 + 4*i]= z1 + z2; | |
173 block[2 + 4*i]= z1 - z2; | |
174 block[3 + 4*i]= z0 - z3; | |
175 } | |
176 | |
177 for (i=0; i < 4; i++) { | |
178 const int z0= 13*(block[i + 4*0] + block[i + 4*2]); | |
179 const int z1= 13*(block[i + 4*0] - block[i + 4*2]); | |
180 const int z2= 7* block[i + 4*1] - 17*block[i + 4*3]; | |
181 const int z3= 17* block[i + 4*1] + 7*block[i + 4*3]; | |
182 const int rr= (dc + 0x80000); | |
183 | |
184 dst[i + stride*0]= cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ]; | |
185 dst[i + stride*1]= cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ]; | |
186 dst[i + stride*2]= cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ]; | |
187 dst[i + stride*3]= cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ]; | |
188 } | |
189 } | |
190 | |
8195 | 191 static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block, |
192 int index, const int type) | |
193 { | |
1234 | 194 static const uint8_t *const scan_patterns[4] = |
195 { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan }; | |
196 | |
197 int run, level, sign, vlc, limit; | |
198 const int intra = (3 * type) >> 2; | |
199 const uint8_t *const scan = scan_patterns[type]; | |
200 | |
201 for (limit=(16 >> intra); index < 16; index=limit, limit+=8) { | |
202 for (; (vlc = svq3_get_ue_golomb (gb)) != 0; index++) { | |
203 | |
204 if (vlc == INVALID_VLC) | |
2979 | 205 return -1; |
1234 | 206 |
207 sign = (vlc & 0x1) - 1; | |
208 vlc = (vlc + 1) >> 1; | |
209 | |
210 if (type == 3) { | |
2979 | 211 if (vlc < 3) { |
212 run = 0; | |
213 level = vlc; | |
214 } else if (vlc < 4) { | |
215 run = 1; | |
216 level = 1; | |
217 } else { | |
218 run = (vlc & 0x3); | |
219 level = ((vlc + 9) >> 2) - run; | |
220 } | |
1234 | 221 } else { |
2979 | 222 if (vlc < 16) { |
223 run = svq3_dct_tables[intra][vlc].run; | |
224 level = svq3_dct_tables[intra][vlc].level; | |
225 } else if (intra) { | |
226 run = (vlc & 0x7); | |
227 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1))); | |
228 } else { | |
229 run = (vlc & 0xF); | |
230 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0))); | |
231 } | |
1234 | 232 } |
233 | |
234 if ((index += run) >= limit) | |
2979 | 235 return -1; |
1234 | 236 |
237 block[scan[index]] = (level ^ sign) - sign; | |
238 } | |
239 | |
240 if (type != 2) { | |
241 break; | |
242 } | |
243 } | |
244 | |
245 return 0; | |
246 } | |
247 | |
8195 | 248 static inline void svq3_mc_dir_part(MpegEncContext *s, |
249 int x, int y, int width, int height, | |
250 int mx, int my, int dxy, | |
251 int thirdpel, int dir, int avg) | |
252 { | |
1319 | 253 const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture; |
1234 | 254 uint8_t *src, *dest; |
255 int i, emu = 0; | |
1267
85b71f9f7450
moving the svq3 motion compensation stuff to dsputil (this also means that existing optimized halfpel code is used now ...)
michaelni
parents:
1265
diff
changeset
|
256 int blocksize= 2 - (width>>3); //16->0, 8->1, 4->2 |
1234 | 257 |
1265 | 258 mx += x; |
259 my += y; | |
2967 | 260 |
1268 | 261 if (mx < 0 || mx >= (s->h_edge_pos - width - 1) || |
262 my < 0 || my >= (s->v_edge_pos - height - 1)) { | |
1234 | 263 |
264 if ((s->flags & CODEC_FLAG_EMU_EDGE)) { | |
265 emu = 1; | |
266 } | |
267 | |
4594 | 268 mx = av_clip (mx, -16, (s->h_edge_pos - width + 15)); |
269 my = av_clip (my, -16, (s->v_edge_pos - height + 15)); | |
1234 | 270 } |
271 | |
272 /* form component predictions */ | |
273 dest = s->current_picture.data[0] + x + y*s->linesize; | |
1319 | 274 src = pic->data[0] + mx + my*s->linesize; |
1234 | 275 |
276 if (emu) { | |
1321 | 277 ff_emulated_edge_mc (s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1), |
2979 | 278 mx, my, s->h_edge_pos, s->v_edge_pos); |
1234 | 279 src = s->edge_emu_buffer; |
280 } | |
1267
85b71f9f7450
moving the svq3 motion compensation stuff to dsputil (this also means that existing optimized halfpel code is used now ...)
michaelni
parents:
1265
diff
changeset
|
281 if(thirdpel) |
1319 | 282 (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize, width, height); |
1267
85b71f9f7450
moving the svq3 motion compensation stuff to dsputil (this also means that existing optimized halfpel code is used now ...)
michaelni
parents:
1265
diff
changeset
|
283 else |
1319 | 284 (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize, height); |
1234 | 285 |
286 if (!(s->flags & CODEC_FLAG_GRAY)) { | |
2979 | 287 mx = (mx + (mx < (int) x)) >> 1; |
288 my = (my + (my < (int) y)) >> 1; | |
1234 | 289 width = (width >> 1); |
290 height = (height >> 1); | |
1267
85b71f9f7450
moving the svq3 motion compensation stuff to dsputil (this also means that existing optimized halfpel code is used now ...)
michaelni
parents:
1265
diff
changeset
|
291 blocksize++; |
1234 | 292 |
293 for (i=1; i < 3; i++) { | |
294 dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize; | |
1319 | 295 src = pic->data[i] + mx + my*s->uvlinesize; |
1234 | 296 |
297 if (emu) { | |
1321 | 298 ff_emulated_edge_mc (s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1), |
2979 | 299 mx, my, (s->h_edge_pos >> 1), (s->v_edge_pos >> 1)); |
1321 | 300 src = s->edge_emu_buffer; |
1234 | 301 } |
1267
85b71f9f7450
moving the svq3 motion compensation stuff to dsputil (this also means that existing optimized halfpel code is used now ...)
michaelni
parents:
1265
diff
changeset
|
302 if(thirdpel) |
1319 | 303 (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->uvlinesize, width, height); |
1267
85b71f9f7450
moving the svq3 motion compensation stuff to dsputil (this also means that existing optimized halfpel code is used now ...)
michaelni
parents:
1265
diff
changeset
|
304 else |
1319 | 305 (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->uvlinesize, height); |
1234 | 306 } |
307 } | |
308 } | |
309 | |
8195 | 310 static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir, |
311 int avg) | |
312 { | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
313 int i, j, k, mx, my, dx, dy, x, y; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
314 MpegEncContext *const s = (MpegEncContext *) h; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
315 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1); |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
316 const int part_height = 16 >> ((unsigned) (size + 1) / 3); |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
317 const int extra_width = (mode == PREDICT_MODE) ? -16*6 : 0; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
318 const int h_edge_pos = 6*(s->h_edge_pos - part_width ) - extra_width; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
319 const int v_edge_pos = 6*(s->v_edge_pos - part_height) - extra_width; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
320 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
321 for (i=0; i < 16; i+=part_height) { |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
322 for (j=0; j < 16; j+=part_width) { |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
323 const int b_xy = (4*s->mb_x+(j>>2)) + (4*s->mb_y+(i>>2))*h->b_stride; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
324 int dxy; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
325 x = 16*s->mb_x + j; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
326 y = 16*s->mb_y + i; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
327 k = ((j>>2)&1) + ((i>>1)&2) + ((j>>1)&4) + (i&8); |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
328 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
329 if (mode != PREDICT_MODE) { |
2979 | 330 pred_motion (h, k, (part_width >> 2), dir, 1, &mx, &my); |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
331 } else { |
2979 | 332 mx = s->next_picture.motion_val[0][b_xy][0]<<1; |
333 my = s->next_picture.motion_val[0][b_xy][1]<<1; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
334 |
2979 | 335 if (dir == 0) { |
336 mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1; | |
337 my = ((my * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1; | |
338 } else { | |
339 mx = ((mx * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1; | |
340 my = ((my * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1; | |
341 } | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
342 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
343 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
344 /* clip motion vector prediction to frame border */ |
4594 | 345 mx = av_clip (mx, extra_width - 6*x, h_edge_pos - 6*x); |
346 my = av_clip (my, extra_width - 6*y, v_edge_pos - 6*y); | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
347 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
348 /* get (optional) motion vector differential */ |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
349 if (mode == PREDICT_MODE) { |
2979 | 350 dx = dy = 0; |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
351 } else { |
2979 | 352 dy = svq3_get_se_golomb (&s->gb); |
353 dx = svq3_get_se_golomb (&s->gb); | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
354 |
2979 | 355 if (dx == INVALID_VLC || dy == INVALID_VLC) { |
2452 | 356 av_log(h->s.avctx, AV_LOG_ERROR, "invalid MV vlc\n"); |
2979 | 357 return -1; |
358 } | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
359 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
360 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
361 /* compute motion vector */ |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
362 if (mode == THIRDPEL_MODE) { |
2979 | 363 int fx, fy; |
364 mx = ((mx + 1)>>1) + dx; | |
365 my = ((my + 1)>>1) + dy; | |
366 fx= ((unsigned)(mx + 0x3000))/3 - 0x1000; | |
367 fy= ((unsigned)(my + 0x3000))/3 - 0x1000; | |
368 dxy= (mx - 3*fx) + 4*(my - 3*fy); | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
369 |
2979 | 370 svq3_mc_dir_part (s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg); |
371 mx += mx; | |
372 my += my; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
373 } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) { |
2979 | 374 mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000; |
375 my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000; | |
376 dxy= (mx&1) + 2*(my&1); | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
377 |
2979 | 378 svq3_mc_dir_part (s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg); |
379 mx *= 3; | |
380 my *= 3; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
381 } else { |
2979 | 382 mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000; |
383 my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
384 |
2979 | 385 svq3_mc_dir_part (s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg); |
386 mx *= 6; | |
387 my *= 6; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
388 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
389 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
390 /* update mv_cache */ |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
391 if (mode != PREDICT_MODE) { |
2979 | 392 int32_t mv = pack16to32(mx,my); |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
393 |
2979 | 394 if (part_height == 8 && i < 8) { |
395 *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv; | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
396 |
2979 | 397 if (part_width == 8 && j < 8) { |
398 *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv; | |
399 } | |
400 } | |
401 if (part_width == 8 && j < 8) { | |
402 *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv; | |
403 } | |
404 if (part_width == 4 || part_height == 4) { | |
405 *(int32_t *) h->mv_cache[dir][scan8[k]] = mv; | |
406 } | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
407 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
408 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
409 /* write back motion vectors */ |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
410 fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4); |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
411 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
412 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
413 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
414 return 0; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
415 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
416 |
8195 | 417 static int svq3_decode_mb(H264Context *h, unsigned int mb_type) |
418 { | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
419 int i, j, k, m, dir, mode; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
420 int cbp = 0; |
1234 | 421 uint32_t vlc; |
422 int8_t *top, *left; | |
423 MpegEncContext *const s = (MpegEncContext *) h; | |
6787 | 424 const int mb_xy = h->mb_xy; |
1234 | 425 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; |
426 | |
2979 | 427 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF; |
428 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF; | |
429 h->topright_samples_available = 0xFFFF; | |
1234 | 430 |
2979 | 431 if (mb_type == 0) { /* SKIP */ |
6481 | 432 if (s->pict_type == FF_P_TYPE || s->next_picture.mb_type[mb_xy] == -1) { |
1319 | 433 svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0); |
434 | |
6481 | 435 if (s->pict_type == FF_B_TYPE) { |
2979 | 436 svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1); |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
437 } |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
438 |
1319 | 439 mb_type = MB_TYPE_SKIP; |
440 } else { | |
2088
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
441 mb_type= FFMIN(s->next_picture.mb_type[mb_xy], 6); |
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
442 if(svq3_mc_dir (h, mb_type, PREDICT_MODE, 0, 0) < 0) |
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
443 return -1; |
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
444 if(svq3_mc_dir (h, mb_type, PREDICT_MODE, 1, 1) < 0) |
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
445 return -1; |
1319 | 446 |
447 mb_type = MB_TYPE_16x16; | |
448 } | |
2979 | 449 } else if (mb_type < 8) { /* INTER */ |
5513 | 450 if (h->thirdpel_flag && h->halfpel_flag == !get_bits1 (&s->gb)) { |
1265 | 451 mode = THIRDPEL_MODE; |
5513 | 452 } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits1 (&s->gb)) { |
1265 | 453 mode = HALFPEL_MODE; |
1234 | 454 } else { |
1265 | 455 mode = FULLPEL_MODE; |
1234 | 456 } |
457 | |
458 /* fill caches */ | |
1319 | 459 /* note ref_cache should contain here: |
1252 | 460 ???????? |
461 ???11111 | |
462 N??11111 | |
463 N??11111 | |
464 N??11111 | |
465 */ | |
2967 | 466 |
1319 | 467 for (m=0; m < 2; m++) { |
468 if (s->mb_x > 0 && h->intra4x4_pred_mode[mb_xy - 1][0] != -1) { | |
2979 | 469 for (i=0; i < 4; i++) { |
470 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - 1 + i*h->b_stride]; | |
471 } | |
1319 | 472 } else { |
2979 | 473 for (i=0; i < 4; i++) { |
474 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0; | |
475 } | |
1234 | 476 } |
1319 | 477 if (s->mb_y > 0) { |
2979 | 478 memcpy (h->mv_cache[m][scan8[0] - 1*8], s->current_picture.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t)); |
479 memset (&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[mb_xy - s->mb_stride][4] == -1) ? PART_NOT_AVAILABLE : 1, 4); | |
1234 | 480 |
2979 | 481 if (s->mb_x < (s->mb_width - 1)) { |
482 *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride + 4]; | |
483 h->ref_cache[m][scan8[0] + 4 - 1*8] = | |
484 (h->intra4x4_pred_mode[mb_xy - s->mb_stride + 1][0] == -1 || | |
485 h->intra4x4_pred_mode[mb_xy - s->mb_stride][4] == -1) ? PART_NOT_AVAILABLE : 1; | |
486 }else | |
487 h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE; | |
488 if (s->mb_x > 0) { | |
489 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride - 1]; | |
490 h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] == -1) ? PART_NOT_AVAILABLE : 1; | |
491 }else | |
492 h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE; | |
1252 | 493 }else |
2979 | 494 memset (&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8); |
1319 | 495 |
6481 | 496 if (s->pict_type != FF_B_TYPE) |
2979 | 497 break; |
1319 | 498 } |
1234 | 499 |
500 /* decode motion vector(s) and form prediction(s) */ | |
6481 | 501 if (s->pict_type == FF_P_TYPE) { |
2088
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
502 if(svq3_mc_dir (h, (mb_type - 1), mode, 0, 0) < 0) |
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
503 return -1; |
6481 | 504 } else { /* FF_B_TYPE */ |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
505 if (mb_type != 2) { |
2979 | 506 if(svq3_mc_dir (h, 0, mode, 0, 0) < 0) |
2088
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
507 return -1; |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
508 } else { |
2979 | 509 for (i=0; i < 4; i++) { |
510 memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); | |
511 } | |
1234 | 512 } |
1319 | 513 if (mb_type != 1) { |
2979 | 514 if(svq3_mc_dir (h, 0, mode, 1, (mb_type == 3)) < 0) |
2088
19d4d5c6a8f4
1000l to myself for FFMIN(...,0) instead of ...,6)
michael
parents:
2086
diff
changeset
|
515 return -1; |
1319 | 516 } else { |
2979 | 517 for (i=0; i < 4; i++) { |
518 memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); | |
519 } | |
1319 | 520 } |
1234 | 521 } |
522 | |
523 mb_type = MB_TYPE_16x16; | |
2979 | 524 } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */ |
1234 | 525 memset (h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t)); |
526 | |
1319 | 527 if (mb_type == 8) { |
528 if (s->mb_x > 0) { | |
2979 | 529 for (i=0; i < 4; i++) { |
530 h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[mb_xy - 1][i]; | |
531 } | |
532 if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) { | |
533 h->left_samples_available = 0x5F5F; | |
534 } | |
1234 | 535 } |
1319 | 536 if (s->mb_y > 0) { |
2979 | 537 h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][4]; |
538 h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][5]; | |
539 h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][6]; | |
540 h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][3]; | |
1319 | 541 |
2979 | 542 if (h->intra4x4_pred_mode_cache[4+8*0] == -1) { |
543 h->top_samples_available = 0x33FF; | |
544 } | |
1319 | 545 } |
1234 | 546 |
1319 | 547 /* decode prediction codes for luma blocks */ |
548 for (i=0; i < 16; i+=2) { | |
2979 | 549 vlc = svq3_get_ue_golomb (&s->gb); |
1234 | 550 |
2979 | 551 if (vlc >= 25){ |
2452 | 552 av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc); |
2979 | 553 return -1; |
2452 | 554 } |
1319 | 555 |
2979 | 556 left = &h->intra4x4_pred_mode_cache[scan8[i] - 1]; |
557 top = &h->intra4x4_pred_mode_cache[scan8[i] - 8]; | |
1234 | 558 |
2979 | 559 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]]; |
560 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]]; | |
1234 | 561 |
2979 | 562 if (left[1] == -1 || left[2] == -1){ |
2452 | 563 av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n"); |
2979 | 564 return -1; |
2452 | 565 } |
1319 | 566 } |
2979 | 567 } else { /* mb_type == 33, DC_128_PRED block type */ |
1319 | 568 for (i=0; i < 4; i++) { |
2979 | 569 memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4); |
1319 | 570 } |
1234 | 571 } |
572 | |
573 write_back_intra_pred_mode (h); | |
1319 | 574 |
575 if (mb_type == 8) { | |
576 check_intra4x4_pred_mode (h); | |
577 | |
578 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF; | |
579 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF; | |
580 } else { | |
581 for (i=0; i < 4; i++) { | |
582 memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4); | |
583 } | |
584 | |
585 h->top_samples_available = 0x33FF; | |
586 h->left_samples_available = 0x5F5F; | |
587 } | |
1234 | 588 |
589 mb_type = MB_TYPE_INTRA4x4; | |
2979 | 590 } else { /* INTRA16x16 */ |
1234 | 591 dir = i_mb_type_info[mb_type - 8].pred_mode; |
592 dir = (dir >> 1) ^ 3*(dir & 1) ^ 1; | |
593 | |
2452 | 594 if ((h->intra16x16_pred_mode = check_intra_pred_mode (h, dir)) == -1){ |
595 av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n"); | |
1234 | 596 return -1; |
2452 | 597 } |
1234 | 598 |
599 cbp = i_mb_type_info[mb_type - 8].cbp; | |
600 mb_type = MB_TYPE_INTRA16x16; | |
601 } | |
602 | |
6481 | 603 if (!IS_INTER(mb_type) && s->pict_type != FF_I_TYPE) { |
1234 | 604 for (i=0; i < 4; i++) { |
605 memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); | |
606 } | |
6481 | 607 if (s->pict_type == FF_B_TYPE) { |
1319 | 608 for (i=0; i < 4; i++) { |
2979 | 609 memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); |
1319 | 610 } |
611 } | |
1234 | 612 } |
613 if (!IS_INTRA4x4(mb_type)) { | |
614 memset (h->intra4x4_pred_mode[mb_xy], DC_PRED, 8); | |
615 } | |
6481 | 616 if (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE) { |
1252 | 617 memset (h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t)); |
618 s->dsp.clear_blocks(h->mb); | |
1234 | 619 } |
620 | |
6481 | 621 if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE)) { |
2452 | 622 if ((vlc = svq3_get_ue_golomb (&s->gb)) >= 48){ |
623 av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc); | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
624 return -1; |
2452 | 625 } |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
626 |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
627 cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc]; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
628 } |
6481 | 629 if (IS_INTRA16x16(mb_type) || (s->pict_type != FF_I_TYPE && s->adaptive_quant && cbp)) { |
1234 | 630 s->qscale += svq3_get_se_golomb (&s->gb); |
631 | |
2452 | 632 if (s->qscale > 31){ |
633 av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale); | |
1234 | 634 return -1; |
2452 | 635 } |
1234 | 636 } |
637 if (IS_INTRA16x16(mb_type)) { | |
2452 | 638 if (svq3_decode_block (&s->gb, h->mb, 0, 0)){ |
639 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n"); | |
1234 | 640 return -1; |
2452 | 641 } |
1234 | 642 } |
643 | |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
644 if (cbp) { |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
645 const int index = IS_INTRA16x16(mb_type) ? 1 : 0; |
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
646 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1); |
1234 | 647 |
648 for (i=0; i < 4; i++) { | |
649 if ((cbp & (1 << i))) { | |
2979 | 650 for (j=0; j < 4; j++) { |
651 k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j); | |
652 h->non_zero_count_cache[ scan8[k] ] = 1; | |
1234 | 653 |
2979 | 654 if (svq3_decode_block (&s->gb, &h->mb[16*k], index, type)){ |
2452 | 655 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n"); |
2979 | 656 return -1; |
2452 | 657 } |
2979 | 658 } |
1234 | 659 } |
660 } | |
661 | |
662 if ((cbp & 0x30)) { | |
663 for (i=0; i < 2; ++i) { | |
2979 | 664 if (svq3_decode_block (&s->gb, &h->mb[16*(16 + 4*i)], 0, 3)){ |
2452 | 665 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n"); |
2979 | 666 return -1; |
2452 | 667 } |
1234 | 668 } |
669 | |
670 if ((cbp & 0x20)) { | |
2979 | 671 for (i=0; i < 8; i++) { |
672 h->non_zero_count_cache[ scan8[16+i] ] = 1; | |
1234 | 673 |
2979 | 674 if (svq3_decode_block (&s->gb, &h->mb[16*(16 + i)], 1, 1)){ |
2452 | 675 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n"); |
2979 | 676 return -1; |
2452 | 677 } |
2979 | 678 } |
1234 | 679 } |
680 } | |
681 } | |
682 | |
683 s->current_picture.mb_type[mb_xy] = mb_type; | |
684 | |
685 if (IS_INTRA(mb_type)) { | |
686 h->chroma_pred_mode = check_intra_pred_mode (h, DC_PRED8x8); | |
687 } | |
688 | |
689 return 0; | |
690 } | |
691 | |
8195 | 692 static int svq3_decode_slice_header(H264Context *h) |
693 { | |
1319 | 694 MpegEncContext *const s = (MpegEncContext *) h; |
6789
8107e891b226
Previous commit missed an initialization - this fixes FATE's test sample.
astrange
parents:
6787
diff
changeset
|
695 const int mb_xy = h->mb_xy; |
1319 | 696 int i, header; |
697 | |
698 header = get_bits (&s->gb, 8); | |
699 | |
700 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) { | |
701 /* TODO: what? */ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1330
diff
changeset
|
702 av_log(h->s.avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header); |
1319 | 703 return -1; |
704 } else { | |
705 int length = (header >> 5) & 3; | |
706 | |
2614
5e24800ab329
various fixes related to the non alt_bitstream_reader
michael
parents:
2453
diff
changeset
|
707 h->next_slice_index = get_bits_count(&s->gb) + 8*show_bits (&s->gb, 8*length) + 8*length; |
1319 | 708 |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
709 if (h->next_slice_index > s->gb.size_in_bits){ |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
710 av_log(h->s.avctx, AV_LOG_ERROR, "slice after bitstream end\n"); |
1319 | 711 return -1; |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
712 } |
1319 | 713 |
714 s->gb.size_in_bits = h->next_slice_index - 8*(length - 1); | |
2614
5e24800ab329
various fixes related to the non alt_bitstream_reader
michael
parents:
2453
diff
changeset
|
715 skip_bits(&s->gb, 8); |
1319 | 716 |
8066
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
717 if (h->svq3_watermark_key) { |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
718 uint32_t header = AV_RL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1]); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
719 AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1], header ^ h->svq3_watermark_key); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
720 } |
1319 | 721 if (length > 0) { |
7291 | 722 memcpy ((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3], |
1319 | 723 &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1)); |
724 } | |
725 } | |
726 | |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
727 if ((i = svq3_get_ue_golomb (&s->gb)) == INVALID_VLC || i >= 3){ |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
728 av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i); |
1319 | 729 return -1; |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
730 } |
1319 | 731 |
732 h->slice_type = golomb_to_pict_type[i]; | |
733 | |
734 if ((header & 0x9F) == 2) { | |
735 i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1)); | |
736 s->mb_skip_run = get_bits (&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width)); | |
737 } else { | |
5519 | 738 skip_bits1 (&s->gb); |
1319 | 739 s->mb_skip_run = 0; |
740 } | |
741 | |
742 h->slice_num = get_bits (&s->gb, 8); | |
743 s->qscale = get_bits (&s->gb, 5); | |
744 s->adaptive_quant = get_bits1 (&s->gb); | |
745 | |
746 /* unknown fields */ | |
5519 | 747 skip_bits1 (&s->gb); |
1319 | 748 |
749 if (h->unknown_svq3_flag) { | |
5519 | 750 skip_bits1 (&s->gb); |
1319 | 751 } |
752 | |
5519 | 753 skip_bits1 (&s->gb); |
754 skip_bits (&s->gb, 2); | |
1319 | 755 |
756 while (get_bits1 (&s->gb)) { | |
5519 | 757 skip_bits (&s->gb, 8); |
1319 | 758 } |
759 | |
760 /* reset intra predictors and invalidate motion vector references */ | |
761 if (s->mb_x > 0) { | |
762 memset (h->intra4x4_pred_mode[mb_xy - 1], -1, 4*sizeof(int8_t)); | |
763 memset (h->intra4x4_pred_mode[mb_xy - s->mb_x], -1, 8*sizeof(int8_t)*s->mb_x); | |
764 } | |
765 if (s->mb_y > 0) { | |
766 memset (h->intra4x4_pred_mode[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x)); | |
767 | |
768 if (s->mb_x > 0) { | |
769 h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] = -1; | |
770 } | |
771 } | |
772 | |
773 return 0; | |
774 } | |
775 | |
8195 | 776 static int svq3_decode_frame(AVCodecContext *avctx, |
777 void *data, int *data_size, | |
778 const uint8_t *buf, int buf_size) | |
779 { | |
1234 | 780 MpegEncContext *const s = avctx->priv_data; |
781 H264Context *const h = avctx->priv_data; | |
1319 | 782 int m, mb_type; |
1877
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
783 unsigned char *extradata; |
1878
838c18d1e7fc
be smarter about the variable size of the extra SVQ3 data
melanson
parents:
1877
diff
changeset
|
784 unsigned int size; |
1319 | 785 |
1234 | 786 s->flags = avctx->flags; |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1699
diff
changeset
|
787 s->flags2 = avctx->flags2; |
1699 | 788 s->unrestricted_mv = 1; |
789 | |
1234 | 790 if (!s->context_initialized) { |
1268 | 791 s->width = avctx->width; |
792 s->height = avctx->height; | |
1234 | 793 h->halfpel_flag = 1; |
794 h->thirdpel_flag = 1; | |
1319 | 795 h->unknown_svq3_flag = 0; |
5231
07a97575d0c4
Add support for streams with different chroma_qp_index_offset
gpoirier
parents:
5215
diff
changeset
|
796 h->chroma_qp[0] = h->chroma_qp[1] = 4; |
1234 | 797 |
798 if (MPV_common_init (s) < 0) | |
799 return -1; | |
800 | |
1268 | 801 h->b_stride = 4*s->mb_width; |
802 | |
1234 | 803 alloc_tables (h); |
1319 | 804 |
1877
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
805 /* prowl for the "SEQH" marker in the extradata */ |
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
806 extradata = (unsigned char *)avctx->extradata; |
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
807 for (m = 0; m < avctx->extradata_size; m++) { |
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
808 if (!memcmp (extradata, "SEQH", 4)) |
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
809 break; |
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
810 extradata++; |
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
811 } |
1878
838c18d1e7fc
be smarter about the variable size of the extra SVQ3 data
melanson
parents:
1877
diff
changeset
|
812 |
1877
869256817a91
smarten up the SVQ3 extradata decoder without changing the external API
melanson
parents:
1754
diff
changeset
|
813 /* if a match was found, parse the extra data */ |
4392
e0c94f1b8f55
maybe fix segfault with missing extradata (unchecked)
michael
parents:
4364
diff
changeset
|
814 if (extradata && !memcmp (extradata, "SEQH", 4)) { |
1319 | 815 |
816 GetBitContext gb; | |
1234 | 817 |
4364 | 818 size = AV_RB32(&extradata[4]); |
2966
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2792
diff
changeset
|
819 init_get_bits (&gb, extradata + 8, size*8); |
1234 | 820 |
1319 | 821 /* 'frame size code' and optional 'width, height' */ |
822 if (get_bits (&gb, 3) == 7) { | |
5519 | 823 skip_bits (&gb, 12); |
824 skip_bits (&gb, 12); | |
1234 | 825 } |
826 | |
1319 | 827 h->halfpel_flag = get_bits1 (&gb); |
828 h->thirdpel_flag = get_bits1 (&gb); | |
829 | |
830 /* unknown fields */ | |
5519 | 831 skip_bits1 (&gb); |
832 skip_bits1 (&gb); | |
833 skip_bits1 (&gb); | |
834 skip_bits1 (&gb); | |
1319 | 835 |
836 s->low_delay = get_bits1 (&gb); | |
837 | |
838 /* unknown field */ | |
5519 | 839 skip_bits1 (&gb); |
1319 | 840 |
841 while (get_bits1 (&gb)) { | |
5519 | 842 skip_bits (&gb, 8); |
1319 | 843 } |
844 | |
845 h->unknown_svq3_flag = get_bits1 (&gb); | |
846 avctx->has_b_frames = !s->low_delay; | |
8066
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
847 if (h->unknown_svq3_flag) { |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
848 #ifdef CONFIG_ZLIB |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
849 unsigned watermark_width = svq3_get_ue_golomb(&gb); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
850 unsigned watermark_height = svq3_get_ue_golomb(&gb); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
851 int u1 = svq3_get_ue_golomb(&gb); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
852 int u2 = get_bits(&gb, 8); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
853 int u3 = get_bits(&gb, 2); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
854 int u4 = svq3_get_ue_golomb(&gb); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
855 unsigned buf_len = watermark_width*watermark_height*4; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
856 int offset = (get_bits_count(&gb)+7)>>3; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
857 uint8_t *buf; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
858 |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
859 if ((uint64_t)watermark_width*4 > UINT_MAX/watermark_height) |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
860 return -1; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
861 |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
862 buf = av_malloc(buf_len); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
863 av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n", watermark_width, watermark_height); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
864 av_log(avctx, AV_LOG_DEBUG, "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", u1, u2, u3, u4, offset); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
865 if (uncompress(buf, (uLong*)&buf_len, extradata + 8 + offset, size - offset) != Z_OK) { |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
866 av_log(avctx, AV_LOG_ERROR, "could not uncompress watermark logo\n"); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
867 av_free(buf); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
868 return -1; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
869 } |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
870 h->svq3_watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
871 h->svq3_watermark_key = h->svq3_watermark_key << 16 | h->svq3_watermark_key; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
872 av_log(avctx, AV_LOG_DEBUG, "watermark key %#x\n", h->svq3_watermark_key); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
873 av_free(buf); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
874 #else |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
875 av_log(avctx, AV_LOG_ERROR, "this svq3 file contains watermark which need zlib support compiled in\n"); |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
876 return -1; |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
877 #endif |
94fa05bc0390
svq3 watermark decoding support, based on reverse engineering work by chrono
bcoudurier
parents:
8059
diff
changeset
|
878 } |
1234 | 879 } |
880 } | |
881 | |
1319 | 882 /* special case for last picture */ |
883 if (buf_size == 0) { | |
884 if (s->next_picture_ptr && !s->low_delay) { | |
885 *(AVFrame *) data = *(AVFrame *) &s->next_picture; | |
7276 | 886 s->next_picture_ptr= NULL; |
1319 | 887 *data_size = sizeof(AVFrame); |
1234 | 888 } |
1319 | 889 return 0; |
1234 | 890 } |
891 | |
1319 | 892 init_get_bits (&s->gb, buf, 8*buf_size); |
1234 | 893 |
6789
8107e891b226
Previous commit missed an initialization - this fixes FATE's test sample.
astrange
parents:
6787
diff
changeset
|
894 s->mb_x = s->mb_y = h->mb_xy = 0; |
1319 | 895 |
896 if (svq3_decode_slice_header (h)) | |
1234 | 897 return -1; |
898 | |
1319 | 899 s->pict_type = h->slice_type; |
900 s->picture_number = h->slice_num; | |
1234 | 901 |
1250 | 902 if(avctx->debug&FF_DEBUG_PICT_INFO){ |
7287 | 903 av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n", |
1264 | 904 av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag, |
7287 | 905 s->adaptive_quant, s->qscale, h->slice_num |
1250 | 906 ); |
907 } | |
1234 | 908 |
1319 | 909 /* for hurry_up==5 */ |
910 s->current_picture.pict_type = s->pict_type; | |
6481 | 911 s->current_picture.key_frame = (s->pict_type == FF_I_TYPE); |
1319 | 912 |
5127 | 913 /* Skip B-frames if we do not have reference frames. */ |
8194
f48a0ed93396
cosmetics: Put statements after 'if' on their own line.
diego
parents:
8080
diff
changeset
|
914 if (s->last_picture_ptr == NULL && s->pict_type == FF_B_TYPE) |
f48a0ed93396
cosmetics: Put statements after 'if' on their own line.
diego
parents:
8080
diff
changeset
|
915 return 0; |
5127 | 916 /* Skip B-frames if we are in a hurry. */ |
8194
f48a0ed93396
cosmetics: Put statements after 'if' on their own line.
diego
parents:
8080
diff
changeset
|
917 if (avctx->hurry_up && s->pict_type == FF_B_TYPE) |
f48a0ed93396
cosmetics: Put statements after 'if' on their own line.
diego
parents:
8080
diff
changeset
|
918 return 0; |
5127 | 919 /* Skip everything if we are in a hurry >= 5. */ |
8194
f48a0ed93396
cosmetics: Put statements after 'if' on their own line.
diego
parents:
8080
diff
changeset
|
920 if (avctx->hurry_up >= 5) |
f48a0ed93396
cosmetics: Put statements after 'if' on their own line.
diego
parents:
8080
diff
changeset
|
921 return 0; |
6481 | 922 if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) |
923 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) | |
2792 | 924 || avctx->skip_frame >= AVDISCARD_ALL) |
925 return 0; | |
1319 | 926 |
927 if (s->next_p_frame_damaged) { | |
6481 | 928 if (s->pict_type == FF_B_TYPE) |
1319 | 929 return 0; |
930 else | |
931 s->next_p_frame_damaged = 0; | |
932 } | |
1234 | 933 |
4395 | 934 if (frame_start (h) < 0) |
935 return -1; | |
1234 | 936 |
6481 | 937 if (s->pict_type == FF_B_TYPE) { |
1319 | 938 h->frame_num_offset = (h->slice_num - h->prev_frame_num); |
939 | |
940 if (h->frame_num_offset < 0) { | |
941 h->frame_num_offset += 256; | |
942 } | |
943 if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1330
diff
changeset
|
944 av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n"); |
1319 | 945 return -1; |
946 } | |
947 } else { | |
948 h->prev_frame_num = h->frame_num; | |
949 h->frame_num = h->slice_num; | |
950 h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num); | |
951 | |
952 if (h->prev_frame_num_offset < 0) { | |
953 h->prev_frame_num_offset += 256; | |
954 } | |
955 } | |
956 | |
957 for(m=0; m<2; m++){ | |
958 int i; | |
959 for(i=0; i<4; i++){ | |
960 int j; | |
961 for(j=-1; j<4; j++) | |
2979 | 962 h->ref_cache[m][scan8[0] + 8*i + j]= 1; |
5008 | 963 if(i<3) |
964 h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE; | |
1319 | 965 } |
1252 | 966 } |
2967 | 967 |
1234 | 968 for (s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) { |
969 for (s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { | |
6789
8107e891b226
Previous commit missed an initialization - this fixes FATE's test sample.
astrange
parents:
6787
diff
changeset
|
970 h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; |
1319 | 971 |
2614
5e24800ab329
various fixes related to the non alt_bitstream_reader
michael
parents:
2453
diff
changeset
|
972 if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits && |
2979 | 973 ((get_bits_count(&s->gb) & 7) == 0 || show_bits (&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) { |
1319 | 974 |
2979 | 975 skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb)); |
976 s->gb.size_in_bits = 8*buf_size; | |
1319 | 977 |
2979 | 978 if (svq3_decode_slice_header (h)) |
979 return -1; | |
1319 | 980 |
2979 | 981 /* TODO: support s->mb_skip_run */ |
1319 | 982 } |
983 | |
984 mb_type = svq3_get_ue_golomb (&s->gb); | |
1234 | 985 |
6481 | 986 if (s->pict_type == FF_I_TYPE) { |
2979 | 987 mb_type += 8; |
6481 | 988 } else if (s->pict_type == FF_B_TYPE && mb_type >= 4) { |
2979 | 989 mb_type += 4; |
1234 | 990 } |
1319 | 991 if (mb_type > 33 || svq3_decode_mb (h, mb_type)) { |
2979 | 992 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); |
993 return -1; | |
1234 | 994 } |
995 | |
996 if (mb_type != 0) { | |
2979 | 997 hl_decode_mb (h); |
1234 | 998 } |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
999 |
6481 | 1000 if (s->pict_type != FF_B_TYPE && !s->low_delay) { |
2979 | 1001 s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] = |
6481 | 1002 (s->pict_type == FF_P_TYPE && mb_type < 8) ? (mb_type - 1) : -1; |
1330
c05c381a9c47
- fix PLANE_PRED8x8 prediction (H/V are swapped, this is correct!)
tmmm
parents:
1321
diff
changeset
|
1003 } |
1234 | 1004 } |
1268 | 1005 |
1006 ff_draw_horiz_band(s, 16*s->mb_y, 16); | |
1234 | 1007 } |
1008 | |
1319 | 1009 MPV_frame_end(s); |
1010 | |
6481 | 1011 if (s->pict_type == FF_B_TYPE || s->low_delay) { |
1319 | 1012 *(AVFrame *) data = *(AVFrame *) &s->current_picture; |
1013 } else { | |
1014 *(AVFrame *) data = *(AVFrame *) &s->last_picture; | |
1015 } | |
1234 | 1016 |
1319 | 1017 avctx->frame_number = s->picture_number - 1; |
1018 | |
5127 | 1019 /* Do not output the last pic after seeking. */ |
1319 | 1020 if (s->last_picture_ptr || s->low_delay) { |
1021 *data_size = sizeof(AVFrame); | |
1022 } | |
1023 | |
1234 | 1024 return buf_size; |
1025 } | |
1026 | |
1027 | |
1028 AVCodec svq3_decoder = { | |
1029 "svq3", | |
1030 CODEC_TYPE_VIDEO, | |
1031 CODEC_ID_SVQ3, | |
1032 sizeof(H264Context), | |
1033 decode_init, | |
1034 NULL, | |
1035 decode_end, | |
1036 svq3_decode_frame, | |
2453 | 1037 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6789
diff
changeset
|
1038 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3"), |
1234 | 1039 }; |