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] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
@ 2024-03-20 23:35 James Almer
  2024-03-21  4:00 ` Michael Niedermayer
  2024-03-21 11:15 ` Andreas Rheinhardt
  0 siblings, 2 replies; 8+ messages in thread
From: James Almer @ 2024-03-20 23:35 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/hevc_ps.c     | 17 +++++++++++++++--
 libavcodec/hevc_ps.h     |  2 +-
 libavcodec/vulkan_hevc.c |  2 +-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 20ceb09829..d3edc0810d 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -442,13 +442,21 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
     return 0;
 }
 
+static void uninit_vps(FFRefStructOpaque opaque, void *obj)
+{
+    HEVCVPS *vps = obj;
+
+    for (int i = 0; i < vps->vps_num_hrd_parameters; i++)
+        ff_refstruct_unref(&vps->hdr[i]);
+}
+
 int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
                            HEVCParamSets *ps)
 {
     int i,j;
     int vps_id = 0;
     ptrdiff_t nal_size;
-    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
+    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);
 
     if (!vps)
         return AVERROR(ENOMEM);
@@ -538,12 +546,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
             goto err;
         }
         for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
+            HEVCHdrParams *hdr = ff_refstruct_allocz(sizeof(*hdr));
             int common_inf_present = 1;
 
+            if (!hdr)
+                return AVERROR(ENOMEM);
+
             get_ue_golomb_long(gb); // hrd_layer_set_idx
             if (i)
                 common_inf_present = get_bits1(gb);
-            decode_hrd(gb, common_inf_present, &vps->hdr[i],
+
+            decode_hrd(gb, common_inf_present, hdr,
                        vps->vps_max_sub_layers);
         }
     }
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 9cdec9b6c1..ff94f90a5e 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -150,7 +150,7 @@ typedef struct PTL {
 
 typedef struct HEVCVPS {
     unsigned int vps_id;
-    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
+    HEVCHdrParams *hdr[HEVC_MAX_LAYER_SETS];
 
     uint8_t vps_temporal_id_nesting_flag : 1;
     uint8_t vps_sub_layer_ordering_info_present_flag : 1;
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index 239bff75e5..a89d09a372 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -563,7 +563,7 @@ static void set_vps(const HEVCVPS *vps,
                     HEVCHeaderVPSSet sls[])
 {
     for (int i = 0; i < vps->vps_num_hrd_parameters; i++) {
-        const HEVCHdrParams *src = &vps->hdr[i];
+        const HEVCHdrParams *src = vps->hdr[i];
 
         sls_hdr[i] = (StdVideoH265HrdParameters) {
             .flags = (StdVideoH265HrdFlags) {
-- 
2.44.0

_______________________________________________
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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-20 23:35 [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS James Almer
@ 2024-03-21  4:00 ` Michael Niedermayer
  2024-03-21 11:15 ` Andreas Rheinhardt
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Niedermayer @ 2024-03-21  4:00 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 731 bytes --]

On Wed, Mar 20, 2024 at 08:35:25PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/hevc_ps.c     | 17 +++++++++++++++--
>  libavcodec/hevc_ps.h     |  2 +-
>  libavcodec/vulkan_hevc.c |  2 +-
>  3 files changed, 17 insertions(+), 4 deletions(-)

the 3 patches fix the timeout from (didnt test only the 3rd as it doesnt apply automatcially alone)
64033/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5332101272305664

feel free to apply

thx


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Good people do not need laws to tell them to act responsibly, while bad
people will find a way around the laws. -- Plato

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-20 23:35 [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS James Almer
  2024-03-21  4:00 ` Michael Niedermayer
@ 2024-03-21 11:15 ` Andreas Rheinhardt
  2024-03-21 12:11   ` James Almer
  1 sibling, 1 reply; 8+ messages in thread
From: Andreas Rheinhardt @ 2024-03-21 11:15 UTC (permalink / raw)
  To: ffmpeg-devel

James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/hevc_ps.c     | 17 +++++++++++++++--
>  libavcodec/hevc_ps.h     |  2 +-
>  libavcodec/vulkan_hevc.c |  2 +-
>  3 files changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index 20ceb09829..d3edc0810d 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -442,13 +442,21 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
>      return 0;
>  }
>  
> +static void uninit_vps(FFRefStructOpaque opaque, void *obj)
> +{
> +    HEVCVPS *vps = obj;
> +
> +    for (int i = 0; i < vps->vps_num_hrd_parameters; i++)
> +        ff_refstruct_unref(&vps->hdr[i]);
> +}
> +
>  int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>                             HEVCParamSets *ps)
>  {
>      int i,j;
>      int vps_id = 0;
>      ptrdiff_t nal_size;
> -    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
> +    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);
>  
>      if (!vps)
>          return AVERROR(ENOMEM);
> @@ -538,12 +546,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>              goto err;
>          }
>          for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
> +            HEVCHdrParams *hdr = ff_refstruct_allocz(sizeof(*hdr));
>              int common_inf_present = 1;
>  
> +            if (!hdr)
> +                return AVERROR(ENOMEM);
> +
>              get_ue_golomb_long(gb); // hrd_layer_set_idx
>              if (i)
>                  common_inf_present = get_bits1(gb);
> -            decode_hrd(gb, common_inf_present, &vps->hdr[i],
> +
> +            decode_hrd(gb, common_inf_present, hdr,
>                         vps->vps_max_sub_layers);
>          }

Why do you allocate the HEVCHdrParams separately when you know
vps_num_hrd_parameters before allocating the first one?

>      }
> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
> index 9cdec9b6c1..ff94f90a5e 100644
> --- a/libavcodec/hevc_ps.h
> +++ b/libavcodec/hevc_ps.h
> @@ -150,7 +150,7 @@ typedef struct PTL {
>  
>  typedef struct HEVCVPS {
>      unsigned int vps_id;
> -    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
> +    HEVCHdrParams *hdr[HEVC_MAX_LAYER_SETS];
>  
>      uint8_t vps_temporal_id_nesting_flag : 1;
>      uint8_t vps_sub_layer_ordering_info_present_flag : 1;
> diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
> index 239bff75e5..a89d09a372 100644
> --- a/libavcodec/vulkan_hevc.c
> +++ b/libavcodec/vulkan_hevc.c
> @@ -563,7 +563,7 @@ static void set_vps(const HEVCVPS *vps,
>                      HEVCHeaderVPSSet sls[])
>  {
>      for (int i = 0; i < vps->vps_num_hrd_parameters; i++) {
> -        const HEVCHdrParams *src = &vps->hdr[i];
> +        const HEVCHdrParams *src = vps->hdr[i];
>  
>          sls_hdr[i] = (StdVideoH265HrdParameters) {
>              .flags = (StdVideoH265HrdFlags) {

_______________________________________________
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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-21 11:15 ` Andreas Rheinhardt
@ 2024-03-21 12:11   ` James Almer
  2024-03-21 12:19     ` Andreas Rheinhardt
  0 siblings, 1 reply; 8+ messages in thread
From: James Almer @ 2024-03-21 12:11 UTC (permalink / raw)
  To: ffmpeg-devel

On 3/21/2024 8:15 AM, Andreas Rheinhardt wrote:
> James Almer:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavcodec/hevc_ps.c     | 17 +++++++++++++++--
>>   libavcodec/hevc_ps.h     |  2 +-
>>   libavcodec/vulkan_hevc.c |  2 +-
>>   3 files changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
>> index 20ceb09829..d3edc0810d 100644
>> --- a/libavcodec/hevc_ps.c
>> +++ b/libavcodec/hevc_ps.c
>> @@ -442,13 +442,21 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
>>       return 0;
>>   }
>>   
>> +static void uninit_vps(FFRefStructOpaque opaque, void *obj)
>> +{
>> +    HEVCVPS *vps = obj;
>> +
>> +    for (int i = 0; i < vps->vps_num_hrd_parameters; i++)
>> +        ff_refstruct_unref(&vps->hdr[i]);
>> +}
>> +
>>   int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>>                              HEVCParamSets *ps)
>>   {
>>       int i,j;
>>       int vps_id = 0;
>>       ptrdiff_t nal_size;
>> -    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
>> +    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);
>>   
>>       if (!vps)
>>           return AVERROR(ENOMEM);
>> @@ -538,12 +546,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>>               goto err;
>>           }
>>           for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
>> +            HEVCHdrParams *hdr = ff_refstruct_allocz(sizeof(*hdr));
>>               int common_inf_present = 1;
>>   
>> +            if (!hdr)
>> +                return AVERROR(ENOMEM);
>> +
>>               get_ue_golomb_long(gb); // hrd_layer_set_idx
>>               if (i)
>>                   common_inf_present = get_bits1(gb);
>> -            decode_hrd(gb, common_inf_present, &vps->hdr[i],
>> +
>> +            decode_hrd(gb, common_inf_present, hdr,
>>                          vps->vps_max_sub_layers);
>>           }
> 
> Why do you allocate the HEVCHdrParams separately when you know
> vps_num_hrd_parameters before allocating the first one?

You want me to allocate all of them with a single ff_refstruct_allocz() 
and store individual pointers for each?

> 
>>       }
>> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
>> index 9cdec9b6c1..ff94f90a5e 100644
>> --- a/libavcodec/hevc_ps.h
>> +++ b/libavcodec/hevc_ps.h
>> @@ -150,7 +150,7 @@ typedef struct PTL {
>>   
>>   typedef struct HEVCVPS {
>>       unsigned int vps_id;
>> -    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
>> +    HEVCHdrParams *hdr[HEVC_MAX_LAYER_SETS];
>>   
>>       uint8_t vps_temporal_id_nesting_flag : 1;
>>       uint8_t vps_sub_layer_ordering_info_present_flag : 1;
>> diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
>> index 239bff75e5..a89d09a372 100644
>> --- a/libavcodec/vulkan_hevc.c
>> +++ b/libavcodec/vulkan_hevc.c
>> @@ -563,7 +563,7 @@ static void set_vps(const HEVCVPS *vps,
>>                       HEVCHeaderVPSSet sls[])
>>   {
>>       for (int i = 0; i < vps->vps_num_hrd_parameters; i++) {
>> -        const HEVCHdrParams *src = &vps->hdr[i];
>> +        const HEVCHdrParams *src = vps->hdr[i];
>>   
>>           sls_hdr[i] = (StdVideoH265HrdParameters) {
>>               .flags = (StdVideoH265HrdFlags) {
> 
> _______________________________________________
> 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".
_______________________________________________
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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-21 12:11   ` James Almer
@ 2024-03-21 12:19     ` Andreas Rheinhardt
  2024-03-21 12:29       ` James Almer
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Rheinhardt @ 2024-03-21 12:19 UTC (permalink / raw)
  To: ffmpeg-devel

James Almer:
> On 3/21/2024 8:15 AM, Andreas Rheinhardt wrote:
>> James Almer:
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>>   libavcodec/hevc_ps.c     | 17 +++++++++++++++--
>>>   libavcodec/hevc_ps.h     |  2 +-
>>>   libavcodec/vulkan_hevc.c |  2 +-
>>>   3 files changed, 17 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
>>> index 20ceb09829..d3edc0810d 100644
>>> --- a/libavcodec/hevc_ps.c
>>> +++ b/libavcodec/hevc_ps.c
>>> @@ -442,13 +442,21 @@ static int decode_hrd(GetBitContext *gb, int
>>> common_inf_present,
>>>       return 0;
>>>   }
>>>   +static void uninit_vps(FFRefStructOpaque opaque, void *obj)
>>> +{
>>> +    HEVCVPS *vps = obj;
>>> +
>>> +    for (int i = 0; i < vps->vps_num_hrd_parameters; i++)
>>> +        ff_refstruct_unref(&vps->hdr[i]);
>>> +}
>>> +
>>>   int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>>>                              HEVCParamSets *ps)
>>>   {
>>>       int i,j;
>>>       int vps_id = 0;
>>>       ptrdiff_t nal_size;
>>> -    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
>>> +    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL,
>>> uninit_vps);
>>>         if (!vps)
>>>           return AVERROR(ENOMEM);
>>> @@ -538,12 +546,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb,
>>> AVCodecContext *avctx,
>>>               goto err;
>>>           }
>>>           for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
>>> +            HEVCHdrParams *hdr = ff_refstruct_allocz(sizeof(*hdr));
>>>               int common_inf_present = 1;
>>>   +            if (!hdr)
>>> +                return AVERROR(ENOMEM);
>>> +
>>>               get_ue_golomb_long(gb); // hrd_layer_set_idx
>>>               if (i)
>>>                   common_inf_present = get_bits1(gb);
>>> -            decode_hrd(gb, common_inf_present, &vps->hdr[i],
>>> +
>>> +            decode_hrd(gb, common_inf_present, hdr,
>>>                          vps->vps_max_sub_layers);
>>>           }
>>
>> Why do you allocate the HEVCHdrParams separately when you know
>> vps_num_hrd_parameters before allocating the first one?
> 
> You want me to allocate all of them with a single ff_refstruct_allocz()
> and store individual pointers for each?
> 

No, I want you to allocate them jointly and access them via "const
HEVCHdrParams *src = &vps->hdr[i]".
(Removing the individual pointers is precisely the point.)
Furthermore, there is no reason to allocate it via RefStruct. A simple
av_calloc() is enough (they have one owner: The containing HEVCVPS; that
said HEVCVPS can have multiple owners doesn't change this).

>>
>>>       }
>>> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
>>> index 9cdec9b6c1..ff94f90a5e 100644
>>> --- a/libavcodec/hevc_ps.h
>>> +++ b/libavcodec/hevc_ps.h
>>> @@ -150,7 +150,7 @@ typedef struct PTL {
>>>     typedef struct HEVCVPS {
>>>       unsigned int vps_id;
>>> -    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
>>> +    HEVCHdrParams *hdr[HEVC_MAX_LAYER_SETS];
>>>         uint8_t vps_temporal_id_nesting_flag : 1;
>>>       uint8_t vps_sub_layer_ordering_info_present_flag : 1;
>>> diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
>>> index 239bff75e5..a89d09a372 100644
>>> --- a/libavcodec/vulkan_hevc.c
>>> +++ b/libavcodec/vulkan_hevc.c
>>> @@ -563,7 +563,7 @@ static void set_vps(const HEVCVPS *vps,
>>>                       HEVCHeaderVPSSet sls[])
>>>   {
>>>       for (int i = 0; i < vps->vps_num_hrd_parameters; i++) {
>>> -        const HEVCHdrParams *src = &vps->hdr[i];
>>> +        const HEVCHdrParams *src = vps->hdr[i];
>>>             sls_hdr[i] = (StdVideoH265HrdParameters) {
>>>               .flags = (StdVideoH265HrdFlags) {
>>
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".

_______________________________________________
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] 8+ messages in thread

* [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-21 12:19     ` Andreas Rheinhardt
@ 2024-03-21 12:29       ` James Almer
  2024-03-21 12:54         ` Andreas Rheinhardt
  2024-03-27  7:41         ` Wu, Tong1
  0 siblings, 2 replies; 8+ messages in thread
From: James Almer @ 2024-03-21 12:29 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/hevc_ps.c | 14 +++++++++++++-
 libavcodec/hevc_ps.h |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index fb997066d9..d29cf9f372 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -438,13 +438,20 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
     return 0;
 }
 
+static void uninit_vps(FFRefStructOpaque opaque, void *obj)
+{
+    HEVCVPS *vps = obj;
+
+    av_freep(&vps->hdr);
+}
+
 int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
                            HEVCParamSets *ps)
 {
     int i,j;
     int vps_id = 0;
     ptrdiff_t nal_size;
-    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
+    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);
 
     if (!vps)
         return AVERROR(ENOMEM);
@@ -533,6 +540,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
                    "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters);
             goto err;
         }
+
+        vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
+        if (!vps->hdr)
+            goto err;
+
         for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
             int common_inf_present = 1;
 
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 786c896709..87cea479e9 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -152,7 +152,7 @@ typedef struct PTL {
 
 typedef struct HEVCVPS {
     unsigned int vps_id;
-    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
+    HEVCHdrParams *hdr;
 
     uint8_t vps_temporal_id_nesting_flag;
     int vps_max_layers;
-- 
2.44.0

_______________________________________________
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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-21 12:29       ` James Almer
@ 2024-03-21 12:54         ` Andreas Rheinhardt
  2024-03-27  7:41         ` Wu, Tong1
  1 sibling, 0 replies; 8+ messages in thread
From: Andreas Rheinhardt @ 2024-03-21 12:54 UTC (permalink / raw)
  To: ffmpeg-devel

James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/hevc_ps.c | 14 +++++++++++++-
>  libavcodec/hevc_ps.h |  2 +-
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index fb997066d9..d29cf9f372 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -438,13 +438,20 @@ static int decode_hrd(GetBitContext *gb, int common_inf_present,
>      return 0;
>  }
>  
> +static void uninit_vps(FFRefStructOpaque opaque, void *obj)
> +{
> +    HEVCVPS *vps = obj;
> +
> +    av_freep(&vps->hdr);
> +}
> +
>  int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>                             HEVCParamSets *ps)
>  {
>      int i,j;
>      int vps_id = 0;
>      ptrdiff_t nal_size;
> -    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
> +    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);
>  
>      if (!vps)
>          return AVERROR(ENOMEM);
> @@ -533,6 +540,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>                     "vps_num_hrd_parameters %d is invalid\n", vps->vps_num_hrd_parameters);
>              goto err;
>          }
> +
> +        vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
> +        if (!vps->hdr)
> +            goto err;
> +
>          for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
>              int common_inf_present = 1;
>  
> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
> index 786c896709..87cea479e9 100644
> --- a/libavcodec/hevc_ps.h
> +++ b/libavcodec/hevc_ps.h
> @@ -152,7 +152,7 @@ typedef struct PTL {
>  
>  typedef struct HEVCVPS {
>      unsigned int vps_id;
> -    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
> +    HEVCHdrParams *hdr;
>  
>      uint8_t vps_temporal_id_nesting_flag;
>      int vps_max_layers;

That's what I had in mind.

- 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] 8+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS
  2024-03-21 12:29       ` James Almer
  2024-03-21 12:54         ` Andreas Rheinhardt
@ 2024-03-27  7:41         ` Wu, Tong1
  1 sibling, 0 replies; 8+ messages in thread
From: Wu, Tong1 @ 2024-03-27  7:41 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


Hi James,

>From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of James
>Almer
>Sent: Thursday, March 21, 2024 8:29 PM
>To: ffmpeg-devel@ffmpeg.org
>Subject: [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required
>HEVCHdrParams within a VPS
>
>Signed-off-by: James Almer <jamrial@gmail.com>
>---
> libavcodec/hevc_ps.c | 14 +++++++++++++-
> libavcodec/hevc_ps.h |  2 +-
> 2 files changed, 14 insertions(+), 2 deletions(-)
>
>diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
>index fb997066d9..d29cf9f372 100644
>--- a/libavcodec/hevc_ps.c
>+++ b/libavcodec/hevc_ps.c
>@@ -438,13 +438,20 @@ static int decode_hrd(GetBitContext *gb, int
>common_inf_present,
>     return 0;
> }
>
>+static void uninit_vps(FFRefStructOpaque opaque, void *obj)
>+{
>+    HEVCVPS *vps = obj;
>+
>+    av_freep(&vps->hdr);
>+}
>+
> int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx,
>                            HEVCParamSets *ps)
> {
>     int i,j;
>     int vps_id = 0;
>     ptrdiff_t nal_size;
>-    HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps));
>+    HEVCVPS *vps = ff_refstruct_alloc_ext(sizeof(*vps), 0, NULL, uninit_vps);
>
>     if (!vps)
>         return AVERROR(ENOMEM);
>@@ -533,6 +540,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb,
>AVCodecContext *avctx,
>                    "vps_num_hrd_parameters %d is invalid\n", vps-
>>vps_num_hrd_parameters);
>             goto err;
>         }
>+
>+        vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr));
>+        if (!vps->hdr)
>+            goto err;
>+

It looks like this will cause the following !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps)) becomes 0 and furtherly remove_vps is called. Is that expected?

Thanks,
Tong


>         for (i = 0; i < vps->vps_num_hrd_parameters; i++) {
>             int common_inf_present = 1;
>
>diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
>index 786c896709..87cea479e9 100644
>--- a/libavcodec/hevc_ps.h
>+++ b/libavcodec/hevc_ps.h
>@@ -152,7 +152,7 @@ typedef struct PTL {
>
> typedef struct HEVCVPS {
>     unsigned int vps_id;
>-    HEVCHdrParams hdr[HEVC_MAX_LAYER_SETS];
>+    HEVCHdrParams *hdr;
>
>     uint8_t vps_temporal_id_nesting_flag;
>     int vps_max_layers;
>--
>2.44.0
>
>_______________________________________________
>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".
_______________________________________________
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] 8+ messages in thread

end of thread, other threads:[~2024-03-27  7:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 23:35 [FFmpeg-devel] [PATCH] avcodec/hevc_ps: allocate only the required HEVCHdrParams within a VPS James Almer
2024-03-21  4:00 ` Michael Niedermayer
2024-03-21 11:15 ` Andreas Rheinhardt
2024-03-21 12:11   ` James Almer
2024-03-21 12:19     ` Andreas Rheinhardt
2024-03-21 12:29       ` James Almer
2024-03-21 12:54         ` Andreas Rheinhardt
2024-03-27  7:41         ` Wu, Tong1

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