Mercurial > libavcodec.hg
comparison mpeg12.c @ 716:2ec5bd9f7116 libavcodec
sliced mode for mpeg1/2
author | michaelni |
---|---|
date | Wed, 02 Oct 2002 16:36:43 +0000 |
parents | 8b3ccabfce4a |
children | 6cba3b6196f0 |
comparison
equal
deleted
inserted
replaced
715:8b3ccabfce4a | 716:2ec5bd9f7116 |
---|---|
672 static int mpeg_decode_mb(MpegEncContext *s, | 672 static int mpeg_decode_mb(MpegEncContext *s, |
673 DCTELEM block[6][64]) | 673 DCTELEM block[6][64]) |
674 { | 674 { |
675 int i, j, k, cbp, val, code, mb_type, motion_type; | 675 int i, j, k, cbp, val, code, mb_type, motion_type; |
676 | 676 |
677 /* skip mb handling */ | |
678 if (s->mb_incr == 0) { | |
679 /* read again increment */ | |
680 s->mb_incr = 1; | |
681 for(;;) { | |
682 code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | |
683 if (code < 0) | |
684 return 1; /* error = end of slice */ | |
685 if (code >= 33) { | |
686 if (code == 33) { | |
687 s->mb_incr += 33; | |
688 } | |
689 /* otherwise, stuffing, nothing to do */ | |
690 } else { | |
691 s->mb_incr += code; | |
692 break; | |
693 } | |
694 } | |
695 } | |
696 if(s->mb_x==-1 /* first MB in a slice */ && s->mb_incr>1){ | |
697 s->mb_x+= (s->mb_incr - 1) % s->mb_width; | |
698 s->mb_y+= (s->mb_incr - 1) / s->mb_width; | |
699 s->mb_incr= 1; | |
700 } | |
701 | |
702 if (++s->mb_x >= s->mb_width) { | |
703 s->mb_x = 0; | |
704 if (s->mb_y >= (s->mb_height - 1)){ | |
705 fprintf(stderr, "slice too long\n"); | |
706 return -1; | |
707 } | |
708 s->mb_y++; | |
709 } | |
710 dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); | 677 dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); |
711 | 678 |
712 if (--s->mb_incr != 0) { | 679 if (--s->mb_incr != 0) { |
713 /* skip mb */ | 680 /* skip mb */ |
714 s->mb_intra = 0; | 681 s->mb_intra = 0; |
1583 } | 1550 } |
1584 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); | 1551 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); |
1585 s->last_dc[1] = s->last_dc[0]; | 1552 s->last_dc[1] = s->last_dc[0]; |
1586 s->last_dc[2] = s->last_dc[0]; | 1553 s->last_dc[2] = s->last_dc[0]; |
1587 memset(s->last_mv, 0, sizeof(s->last_mv)); | 1554 memset(s->last_mv, 0, sizeof(s->last_mv)); |
1588 s->mb_x = -1; | |
1589 s->mb_y = start_code; | |
1590 s->mb_incr = 0; | |
1591 /* start frame decoding */ | 1555 /* start frame decoding */ |
1592 if (s->first_slice) { | 1556 if (s->first_slice) { |
1593 s->first_slice = 0; | 1557 s->first_slice = 0; |
1594 MPV_frame_start(s, avctx); | 1558 MPV_frame_start(s, avctx); |
1595 } | 1559 } |
1600 /* extra slice info */ | 1564 /* extra slice info */ |
1601 while (get_bits1(&s->gb) != 0) { | 1565 while (get_bits1(&s->gb) != 0) { |
1602 skip_bits(&s->gb, 8); | 1566 skip_bits(&s->gb, 8); |
1603 } | 1567 } |
1604 | 1568 |
1569 s->mb_x=0; | |
1570 for(;;) { | |
1571 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | |
1572 if (code < 0) | |
1573 return -1; /* error = end of slice, but empty slice is bad or?*/ | |
1574 if (code >= 33) { | |
1575 if (code == 33) { | |
1576 s->mb_x += 33; | |
1577 } | |
1578 /* otherwise, stuffing, nothing to do */ | |
1579 } else { | |
1580 s->mb_x += code; | |
1581 break; | |
1582 } | |
1583 } | |
1584 s->mb_y = start_code; | |
1585 s->mb_incr= 1; | |
1586 | |
1605 for(;;) { | 1587 for(;;) { |
1606 clear_blocks(s->block[0]); | 1588 clear_blocks(s->block[0]); |
1607 emms_c(); | 1589 emms_c(); |
1590 | |
1608 ret = mpeg_decode_mb(s, s->block); | 1591 ret = mpeg_decode_mb(s, s->block); |
1609 dprintf("ret=%d\n", ret); | 1592 dprintf("ret=%d\n", ret); |
1610 if (ret < 0) | 1593 if (ret < 0) |
1611 return -1; | 1594 return -1; |
1612 if (ret == 1) | 1595 |
1613 break; | 1596 MPV_decode_mb(s, s->block); |
1614 | 1597 |
1615 if(s->mb_x==0) | 1598 if (++s->mb_x >= s->mb_width) { |
1599 if ( avctx->draw_horiz_band | |
1600 && (s->num_available_buffers>=1 || (!s->has_b_frames)) ) { | |
1601 UINT8 *src_ptr[3]; | |
1602 int y, h, offset; | |
1603 y = s->mb_y * 16; | |
1604 h = s->height - y; | |
1605 if (h > 16) | |
1606 h = 16; | |
1607 offset = y * s->linesize; | |
1608 if(s->pict_type==B_TYPE || (!s->has_b_frames)){ | |
1609 src_ptr[0] = s->current_picture[0] + offset; | |
1610 src_ptr[1] = s->current_picture[1] + (offset >> 2); | |
1611 src_ptr[2] = s->current_picture[2] + (offset >> 2); | |
1612 } else { | |
1613 src_ptr[0] = s->last_picture[0] + offset; | |
1614 src_ptr[1] = s->last_picture[1] + (offset >> 2); | |
1615 src_ptr[2] = s->last_picture[2] + (offset >> 2); | |
1616 } | |
1617 avctx->draw_horiz_band(avctx, src_ptr, s->linesize, | |
1618 y, s->width, h); | |
1619 } | |
1620 | |
1621 s->mb_x = 0; | |
1622 s->mb_y++; | |
1616 PRINT_QP("%s", "\n"); | 1623 PRINT_QP("%s", "\n"); |
1624 } | |
1617 PRINT_QP("%2d", s->qscale); | 1625 PRINT_QP("%2d", s->qscale); |
1618 | 1626 |
1619 MPV_decode_mb(s, s->block); | 1627 /* skip mb handling */ |
1620 } | 1628 if (s->mb_incr == 0) { |
1629 /* read again increment */ | |
1630 s->mb_incr = 1; | |
1631 for(;;) { | |
1632 int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); | |
1633 if (code < 0) | |
1634 goto eos; /* error = end of slice */ | |
1635 if (code >= 33) { | |
1636 if (code == 33) { | |
1637 s->mb_incr += 33; | |
1638 } | |
1639 /* otherwise, stuffing, nothing to do */ | |
1640 } else { | |
1641 s->mb_incr += code; | |
1642 break; | |
1643 } | |
1644 } | |
1645 } | |
1646 if(s->mb_y >= s->mb_height){ | |
1647 fprintf(stderr, "slice too long\n"); | |
1648 return -1; | |
1649 } | |
1650 } | |
1651 eos: //end of slice | |
1652 | |
1621 emms_c(); | 1653 emms_c(); |
1622 | 1654 |
1623 /* end of slice reached */ | 1655 /* end of slice reached */ |
1624 if (s->mb_x == (s->mb_width - 1) && | 1656 if (/*s->mb_x == 0 &&*/ |
1625 s->mb_y == (s->mb_height - 1)) { | 1657 s->mb_y == s->mb_height) { |
1626 /* end of image */ | 1658 /* end of image */ |
1627 UINT8 **picture; | 1659 UINT8 **picture; |
1628 | 1660 |
1629 MPV_frame_end(s); | 1661 MPV_frame_end(s); |
1630 | 1662 |
1919 sizeof(Mpeg1Context), | 1951 sizeof(Mpeg1Context), |
1920 mpeg_decode_init, | 1952 mpeg_decode_init, |
1921 NULL, | 1953 NULL, |
1922 mpeg_decode_end, | 1954 mpeg_decode_end, |
1923 mpeg_decode_frame, | 1955 mpeg_decode_frame, |
1924 CODEC_CAP_DR1, | 1956 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, |
1925 }; | 1957 }; |