aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2003-12-15 14:40:37 +0000
committerFabrice Bellard <fabrice@bellard.org>2003-12-15 14:40:37 +0000
commit6e45e928562810f40811e30b1dc0a485cb8257ef (patch)
tree31c6c51808defbe0b067cddaaa2cd5eb87062486
parent5d43635e475188e118b4417d8ea3ed7d8e466d49 (diff)
downloadffmpeg-6e45e928562810f40811e30b1dc0a485cb8257ef.tar.gz
added End Of File handling to return last picture for MPEG1/2/4
Originally committed as revision 2614 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/parser.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 3c9cc7e9d7..211e72e426 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -63,12 +63,22 @@ AVCodecParserContext *av_parser_init(int codec_id)
return s;
}
+/* NOTE: buf_size == 0 is used to signal EOF so that the last frame
+ can be returned if necessary */
int av_parser_parse(AVCodecParserContext *s,
AVCodecContext *avctx,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
int index;
+ uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
+
+ if (buf_size == 0) {
+ /* padding is always necessary even if EOF, so we add it here */
+ memset(dummy_buf, 0, sizeof(dummy_buf));
+ buf = dummy_buf;
+ }
+
/* WARNING: the returned index can be negative */
index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size);
/* update the file pointer */
@@ -201,6 +211,9 @@ static int mpeg1_find_frame_end(ParseContext1 *pc, const uint8_t *buf, int buf_s
}
if(pc->frame_start_found){
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
for(; i<buf_size; i++){
state= (state<<8) | buf[i];
if((state&0xFFFFFF00) == 0x100){
@@ -418,14 +431,17 @@ static int mpeg4_find_frame_end(ParseContext1 *pc,
}
if(vop_found){
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF00) == 0x100){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
+ /* EOF considered as end of frame */
+ if (buf_size == 0)
+ return 0;
+ for(; i<buf_size; i++){
+ state= (state<<8) | buf[i];
+ if((state&0xFFFFFF00) == 0x100){
+ pc->frame_start_found=0;
+ pc->state=-1;
+ return i-3;
+ }
}
- }
}
pc->frame_start_found= vop_found;
pc->state= state;