75 val = (val - 1) << shift;
94 const int qscale = s->
qscale;
97 component = (n <= 3 ? 0 : n - 4 + 1);
104 block[0] = dc * quant_matrix[0];
116 }
else if (level != 0) {
119 level = (level * qscale * quant_matrix[j]) >> 4;
120 level = (level - 1) | 1;
130 }
else if (level == 0) {
137 level = (level * qscale * quant_matrix[j]) >> 4;
138 level = (level - 1) | 1;
141 level = (level * qscale * quant_matrix[j]) >> 4;
142 level = (level - 1) | 1;
169 const int qscale = s->
qscale;
177 level = (3 * qscale * quant_matrix[0]) >> 5;
178 level = (level - 1) | 1;
194 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
195 level = (level - 1) | 1;
205 }
else if (level == 0) {
212 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
213 level = (level - 1) | 1;
216 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
217 level = (level - 1) | 1;
248 const int qscale = s->
qscale;
256 level = (3 * qscale) >> 1;
257 level = (level - 1) | 1;
274 level = ((level * 2 + 1) * qscale) >> 1;
275 level = (level - 1) | 1;
285 }
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;
355 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
367 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
370 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
388 block[63] ^= (mismatch & 1);
405 const int qscale = s->
qscale;
412 level = (3 * qscale) >> 1;
429 level = ((level * 2 + 1) * qscale) >> 1;
441 level = ((-level * 2 + 1) * qscale) >> 1;
444 level = ((level * 2 + 1) * qscale) >> 1;
467 const uint16_t *quant_matrix;
468 const int qscale = s->
qscale;
477 component = (n & 1) + 1;
487 mismatch = block[0] ^ 1;
503 }
else if (level != 0) {
506 level = (level * qscale * quant_matrix[j]) >> 4;
517 level = (-level * qscale * quant_matrix[j]) >> 4;
520 level = (level * qscale * quant_matrix[j]) >> 4;
533 block[63] ^= mismatch & 1;
550 const uint16_t *quant_matrix;
551 const int qscale = s->
qscale;
559 component = (n & 1) + 1;
582 }
else if (level != 0) {
585 level = (level * qscale * quant_matrix[j]) >> 4;
596 level = (-level * qscale * quant_matrix[j]) >> 4;
599 level = (level * qscale * quant_matrix[j]) >> 4;
650 int i, j, k, cbp,
val, mb_type, motion_type;
677 if ((s->
mv[0][0][0] | s->
mv[0][0][1] | s->
mv[1][0][0] | s->
mv[1][0][1]) == 0)
756 for (i = 0; i < 6; i++) {
760 for (i = 0; i < mb_block_count; i++) {
766 for (i = 0; i < 6; i++) {
812 s->
mv_dir = (mb_type >> 13) & 3;
814 switch (motion_type) {
819 for (i = 0; i < 2; i++) {
828 s->
mv[i][0][0] <<= 1;
829 s->
mv[i][0][1] <<= 1;
836 for (i = 0; i < 2; i++) {
839 for (j = 0; j < 2; j++) {
841 for (k = 0; k < 2; k++) {
845 s->
mv[i][j][k] =
val;
856 for (i = 0; i < 2; i++) {
858 for (j = 0; j < 2; j++) {
863 s->
mv[i][j][0] =
val;
867 s->
last_mv[i][j][1] = val << 1;
868 s->
mv[i][j][1] =
val;
876 for (i = 0; i < 2; i++) {
879 for (k = 0; k < 2; k++) {
884 s->
mv[i][0][k] =
val;
896 for (i = 0; i < 2; i++) {
898 int dmx, dmy, mx, my,
m;
907 s->
last_mv[i][0][1] >> my_shift);
911 s->
last_mv[i][0][1] = my << my_shift;
912 s->
last_mv[i][1][1] = my << my_shift;
926 s->
mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
927 s->
mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
929 s->
mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
930 s->
mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
934 s->
mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
935 s->
mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
955 if (mb_block_count > 6) {
956 cbp <<= mb_block_count - 6;
975 for (i = 0; i < 6; i++) {
984 cbp <<= 12-mb_block_count;
986 for (i = 0; i < mb_block_count; i++) {
987 if (cbp & (1 << 11)) {
998 for (i = 0; i < 6; i++) {
1007 for (i = 0; i < 6; i++) {
1019 for (i = 0; i < 12; i++)
1037 for (i = 0; i < 64; i++)
1066 if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !
s1->context_initialized)
1070 if (err)
return err;
1084 uint16_t temp_matrix[64];
1087 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1089 for (i = 0; i < 64; i++) {
1090 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1095 #if CONFIG_MPEG_XVMC_DECODER
1099 #if CONFIG_MPEG1_VDPAU_HWACCEL
1108 #if CONFIG_MPEG_XVMC_DECODER
1112 #if CONFIG_MPEG2_VDPAU_HWACCEL
1116 #if CONFIG_MPEG2_DXVA2_HWACCEL
1119 #if CONFIG_MPEG2_VAAPI_HWACCEL
1249 s->avctx->sample_aspect_ratio =
1259 memcpy(old_permutation,
s->dsp.idct_permutation, 64 *
sizeof(
uint8_t));
1269 s1->mpeg_enc_ctx_allocated = 1;
1279 int ref, f_code, vbv_delay;
1322 int horiz_size_ext, vert_size_ext;
1332 s->
width |= (horiz_size_ext << 12);
1333 s->
height |= (vert_size_ext << 12);
1335 s->
bit_rate += (bit_rate_ext << 18) * 400;
1358 int color_description, w, h;
1362 if (color_description) {
1398 for (i = 0; i < nofco; i++) {
1416 for (i = 0; i < 64; i++) {
1423 if (intra && i == 0 && v != 8) {
1553 for (i = 0; i < 4; i++) {
1575 #define DECODE_SLICE_ERROR -1
1576 #define DECODE_SLICE_OK 0
1645 const uint8_t *buf_end, *buf_start = *buf - 4;
1646 int start_code = -1;
1648 if (buf_end < *buf + buf_size)
1664 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",
1685 int motion_x, motion_y, dir, i;
1687 for (i = 0; i < 2; i++) {
1688 for (dir = 0; dir < 2; dir++) {
1690 motion_x = motion_y = 0;
1692 motion_x = s->
mv[dir][0][0];
1693 motion_y = s->
mv[dir][0][1];
1695 motion_x = s->
mv[dir][i][0];
1696 motion_y = s->
mv[dir][i][1];
1725 s->
mb_y += 1 << field_pic;
1733 if (left >= 32 && !is_d10) {
1767 }
else if (code == 35) {
1789 for (i = 0; i < 12; i++)
1798 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
1828 uint32_t start_code;
1833 av_dlog(c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1852 mb_y += (*buf&0xE0)<<2;
1856 if (mb_y < 0 || mb_y >= s->
end_mb_y)
1927 if (width == 0 || height == 0) {
1955 for (i = 0; i < 64; i++) {
1965 for (i = 0; i < 64; i++) {
2021 for (i = 0; i < 64; i++) {
2053 const uint8_t *p,
int buf_size)
2056 const uint8_t *buf_end = p + buf_size;
2061 if(!memcmp(p+i,
"\0TMPGEXS\0", 9)){
2072 if (buf_end - p >= 5 &&
2073 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2081 if (buf_end - p < 1)
2110 "GOP (%s) closed_gop=%d broken_link=%d\n",
2116 AVFrame *picture,
int *got_output,
2122 const uint8_t *buf_end = buf + buf_size;
2123 int ret, input_size;
2124 int last_code = 0, skip_frame = 0;
2125 int picture_start_code_seen = 0;
2129 uint32_t start_code = -1;
2131 if (start_code > 0x1ff) {
2142 if ((CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER)
2158 input_size = buf_end - buf_ptr;
2161 av_log(avctx,
AV_LOG_DEBUG,
"%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
2165 switch (start_code) {
2167 if (last_code == 0) {
2185 picture_start_code_seen = 1;
2230 if (last_code == 0) {
2262 if (last_code == 0) {
2305 mb_y += (*buf_ptr&0xE0)<<2;
2377 if (threshold <= mb_y) {
2413 void *
data,
int *got_output,
2418 int buf_size = avpkt->
size;
2422 av_dlog(avctx,
"fill_buffer\n");
2466 ret =
decode_chunks(avctx, picture, got_output, buf, buf_size);
2467 if (ret<0 || *got_output)
2506 .
name =
"mpeg1video",
2523 .
name =
"mpeg2video",
2541 .
name =
"mpegvideo",
2554 #if CONFIG_MPEG_XVMC_DECODER
2562 av_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2572 AVCodec ff_mpeg_xvmc_decoder = {
2573 .
name =
"mpegvideo_xvmc",
2577 .
init = mpeg_mc_decode_init,
2588 #if CONFIG_MPEG_VDPAU_DECODER
2589 AVCodec ff_mpeg_vdpau_decoder = {
2590 .
name =
"mpegvideo_vdpau",
2604 #if CONFIG_MPEG1_VDPAU_DECODER
2605 AVCodec ff_mpeg1_vdpau_decoder = {
2606 .
name =
"mpeg1video_vdpau",