diff mbox

[FFmpeg-devel] avcodec/encode: remove usage of av_dup_packet()

Message ID 20171002021759.5460-1-jamrial@gmail.com
State Accepted
Commit a22c6a4796ca1f2cbee6784262515da876fbec22
Headers show

Commit Message

James Almer Oct. 2, 2017, 2:17 a.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/encode.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

wm4 Oct. 2, 2017, 9:44 a.m. UTC | #1
On Sun,  1 Oct 2017 23:17:59 -0300
James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/encode.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index 525ee1f5d6..dd50486bcf 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -222,10 +222,12 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
>              }
>              avpkt->buf      = user_pkt.buf;
>              avpkt->data     = user_pkt.data;
> -        } else {
> -            if (av_dup_packet(avpkt) < 0) {
> -                ret = AVERROR(ENOMEM);
> -            }
> +        } else if (!avpkt->buf) {
> +            AVPacket tmp = { 0 };
> +            ret = av_packet_ref(&tmp, avpkt);
> +            if (ret < 0)
> +                return ret;
> +            *avpkt = tmp;
>          }
>      }
>  
> @@ -318,10 +320,12 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
>              }
>              avpkt->buf      = user_pkt.buf;
>              avpkt->data     = user_pkt.data;
> -        } else {
> -            if (av_dup_packet(avpkt) < 0) {
> -                ret = AVERROR(ENOMEM);
> -            }
> +        } else if (!avpkt->buf) {
> +            AVPacket tmp = { 0 };
> +            ret = av_packet_ref(&tmp, avpkt);
> +            if (ret < 0)
> +                return ret;
> +            *avpkt = tmp;
>          }
>      }
>  

LGTM, isn't this legacy code though?
James Almer Oct. 2, 2017, 2:16 p.m. UTC | #2
On 10/2/2017 6:44 AM, wm4 wrote:
> On Sun,  1 Oct 2017 23:17:59 -0300
> James Almer <jamrial@gmail.com> wrote:
> 
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavcodec/encode.c | 20 ++++++++++++--------
>>  1 file changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
>> index 525ee1f5d6..dd50486bcf 100644
>> --- a/libavcodec/encode.c
>> +++ b/libavcodec/encode.c
>> @@ -222,10 +222,12 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
>>              }
>>              avpkt->buf      = user_pkt.buf;
>>              avpkt->data     = user_pkt.data;
>> -        } else {
>> -            if (av_dup_packet(avpkt) < 0) {
>> -                ret = AVERROR(ENOMEM);
>> -            }
>> +        } else if (!avpkt->buf) {
>> +            AVPacket tmp = { 0 };
>> +            ret = av_packet_ref(&tmp, avpkt);
>> +            if (ret < 0)
>> +                return ret;
>> +            *avpkt = tmp;
>>          }
>>      }
>>  
>> @@ -318,10 +320,12 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
>>              }
>>              avpkt->buf      = user_pkt.buf;
>>              avpkt->data     = user_pkt.data;
>> -        } else {
>> -            if (av_dup_packet(avpkt) < 0) {
>> -                ret = AVERROR(ENOMEM);
>> -            }
>> +        } else if (!avpkt->buf) {
>> +            AVPacket tmp = { 0 };
>> +            ret = av_packet_ref(&tmp, avpkt);
>> +            if (ret < 0)
>> +                return ret;
>> +            *avpkt = tmp;
>>          }
>>      }
>>  
> 
> LGTM, isn't this legacy code though?

Yes, but i don't know if av_dup_packet() will be gone before or at the
same time as the old decode API (which doesn't even seem to have
deprecation guards), so just to be sure i figured I'd remove it now
alongside every other use in the tree.

Pushed.
diff mbox

Patch

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 525ee1f5d6..dd50486bcf 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -222,10 +222,12 @@  int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
             }
             avpkt->buf      = user_pkt.buf;
             avpkt->data     = user_pkt.data;
-        } else {
-            if (av_dup_packet(avpkt) < 0) {
-                ret = AVERROR(ENOMEM);
-            }
+        } else if (!avpkt->buf) {
+            AVPacket tmp = { 0 };
+            ret = av_packet_ref(&tmp, avpkt);
+            if (ret < 0)
+                return ret;
+            *avpkt = tmp;
         }
     }
 
@@ -318,10 +320,12 @@  int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
             }
             avpkt->buf      = user_pkt.buf;
             avpkt->data     = user_pkt.data;
-        } else {
-            if (av_dup_packet(avpkt) < 0) {
-                ret = AVERROR(ENOMEM);
-            }
+        } else if (!avpkt->buf) {
+            AVPacket tmp = { 0 };
+            ret = av_packet_ref(&tmp, avpkt);
+            if (ret < 0)
+                return ret;
+            *avpkt = tmp;
         }
     }