Revision ce5b7c5e libavcodec/mpeg12.c

View differences:

libavcodec/mpeg12.c
674 674
{
675 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 677
    dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
711 678

  
712 679
    if (--s->mb_incr != 0) {
......
1585 1552
    s->last_dc[1] = s->last_dc[0];
1586 1553
    s->last_dc[2] = s->last_dc[0];
1587 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 1555
    /* start frame decoding */
1592 1556
    if (s->first_slice) {
1593 1557
        s->first_slice = 0;
......
1602 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 1587
    for(;;) {
1606 1588
        clear_blocks(s->block[0]);
1607 1589
        emms_c();
1590
        
1608 1591
        ret = mpeg_decode_mb(s, s->block);
1609 1592
        dprintf("ret=%d\n", ret);
1610 1593
        if (ret < 0)
1611 1594
            return -1;
1612
        if (ret == 1)
1613
            break;
1614 1595
    
1615
        if(s->mb_x==0)
1596
        MPV_decode_mb(s, s->block);
1597

  
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 1623
            PRINT_QP("%s", "\n");
1624
        }
1617 1625
        PRINT_QP("%2d", s->qscale);
1618
        
1619
        MPV_decode_mb(s, s->block);
1626

  
1627
        /* skip mb handling */
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
        }
1620 1650
    }
1651
eos: //end of slice
1652
    
1621 1653
    emms_c();
1622 1654

  
1623 1655
    /* end of slice reached */
1624
    if (s->mb_x == (s->mb_width - 1) &&
1625
        s->mb_y == (s->mb_height - 1)) {
1656
    if (/*s->mb_x == 0 &&*/
1657
        s->mb_y == s->mb_height) {
1626 1658
        /* end of image */
1627 1659
        UINT8 **picture;
1628 1660

  
......
1921 1953
    NULL,
1922 1954
    mpeg_decode_end,
1923 1955
    mpeg_decode_frame,
1924
    CODEC_CAP_DR1,
1956
    CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
1925 1957
};

Also available in: Unified diff