[FFmpeg-devel,v4,6/9] avformat/utils: Don't create unnecessary references

Submitted by Andreas Rheinhardt on Sept. 20, 2019, 8:39 p.m.

Details

Message ID 20190920203916.16904-7-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Sept. 20, 2019, 8:39 p.m.
When AVFMT_FLAG_GENPTS is set, av_read_frame would put a reference to a
packet in the packet list (via av_packet_ref) and then immediately
thereafter unreference the original packet. This has been changed to
move the reference instead. Given that the packet originated from
read_frame_internal, it is already reference counted*, so that the
outcome of the new code is equivalent to the old code.

*: Packets from read_frame_internal either come directly from
ff_read_packet or from parse_packet; the latter makes sure that the
packet is reference counted. Packets from the former have been either
directly read or come from the raw_packet_buffer. The directly read
packets have been made refcounted and the other packets originate either
from directly read ones or from attached pics which are inserted into
the packet list via av_packet_ref.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/utils.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 701e9ea030..4eb063c54a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1856,10 +1856,11 @@  int av_read_frame(AVFormatContext *s, AVPacket *pkt)
 
         ret = ff_packet_list_put(&s->internal->packet_buffer,
                                  &s->internal->packet_buffer_end,
-                                 pkt, FF_PACKETLIST_FLAG_REF_PACKET);
-        av_packet_unref(pkt);
-        if (ret < 0)
+                                 pkt, 0);
+        if (ret < 0) {
+            av_packet_unref(pkt);
             return ret;
+        }
     }
 
 return_packet: