diff mbox series

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

Message ID 20210204191005.48190-47-jamrial@gmail.com
State New
Headers show
Series deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI
Related show

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 Feb. 4, 2021, 7:10 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 doc/examples/vaapi_encode.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
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;
 }