• Aman Gupta's avatar
    libavcodec/videotoolbox: fix decoding of h264 streams with minor SPS changes · 259dc4e0
    Aman Gupta authored
    Previously the codec kept an entire copy of the SPS, and restarted the VT decoder
    session whenever it changed. This fixed decoding errors in [1], as
    described in 9519983c. On further inspection, that sample features an SPS change
    from High/4.0 to High/3.2 while moving from one scene to another.
    
    Yesterday I received [2], which contains minor SPS changes where the
    profile and level do not change. These occur frequently and are not associated with
    scene changes. After 9519983c, the VT decoder session is recreated unnecessarily when
    these are encountered causing visual glitches.
    
    This commit simplifies the state kept in the VTContext to include just the first three
    bytes of the SPS, containing the profile and level details. This is populated initially
    when the VT decoder session is created, and used to detect changes and force a restart.
    
    This means minor SPS changes are fed directly into the existing decoder, whereas
    profile/level changes force the decoder session to be recreated with the new parameters.
    
    After this commit, both samples [1] and [2] playback as expected.
    
    [1] https://s3.amazonaws.com/tmm1/videotoolbox/spschange.ts
    [2] https://s3.amazonaws.com/tmm1/videotoolbox/spschange2.tsSigned-off-by: 's avatarAman Gupta <aman@tmm1.net>
    259dc4e0
vt_internal.h 2.35 KB