diff mbox series

[FFmpeg-devel,4/5] avcodec/h264dec: use the RefStruct API for h264db

Message ID 20241025022613.3921-4-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/5] Partially revert "avcodec/h2645: allocate film grain metadata dynamically" | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer Oct. 25, 2024, 2:26 a.m. UTC
And ensure the buffer is synced between threads.

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

Comments

Anton Khirnov Oct. 25, 2024, 8:17 a.m. UTC | #1
Quoting James Almer (2024-10-25 04:26:12)
> And ensure the buffer is synced between threads.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/h264_picture.c | 2 +-
>  libavcodec/h264_slice.c   | 2 ++
>  libavcodec/h264dec.c      | 2 +-
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
> index 371a794ec2..d07c3a0af8 100644
> --- a/libavcodec/h264_picture.c
> +++ b/libavcodec/h264_picture.c
> @@ -215,7 +215,7 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
>          err = AVERROR_INVALIDDATA;
>          if (sd) { // a decoding error may have happened before the side data could be allocated
>              if (!h->h274db) {
> -                h->h274db = av_mallocz(sizeof(*h->h274db));
> +                h->h274db = ff_refstruct_allocz(sizeof(*h->h274db));

Doesn't this happen after ff_thread_finish_setup()?
James Almer Oct. 25, 2024, 12:11 p.m. UTC | #2
On 10/25/2024 5:17 AM, Anton Khirnov wrote:
> Quoting James Almer (2024-10-25 04:26:12)
>> And ensure the buffer is synced between threads.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavcodec/h264_picture.c | 2 +-
>>   libavcodec/h264_slice.c   | 2 ++
>>   libavcodec/h264dec.c      | 2 +-
>>   3 files changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
>> index 371a794ec2..d07c3a0af8 100644
>> --- a/libavcodec/h264_picture.c
>> +++ b/libavcodec/h264_picture.c
>> @@ -215,7 +215,7 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
>>           err = AVERROR_INVALIDDATA;
>>           if (sd) { // a decoding error may have happened before the side data could be allocated
>>               if (!h->h274db) {
>> -                h->h274db = av_mallocz(sizeof(*h->h274db));
>> +                h->h274db = ff_refstruct_allocz(sizeof(*h->h274db));
> 
> Doesn't this happen after ff_thread_finish_setup()?

I have no idea. Currently, h274db is not being synced between threads, 
but i think that was also the case before 08b1bffa4971, so maybe this 
patch can be dropped.
diff mbox series

Patch

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index 371a794ec2..d07c3a0af8 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -215,7 +215,7 @@  int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
         err = AVERROR_INVALIDDATA;
         if (sd) { // a decoding error may have happened before the side data could be allocated
             if (!h->h274db) {
-                h->h274db = av_mallocz(sizeof(*h->h274db));
+                h->h274db = ff_refstruct_allocz(sizeof(*h->h274db));
                 if (!h->h274db)
                     return AVERROR(ENOMEM);
             }
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 84595b1a8b..b88545a075 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -445,6 +445,8 @@  int ff_h264_update_thread_context(AVCodecContext *dst,
     h->sei.common.mastering_display = h1->sei.common.mastering_display;
     h->sei.common.content_light = h1->sei.common.content_light;
 
+    ff_refstruct_replace(&h->h274db, h1->h274db);
+
     if (!h->cur_pic_ptr)
         return 0;
 
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index af0913ca2c..805732057a 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -156,7 +156,7 @@  void ff_h264_free_tables(H264Context *h)
     av_freep(&h->mb2b_xy);
     av_freep(&h->mb2br_xy);
 
-    av_freep(&h->h274db);
+    ff_refstruct_unref(&h->h274db);
 
     ff_refstruct_pool_uninit(&h->qscale_table_pool);
     ff_refstruct_pool_uninit(&h->mb_type_pool);