Commit 1af3571e authored by Michael Niedermayer's avatar Michael Niedermayer

mjpeg_parser: Rewrite to skip marker segments

Based on code by Aaron Miller <amiller@atlasdigital.tv>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 429b3cd6
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
typedef struct MJPEGParserContext{ typedef struct MJPEGParserContext{
ParseContext pc; ParseContext pc;
int size;
}MJPEGParserContext; }MJPEGParserContext;
/** /**
...@@ -39,20 +40,32 @@ typedef struct MJPEGParserContext{ ...@@ -39,20 +40,32 @@ typedef struct MJPEGParserContext{
static int find_frame_end(MJPEGParserContext *m, const uint8_t *buf, int buf_size){ static int find_frame_end(MJPEGParserContext *m, const uint8_t *buf, int buf_size){
ParseContext *pc= &m->pc; ParseContext *pc= &m->pc;
int vop_found, i; int vop_found, i;
uint16_t state; uint32_t state;
vop_found= pc->frame_start_found; vop_found= pc->frame_start_found;
state= pc->state; state= pc->state;
i=0; i=0;
if(!vop_found){ if(!vop_found){
for(i=0; i<buf_size; i++){ for(i=0; i<buf_size;){
state= (state<<8) | buf[i]; state= (state<<8) | buf[i];
if(state == 0xFFD8){ if(state>=0xFFC00000 && state<=0xFFFEFFFF){
i++; if(state>=0xFFD80000 && state<=0xFFD8FFFF){
vop_found=1; i++;
break; 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 ...@@ -60,13 +73,25 @@ static int find_frame_end(MJPEGParserContext *m, const uint8_t *buf, int buf_siz
/* EOF considered as end of frame */ /* EOF considered as end of frame */
if (buf_size == 0) if (buf_size == 0)
return 0; return 0;
for(; i<buf_size; i++){ for(; i<buf_size;){
state= (state<<8) | buf[i]; state= (state<<8) | buf[i];
if(state == 0xFFD8){ if(state>=0xFFC00000 && state<=0xFFFEFFFF){
pc->frame_start_found=0; if(state>=0xFFD80000 && state<=0xFFD8FFFF){
pc->state=0; pc->frame_start_found=0;
return i-1; 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; pc->frame_start_found= vop_found;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment