• Andreas Rheinhardt's avatar
    avformat/matroskaenc: Remove inconsistencies wrt seekability handling · 1779f0b1
    Andreas Rheinhardt authored
    The Matroska muxer behaves differently in several ways when it thinks
    that it is in unseekable/livestreaming mode: It does not add Cue entries
    because they won't be written anyway for a livestream and it writes some
    elements only preliminarily (with the intention to overwrite them with
    an updated version at the end) when non-livestreaming etc.
    
    There are two ways to set the Matroska muxer into livestreaming mode:
    Setting an option or by providing an unseekable AVIOContext. Yet the
    actual checks were not consistent:
    
    If the AVIOContext was unseekable and no AAC extradata was available
    when writing the header, writing the header failed; but if the AVIOContext
    was seekable, it didn't, because the muxer expected to get the extradata
    via packet side-data. Here the livestreaming option has not been checked,
    although one can't use the updated extradata in case it is a livestream.
    
    If the reserve_index_space option was used, space for writing Cues would
    be reserved when writing the header unless the AVIOContext was
    unseekable. Yet Cues were only written if the livestreaming option was
    not set and the AVIOContext was seekable (when writing the trailer), so
    if the AVIOContext was seekable and the livestreaming option set, the
    reserved space would never be used at all.
    
    If the AVIOContext was unseekable and the livestreaming option was not
    set, it would be attempted to update the main length field at the end.
    After all, it might be possible that the file is so short that it fits
    into the AVIOContext's buffer in which case the seek back would work.
    Yet this is dangerous: It might be that we are not dealing with a
    simple output file, but that our output gets split into chunks and that
    each of these chunks is actually seekable. In this case some part of the
    last chunk (namely the eight bytes that have the same offset as the
    length field had in the header) will be overwritten with what the muxer
    wrongly believes to be the filesize.
    (The livestreaming option has been added to deal with this scenario,
    yet its documentation ("Write files assuming it is a live stream.")
    doesn't make this clear at all. At least the segment muxer does not
    set the option for live and given that the chances of successfully
    seeking when the output is actually unseekable are slim, it is best to
    not attempt to update the length field in the unseekable case at all.)
    
    All these inconsistencies were fixed by treating the output as seekable
    if the livestreaming option is not set and if the AVIOContext is
    seekable. A macro has been used to enforce consistency and improve code
    readability.
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
    1779f0b1
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...