28 #define UNCHECKED_BITSTREAM_READER 1
48 #define MBINCR_VLC_BITS 9
49 #define MB_PAT_VLC_BITS 9
50 #define MB_PTYPE_VLC_BITS 6
51 #define MB_BTYPE_VLC_BITS 6
58 int code, sign, val,
shift;
72 val = (val - 1) << shift;
91 const int qscale = s->
qscale;
94 component = (n <= 3 ? 0 : n - 4 + 1);
101 block[0] = dc * quant_matrix[0];
113 }
else if (level != 0) {
116 level = (level * qscale * quant_matrix[j]) >> 4;
117 level = (level - 1) | 1;
127 }
else if (level == 0) {
134 level = (level * qscale * quant_matrix[j]) >> 4;
135 level = (level - 1) | 1;
138 level = (level * qscale * quant_matrix[j]) >> 4;
139 level = (level - 1) | 1;
166 const int qscale = s->
qscale;
174 level = (3 * qscale * quant_matrix[0]) >> 5;
175 level = (level - 1) | 1;
191 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
192 level = (level - 1) | 1;
202 }
else if (level == 0) {
209 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
210 level = (level - 1) | 1;
213 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
214 level = (level - 1) | 1;
245 const int qscale = s->
qscale;
253 level = (3 * qscale) >> 1;
254 level = (level - 1) | 1;
271 level = ((level * 2 + 1) * qscale) >> 1;
272 level = (level - 1) | 1;
282 }
else if (level == 0) {
289 level = ((level * 2 + 1) * qscale) >> 1;
290 level = (level - 1) | 1;
293 level = ((level * 2 + 1) * qscale) >> 1;
294 level = (level - 1) | 1;
317 const uint16_t *quant_matrix;
318 const int qscale = s->
qscale;
334 level= (3 * qscale * quant_matrix[0]) >> 5;
352 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
364 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
367 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
385 block[63] ^= (mismatch & 1);
397 int16_t *
block,
int n)
402 const int qscale = s->
qscale;
409 level = (3 * qscale) >> 1;
426 level = ((level * 2 + 1) * qscale) >> 1;
438 level = ((-level * 2 + 1) * qscale) >> 1;
441 level = ((level * 2 + 1) * qscale) >> 1;
464 const uint16_t *quant_matrix;
465 const int qscale = s->
qscale;
474 component = (n & 1) + 1;
484 mismatch = block[0] ^ 1;
500 }
else if (level != 0) {
503 level = (level * qscale * quant_matrix[j]) >> 4;
514 level = (-level * qscale * quant_matrix[j]) >> 4;
517 level = (level * qscale * quant_matrix[j]) >> 4;
530 block[63] ^= mismatch & 1;
547 const uint16_t *quant_matrix;
548 const int qscale = s->
qscale;
556 component = (n & 1) + 1;
579 }
else if (level != 0) {
582 level = (level * qscale * quant_matrix[j]) >> 4;
593 level = (-level * qscale * quant_matrix[j]) >> 4;
596 level = (level * qscale * quant_matrix[j]) >> 4;
611 #define INIT_2D_VLC_RL(rl, static_size)\
613 static RL_VLC_ELEM rl_vlc_table[static_size];\
614 INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
615 &rl.table_vlc[0][1], 4, 2,\
616 &rl.table_vlc[0][0], 4, 2, static_size);\
618 rl.rl_vlc[0] = rl_vlc_table;\
619 init_2d_vlc_rl(&rl);\
641 }
else if (code == rl->
n+1) {
755 int i, j, k, cbp, val, mb_type, motion_type;
781 if ((s->
mv[0][0][0] | s->
mv[0][0][1] | s->
mv[1][0][0] | s->
mv[1][0][1]) == 0)
860 for (i = 0; i < 6; i++) {
864 for (i = 0; i < mb_block_count; i++) {
870 for (i = 0; i < 6; i++) {
916 s->
mv_dir = (mb_type >> 13) & 3;
918 switch (motion_type) {
923 for (i = 0; i < 2; i++) {
932 s->
mv[i][0][0] <<= 1;
933 s->
mv[i][0][1] <<= 1;
940 for (i = 0; i < 2; i++) {
943 for (j = 0; j < 2; j++) {
945 for (k = 0; k < 2; k++) {
949 s->
mv[i][j][k] = val;
960 for (i = 0; i < 2; i++) {
962 for (j = 0; j < 2; j++) {
967 s->
mv[i][j][0] = val;
971 s->
last_mv[i][j][1] = val << 1;
972 s->
mv[i][j][1] = val;
980 for (i = 0; i < 2; i++) {
983 for (k = 0; k < 2; k++) {
988 s->
mv[i][0][k] = val;
1000 for (i = 0; i < 2; i++) {
1002 int dmx, dmy, mx, my,
m;
1011 s->
last_mv[i][0][1] >> my_shift);
1015 s->
last_mv[i][0][1] = my << my_shift;
1016 s->
last_mv[i][1][1] = my << my_shift;
1018 s->
mv[i][0][0] = mx;
1019 s->
mv[i][0][1] = my;
1020 s->
mv[i][1][0] = mx;
1021 s->
mv[i][1][1] = my;
1030 s->
mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
1031 s->
mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
1033 s->
mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
1034 s->
mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
1038 s->
mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
1039 s->
mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
1059 if (mb_block_count > 6) {
1060 cbp <<= mb_block_count - 6;
1079 for (i = 0; i < 6; i++) {
1088 cbp <<= 12-mb_block_count;
1090 for (i = 0; i < mb_block_count; i++) {
1091 if (cbp & (1 << 11)) {
1102 for (i = 0; i < 6; i++) {
1111 for (i = 0; i < 6; i++) {
1123 for (i = 0; i < 12; i++)
1141 for (i = 0; i < 64; i++)
1170 if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !
s1->context_initialized)
1174 if (err)
return err;
1188 uint16_t temp_matrix[64];
1191 memcpy(temp_matrix, matrix, 64 *
sizeof(uint16_t));
1193 for (i = 0; i < 64; i++) {
1194 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1199 #if CONFIG_MPEG_XVMC_DECODER
1203 #if CONFIG_MPEG1_VDPAU_HWACCEL
1211 #if CONFIG_MPEG_XVMC_DECODER
1215 #if CONFIG_MPEG2_VDPAU_HWACCEL
1218 #if CONFIG_MPEG2_DXVA2_HWACCEL
1221 #if CONFIG_MPEG2_VAAPI_HWACCEL
1343 s->avctx->sample_aspect_ratio =
1358 memcpy(old_permutation, s->dsp.idct_permutation, 64 *
sizeof(
uint8_t));
1368 s1->mpeg_enc_ctx_allocated = 1;
1374 const uint8_t *buf,
int buf_size)
1378 int ref, f_code, vbv_delay;
1421 int horiz_size_ext, vert_size_ext;
1431 s->
width |= (horiz_size_ext << 12);
1432 s->
height |= (vert_size_ext << 12);
1434 s->
bit_rate += (bit_rate_ext << 18) * 400;
1457 int color_description, w, h;
1461 if (color_description) {
1497 for (i = 0; i < nofco; i++) {
1515 for (i = 0; i < 64; i++) {
1522 if (intra && i == 0 && v != 8) {
1645 for (i = 0; i < 4; i++) {
1667 #define DECODE_SLICE_ERROR -1
1668 #define DECODE_SLICE_OK 0
1677 const uint8_t **buf,
int buf_size)
1736 const uint8_t *buf_end, *buf_start = *buf - 4;
1737 int start_code = -1;
1739 if (buf_end < *buf + buf_size)
1755 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",
1776 int motion_x, motion_y, dir, i;
1778 for (i = 0; i < 2; i++) {
1779 for (dir = 0; dir < 2; dir++) {
1781 motion_x = motion_y = 0;
1783 motion_x = s->
mv[dir][0][0];
1784 motion_y = s->
mv[dir][0][1];
1786 motion_x = s->
mv[dir][i][0];
1787 motion_y = s->
mv[dir][i][1];
1816 s->
mb_y += 1 << field_pic;
1824 if (left >= 32 && !is_d10) {
1857 }
else if (code == 35) {
1879 for (i = 0; i < 12; i++)
1888 s->
mv[0][0][0] = s->
mv[0][0][1] = 0;
1918 uint32_t start_code;
1923 av_dlog(c,
"ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1942 mb_y += (*buf&0xE0)<<2;
1946 if (mb_y < 0 || mb_y >= s->
end_mb_y)
2002 const uint8_t *buf,
int buf_size)
2035 for (i = 0; i < 64; i++) {
2045 for (i = 0; i < 64; i++) {
2105 for (i = 0; i < 64; i++) {
2137 const uint8_t *p,
int buf_size)
2140 const uint8_t *buf_end = p + buf_size;
2145 if(!memcmp(p+i,
"\0TMPGEXS\0", 9)){
2156 if (buf_end - p >= 5 &&
2157 p[0] ==
'D' && p[1] ==
'T' && p[2] ==
'G' && p[3] ==
'1') {
2165 if (buf_end - p < 1)
2173 const uint8_t *buf,
int buf_size)
2194 "GOP (%s) closed_gop=%d broken_link=%d\n",
2219 for (i = 0; i < buf_size; i++) {
2225 if ((buf[i] & 3) == 3)
2263 AVFrame *picture,
int *got_output,
2264 const uint8_t *buf,
int buf_size)
2269 const uint8_t *buf_end = buf + buf_size;
2270 int ret, input_size;
2272 int picture_start_code_seen = 0;
2276 uint32_t start_code = -1;
2278 if (start_code > 0x1ff) {
2302 input_size = buf_end - buf_ptr;
2305 av_log(avctx,
AV_LOG_DEBUG,
"%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
2309 switch (start_code) {
2311 if (last_code == 0) {
2329 picture_start_code_seen = 1;
2373 if (last_code == 0) {
2405 if (last_code == 0) {
2448 mb_y += (*buf_ptr&0xE0)<<2;
2512 if (threshold <= mb_y) {
2548 void *
data,
int *got_output,
2553 int buf_size = avpkt->
size;
2557 av_dlog(avctx,
"fill_buffer\n");
2598 ret =
decode_chunks(avctx, picture, got_output, buf, buf_size);
2599 if (ret<0 || *got_output)
2638 .
name =
"mpeg1video",
2655 .
name =
"mpeg2video",
2673 .
name =
"mpegvideo",
2686 #if CONFIG_MPEG_XVMC_DECODER
2694 av_dlog(avctx,
"mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
2704 AVCodec ff_mpeg_xvmc_decoder = {
2705 .
name =
"mpegvideo_xvmc",
2709 .
init = mpeg_mc_decode_init,
2720 #if CONFIG_MPEG_VDPAU_DECODER
2721 AVCodec ff_mpeg_vdpau_decoder = {
2722 .
name =
"mpegvideo_vdpau",
2736 #if CONFIG_MPEG1_VDPAU_DECODER
2737 AVCodec ff_mpeg1_vdpau_decoder = {
2738 .
name =
"mpeg1video_vdpau",