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;
90 const int qscale = s->
qscale;
93 component = (n <= 3 ? 0 : n - 4 + 1);
100 block[0] = dc * quant_matrix[0];
112 }
else if (level != 0) {
115 level = (level * qscale * quant_matrix[j]) >> 4;
116 level = (level - 1) | 1;
126 }
else if (level == 0) {
133 level = (level * qscale * quant_matrix[j]) >> 4;
134 level = (level - 1) | 1;
137 level = (level * qscale * quant_matrix[j]) >> 4;
138 level = (level - 1) | 1;
165 const int qscale = s->
qscale;
173 level = (3 * qscale * quant_matrix[0]) >> 5;
174 level = (level - 1) | 1;
190 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
191 level = (level - 1) | 1;
201 }
else if (level == 0) {
208 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
209 level = (level - 1) | 1;
212 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
213 level = (level - 1) | 1;
239 const int qscale = s->
qscale;
247 level = (3 * qscale) >> 1;
248 level = (level - 1) | 1;
265 level = ((level * 2 + 1) * qscale) >> 1;
266 level = (level - 1) | 1;
276 }
else if (level == 0) {
283 level = ((level * 2 + 1) * qscale) >> 1;
284 level = (level - 1) | 1;
287 level = ((level * 2 + 1) * qscale) >> 1;
288 level = (level - 1) | 1;
311 const uint16_t *quant_matrix;
312 const int qscale = s->
qscale;
328 level= (3 * qscale * quant_matrix[0]) >> 5;
346 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
358 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
361 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
379 block[63] ^= (mismatch & 1);
391 const int qscale = s->
qscale;
398 level = (3 * qscale) >> 1;
415 level = ((level * 2 + 1) * qscale) >> 1;
427 level = ((-level * 2 + 1) * qscale) >> 1;
430 level = ((level * 2 + 1) * qscale) >> 1;
453 const uint16_t *quant_matrix;
454 const int qscale = s->
qscale;
463 component = (n & 1) + 1;
473 mismatch = block[0] ^ 1;
489 }
else if (level != 0) {
492 level = (level * qscale * quant_matrix[j]) >> 4;
503 level = (-level * qscale * quant_matrix[j]) >> 4;
506 level = (level * qscale * quant_matrix[j]) >> 4;
519 block[63] ^= mismatch & 1;
531 const uint16_t *quant_matrix;
532 const int qscale = s->
qscale;
540 component = (n & 1) + 1;
563 }
else if (level != 0) {
566 level = (level * qscale * quant_matrix[j]) >> 4;
577 level = (-level * qscale * quant_matrix[j]) >> 4;
580 level = (level * qscale * quant_matrix[j]) >> 4;
595 #define INIT_2D_VLC_RL(rl, static_size)\
597 static RL_VLC_ELEM rl_vlc_table[static_size];\
598 INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
599 &rl.table_vlc[0][1], 4, 2,\
600 &rl.table_vlc[0][0], 4, 2, static_size);\
602 rl.rl_vlc[0] = rl_vlc_table;\
603 init_2d_vlc_rl(&rl);\
625 }
else if (code == rl->
n+1) {
739 int i, j, k, cbp, val, mb_type, motion_type;
763 if ((s->
mv[0][0][0] | s->
mv[0][0][1] | s->
mv[1][0][0] | s->
mv[1][0][1]) == 0)
842 for (i = 0; i < 6; i++) {
846 for (i = 0; i < mb_block_count; i++) {
852 for (i = 0; i < 6; i++) {
897 s->
mv_dir = (mb_type >> 13) & 3;
899 switch (motion_type) {
904 for (i = 0; i < 2; i++) {
913 s->
mv[i][0][0] <<= 1;
914 s->
mv[i][0][1] <<= 1;
921 for (i = 0; i < 2; i++) {
924 for (j = 0; j < 2; j++) {
926 for (k = 0; k < 2; k++) {
930 s->
mv[i][j][k] = val;
941 for (i = 0; i < 2; i++) {
943 for (j = 0; j < 2; j++) {
948 s->
mv[i][j][0] = val;
952 s->
last_mv[i][j][1] = val << 1;
953 s->
mv[i][j][1] = val;
960 for (i = 0; i < 2; i++) {
963 for (k = 0; k < 2; k++) {
968 s->
mv[i][0][k] = val;
976 for (i = 0; i < 2; i++) {
978 int dmx, dmy, mx, my, m;
987 s->
last_mv[i][0][1] >> my_shift);
991 s->
last_mv[i][0][1] = my << my_shift;
992 s->
last_mv[i][1][1] = my << my_shift;
1006 s->
mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
1007 s->
mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
1009 s->
mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
1010 s->
mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
1014 s->
mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
1015 s->
mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
1035 if (mb_block_count > 6) {
1036 cbp <<= mb_block_count - 6;
1055 for (i = 0; i < 6; i++) {
1064 cbp <<= 12-mb_block_count;
1066 for (i = 0; i < mb_block_count; i++) {
1067 if (cbp & (1 << 11)) {
1078 for (i = 0; i < 6; i++) {
1087 for (i = 0; i < 6; i++) {
1099 for (i = 0; i < 12; i++)
1117 for (i = 0; i < 64; i++)
1146 if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !
s1->context_initialized)
1150 if (err)
return err;
1162 const uint8_t *new_perm)
1164 uint16_t temp_matrix[64];
1167 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1169 for (i = 0; i < 64; i++) {
1170 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1207 uint8_t old_permutation[64];
1283 s->avctx->sample_aspect_ratio =
1299 memcpy(old_permutation, s->dsp.idct_permutation, 64 *
sizeof(uint8_t));
1309 s1->mpeg_enc_ctx_allocated = 1;
1315 const uint8_t *buf,
int buf_size)
1319 int ref, f_code, vbv_delay;
1359 int horiz_size_ext, vert_size_ext;
1369 s->
width |= (horiz_size_ext << 12);
1370 s->
height |= (vert_size_ext << 12);
1372 s->
bit_rate += (bit_rate_ext << 18) * 400;
1396 int color_description, w, h;
1400 if (color_description) {
1436 for (i = 0; i < nofco; i++) {
1454 for (i = 0; i < 64; i++) {
1461 if (intra && i == 0 && v != 8) {
1596 for (i = 0; i < 4; i++) {
1618 #define DECODE_SLICE_ERROR -1
1619 #define DECODE_SLICE_OK 0
1628 const uint8_t **buf,
int buf_size)
1637 assert(mb_y < s->mb_height);
1685 const uint8_t *buf_end, *buf_start = *buf - 4;
1686 int start_code = -1;
1688 if (buf_end < *buf + buf_size)
1704 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",
1725 int motion_x, motion_y, dir, i;
1727 for (i = 0; i < 2; i++) {
1728 for (dir = 0; dir < 2; dir++) {
1730 motion_x = motion_y = 0;
1732 motion_x = s->
mv[dir][0][0];
1733 motion_y = s->
mv[dir][0][1];
1735 motion_x = s->
mv[dir][i][0];
1736 motion_y = s->
mv[dir][i][1];
1765 s->
mb_y += 1 << field_pic;
1797 }
else if (code == 35) {
1819 for (i = 0; i < 12; i++)
1828 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
1858 uint32_t start_code;
1882 if (mb_y < 0 || mb_y >= s->
end_mb_y)
1938 const uint8_t *buf,
int buf_size)
1949 if (width <= 0 || height <= 0)
1973 for (i = 0; i < 64; i++) {
1983 for (i = 0; i < 64; i++) {
2046 for (i = 0; i < 64; i++) {
2072 const uint8_t *p,
int buf_size)
2074 const uint8_t *buf_end = p + buf_size;
2077 if (buf_end - p >= 5 &&
2078 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2086 if (buf_end - p < 1)
2094 const uint8_t *buf,
int buf_size)
2099 int time_code_hours, time_code_minutes;
2100 int time_code_seconds, time_code_pictures;
2121 time_code_hours, time_code_minutes, time_code_seconds,
2122 time_code_pictures, s1->
closed_gop, broken_link);
2145 for (i = 0; i < buf_size; i++) {
2151 if ((buf[i] & 3) == 3)
2189 const uint8_t *buf,
int buf_size);
2193 void *
data,
int *data_size,
2196 const uint8_t *buf = avpkt->
data;
2197 int buf_size = avpkt->
size;
2201 av_dlog(avctx,
"fill_buffer\n");
2232 return decode_chunks(avctx, picture, data_size, buf, buf_size);
2237 const uint8_t *buf,
int buf_size)
2241 const uint8_t *buf_ptr = buf;
2242 const uint8_t *buf_end = buf + buf_size;
2243 int ret, input_size;
2248 uint32_t start_code = -1;
2250 if (start_code > 0x1ff) {
2272 input_size = buf_end - buf_ptr;
2275 av_log(avctx,
AV_LOG_DEBUG,
"%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
2279 switch (start_code) {
2281 if (last_code == 0) {
2325 if (last_code == 0) {
2357 if (last_code == 0) {
2434 if (threshold <= mb_y) {
2499 .
name =
"mpeg1video",
2514 .
name =
"mpeg2video",
2528 #if CONFIG_MPEG_XVMC_DECODER
2536 av_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2546 AVCodec ff_mpeg_xvmc_decoder = {
2547 .
name =
"mpegvideo_xvmc",
2551 .
init = mpeg_mc_decode_init,
2561 #if CONFIG_MPEG_VDPAU_DECODER
2562 AVCodec ff_mpeg_vdpau_decoder = {
2563 .
name =
"mpegvideo_vdpau",
2576 #if CONFIG_MPEG1_VDPAU_DECODER
2577 AVCodec ff_mpeg1_vdpau_decoder = {
2578 .
name =
"mpeg1video_vdpau",