• Andreas Rheinhardt's avatar
    avformat/matroskaenc: Only write Cluster if it has in fact been opened · 68c7186d
    Andreas Rheinhardt authored
    Since commit 4aa0665f, the dynamic
    buffer destined for the contents of the current Cluster is no longer
    constantly allocated, reallocated and then freed after writing the
    content; instead it is reset and reused when closing a Cluster.
    
    Yet the code in mkv_write_trailer() still checked for whether a Cluster
    is open by checking whether the pointer to the dynamic buffer is NULL or
    not (instead of checking whether the position of the current Cluster is
    -1 or not). If a Cluster was not open, an empty Cluster would be output.
    
    One usually does not run into this issue, because unless there are
    errors, there are only three possibilities to not have an opened Cluster
    at the end of writing a packet:
    The first is if one sent an audio packet to the muxer. It might trigger
    closing and outputting the old Cluster, but because the muxer caches
    audio packets internally, it would not be output immediately and
    therefore no new Cluster would be opened.
    The second is an audio packet that does not contain data (such packets
    are sometimes sent for side-data only, e.g. by the FLAC encoder). The
    only difference to the first scenario is that such packets are not
    cached.
    The third is if one explicitly flushes the muxer by sending a NULL
    packet via av_write_frame().
    
    If one also allows for errors, then there is also another possibility:
    Caching the audio packet may fail in the first scenario.
    
    If one calls av_write_trailer() after the first scenario, the cached
    audio packet will be output when writing the trailer, for which
    a Cluster is opened and everything is fine; because flushing the muxer
    does currently not output the cached audio packet (if one is cached),
    the issue also does not exist if an audio packet has been cached before
    flushing. The issue only exists in one of the other scenarios.
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    68c7186d
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...