• xhwang's avatar
    media: Support better decoder switching · 1492be9e
    xhwang authored
    Today on reinitialization error, or decode error of the first buffer,
    DecoderStream will fall back to decoders left in the DecoderSelector.
    Since we will have less and less decoders in the DecoderSelector, the
    ability to switch decoders is limited.
    
    This CL updates DecoderSelector so that it takes a callback to create
    a list of decoders, instead of taking the list of decoders directly.
    This allows the DecoderSelector to select a decoder that has been
    tried or selected before, such that upon decoder reinitialization error
    (e.g. switching from clear to encrypted config), or upon decode error of
    the first buffer, we always have the full list of decoders to select
    from.
    
    Two mechanisms are added to avoid trying the same failing decoder again:
    
    1. Blacklist
    
    When SelectDecoder() is called due to reinitialization failure, or
    decoding failure of the first buffer, the existing decoder is listed as
    the "blacklisted decoder" such that DecoderSelector will not even try
    it.
    
    There is one exception though. When DecryptingDemuxerStream is selected,
    since the input steam is changed (encrypted -> clear), the blacklisted
    decoder is ignored. For example, FFmpegVideoDecoder is slected first for
    a clear stream. Then on a config change, the stream becomes encrypted so
    FFmpegVideoDecoder fails to reinitialize and we need to select a new
    decoder. After DecryptingDemuxerStream is selected, we should still be
    able to use FFmpegVideoDecoder to decode the decrypted stream.
    
    2. Fall back at most once
    
    If fallback has already happened and decode of the first buffer failed
    again, we don't try to fallback again. This is to avoid the infinite
    loop of "select decoder 1 -> decode error -> select decoder 2 -> decode
    error -> select decoder 1".
    
    BUG=695595
    TEST=Updated/Added unittests.
    
    Review-Url: https://codereview.chromium.org/2837613004
    Cr-Commit-Position: refs/heads/master@{#469579}
    1492be9e
audio_decoder.h 3.52 KB