• Andreas Rheinhardt's avatar
    avformat/mux: Make uncoded frames av_packet_unref() compatible · ad1dc918
    Andreas Rheinhardt authored
    Currently uncoded frames (i.e. packets whose data actually points to an
    AVFrame) are not refcounted. As a consequence, calling av_packet_unref()
    on them will not free them, but may simply make sure that they leak by
    losing the pointer to the frame.
    
    This commit changes this by actually making uncoded frames refcounted.
    In order not to rely on sizeof(AVFrame) (which is not part of the public
    API and so must not be used here in libavformat) the packet's data is
    changed to a (padded) buffer containing just a pointer to an AVFrame.
    Said buffer is owned by an AVBuffer with a custom free function that
    frees the frame as well as the buffer. Thereby the pointer/the AVBuffer
    owns the AVFrame.
    
    Said ownership can actually be transferred by copying and resetting
    the pointer, as might happen when actually writing the uncoded frames
    in AVOutputFormat.write_uncoded_frame() (although currently no muxer
    makes use of this possibility).
    
    This makes packets containing uncoded frames compatible with
    av_packet_unref(). This already has three advantages in interleaved mode:
    1. If an error happens at the preparatory steps (before the packet is
    put into the interleavement queue), the frame is properly freed.
    2. If the trailer is never written, the frames still in the
    interleavement queue will now be properly freed by
    ff_packet_list_free().
    3. The custom code for moving the packet to the packet list in
    ff_interleave_add_packet() can be removed.
    
    It will also simplify fixing further memleaks in future commits.
    Suggested-by: 's avatarMarton Balint <cus@passwd.hu>
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    ad1dc918
Name
Last commit
Last update
compat Loading commit data...
doc Loading commit data...
ffbuild Loading commit data...
fftools Loading commit data...
libavcodec Loading commit data...
libavdevice Loading commit data...
libavfilter Loading commit data...
libavformat Loading commit data...
libavresample Loading commit data...
libavutil Loading commit data...
libpostproc Loading commit data...
libswresample Loading commit data...
libswscale Loading commit data...
presets Loading commit data...
tests Loading commit data...
tools Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
CONTRIBUTING.md Loading commit data...
COPYING.GPLv2 Loading commit data...
COPYING.GPLv3 Loading commit data...
COPYING.LGPLv2.1 Loading commit data...
COPYING.LGPLv3 Loading commit data...
CREDITS Loading commit data...
Changelog Loading commit data...
INSTALL.md Loading commit data...
LICENSE.md Loading commit data...
MAINTAINERS Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
RELEASE Loading commit data...
configure Loading commit data...