47 #define MBINCR_VLC_BITS 9
48 #define MB_PAT_VLC_BITS 9
49 #define MB_PTYPE_VLC_BITS 6
50 #define MB_BTYPE_VLC_BITS 6
57 int code, sign, val, shift;
71 val = (val - 1) << shift;
83 #define check_scantable_index(ctx, x) \
86 av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
87 ctx->mb_x, ctx->mb_y); \
88 return AVERROR_INVALIDDATA; \
99 const int qscale = s->
qscale;
102 component = (n <= 3 ? 0 : n - 4 + 1);
109 block[0] = dc * quant_matrix[0];
121 }
else if (level != 0) {
125 level = (level * qscale * quant_matrix[j]) >> 4;
126 level = (level - 1) | 1;
136 }
else if (level == 0) {
144 level = (level * qscale * quant_matrix[j]) >> 4;
145 level = (level - 1) | 1;
148 level = (level * qscale * quant_matrix[j]) >> 4;
149 level = (level - 1) | 1;
172 const int qscale = s->
qscale;
180 level = (3 * qscale * quant_matrix[0]) >> 5;
181 level = (level - 1) | 1;
197 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
198 level = (level - 1) | 1;
208 }
else if (level == 0) {
215 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
216 level = (level - 1) | 1;
219 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
220 level = (level - 1) | 1;
246 const int qscale = s->
qscale;
254 level = (3 * qscale) >> 1;
255 level = (level - 1) | 1;
273 level = ((level * 2 + 1) * qscale) >> 1;
274 level = (level - 1) | 1;
284 }
else if (level == 0) {
292 level = ((level * 2 + 1) * qscale) >> 1;
293 level = (level - 1) | 1;
296 level = ((level * 2 + 1) * qscale) >> 1;
297 level = (level - 1) | 1;
320 const uint16_t *quant_matrix;
321 const int qscale = s->
qscale;
337 level= (3 * qscale * quant_matrix[0]) >> 5;
356 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
369 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
372 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
386 block[63] ^= (mismatch & 1);
398 const int qscale = s->
qscale;
405 level = (3 * qscale) >> 1;
423 level = ((level * 2 + 1) * qscale) >> 1;
436 level = ((-level * 2 + 1) * qscale) >> 1;
439 level = ((level * 2 + 1) * qscale) >> 1;
462 const uint16_t *quant_matrix;
463 const int qscale = s->
qscale;
472 component = (n & 1) + 1;
482 mismatch = block[0] ^ 1;
498 }
else if (level != 0) {
502 level = (level * qscale * quant_matrix[j]) >> 4;
514 level = (-level * qscale * quant_matrix[j]) >> 4;
517 level = (level * qscale * quant_matrix[j]) >> 4;
526 block[63] ^= mismatch & 1;
538 const uint16_t *quant_matrix;
539 const int qscale = s->
qscale;
547 component = (n & 1) + 1;
571 }
else if (level != 0) {
575 level = (level * qscale * quant_matrix[j]) >> 4;
587 level = (-level * qscale * quant_matrix[j]) >> 4;
590 level = (level * qscale * quant_matrix[j]) >> 4;
605 #define INIT_2D_VLC_RL(rl, static_size)\
607 static RL_VLC_ELEM rl_vlc_table[static_size];\
608 INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
609 &rl.table_vlc[0][1], 4, 2,\
610 &rl.table_vlc[0][0], 4, 2, static_size);\
612 rl.rl_vlc[0] = rl_vlc_table;\
613 init_2d_vlc_rl(&rl);\
635 }
else if (code == rl->
n+1) {
749 int i, j, k, cbp, val, mb_type, motion_type;
773 if ((s->
mv[0][0][0] | s->
mv[0][0][1] | s->
mv[1][0][0] | s->
mv[1][0][1]) == 0)
852 for (i = 0; i < 6; i++) {
856 for (i = 0; i < mb_block_count; i++) {
862 for (i = 0; i < 6; i++) {
907 s->
mv_dir = (mb_type >> 13) & 3;
909 switch (motion_type) {
914 for (i = 0; i < 2; i++) {
923 s->
mv[i][0][0] <<= 1;
924 s->
mv[i][0][1] <<= 1;
931 for (i = 0; i < 2; i++) {
934 for (j = 0; j < 2; j++) {
936 for (k = 0; k < 2; k++) {
940 s->
mv[i][j][k] = val;
951 for (i = 0; i < 2; i++) {
953 for (j = 0; j < 2; j++) {
958 s->
mv[i][j][0] = val;
962 s->
last_mv[i][j][1] = val << 1;
963 s->
mv[i][j][1] = val;
970 for (i = 0; i < 2; i++) {
973 for (k = 0; k < 2; k++) {
978 s->
mv[i][0][k] = val;
986 for (i = 0; i < 2; i++) {
988 int dmx, dmy, mx, my, m;
997 s->
last_mv[i][0][1] >> my_shift);
1001 s->
last_mv[i][0][1] = my << my_shift;
1002 s->
last_mv[i][1][1] = my << my_shift;
1004 s->
mv[i][0][0] = mx;
1005 s->
mv[i][0][1] = my;
1006 s->
mv[i][1][0] = mx;
1007 s->
mv[i][1][1] = my;
1016 s->
mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
1017 s->
mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
1019 s->
mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
1020 s->
mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
1024 s->
mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
1025 s->
mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
1045 if (mb_block_count > 6) {
1046 cbp <<= mb_block_count - 6;
1065 for (i = 0; i < 6; i++) {
1074 cbp <<= 12-mb_block_count;
1076 for (i = 0; i < mb_block_count; i++) {
1077 if (cbp & (1 << 11)) {
1088 for (i = 0; i < 6; i++) {
1097 for (i = 0; i < 6; i++) {
1109 for (i = 0; i < 12; i++)
1127 for (i = 0; i < 64; i++)
1156 if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !
s1->context_initialized)
1160 if (err)
return err;
1174 uint16_t temp_matrix[64];
1177 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1179 for (i = 0; i < 64; i++) {
1180 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1294 s->avctx->sample_aspect_ratio =
1304 s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
1305 if (avctx->idct_algo == FF_IDCT_AUTO)
1310 memcpy(old_permutation, s->dsp.idct_permutation, 64 *
sizeof(
uint8_t));
1320 s1->mpeg_enc_ctx_allocated = 1;
1326 const uint8_t *buf,
int buf_size)
1330 int ref, f_code, vbv_delay;
1370 int horiz_size_ext, vert_size_ext;
1380 s->
width |= (horiz_size_ext << 12);
1381 s->
height |= (vert_size_ext << 12);
1383 s->
bit_rate += (bit_rate_ext << 18) * 400;
1406 int color_description, w, h;
1410 if (color_description) {
1446 for (i = 0; i < nofco; i++) {
1464 for (i = 0; i < 64; i++) {
1471 if (intra && i == 0 && v != 8) {
1611 for (i = 0; i < 4; i++) {
1633 #define DECODE_SLICE_ERROR -1
1634 #define DECODE_SLICE_OK 0
1643 const uint8_t **buf,
int buf_size)
1651 assert(mb_y < s->mb_height);
1699 const uint8_t *buf_end, *buf_start = *buf - 4;
1700 int start_code = -1;
1702 if (buf_end < *buf + buf_size)
1718 av_log(s->
avctx,
AV_LOG_DEBUG,
"qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
1739 int motion_x, motion_y, dir, i;
1741 for (i = 0; i < 2; i++) {
1742 for (dir = 0; dir < 2; dir++) {
1744 motion_x = motion_y = 0;
1746 motion_x = s->
mv[dir][0][0];
1747 motion_y = s->
mv[dir][0][1];
1749 motion_x = s->
mv[dir][i][0];
1750 motion_y = s->
mv[dir][i][1];
1773 const int mb_size = 16;
1779 s->
mb_y += 1 << field_pic;
1811 }
else if (code == 35) {
1833 for (i = 0; i < 12; i++)
1842 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
1872 uint32_t start_code;
1877 av_dlog(c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1897 if (mb_y < 0 || mb_y >= s->
end_mb_y)
1953 const uint8_t *buf,
int buf_size)
1964 if (width <= 0 || height <= 0)
1988 for (i = 0; i < 64; i++) {
1998 for (i = 0; i < 64; i++) {
2060 for (i = 0; i < 64; i++) {
2085 const uint8_t *p,
int buf_size)
2087 const uint8_t *buf_end = p + buf_size;
2090 if (buf_end - p >= 5 &&
2091 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2099 if (buf_end - p < 1)
2107 const uint8_t *buf,
int buf_size)
2112 int time_code_hours, time_code_minutes;
2113 int time_code_seconds, time_code_pictures;
2134 time_code_hours, time_code_minutes, time_code_seconds,
2135 time_code_pictures, s1->
closed_gop, broken_link);
2158 for (i = 0; i < buf_size; i++) {
2164 if ((buf[i] & 3) == 3)
2203 const uint8_t *buf,
int buf_size)
2208 const uint8_t *buf_end = buf + buf_size;
2209 int ret, input_size;
2214 uint32_t start_code = -1;
2216 if (start_code > 0x1ff) {
2238 input_size = buf_end - buf_ptr;
2241 av_log(avctx,
AV_LOG_DEBUG,
"%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
2245 switch (start_code) {
2247 if (last_code == 0) {
2291 if (last_code == 0) {
2323 if (last_code == 0) {
2400 if (threshold <= mb_y) {
2436 void *
data,
int *got_output,
2440 int buf_size = avpkt->
size;
2444 av_dlog(avctx,
"fill_buffer\n");
2476 return decode_chunks(avctx, picture, got_output, buf, buf_size);
2513 .
name =
"mpeg1video",
2529 .
name =
"mpeg2video",
2544 #if CONFIG_MPEG_XVMC_DECODER
2549 if (!(avctx->
slice_flags & SLICE_FLAG_CODED_ORDER))
2551 if (!(avctx->
slice_flags & SLICE_FLAG_ALLOW_FIELD)) {
2552 av_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2562 AVCodec ff_mpeg_xvmc_decoder = {
2563 .
name =
"mpegvideo_xvmc",
2567 .
init = mpeg_mc_decode_init,
2570 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
2571 CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
2578 #if CONFIG_MPEG_VDPAU_DECODER
2579 AVCodec ff_mpeg_vdpau_decoder = {
2580 .
name =
"mpegvideo_vdpau",
2587 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED |
2588 CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
2594 #if CONFIG_MPEG1_VDPAU_DECODER
2595 AVCodec ff_mpeg1_vdpau_decoder = {
2596 .
name =
"mpeg1video_vdpau",
2603 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED |
2604 CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,