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;
1172 const uint8_t *new_perm)
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]];
1217 uint8_t old_permutation[64];
1293 s->avctx->sample_aspect_ratio =
1309 memcpy(old_permutation, s->dsp.idct_permutation, 64 *
sizeof(uint8_t));
1319 s1->mpeg_enc_ctx_allocated = 1;
1325 const uint8_t *buf,
int buf_size)
1329 int ref, f_code, vbv_delay;
1369 int horiz_size_ext, vert_size_ext;
1379 s->
width |= (horiz_size_ext << 12);
1380 s->
height |= (vert_size_ext << 12);
1382 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) {
1606 for (i = 0; i < 4; i++) {
1628 #define DECODE_SLICE_ERROR -1
1629 #define DECODE_SLICE_OK 0
1638 const uint8_t **buf,
int buf_size)
1647 assert(mb_y < s->mb_height);
1695 const uint8_t *buf_end, *buf_start = *buf - 4;
1696 int start_code = -1;
1698 if (buf_end < *buf + buf_size)
1714 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",
1735 int motion_x, motion_y, dir, i;
1737 for (i = 0; i < 2; i++) {
1738 for (dir = 0; dir < 2; dir++) {
1740 motion_x = motion_y = 0;
1742 motion_x = s->
mv[dir][0][0];
1743 motion_y = s->
mv[dir][0][1];
1745 motion_x = s->
mv[dir][i][0];
1746 motion_y = s->
mv[dir][i][1];
1775 s->
mb_y += 1 << field_pic;
1807 }
else if (code == 35) {
1829 for (i = 0; i < 12; i++)
1838 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
1868 uint32_t start_code;
1892 if (mb_y < 0 || mb_y >= s->
end_mb_y)
1948 const uint8_t *buf,
int buf_size)
1959 if (width <= 0 || height <= 0)
1983 for (i = 0; i < 64; i++) {
1993 for (i = 0; i < 64; i++) {
2056 for (i = 0; i < 64; i++) {
2082 const uint8_t *p,
int buf_size)
2084 const uint8_t *buf_end = p + buf_size;
2087 if (buf_end - p >= 5 &&
2088 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2096 if (buf_end - p < 1)
2104 const uint8_t *buf,
int buf_size)
2109 int time_code_hours, time_code_minutes;
2110 int time_code_seconds, time_code_pictures;
2131 time_code_hours, time_code_minutes, time_code_seconds,
2132 time_code_pictures, s1->
closed_gop, broken_link);
2155 for (i = 0; i < buf_size; i++) {
2161 if ((buf[i] & 3) == 3)
2199 const uint8_t *buf,
int buf_size);
2203 void *
data,
int *data_size,
2206 const uint8_t *buf = avpkt->
data;
2207 int buf_size = avpkt->
size;
2211 av_dlog(avctx,
"fill_buffer\n");
2243 return decode_chunks(avctx, picture, data_size, buf, buf_size);
2248 const uint8_t *buf,
int buf_size)
2252 const uint8_t *buf_ptr = buf;
2253 const uint8_t *buf_end = buf + buf_size;
2254 int ret, input_size;
2259 uint32_t start_code = -1;
2261 if (start_code > 0x1ff) {
2283 input_size = buf_end - buf_ptr;
2286 av_log(avctx,
AV_LOG_DEBUG,
"%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
2290 switch (start_code) {
2292 if (last_code == 0) {
2336 if (last_code == 0) {
2368 if (last_code == 0) {
2445 if (threshold <= mb_y) {
2510 .
name =
"mpeg1video",
2525 .
name =
"mpeg2video",
2539 #if CONFIG_MPEG_XVMC_DECODER
2547 av_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2557 AVCodec ff_mpeg_xvmc_decoder = {
2558 .
name =
"mpegvideo_xvmc",
2562 .
init = mpeg_mc_decode_init,
2572 #if CONFIG_MPEG_VDPAU_DECODER
2573 AVCodec ff_mpeg_vdpau_decoder = {
2574 .
name =
"mpegvideo_vdpau",
2587 #if CONFIG_MPEG1_VDPAU_DECODER
2588 AVCodec ff_mpeg1_vdpau_decoder = {
2589 .
name =
"mpeg1video_vdpau",