diff mbox series

[FFmpeg-devel,v3,06/11] avcodec/cbs_h2645: reface, move zero bytes check to a function

Message ID 20210111163319.13387-7-nuomi2021@gmail.com
State Superseded
Headers show
Series add vvc raw demuxer, muxer, parser, metadata bsf | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Nuo Mi Jan. 11, 2021, 4:33 p.m. UTC
---
 libavcodec/cbs_h2645.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

Comments

Mark Thompson Jan. 11, 2021, 9:38 p.m. UTC | #1
On 11/01/2021 16:33, Nuo Mi wrote:
> ---
>   libavcodec/cbs_h2645.c | 23 +++++++++++++++--------
>   1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 434322492c..5d7ae95931 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1207,6 +1207,20 @@ static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
>       return 0;
>   }
>   
> +//defined in B.2.2 zero_byte section
> +static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id,
> +                                             CodedBitstreamUnitType type,
> +                                             int i)
> +{
> +    if (i == 0)
> +        return 1; /* (Assume this is the start of an access unit.) */
> +    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 +1255,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;
>           }
> 

I clarified the comments (the section reference is not the same for H.264) and applied.

Thanks,

- Mark
diff mbox series

Patch

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 434322492c..5d7ae95931 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1207,6 +1207,20 @@  static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx,
     return 0;
 }
 
+//defined in B.2.2 zero_byte section
+static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id,
+                                             CodedBitstreamUnitType type,
+                                             int i)
+{
+    if (i == 0)
+        return 1; /* (Assume this is the start of an access unit.) */
+    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 +1255,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;
         }