Mercurial > libavcodec.hg
comparison parser.c @ 1694:13169235c306 libavcodec
added End Of File handling to return last picture for MPEG1/2/4
| author | bellard |
|---|---|
| date | Mon, 15 Dec 2003 14:40:37 +0000 |
| parents | 27a272442d6b |
| children | f5af91b8be17 |
comparison
equal
deleted
inserted
replaced
| 1693:61cebcb5a997 | 1694:13169235c306 |
|---|---|
| 61 } | 61 } |
| 62 } | 62 } |
| 63 return s; | 63 return s; |
| 64 } | 64 } |
| 65 | 65 |
| 66 /* NOTE: buf_size == 0 is used to signal EOF so that the last frame | |
| 67 can be returned if necessary */ | |
| 66 int av_parser_parse(AVCodecParserContext *s, | 68 int av_parser_parse(AVCodecParserContext *s, |
| 67 AVCodecContext *avctx, | 69 AVCodecContext *avctx, |
| 68 uint8_t **poutbuf, int *poutbuf_size, | 70 uint8_t **poutbuf, int *poutbuf_size, |
| 69 const uint8_t *buf, int buf_size) | 71 const uint8_t *buf, int buf_size) |
| 70 { | 72 { |
| 71 int index; | 73 int index; |
| 74 uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; | |
| 75 | |
| 76 if (buf_size == 0) { | |
| 77 /* padding is always necessary even if EOF, so we add it here */ | |
| 78 memset(dummy_buf, 0, sizeof(dummy_buf)); | |
| 79 buf = dummy_buf; | |
| 80 } | |
| 81 | |
| 72 /* WARNING: the returned index can be negative */ | 82 /* WARNING: the returned index can be negative */ |
| 73 index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); | 83 index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); |
| 74 /* update the file pointer */ | 84 /* update the file pointer */ |
| 75 if (*poutbuf_size) { | 85 if (*poutbuf_size) { |
| 76 s->frame_offset = s->last_frame_offset; | 86 s->frame_offset = s->last_frame_offset; |
| 199 } | 209 } |
| 200 } | 210 } |
| 201 } | 211 } |
| 202 | 212 |
| 203 if(pc->frame_start_found){ | 213 if(pc->frame_start_found){ |
| 214 /* EOF considered as end of frame */ | |
| 215 if (buf_size == 0) | |
| 216 return 0; | |
| 204 for(; i<buf_size; i++){ | 217 for(; i<buf_size; i++){ |
| 205 state= (state<<8) | buf[i]; | 218 state= (state<<8) | buf[i]; |
| 206 if((state&0xFFFFFF00) == 0x100){ | 219 if((state&0xFFFFFF00) == 0x100){ |
| 207 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ | 220 if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ |
| 208 pc->frame_start_found=0; | 221 pc->frame_start_found=0; |
| 416 } | 429 } |
| 417 } | 430 } |
| 418 } | 431 } |
| 419 | 432 |
| 420 if(vop_found){ | 433 if(vop_found){ |
| 421 for(; i<buf_size; i++){ | 434 /* EOF considered as end of frame */ |
| 422 state= (state<<8) | buf[i]; | 435 if (buf_size == 0) |
| 423 if((state&0xFFFFFF00) == 0x100){ | 436 return 0; |
| 424 pc->frame_start_found=0; | 437 for(; i<buf_size; i++){ |
| 425 pc->state=-1; | 438 state= (state<<8) | buf[i]; |
| 426 return i-3; | 439 if((state&0xFFFFFF00) == 0x100){ |
| 427 } | 440 pc->frame_start_found=0; |
| 428 } | 441 pc->state=-1; |
| 442 return i-3; | |
| 443 } | |
| 444 } | |
| 429 } | 445 } |
| 430 pc->frame_start_found= vop_found; | 446 pc->frame_start_found= vop_found; |
| 431 pc->state= state; | 447 pc->state= state; |
| 432 return END_NOT_FOUND; | 448 return END_NOT_FOUND; |
| 433 } | 449 } |
