57 #define MB_TYPE_ZERO_MV 0x20000000
84 0, 1, 2, 3, 4, 5, 6, 7,
85 8,10,12,14,16,18,20,22,
86 24,28,32,36,40,44,48,52,
87 56,64,72,80,88,96,104,112,
107 val = (val - 1) << shift;
126 const int qscale = s->
qscale;
129 component = (n <= 3 ? 0 : n - 4 + 1);
136 block[0] = dc * quant_matrix[0];
148 }
else if (level != 0) {
151 level = (level * qscale * quant_matrix[j]) >> 4;
152 level = (level - 1) | 1;
162 }
else if (level == 0) {
169 level = (level * qscale * quant_matrix[j]) >> 4;
170 level = (level - 1) | 1;
173 level = (level * qscale * quant_matrix[j]) >> 4;
174 level = (level - 1) | 1;
201 const int qscale = s->
qscale;
209 level = (3 * qscale * quant_matrix[0]) >> 5;
210 level = (level - 1) | 1;
226 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
227 level = (level - 1) | 1;
237 }
else if (level == 0) {
244 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
245 level = (level - 1) | 1;
248 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
249 level = (level - 1) | 1;
280 const int qscale = s->
qscale;
288 level = (3 * qscale) >> 1;
289 level = (level - 1) | 1;
306 level = ((level * 2 + 1) * qscale) >> 1;
307 level = (level - 1) | 1;
317 }
else if (level == 0) {
324 level = ((level * 2 + 1) * qscale) >> 1;
325 level = (level - 1) | 1;
328 level = ((level * 2 + 1) * qscale) >> 1;
329 level = (level - 1) | 1;
352 const uint16_t *quant_matrix;
353 const int qscale = s->
qscale;
369 level= (3 * qscale * quant_matrix[0]) >> 5;
387 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
399 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
402 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
420 block[63] ^= (mismatch & 1);
437 const int qscale = s->
qscale;
444 level = (3 * qscale) >> 1;
461 level = ((level * 2 + 1) * qscale) >> 1;
473 level = ((-level * 2 + 1) * qscale) >> 1;
476 level = ((level * 2 + 1) * qscale) >> 1;
499 const uint16_t *quant_matrix;
500 const int qscale = s->
qscale;
509 component = (n & 1) + 1;
519 mismatch = block[0] ^ 1;
535 }
else if (level != 0) {
538 level = (level * qscale * quant_matrix[j]) >> 4;
549 level = (-level * qscale * quant_matrix[j]) >> 4;
552 level = (level * qscale * quant_matrix[j]) >> 4;
565 block[63] ^= mismatch & 1;
582 const uint16_t *quant_matrix;
583 const int qscale = s->
qscale;
591 component = (n & 1) + 1;
614 }
else if (level != 0) {
617 level = (level * qscale * quant_matrix[j]) >> 4;
628 level = (-level * qscale * quant_matrix[j]) >> 4;
631 level = (level * qscale * quant_matrix[j]) >> 4;
682 int i, j, k, cbp,
val, mb_type, motion_type;
707 if ((s->
mv[0][0][0] | s->
mv[0][0][1] | s->
mv[1][0][0] | s->
mv[1][0][1]) == 0)
786 for (i = 0; i < 6; i++) {
790 for (i = 0; i < mb_block_count; i++) {
796 for (i = 0; i < 6; i++) {
842 s->
mv_dir = (mb_type >> 13) & 3;
844 switch (motion_type) {
849 for (i = 0; i < 2; i++) {
858 s->
mv[i][0][0] <<= 1;
859 s->
mv[i][0][1] <<= 1;
866 for (i = 0; i < 2; i++) {
869 for (j = 0; j < 2; j++) {
871 for (k = 0; k < 2; k++) {
875 s->
mv[i][j][k] =
val;
886 for (i = 0; i < 2; i++) {
888 for (j = 0; j < 2; j++) {
893 s->
mv[i][j][0] =
val;
897 s->
last_mv[i][j][1] = val << 1;
898 s->
mv[i][j][1] =
val;
906 for (i = 0; i < 2; i++) {
909 for (k = 0; k < 2; k++) {
914 s->
mv[i][0][k] =
val;
926 for (i = 0; i < 2; i++) {
928 int dmx, dmy, mx, my,
m;
937 s->
last_mv[i][0][1] >> my_shift);
941 s->
last_mv[i][0][1] = my << my_shift;
942 s->
last_mv[i][1][1] = my << my_shift;
956 s->
mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
957 s->
mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
959 s->
mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
960 s->
mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
964 s->
mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
965 s->
mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
985 if (mb_block_count > 6) {
986 cbp <<= mb_block_count - 6;
1005 for (i = 0; i < 6; i++) {
1014 cbp <<= 12-mb_block_count;
1016 for (i = 0; i < mb_block_count; i++) {
1017 if (cbp & (1 << 11)) {
1028 for (i = 0; i < 6; i++) {
1037 for (i = 0; i < 6; i++) {
1049 for (i = 0; i < 12; i++)
1067 for (i = 0; i < 64; i++)
1096 if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !
s1->context_initialized)
1100 if (err)
return err;
1114 uint16_t temp_matrix[64];
1117 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1119 for (i = 0; i < 64; i++) {
1120 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1125 #if CONFIG_MPEG_XVMC_DECODER
1129 #if CONFIG_MPEG1_VDPAU_HWACCEL
1138 #if CONFIG_MPEG_XVMC_DECODER
1142 #if CONFIG_MPEG2_VDPAU_HWACCEL
1146 #if CONFIG_MPEG2_DXVA2_HWACCEL
1149 #if CONFIG_MPEG2_VAAPI_HWACCEL
1280 s->avctx->sample_aspect_ratio =
1290 memcpy(old_permutation,
s->dsp.idct_permutation, 64 *
sizeof(
uint8_t));
1300 s1->mpeg_enc_ctx_allocated = 1;
1310 int ref, f_code, vbv_delay;
1353 int horiz_size_ext, vert_size_ext;
1363 s->
width |= (horiz_size_ext << 12);
1364 s->
height |= (vert_size_ext << 12);
1366 s->
bit_rate += (bit_rate_ext << 18) * 400;
1389 int color_description, w, h;
1393 if (color_description) {
1429 for (i = 0; i < nofco; i++) {
1447 for (i = 0; i < 64; i++) {
1454 if (intra && i == 0 && v != 8) {
1584 for (i = 0; i < 4; i++) {
1606 #define DECODE_SLICE_ERROR -1
1607 #define DECODE_SLICE_OK 0
1676 const uint8_t *buf_end, *buf_start = *buf - 4;
1679 if (buf_end < *buf + buf_size)
1695 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",
1716 int motion_x, motion_y, dir, i;
1718 for (i = 0; i < 2; i++) {
1719 for (dir = 0; dir < 2; dir++) {
1721 motion_x = motion_y = 0;
1723 motion_x = s->
mv[dir][0][0];
1724 motion_y = s->
mv[dir][0][1];
1726 motion_x = s->
mv[dir][i][0];
1727 motion_y = s->
mv[dir][i][1];
1756 s->
mb_y += 1 << field_pic;
1764 if (left >= 32 && !is_d10) {
1798 }
else if (code == 35) {
1820 for (i = 0; i < 12; i++)
1829 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
1864 av_dlog(c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1883 mb_y += (*buf&0xE0)<<2;
1887 if (mb_y < 0 || mb_y >= s->
end_mb_y)
1958 if (width == 0 || height == 0) {
1986 for (i = 0; i < 64; i++) {
1996 for (i = 0; i < 64; i++) {
2053 for (i = 0; i < 64; i++) {
2084 const uint8_t *p,
int buf_size)
2087 const uint8_t *buf_end = p + buf_size;
2092 if(!memcmp(p+i,
"\0TMPGEXS\0", 9)){
2103 if (buf_end - p >= 5 &&
2104 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2112 if (buf_end - p < 1)
2141 "GOP (%s) closed_gop=%d broken_link=%d\n",
2147 AVFrame *picture,
int *got_output,
2153 const uint8_t *buf_end = buf + buf_size;
2154 int ret, input_size;
2155 int last_code = 0, skip_frame = 0;
2156 int picture_start_code_seen = 0;
2162 if (start_code > 0x1ff) {
2174 if ((CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER)
2190 input_size = buf_end - buf_ptr;
2193 av_log(avctx,
AV_LOG_DEBUG,
"%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
2197 switch (start_code) {
2199 if (last_code == 0) {
2217 picture_start_code_seen = 1;
2263 if (last_code == 0) {
2295 if (last_code == 0) {
2338 mb_y += (*buf_ptr&0xE0)<<2;
2344 if (buf_end - buf_ptr < 2) {
2416 if (threshold <= mb_y) {
2452 void *
data,
int *got_output,
2457 int buf_size = avpkt->
size;
2461 av_dlog(avctx,
"fill_buffer\n");
2505 ret =
decode_chunks(avctx, picture, got_output, buf, buf_size);
2506 if (ret<0 || *got_output)
2545 .
name =
"mpeg1video",
2562 .
name =
"mpeg2video",
2580 .
name =
"mpegvideo",
2593 #if CONFIG_MPEG_XVMC_DECODER
2601 av_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2611 AVCodec ff_mpeg_xvmc_decoder = {
2612 .
name =
"mpegvideo_xvmc",
2617 .
init = mpeg_mc_decode_init,
2627 #if CONFIG_MPEG_VDPAU_DECODER
2628 AVCodec ff_mpeg_vdpau_decoder = {
2629 .
name =
"mpegvideo_vdpau",
2643 #if CONFIG_MPEG1_VDPAU_DECODER
2644 AVCodec ff_mpeg1_vdpau_decoder = {
2645 .
name =
"mpeg1video_vdpau",