]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/cbs_h2645: Move zero_byte check to its own function
authorNuo Mi <nuomi2021@gmail.com>
Mon, 11 Jan 2021 16:33:14 +0000 (00:33 +0800)
committerMark Thompson <sw@jkqxz.net>
Mon, 11 Jan 2021 21:34:43 +0000 (21:34 +0000)
Signed-off-by: Mark Thompson <sw@jkqxz.net>
libavcodec/cbs_h2645.c

index 434322492c41ad3a8f13dba5aacd87aef6aaad74..550c059ef37a20ff53b1a01bee3ba0f3d8031f9f 100644 (file)
@@ -1207,6 +1207,22 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
     return 0;
 }
 
+static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id,
+                                             CodedBitstreamUnitType type,
+                                             int nal_unit_index)
+{
+    // Section B.1.2 in H.264, section B.2.2 in H.265.
+    if (nal_unit_index == 0) {
+        // Assume that this is the first NAL unit in an access unit.
+        return 1;
+    }
+    if (codec_id == AV_CODEC_ID_H264)
+        return type == H264_NAL_SPS || type == H264_NAL_PPS;
+    if (codec_id == AV_CODEC_ID_HEVC)
+        return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS;
+    return 0;
+}
+
 static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
                                        CodedBitstreamFragment *frag)
 {
@@ -1241,14 +1257,7 @@ static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx,
                 frag->data_bit_padding = unit->data_bit_padding;
         }
 
-        if ((ctx->codec->codec_id == AV_CODEC_ID_H264 &&
-             (unit->type == H264_NAL_SPS ||
-              unit->type == H264_NAL_PPS)) ||
-            (ctx->codec->codec_id == AV_CODEC_ID_HEVC &&
-             (unit->type == HEVC_NAL_VPS ||
-              unit->type == HEVC_NAL_SPS ||
-              unit->type == HEVC_NAL_PPS)) ||
-            i == 0 /* (Assume this is the start of an access unit.) */) {
+        if (cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) {
             // zero_byte
             data[dp++] = 0;
         }