• Niklas Haas's avatar
    lavc: Implement Dolby Vision RPU parsing · fe040337
    Niklas Haas authored
    Based on a mixture of guesswork, partial documentation in patents, and
    reverse engineering of real-world samples. Confirmed working for all the
    samples I've thrown at it.
    
    Contains some annoying machinery to persist these values in between
    frames, which is needed in theory even though I've never actually seen a
    sample that relies on it in practice. May or may not work.
    
    Since the distinction matters greatly for parsing the color matrix
    values, this includes a small helper function to guess the right profile
    from the RPU itself in case the user has forgotten to forward the dovi
    configuration record to the decoder. (Which in practice, only ffmpeg.c
    and ffplay do..)
    
    Notable omissions / deviations:
    - CRC32 verification. This is based on the MPEG2 CRC32 type, which is
      similar to IEEE CRC32 but apparently different in subtle enough ways
      that I could not get it to pass verification no matter what parameters
      I fed to av_crc. It's possible the code needs some changes.
    - Linear interpolation support. Nothing documents this (beyond its
      existence) and no samples use it, so impossible to implement.
    - All of the extension metadata blocks, but these contain values that
      seem largely congruent with ST2094, HDR10, or other existing forms of
      side data, so I will defer parsing/attaching them to a future commit.
    - The patent describes a mechanism for predicting coefficients from
      previous RPUs, but the bit for the flag whether to use the
      prediction deltas or signal entirely new coefficients does not seem to
      be present in actual RPUs, so we ignore this subsystem entirely.
    - In the patent's spec, the NLQ subsystem also loops over
      num_nlq_pivots, but even in the patent the number is hard-coded to one
      iteration rather than signalled. So we only store one set of coefs.
    
    Heavily influenced by https://github.com/quietvoid/dovi_tool
    Documentation drawn from US Patent 10,701,399 B2 and ETSI GS CCM 001
    Signed-off-by: 's avatarNiklas Haas <git@haasn.dev>
    Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
    fe040337
dovi_rpu.c 15.3 KB