diff mbox series

[FFmpeg-devel,1/4,v2] avcodec/cbs: add an AVClass to CodedBitstreamType for option handling

Message ID 20201115215541.4526-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/4,v2] avcodec/cbs: add an AVClass to CodedBitstreamType for option handling | expand

Checks

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

Commit Message

James Almer Nov. 15, 2020, 9:55 p.m. UTC
So unit parsing may be configured with caller set options.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs.c          | 9 +++++++++
 libavcodec/cbs_internal.h | 6 ++++++
 2 files changed, 15 insertions(+)

Comments

James Almer Dec. 1, 2020, 2:58 p.m. UTC | #1
On 11/15/2020 6:55 PM, James Almer wrote:
> So unit parsing may be configured with caller set options.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavcodec/cbs.c          | 9 +++++++++
>   libavcodec/cbs_internal.h | 6 ++++++
>   2 files changed, 15 insertions(+)
> 
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index c8c526ab12..c7afccd6f5 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -23,6 +23,7 @@
>   #include "libavutil/avassert.h"
>   #include "libavutil/buffer.h"
>   #include "libavutil/common.h"
> +#include "libavutil/opt.h"
>   
>   #include "cbs.h"
>   #include "cbs_internal.h"
> @@ -101,6 +102,10 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
>               av_freep(&ctx);
>               return AVERROR(ENOMEM);
>           }
> +        if (type->priv_class) {
> +            *(const AVClass **)ctx->priv_data = type->priv_class;
> +            av_opt_set_defaults(ctx->priv_data);
> +        }
>       }
>   
>       ctx->decompose_unit_types = NULL;
> @@ -129,6 +134,10 @@ void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
>           ctx->codec->close(ctx);
>   
>       av_freep(&ctx->write_buffer);
> +
> +    if (ctx->codec->priv_class && ctx->priv_data)
> +        av_opt_free(ctx->priv_data);
> +
>       av_freep(&ctx->priv_data);
>       av_freep(ctx_ptr);
>   }
> diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
> index faa847aad3..a392880036 100644
> --- a/libavcodec/cbs_internal.h
> +++ b/libavcodec/cbs_internal.h
> @@ -86,6 +86,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
>   typedef struct CodedBitstreamType {
>       enum AVCodecID codec_id;
>   
> +    // A class for the private data, used to declare private AVOptions.
> +    // This field is NULL for types that do not declare any options.
> +    // If this field is non-NULL, the first member of the filter private data
> +    // must be a pointer to AVClass.
> +    const AVClass *priv_class;
> +
>       size_t priv_data_size;
>   
>       // List of unit type descriptors for this codec.

Ping for the set.
James Almer Dec. 9, 2020, 3:34 p.m. UTC | #2
On 12/1/2020 11:58 AM, James Almer wrote:
> On 11/15/2020 6:55 PM, James Almer wrote:
>> So unit parsing may be configured with caller set options.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavcodec/cbs.c          | 9 +++++++++
>>   libavcodec/cbs_internal.h | 6 ++++++
>>   2 files changed, 15 insertions(+)
>>
>> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
>> index c8c526ab12..c7afccd6f5 100644
>> --- a/libavcodec/cbs.c
>> +++ b/libavcodec/cbs.c
>> @@ -23,6 +23,7 @@
>>   #include "libavutil/avassert.h"
>>   #include "libavutil/buffer.h"
>>   #include "libavutil/common.h"
>> +#include "libavutil/opt.h"
>>   #include "cbs.h"
>>   #include "cbs_internal.h"
>> @@ -101,6 +102,10 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
>>               av_freep(&ctx);
>>               return AVERROR(ENOMEM);
>>           }
>> +        if (type->priv_class) {
>> +            *(const AVClass **)ctx->priv_data = type->priv_class;
>> +            av_opt_set_defaults(ctx->priv_data);
>> +        }
>>       }
>>       ctx->decompose_unit_types = NULL;
>> @@ -129,6 +134,10 @@ void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
>>           ctx->codec->close(ctx);
>>       av_freep(&ctx->write_buffer);
>> +
>> +    if (ctx->codec->priv_class && ctx->priv_data)
>> +        av_opt_free(ctx->priv_data);
>> +
>>       av_freep(&ctx->priv_data);
>>       av_freep(ctx_ptr);
>>   }
>> diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
>> index faa847aad3..a392880036 100644
>> --- a/libavcodec/cbs_internal.h
>> +++ b/libavcodec/cbs_internal.h
>> @@ -86,6 +86,12 @@ typedef const struct 
>> CodedBitstreamUnitTypeDescriptor {
>>   typedef struct CodedBitstreamType {
>>       enum AVCodecID codec_id;
>> +    // A class for the private data, used to declare private AVOptions.
>> +    // This field is NULL for types that do not declare any options.
>> +    // If this field is non-NULL, the first member of the filter 
>> private data
>> +    // must be a pointer to AVClass.
>> +    const AVClass *priv_class;
>> +
>>       size_t priv_data_size;
>>       // List of unit type descriptors for this codec.
> 
> Ping for the set.

Ping? Mark? This version of the set addressed your concerns, so will 
apply it soon.
diff mbox series

Patch

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index c8c526ab12..c7afccd6f5 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -23,6 +23,7 @@ 
 #include "libavutil/avassert.h"
 #include "libavutil/buffer.h"
 #include "libavutil/common.h"
+#include "libavutil/opt.h"
 
 #include "cbs.h"
 #include "cbs_internal.h"
@@ -101,6 +102,10 @@  int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
             av_freep(&ctx);
             return AVERROR(ENOMEM);
         }
+        if (type->priv_class) {
+            *(const AVClass **)ctx->priv_data = type->priv_class;
+            av_opt_set_defaults(ctx->priv_data);
+        }
     }
 
     ctx->decompose_unit_types = NULL;
@@ -129,6 +134,10 @@  void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
         ctx->codec->close(ctx);
 
     av_freep(&ctx->write_buffer);
+
+    if (ctx->codec->priv_class && ctx->priv_data)
+        av_opt_free(ctx->priv_data);
+
     av_freep(&ctx->priv_data);
     av_freep(ctx_ptr);
 }
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
index faa847aad3..a392880036 100644
--- a/libavcodec/cbs_internal.h
+++ b/libavcodec/cbs_internal.h
@@ -86,6 +86,12 @@  typedef const struct CodedBitstreamUnitTypeDescriptor {
 typedef struct CodedBitstreamType {
     enum AVCodecID codec_id;
 
+    // A class for the private data, used to declare private AVOptions.
+    // This field is NULL for types that do not declare any options.
+    // If this field is non-NULL, the first member of the filter private data
+    // must be a pointer to AVClass.
+    const AVClass *priv_class;
+
     size_t priv_data_size;
 
     // List of unit type descriptors for this codec.