diff mbox series

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

Message ID 20201118130517.585-2-git@gpost.dk
State New
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/cbs_av1.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 9badfe31e4..cf680aed6c 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -896,12 +896,11 @@  static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
             if (err < 0)
                 return err;
 
-            av_buffer_unref(&priv->sequence_header_ref);
-            priv->sequence_header = NULL;
-
-            priv->sequence_header_ref = av_buffer_ref(unit->content_ref);
-            if (!priv->sequence_header_ref)
-                return AVERROR(ENOMEM);
+            err = av_buffer_replace(&priv->sequence_header_ref, unit->content_ref);
+            if (err < 0) {
+                priv->sequence_header = NULL;
+                return err;
+            }
             priv->sequence_header = &obu->obu.sequence_header;
         }
         break;
@@ -1039,12 +1038,11 @@  static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
             if (err < 0)
                 return err;
 
-            av_buffer_unref(&priv->sequence_header_ref);
-            priv->sequence_header = NULL;
-
-            priv->sequence_header_ref = av_buffer_ref(unit->content_ref);
-            if (!priv->sequence_header_ref)
-                return AVERROR(ENOMEM);
+            err = av_buffer_replace(&priv->sequence_header_ref, unit->content_ref);
+            if (err < 0) {
+                priv->sequence_header = NULL;
+                return err;
+            }
             priv->sequence_header = &obu->obu.sequence_header;
         }
         break;