• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/pnm_parser.c

Go to the documentation of this file.
00001 /*
00002  * PNM image parser
00003  * Copyright (c) 2002, 2003 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "parser.h" //for ParseContext
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; /* casts avoid warnings */
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 };

Generated on Tue Nov 4 2014 12:59:22 for ffmpeg by  doxygen 1.7.1