[09/14] avcodec/cbs_mpeg2: create a reference to the existing buffer when decomposing slice units

Message ID 20190504121427.9638-10-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 | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Alexandra Hájková May 13, 2019, 8:54 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 | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index 8974bcabac..d65d84bd3d 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -191,16 +191,11 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
>          len = unit->data_size;
>
>          slice->data_size = len - pos / 8;
> -        slice->data_ref  = av_buffer_alloc(slice->data_size +
> -                                           AV_INPUT_BUFFER_PADDING_SIZE);
> +        slice->data_ref  = av_buffer_ref(unit->data_ref);
>          if (!slice->data_ref)
>              return AVERROR(ENOMEM);
> -        slice->data = slice->data_ref->data;
> +        slice->data = unit->data + pos / 8;
>
> -        memcpy(slice->data,
> -               unit->data + pos / 8, slice->data_size);
> -        memset(slice->data + slice->data_size, 0,
> -               AV_INPUT_BUFFER_PADDING_SIZE);
>          slice->data_bit_start = pos % 8;
>
>      } else {
> --
> 2.12.2
>
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel

OK

Patch

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 8974bcabac..d65d84bd3d 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -191,16 +191,11 @@  static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
         len = unit->data_size;
 
         slice->data_size = len - pos / 8;
-        slice->data_ref  = av_buffer_alloc(slice->data_size +
-                                           AV_INPUT_BUFFER_PADDING_SIZE);
+        slice->data_ref  = av_buffer_ref(unit->data_ref);
         if (!slice->data_ref)
             return AVERROR(ENOMEM);
-        slice->data = slice->data_ref->data;
+        slice->data = unit->data + pos / 8;
 
-        memcpy(slice->data,
-               unit->data + pos / 8, slice->data_size);
-        memset(slice->data + slice->data_size, 0,
-               AV_INPUT_BUFFER_PADDING_SIZE);
         slice->data_bit_start = pos % 8;
 
     } else {