diff mbox series

[FFmpeg-devel,11/11] examples/qsvdec: Don't use stack packet

Message ID AM7PR03MB66607BFF4EBFE0E96CE9B05D8FCF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 3, 2021, 11:18 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 doc/examples/qsvdec.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/qsvdec.c b/doc/examples/qsvdec.c
index 571d868f93..b662ae91c3 100644
--- a/doc/examples/qsvdec.c
+++ b/doc/examples/qsvdec.c
@@ -113,7 +113,7 @@  int main(int argc, char **argv)
     AVCodecContext *decoder_ctx = NULL;
     const AVCodec *decoder;
 
-    AVPacket pkt = { 0 };
+    AVPacket *pkt = NULL;
     AVFrame *frame = NULL, *sw_frame = NULL;
 
     AVIOContext *output_ctx = NULL;
@@ -200,27 +200,26 @@  int main(int argc, char **argv)
 
     frame    = av_frame_alloc();
     sw_frame = av_frame_alloc();
-    if (!frame || !sw_frame) {
+    pkt      = av_packet_alloc();
+    if (!frame || !sw_frame || !pkt) {
         ret = AVERROR(ENOMEM);
         goto finish;
     }
 
     /* actual decoding */
     while (ret >= 0) {
-        ret = av_read_frame(input_ctx, &pkt);
+        ret = av_read_frame(input_ctx, pkt);
         if (ret < 0)
             break;
 
-        if (pkt.stream_index == video_st->index)
-            ret = decode_packet(decoder_ctx, frame, sw_frame, &pkt, output_ctx);
+        if (pkt->stream_index == video_st->index)
+            ret = decode_packet(decoder_ctx, frame, sw_frame, pkt, output_ctx);
 
-        av_packet_unref(&pkt);
+        av_packet_unref(pkt);
     }
 
     /* flush the decoder */
-    pkt.data = NULL;
-    pkt.size = 0;
-    ret = decode_packet(decoder_ctx, frame, sw_frame, &pkt, output_ctx);
+    ret = decode_packet(decoder_ctx, frame, sw_frame, NULL, output_ctx);
 
 finish:
     if (ret < 0) {
@@ -233,6 +232,7 @@  finish:
 
     av_frame_free(&frame);
     av_frame_free(&sw_frame);
+    av_packet_free(&pkt);
 
     avcodec_free_context(&decoder_ctx);