diff mbox series

[FFmpeg-devel,05/10] avcodec/crystalhd: Use AVCodecInternal.in_pkt instead of stack packet

Message ID AM7PR03MB66601069D72033BDE04577188FB59@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 9b851c4b92b7c55ec9d626b729350a5761aef183
Headers show
Series [FFmpeg-devel,01/10] avcodec/binkaudio: Remove AV_CODEC_CAP_DELAY | expand

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 Oct. 11, 2021, 3:36 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/crystalhd.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c
index 0238ab7378..9202a16a77 100644
--- a/libavcodec/crystalhd.c
+++ b/libavcodec/crystalhd.c
@@ -90,6 +90,9 @@  typedef struct OpaqueList {
 typedef struct {
     AVClass *av_class;
     AVCodecContext *avctx;
+    /* This packet coincides with AVCodecInternal.in_pkt
+     * and is not owned by us. */
+    AVPacket *pkt;
     HANDLE dev;
 
     uint8_t is_70012;
@@ -328,6 +331,7 @@  static av_cold int init(AVCodecContext *avctx)
     /* Initialize the library */
     priv               = avctx->priv_data;
     priv->avctx        = avctx;
+    priv->pkt          = avctx->internal->in_pkt;
     priv->draining     = 0;
 
     subtype = id2subtype(priv, avctx->codec->id);
@@ -703,19 +707,19 @@  static int crystalhd_receive_frame(AVCodecContext *avctx, AVFrame *frame)
     BC_DTS_STATUS decoder_status = { 0, };
     CopyRet rec_ret;
     CHDContext *priv   = avctx->priv_data;
+    AVPacket *const pkt = priv->pkt;
     HANDLE dev         = priv->dev;
     int got_frame = 0;
     int ret = 0;
-    AVPacket pkt = {0};
 
     av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: receive_frame\n");
 
-    ret = ff_decode_get_packet(avctx, &pkt);
+    ret = ff_decode_get_packet(avctx, pkt);
     if (ret < 0 && ret != AVERROR_EOF) {
         return ret;
     }
 
-    while (pkt.size > DtsTxFreeSize(dev)) {
+    while (pkt->size > DtsTxFreeSize(dev)) {
         /*
          * Block until there is space in the buffer for the next packet.
          * We assume that the hardware will make forward progress at this
@@ -724,8 +728,8 @@  static int crystalhd_receive_frame(AVCodecContext *avctx, AVFrame *frame)
         av_log(avctx, AV_LOG_TRACE, "CrystalHD: Waiting for space in input buffer\n");
     }
 
-    ret = crystalhd_decode_packet(avctx, &pkt);
-    av_packet_unref(&pkt);
+    ret = crystalhd_decode_packet(avctx, pkt);
+    av_packet_unref(pkt);
     // crystalhd_is_buffer_full() should avoid this.
     if (ret == AVERROR(EAGAIN)) {
         ret = AVERROR_EXTERNAL;