Revision 21da962c

View differences:

libavcodec/mpeg12.c
2182 2182
    int i;
2183 2183
    uint32_t state= pc->state;
2184 2184

  
2185
    i=0;
2186
    if(!pc->frame_start_found){
2187
        for(i=0; i<buf_size; i++){
2185
    /* EOF considered as end of frame */
2186
    if (buf_size == 0)
2187
        return 0;
2188

  
2189
/*
2190
 0  frame start         -> 1/4
2191
 1  first_SEQEXT        -> 0/2
2192
 2  first field start   -> 3/0
2193
 3  second_SEQEXT       -> 2/0
2194
 4  searching end
2195
*/
2196

  
2197
    for(i=0; i<buf_size; i++){
2198
        assert(pc->frame_start_found>=0 && pc->frame_start_found<=4);
2199
        if(pc->frame_start_found&1){
2200
            if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80)
2201
                pc->frame_start_found--;
2202
            else if(state == EXT_START_CODE+2){
2203
                if((buf[i]&3) == 3) pc->frame_start_found= 0;
2204
                else                pc->frame_start_found= (pc->frame_start_found+1)&3;
2205
            }
2206
            state++;
2207
        }else{
2188 2208
            i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
2189
            if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
2209
            if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
2190 2210
                i++;
2191
                pc->frame_start_found=1;
2192
                break;
2211
                pc->frame_start_found=4;
2193 2212
            }
2194 2213
            if(state == SEQ_END_CODE){
2195 2214
                pc->state=-1;
2196 2215
                return i+1;
2197 2216
            }
2198
        }
2199
    }
2200

  
2201
    if(pc->frame_start_found){
2202
        /* EOF considered as end of frame */
2203
        if (buf_size == 0)
2204
            return 0;
2205
        for(; i<buf_size; i++){
2206
            i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
2207
            if((state&0xFFFFFF00) == 0x100){
2217
            if(pc->frame_start_found==2 && state == SEQ_START_CODE)
2218
                pc->frame_start_found= 0;
2219
            if(pc->frame_start_found<4 && state == EXT_START_CODE)
2220
                pc->frame_start_found++;
2221
            if(pc->frame_start_found == 4 && (state&0xFFFFFF00) == 0x100){
2208 2222
                if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
2209 2223
                    pc->frame_start_found=0;
2210 2224
                    pc->state=-1;

Also available in: Unified diff