00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "internal.h"
00043 #include "dsputil.h"
00044 #include "avcodec.h"
00045 #include "mpegvideo.h"
00046 #include "h264.h"
00047
00048 #include "h264data.h"
00049
00050 #include "h264_mvpred.h"
00051 #include "golomb.h"
00052 #include "rectangle.h"
00053 #include "vdpau_internal.h"
00054
00055 #if CONFIG_ZLIB
00056 #include <zlib.h>
00057 #endif
00058
00059 #include "svq1.h"
00060
00066 typedef struct {
00067 H264Context h;
00068 int halfpel_flag;
00069 int thirdpel_flag;
00070 int unknown_flag;
00071 int next_slice_index;
00072 uint32_t watermark_key;
00073 uint8_t *buf;
00074 int buf_size;
00075 } SVQ3Context;
00076
00077 #define FULLPEL_MODE 1
00078 #define HALFPEL_MODE 2
00079 #define THIRDPEL_MODE 3
00080 #define PREDICT_MODE 4
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 static const uint8_t svq3_scan[16] = {
00092 0+0*4, 1+0*4, 2+0*4, 2+1*4,
00093 2+2*4, 3+0*4, 3+1*4, 3+2*4,
00094 0+1*4, 0+2*4, 1+1*4, 1+2*4,
00095 0+3*4, 1+3*4, 2+3*4, 3+3*4,
00096 };
00097
00098 static const uint8_t svq3_pred_0[25][2] = {
00099 { 0, 0 },
00100 { 1, 0 }, { 0, 1 },
00101 { 0, 2 }, { 1, 1 }, { 2, 0 },
00102 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
00103 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
00104 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
00105 { 2, 4 }, { 3, 3 }, { 4, 2 },
00106 { 4, 3 }, { 3, 4 },
00107 { 4, 4 }
00108 };
00109
00110 static const int8_t svq3_pred_1[6][6][5] = {
00111 { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 },
00112 { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } },
00113 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
00114 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
00115 { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
00116 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
00117 { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
00118 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
00119 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
00120 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
00121 { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
00122 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
00123 };
00124
00125 static const struct { uint8_t run; uint8_t level; } svq3_dct_tables[2][16] = {
00126 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
00127 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
00128 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
00129 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
00130 };
00131
00132 static const uint32_t svq3_dequant_coeff[32] = {
00133 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
00134 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
00135 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
00136 61694, 68745, 77615, 89113,100253,109366,126635,141533
00137 };
00138
00139 void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp){
00140 const int qmul = svq3_dequant_coeff[qp];
00141 #define stride 16
00142 int i;
00143 int temp[16];
00144 static const uint8_t x_offset[4]={0, 1*stride, 4*stride, 5*stride};
00145
00146 for(i=0; i<4; i++){
00147 const int z0 = 13*(input[4*i+0] + input[4*i+2]);
00148 const int z1 = 13*(input[4*i+0] - input[4*i+2]);
00149 const int z2 = 7* input[4*i+1] - 17*input[4*i+3];
00150 const int z3 = 17* input[4*i+1] + 7*input[4*i+3];
00151
00152 temp[4*i+0] = z0+z3;
00153 temp[4*i+1] = z1+z2;
00154 temp[4*i+2] = z1-z2;
00155 temp[4*i+3] = z0-z3;
00156 }
00157
00158 for(i=0; i<4; i++){
00159 const int offset= x_offset[i];
00160 const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
00161 const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
00162 const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
00163 const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
00164
00165 output[stride* 0+offset] = ((z0 + z3)*qmul + 0x80000) >> 20;
00166 output[stride* 2+offset] = ((z1 + z2)*qmul + 0x80000) >> 20;
00167 output[stride* 8+offset] = ((z1 - z2)*qmul + 0x80000) >> 20;
00168 output[stride*10+offset] = ((z0 - z3)*qmul + 0x80000) >> 20;
00169 }
00170 }
00171 #undef stride
00172
00173 void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp,
00174 int dc)
00175 {
00176 const int qmul = svq3_dequant_coeff[qp];
00177 int i;
00178 uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
00179
00180 if (dc) {
00181 dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
00182 block[0] = 0;
00183 }
00184
00185 for (i = 0; i < 4; i++) {
00186 const int z0 = 13*(block[0 + 4*i] + block[2 + 4*i]);
00187 const int z1 = 13*(block[0 + 4*i] - block[2 + 4*i]);
00188 const int z2 = 7* block[1 + 4*i] - 17*block[3 + 4*i];
00189 const int z3 = 17* block[1 + 4*i] + 7*block[3 + 4*i];
00190
00191 block[0 + 4*i] = z0 + z3;
00192 block[1 + 4*i] = z1 + z2;
00193 block[2 + 4*i] = z1 - z2;
00194 block[3 + 4*i] = z0 - z3;
00195 }
00196
00197 for (i = 0; i < 4; i++) {
00198 const int z0 = 13*(block[i + 4*0] + block[i + 4*2]);
00199 const int z1 = 13*(block[i + 4*0] - block[i + 4*2]);
00200 const int z2 = 7* block[i + 4*1] - 17*block[i + 4*3];
00201 const int z3 = 17* block[i + 4*1] + 7*block[i + 4*3];
00202 const int rr = (dc + 0x80000);
00203
00204 dst[i + stride*0] = cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ];
00205 dst[i + stride*1] = cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ];
00206 dst[i + stride*2] = cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ];
00207 dst[i + stride*3] = cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ];
00208 }
00209 }
00210
00211 static inline int svq3_decode_block(GetBitContext *gb, DCTELEM *block,
00212 int index, const int type)
00213 {
00214 static const uint8_t *const scan_patterns[4] =
00215 { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };
00216
00217 int run, level, sign, vlc, limit;
00218 const int intra = (3 * type) >> 2;
00219 const uint8_t *const scan = scan_patterns[type];
00220
00221 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
00222 for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) {
00223
00224 if (vlc < 0)
00225 return -1;
00226
00227 sign = (vlc & 0x1) - 1;
00228 vlc = (vlc + 1) >> 1;
00229
00230 if (type == 3) {
00231 if (vlc < 3) {
00232 run = 0;
00233 level = vlc;
00234 } else if (vlc < 4) {
00235 run = 1;
00236 level = 1;
00237 } else {
00238 run = (vlc & 0x3);
00239 level = ((vlc + 9) >> 2) - run;
00240 }
00241 } else {
00242 if (vlc < 16U) {
00243 run = svq3_dct_tables[intra][vlc].run;
00244 level = svq3_dct_tables[intra][vlc].level;
00245 } else if (intra) {
00246 run = (vlc & 0x7);
00247 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
00248 } else {
00249 run = (vlc & 0xF);
00250 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
00251 }
00252 }
00253
00254 if ((index += run) >= limit)
00255 return -1;
00256
00257 block[scan[index]] = (level ^ sign) - sign;
00258 }
00259
00260 if (type != 2) {
00261 break;
00262 }
00263 }
00264
00265 return 0;
00266 }
00267
00268 static inline void svq3_mc_dir_part(MpegEncContext *s,
00269 int x, int y, int width, int height,
00270 int mx, int my, int dxy,
00271 int thirdpel, int dir, int avg)
00272 {
00273 const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture;
00274 uint8_t *src, *dest;
00275 int i, emu = 0;
00276 int blocksize = 2 - (width>>3);
00277
00278 mx += x;
00279 my += y;
00280
00281 if (mx < 0 || mx >= (s->h_edge_pos - width - 1) ||
00282 my < 0 || my >= (s->v_edge_pos - height - 1)) {
00283
00284 if ((s->flags & CODEC_FLAG_EMU_EDGE)) {
00285 emu = 1;
00286 }
00287
00288 mx = av_clip (mx, -16, (s->h_edge_pos - width + 15));
00289 my = av_clip (my, -16, (s->v_edge_pos - height + 15));
00290 }
00291
00292
00293 dest = s->current_picture.f.data[0] + x + y*s->linesize;
00294 src = pic->f.data[0] + mx + my*s->linesize;
00295
00296 if (emu) {
00297 s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1),
00298 mx, my, s->h_edge_pos, s->v_edge_pos);
00299 src = s->edge_emu_buffer;
00300 }
00301 if (thirdpel)
00302 (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize, width, height);
00303 else
00304 (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize, height);
00305
00306 if (!(s->flags & CODEC_FLAG_GRAY)) {
00307 mx = (mx + (mx < (int) x)) >> 1;
00308 my = (my + (my < (int) y)) >> 1;
00309 width = (width >> 1);
00310 height = (height >> 1);
00311 blocksize++;
00312
00313 for (i = 1; i < 3; i++) {
00314 dest = s->current_picture.f.data[i] + (x >> 1) + (y >> 1) * s->uvlinesize;
00315 src = pic->f.data[i] + mx + my * s->uvlinesize;
00316
00317 if (emu) {
00318 s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1),
00319 mx, my, (s->h_edge_pos >> 1), (s->v_edge_pos >> 1));
00320 src = s->edge_emu_buffer;
00321 }
00322 if (thirdpel)
00323 (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->uvlinesize, width, height);
00324 else
00325 (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->uvlinesize, height);
00326 }
00327 }
00328 }
00329
00330 static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir,
00331 int avg)
00332 {
00333 int i, j, k, mx, my, dx, dy, x, y;
00334 MpegEncContext *const s = (MpegEncContext *) h;
00335 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
00336 const int part_height = 16 >> ((unsigned) (size + 1) / 3);
00337 const int extra_width = (mode == PREDICT_MODE) ? -16*6 : 0;
00338 const int h_edge_pos = 6*(s->h_edge_pos - part_width ) - extra_width;
00339 const int v_edge_pos = 6*(s->v_edge_pos - part_height) - extra_width;
00340
00341 for (i = 0; i < 16; i += part_height) {
00342 for (j = 0; j < 16; j += part_width) {
00343 const int b_xy = (4*s->mb_x + (j >> 2)) + (4*s->mb_y + (i >> 2))*h->b_stride;
00344 int dxy;
00345 x = 16*s->mb_x + j;
00346 y = 16*s->mb_y + i;
00347 k = ((j >> 2) & 1) + ((i >> 1) & 2) + ((j >> 1) & 4) + (i & 8);
00348
00349 if (mode != PREDICT_MODE) {
00350 pred_motion(h, k, (part_width >> 2), dir, 1, &mx, &my);
00351 } else {
00352 mx = s->next_picture.f.motion_val[0][b_xy][0] << 1;
00353 my = s->next_picture.f.motion_val[0][b_xy][1] << 1;
00354
00355 if (dir == 0) {
00356 mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1) >> 1;
00357 my = ((my * h->frame_num_offset) / h->prev_frame_num_offset + 1) >> 1;
00358 } else {
00359 mx = ((mx * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1) >> 1;
00360 my = ((my * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1) >> 1;
00361 }
00362 }
00363
00364
00365 mx = av_clip(mx, extra_width - 6*x, h_edge_pos - 6*x);
00366 my = av_clip(my, extra_width - 6*y, v_edge_pos - 6*y);
00367
00368
00369 if (mode == PREDICT_MODE) {
00370 dx = dy = 0;
00371 } else {
00372 dy = svq3_get_se_golomb(&s->gb);
00373 dx = svq3_get_se_golomb(&s->gb);
00374
00375 if (dx == INVALID_VLC || dy == INVALID_VLC) {
00376 av_log(h->s.avctx, AV_LOG_ERROR, "invalid MV vlc\n");
00377 return -1;
00378 }
00379 }
00380
00381
00382 if (mode == THIRDPEL_MODE) {
00383 int fx, fy;
00384 mx = ((mx + 1)>>1) + dx;
00385 my = ((my + 1)>>1) + dy;
00386 fx = ((unsigned)(mx + 0x3000))/3 - 0x1000;
00387 fy = ((unsigned)(my + 0x3000))/3 - 0x1000;
00388 dxy = (mx - 3*fx) + 4*(my - 3*fy);
00389
00390 svq3_mc_dir_part(s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
00391 mx += mx;
00392 my += my;
00393 } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
00394 mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
00395 my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
00396 dxy = (mx&1) + 2*(my&1);
00397
00398 svq3_mc_dir_part(s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
00399 mx *= 3;
00400 my *= 3;
00401 } else {
00402 mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
00403 my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
00404
00405 svq3_mc_dir_part(s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
00406 mx *= 6;
00407 my *= 6;
00408 }
00409
00410
00411 if (mode != PREDICT_MODE) {
00412 int32_t mv = pack16to32(mx,my);
00413
00414 if (part_height == 8 && i < 8) {
00415 *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv;
00416
00417 if (part_width == 8 && j < 8) {
00418 *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv;
00419 }
00420 }
00421 if (part_width == 8 && j < 8) {
00422 *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv;
00423 }
00424 if (part_width == 4 || part_height == 4) {
00425 *(int32_t *) h->mv_cache[dir][scan8[k]] = mv;
00426 }
00427 }
00428
00429
00430 fill_rectangle(s->current_picture.f.motion_val[dir][b_xy],
00431 part_width >> 2, part_height >> 2, h->b_stride,
00432 pack16to32(mx, my), 4);
00433 }
00434 }
00435
00436 return 0;
00437 }
00438
00439 static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
00440 {
00441 H264Context *h = &svq3->h;
00442 int i, j, k, m, dir, mode;
00443 int cbp = 0;
00444 uint32_t vlc;
00445 int8_t *top, *left;
00446 MpegEncContext *const s = (MpegEncContext *) h;
00447 const int mb_xy = h->mb_xy;
00448 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
00449
00450 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
00451 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
00452 h->topright_samples_available = 0xFFFF;
00453
00454 if (mb_type == 0) {
00455 if (s->pict_type == AV_PICTURE_TYPE_P || s->next_picture.f.mb_type[mb_xy] == -1) {
00456 svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
00457
00458 if (s->pict_type == AV_PICTURE_TYPE_B) {
00459 svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
00460 }
00461
00462 mb_type = MB_TYPE_SKIP;
00463 } else {
00464 mb_type = FFMIN(s->next_picture.f.mb_type[mb_xy], 6);
00465 if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0)
00466 return -1;
00467 if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0)
00468 return -1;
00469
00470 mb_type = MB_TYPE_16x16;
00471 }
00472 } else if (mb_type < 8) {
00473 if (svq3->thirdpel_flag && svq3->halfpel_flag == !get_bits1 (&s->gb)) {
00474 mode = THIRDPEL_MODE;
00475 } else if (svq3->halfpel_flag && svq3->thirdpel_flag == !get_bits1 (&s->gb)) {
00476 mode = HALFPEL_MODE;
00477 } else {
00478 mode = FULLPEL_MODE;
00479 }
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 for (m = 0; m < 2; m++) {
00491 if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) {
00492 for (i = 0; i < 4; i++) {
00493 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - 1 + i*h->b_stride];
00494 }
00495 } else {
00496 for (i = 0; i < 4; i++) {
00497 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0;
00498 }
00499 }
00500 if (s->mb_y > 0) {
00501 memcpy(h->mv_cache[m][scan8[0] - 1*8], s->current_picture.f.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t));
00502 memset(&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
00503
00504 if (s->mb_x < (s->mb_width - 1)) {
00505 *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4];
00506 h->ref_cache[m][scan8[0] + 4 - 1*8] =
00507 (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1]+6] == -1 ||
00508 h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1;
00509 }else
00510 h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE;
00511 if (s->mb_x > 0) {
00512 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1];
00513 h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] == -1) ? PART_NOT_AVAILABLE : 1;
00514 }else
00515 h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
00516 }else
00517 memset(&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8);
00518
00519 if (s->pict_type != AV_PICTURE_TYPE_B)
00520 break;
00521 }
00522
00523
00524 if (s->pict_type == AV_PICTURE_TYPE_P) {
00525 if (svq3_mc_dir(h, (mb_type - 1), mode, 0, 0) < 0)
00526 return -1;
00527 } else {
00528 if (mb_type != 2) {
00529 if (svq3_mc_dir(h, 0, mode, 0, 0) < 0)
00530 return -1;
00531 } else {
00532 for (i = 0; i < 4; i++) {
00533 memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00534 }
00535 }
00536 if (mb_type != 1) {
00537 if (svq3_mc_dir(h, 0, mode, 1, (mb_type == 3)) < 0)
00538 return -1;
00539 } else {
00540 for (i = 0; i < 4; i++) {
00541 memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00542 }
00543 }
00544 }
00545
00546 mb_type = MB_TYPE_16x16;
00547 } else if (mb_type == 8 || mb_type == 33) {
00548 memset(h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t));
00549
00550 if (mb_type == 8) {
00551 if (s->mb_x > 0) {
00552 for (i = 0; i < 4; i++) {
00553 h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6-i];
00554 }
00555 if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) {
00556 h->left_samples_available = 0x5F5F;
00557 }
00558 }
00559 if (s->mb_y > 0) {
00560 h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+0];
00561 h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+1];
00562 h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+2];
00563 h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+3];
00564
00565 if (h->intra4x4_pred_mode_cache[4+8*0] == -1) {
00566 h->top_samples_available = 0x33FF;
00567 }
00568 }
00569
00570
00571 for (i = 0; i < 16; i+=2) {
00572 vlc = svq3_get_ue_golomb(&s->gb);
00573
00574 if (vlc >= 25U){
00575 av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
00576 return -1;
00577 }
00578
00579 left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
00580 top = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
00581
00582 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
00583 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
00584
00585 if (left[1] == -1 || left[2] == -1){
00586 av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n");
00587 return -1;
00588 }
00589 }
00590 } else {
00591 for (i = 0; i < 4; i++) {
00592 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4);
00593 }
00594 }
00595
00596 write_back_intra_pred_mode(h);
00597
00598 if (mb_type == 8) {
00599 ff_h264_check_intra4x4_pred_mode(h);
00600
00601 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
00602 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
00603 } else {
00604 for (i = 0; i < 4; i++) {
00605 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4);
00606 }
00607
00608 h->top_samples_available = 0x33FF;
00609 h->left_samples_available = 0x5F5F;
00610 }
00611
00612 mb_type = MB_TYPE_INTRA4x4;
00613 } else {
00614 dir = i_mb_type_info[mb_type - 8].pred_mode;
00615 dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
00616
00617 if ((h->intra16x16_pred_mode = ff_h264_check_intra16x16_pred_mode(h, dir)) == -1){
00618 av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
00619 return -1;
00620 }
00621
00622 cbp = i_mb_type_info[mb_type - 8].cbp;
00623 mb_type = MB_TYPE_INTRA16x16;
00624 }
00625
00626 if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
00627 for (i = 0; i < 4; i++) {
00628 memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00629 }
00630 if (s->pict_type == AV_PICTURE_TYPE_B) {
00631 for (i = 0; i < 4; i++) {
00632 memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00633 }
00634 }
00635 }
00636 if (!IS_INTRA4x4(mb_type)) {
00637 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy], DC_PRED, 8);
00638 }
00639 if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
00640 memset(h->non_zero_count_cache + 8, 0, 14*8*sizeof(uint8_t));
00641 s->dsp.clear_blocks(h->mb+ 0);
00642 s->dsp.clear_blocks(h->mb+384);
00643 }
00644
00645 if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
00646 if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48U){
00647 av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
00648 return -1;
00649 }
00650
00651 cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc];
00652 }
00653 if (IS_INTRA16x16(mb_type) || (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
00654 s->qscale += svq3_get_se_golomb(&s->gb);
00655
00656 if (s->qscale > 31U){
00657 av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
00658 return -1;
00659 }
00660 }
00661 if (IS_INTRA16x16(mb_type)) {
00662 AV_ZERO128(h->mb_luma_dc[0]+0);
00663 AV_ZERO128(h->mb_luma_dc[0]+8);
00664 if (svq3_decode_block(&s->gb, h->mb_luma_dc, 0, 1)){
00665 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n");
00666 return -1;
00667 }
00668 }
00669
00670 if (cbp) {
00671 const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
00672 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
00673
00674 for (i = 0; i < 4; i++) {
00675 if ((cbp & (1 << i))) {
00676 for (j = 0; j < 4; j++) {
00677 k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
00678 h->non_zero_count_cache[ scan8[k] ] = 1;
00679
00680 if (svq3_decode_block(&s->gb, &h->mb[16*k], index, type)){
00681 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n");
00682 return -1;
00683 }
00684 }
00685 }
00686 }
00687
00688 if ((cbp & 0x30)) {
00689 for (i = 1; i < 3; ++i) {
00690 if (svq3_decode_block(&s->gb, &h->mb[16*16*i], 0, 3)){
00691 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n");
00692 return -1;
00693 }
00694 }
00695
00696 if ((cbp & 0x20)) {
00697 for (i = 1; i < 3; i++) {
00698 for (j = 0; j < 4; j++) {
00699 k = 16*i + j;
00700 h->non_zero_count_cache[ scan8[k] ] = 1;
00701
00702 if (svq3_decode_block(&s->gb, &h->mb[16*k], 1, 1)){
00703 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n");
00704 return -1;
00705 }
00706 }
00707 }
00708 }
00709 }
00710 }
00711
00712 h->cbp= cbp;
00713 s->current_picture.f.mb_type[mb_xy] = mb_type;
00714
00715 if (IS_INTRA(mb_type)) {
00716 h->chroma_pred_mode = ff_h264_check_intra_chroma_pred_mode(h, DC_PRED8x8);
00717 }
00718
00719 return 0;
00720 }
00721
00722 static int svq3_decode_slice_header(AVCodecContext *avctx)
00723 {
00724 SVQ3Context *svq3 = avctx->priv_data;
00725 H264Context *h = &svq3->h;
00726 MpegEncContext *s = &h->s;
00727 const int mb_xy = h->mb_xy;
00728 int i, header;
00729
00730 header = get_bits(&s->gb, 8);
00731
00732 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
00733
00734 av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
00735 return -1;
00736 } else {
00737 int length = (header >> 5) & 3;
00738
00739 svq3->next_slice_index = get_bits_count(&s->gb) + 8*show_bits(&s->gb, 8*length) + 8*length;
00740
00741 if (svq3->next_slice_index > s->gb.size_in_bits) {
00742 av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
00743 return -1;
00744 }
00745
00746 s->gb.size_in_bits = svq3->next_slice_index - 8*(length - 1);
00747 skip_bits(&s->gb, 8);
00748
00749 if (svq3->watermark_key) {
00750 uint32_t header = AV_RL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1]);
00751 AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1], header ^ svq3->watermark_key);
00752 }
00753 if (length > 0) {
00754 memcpy((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3],
00755 &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1));
00756 }
00757 skip_bits_long(&s->gb, 0);
00758 }
00759
00760 if ((i = svq3_get_ue_golomb(&s->gb)) >= 3U){
00761 av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
00762 return -1;
00763 }
00764
00765 h->slice_type = golomb_to_pict_type[i];
00766
00767 if ((header & 0x9F) == 2) {
00768 i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1));
00769 s->mb_skip_run = get_bits(&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width));
00770 } else {
00771 skip_bits1(&s->gb);
00772 s->mb_skip_run = 0;
00773 }
00774
00775 h->slice_num = get_bits(&s->gb, 8);
00776 s->qscale = get_bits(&s->gb, 5);
00777 s->adaptive_quant = get_bits1(&s->gb);
00778
00779
00780 skip_bits1(&s->gb);
00781
00782 if (svq3->unknown_flag) {
00783 skip_bits1(&s->gb);
00784 }
00785
00786 skip_bits1(&s->gb);
00787 skip_bits(&s->gb, 2);
00788
00789 while (get_bits1(&s->gb)) {
00790 skip_bits(&s->gb, 8);
00791 }
00792
00793
00794 if (s->mb_x > 0) {
00795 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - 1 ]+3, -1, 4*sizeof(int8_t));
00796 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - s->mb_x] , -1, 8*sizeof(int8_t)*s->mb_x);
00797 }
00798 if (s->mb_y > 0) {
00799 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x));
00800
00801 if (s->mb_x > 0) {
00802 h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] = -1;
00803 }
00804 }
00805
00806 return 0;
00807 }
00808
00809 static av_cold int svq3_decode_init(AVCodecContext *avctx)
00810 {
00811 SVQ3Context *svq3 = avctx->priv_data;
00812 H264Context *h = &svq3->h;
00813 MpegEncContext *s = &h->s;
00814 int m;
00815 unsigned char *extradata;
00816 unsigned int size;
00817
00818 if (ff_h264_decode_init(avctx) < 0)
00819 return -1;
00820
00821 s->flags = avctx->flags;
00822 s->flags2 = avctx->flags2;
00823 s->unrestricted_mv = 1;
00824 h->is_complex=1;
00825 avctx->pix_fmt = avctx->codec->pix_fmts[0];
00826
00827 if (!s->context_initialized) {
00828 h->chroma_qp[0] = h->chroma_qp[1] = 4;
00829
00830 svq3->halfpel_flag = 1;
00831 svq3->thirdpel_flag = 1;
00832 svq3->unknown_flag = 0;
00833
00834
00835
00836 extradata = (unsigned char *)avctx->extradata;
00837 for (m = 0; m < avctx->extradata_size; m++) {
00838 if (!memcmp(extradata, "SEQH", 4))
00839 break;
00840 extradata++;
00841 }
00842
00843
00844 if (extradata && !memcmp(extradata, "SEQH", 4)) {
00845
00846 GetBitContext gb;
00847 int frame_size_code;
00848
00849 size = AV_RB32(&extradata[4]);
00850 init_get_bits(&gb, extradata + 8, size*8);
00851
00852
00853 frame_size_code = get_bits(&gb, 3);
00854 switch (frame_size_code) {
00855 case 0: avctx->width = 160; avctx->height = 120; break;
00856 case 1: avctx->width = 128; avctx->height = 96; break;
00857 case 2: avctx->width = 176; avctx->height = 144; break;
00858 case 3: avctx->width = 352; avctx->height = 288; break;
00859 case 4: avctx->width = 704; avctx->height = 576; break;
00860 case 5: avctx->width = 240; avctx->height = 180; break;
00861 case 6: avctx->width = 320; avctx->height = 240; break;
00862 case 7:
00863 avctx->width = get_bits(&gb, 12);
00864 avctx->height = get_bits(&gb, 12);
00865 break;
00866 }
00867
00868 svq3->halfpel_flag = get_bits1(&gb);
00869 svq3->thirdpel_flag = get_bits1(&gb);
00870
00871
00872 skip_bits1(&gb);
00873 skip_bits1(&gb);
00874 skip_bits1(&gb);
00875 skip_bits1(&gb);
00876
00877 s->low_delay = get_bits1(&gb);
00878
00879
00880 skip_bits1(&gb);
00881
00882 while (get_bits1(&gb)) {
00883 skip_bits(&gb, 8);
00884 }
00885
00886 svq3->unknown_flag = get_bits1(&gb);
00887 avctx->has_b_frames = !s->low_delay;
00888 if (svq3->unknown_flag) {
00889 #if CONFIG_ZLIB
00890 unsigned watermark_width = svq3_get_ue_golomb(&gb);
00891 unsigned watermark_height = svq3_get_ue_golomb(&gb);
00892 int u1 = svq3_get_ue_golomb(&gb);
00893 int u2 = get_bits(&gb, 8);
00894 int u3 = get_bits(&gb, 2);
00895 int u4 = svq3_get_ue_golomb(&gb);
00896 unsigned long buf_len = watermark_width*watermark_height*4;
00897 int offset = (get_bits_count(&gb)+7)>>3;
00898 uint8_t *buf;
00899
00900 if ((uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
00901 return -1;
00902
00903 buf = av_malloc(buf_len);
00904 av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n", watermark_width, watermark_height);
00905 av_log(avctx, AV_LOG_DEBUG, "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", u1, u2, u3, u4, offset);
00906 if (uncompress(buf, &buf_len, extradata + 8 + offset, size - offset) != Z_OK) {
00907 av_log(avctx, AV_LOG_ERROR, "could not uncompress watermark logo\n");
00908 av_free(buf);
00909 return -1;
00910 }
00911 svq3->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
00912 svq3->watermark_key = svq3->watermark_key << 16 | svq3->watermark_key;
00913 av_log(avctx, AV_LOG_DEBUG, "watermark key %#x\n", svq3->watermark_key);
00914 av_free(buf);
00915 #else
00916 av_log(avctx, AV_LOG_ERROR, "this svq3 file contains watermark which need zlib support compiled in\n");
00917 return -1;
00918 #endif
00919 }
00920 }
00921
00922 s->width = avctx->width;
00923 s->height = avctx->height;
00924
00925 if (MPV_common_init(s) < 0)
00926 return -1;
00927
00928 h->b_stride = 4*s->mb_width;
00929
00930 if (ff_h264_alloc_tables(h) < 0) {
00931 av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n");
00932 return AVERROR(ENOMEM);
00933 }
00934 }
00935
00936 return 0;
00937 }
00938
00939 static int svq3_decode_frame(AVCodecContext *avctx,
00940 void *data, int *data_size,
00941 AVPacket *avpkt)
00942 {
00943 SVQ3Context *svq3 = avctx->priv_data;
00944 H264Context *h = &svq3->h;
00945 MpegEncContext *s = &h->s;
00946 int buf_size = avpkt->size;
00947 int m, mb_type, left;
00948 uint8_t *buf;
00949
00950
00951 if (buf_size == 0) {
00952 if (s->next_picture_ptr && !s->low_delay) {
00953 *(AVFrame *) data = *(AVFrame *) &s->next_picture;
00954 s->next_picture_ptr = NULL;
00955 *data_size = sizeof(AVFrame);
00956 }
00957 return 0;
00958 }
00959
00960 s->mb_x = s->mb_y = h->mb_xy = 0;
00961
00962 if (svq3->watermark_key) {
00963 av_fast_malloc(&svq3->buf, &svq3->buf_size,
00964 buf_size+FF_INPUT_BUFFER_PADDING_SIZE);
00965 if (!svq3->buf)
00966 return AVERROR(ENOMEM);
00967 memcpy(svq3->buf, avpkt->data, buf_size);
00968 buf = svq3->buf;
00969 } else {
00970 buf = avpkt->data;
00971 }
00972
00973 init_get_bits(&s->gb, buf, 8*buf_size);
00974
00975 if (svq3_decode_slice_header(avctx))
00976 return -1;
00977
00978 s->pict_type = h->slice_type;
00979 s->picture_number = h->slice_num;
00980
00981 if (avctx->debug&FF_DEBUG_PICT_INFO){
00982 av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
00983 av_get_picture_type_char(s->pict_type), svq3->halfpel_flag, svq3->thirdpel_flag,
00984 s->adaptive_quant, s->qscale, h->slice_num);
00985 }
00986
00987
00988 s->current_picture.f.pict_type = s->pict_type;
00989 s->current_picture.f.key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
00990
00991
00992 if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B)
00993 return 0;
00994 if ( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B)
00995 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I)
00996 || avctx->skip_frame >= AVDISCARD_ALL)
00997 return 0;
00998
00999 if (s->next_p_frame_damaged) {
01000 if (s->pict_type == AV_PICTURE_TYPE_B)
01001 return 0;
01002 else
01003 s->next_p_frame_damaged = 0;
01004 }
01005
01006 if (ff_h264_frame_start(h) < 0)
01007 return -1;
01008
01009 if (s->pict_type == AV_PICTURE_TYPE_B) {
01010 h->frame_num_offset = (h->slice_num - h->prev_frame_num);
01011
01012 if (h->frame_num_offset < 0) {
01013 h->frame_num_offset += 256;
01014 }
01015 if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
01016 av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
01017 return -1;
01018 }
01019 } else {
01020 h->prev_frame_num = h->frame_num;
01021 h->frame_num = h->slice_num;
01022 h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
01023
01024 if (h->prev_frame_num_offset < 0) {
01025 h->prev_frame_num_offset += 256;
01026 }
01027 }
01028
01029 for (m = 0; m < 2; m++){
01030 int i;
01031 for (i = 0; i < 4; i++){
01032 int j;
01033 for (j = -1; j < 4; j++)
01034 h->ref_cache[m][scan8[0] + 8*i + j]= 1;
01035 if (i < 3)
01036 h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
01037 }
01038 }
01039
01040 for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
01041 for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
01042 h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
01043
01044 if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
01045 ((get_bits_count(&s->gb) & 7) == 0 || show_bits(&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) {
01046
01047 skip_bits(&s->gb, svq3->next_slice_index - get_bits_count(&s->gb));
01048 s->gb.size_in_bits = 8*buf_size;
01049
01050 if (svq3_decode_slice_header(avctx))
01051 return -1;
01052
01053
01054 }
01055
01056 mb_type = svq3_get_ue_golomb(&s->gb);
01057
01058 if (s->pict_type == AV_PICTURE_TYPE_I) {
01059 mb_type += 8;
01060 } else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4) {
01061 mb_type += 4;
01062 }
01063 if ((unsigned)mb_type > 33 || svq3_decode_mb(svq3, mb_type)) {
01064 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
01065 return -1;
01066 }
01067
01068 if (mb_type != 0) {
01069 ff_h264_hl_decode_mb (h);
01070 }
01071
01072 if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay) {
01073 s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
01074 (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
01075 }
01076 }
01077
01078 ff_draw_horiz_band(s, 16*s->mb_y, 16);
01079 }
01080
01081 left = buf_size*8 - get_bits_count(&s->gb);
01082
01083 if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
01084 av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, s->mb_y, s->mb_x, left);
01085
01086 }
01087
01088 if (left < 0) {
01089 av_log(avctx, AV_LOG_ERROR, "frame num %d left %d\n", avctx->frame_number, left);
01090 return -1;
01091 }
01092
01093 MPV_frame_end(s);
01094
01095 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
01096 *(AVFrame *) data = *(AVFrame *) &s->current_picture;
01097 } else {
01098 *(AVFrame *) data = *(AVFrame *) &s->last_picture;
01099 }
01100
01101
01102 if (s->last_picture_ptr || s->low_delay) {
01103 *data_size = sizeof(AVFrame);
01104 }
01105
01106 return buf_size;
01107 }
01108
01109 static int svq3_decode_end(AVCodecContext *avctx)
01110 {
01111 SVQ3Context *svq3 = avctx->priv_data;
01112 H264Context *h = &svq3->h;
01113 MpegEncContext *s = &h->s;
01114
01115 ff_h264_free_context(h);
01116
01117 MPV_common_end(s);
01118
01119 av_freep(&svq3->buf);
01120 svq3->buf_size = 0;
01121
01122 return 0;
01123 }
01124
01125 AVCodec ff_svq3_decoder = {
01126 .name = "svq3",
01127 .type = AVMEDIA_TYPE_VIDEO,
01128 .id = CODEC_ID_SVQ3,
01129 .priv_data_size = sizeof(SVQ3Context),
01130 .init = svq3_decode_init,
01131 .close = svq3_decode_end,
01132 .decode = svq3_decode_frame,
01133 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
01134 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
01135 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_NONE},
01136 };