Mercurial > libavcodec.hg
comparison mpeg12.c @ 267:e10840e4f773 libavcodec
- Bug fix MPEG-2 decoder to handle "repeat_first_field" (Telecine)
- Hack in MPEG-2 demux to cope with buggy VOBs.
author | pulento |
---|---|
date | Sat, 16 Mar 2002 02:41:00 +0000 |
parents | 4bb6289eff93 |
children | 7ebb3f9aaf3b |
comparison
equal
deleted
inserted
replaced
266:252444e5259b | 267:e10840e4f773 |
---|---|
1117 int start_code; /* current start code */ | 1117 int start_code; /* current start code */ |
1118 UINT8 buffer[PICTURE_BUFFER_SIZE]; | 1118 UINT8 buffer[PICTURE_BUFFER_SIZE]; |
1119 UINT8 *buf_ptr; | 1119 UINT8 *buf_ptr; |
1120 int buffer_size; | 1120 int buffer_size; |
1121 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ | 1121 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ |
1122 int repeat_field; /* true if we must repeat the field */ | |
1122 } Mpeg1Context; | 1123 } Mpeg1Context; |
1123 | 1124 |
1124 static int mpeg_decode_init(AVCodecContext *avctx) | 1125 static int mpeg_decode_init(AVCodecContext *avctx) |
1125 { | 1126 { |
1126 Mpeg1Context *s = avctx->priv_data; | 1127 Mpeg1Context *s = avctx->priv_data; |
1129 s->mpeg_enc_ctx_allocated = 0; | 1130 s->mpeg_enc_ctx_allocated = 0; |
1130 s->buffer_size = PICTURE_BUFFER_SIZE; | 1131 s->buffer_size = PICTURE_BUFFER_SIZE; |
1131 s->start_code = -1; | 1132 s->start_code = -1; |
1132 s->buf_ptr = s->buffer; | 1133 s->buf_ptr = s->buffer; |
1133 s->mpeg_enc_ctx.picture_number = 0; | 1134 s->mpeg_enc_ctx.picture_number = 0; |
1135 s->repeat_field = 0; | |
1134 return 0; | 1136 return 0; |
1135 } | 1137 } |
1136 | 1138 |
1137 /* return the 8 bit start code value and update the search | 1139 /* return the 8 bit start code value and update the search |
1138 state. Return -1 if no start code found */ | 1140 state. Return -1 if no start code found */ |
1201 int horiz_size_ext, vert_size_ext; | 1203 int horiz_size_ext, vert_size_ext; |
1202 int bit_rate_ext, vbv_buf_ext, low_delay; | 1204 int bit_rate_ext, vbv_buf_ext, low_delay; |
1203 int frame_rate_ext_n, frame_rate_ext_d; | 1205 int frame_rate_ext_n, frame_rate_ext_d; |
1204 | 1206 |
1205 skip_bits(&s->gb, 8); /* profil and level */ | 1207 skip_bits(&s->gb, 8); /* profil and level */ |
1206 skip_bits(&s->gb, 1); /* progressive_sequence */ | 1208 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */ |
1207 skip_bits(&s->gb, 2); /* chroma_format */ | 1209 skip_bits(&s->gb, 2); /* chroma_format */ |
1208 horiz_size_ext = get_bits(&s->gb, 2); | 1210 horiz_size_ext = get_bits(&s->gb, 2); |
1209 vert_size_ext = get_bits(&s->gb, 2); | 1211 vert_size_ext = get_bits(&s->gb, 2); |
1210 s->width |= (horiz_size_ext << 12); | 1212 s->width |= (horiz_size_ext << 12); |
1211 s->height |= (vert_size_ext << 12); | 1213 s->height |= (vert_size_ext << 12); |
1277 s->alternate_scan = get_bits1(&s->gb); | 1279 s->alternate_scan = get_bits1(&s->gb); |
1278 s->repeat_first_field = get_bits1(&s->gb); | 1280 s->repeat_first_field = get_bits1(&s->gb); |
1279 s->chroma_420_type = get_bits1(&s->gb); | 1281 s->chroma_420_type = get_bits1(&s->gb); |
1280 s->progressive_frame = get_bits1(&s->gb); | 1282 s->progressive_frame = get_bits1(&s->gb); |
1281 /* composite display not parsed */ | 1283 /* composite display not parsed */ |
1282 dprintf("intra_dc_precion=%d\n", s->intra_dc_precision); | 1284 dprintf("intra_dc_precision=%d\n", s->intra_dc_precision); |
1283 dprintf("picture_structure=%d\n", s->picture_structure); | 1285 dprintf("picture_structure=%d\n", s->picture_structure); |
1284 dprintf("conceal=%d\n", s->concealment_motion_vectors); | 1286 dprintf("conceal=%d\n", s->concealment_motion_vectors); |
1285 dprintf("intra_vlc_format=%d\n", s->intra_vlc_format); | 1287 dprintf("intra_vlc_format=%d\n", s->intra_vlc_format); |
1286 dprintf("alternate_scan=%d\n", s->alternate_scan); | 1288 dprintf("alternate_scan=%d\n", s->alternate_scan); |
1287 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); | 1289 dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct); |
1290 dprintf("progressive_frame=%d\n", s->progressive_frame); | |
1288 } | 1291 } |
1289 | 1292 |
1290 static void mpeg_decode_extension(AVCodecContext *avctx, | 1293 static void mpeg_decode_extension(AVCodecContext *avctx, |
1291 UINT8 *buf, int buf_size) | 1294 UINT8 *buf, int buf_size) |
1292 { | 1295 { |
1432 s->has_b_frames = 1; | 1435 s->has_b_frames = 1; |
1433 s->avctx = avctx; | 1436 s->avctx = avctx; |
1434 avctx->width = width; | 1437 avctx->width = width; |
1435 avctx->height = height; | 1438 avctx->height = height; |
1436 avctx->frame_rate = frame_rate_tab[s->frame_rate_index]; | 1439 avctx->frame_rate = frame_rate_tab[s->frame_rate_index]; |
1440 s->frame_rate = avctx->frame_rate; | |
1437 avctx->bit_rate = s->bit_rate; | 1441 avctx->bit_rate = s->bit_rate; |
1438 | 1442 |
1439 if (MPV_common_init(s) < 0) | 1443 if (MPV_common_init(s) < 0) |
1440 return -1; | 1444 return -1; |
1441 mpeg1_init_vlc(s); | 1445 mpeg1_init_vlc(s); |
1503 { | 1507 { |
1504 Mpeg1Context *s = avctx->priv_data; | 1508 Mpeg1Context *s = avctx->priv_data; |
1505 UINT8 *buf_end, *buf_ptr, *buf_start; | 1509 UINT8 *buf_end, *buf_ptr, *buf_start; |
1506 int len, start_code_found, ret, code, start_code, input_size; | 1510 int len, start_code_found, ret, code, start_code, input_size; |
1507 AVPicture *picture = data; | 1511 AVPicture *picture = data; |
1508 | 1512 MpegEncContext *s2 = &s->mpeg_enc_ctx; |
1513 | |
1509 dprintf("fill_buffer\n"); | 1514 dprintf("fill_buffer\n"); |
1510 | 1515 |
1511 *data_size = 0; | 1516 *data_size = 0; |
1517 | |
1512 /* special case for last picture */ | 1518 /* special case for last picture */ |
1513 if (buf_size == 0) { | 1519 if (buf_size == 0) { |
1514 MpegEncContext *s2 = &s->mpeg_enc_ctx; | |
1515 if (s2->picture_number > 0) { | 1520 if (s2->picture_number > 0) { |
1516 picture->data[0] = s2->next_picture[0]; | 1521 picture->data[0] = s2->next_picture[0]; |
1517 picture->data[1] = s2->next_picture[1]; | 1522 picture->data[1] = s2->next_picture[1]; |
1518 picture->data[2] = s2->next_picture[2]; | 1523 picture->data[2] = s2->next_picture[2]; |
1519 picture->linesize[0] = s2->linesize; | 1524 picture->linesize[0] = s2->linesize; |
1524 return 0; | 1529 return 0; |
1525 } | 1530 } |
1526 | 1531 |
1527 buf_ptr = buf; | 1532 buf_ptr = buf; |
1528 buf_end = buf + buf_size; | 1533 buf_end = buf + buf_size; |
1534 | |
1535 if (s->repeat_field % 2 == 1) { | |
1536 s->repeat_field++; | |
1537 //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number, | |
1538 // s2->picture_number, s->repeat_field); | |
1539 *data_size = 1; | |
1540 goto the_end; | |
1541 } | |
1542 | |
1529 while (buf_ptr < buf_end) { | 1543 while (buf_ptr < buf_end) { |
1530 buf_start = buf_ptr; | 1544 buf_start = buf_ptr; |
1531 /* find start next code */ | 1545 /* find start next code */ |
1532 code = find_start_code(&buf_ptr, buf_end, &s->header_state); | 1546 code = find_start_code(&buf_ptr, buf_end, &s->header_state); |
1533 if (code >= 0) { | 1547 if (code >= 0) { |
1572 start_code <= SLICE_MAX_START_CODE) { | 1586 start_code <= SLICE_MAX_START_CODE) { |
1573 ret = mpeg_decode_slice(avctx, picture, | 1587 ret = mpeg_decode_slice(avctx, picture, |
1574 start_code, s->buffer, input_size); | 1588 start_code, s->buffer, input_size); |
1575 if (ret == 1) { | 1589 if (ret == 1) { |
1576 /* got a picture: exit */ | 1590 /* got a picture: exit */ |
1591 /* first check if we must repeat the frame */ | |
1592 if (s2->progressive_frame && s2->repeat_first_field) { | |
1593 //fprintf(stderr,"\nRepeat this frame: %d! pict: %d",avctx->frame_number,s2->picture_number); | |
1594 s2->repeat_first_field = 0; | |
1595 s2->progressive_frame = 0; | |
1596 if (++s->repeat_field > 2) | |
1597 s->repeat_field = 0; | |
1598 } | |
1577 *data_size = sizeof(AVPicture); | 1599 *data_size = sizeof(AVPicture); |
1578 goto the_end; | 1600 goto the_end; |
1579 } | 1601 } |
1580 } | 1602 } |
1581 break; | 1603 break; |