]> git.sesse.net Git - ffmpeg/commitdiff
avformat/utils: Don't allocate separate packet for extract_extradata
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 18 Mar 2021 04:23:54 +0000 (05:23 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 23 Mar 2021 13:23:49 +0000 (14:23 +0100)
One can simply reuse AVFormatInternal.parse_pkt instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/internal.h
libavformat/utils.c

index 3c6b2921c1e2167f0560131501c1bc9b80f5699d..a810d51bba51f0511e9273c9ed58147b149287c5 100644 (file)
@@ -90,9 +90,18 @@ struct AVFormatInternal {
     /**
      * Packets split by the parser get queued here.
      */
-    AVPacket *parse_pkt;
     struct PacketList *parse_queue;
     struct PacketList *parse_queue_end;
+    /**
+     * The generic code uses this as a temporary packet
+     * to parse packets; it may also be used for other means
+     * for short periods that are guaranteed not to overlap
+     * with calls to av_read_frame() (or ff_read_packet())
+     * or with each other.
+     * Every user has to ensure that this packet is blank
+     * after using it.
+     */
+    AVPacket *parse_pkt;
 
     /**
      * Used to hold temporary packets.
@@ -190,7 +199,6 @@ struct AVStreamInternal {
      * supported) */
     struct {
         AVBSFContext *bsf;
-        AVPacket     *pkt;
         int inited;
     } extract_extradata;
 
index c7d8369fb90d831c9234c6f4cb5868e4791ad2c7..96a52e07d4904bccf09c254eccab1f2384ff7474 100644 (file)
@@ -3496,13 +3496,9 @@ 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;
+        return ret;
 
     ret = avcodec_parameters_copy(sti->extract_extradata.bsf->par_in,
                                   st->codecpar);
@@ -3521,14 +3517,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, const AVPacket *pkt)
+static int extract_extradata(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
 {
     AVStreamInternal *sti = st->internal;
-    AVPacket *pkt_ref;
+    AVPacket *pkt_ref = s->internal->parse_pkt;
     int ret;
 
     if (!sti->extract_extradata.inited) {
@@ -3540,7 +3535,6 @@ static int extract_extradata(AVStream *st, const 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;
@@ -3921,7 +3915,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                 st->internal->info->frame_delay_evidence = 1;
         }
         if (!st->internal->avctx->extradata) {
-            ret = extract_extradata(st, pkt);
+            ret = extract_extradata(ic, st, pkt);
             if (ret < 0)
                 goto unref_then_goto_end;
         }
@@ -4187,7 +4181,6 @@ find_stream_info_err:
         avcodec_close(ic->streams[i]->internal->avctx);
         av_freep(&ic->streams[i]->internal->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",
@@ -4389,7 +4382,6 @@ static void free_stream(AVStream **pst)
         av_freep(&st->internal->probe_data.buf);
 
         av_bsf_free(&st->internal->extract_extradata.bsf);
-        av_packet_free(&st->internal->extract_extradata.pkt);
 
         if (st->internal->info)
             av_freep(&st->internal->info->duration_error);