Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD
@ 2022-10-19 15:03 Andreas Rheinhardt
  2022-10-19 15:05 ` [FFmpeg-devel] [PATCH 2/2] avocdec/cbs_internal: Rename CBS_MAX_UNIT_TYPES->CBS_MAX_LIST_UNIT_TYPES Andreas Rheinhardt
  2022-10-21 22:17 ` [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD Andreas Rheinhardt
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2022-10-19 15:03 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It is equivalent to CBS_CONTENT_TYPE_INTERNAL_REFS
with nb_offsets equal to zero.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/cbs.c          | 18 ++++--------------
 libavcodec/cbs_internal.h | 21 ++++++++++++---------
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 8d6e3c3442..504197e06d 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -839,12 +839,10 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
 static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
 {
     const CodedBitstreamUnitTypeDescriptor *desc = opaque;
-    if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
-        int i;
-        for (i = 0; i < desc->type.ref.nb_offsets; i++) {
-            void **ptr = (void**)(data + desc->type.ref.offsets[i]);
-            av_buffer_unref((AVBufferRef**)(ptr + 1));
-        }
+
+    for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
+        void **ptr = (void**)(data + desc->type.ref.offsets[i]);
+        av_buffer_unref((AVBufferRef**)(ptr + 1));
     }
     av_free(data);
 }
@@ -981,14 +979,6 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
         return AVERROR(ENOSYS);
 
     switch (desc->content_type) {
-    case CBS_CONTENT_TYPE_POD:
-        ref = av_buffer_alloc(desc->content_size);
-        if (!ref)
-            return AVERROR(ENOMEM);
-        memcpy(ref->data, unit->content, desc->content_size);
-        err = 0;
-        break;
-
     case CBS_CONTENT_TYPE_INTERNAL_REFS:
         err = cbs_clone_internal_refs_unit_content(&ref, unit, desc);
         break;
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 5ccba3c901..045df91744 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -31,9 +31,7 @@
 
 
 enum CBSContentType {
-    // Unit content is a simple structure.
-    CBS_CONTENT_TYPE_POD,
-    // Unit content contains some references to other structures, but all
+    // Unit content may contain some references to other structures, but all
     // managed via buffer reference counting.  The descriptor defines the
     // structure offsets of every buffer reference.
     CBS_CONTENT_TYPE_INTERNAL_REFS,
@@ -78,9 +76,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
     size_t content_size;
 
     union {
+        // This union's state is determined by content_type:
+        // ref for CBS_CONTENT_TYPE_INTERNAL_REFS,
+        // complex for CBS_CONTENT_TYPE_COMPLEX.
         struct {
-            // Number of entries in the ref_offsets array.  Only nonzero
-            // if the content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
+            // Number of entries in the ref_offsets array.
+            // May be zero, then the structure is POD-like.
             int nb_offsets;
             // The structure must contain two adjacent elements:
             //   type        *field;
@@ -191,18 +192,20 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
 
 #define TYPE_LIST(...) { __VA_ARGS__ }
-#define CBS_UNIT_TYPE_POD(type, structure) { \
+#define CBS_UNIT_TYPE_POD(type_, structure) { \
         .nb_unit_types  = 1, \
-        .unit_type.list = { type }, \
-        .content_type   = CBS_CONTENT_TYPE_POD, \
+        .unit_type.list = { type_ }, \
+        .content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS, \
         .content_size   = sizeof(structure), \
+        .type.ref       = { .nb_offsets = 0 }, \
     }
 #define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \
         .nb_unit_types         = CBS_UNIT_TYPE_RANGE, \
         .unit_type.range.start = range_start, \
         .unit_type.range.end   = range_end, \
-        .content_type          = CBS_CONTENT_TYPE_POD, \
+        .content_type          = CBS_CONTENT_TYPE_INTERNAL_REFS, \
         .content_size          = sizeof(structure), \
+        .type.ref              = { .nb_offsets = 0 }, \
     }
 
 #define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avocdec/cbs_internal: Rename CBS_MAX_UNIT_TYPES->CBS_MAX_LIST_UNIT_TYPES
  2022-10-19 15:03 [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD Andreas Rheinhardt
@ 2022-10-19 15:05 ` Andreas Rheinhardt
  2022-10-21 22:17 ` [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD Andreas Rheinhardt
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2022-10-19 15:05 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

This makes it clearer that this limit does not apply to
CBS_UNIT_TYPE_RANGE units.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
Inspired by https://ffmpeg.org/pipermail/ffmpeg-devel/2022-October/303005.html

 libavcodec/cbs_internal.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index 045df91744..7887552269 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -41,9 +41,9 @@ enum CBSContentType {
 };
 
 enum {
-      // Maximum number of unit types described by the same unit type
-      // descriptor.
-      CBS_MAX_UNIT_TYPES  = 3,
+      // Maximum number of unit types described by the same non-range
+      // unit type descriptor.
+      CBS_MAX_LIST_UNIT_TYPES  = 3,
       // Maximum number of reference buffer offsets in any one unit.
       CBS_MAX_REF_OFFSETS = 2,
       // Special value used in a unit type descriptor to indicate that it
@@ -60,7 +60,7 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
 
     union {
         // Array of unit types that this entry describes.
-        CodedBitstreamUnitType list[CBS_MAX_UNIT_TYPES];
+        CodedBitstreamUnitType list[CBS_MAX_LIST_UNIT_TYPES];
         // Start and end of unit type range, used if nb_unit_types is
         // CBS_UNIT_TYPE_RANGE.
         struct {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD
  2022-10-19 15:03 [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD Andreas Rheinhardt
  2022-10-19 15:05 ` [FFmpeg-devel] [PATCH 2/2] avocdec/cbs_internal: Rename CBS_MAX_UNIT_TYPES->CBS_MAX_LIST_UNIT_TYPES Andreas Rheinhardt
@ 2022-10-21 22:17 ` Andreas Rheinhardt
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2022-10-21 22:17 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> It is equivalent to CBS_CONTENT_TYPE_INTERNAL_REFS
> with nb_offsets equal to zero.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/cbs.c          | 18 ++++--------------
>  libavcodec/cbs_internal.h | 21 ++++++++++++---------
>  2 files changed, 16 insertions(+), 23 deletions(-)
> 
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index 8d6e3c3442..504197e06d 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -839,12 +839,10 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
>  static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
>  {
>      const CodedBitstreamUnitTypeDescriptor *desc = opaque;
> -    if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
> -        int i;
> -        for (i = 0; i < desc->type.ref.nb_offsets; i++) {
> -            void **ptr = (void**)(data + desc->type.ref.offsets[i]);
> -            av_buffer_unref((AVBufferRef**)(ptr + 1));
> -        }
> +
> +    for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
> +        void **ptr = (void**)(data + desc->type.ref.offsets[i]);
> +        av_buffer_unref((AVBufferRef**)(ptr + 1));
>      }
>      av_free(data);
>  }
> @@ -981,14 +979,6 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx,
>          return AVERROR(ENOSYS);
>  
>      switch (desc->content_type) {
> -    case CBS_CONTENT_TYPE_POD:
> -        ref = av_buffer_alloc(desc->content_size);
> -        if (!ref)
> -            return AVERROR(ENOMEM);
> -        memcpy(ref->data, unit->content, desc->content_size);
> -        err = 0;
> -        break;
> -
>      case CBS_CONTENT_TYPE_INTERNAL_REFS:
>          err = cbs_clone_internal_refs_unit_content(&ref, unit, desc);
>          break;
> diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
> index 5ccba3c901..045df91744 100644
> --- a/libavcodec/cbs_internal.h
> +++ b/libavcodec/cbs_internal.h
> @@ -31,9 +31,7 @@
>  
>  
>  enum CBSContentType {
> -    // Unit content is a simple structure.
> -    CBS_CONTENT_TYPE_POD,
> -    // Unit content contains some references to other structures, but all
> +    // Unit content may contain some references to other structures, but all
>      // managed via buffer reference counting.  The descriptor defines the
>      // structure offsets of every buffer reference.
>      CBS_CONTENT_TYPE_INTERNAL_REFS,
> @@ -78,9 +76,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
>      size_t content_size;
>  
>      union {
> +        // This union's state is determined by content_type:
> +        // ref for CBS_CONTENT_TYPE_INTERNAL_REFS,
> +        // complex for CBS_CONTENT_TYPE_COMPLEX.
>          struct {
> -            // Number of entries in the ref_offsets array.  Only nonzero
> -            // if the content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
> +            // Number of entries in the ref_offsets array.
> +            // May be zero, then the structure is POD-like.
>              int nb_offsets;
>              // The structure must contain two adjacent elements:
>              //   type        *field;
> @@ -191,18 +192,20 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
>  #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
>  
>  #define TYPE_LIST(...) { __VA_ARGS__ }
> -#define CBS_UNIT_TYPE_POD(type, structure) { \
> +#define CBS_UNIT_TYPE_POD(type_, structure) { \
>          .nb_unit_types  = 1, \
> -        .unit_type.list = { type }, \
> -        .content_type   = CBS_CONTENT_TYPE_POD, \
> +        .unit_type.list = { type_ }, \
> +        .content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS, \
>          .content_size   = sizeof(structure), \
> +        .type.ref       = { .nb_offsets = 0 }, \
>      }
>  #define CBS_UNIT_RANGE_POD(range_start, range_end, structure) { \
>          .nb_unit_types         = CBS_UNIT_TYPE_RANGE, \
>          .unit_type.range.start = range_start, \
>          .unit_type.range.end   = range_end, \
> -        .content_type          = CBS_CONTENT_TYPE_POD, \
> +        .content_type          = CBS_CONTENT_TYPE_INTERNAL_REFS, \
>          .content_size          = sizeof(structure), \
> +        .type.ref              = { .nb_offsets = 0 }, \
>      }
>  
>  #define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field) { \

Will apply this patchset tonight unless there are objections.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-21 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 15:03 [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD Andreas Rheinhardt
2022-10-19 15:05 ` [FFmpeg-devel] [PATCH 2/2] avocdec/cbs_internal: Rename CBS_MAX_UNIT_TYPES->CBS_MAX_LIST_UNIT_TYPES Andreas Rheinhardt
2022-10-21 22:17 ` [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: Remove CBS_CONTENT_TYPE_POD Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git