diff mbox series

[FFmpeg-devel,5/6] avcodec/wavpack: use av_buffer_replace() to simplify code

Message ID 20201118130517.585-6-git@gpost.dk
State Accepted
Commit abcca6a055919916fcd199c6e40d5102a3de4a70
Headers show
Series Use av_buffer_replace()
Related show

Checks

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

Commit Message

Gil Pedersen Nov. 18, 2020, 1:05 p.m. UTC
Signed-off-by: Gil Pedersen <git@gpost.dk>
---
 libavcodec/wavpack.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Anton Khirnov Nov. 19, 2020, 7:40 a.m. UTC | #1
Quoting Gil Pedersen (2020-11-18 14:05:16)
> Signed-off-by: Gil Pedersen <git@gpost.dk>
> ---
>  libavcodec/wavpack.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
> index f77548e5a5..58122c948c 100644
> --- a/libavcodec/wavpack.c
> +++ b/libavcodec/wavpack.c
> @@ -1024,13 +1024,12 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
>              return ret;
>      }
>  
> -    av_buffer_unref(&fdst->dsd_ref);
>      fdst->dsdctx = NULL;
>      fdst->dsd_channels = 0;
> +    ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
> +    if (ret < 0)
> +        return ret;
>      if (fsrc->dsd_ref) {
> -        fdst->dsd_ref = av_buffer_ref(fsrc->dsd_ref);
> -        if (!fdst->dsd_ref)
> -            return AVERROR(ENOMEM);
>          fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
>          fdst->dsd_channels = fsrc->dsd_channels;
>      }
> -- 
> 2.17.1

Ok.
James Almer Nov. 19, 2020, 1:14 p.m. UTC | #2
On 11/19/2020 4:40 AM, Anton Khirnov wrote:
> Quoting Gil Pedersen (2020-11-18 14:05:16)
>> Signed-off-by: Gil Pedersen <git@gpost.dk>
>> ---
>>   libavcodec/wavpack.c | 7 +++----
>>   1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
>> index f77548e5a5..58122c948c 100644
>> --- a/libavcodec/wavpack.c
>> +++ b/libavcodec/wavpack.c
>> @@ -1024,13 +1024,12 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
>>               return ret;
>>       }
>>   
>> -    av_buffer_unref(&fdst->dsd_ref);
>>       fdst->dsdctx = NULL;
>>       fdst->dsd_channels = 0;
>> +    ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
>> +    if (ret < 0)
>> +        return ret;
>>       if (fsrc->dsd_ref) {
>> -        fdst->dsd_ref = av_buffer_ref(fsrc->dsd_ref);
>> -        if (!fdst->dsd_ref)
>> -            return AVERROR(ENOMEM);
>>           fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
>>           fdst->dsd_channels = fsrc->dsd_channels;
>>       }
>> -- 
>> 2.17.1
> 
> Ok.

Applied.
diff mbox series

Patch

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index f77548e5a5..58122c948c 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1024,13 +1024,12 @@  static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
             return ret;
     }
 
-    av_buffer_unref(&fdst->dsd_ref);
     fdst->dsdctx = NULL;
     fdst->dsd_channels = 0;
+    ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
+    if (ret < 0)
+        return ret;
     if (fsrc->dsd_ref) {
-        fdst->dsd_ref = av_buffer_ref(fsrc->dsd_ref);
-        if (!fdst->dsd_ref)
-            return AVERROR(ENOMEM);
         fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
         fdst->dsd_channels = fsrc->dsd_channels;
     }