diff --git a/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.cc b/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.cc index 0c341ea3e912..40c77b2cf2c8 100644 --- a/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.cc +++ b/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.cc @@ -44,7 +44,12 @@ AdaptiveAudioDecoder::AdaptiveAudioDecoder( } AdaptiveAudioDecoder::~AdaptiveAudioDecoder() { - Reset(); + SB_DCHECK(BelongsToCurrentThread()); + + if (audio_decoder_) { + TeardownAudioDecoder(); + } + ResetInternal(); } void AdaptiveAudioDecoder::Initialize(const OutputCB& output_cb, @@ -150,15 +155,7 @@ void AdaptiveAudioDecoder::Reset() { resampler_.reset(); channel_mixer_.reset(); } - CancelPendingJobs(); - while (!decoded_audios_.empty()) { - decoded_audios_.pop(); - } - pending_input_buffers_.clear(); - pending_consumed_cb_ = nullptr; - flushing_ = false; - stream_ended_ = false; - first_output_received_ = false; + ResetInternal(); } void AdaptiveAudioDecoder::InitializeAudioDecoder( @@ -188,6 +185,18 @@ void AdaptiveAudioDecoder::TeardownAudioDecoder() { channel_mixer_.reset(); } +void AdaptiveAudioDecoder::ResetInternal() { + CancelPendingJobs(); + while (!decoded_audios_.empty()) { + decoded_audios_.pop(); + } + pending_input_buffers_.clear(); + pending_consumed_cb_ = nullptr; + flushing_ = false; + stream_ended_ = false; + first_output_received_ = false; +} + void AdaptiveAudioDecoder::OnDecoderOutput() { if (!BelongsToCurrentThread()) { Schedule(std::bind(&AdaptiveAudioDecoder::OnDecoderOutput, this)); diff --git a/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.h b/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.h index 2fc9964f1d50..f128e8826127 100644 --- a/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.h +++ b/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.h @@ -65,6 +65,7 @@ class AdaptiveAudioDecoder : public AudioDecoder, private JobQueue::JobOwner { void InitializeAudioDecoder(const media::AudioStreamInfo& audio_stream_info); void TeardownAudioDecoder(); void OnDecoderOutput(); + void ResetInternal(); const uint32_t initial_samples_per_second_; const SbDrmSystem drm_system_;