The effective lifetime of the packet does not extend beyond the
extract_extradata in libavformat/utils.c, so the packet can simply be
put on the stack there. This allows to remove the allocation and the
corresponding frees.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@gmail.com>
---
 libavformat/internal.h |  1 -
 libavformat/utils.c    | 10 +---------
 2 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index d6a039c497..2574d2da0c 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -182,7 +182,6 @@ struct AVStreamInternal {
      * supported) */
     struct {
         AVBSFContext *bsf;
-        AVPacket     *pkt;
         int inited;
     } extract_extradata;
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 64516a6a81..d3cd4b4167 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3491,10 +3491,6 @@ static int extract_extradata_init(AVStream *st)
     if (!ret)
         goto finish;
 
-    sti->extract_extradata.pkt = av_packet_alloc();
-    if (!sti->extract_extradata.pkt)
-        return AVERROR(ENOMEM);
-
     ret = av_bsf_alloc(f, &sti->extract_extradata.bsf);
     if (ret < 0)
         goto fail;
@@ -3516,14 +3512,13 @@ finish:
     return 0;
 fail:
     av_bsf_free(&sti->extract_extradata.bsf);
-    av_packet_free(&sti->extract_extradata.pkt);
     return ret;
 }
 
 static int extract_extradata(AVStream *st, AVPacket *pkt)
 {
     AVStreamInternal *sti = st->internal;
-    AVPacket *pkt_ref;
+    AVPacket pkt1, *pkt_ref = &pkt1;
     int ret;
 
     if (!sti->extract_extradata.inited) {
@@ -3535,7 +3530,6 @@ static int extract_extradata(AVStream *st, AVPacket *pkt)
     if (sti->extract_extradata.inited && !sti->extract_extradata.bsf)
         return 0;
 
-    pkt_ref = sti->extract_extradata.pkt;
     ret = av_packet_ref(pkt_ref, pkt);
     if (ret < 0)
         return ret;
@@ -4171,7 +4165,6 @@ find_stream_info_err:
         avcodec_close(ic->streams[i]->internal->avctx);
         av_freep(&ic->streams[i]->info);
         av_bsf_free(&ic->streams[i]->internal->extract_extradata.bsf);
-        av_packet_free(&ic->streams[i]->internal->extract_extradata.pkt);
     }
     if (ic->pb)
         av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: 
%"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n",
@@ -4369,7 +4362,6 @@ static void free_stream(AVStream **pst)
         }
         av_freep(&st->internal->priv_pts);
         av_bsf_free(&st->internal->extract_extradata.bsf);
-        av_packet_free(&st->internal->extract_extradata.pkt);
     }
     av_freep(&st->internal);
 
-- 
2.21.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to