]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pgssubdec.c
Vivo demuxer
[ffmpeg] / libavcodec / pgssubdec.c
index d0d4dd6aff0bebd29ec77986ebdf4642dec49fa6..d0cff7bba63325cd74abdd8850d731deb6140306 100644 (file)
@@ -52,6 +52,7 @@ typedef struct PGSSubPresentation {
     int                    id_number;
     int                    object_count;
     PGSSubPictureReference *objects;
+    int64_t pts;
 } PGSSubPresentation;
 
 typedef struct PGSSubPicture {
@@ -67,7 +68,6 @@ typedef struct PGSSubContext {
     PGSSubPresentation presentation;
     uint32_t           clut[256];
     PGSSubPicture      pictures[UINT16_MAX];
-    int64_t            pts;
     int forced_subs_only;
 } PGSSubContext;
 
@@ -222,6 +222,11 @@ static int parse_picture_segment(AVCodecContext *avctx,
         return -1;
     }
 
+    if (buf_size > rle_bitmap_len) {
+        av_log(avctx, AV_LOG_ERROR, "too much RLE data\n");
+        return AVERROR_INVALIDDATA;
+    }
+
     ctx->pictures[picture_id].w = width;
     ctx->pictures[picture_id].h = height;
 
@@ -290,7 +295,8 @@ static void parse_palette_segment(AVCodecContext *avctx,
  * @todo TODO: Implement cropping
  */
 static void parse_presentation_segment(AVCodecContext *avctx,
-                                       const uint8_t *buf, int buf_size)
+                                       const uint8_t *buf, int buf_size,
+                                       int64_t pts)
 {
     PGSSubContext *ctx = avctx->priv_data;
 
@@ -299,6 +305,8 @@ static void parse_presentation_segment(AVCodecContext *avctx,
 
     uint16_t object_index;
 
+    ctx->presentation.pts = pts;
+
     av_dlog(avctx, "Video Dimensions %dx%d\n",
             w, h);
     if (av_image_check_size(w, h, 0, avctx) >= 0)
@@ -389,10 +397,10 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
      *      not been cleared by a subsequent empty display command.
      */
 
-    pts = ctx->pts != AV_NOPTS_VALUE ? ctx->pts : sub->pts;
+    pts = ctx->presentation.pts != AV_NOPTS_VALUE ? ctx->presentation.pts : sub->pts;
     memset(sub, 0, sizeof(*sub));
     sub->pts = pts;
-    ctx->pts = AV_NOPTS_VALUE;
+    ctx->presentation.pts = AV_NOPTS_VALUE;
 
     // Blank if last object_count was 0.
     if (!ctx->presentation.object_count)
@@ -429,7 +437,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
         sub->rects[rect]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
 
         /* Copy the forced flag */
-        sub->rects[rect]->forced = (ctx->presentation.objects[rect].composition & 0x40) != 0;
+        sub->rects[rect]->flags = (ctx->presentation.objects[rect].composition & 0x40) != 0 ? AV_SUBTITLE_FLAG_FORCED : 0;
 
         if (!ctx->forced_subs_only || ctx->presentation.objects[rect].composition & 0x40)
         memcpy(sub->rects[rect]->pict.data[1], ctx->clut, sub->rects[rect]->nb_colors * sizeof(uint32_t));
@@ -441,7 +449,6 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
 static int decode(AVCodecContext *avctx, void *data, int *data_size,
                   AVPacket *avpkt)
 {
-    PGSSubContext *ctx = avctx->priv_data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
     AVSubtitle *sub    = data;
@@ -488,8 +495,7 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size,
             parse_picture_segment(avctx, buf, segment_length);
             break;
         case PRESENTATION_SEGMENT:
-            parse_presentation_segment(avctx, buf, segment_length);
-            ctx->pts = sub->pts;
+            parse_presentation_segment(avctx, buf, segment_length, sub->pts);
             break;
         case WINDOW_SEGMENT:
             /*