Revision 8c7aaf5b

View differences:

libavcodec/h261.c
130 130

  
131 131
    h261_decode_init_vlc(h);
132 132

  
133
    h->bits_left = 0;
134
    h->last_bits = 0;
135 133
    h->gob_start_code_skipped = 0;
136 134
    
137 135
    return 0;
......
486 484
int h261_decode_picture_header(H261Context *h){
487 485
    MpegEncContext * const s = &h->s;
488 486
    int format, i;
489
    uint32_t startcode;
490
    align_get_bits(&s->gb);
491

  
492
    startcode = (h->last_bits << (12 - (8-h->bits_left))) | get_bits(&s->gb, 20-8 - (8- h->bits_left));
487
    uint32_t startcode= 0;
493 488

  
494 489
    for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){
495 490
        startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
......
646 641
 * returns the number of bytes consumed for building the current frame
647 642
 */
648 643
static int get_consumed_bytes(MpegEncContext *s, int buf_size){
649
    int pos= (get_bits_count(&s->gb)+7)>>3;
650

  
651 644
    if(s->flags&CODEC_FLAG_TRUNCATED){
645
        int pos= (get_bits_count(&s->gb)+7)>>3;
652 646
        pos -= s->parse_context.last_index;
653 647
        if(pos<0) pos=0;// padding is not really read so this might be -1
654 648
        return pos;
655 649
    }else{
650
        int pos= get_bits_count(&s->gb)>>3;
656 651
        if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
657 652
        if(pos+10>buf_size) pos=buf_size; // oops ;)
658 653

  
......
678 673

  
679 674
    /* no supplementary picture */
680 675
    if (buf_size == 0) {
681

  
682 676
        return 0;
683 677
    }
684 678

  
......
750 744
    }
751 745
    MPV_frame_end(s);
752 746

  
753
    // h261 doesn't have byte aligned codes
754
    // store the bits of the next frame that are left in the last byte
755
    // in the H261Context and remember the number of stored bits
756
    {
757
        int bitsleft;
758
        int current_pos= get_bits_count(&s->gb)>>3;
759
        bitsleft =  (current_pos<<3) - get_bits_count(&s->gb);
760
        h->bits_left = - bitsleft;
761
        if(bitsleft > 0)
762
            h->last_bits= get_bits(&s->gb, 8 - h->bits_left);
763
        else
764
            h->last_bits = 0;
765
    }
766

  
767 747
assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
768 748
assert(s->current_picture.pict_type == s->pict_type);
769 749
    *pict= *(AVFrame*)&s->current_picture;

Also available in: Unified diff