]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dvbsub_parser.c
avcodec: Constify all the AVCodecParsers
[ffmpeg] / libavcodec / dvbsub_parser.c
index e77b9655cca2377f780ca0b0ede511663275783b..3dd97200b441b6319d2a290832bcd69932dd0483 100644 (file)
 
 /* parser definition */
 typedef struct DVBSubParseContext {
-    uint8_t *packet_buf;
     int packet_start;
     int packet_index;
     int in_packet;
+    uint8_t packet_buf[PARSE_BUF_SIZE];
 } DVBSubParseContext;
 
-static av_cold int dvbsub_parse_init(AVCodecParserContext *s)
-{
-    DVBSubParseContext *pc = s->priv_data;
-    pc->packet_buf = av_malloc(PARSE_BUF_SIZE);
-
-    return 0;
-}
-
 static int dvbsub_parse(AVCodecParserContext *s,
                         AVCodecContext *avctx,
                         const uint8_t **poutbuf, int *poutbuf_size,
@@ -57,6 +49,7 @@ static int dvbsub_parse(AVCodecParserContext *s,
     DVBSubParseContext *pc = s->priv_data;
     uint8_t *p, *p_end;
     int i, len, buf_pos = 0;
+    int out_size = 0;
 
     ff_dlog(avctx, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n",
             s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]);
@@ -71,8 +64,8 @@ static int dvbsub_parse(AVCodecParserContext *s,
     if (i % 16 != 0)
         ff_dlog(avctx, "\n");
 
-    *poutbuf = NULL;
-    *poutbuf_size = 0;
+    *poutbuf      = buf;
+    *poutbuf_size = buf_size;
 
     s->fetch_timestamp = 1;
 
@@ -89,7 +82,7 @@ static int dvbsub_parse(AVCodecParserContext *s,
 
         if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) {
             ff_dlog(avctx, "Bad packet header\n");
-            return -1;
+            return buf_size;
         }
 
         buf_pos = 2;
@@ -113,9 +106,9 @@ static int dvbsub_parse(AVCodecParserContext *s,
     }
 
     if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE)
-        return -1;
+        return buf_size;
 
-/* if not currently in a packet, discard data */
+/* if not currently in a packet, pass data */
     if (pc->in_packet == 0)
         return buf_size;
 
@@ -135,7 +128,7 @@ static int dvbsub_parse(AVCodecParserContext *s,
 
                 if (len + 6 <= p_end - p)
                 {
-                    *poutbuf_size += len + 6;
+                    out_size += len + 6;
 
                     p += len + 6;
                 } else
@@ -159,9 +152,10 @@ static int dvbsub_parse(AVCodecParserContext *s,
         }
     }
 
-    if (*poutbuf_size > 0)
+    if (out_size > 0)
     {
         *poutbuf = pc->packet_buf;
+        *poutbuf_size = out_size;
         pc->packet_start = *poutbuf_size;
     }
 
@@ -171,16 +165,8 @@ static int dvbsub_parse(AVCodecParserContext *s,
     return buf_size;
 }
 
-static av_cold void dvbsub_parse_close(AVCodecParserContext *s)
-{
-    DVBSubParseContext *pc = s->priv_data;
-    av_freep(&pc->packet_buf);
-}
-
-AVCodecParser ff_dvbsub_parser = {
+const AVCodecParser ff_dvbsub_parser = {
     .codec_ids      = { AV_CODEC_ID_DVB_SUBTITLE },
     .priv_data_size = sizeof(DVBSubParseContext),
-    .parser_init    = dvbsub_parse_init,
     .parser_parse   = dvbsub_parse,
-    .parser_close   = dvbsub_parse_close,
 };