[SCM] libav/experimental: pnm parser

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:42:10 UTC 2013


The following commit has been merged in the experimental branch:
commit 99f0623629dc0aeb805e7070a1b62c29688ce1bd
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Fri Nov 12 22:55:29 2004 +0000

    pnm parser
    
    Originally committed as revision 3675 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 649ae0b..fcccf18 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -247,6 +247,7 @@ PCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
     av_register_codec_parser(&h263_parser);
     av_register_codec_parser(&h264_parser);
     av_register_codec_parser(&mjpeg_parser);
+    av_register_codec_parser(&pnm_parser);
 
     av_register_codec_parser(&mpegaudio_parser);
 #ifdef CONFIG_AC3
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index a379b52..afdce31 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -17,7 +17,7 @@ extern "C" {
 
 #define FFMPEG_VERSION_INT     0x000409
 #define FFMPEG_VERSION         "0.4.9-pre1"
-#define LIBAVCODEC_BUILD       4730
+#define LIBAVCODEC_BUILD       4731
 
 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
 #define LIBAVCODEC_VERSION     FFMPEG_VERSION
@@ -2152,7 +2152,7 @@ typedef struct AVCodecParserContext {
 } AVCodecParserContext;
 
 typedef struct AVCodecParser {
-    int codec_ids[3]; /* several codec IDs are permitted */
+    int codec_ids[5]; /* several codec IDs are permitted */
     int priv_data_size;
     int (*parser_init)(AVCodecParserContext *s);
     int (*parser_parse)(AVCodecParserContext *s, 
@@ -2180,6 +2180,7 @@ extern AVCodecParser h261_parser;
 extern AVCodecParser h263_parser;
 extern AVCodecParser h264_parser;
 extern AVCodecParser mjpeg_parser;
+extern AVCodecParser pnm_parser;
 extern AVCodecParser mpegaudio_parser;
 extern AVCodecParser ac3_parser;
 
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 97cadc1..b15c1c4 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -38,7 +38,9 @@ AVCodecParserContext *av_parser_init(int codec_id)
     for(parser = av_first_parser; parser != NULL; parser = parser->next) {
         if (parser->codec_ids[0] == codec_id ||
             parser->codec_ids[1] == codec_id ||
-            parser->codec_ids[2] == codec_id)
+            parser->codec_ids[2] == codec_id ||
+            parser->codec_ids[3] == codec_id ||
+            parser->codec_ids[4] == codec_id)
             goto found;
     }
     return NULL;
diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index 1bf2d4a..cbe48a2 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -17,6 +17,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "avcodec.h"
+#include "mpegvideo.h" //only for ParseContext
 
 typedef struct PNMContext {
     uint8_t *bytestream;
@@ -65,25 +66,9 @@ static int common_init(AVCodecContext *avctx){
     return 0;
 }
 
-static int pnm_decode_frame(AVCodecContext *avctx, 
-                        void *data, int *data_size,
-                        uint8_t *buf, int buf_size)
-{
-    PNMContext * const s = avctx->priv_data;
-    AVFrame *picture = data;
-    AVFrame * const p= (AVFrame*)&s->picture;
-    int i, n, linesize, h;
+static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){
     char buf1[32];
-    unsigned char *ptr;
-
-    /* special case for last picture */
-    if (buf_size == 0) {
-        return 0;
-    }
-    
-    s->bytestream_start=
-    s->bytestream= buf;
-    s->bytestream_end= buf + buf_size;
+    int h;
 
     pnm_get(s, buf1, sizeof(buf1));
     if (!strcmp(buf1, "P4")) {
@@ -120,6 +105,30 @@ static int pnm_decode_frame(AVCodecContext *avctx,
         h /= 3;
         avctx->height = h;
     }
+    return 0;
+}
+
+static int pnm_decode_frame(AVCodecContext *avctx, 
+                        void *data, int *data_size,
+                        uint8_t *buf, int buf_size)
+{
+    PNMContext * const s = avctx->priv_data;
+    AVFrame *picture = data;
+    AVFrame * const p= (AVFrame*)&s->picture;
+    int i, n, linesize, h;
+    unsigned char *ptr;
+
+    /* special case for last picture */
+    if (buf_size == 0) {
+        return 0;
+    }
+    
+    s->bytestream_start=
+    s->bytestream= buf;
+    s->bytestream_end= buf + buf_size;
+    
+    if(pnm_decode_header(avctx, s) < 0)
+        return h;
     
     if(p->data[0])
         avctx->release_buffer(avctx, p);
@@ -492,6 +501,75 @@ static int pam_probe(AVProbeData *pd)
 }
 #endif
 
+static int pnm_parse(AVCodecParserContext *s,
+                           AVCodecContext *avctx,
+                           uint8_t **poutbuf, int *poutbuf_size, 
+                           const uint8_t *buf, int buf_size)
+{
+    ParseContext *pc = s->priv_data;
+    PNMContext pnmctx;
+    int next;
+
+    for(; pc->overread>0; pc->overread--){
+        pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
+    }
+retry:
+    if(pc->index){
+        pnmctx.bytestream_start=
+        pnmctx.bytestream= pc->buffer;
+        pnmctx.bytestream_end= pc->buffer + pc->index;
+    }else{
+        pnmctx.bytestream_start=
+        pnmctx.bytestream= buf;
+        pnmctx.bytestream_end= buf + buf_size;
+    }
+    if(pnm_decode_header(avctx, &pnmctx) < 0){
+        if(pnmctx.bytestream < pnmctx.bytestream_end){
+            if(pc->index){
+                pc->index=0;
+            }else{
+                buf++;
+                buf_size--;
+            }
+            goto retry;
+        }
+#if 0
+        if(pc->index && pc->index*2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index){
+            memcpy(pc->buffer + pc->index, buf, pc->index);
+            pc->index += pc->index;
+            buf += pc->index;
+            buf_size -= pc->index;
+            goto retry;
+        }
+#endif
+        next= END_NOT_FOUND;
+    }else{
+        next= pnmctx.bytestream - pnmctx.bytestream_start 
+            + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+        if(pnmctx.bytestream_start!=buf)
+            next-= pc->index;
+        if(next > buf_size)
+            next= END_NOT_FOUND;
+    }
+    
+    if(ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size)<0){
+        *poutbuf = NULL;
+        *poutbuf_size = 0;
+        return buf_size;
+    }
+    *poutbuf = (uint8_t *)buf;
+    *poutbuf_size = buf_size;
+    return next;
+}
+
+AVCodecParser pnm_parser = {
+    { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM},
+    sizeof(ParseContext),
+    NULL,
+    pnm_parse,
+    ff_parse_close,
+};
+
 AVCodec pgm_encoder = {
     "pgm",
     CODEC_TYPE_VIDEO,

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list