1. 21 May, 2020 13 commits
  2. 20 May, 2020 8 commits
  3. 19 May, 2020 17 commits
  4. 18 May, 2020 2 commits
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Don't assert when writing huge files · 575557ce
      Andreas Rheinhardt authored
      EBML numbers are variable length numbers: Only seven bits of every byte
      are available to encode the number, the other bits encode the length of
      the number itself. So an eight byte EBML number can only encode numbers
      in the range 0..(2^56 - 1). And when using EBML numbers to encode the
      length of an EBML element, the EBML number corresponding to 2^56 - 1 is
      actually reserved to mean that the length of the corresponding element
      is unknown.
      
      And therefore put_ebml_length() asserted that the length it should
      represent is < 2^56 - 1. Yet there was nothing that actually guaranteed
      this to be true for the Segment (the main/root EBML element of a
      Matroska file that encompasses nearly the whole file). This commit
      changes this by checking in advance how big the length is and only
      updating the number if it is representable at all; if not, the unknown
      length element is not touched.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      575557ce
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Avoid unnecessary seek · efeb3a53
      Andreas Rheinhardt authored
      The Matroska muxer has a pair of functions designed to write master
      elements whose exact length is not known in advance: start_ebml_master()
      and end_ebml_master(). The first one of these would write the EBML ID of
      the master element that is about to be started, reserve some bytes for
      the length field and record the current position as well as how many
      bytes were used for the length field. When writing the master's contents
      is finished, end_ebml_master() gets the current position (at the end of
      the master element), seeks to the length field using the recorded
      position, writes the length field and seeks back to the end of the
      master element so that one can continue writing other elements.
      
      But if one wants to modify the content of the master element itself,
      then the seek back is superfluous. This is the scenario that presents
      itself when writing the trailer: One wants to update several elements
      contained in the Segment master element (this is the main/root master
      element of a Matroska file) that were already written when writing the
      header. The current approach is to seek to the beginning of the file
      to update the elements, then seek to the end, call end_ebml_master()
      which immediately seeks to the beginning to write the length and seeks
      back. The seek to the end (which has only been performed because
      end_ebml_master() uses the initial position to determine the length
      of the master element) and the seek back are of course superfluous.
      
      This commit avoids these seeks by no longer using start/end_ebml_master()
      to write the segment's length field. Instead, it is now written
      manually. The new approach is: Seek to the beginning to write the length
      field, then update the elements (in the order they appear in the file)
      and seek back to the end.
      
      This reduces the ordinary amount of seeks of the Matroska muxer to two
      (ordinary excludes scenarios where one has big Chapters or Attachments
      or where one writes the Cues at the front).
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      efeb3a53