• Hari Nandagopal's avatar
    Prevent a race condition in CastAudioOutputStream · 07ab7f26
    Hari Nandagopal authored
    - Prevent race condition in CastAudioOutputStream to prevent
    FillNextBuffer() from calling AudioSourceCallback::OnMoreData() after
    AudioOutputStream::Close() is called.
    - FillNextBuffer() will now acquire running_lock_ for the entirety of
    its scope.
    - CastAudioOutputStream::Close() will synchronously block on
    running_lock_ until FillNextBuffer() has completed before setting
    running_ to false and continuing its close sequence.
    - Subsequent calls to FillNextBuffer() will early return without calling
    AudioSourceCallback::OnMoreData().
    - Add infrastructure in CastAudioOutputStream unittests to pause and
    resume the audio thread.
    - Add a test in CastAudioOutputStream unittests to ensure that a call to
    Close() will synchronously prevent any further callbacks.
    
    mutex synchronization is removed, race condition is difficult to
    reproduce in real-world testing.
    
    Bug: 138695782
    Test: Builds, unit tests pass, new unit test passes and fails when the
    Change-Id: I11cdd64c0987298ba3fc6a9090359bd2715e6f03
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1761483Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
    Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
    Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
    Commit-Queue: Hari Nandagopal <hnandagopal@google.com>
    Cr-Commit-Position: refs/heads/master@{#691784}
    07ab7f26
cast_audio_output_stream_unittest.cc 32.7 KB