diff mbox

[FFmpeg-devel] avcodec/cbs_mpeg2: create a reference to the existing buffer when decomposing slice units

Message ID 20180427223610.10668-1-jamrial@gmail.com
State Accepted
Commit 65d36473c930b2cefaab96da8e514cd200330c94
Headers show

Commit Message

James Almer April 27, 2018, 10:36 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cbs_mpeg2.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Xiang, Haihao April 28, 2018, 8:10 a.m. UTC | #1
> 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 989daf0a4d..8ca47061fe 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);


How about adding an assertion to check unit->data_ref against NULL?

>          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 {
Mark Thompson April 30, 2018, 11:03 p.m. UTC | #2
On 27/04/18 23:36, James Almer wrote:
> 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 989daf0a4d..8ca47061fe 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 {
> 

LGTM.

Thanks,

- Mark
diff mbox

Patch

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 989daf0a4d..8ca47061fe 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 {