[FFmpeg-cvslog] tests/api/api-flac-test: use av_packet_alloc() to allocate packets

James Almer git at videolan.org
Wed Mar 17 21:17:29 EET 2021


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Jan 31 13:28:43 2021 -0300| [7643a354741e54444a9abb08ee2727ec510bcc3f] | committer: James Almer

tests/api/api-flac-test: use av_packet_alloc() to allocate packets

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7643a354741e54444a9abb08ee2727ec510bcc3f
---

 tests/api/api-flac-test.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/tests/api/api-flac-test.c b/tests/api/api-flac-test.c
index b67c3d7363..f3bfbc95b5 100644
--- a/tests/api/api-flac-test.c
+++ b/tests/api/api-flac-test.c
@@ -108,7 +108,7 @@ static int init_decoder(AVCodec *dec, AVCodecContext **dec_ctx,
 static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
                     AVCodecContext *dec_ctx)
 {
-    AVPacket enc_pkt;
+    AVPacket *enc_pkt;
     AVFrame *in_frame, *out_frame;
     uint8_t *raw_in = NULL, *raw_out = NULL;
     int in_offset = 0, out_offset = 0;
@@ -116,6 +116,12 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
     int i = 0;
     int in_frame_bytes, out_frame_bytes;
 
+    enc_pkt = av_packet_alloc();
+    if (!enc_pkt) {
+        av_log(NULL, AV_LOG_ERROR, "Can't allocate output packet\n");
+        return AVERROR(ENOMEM);
+    }
+
     in_frame = av_frame_alloc();
     if (!in_frame) {
         av_log(NULL, AV_LOG_ERROR, "Can't allocate input frame\n");
@@ -149,10 +155,6 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
     }
 
     for (i = 0; i < NUMBER_OF_AUDIO_FRAMES; i++) {
-        av_init_packet(&enc_pkt);
-        enc_pkt.data = NULL;
-        enc_pkt.size = 0;
-
         result = av_frame_make_writable(in_frame);
         if (result < 0)
             return result;
@@ -173,7 +175,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
         }
 
         while (result >= 0) {
-            result = avcodec_receive_packet(enc_ctx, &enc_pkt);
+            result = avcodec_receive_packet(enc_ctx, enc_pkt);
             if (result == AVERROR(EAGAIN))
                 break;
             else if (result < 0 && result != AVERROR_EOF) {
@@ -182,8 +184,8 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
             }
 
             /* if we get an encoded packet, feed it straight to the decoder */
-            result = avcodec_send_packet(dec_ctx, &enc_pkt);
-            av_packet_unref(&enc_pkt);
+            result = avcodec_send_packet(dec_ctx, enc_pkt);
+            av_packet_unref(enc_pkt);
             if (result < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
                 return result;
@@ -234,6 +236,7 @@ static int run_test(AVCodec *enc, AVCodec *dec, AVCodecContext *enc_ctx,
 
     av_freep(&raw_in);
     av_freep(&raw_out);
+    av_packet_free(&enc_pkt);
     av_frame_free(&in_frame);
     av_frame_free(&out_frame);
     return 0;



More information about the ffmpeg-cvslog mailing list