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.data[0] + x + y*s->linesize;
00294 src = pic->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.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize;
00315 src = pic->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.motion_val[0][b_xy][0]<<1;
00353 my = s->next_picture.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.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4);
00431 }
00432 }
00433
00434 return 0;
00435 }
00436
00437 static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
00438 {
00439 H264Context *h = &svq3->h;
00440 int i, j, k, m, dir, mode;
00441 int cbp = 0;
00442 uint32_t vlc;
00443 int8_t *top, *left;
00444 MpegEncContext *const s = (MpegEncContext *) h;
00445 const int mb_xy = h->mb_xy;
00446 const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
00447
00448 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
00449 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
00450 h->topright_samples_available = 0xFFFF;
00451
00452 if (mb_type == 0) {
00453 if (s->pict_type == AV_PICTURE_TYPE_P || s->next_picture.mb_type[mb_xy] == -1) {
00454 svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
00455
00456 if (s->pict_type == AV_PICTURE_TYPE_B) {
00457 svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
00458 }
00459
00460 mb_type = MB_TYPE_SKIP;
00461 } else {
00462 mb_type = FFMIN(s->next_picture.mb_type[mb_xy], 6);
00463 if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0)
00464 return -1;
00465 if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0)
00466 return -1;
00467
00468 mb_type = MB_TYPE_16x16;
00469 }
00470 } else if (mb_type < 8) {
00471 if (svq3->thirdpel_flag && svq3->halfpel_flag == !get_bits1 (&s->gb)) {
00472 mode = THIRDPEL_MODE;
00473 } else if (svq3->halfpel_flag && svq3->thirdpel_flag == !get_bits1 (&s->gb)) {
00474 mode = HALFPEL_MODE;
00475 } else {
00476 mode = FULLPEL_MODE;
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 for (m = 0; m < 2; m++) {
00489 if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) {
00490 for (i = 0; i < 4; i++) {
00491 *(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];
00492 }
00493 } else {
00494 for (i = 0; i < 4; i++) {
00495 *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0;
00496 }
00497 }
00498 if (s->mb_y > 0) {
00499 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));
00500 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);
00501
00502 if (s->mb_x < (s->mb_width - 1)) {
00503 *(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];
00504 h->ref_cache[m][scan8[0] + 4 - 1*8] =
00505 (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1]+6] == -1 ||
00506 h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1;
00507 }else
00508 h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE;
00509 if (s->mb_x > 0) {
00510 *(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];
00511 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;
00512 }else
00513 h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
00514 }else
00515 memset(&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8);
00516
00517 if (s->pict_type != AV_PICTURE_TYPE_B)
00518 break;
00519 }
00520
00521
00522 if (s->pict_type == AV_PICTURE_TYPE_P) {
00523 if (svq3_mc_dir(h, (mb_type - 1), mode, 0, 0) < 0)
00524 return -1;
00525 } else {
00526 if (mb_type != 2) {
00527 if (svq3_mc_dir(h, 0, mode, 0, 0) < 0)
00528 return -1;
00529 } else {
00530 for (i = 0; i < 4; i++) {
00531 memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00532 }
00533 }
00534 if (mb_type != 1) {
00535 if (svq3_mc_dir(h, 0, mode, 1, (mb_type == 3)) < 0)
00536 return -1;
00537 } else {
00538 for (i = 0; i < 4; i++) {
00539 memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00540 }
00541 }
00542 }
00543
00544 mb_type = MB_TYPE_16x16;
00545 } else if (mb_type == 8 || mb_type == 33) {
00546 memset(h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t));
00547
00548 if (mb_type == 8) {
00549 if (s->mb_x > 0) {
00550 for (i = 0; i < 4; i++) {
00551 h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6-i];
00552 }
00553 if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) {
00554 h->left_samples_available = 0x5F5F;
00555 }
00556 }
00557 if (s->mb_y > 0) {
00558 h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+0];
00559 h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+1];
00560 h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+2];
00561 h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+3];
00562
00563 if (h->intra4x4_pred_mode_cache[4+8*0] == -1) {
00564 h->top_samples_available = 0x33FF;
00565 }
00566 }
00567
00568
00569 for (i = 0; i < 16; i+=2) {
00570 vlc = svq3_get_ue_golomb(&s->gb);
00571
00572 if (vlc >= 25U){
00573 av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc);
00574 return -1;
00575 }
00576
00577 left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
00578 top = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
00579
00580 left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
00581 left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
00582
00583 if (left[1] == -1 || left[2] == -1){
00584 av_log(h->s.avctx, AV_LOG_ERROR, "weird prediction\n");
00585 return -1;
00586 }
00587 }
00588 } else {
00589 for (i = 0; i < 4; i++) {
00590 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4);
00591 }
00592 }
00593
00594 ff_h264_write_back_intra_pred_mode(h);
00595
00596 if (mb_type == 8) {
00597 ff_h264_check_intra4x4_pred_mode(h);
00598
00599 h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
00600 h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
00601 } else {
00602 for (i = 0; i < 4; i++) {
00603 memset(&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4);
00604 }
00605
00606 h->top_samples_available = 0x33FF;
00607 h->left_samples_available = 0x5F5F;
00608 }
00609
00610 mb_type = MB_TYPE_INTRA4x4;
00611 } else {
00612 dir = i_mb_type_info[mb_type - 8].pred_mode;
00613 dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
00614
00615 if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir, 0)) == -1){
00616 av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n");
00617 return -1;
00618 }
00619
00620 cbp = i_mb_type_info[mb_type - 8].cbp;
00621 mb_type = MB_TYPE_INTRA16x16;
00622 }
00623
00624 if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
00625 for (i = 0; i < 4; i++) {
00626 memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00627 }
00628 if (s->pict_type == AV_PICTURE_TYPE_B) {
00629 for (i = 0; i < 4; i++) {
00630 memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
00631 }
00632 }
00633 }
00634 if (!IS_INTRA4x4(mb_type)) {
00635 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy], DC_PRED, 8);
00636 }
00637 if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
00638 memset(h->non_zero_count_cache + 8, 0, 14*8*sizeof(uint8_t));
00639 s->dsp.clear_blocks(h->mb+ 0);
00640 s->dsp.clear_blocks(h->mb+384);
00641 }
00642
00643 if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
00644 if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48U){
00645 av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc);
00646 return -1;
00647 }
00648
00649 cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc];
00650 }
00651 if (IS_INTRA16x16(mb_type) || (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
00652 s->qscale += svq3_get_se_golomb(&s->gb);
00653
00654 if (s->qscale > 31U){
00655 av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
00656 return -1;
00657 }
00658 }
00659 if (IS_INTRA16x16(mb_type)) {
00660 AV_ZERO128(h->mb_luma_dc[0]+0);
00661 AV_ZERO128(h->mb_luma_dc[0]+8);
00662 if (svq3_decode_block(&s->gb, h->mb_luma_dc, 0, 1)){
00663 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n");
00664 return -1;
00665 }
00666 }
00667
00668 if (cbp) {
00669 const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
00670 const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
00671
00672 for (i = 0; i < 4; i++) {
00673 if ((cbp & (1 << i))) {
00674 for (j = 0; j < 4; j++) {
00675 k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
00676 h->non_zero_count_cache[ scan8[k] ] = 1;
00677
00678 if (svq3_decode_block(&s->gb, &h->mb[16*k], index, type)){
00679 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding block\n");
00680 return -1;
00681 }
00682 }
00683 }
00684 }
00685
00686 if ((cbp & 0x30)) {
00687 for (i = 1; i < 3; ++i) {
00688 if (svq3_decode_block(&s->gb, &h->mb[16*16*i], 0, 3)){
00689 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n");
00690 return -1;
00691 }
00692 }
00693
00694 if ((cbp & 0x20)) {
00695 for (i = 1; i < 3; i++) {
00696 for (j = 0; j < 4; j++) {
00697 k = 16*i + j;
00698 h->non_zero_count_cache[ scan8[k] ] = 1;
00699
00700 if (svq3_decode_block(&s->gb, &h->mb[16*k], 1, 1)){
00701 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n");
00702 return -1;
00703 }
00704 }
00705 }
00706 }
00707 }
00708 }
00709
00710 h->cbp= cbp;
00711 s->current_picture.mb_type[mb_xy] = mb_type;
00712
00713 if (IS_INTRA(mb_type)) {
00714 h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8, 1);
00715 }
00716
00717 return 0;
00718 }
00719
00720 static int svq3_decode_slice_header(AVCodecContext *avctx)
00721 {
00722 SVQ3Context *svq3 = avctx->priv_data;
00723 H264Context *h = &svq3->h;
00724 MpegEncContext *s = &h->s;
00725 const int mb_xy = h->mb_xy;
00726 int i, header;
00727
00728 header = get_bits(&s->gb, 8);
00729
00730 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
00731
00732 av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
00733 return -1;
00734 } else {
00735 int length = (header >> 5) & 3;
00736
00737 svq3->next_slice_index = get_bits_count(&s->gb) + 8*show_bits(&s->gb, 8*length) + 8*length;
00738
00739 if (svq3->next_slice_index > s->gb.size_in_bits) {
00740 av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
00741 return -1;
00742 }
00743
00744 s->gb.size_in_bits = svq3->next_slice_index - 8*(length - 1);
00745 skip_bits(&s->gb, 8);
00746
00747 if (svq3->watermark_key) {
00748 uint32_t header = AV_RL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1]);
00749 AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1], header ^ svq3->watermark_key);
00750 }
00751 if (length > 0) {
00752 memcpy((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3],
00753 &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1));
00754 }
00755 skip_bits_long(&s->gb, 0);
00756 }
00757
00758 if ((i = svq3_get_ue_golomb(&s->gb)) >= 3U){
00759 av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
00760 return -1;
00761 }
00762
00763 h->slice_type = golomb_to_pict_type[i];
00764
00765 if ((header & 0x9F) == 2) {
00766 i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1));
00767 s->mb_skip_run = get_bits(&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width));
00768 } else {
00769 skip_bits1(&s->gb);
00770 s->mb_skip_run = 0;
00771 }
00772
00773 h->slice_num = get_bits(&s->gb, 8);
00774 s->qscale = get_bits(&s->gb, 5);
00775 s->adaptive_quant = get_bits1(&s->gb);
00776
00777
00778 skip_bits1(&s->gb);
00779
00780 if (svq3->unknown_flag) {
00781 skip_bits1(&s->gb);
00782 }
00783
00784 skip_bits1(&s->gb);
00785 skip_bits(&s->gb, 2);
00786
00787 while (get_bits1(&s->gb)) {
00788 skip_bits(&s->gb, 8);
00789 }
00790
00791
00792 if (s->mb_x > 0) {
00793 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - 1 ]+3, -1, 4*sizeof(int8_t));
00794 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - s->mb_x] , -1, 8*sizeof(int8_t)*s->mb_x);
00795 }
00796 if (s->mb_y > 0) {
00797 memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x));
00798
00799 if (s->mb_x > 0) {
00800 h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] = -1;
00801 }
00802 }
00803
00804 return 0;
00805 }
00806
00807 static av_cold int svq3_decode_init(AVCodecContext *avctx)
00808 {
00809 SVQ3Context *svq3 = avctx->priv_data;
00810 H264Context *h = &svq3->h;
00811 MpegEncContext *s = &h->s;
00812 int m;
00813 unsigned char *extradata;
00814 unsigned char *extradata_end;
00815 unsigned int size;
00816 int marker_found = 0;
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 extradata_end = avctx->extradata + avctx->extradata_size;
00838 if (extradata) {
00839 for (m = 0; m + 8 < avctx->extradata_size; m++) {
00840 if (!memcmp(extradata, "SEQH", 4)) {
00841 marker_found = 1;
00842 break;
00843 }
00844 extradata++;
00845 }
00846 }
00847
00848
00849 if (marker_found) {
00850
00851 GetBitContext gb;
00852 int frame_size_code;
00853
00854 size = AV_RB32(&extradata[4]);
00855 if (size > extradata_end - extradata - 8)
00856 return AVERROR_INVALIDDATA;
00857 init_get_bits(&gb, extradata + 8, size*8);
00858
00859
00860 frame_size_code = get_bits(&gb, 3);
00861 switch (frame_size_code) {
00862 case 0: avctx->width = 160; avctx->height = 120; break;
00863 case 1: avctx->width = 128; avctx->height = 96; break;
00864 case 2: avctx->width = 176; avctx->height = 144; break;
00865 case 3: avctx->width = 352; avctx->height = 288; break;
00866 case 4: avctx->width = 704; avctx->height = 576; break;
00867 case 5: avctx->width = 240; avctx->height = 180; break;
00868 case 6: avctx->width = 320; avctx->height = 240; break;
00869 case 7:
00870 avctx->width = get_bits(&gb, 12);
00871 avctx->height = get_bits(&gb, 12);
00872 break;
00873 }
00874
00875 svq3->halfpel_flag = get_bits1(&gb);
00876 svq3->thirdpel_flag = get_bits1(&gb);
00877
00878
00879 skip_bits1(&gb);
00880 skip_bits1(&gb);
00881 skip_bits1(&gb);
00882 skip_bits1(&gb);
00883
00884 s->low_delay = get_bits1(&gb);
00885
00886
00887 skip_bits1(&gb);
00888
00889 while (get_bits1(&gb)) {
00890 skip_bits(&gb, 8);
00891 }
00892
00893 svq3->unknown_flag = get_bits1(&gb);
00894 avctx->has_b_frames = !s->low_delay;
00895 if (svq3->unknown_flag) {
00896 #if CONFIG_ZLIB
00897 unsigned watermark_width = svq3_get_ue_golomb(&gb);
00898 unsigned watermark_height = svq3_get_ue_golomb(&gb);
00899 int u1 = svq3_get_ue_golomb(&gb);
00900 int u2 = get_bits(&gb, 8);
00901 int u3 = get_bits(&gb, 2);
00902 int u4 = svq3_get_ue_golomb(&gb);
00903 unsigned long buf_len = watermark_width*watermark_height*4;
00904 int offset = (get_bits_count(&gb)+7)>>3;
00905 uint8_t *buf;
00906
00907 if ((uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
00908 return -1;
00909
00910 buf = av_malloc(buf_len);
00911 av_log(avctx, AV_LOG_DEBUG, "watermark size: %dx%d\n", watermark_width, watermark_height);
00912 av_log(avctx, AV_LOG_DEBUG, "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", u1, u2, u3, u4, offset);
00913 if (uncompress(buf, &buf_len, extradata + 8 + offset, size - offset) != Z_OK) {
00914 av_log(avctx, AV_LOG_ERROR, "could not uncompress watermark logo\n");
00915 av_free(buf);
00916 return -1;
00917 }
00918 svq3->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0);
00919 svq3->watermark_key = svq3->watermark_key << 16 | svq3->watermark_key;
00920 av_log(avctx, AV_LOG_DEBUG, "watermark key %#x\n", svq3->watermark_key);
00921 av_free(buf);
00922 #else
00923 av_log(avctx, AV_LOG_ERROR, "this svq3 file contains watermark which need zlib support compiled in\n");
00924 return -1;
00925 #endif
00926 }
00927 }
00928
00929 s->width = avctx->width;
00930 s->height = avctx->height;
00931
00932 if (MPV_common_init(s) < 0)
00933 return -1;
00934
00935 h->b_stride = 4*s->mb_width;
00936
00937 ff_h264_alloc_tables(h);
00938 }
00939
00940 return 0;
00941 }
00942
00943 static int svq3_decode_frame(AVCodecContext *avctx,
00944 void *data, int *data_size,
00945 AVPacket *avpkt)
00946 {
00947 SVQ3Context *svq3 = avctx->priv_data;
00948 H264Context *h = &svq3->h;
00949 MpegEncContext *s = &h->s;
00950 int buf_size = avpkt->size;
00951 int m, mb_type, left;
00952 uint8_t *buf;
00953
00954
00955 if (buf_size == 0) {
00956 if (s->next_picture_ptr && !s->low_delay) {
00957 *(AVFrame *) data = *(AVFrame *) &s->next_picture;
00958 s->next_picture_ptr = NULL;
00959 *data_size = sizeof(AVFrame);
00960 }
00961 return 0;
00962 }
00963
00964 s->mb_x = s->mb_y = h->mb_xy = 0;
00965
00966 if (svq3->watermark_key) {
00967 av_fast_malloc(&svq3->buf, &svq3->buf_size,
00968 buf_size+FF_INPUT_BUFFER_PADDING_SIZE);
00969 if (!svq3->buf)
00970 return AVERROR(ENOMEM);
00971 memcpy(svq3->buf, avpkt->data, buf_size);
00972 buf = svq3->buf;
00973 } else {
00974 buf = avpkt->data;
00975 }
00976
00977 init_get_bits(&s->gb, buf, 8*buf_size);
00978
00979 if (svq3_decode_slice_header(avctx))
00980 return -1;
00981
00982 s->pict_type = h->slice_type;
00983 s->picture_number = h->slice_num;
00984
00985 if (avctx->debug&FF_DEBUG_PICT_INFO){
00986 av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
00987 av_get_picture_type_char(s->pict_type), svq3->halfpel_flag, svq3->thirdpel_flag,
00988 s->adaptive_quant, s->qscale, h->slice_num);
00989 }
00990
00991
00992 s->current_picture.pict_type = s->pict_type;
00993 s->current_picture.key_frame = (s->pict_type == AV_PICTURE_TYPE_I);
00994
00995
00996 if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B)
00997 return 0;
00998 if ( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B)
00999 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I)
01000 || avctx->skip_frame >= AVDISCARD_ALL)
01001 return 0;
01002
01003 if (s->next_p_frame_damaged) {
01004 if (s->pict_type == AV_PICTURE_TYPE_B)
01005 return 0;
01006 else
01007 s->next_p_frame_damaged = 0;
01008 }
01009
01010 if (ff_h264_frame_start(h) < 0)
01011 return -1;
01012
01013 if (s->pict_type == AV_PICTURE_TYPE_B) {
01014 h->frame_num_offset = (h->slice_num - h->prev_frame_num);
01015
01016 if (h->frame_num_offset < 0) {
01017 h->frame_num_offset += 256;
01018 }
01019 if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
01020 av_log(h->s.avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
01021 return -1;
01022 }
01023 } else {
01024 h->prev_frame_num = h->frame_num;
01025 h->frame_num = h->slice_num;
01026 h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
01027
01028 if (h->prev_frame_num_offset < 0) {
01029 h->prev_frame_num_offset += 256;
01030 }
01031 }
01032
01033 for (m = 0; m < 2; m++){
01034 int i;
01035 for (i = 0; i < 4; i++){
01036 int j;
01037 for (j = -1; j < 4; j++)
01038 h->ref_cache[m][scan8[0] + 8*i + j]= 1;
01039 if (i < 3)
01040 h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
01041 }
01042 }
01043
01044 for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
01045 for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
01046 h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
01047
01048 if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits &&
01049 ((get_bits_count(&s->gb) & 7) == 0 || show_bits(&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) {
01050
01051 skip_bits(&s->gb, svq3->next_slice_index - get_bits_count(&s->gb));
01052 s->gb.size_in_bits = 8*buf_size;
01053
01054 if (svq3_decode_slice_header(avctx))
01055 return -1;
01056
01057
01058 }
01059
01060 mb_type = svq3_get_ue_golomb(&s->gb);
01061
01062 if (s->pict_type == AV_PICTURE_TYPE_I) {
01063 mb_type += 8;
01064 } else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4) {
01065 mb_type += 4;
01066 }
01067 if ((unsigned)mb_type > 33 || svq3_decode_mb(svq3, mb_type)) {
01068 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
01069 return -1;
01070 }
01071
01072 if (mb_type != 0) {
01073 ff_h264_hl_decode_mb (h);
01074 }
01075
01076 if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay) {
01077 s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
01078 (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
01079 }
01080 }
01081
01082 ff_draw_horiz_band(s, 16*s->mb_y, 16);
01083 }
01084
01085 left = buf_size*8 - get_bits_count(&s->gb);
01086
01087 if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
01088 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);
01089
01090 }
01091
01092 if (left < 0) {
01093 av_log(avctx, AV_LOG_ERROR, "frame num %d left %d\n", avctx->frame_number, left);
01094 return -1;
01095 }
01096
01097 MPV_frame_end(s);
01098
01099 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
01100 *(AVFrame *) data = *(AVFrame *) &s->current_picture;
01101 } else {
01102 *(AVFrame *) data = *(AVFrame *) &s->last_picture;
01103 }
01104
01105
01106 if (s->last_picture_ptr || s->low_delay) {
01107 *data_size = sizeof(AVFrame);
01108 }
01109
01110 return buf_size;
01111 }
01112
01113 static int svq3_decode_end(AVCodecContext *avctx)
01114 {
01115 SVQ3Context *svq3 = avctx->priv_data;
01116 H264Context *h = &svq3->h;
01117 MpegEncContext *s = &h->s;
01118
01119 ff_h264_free_context(h);
01120
01121 MPV_common_end(s);
01122
01123 av_freep(&svq3->buf);
01124 svq3->buf_size = 0;
01125
01126 return 0;
01127 }
01128
01129 AVCodec ff_svq3_decoder = {
01130 "svq3",
01131 AVMEDIA_TYPE_VIDEO,
01132 CODEC_ID_SVQ3,
01133 sizeof(SVQ3Context),
01134 svq3_decode_init,
01135 NULL,
01136 svq3_decode_end,
01137 svq3_decode_frame,
01138 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY,
01139 .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
01140 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_NONE},
01141 };