[FFmpeg-cvslog] mjpeg_parser: Rewrite to skip marker segments
Michael Niedermayer
git at videolan.org
Sun Oct 30 00:32:06 CEST 2011
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Oct 29 23:54:21 2011 +0200| [1af3571e05522df4e71a5b33de05bdb9e953a6c4] | committer: Michael Niedermayer
mjpeg_parser: Rewrite to skip marker segments
Based on code by Aaron Miller <amiller at atlasdigital.tv>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1af3571e05522df4e71a5b33de05bdb9e953a6c4
---
libavcodec/mjpeg_parser.c | 47 ++++++++++++++++++++++++++++++++++----------
1 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/libavcodec/mjpeg_parser.c b/libavcodec/mjpeg_parser.c
index 79c9d49..38abc45 100644
--- a/libavcodec/mjpeg_parser.c
+++ b/libavcodec/mjpeg_parser.c
@@ -30,6 +30,7 @@
typedef struct MJPEGParserContext{
ParseContext pc;
+ int size;
}MJPEGParserContext;
/**
@@ -39,20 +40,32 @@ typedef struct MJPEGParserContext{
static int find_frame_end(MJPEGParserContext *m, const uint8_t *buf, int buf_size){
ParseContext *pc= &m->pc;
int vop_found, i;
- uint16_t state;
+ uint32_t state;
vop_found= pc->frame_start_found;
state= pc->state;
i=0;
if(!vop_found){
- for(i=0; i<buf_size; i++){
+ for(i=0; i<buf_size;){
state= (state<<8) | buf[i];
- if(state == 0xFFD8){
- i++;
- vop_found=1;
- break;
+ if(state>=0xFFC00000 && state<=0xFFFEFFFF){
+ if(state>=0xFFD80000 && state<=0xFFD8FFFF){
+ i++;
+ vop_found=1;
+ break;
+ }else if(state<0xFFD00000 || state>0xFFD9FFFF){
+ m->size= (state&0xFFFF)-1;
+ }
}
+ if(m->size>0){
+ int size= FFMIN(buf_size-i, m->size);
+ i+=size;
+ m->size-=size;
+ state=0;
+ continue;
+ }else
+ i++;
}
}
@@ -60,13 +73,25 @@ static int find_frame_end(MJPEGParserContext *m, const uint8_t *buf, int buf_siz
/* EOF considered as end of frame */
if (buf_size == 0)
return 0;
- for(; i<buf_size; i++){
+ for(; i<buf_size;){
state= (state<<8) | buf[i];
- if(state == 0xFFD8){
- pc->frame_start_found=0;
- pc->state=0;
- return i-1;
+ if(state>=0xFFC00000 && state<=0xFFFEFFFF){
+ if(state>=0xFFD80000 && state<=0xFFD8FFFF){
+ pc->frame_start_found=0;
+ pc->state=0;
+ return i-3;
+ } else if(state<0xFFD00000 || state>0xFFD9FFFF){
+ m->size= (state&0xFFFF)-1;
+ }
}
+ if(m->size>0){
+ int size= FFMIN(buf_size-i, m->size);
+ i+=size;
+ m->size-=size;
+ state=0;
+ continue;
+ }else
+ i++;
}
}
pc->frame_start_found= vop_found;
More information about the ffmpeg-cvslog
mailing list