[FFmpeg-devel] [PATCH v2] cbs_h2645: Implement replace-PS with a table rather than many functions

Nuo Mi nuomi2021 at gmail.com
Tue Feb 16 17:16:21 EET 2021


On Tue, Feb 16, 2021 at 7:20 AM Mark Thompson <sw at jkqxz.net> wrote:

> While this is mode source code, it generates less binary code and can be
> more cleanly extended to H.266.
> ---
> On 14/02/2021 19:45, Andreas Rheinhardt wrote:
> > Nuo Mi:
> >> From: Mark Thompson <sw at jkqxz.net>
>
> Hi Andreas & Mark,
thanks for the suggestion.

Hi Mark,
vvc's xps does not need active_offset. vvc's picture header does not need
id_offset. see [1], [2] for details
How about we change the patch like this:

$git diff
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 6c44e781fa..57c419aa05 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -690,20 +690,24 @@ static int cbs_h2645_replace_ps(CodedBitstreamContext
*ctx,
         size_t active_offset;
     } PSType;

-#define H2645_PS_TYPE(codec, nal, cname, uname, count, id_name,
active_field) { \
+#define H26456_PS_TYPE(codec, nal, cname, uname, count, id_off,
active_off) { \
         .codec_id         = AV_CODEC_ID_ ## codec, \
         .nal_unit_type    = nal, \
         .name             = #cname, \
         .id_count         = count, \
-        .id_offset        = offsetof(codec ## Raw ## cname, \
-                                     id_name ## _parameter_set_id), \
+        .id_offset        = id_off, \
         .ref_array_offset = offsetof(CodedBitstream ## codec ## Context, \
                                      uname ## _ref), \
         .ptr_array_offset = offsetof(CodedBitstream ## codec ## Context, \
                                      uname), \
-        .active_offset    = offsetof(CodedBitstream ## codec ## Context, \
-                                     active_field), \
+        .active_offset    = active_off, \
     }
+
+#define H2645_PS_TYPE(codec, nal, cname, uname, count, id_name,
active_field) \
+        H26456_PS_TYPE(codec, nal, cname, uname, count, \
+            offsetof(codec ## Raw ## cname, id_name ## _parameter_set_id),
\
+            offsetof(CodedBitstream ## codec ## Context, active_field))
+
 #define H264_PS_TYPE(cname, uname, id_name) \
     H2645_PS_TYPE(H264, H264_NAL_ ## cname, cname, uname, \
                   H264_MAX_ ## cname ## _COUNT, \
@@ -724,7 +728,7 @@ static int cbs_h2645_replace_ps(CodedBitstreamContext
*ctx,
     const PSType *ps_type;
     AVBufferRef **ref_array;
     void **ptr_array;
-    int err, id, i;
+    int err, id = 0, i;

     ps_type = NULL;
     for (i = 0; i < FF_ARRAY_ELEMS(ps_types); i++) {
@@ -736,12 +740,14 @@ static int cbs_h2645_replace_ps(CodedBitstreamContext
*ctx,
     }
     av_assert0(ps_type);

-    id = *((uint8_t*)unit->content + ps_type->id_offset);
+    if (ps_type->id_offset) {
+        id = *((uint8_t*)unit->content + ps_type->id_offset);

-    if (id >= ps_type->id_count) {
-        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid %s id: %d.\n",
-               ps_type->name, id);
-        return AVERROR_INVALIDDATA;
+        if (id >= ps_type->id_count) {
+            av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid %s id: %d.\n",
+                ps_type->name, id);
+            return AVERROR_INVALIDDATA;
+        }
     }

     err = ff_cbs_make_unit_refcounted(ctx, unit);


[1]:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210211143611.5663-5-nuomi2021@gmail.com/
[2] h266_ps_types in
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210211143611.5663-6-nuomi2021@gmail.com/


More information about the ffmpeg-devel mailing list