[FFmpeg-devel] [PATCH v1] avcodec/av1_parser: ensure only one show frame packed data parsered

Fei Wang fei.w.wang at intel.com
Fri Dec 3 10:09:20 EET 2021


Split packed data when it contains multiple show frames in some
non-standard bitstream. This can benefit downstream decoder which can
decode continuously instead of interrupt with unexpected error.

Signed-off-by: Fei Wang <fei.w.wang at intel.com>
---
 libavcodec/av1_parser.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index d2dfdb3580..d6f5cace4b 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -59,11 +59,10 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
     const CodedBitstreamAV1Context *av1 = s->cbc->priv_data;
     const AV1RawSequenceHeader *seq;
     const AV1RawColorConfig *color;
+    int pic_found = 0;
+    int next = 0;
     int ret;
 
-    *out_data = data;
-    *out_size = size;
-
     ctx->key_frame         = -1;
     ctx->pict_type         = AV_PICTURE_TYPE_NONE;
     ctx->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
@@ -100,6 +99,8 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
         const AV1RawOBU *obu = unit->content;
         const AV1RawFrameHeader *frame;
 
+        next += unit->data_size;
+
         if (unit->type == AV1_OBU_FRAME)
             frame = &obu->obu.frame.header;
         else if (unit->type == AV1_OBU_FRAME_HEADER)
@@ -113,6 +114,12 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
         if (!frame->show_frame && !frame->show_existing_frame)
             continue;
 
+        /* split data if it contains multi show frames */
+        if (pic_found) {
+            next -= unit->data_size;
+            break;
+        }
+
         ctx->width  = frame->frame_width_minus_1 + 1;
         ctx->height = frame->frame_height_minus_1 + 1;
 
@@ -131,8 +138,12 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
             break;
         }
         ctx->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
+        pic_found = 1;
     }
 
+    *out_size = next;
+    *out_data = data;
+
     switch (av1->bit_depth) {
     case 8:
         ctx->format = color->mono_chrome ? AV_PIX_FMT_GRAY8
@@ -171,7 +182,7 @@ end:
 
     s->cbc->log_ctx = NULL;
 
-    return size;
+    return next;
 }
 
 static const CodedBitstreamUnitType decompose_unit_types[] = {
-- 
2.25.1



More information about the ffmpeg-devel mailing list