00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "parser.h"
00023 #include "pnm.h"
00024
00025
00026 static int pnm_parse(AVCodecParserContext *s,
00027 AVCodecContext *avctx,
00028 const uint8_t **poutbuf, int *poutbuf_size,
00029 const uint8_t *buf, int buf_size)
00030 {
00031 ParseContext *pc = s->priv_data;
00032 PNMContext pnmctx;
00033 int next;
00034
00035 for(; pc->overread>0; pc->overread--){
00036 pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
00037 }
00038 retry:
00039 if(pc->index){
00040 pnmctx.bytestream_start=
00041 pnmctx.bytestream= pc->buffer;
00042 pnmctx.bytestream_end= pc->buffer + pc->index;
00043 }else{
00044 pnmctx.bytestream_start=
00045 pnmctx.bytestream= (uint8_t *) buf;
00046 pnmctx.bytestream_end= (uint8_t *) buf + buf_size;
00047 }
00048 if(ff_pnm_decode_header(avctx, &pnmctx) < 0){
00049 if(pnmctx.bytestream < pnmctx.bytestream_end){
00050 if(pc->index){
00051 pc->index=0;
00052 }else{
00053 buf++;
00054 buf_size--;
00055 }
00056 goto retry;
00057 }
00058 #if 0
00059 if(pc->index && pc->index*2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index){
00060 memcpy(pc->buffer + pc->index, buf, pc->index);
00061 pc->index += pc->index;
00062 buf += pc->index;
00063 buf_size -= pc->index;
00064 goto retry;
00065 }
00066 #endif
00067 next= END_NOT_FOUND;
00068 }else{
00069 next= pnmctx.bytestream - pnmctx.bytestream_start
00070 + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
00071 if(pnmctx.bytestream_start!=buf)
00072 next-= pc->index;
00073 if(next > buf_size)
00074 next= END_NOT_FOUND;
00075 }
00076
00077 if(ff_combine_frame(pc, next, &buf, &buf_size)<0){
00078 *poutbuf = NULL;
00079 *poutbuf_size = 0;
00080 return buf_size;
00081 }
00082 *poutbuf = buf;
00083 *poutbuf_size = buf_size;
00084 return next;
00085 }
00086
00087 AVCodecParser pnm_parser = {
00088 { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM},
00089 sizeof(ParseContext),
00090 NULL,
00091 pnm_parse,
00092 ff_parse_close,
00093 };