diff mbox series

[FFmpeg-devel,45/48] doc/examples/vaapi_encode: use av_packet_alloc() to allocate packets

Message ID 20210305163339.63164-46-jamrial@gmail.com
State New
Headers show
Series deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer March 5, 2021, 4:33 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 doc/examples/vaapi_encode.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Michael Niedermayer March 6, 2021, 9:35 p.m. UTC | #1
On Fri, Mar 05, 2021 at 01:33:36PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  doc/examples/vaapi_encode.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
> index 707939db37..66cb949cdc 100644
> --- a/doc/examples/vaapi_encode.c
> +++ b/doc/examples/vaapi_encode.c
> @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
>  static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
>  {
>      int ret = 0;
> -    AVPacket enc_pkt;
> +    AVPacket *enc_pkt;
>  
> -    av_init_packet(&enc_pkt);
> -    enc_pkt.data = NULL;
> -    enc_pkt.size = 0;
> +    if (!(enc_pkt = av_packet_alloc()))
> +        return AVERROR(ENOMEM);
>  
>      if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
>          fprintf(stderr, "Error code: %s\n", av_err2str(ret));
>          goto end;
>      }
>      while (1) {
> -        ret = avcodec_receive_packet(avctx, &enc_pkt);
> +        ret = avcodec_receive_packet(avctx, enc_pkt);
>          if (ret)
>              break;
>  
> -        enc_pkt.stream_index = 0;
> -        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
> -        av_packet_unref(&enc_pkt);
> +        enc_pkt->stream_index = 0;
> +        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
> +        av_packet_unref(enc_pkt);
>      }
>  
>  end:
> +    av_packet_free(&enc_pkt);
>      ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
>      return ret;
>  }

breaks: 
doc/examples/vaapi_encode.c: In function ‘encode_write’:
doc/examples/vaapi_encode.c:92:29: error: ‘enc_pkt’ is a pointer; did you mean to use ‘->’?
         ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
                             ^
                             ->
ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_encode.o' failed
make: *** [doc/examples/vaapi_encode.o] Error 1
make: *** Waiting for unfinished jobs....

[...]
James Almer March 6, 2021, 9:45 p.m. UTC | #2
On 3/6/2021 6:35 PM, Michael Niedermayer wrote:
> On Fri, Mar 05, 2021 at 01:33:36PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   doc/examples/vaapi_encode.c | 16 ++++++++--------
>>   1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
>> index 707939db37..66cb949cdc 100644
>> --- a/doc/examples/vaapi_encode.c
>> +++ b/doc/examples/vaapi_encode.c
>> @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
>>   static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
>>   {
>>       int ret = 0;
>> -    AVPacket enc_pkt;
>> +    AVPacket *enc_pkt;
>>   
>> -    av_init_packet(&enc_pkt);
>> -    enc_pkt.data = NULL;
>> -    enc_pkt.size = 0;
>> +    if (!(enc_pkt = av_packet_alloc()))
>> +        return AVERROR(ENOMEM);
>>   
>>       if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
>>           fprintf(stderr, "Error code: %s\n", av_err2str(ret));
>>           goto end;
>>       }
>>       while (1) {
>> -        ret = avcodec_receive_packet(avctx, &enc_pkt);
>> +        ret = avcodec_receive_packet(avctx, enc_pkt);
>>           if (ret)
>>               break;
>>   
>> -        enc_pkt.stream_index = 0;
>> -        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
>> -        av_packet_unref(&enc_pkt);
>> +        enc_pkt->stream_index = 0;
>> +        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
>> +        av_packet_unref(enc_pkt);
>>       }
>>   
>>   end:
>> +    av_packet_free(&enc_pkt);
>>       ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
>>       return ret;
>>   }
> 
> breaks:
> doc/examples/vaapi_encode.c: In function ‘encode_write’:
> doc/examples/vaapi_encode.c:92:29: error: ‘enc_pkt’ is a pointer; did you mean to use ‘->’?
>           ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
>                               ^
>                               ->
> ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_encode.o' failed
> make: *** [doc/examples/vaapi_encode.o] Error 1
> make: *** Waiting for unfinished jobs....

Fixed locally. Thanks.
Michael Niedermayer March 10, 2021, 8:22 p.m. UTC | #3
On Sat, Mar 06, 2021 at 06:45:57PM -0300, James Almer wrote:
> On 3/6/2021 6:35 PM, Michael Niedermayer wrote:
> > On Fri, Mar 05, 2021 at 01:33:36PM -0300, James Almer wrote:
> > > Signed-off-by: James Almer <jamrial@gmail.com>
> > > ---
> > >   doc/examples/vaapi_encode.c | 16 ++++++++--------
> > >   1 file changed, 8 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
> > > index 707939db37..66cb949cdc 100644
> > > --- a/doc/examples/vaapi_encode.c
> > > +++ b/doc/examples/vaapi_encode.c
> > > @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
> > >   static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
> > >   {
> > >       int ret = 0;
> > > -    AVPacket enc_pkt;
> > > +    AVPacket *enc_pkt;
> > > -    av_init_packet(&enc_pkt);
> > > -    enc_pkt.data = NULL;
> > > -    enc_pkt.size = 0;
> > > +    if (!(enc_pkt = av_packet_alloc()))
> > > +        return AVERROR(ENOMEM);
> > >       if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
> > >           fprintf(stderr, "Error code: %s\n", av_err2str(ret));
> > >           goto end;
> > >       }
> > >       while (1) {
> > > -        ret = avcodec_receive_packet(avctx, &enc_pkt);
> > > +        ret = avcodec_receive_packet(avctx, enc_pkt);
> > >           if (ret)
> > >               break;
> > > -        enc_pkt.stream_index = 0;
> > > -        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
> > > -        av_packet_unref(&enc_pkt);
> > > +        enc_pkt->stream_index = 0;
> > > +        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
> > > +        av_packet_unref(enc_pkt);
> > >       }
> > >   end:
> > > +    av_packet_free(&enc_pkt);
> > >       ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
> > >       return ret;
> > >   }
> > 
> > breaks:
> > doc/examples/vaapi_encode.c: In function ‘encode_write’:
> > doc/examples/vaapi_encode.c:92:29: error: ‘enc_pkt’ is a pointer; did you mean to use ‘->’?
> >           ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
> >                               ^
> >                               ->
> > ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_encode.o' failed
> > make: *** [doc/examples/vaapi_encode.o] Error 1
> > make: *** Waiting for unfinished jobs....
> 
> Fixed locally. Thanks.

do you have a public git tree for testing such minor changes ?
so i can retest the update set easily 

thanks

[...]
James Almer March 10, 2021, 9:25 p.m. UTC | #4
On 3/10/2021 5:22 PM, Michael Niedermayer wrote:
> On Sat, Mar 06, 2021 at 06:45:57PM -0300, James Almer wrote:
>> On 3/6/2021 6:35 PM, Michael Niedermayer wrote:
>>> On Fri, Mar 05, 2021 at 01:33:36PM -0300, James Almer wrote:
>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>> ---
>>>>    doc/examples/vaapi_encode.c | 16 ++++++++--------
>>>>    1 file changed, 8 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
>>>> index 707939db37..66cb949cdc 100644
>>>> --- a/doc/examples/vaapi_encode.c
>>>> +++ b/doc/examples/vaapi_encode.c
>>>> @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
>>>>    static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
>>>>    {
>>>>        int ret = 0;
>>>> -    AVPacket enc_pkt;
>>>> +    AVPacket *enc_pkt;
>>>> -    av_init_packet(&enc_pkt);
>>>> -    enc_pkt.data = NULL;
>>>> -    enc_pkt.size = 0;
>>>> +    if (!(enc_pkt = av_packet_alloc()))
>>>> +        return AVERROR(ENOMEM);
>>>>        if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
>>>>            fprintf(stderr, "Error code: %s\n", av_err2str(ret));
>>>>            goto end;
>>>>        }
>>>>        while (1) {
>>>> -        ret = avcodec_receive_packet(avctx, &enc_pkt);
>>>> +        ret = avcodec_receive_packet(avctx, enc_pkt);
>>>>            if (ret)
>>>>                break;
>>>> -        enc_pkt.stream_index = 0;
>>>> -        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
>>>> -        av_packet_unref(&enc_pkt);
>>>> +        enc_pkt->stream_index = 0;
>>>> +        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
>>>> +        av_packet_unref(enc_pkt);
>>>>        }
>>>>    end:
>>>> +    av_packet_free(&enc_pkt);
>>>>        ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
>>>>        return ret;
>>>>    }
>>>
>>> breaks:
>>> doc/examples/vaapi_encode.c: In function ‘encode_write’:
>>> doc/examples/vaapi_encode.c:92:29: error: ‘enc_pkt’ is a pointer; did you mean to use ‘->’?
>>>            ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
>>>                                ^
>>>                                ->
>>> ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_encode.o' failed
>>> make: *** [doc/examples/vaapi_encode.o] Error 1
>>> make: *** Waiting for unfinished jobs....
>>
>> Fixed locally. Thanks.
> 
> do you have a public git tree for testing such minor changes ?
> so i can retest the update set easily
> 
> thanks

Yes, pushed it to

https://github.com/jamrial/FFmpeg/commits/avpacket
Michael Niedermayer March 11, 2021, 1:34 p.m. UTC | #5
On Wed, Mar 10, 2021 at 06:25:58PM -0300, James Almer wrote:
> On 3/10/2021 5:22 PM, Michael Niedermayer wrote:
> > On Sat, Mar 06, 2021 at 06:45:57PM -0300, James Almer wrote:
> > > On 3/6/2021 6:35 PM, Michael Niedermayer wrote:
> > > > On Fri, Mar 05, 2021 at 01:33:36PM -0300, James Almer wrote:
> > > > > Signed-off-by: James Almer <jamrial@gmail.com>
> > > > > ---
> > > > >    doc/examples/vaapi_encode.c | 16 ++++++++--------
> > > > >    1 file changed, 8 insertions(+), 8 deletions(-)
> > > > > 
> > > > > diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
> > > > > index 707939db37..66cb949cdc 100644
> > > > > --- a/doc/examples/vaapi_encode.c
> > > > > +++ b/doc/examples/vaapi_encode.c
> > > > > @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
> > > > >    static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
> > > > >    {
> > > > >        int ret = 0;
> > > > > -    AVPacket enc_pkt;
> > > > > +    AVPacket *enc_pkt;
> > > > > -    av_init_packet(&enc_pkt);
> > > > > -    enc_pkt.data = NULL;
> > > > > -    enc_pkt.size = 0;
> > > > > +    if (!(enc_pkt = av_packet_alloc()))
> > > > > +        return AVERROR(ENOMEM);
> > > > >        if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
> > > > >            fprintf(stderr, "Error code: %s\n", av_err2str(ret));
> > > > >            goto end;
> > > > >        }
> > > > >        while (1) {
> > > > > -        ret = avcodec_receive_packet(avctx, &enc_pkt);
> > > > > +        ret = avcodec_receive_packet(avctx, enc_pkt);
> > > > >            if (ret)
> > > > >                break;
> > > > > -        enc_pkt.stream_index = 0;
> > > > > -        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
> > > > > -        av_packet_unref(&enc_pkt);
> > > > > +        enc_pkt->stream_index = 0;
> > > > > +        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
> > > > > +        av_packet_unref(enc_pkt);
> > > > >        }
> > > > >    end:
> > > > > +    av_packet_free(&enc_pkt);
> > > > >        ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
> > > > >        return ret;
> > > > >    }
> > > > 
> > > > breaks:
> > > > doc/examples/vaapi_encode.c: In function ‘encode_write’:
> > > > doc/examples/vaapi_encode.c:92:29: error: ‘enc_pkt’ is a pointer; did you mean to use ‘->’?
> > > >            ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
> > > >                                ^
> > > >                                ->
> > > > ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_encode.o' failed
> > > > make: *** [doc/examples/vaapi_encode.o] Error 1
> > > > make: *** Waiting for unfinished jobs....
> > > 
> > > Fixed locally. Thanks.
> > 
> > do you have a public git tree for testing such minor changes ?
> > so i can retest the update set easily
> > 
> > thanks
> 
> Yes, pushed it to
> 
> https://github.com/jamrial/FFmpeg/commits/avpacket

seems to work now, thanks

[...]
James Almer March 16, 2021, 2:07 p.m. UTC | #6
On 3/11/2021 10:34 AM, Michael Niedermayer wrote:
> On Wed, Mar 10, 2021 at 06:25:58PM -0300, James Almer wrote:
>> On 3/10/2021 5:22 PM, Michael Niedermayer wrote:
>>> On Sat, Mar 06, 2021 at 06:45:57PM -0300, James Almer wrote:
>>>> On 3/6/2021 6:35 PM, Michael Niedermayer wrote:
>>>>> On Fri, Mar 05, 2021 at 01:33:36PM -0300, James Almer wrote:
>>>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>>>> ---
>>>>>>     doc/examples/vaapi_encode.c | 16 ++++++++--------
>>>>>>     1 file changed, 8 insertions(+), 8 deletions(-)
>>>>>>
>>>>>> diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
>>>>>> index 707939db37..66cb949cdc 100644
>>>>>> --- a/doc/examples/vaapi_encode.c
>>>>>> +++ b/doc/examples/vaapi_encode.c
>>>>>> @@ -74,27 +74,27 @@ static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
>>>>>>     static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
>>>>>>     {
>>>>>>         int ret = 0;
>>>>>> -    AVPacket enc_pkt;
>>>>>> +    AVPacket *enc_pkt;
>>>>>> -    av_init_packet(&enc_pkt);
>>>>>> -    enc_pkt.data = NULL;
>>>>>> -    enc_pkt.size = 0;
>>>>>> +    if (!(enc_pkt = av_packet_alloc()))
>>>>>> +        return AVERROR(ENOMEM);
>>>>>>         if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
>>>>>>             fprintf(stderr, "Error code: %s\n", av_err2str(ret));
>>>>>>             goto end;
>>>>>>         }
>>>>>>         while (1) {
>>>>>> -        ret = avcodec_receive_packet(avctx, &enc_pkt);
>>>>>> +        ret = avcodec_receive_packet(avctx, enc_pkt);
>>>>>>             if (ret)
>>>>>>                 break;
>>>>>> -        enc_pkt.stream_index = 0;
>>>>>> -        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
>>>>>> -        av_packet_unref(&enc_pkt);
>>>>>> +        enc_pkt->stream_index = 0;
>>>>>> +        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
>>>>>> +        av_packet_unref(enc_pkt);
>>>>>>         }
>>>>>>     end:
>>>>>> +    av_packet_free(&enc_pkt);
>>>>>>         ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
>>>>>>         return ret;
>>>>>>     }
>>>>>
>>>>> breaks:
>>>>> doc/examples/vaapi_encode.c: In function ‘encode_write’:
>>>>> doc/examples/vaapi_encode.c:92:29: error: ‘enc_pkt’ is a pointer; did you mean to use ‘->’?
>>>>>             ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
>>>>>                                 ^
>>>>>                                 ->
>>>>> ffbuild/common.mak:67: recipe for target 'doc/examples/vaapi_encode.o' failed
>>>>> make: *** [doc/examples/vaapi_encode.o] Error 1
>>>>> make: *** Waiting for unfinished jobs....
>>>>
>>>> Fixed locally. Thanks.
>>>
>>> do you have a public git tree for testing such minor changes ?
>>> so i can retest the update set easily
>>>
>>> thanks
>>
>> Yes, pushed it to
>>
>> https://github.com/jamrial/FFmpeg/commits/avpacket
> 
> seems to work now, thanks

Will rebase and apply the patchset soon, then, so we can release 4.4 
after it.
diff mbox series

Patch

diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c
index 707939db37..66cb949cdc 100644
--- a/doc/examples/vaapi_encode.c
+++ b/doc/examples/vaapi_encode.c
@@ -74,27 +74,27 @@  static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx)
 static int encode_write(AVCodecContext *avctx, AVFrame *frame, FILE *fout)
 {
     int ret = 0;
-    AVPacket enc_pkt;
+    AVPacket *enc_pkt;
 
-    av_init_packet(&enc_pkt);
-    enc_pkt.data = NULL;
-    enc_pkt.size = 0;
+    if (!(enc_pkt = av_packet_alloc()))
+        return AVERROR(ENOMEM);
 
     if ((ret = avcodec_send_frame(avctx, frame)) < 0) {
         fprintf(stderr, "Error code: %s\n", av_err2str(ret));
         goto end;
     }
     while (1) {
-        ret = avcodec_receive_packet(avctx, &enc_pkt);
+        ret = avcodec_receive_packet(avctx, enc_pkt);
         if (ret)
             break;
 
-        enc_pkt.stream_index = 0;
-        ret = fwrite(enc_pkt.data, enc_pkt.size, 1, fout);
-        av_packet_unref(&enc_pkt);
+        enc_pkt->stream_index = 0;
+        ret = fwrite(enc_pkt.data, enc_pkt->size, 1, fout);
+        av_packet_unref(enc_pkt);
     }
 
 end:
+    av_packet_free(&enc_pkt);
     ret = ((ret == AVERROR(EAGAIN)) ? 0 : -1);
     return ret;
 }