[07/14] avcodec/cbs_mpeg2: use existing buffer reference when splitting fragments

Message ID 20190504121427.9638-8-lu_zero@gentoo.org
State New
Headers show
Series
  • [01/14] maint: Ignore dot dirs
Related show

Commit Message

Luca Barbato May 4, 2019, 12:14 p.m.
From: James Almer <jamrial@gmail.com>

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_mpeg2.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Alexandra Hájková May 13, 2019, 8:47 a.m. | #1
On Sat, May 4, 2019 at 2:15 PM Luca Barbato <lu_zero@gentoo.org> wrote:
>
> From: James Almer <jamrial@gmail.com>
>
> Reviewed-by: Mark Thompson <sw@jkqxz.net>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/cbs_mpeg2.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index 7f484267fa..8974bcabac 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -146,18 +146,12 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
>              unit_size = (end - 4) - (start - 1);
>          }
>
> -        unit_data = av_malloc(unit_size + AV_INPUT_BUFFER_PADDING_SIZE);
> -        if (!unit_data)
> -            return AVERROR(ENOMEM);
> -        memcpy(unit_data, start - 1, unit_size);
> -        memset(unit_data + unit_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> +        unit_data = (uint8_t *)start - 1;
>
>          err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type,
> -                                      unit_data, unit_size, NULL);
> -        if (err < 0) {
> -            av_freep(&unit_data);
> +                                      unit_data, unit_size, frag->data_ref);
> +        if (err < 0)
>              return err;
> -        }
>
>          if (end == frag->data + frag->data_size)
>              break;
> --
> 2.12.2
>
OK

Patch

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 7f484267fa..8974bcabac 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -146,18 +146,12 @@  static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
             unit_size = (end - 4) - (start - 1);
         }
 
-        unit_data = av_malloc(unit_size + AV_INPUT_BUFFER_PADDING_SIZE);
-        if (!unit_data)
-            return AVERROR(ENOMEM);
-        memcpy(unit_data, start - 1, unit_size);
-        memset(unit_data + unit_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+        unit_data = (uint8_t *)start - 1;
 
         err = ff_cbs_insert_unit_data(ctx, frag, i, unit_type,
-                                      unit_data, unit_size, NULL);
-        if (err < 0) {
-            av_freep(&unit_data);
+                                      unit_data, unit_size, frag->data_ref);
+        if (err < 0)
             return err;
-        }
 
         if (end == frag->data + frag->data_size)
             break;