]> git.sesse.net Git - ffmpeg/commit
avfilter/src_movie: Remove unnecessary secondary AVPacket
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 10 Sep 2020 00:21:59 +0000 (02:21 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 10 Sep 2020 20:25:28 +0000 (22:25 +0200)
commit41e0058b48fc192aaa7b97a58636f4784b93b6fd
tree5d22675d58efca5b87656f38d381390e5f813c61
parentc97d91ecaeb40eefde3909143f36d323b7498e40
avfilter/src_movie: Remove unnecessary secondary AVPacket

The movie and amovie filters currently use two packets. One of the two,
pkt0, is the owner of the returned packet; it is also the destination
packet for av_read_frame(). The other one pkt is initially (i.e. after
av_read_frame()) a copy of pkt0; copy means that the contents of both
are absolutely the same: They both point to the same AVBufferRef and the
same side data. This violation of the refcounted packet API is only
possible because pkt is not considered to own its data. Only pkt0 is
ever unreferenced.
The reason for pkt's existence seems to be historic:
The API used for decoding audio (namely avcodec_decode_audio4()) could
consume frames partially, i.e. it could return multiple frames for one
packet and therefore it returned how much of the input buffer had been
consumed. The caller was then supposed to update the packet's data and
size pointer to reflect this and call avcodec_decode_audio4() again with
the updated packet to get the next frame.
But before the introduction of refcounted AVPackets where knowledge and
responsibility about what to free lies with the underlying AVBuffer such
a procedure required a spare packet (or one would need to record the
original data and size fields separately to restore them before freeing
the packet; notice that this code has been written when AVPackets still
had a destruct field). But these times are long gone, so just remove the
secondary AVPacket.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavfilter/src_movie.c