libavcodec/svq3.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003 The FFmpeg Project
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 /*
00022  * How to use this decoder:
00023  * SVQ3 data is transported within Apple Quicktime files. Quicktime files
00024  * have stsd atoms to describe media trak properties. A stsd atom for a
00025  * video trak contains 1 or more ImageDescription atoms. These atoms begin
00026  * with the 4-byte length of the atom followed by the codec fourcc. Some
00027  * decoders need information in this atom to operate correctly. Such
00028  * is the case with SVQ3. In order to get the best use out of this decoder,
00029  * the calling app must make the SVQ3 ImageDescription atom available
00030  * via the AVCodecContext's extradata[_size] field:
00031  *
00032  * AVCodecContext.extradata = pointer to ImageDescription, first characters
00033  * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
00034  * AVCodecContext.extradata_size = size of ImageDescription atom memory
00035  * buffer (which will be the same as the ImageDescription atom size field
00036  * from the QT file, minus 4 bytes since the length is missing)
00037  *
00038  * You will know you have these parameters passed correctly when the decoder
00039  * correctly decodes this file:
00040  * http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
00041  */
00042 
00043 #if CONFIG_ZLIB
00044 #include <zlib.h>
00045 #endif
00046 
00047 #include "svq1.h"
00048 
00054 #define FULLPEL_MODE 1
00055 #define HALFPEL_MODE 2
00056 #define THIRDPEL_MODE 3
00057 #define PREDICT_MODE 4
00058 
00059 /* dual scan (from some older h264 draft)
00060  o-->o-->o o
00061  | /|
00062  o o o / o
00063  | / | |/ |
00064  o o o o
00065  /
00066  o-->o-->o-->o
00067 */
00068 static const uint8_t svq3_scan[16] = {
00069 0+0*4, 1+0*4, 2+0*4, 2+1*4,
00070 2+2*4, 3+0*4, 3+1*4, 3+2*4,
00071 0+1*4, 0+2*4, 1+1*4, 1+2*4,
00072 0+3*4, 1+3*4, 2+3*4, 3+3*4,
00073 };
00074 
00075 static const uint8_t svq3_pred_0[25][2] = {
00076 { 0, 0 },
00077 { 1, 0 }, { 0, 1 },
00078 { 0, 2 }, { 1, 1 }, { 2, 0 },
00079 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
00080 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
00081 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
00082 { 2, 4 }, { 3, 3 }, { 4, 2 },
00083 { 4, 3 }, { 3, 4 },
00084 { 4, 4 }
00085 };
00086 
00087 static const int8_t svq3_pred_1[6][6][5] = {
00088 { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 },
00089 { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } },
00090 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
00091 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
00092 { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
00093 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
00094 { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
00095 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
00096 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
00097 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
00098 { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
00099 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
00100 };
00101 
00102 static const struct { uint8_t run; uint8_t level; } svq3_dct_tables[2][16] = {
00103 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
00104 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
00105 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
00106 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
00107 };
00108 
00109 static const uint32_t svq3_dequant_coeff[32] = {
00110 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
00111 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
00112 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
00113 61694, 68745, 77615, 89113,100253,109366,126635,141533
00114 };
00115 
00116 
00117 static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp)
00118 {
00119 const int qmul = svq3_dequant_coeff[qp];
00120 #define stride 16
00121 int i;
00122 int temp[16];
00123 static const int x_offset[4] = {0, 1*stride, 4* stride, 5*stride};
00124 static const int y_offset[4] = {0, 2*stride, 8* stride, 10*stride};
00125 
00126 for (i = 0; i < 4; i++){
00127 const int offset = y_offset[i];
00128 const int z0 = 13*(block[offset+stride*0] + block[offset+stride*4]);
00129 const int z1 = 13*(block[offset+stride*0] - block[offset+stride*4]);
00130 const int z2 = 7* block[offset+stride*1] - 17*block[offset+stride*5];
00131 const int z3 = 17* block[offset+stride*1] + 7*block[offset+stride*5];
00132 
00133 temp[4*i+0] = z0+z3;
00134 temp[4*i+1] = z1+z2;
00135 temp[4*i+2] = z1-z2;
00136 temp[4*i+3] = z0-z3;
00137 }
00138 
00139 for (i = 0; i < 4; i++){
00140 const int offset = x_offset[i];
00141 const int z0 = 13*(temp[4*0+i] + temp[4*2+i]);
00142 const int z1 = 13*(temp[4*0+i] - temp[4*2+i]);
00143 const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i];
00144 const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i];
00145 
00146 block[stride*0 +offset] = ((z0 + z3)*qmul + 0x80000) >> 20;
00147 block[stride*2 +offset] = ((z1 + z2)*qmul + 0x80000) >> 20;
00148 block[stride*8 +offset] = ((z1 - z2)*qmul + 0x80000) >> 20;
00149 block[stride*10+offset] = ((z0 - z3)*qmul + 0x80000) >> 20;
00150 }
00151 }
00152 #undef stride
00153 
00154 static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp,
00155 int dc)
00156 {
00157 const int qmul = svq3_dequant_coeff[qp];
00158 int i;
00159 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
00160 
00161 if (dc) {
00162 dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
00163 block[0] = 0;
00164 }
00165 
00166 for (i = 0; i < 4; i++) {
00167 const int z0 = 13*(block[0 + 4*i] + block[2 + 4*i]);
00168 const int z1 = 13*(block[0 + 4*i] - block[2 + 4*i]);
00169 const int z2 = 7* block[1 + 4*i] - 17*block[3 + 4*i];
00170 const int z3 = 17* block[1 + 4*i] + 7*block[3 + 4*i];
00171 
00172 block[0 + 4*i] = z0 + z3;
00173 block[1 + 4*i] = z1 + z2;
00174 block[2 + 4*i] = z1 - z2;
00175 block[3 + 4*i] = z0 - z3;
00176 }
00177 
00178 for (i = 0; i < 4; i++) {
00179 const int z0 = 13*(block[i + 4*0] + block[i + 4*2]);
00180 const int z1 = 13*(block[i + 4*0] - block[i + 4*2]);
00181 const int z2 = 7* block[i + 4*1] - 17*block[i + 4*3];
00182 const int z3 = 17* block[i + 4*1] + 7*block[i + 4*3];
00183 const int rr = (dc + 0x80000);
00184 
00185 dst[i + stride*0] = cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ];
00186 dst[i + stride*1] = cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ];
00187 dst[i + stride*2] = cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ];
00188 dst[i + stride*3] = cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ];
00189 }
00190 }
00191 
00192 static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,
00193 int index, const int type)
00194 {
00195 static const uint8_t *const scan_patterns[4] =
00196 { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };
00197 
00198 int run, level, sign, vlc, limit;
00199 const int intra = (3 * type) >> 2;
00200 const uint8_t *const scan = scan_patterns[type];
00201 
00202 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
00203 for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) {
00204 
00205 if (vlc < 0)
00206 return -1;
00207 
00208 sign = (vlc & 0x1) - 1;
00209 vlc = (vlc + 1) >> 1;
00210 
00211 if (type == 3) {
00212 if (vlc < 3) {
00213 run = 0;
00214 level = vlc;
00215 } else if (vlc < 4) {
00216 run = 1;
00217 level = 1;
00218 } else {
00219 run = (vlc & 0x3);
00220 level = ((vlc + 9) >> 2) - run;
00221 }
00222 } else {
00223 if (vlc < 16U) {
00224 run = svq3_dct_tables[intra][vlc].run;
00225 level = svq3_dct_tables[intra][vlc].level;
00226 } else if (intra) {
00227 run = (vlc & 0x7);
00228 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
00229 } else {
00230 run = (vlc & 0xF);
00231 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
00232 }
00233 }
00234 
00235 if ((index += run) >= limit)
00236 return -1;
00237 
00238 block[scan[index]] = (level ^ sign) - sign;
00239 }
00240 
00241 if (type != 2) {
00242 break;
00243 }
00244 }
00245 
00246 return 0;
00247 }
00248 
00249 static inline void svq3_mc_dir_part(MpegEncContext *s,
00250 int x, int y, int width, int height,
00251 int mx, int my, int dxy,
00252 int thirdpel, int dir, int avg)
00253 {
00254 const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture;
00255 uint8_t *src, *dest;
00256 int i, emu = 0;
00257 int blocksize = 2 - (width>>3); //16->0, 8->1, 4->2
00258 
00259 mx += x;
00260 my += y;
00261 
00262 if (mx < 0 || mx >= (s->h_edge_pos - width - 1) ||
00263 my < 0 || my >= (s->v_edge_pos - height - 1)) {
00264 
00265 if ((s->flags & CODEC_FLAG_EMU_EDGE)) {
00266 emu = 1;
00267 }
00268 
00269 mx = av_clip (mx, -16, (s->h_edge_pos - width + 15));
00270 my = av_clip (my, -16, (s->v_edge_pos - height + 15));
00271 }
00272 
00273 /* form component predictions */
00274 dest = s->current_picture.data[0] + x + y*s->linesize;
00275 src = pic->data[0] + mx + my*s->linesize;
00276 
00277 if (emu) {
00278 ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1),
00279 mx, my, s->h_edge_pos, s->v_edge_pos);
00280 src = s->edge_emu_buffer;
00281 }
00282 if (thirdpel)
00283 (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize, width, height);
00284 else
00285 (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize, height);
00286 
00287 if (!(s->flags & CODEC_FLAG_GRAY)) {
00288 mx = (mx + (mx < (int) x)) >> 1;
00289 my = (my + (my < (int) y)) >> 1;
00290 width = (width >> 1);
00291 height = (height >> 1);
00292 blocksize++;
00293 
00294 for (i = 1; i < 3; i++) {
00295 dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize;
00296 src = pic->data[i] + mx + my*s->uvlinesize;
00297 
00298 if (emu) {
00299 ff_emulated_edge_mc(s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1),
00300 mx, my, (s->h_edge_pos >> 1), (s->v_edge_pos >> 1));
00301 src = s->edge_emu_buffer;
00302 }
00303 if (thirdpel)
00304 (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->uvlinesize, width, height);
00305 else
00306 (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->uvlinesize, height);
00307 }
00308 }
00309 }
00310 
00311 static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir,
00312 int avg)
00313 {
00314 int i, j, k, mx, my, dx, dy, x, y;
00315 MpegEncContext *const s = (MpegEncContext *) h;
00316 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
00317 const int part_height = 16 >> ((unsigned) (size + 1) / 3);
00318 const int extra_width = (mode == PREDICT_MODE) ? -16*6 : 0;
00319 const int h_edge_pos = 6*(s->h_edge_pos - part_width ) - extra_width;
00320 const int v_edge_pos = 6*(s->v_edge_pos - part_height) - extra_width;
00321 
00322 for (i = 0; i < 16; i += part_height) {
00323 for (j = 0; j < 16; j += part_width) {
00324 const int b_xy = (4*s->mb_x + (j >> 2)) + (4*s->mb_y + (i >> 2))*h->b_stride;
00325 int dxy;
00326 x = 16*s->mb_x + j;
00327 y = 16*s->mb_y + i;
00328 k = ((j >> 2) & 1) + ((i >> 1) & 2) + ((j >> 1) & 4) + (i & 8);
00329 
00330 if (mode != PREDICT_MODE) {
00331 pred_motion(h, k, (part_width >> 2), dir, 1, &mx, &my);
00332 } else {
00333 mx = s->next_picture.motion_val[0][b_xy][0]<<1;
00334 my = s->next_picture.motion_val[0][b_xy][1]<<1;
00335 
00336 if (dir == 0) {
00337 mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1) >> 1;
00338 my = ((my * h->frame_num_offset) / h->prev_frame_num_offset + 1) >> 1;
00339 } else {
00340 mx = ((mx * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1) >> 1;
00341 my = ((my * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1) >> 1;
00342 }
00343 }
00344 
00345 /* clip motion vector prediction to frame border */
00346 mx = av_clip(mx, extra_width - 6*x, h_edge_pos - 6*x);
00347 my = av_clip(my, extra_width - 6*y, v_edge_pos - 6*y);
00348 
00349 /* get (optional) motion vector differential */
00350 if (mode == PREDICT_MODE) {
00351 dx = dy = 0;
00352 } else {
00353 dy = svq3_get_se_golomb(&s->gb);
00354 dx = svq3_get_se_golomb(&s->gb);
00355 
00356 if (dx == INVALID_VLC || dy == INVALID_VLC) {
00357 av_log(h->s.avctx, AV_LOG_ERROR, "invalid MV vlc\n");
00358 return -1;
00359 }
00360 }
00361 
00362 /* compute motion vector */
00363 if (mode == THIRDPEL_MODE) {
00364 int fx, fy;
00365 mx = ((mx + 1)>>1) + dx;
00366 my = ((my + 1)>>1) + dy;
00367 fx = ((unsigned)(mx + 0x3000))/3 - 0x1000;
00368 fy = ((unsigned)(my + 0x3000))/3 - 0x1000;
00369 dxy = (mx - 3*fx) + 4*(my - 3*fy);
00370 
00371 svq3_mc_dir_part(s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
00372 mx += mx;
00373 my += my;
00374 } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
00375 mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
00376 my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
00377 dxy = (mx&1) + 2*(my&1);
00378 
00379 svq3_mc_dir_part(s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
00380 mx *= 3;
00381 my *= 3;
00382 } else {
00383 mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
00384 my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
00385 
00386 svq3_mc_dir_part(s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
00387 mx *= 6;
00388 my *= 6;
00389 }
00390 
00391 /* update mv_cache */
00392 if (mode != PREDICT_MODE) {
00393 int32_t mv = pack16to32(mx,my);
00394 
00395 if (part_height == 8 && i < 8) {
00396 *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv;
00397 
00398 if (part_width == 8 && j < 8) {
00399 *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv;
00400 }
00401 }
00402 if (part_width == 8 && j < 8) {
00403 *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv;
00404 }
00405 if (part_width == 4 || part_height == 4) {
00406 *(int32_t *) h->mv_cache[dir][scan8[k]] = mv;
00407 }
00408 }
00409 
00410 /* write back motion vectors */
00411 fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4);
00412 }
00413 }
00414 
00415 return 0;
00416 }
00417 
00418 static int svq3_decode_mb(H264Context *h, unsigned int mb_type)
00419 {
00420 int i, j, k, m, dir, mode;
00421 int cbp = 0;
00422 uint32_t vlc;
00423 int8_t *top, *left;
00424 MpegEncContext *const s = (MpegEncContext *) h;
00425 const int mb_xy = h->mb_xy;
00426 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
00427 
00428 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
00429 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
00430 h->topright_samples_available = 0xFFFF;
00431 
00432 if (mb_type == 0) { /* SKIP */
00433 if (s->pict_type == FF_P_TYPE || s->next_picture.mb_type[mb_xy] == -1) {
00434 svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
00435 
00436 if (s->pict_type == FF_B_TYPE) {
00437 svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
00438 }
00439 
00440 mb_type = MB_TYPE_SKIP;
00441 } else {
00442 mb_type = FFMIN(s->next_picture.mb_type[mb_xy], 6);
00443 if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0)
00444 return -1;
00445 if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0)
00446 return -1;
00447 
00448 mb_type = MB_TYPE_16x16;
00449 }
00450 } else if (mb_type < 8) { /* INTER */
00451 if (h->thirdpel_flag && h->halfpel_flag == !get_bits1 (&s->gb)) {
00452 mode = THIRDPEL_MODE;
00453 } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits1 (&s->gb)) {
00454 mode = HALFPEL_MODE;
00455 } else {
00456 mode = FULLPEL_MODE;
00457 }
00458 
00459 /* fill caches */
00460 /* note ref_cache should contain here:
00461  ????????
00462  ???11111
00463  N??11111
00464  N??11111
00465  N??11111
00466  */
00467 
00468 for (m = 0; m < 2; m++) {
00469 if (s->mb_x > 0 && h->intra4x4_pred_mode[mb_xy - 1][0] != -1) {
00470 for (i = 0; i < 4; i++) {
00471 *(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];
00472 }
00473 } else {
00474 for (i = 0; i < 4; i++) {
00475 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0;
00476 }
00477 }
00478 if (s->mb_y > 0) {
00479 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));
00480 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);
00481 
00482 if (s->mb_x < (s->mb_width - 1)) {
00483 *(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];
00484 h->ref_cache[m][scan8[0] + 4 - 1*8] =
00485 (h->intra4x4_pred_mode[mb_xy - s->mb_stride + 1][0] == -1 ||
00486 h->intra4x4_pred_mode[mb_xy - s->mb_stride ][4] == -1) ? PART_NOT_AVAILABLE : 1;
00487 }else
00488 h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE;
00489 if (s->mb_x > 0) {
00490 *(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];
00491 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;
00492 }else
00493 h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
00494 }else
00495 memset(&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8);
00496 
00497 if (s->pict_type != FF_B_TYPE)
00498 break;
00499 }
00500 
00501 /* decode motion vector(s) and form prediction(s) */
00502 if (s->pict_type == FF_P_TYPE) {
00503 if (svq3_mc_dir(h, (mb_type - 1), mode, 0, 0) < 0)
00504 return -1;
00505 } else { /* FF_B_TYPE */
00506 if (mb_type != 2) {
00507 if (svq3_mc_dir(h, 0, mode, 0, 0) < 0)
00508 return -1;
00509 } else {
00510 for (i = 0; i < 4; i++) {
00511 memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00512 }
00513 }
00514 if (mb_type != 1) {
00515 if (svq3_mc_dir(h, 0, mode, 1, (mb_type == 3)) < 0)
00516 return -1;
00517 } else {
00518 for (i = 0; i < 4; i++) {
00519 memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00520 }
00521 }
00522 }
00523 
00524 mb_type = MB_TYPE_16x16;
00525 } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
00526 memset(h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t));
00527 
00528 if (mb_type == 8) {
00529 if (s->mb_x > 0) {
00530 for (i = 0; i < 4; i++) {
00531 h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[mb_xy - 1][i];
00532 }
00533 if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) {
00534 h->left_samples_available = 0x5F5F;
00535 }
00536 }
00537 if (s->mb_y > 0) {
00538 h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][4];
00539 h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][5];
00540 h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][6];
00541 h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][3];
00542 
00543 if (h->intra4x4_pred_mode_cache[4+8*0] == -1) {
00544 h->top_samples_available = 0x33FF;
00545 }
00546 }
00547 
00548 /* decode prediction codes for luma blocks */
00549 for (i = 0; i < 16; i+=2) {
00550 vlc = svq3_get_ue_golomb(&s->gb);
00551 
00552 if (vlc >= 25U){
00553 av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
00554 return -1;
00555 }
00556 
00557 left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
00558 top = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
00559 
00560 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
00561 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
00562 
00563 if (left[1] == -1 || left[2] == -1){
00564 av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n");
00565 return -1;
00566 }
00567 }
00568 } else { /* mb_type == 33, DC_128_PRED block type */
00569 for (i = 0; i < 4; i++) {
00570 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4);
00571 }
00572 }
00573 
00574 write_back_intra_pred_mode(h);
00575 
00576 if (mb_type == 8) {
00577 check_intra4x4_pred_mode(h);
00578 
00579 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
00580 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
00581 } else {
00582 for (i = 0; i < 4; i++) {
00583 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4);
00584 }
00585 
00586 h->top_samples_available = 0x33FF;
00587 h->left_samples_available = 0x5F5F;
00588 }
00589 
00590 mb_type = MB_TYPE_INTRA4x4;
00591 } else { /* INTRA16x16 */
00592 dir = i_mb_type_info[mb_type - 8].pred_mode;
00593 dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
00594 
00595 if ((h->intra16x16_pred_mode = check_intra_pred_mode(h, dir)) == -1){
00596 av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
00597 return -1;
00598 }
00599 
00600 cbp = i_mb_type_info[mb_type - 8].cbp;
00601 mb_type = MB_TYPE_INTRA16x16;
00602 }
00603 
00604 if (!IS_INTER(mb_type) && s->pict_type != FF_I_TYPE) {
00605 for (i = 0; i < 4; i++) {
00606 memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00607 }
00608 if (s->pict_type == FF_B_TYPE) {
00609 for (i = 0; i < 4; i++) {
00610 memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00611 }
00612 }
00613 }
00614 if (!IS_INTRA4x4(mb_type)) {
00615 memset(h->intra4x4_pred_mode[mb_xy], DC_PRED, 8);
00616 }
00617 if (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE) {
00618 memset(h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t));
00619 s->dsp.clear_blocks(h->mb);
00620 }
00621 
00622 if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE)) {
00623 if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48U){
00624 av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
00625 return -1;
00626 }
00627 
00628 cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc];
00629 }
00630 if (IS_INTRA16x16(mb_type) || (s->pict_type != FF_I_TYPE && s->adaptive_quant && cbp)) {
00631 s->qscale += svq3_get_se_golomb(&s->gb);
00632 
00633 if (s->qscale > 31U){
00634 av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
00635 return -1;
00636 }
00637 }
00638 if (IS_INTRA16x16(mb_type)) {
00639 if (svq3_decode_block(&s->gb, h->mb, 0, 0)){
00640 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n");
00641 return -1;
00642 }
00643 }
00644 
00645 if (cbp) {
00646 const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
00647 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
00648 
00649 for (i = 0; i < 4; i++) {
00650 if ((cbp & (1 << i))) {
00651 for (j = 0; j < 4; j++) {
00652 k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
00653 h->non_zero_count_cache[ scan8[k] ] = 1;
00654 
00655 if (svq3_decode_block(&s->gb, &h->mb[16*k], index, type)){
00656 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n");
00657 return -1;
00658 }
00659 }
00660 }
00661 }
00662 
00663 if ((cbp & 0x30)) {
00664 for (i = 0; i < 2; ++i) {
00665 if (svq3_decode_block(&s->gb, &h->mb[16*(16 + 4*i)], 0, 3)){
00666 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n");
00667 return -1;
00668 }
00669 }
00670 
00671 if ((cbp & 0x20)) {
00672 for (i = 0; i < 8; i++) {
00673 h->non_zero_count_cache[ scan8[16+i] ] = 1;
00674 
00675 if (svq3_decode_block(&s->gb, &h->mb[16*(16 + i)], 1, 1)){
00676 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n");
00677 return -1;
00678 }
00679 }
00680 }
00681 }
00682 }
00683 
00684 h->cbp= cbp;
00685 s->current_picture.mb_type[mb_xy] = mb_type;
00686 
00687 if (IS_INTRA(mb_type)) {
00688 h->chroma_pred_mode = check_intra_pred_mode(h, DC_PRED8x8);
00689 }
00690 
00691 return 0;
00692 }
00693 
00694 static int svq3_decode_slice_header(H264Context *h)
00695 {
00696 MpegEncContext *const s = (MpegEncContext *) h;
00697 const int mb_xy = h->mb_xy;
00698 int i, header;
00699 
00700 header = get_bits(&s->gb, 8);
00701 
00702 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
00703 /* TODO: what? */
00704 av_log(h->s.avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
00705 return -1;
00706 } else {
00707 int length = (header >> 5) & 3;
00708 
00709 h->next_slice_index = get_bits_count(&s->gb) + 8*show_bits(&s->gb, 8*length) + 8*length;
00710 
00711 if (h->next_slice_index > s->gb.size_in_bits) {
00712 av_log(h->s.avctx, AV_LOG_ERROR, "slice after bitstream end\n");
00713 return -1;
00714 }
00715 
00716 s->gb.size_in_bits = h->next_slice_index - 8*(length - 1);
00717 skip_bits(&s->gb, 8);
00718 
00719 if (h->svq3_watermark_key) {
00720 uint32_t header = AV_RL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1]);
00721 AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1], header ^ h->svq3_watermark_key);
00722 }
00723 if (length > 0) {
00724 memcpy((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3],
00725 &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1));
00726 }
00727 skip_bits_long(&s->gb, 0);
00728 }
00729 
00730 if ((i = svq3_get_ue_golomb(&s->gb)) >= 3U){
00731 av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
00732 return -1;
00733 }
00734 
00735 h->slice_type = golomb_to_pict_type[i];
00736 
00737 if ((header & 0x9F) == 2) {
00738 i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1));
00739 s->mb_skip_run = get_bits(&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width));
00740 } else {
00741 skip_bits1(&s->gb);
00742 s->mb_skip_run = 0;
00743 }
00744 
00745 h->slice_num = get_bits(&s->gb, 8);
00746 s->qscale = get_bits(&s->gb, 5);
00747 s->adaptive_quant = get_bits1(&s->gb);
00748 
00749 /* unknown fields */
00750 skip_bits1(&s->gb);
00751 
00752 if (h->unknown_svq3_flag) {
00753 skip_bits1(&s->gb);
00754 }
00755 
00756 skip_bits1(&s->gb);
00757 skip_bits(&s->gb, 2);
00758 
00759 while (get_bits1(&s->gb)) {
00760 skip_bits(&s->gb, 8);
00761 }
00762 
00763 /* reset intra predictors and invalidate motion vector references */
00764 if (s->mb_x > 0) {
00765 memset(h->intra4x4_pred_mode[mb_xy - 1], -1, 4*sizeof(int8_t));
00766 memset(h->intra4x4_pred_mode[mb_xy - s->mb_x], -1, 8*sizeof(int8_t)*s->mb_x);
00767 }
00768 if (s->mb_y > 0) {
00769 memset(h->intra4x4_pred_mode[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x));
00770 
00771 if (s->mb_x > 0) {
00772 h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] = -1;
00773 }
00774 }
00775 
00776 return 0;
00777 }
00778 
00779 static av_cold int svq3_decode_init(AVCodecContext *avctx)
00780 {
00781 MpegEncContext *const s = avctx->priv_data;
00782 H264Context *const h = avctx->priv_data;
00783 int m;
00784 unsigned char *extradata;
00785 unsigned int size;
00786 
00787 if (decode_init(avctx) < 0)
00788 return -1;
00789 
00790 s->flags = avctx->flags;
00791 s->flags2 = avctx->flags2;
00792 s->unrestricted_mv = 1;
00793 h->is_complex=1;
00794 
00795 if (!s->context_initialized) {
00796 s->width = avctx->width;
00797 s->height = avctx->height;
00798 h->halfpel_flag = 1;
00799 h->thirdpel_flag = 1;
00800 h->unknown_svq3_flag = 0;
00801 h->chroma_qp[0] = h->chroma_qp[1] = 4;
00802 
00803 if (MPV_common_init(s) < 0)
00804 return -1;
00805 
00806 h->b_stride = 4*s->mb_width;
00807 
00808 alloc_tables(h);
00809 
00810 /* prowl for the "SEQH" marker in the extradata */
00811 extradata = (unsigned char *)avctx->extradata;
00812 for (m = 0; m < avctx->extradata_size; m++) {
00813 if (!memcmp(extradata, "SEQH", 4))
00814 break;
00815 extradata++;
00816 }
00817 
00818 /* if a match was found, parse the extra data */
00819 if (extradata && !memcmp(extradata, "SEQH", 4)) {
00820 
00821 GetBitContext gb;
00822 
00823 size = AV_RB32(&extradata[4]);
00824 init_get_bits(&gb, extradata + 8, size*8);
00825 
00826 /* 'frame size code' and optional 'width, height' */
00827 if (get_bits(&gb, 3) == 7) {
00828 skip_bits(&gb, 12);
00829 skip_bits(&gb, 12);
00830 }
00831 
00832 h->halfpel_flag = get_bits1(&gb);
00833 h->thirdpel_flag = get_bits1(&gb);
00834 
00835 /* unknown fields */
00836 skip_bits1(&gb);
00837 skip_bits1(&gb);
00838 skip_bits1(&gb);
00839 skip_bits1(&gb);
00840 
00841 s->low_delay = get_bits1(&gb);
00842 
00843 /* unknown field */
00844 skip_bits1(&gb);
00845 
00846 while (get_bits1(&gb)) {
00847 skip_bits(&gb, 8);
00848 }
00849 
00850 h->unknown_svq3_flag = get_bits1(&gb);
00851 avctx->has_b_frames = !s->low_delay;
00852 if (h->unknown_svq3_flag) {
00853 #if CONFIG_ZLIB
00854 unsigned watermark_width = svq3_get_ue_golomb(&gb);
00855 unsigned watermark_height = svq3_get_ue_golomb(&gb);
00856 int u1 = svq3_get_ue_golomb(&gb);
00857 int u2 = get_bits(&gb, 8);
00858 int u3 = get_bits(&gb, 2);
00859 int u4 = svq3_get_ue_golomb(&gb);
00860 unsigned buf_len = watermark_width*watermark_height*4;
00861 int offset = (get_bits_count(&gb)+7)>>3;
00862 uint8_t *buf;
00863 
00864 if ((uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
00865 return -1;
00866 
00867 buf = av_malloc(buf_len);
00868 av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n", watermark_width, watermark_height);
00869 av_log(avctx, AV_LOG_DEBUG, "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", u1, u2, u3, u4, offset);
00870 if (uncompress(buf, (uLong*)&buf_len, extradata + 8 + offset, size - offset) != Z_OK) {
00871 av_log(avctx, AV_LOG_ERROR, "could not uncompress watermark logo\n");
00872 av_free(buf);
00873 return -1;
00874 }
00875 h->svq3_watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
00876 h->svq3_watermark_key = h->svq3_watermark_key << 16 | h->svq3_watermark_key;
00877 av_log(avctx, AV_LOG_DEBUG, "watermark key %#x\n", h->svq3_watermark_key);
00878 av_free(buf);
00879 #else
00880 av_log(avctx, AV_LOG_ERROR, "this svq3 file contains watermark which need zlib support compiled in\n");
00881 return -1;
00882 #endif
00883 }
00884 }
00885 }
00886 
00887 return 0;
00888 }
00889 
00890 static int svq3_decode_frame(AVCodecContext *avctx,
00891 void *data, int *data_size,
00892 const uint8_t *buf, int buf_size)
00893 {
00894 MpegEncContext *const s = avctx->priv_data;
00895 H264Context *const h = avctx->priv_data;
00896 int m, mb_type;
00897 
00898 /* special case for last picture */
00899 if (buf_size == 0) {
00900 if (s->next_picture_ptr && !s->low_delay) {
00901 *(AVFrame *) data = *(AVFrame *) &s->next_picture;
00902 s->next_picture_ptr = NULL;
00903 *data_size = sizeof(AVFrame);
00904 }
00905 return 0;
00906 }
00907 
00908 init_get_bits (&s->gb, buf, 8*buf_size);
00909 
00910 s->mb_x = s->mb_y = h->mb_xy = 0;
00911 
00912 if (svq3_decode_slice_header(h))
00913 return -1;
00914 
00915 s->pict_type = h->slice_type;
00916 s->picture_number = h->slice_num;
00917 
00918 if (avctx->debug&FF_DEBUG_PICT_INFO){
00919 av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
00920 av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag,
00921 s->adaptive_quant, s->qscale, h->slice_num);
00922 }
00923 
00924 /* for hurry_up == 5 */
00925 s->current_picture.pict_type = s->pict_type;
00926 s->current_picture.key_frame = (s->pict_type == FF_I_TYPE);
00927 
00928 /* Skip B-frames if we do not have reference frames. */
00929 if (s->last_picture_ptr == NULL && s->pict_type == FF_B_TYPE)
00930 return 0;
00931 /* Skip B-frames if we are in a hurry. */
00932 if (avctx->hurry_up && s->pict_type == FF_B_TYPE)
00933 return 0;
00934 /* Skip everything if we are in a hurry >= 5. */
00935 if (avctx->hurry_up >= 5)
00936 return 0;
00937 if ( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE)
00938 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE)
00939 || avctx->skip_frame >= AVDISCARD_ALL)
00940 return 0;
00941 
00942 if (s->next_p_frame_damaged) {
00943 if (s->pict_type == FF_B_TYPE)
00944 return 0;
00945 else
00946 s->next_p_frame_damaged = 0;
00947 }
00948 
00949 if (frame_start(h) < 0)
00950 return -1;
00951 
00952 if (s->pict_type == FF_B_TYPE) {
00953 h->frame_num_offset = (h->slice_num - h->prev_frame_num);
00954 
00955 if (h->frame_num_offset < 0) {
00956 h->frame_num_offset += 256;
00957 }
00958 if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
00959 av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
00960 return -1;
00961 }
00962 } else {
00963 h->prev_frame_num = h->frame_num;
00964 h->frame_num = h->slice_num;
00965 h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
00966 
00967 if (h->prev_frame_num_offset < 0) {
00968 h->prev_frame_num_offset += 256;
00969 }
00970 }
00971 
00972 for (m = 0; m < 2; m++){
00973 int i;
00974 for (i = 0; i < 4; i++){
00975 int j;
00976 for (j = -1; j < 4; j++)
00977 h->ref_cache[m][scan8[0] + 8*i + j]= 1;
00978 if (i < 3)
00979 h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
00980 }
00981 }
00982 
00983 for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
00984 for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
00985 h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
00986 
00987 if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
00988 ((get_bits_count(&s->gb) & 7) == 0 || show_bits(&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) {
00989 
00990 skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb));
00991 s->gb.size_in_bits = 8*buf_size;
00992 
00993 if (svq3_decode_slice_header(h))
00994 return -1;
00995 
00996 /* TODO: support s->mb_skip_run */
00997 }
00998 
00999 mb_type = svq3_get_ue_golomb(&s->gb);
01000 
01001 if (s->pict_type == FF_I_TYPE) {
01002 mb_type += 8;
01003 } else if (s->pict_type == FF_B_TYPE && mb_type >= 4) {
01004 mb_type += 4;
01005 }
01006 if (mb_type > 33 || svq3_decode_mb(h, mb_type)) {
01007 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
01008 return -1;
01009 }
01010 
01011 if (mb_type != 0) {
01012 hl_decode_mb (h);
01013 }
01014 
01015 if (s->pict_type != FF_B_TYPE && !s->low_delay) {
01016 s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
01017 (s->pict_type == FF_P_TYPE && mb_type < 8) ? (mb_type - 1) : -1;
01018 }
01019 }
01020 
01021 ff_draw_horiz_band(s, 16*s->mb_y, 16);
01022 }
01023 
01024 MPV_frame_end(s);
01025 
01026 if (s->pict_type == FF_B_TYPE || s->low_delay) {
01027 *(AVFrame *) data = *(AVFrame *) &s->current_picture;
01028 } else {
01029 *(AVFrame *) data = *(AVFrame *) &s->last_picture;
01030 }
01031 
01032 avctx->frame_number = s->picture_number - 1;
01033 
01034 /* Do not output the last pic after seeking. */
01035 if (s->last_picture_ptr || s->low_delay) {
01036 *data_size = sizeof(AVFrame);
01037 }
01038 
01039 return buf_size;
01040 }
01041 
01042 
01043 AVCodec svq3_decoder = {
01044 "svq3",
01045 CODEC_TYPE_VIDEO,
01046 CODEC_ID_SVQ3,
01047 sizeof(H264Context),
01048 svq3_decode_init,
01049 NULL,
01050 decode_end,
01051 svq3_decode_frame,
01052 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
01053 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3"),
01054 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_NONE},
01055 };

Generated on Fri Oct 26 02:35:39 2012 for FFmpeg by doxygen 1.5.8

AltStyle によって変換されたページ (->オリジナル) /