diff mbox series

[FFmpeg-devel,12/15] avformat/(aiff|flac|mov|mp3|tta)enc: Don't create unnecessary references

Message ID AM7PR03MB666065518EFBD395C8BB70458F779@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 3485e79f07d74e47ff00b60a68d609d37d0129ba
Headers show
Series [FFmpeg-devel,01/11] avcodec/Makefile: Remove superfluous avformat->DNXHD dependencies | expand

Checks

Context Check Description
andriy/configurex86 warning Failed to apply patch
andriy/configureppc warning Failed to apply patch

Commit Message

Andreas Rheinhardt Dec. 16, 2021, 1:29 a.m. UTC
The packet given to muxers is not used afterwards; it is always
unreferenced by libavformat. Ergo muxers are allowed to keep
the references in the packets and e.g. move the ownership to
a packet list. This is what this commit does.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/aiffenc.c | 2 +-
 libavformat/flacenc.c | 2 +-
 libavformat/movenc.c  | 4 +++-
 libavformat/mp3enc.c  | 3 ++-
 libavformat/ttaenc.c  | 3 ++-
 5 files changed, 9 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
index 24bc17400e..7bb0978a53 100644
--- a/libavformat/aiffenc.c
+++ b/libavformat/aiffenc.c
@@ -219,7 +219,7 @@  static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
             return 0;
 
         return avpriv_packet_list_put(&aiff->pict_list, &aiff->pict_list_end,
-                                  pkt, av_packet_ref, 0);
+                                      pkt, NULL, 0);
     }
 
     return 0;
diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index f884e5d2c8..e8f043729e 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -360,7 +360,7 @@  static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     if (pkt->stream_index == c->audio_stream_idx) {
         if (c->waiting_pics) {
             /* buffer audio packets until we get all the pictures */
-            ret = avpriv_packet_list_put(&c->queue, &c->queue_end, pkt, av_packet_ref, 0);
+            ret = avpriv_packet_list_put(&c->queue, &c->queue_end, pkt, NULL, 0);
             if (ret < 0) {
                 av_log(s, AV_LOG_ERROR, "Out of memory in packet queue; skipping attached pictures\n");
                 c->waiting_pics = 0;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index fc309fb416..033a6a9f52 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6197,9 +6197,11 @@  static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
                 return AVERROR(EINVAL);
             }
 
+            /* The following will reset pkt and is only allowed to be used
+             * because we return immediately. afterwards. */
             if ((ret = avpriv_packet_list_put(&trk->squashed_packet_queue,
                                               &trk->squashed_packet_queue_end,
-                                              pkt, av_packet_ref, 0)) < 0) {
+                                              pkt, NULL, 0)) < 0) {
                 return ret;
             }
 
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 71e96a8651..0ffc79c025 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -524,7 +524,8 @@  static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (pkt->stream_index == mp3->audio_stream_idx) {
         if (mp3->pics_to_write) {
             /* buffer audio packets until we get all the pictures */
-            int ret = avpriv_packet_list_put(&mp3->queue, &mp3->queue_end, pkt, av_packet_ref, 0);
+            int ret = avpriv_packet_list_put(&mp3->queue, &mp3->queue_end,
+                                             pkt, NULL, 0);
 
             if (ret < 0) {
                 av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n");
diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c
index 11855c32d9..5f21fdc144 100644
--- a/libavformat/ttaenc.c
+++ b/libavformat/ttaenc.c
@@ -95,10 +95,11 @@  static int tta_write_packet(AVFormatContext *s, AVPacket *pkt)
     int ret;
 
     ret = avpriv_packet_list_put(&tta->queue, &tta->queue_end, pkt,
-                                 av_packet_ref, 0);
+                                 NULL, 0);
     if (ret < 0) {
         return ret;
     }
+    pkt = &tta->queue_end->pkt;
 
     avio_wl32(tta->seek_table, pkt->size);
     tta->nb_samples += pkt->duration;