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