00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "parser.h"
00029 #include "vc1.h"
00030
00035 static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf,
00036 int buf_size) {
00037 int pic_found, i;
00038 uint32_t state;
00039
00040 pic_found= pc->frame_start_found;
00041 state= pc->state;
00042
00043 i=0;
00044 if(!pic_found){
00045 for(i=0; i<buf_size; i++){
00046 state= (state<<8) | buf[i];
00047 if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){
00048 i++;
00049 pic_found=1;
00050 break;
00051 }
00052 }
00053 }
00054
00055 if(pic_found){
00056
00057 if (buf_size == 0)
00058 return 0;
00059 for(; i<buf_size; i++){
00060 state= (state<<8) | buf[i];
00061 if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){
00062 pc->frame_start_found=0;
00063 pc->state=-1;
00064 return i-3;
00065 }
00066 }
00067 }
00068 pc->frame_start_found= pic_found;
00069 pc->state= state;
00070 return END_NOT_FOUND;
00071 }
00072
00073 static int vc1_parse(AVCodecParserContext *s,
00074 AVCodecContext *avctx,
00075 const uint8_t **poutbuf, int *poutbuf_size,
00076 const uint8_t *buf, int buf_size)
00077 {
00078 ParseContext *pc = s->priv_data;
00079 int next;
00080
00081 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
00082 next= buf_size;
00083 }else{
00084 next= vc1_find_frame_end(pc, buf, buf_size);
00085
00086 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
00087 *poutbuf = NULL;
00088 *poutbuf_size = 0;
00089 return buf_size;
00090 }
00091 }
00092 *poutbuf = buf;
00093 *poutbuf_size = buf_size;
00094 return next;
00095 }
00096
00097 static int vc1_split(AVCodecContext *avctx,
00098 const uint8_t *buf, int buf_size)
00099 {
00100 int i;
00101 uint32_t state= -1;
00102 int charged=0;
00103
00104 for(i=0; i<buf_size; i++){
00105 state= (state<<8) | buf[i];
00106 if(IS_MARKER(state)){
00107 if(state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT){
00108 charged=1;
00109 }else if(charged){
00110 return i-3;
00111 }
00112 }
00113 }
00114 return 0;
00115 }
00116
00117 AVCodecParser vc1_parser = {
00118 { CODEC_ID_VC1 },
00119 sizeof(ParseContext1),
00120 NULL,
00121 vc1_parse,
00122 ff_parse1_close,
00123 vc1_split,
00124 };