[FFmpeg-devel,2/2] avcodec/cbs_mpeg2: use existing buffer reference when splitting fragments

Submitted by James Almer on April 25, 2018, 10:42 p.m.

Details

Message ID 20180425224217.1936-2-jamrial@gmail.com
State New
Headers show

Commit Message

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

Comments

Mark Thompson April 26, 2018, 10:30 p.m.
On 25/04/18 23:42, 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 94b9591b21..30d2bb6fbf 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -146,16 +146,11 @@ 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);
> +                                      unit_data, unit_size, frag->data_ref);
>          if (err < 0) {
> -            av_freep(&unit_data);

Could remove the braces here too.

>              return err;
>          }
>  
> 

Much nicer :)  Both patches tested, LGTM.

Thanks,

- Mark
James Almer April 26, 2018, 11:07 p.m.
On 4/26/2018 7:30 PM, Mark Thompson wrote:
> On 25/04/18 23:42, 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 94b9591b21..30d2bb6fbf 100644
>> --- a/libavcodec/cbs_mpeg2.c
>> +++ b/libavcodec/cbs_mpeg2.c
>> @@ -146,16 +146,11 @@ 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);
>> +                                      unit_data, unit_size, frag->data_ref);
>>          if (err < 0) {
>> -            av_freep(&unit_data);
> 
> Could remove the braces here too.

Sure, changed.

> 
>>              return err;
>>          }
>>  
>>
> 
> Much nicer :)  Both patches tested, LGTM.
> 
> Thanks,

Pushed, thanks!

Patch hide | download patch | download mbox

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 94b9591b21..30d2bb6fbf 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -146,16 +146,11 @@  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);
+                                      unit_data, unit_size, frag->data_ref);
         if (err < 0) {
-            av_freep(&unit_data);
             return err;
         }