Revision 0268a54a libavcodec/h264.c

View differences:

libavcodec/h264.c
7990 7990
//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
7991 7991
//    mb_addr= pc->mb_addr - 1;
7992 7992
    state= pc->state;
7993
    for(i=0; i<=buf_size; i++){
7994
        if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
7995
            tprintf("find_frame_end new startcode = %08x, frame_start_found = %d, pos = %d\n", state, pc->frame_start_found, i);
7996
            if(pc->frame_start_found){
7997
                // If there isn't one more byte in the buffer
7998
                // the test on first_mb_in_slice cannot be done yet
7999
                // do it at next call.
8000
                if (i >= buf_size) break;
8001
                if (buf[i] & 0x80) {
8002
                    // first_mb_in_slice is 0, probably the first nal of a new
8003
                    // slice
8004
                    tprintf("find_frame_end frame_end_found, state = %08x, pos = %d\n", state, i);
8005
                    pc->state=-1;
7993
    if(state>13)
7994
        state= 7;
7995

  
7996
    for(i=0; i<buf_size; i++){
7997
        if(state==7){
7998
            for(; i<buf_size; i++){
7999
                if(!buf[i]){
8000
                    state=2;
8001
                    break;
8002
                }
8003
            }
8004
        }else if(state<=2){
8005
            if(buf[i]==1)   state^= 5; //2->7, 1->4, 0->5
8006
            else if(buf[i]) state = 7;
8007
            else            state>>=1; //2->1, 1->0, 0->0
8008
        }else if(state<=5){
8009
            int v= buf[i] & 0x1F;
8010
            if(v==7 || v==8 || v==9){
8011
                if(pc->frame_start_found){
8012
                    i++;
8013
found:
8014
                    pc->state=7;
8006 8015
                    pc->frame_start_found= 0;
8007
                    return i-4;
8016
                    return i-(state&5);
8008 8017
                }
8018
            }else if(v==1 || v==2 || v==5){
8019
                if(pc->frame_start_found){
8020
                    state+=8;
8021
                    continue;
8022
                }else
8023
                    pc->frame_start_found = 1;
8009 8024
            }
8010
            pc->frame_start_found = 1;
8011
        }
8012
        if((state&0xFFFFFF1F) == 0x107 || (state&0xFFFFFF1F) == 0x108 || (state&0xFFFFFF1F) == 0x109){
8013
           if(pc->frame_start_found){
8014
                pc->state=-1;
8015
                pc->frame_start_found= 0;
8016
                return i-4;
8017
           }
8025
            state= 7;
8026
        }else{
8027
            if(buf[i] & 0x80)
8028
                goto found;
8029
            state= 7;
8018 8030
        }
8019
        if (i<buf_size)
8020
            state= (state<<8) | buf[i];
8021 8031
    }
8022

  
8023 8032
    pc->state= state;
8024 8033
    return END_NOT_FOUND;
8025 8034
}
......
8042 8051
        return buf_size;
8043 8052
    }
8044 8053

  
8054
    if(next<0){
8055
        find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state
8056
    }
8057

  
8045 8058
    *poutbuf = (uint8_t *)buf;
8046 8059
    *poutbuf_size = buf_size;
8047 8060
    return next;

Also available in: Unified diff