diff --git a/starboard/android/shared/player_components_factory.h b/starboard/android/shared/player_components_factory.h index 0b38256bc0b8..536b404c67ea 100644 --- a/starboard/android/shared/player_components_factory.h +++ b/starboard/android/shared/player_components_factory.h @@ -75,6 +75,11 @@ constexpr bool kForceResetSurfaceUnderTunnelMode = true; // during Seek(). constexpr bool kForceFlushDecoderDuringReset = false; +// By default, Cobalt teardowns AudioDecoder during Reset(). +// Set the following variable to true to force it reset audio decoder +// during Reset(). This should be enabled with kForceFlushDecoderDuringReset. +constexpr bool kForceResetAudioDecoder = false; + // This class allows us to force int16 sample type when tunnel mode is enabled. class AudioRendererSinkAndroid : public ::starboard::shared::starboard::player:: filter::AudioRendererSinkImpl { @@ -381,6 +386,22 @@ class PlayerComponentsFactory : public starboard::shared::starboard::player:: << tunnel_mode_audio_session_id << '.'; } + bool enable_reset_audio_decoder = + video_mime_type.GetParamBoolValue("enableresetaudiodecoder", false); + SB_LOG(INFO) << "Reset AudioDecoder during Reset(): " + << (enable_reset_audio_decoder ? "enabled. " : "disabled. ") + << "Video mime parameter \"enableresetaudiodecoder\" value: " + << video_mime_type.GetParamStringValue( + "enableresetaudiodecoder", "") + << "."; + + if (kForceResetAudioDecoder && !enable_reset_audio_decoder) { + SB_LOG(INFO) + << "`kForceResetAudioDecoder` is set to true, force resetting" + << " audio decoder during Reset()."; + enable_reset_audio_decoder = true; + } + bool enable_flush_during_seek = video_mime_type.GetParamBoolValue("enableflushduringseek", false); SB_LOG(INFO) << "Flush MediaCodec during Reset(): " @@ -430,7 +451,8 @@ class PlayerComponentsFactory : public starboard::shared::starboard::player:: audio_decoder->reset(new AdaptiveAudioDecoder( creation_parameters.audio_stream_info(), - creation_parameters.drm_system(), decoder_creator)); + creation_parameters.drm_system(), decoder_creator, + enable_reset_audio_decoder)); if (tunnel_mode_audio_session_id != -1) { *audio_renderer_sink = TryToCreateTunnelModeAudioRendererSink( 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 440873581577..dbc9f1748776 100644 --- a/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.cc +++ b/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.cc @@ -43,6 +43,19 @@ AdaptiveAudioDecoder::AdaptiveAudioDecoder( SB_DCHECK(audio_stream_info.codec != kSbMediaAudioCodecNone); } +AdaptiveAudioDecoder::AdaptiveAudioDecoder( + const media::AudioStreamInfo& audio_stream_info, + SbDrmSystem drm_system, + const AudioDecoderCreator& audio_decoder_creator, + bool enable_reset_audio_decoder, + const OutputFormatAdjustmentCallback& output_adjustment_callback) + : AdaptiveAudioDecoder(audio_stream_info, + drm_system, + audio_decoder_creator, + output_adjustment_callback) { + enable_reset_audio_decoder_ = enable_reset_audio_decoder; +} + AdaptiveAudioDecoder::~AdaptiveAudioDecoder() { SB_DCHECK(BelongsToCurrentThread()); @@ -154,9 +167,13 @@ void AdaptiveAudioDecoder::Reset() { SB_DCHECK(BelongsToCurrentThread()); if (audio_decoder_) { - audio_decoder_->Reset(); - resampler_.reset(); - channel_mixer_.reset(); + if (enable_reset_audio_decoder_) { + audio_decoder_->Reset(); + resampler_.reset(); + channel_mixer_.reset(); + } else { + TeardownAudioDecoder(); + } } ResetInternal(); } 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 5ee80a7b7b6b..70232de0fca3 100644 --- a/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.h +++ b/starboard/shared/starboard/player/filter/adaptive_audio_decoder_internal.h @@ -52,6 +52,12 @@ class AdaptiveAudioDecoder : public AudioDecoder, private JobQueue::JobOwner { const AudioDecoderCreator& audio_decoder_creator, const OutputFormatAdjustmentCallback& output_adjustment_callback = nullptr); + AdaptiveAudioDecoder(const media::AudioStreamInfo& audio_stream_info, + SbDrmSystem drm_system, + const AudioDecoderCreator& audio_decoder_creator, + bool enable_reset_audio_decoder, + const OutputFormatAdjustmentCallback& + output_adjustment_callback = nullptr); ~AdaptiveAudioDecoder() override; void Initialize(const OutputCB& output_cb, const ErrorCB& error_cb) override; @@ -91,6 +97,7 @@ class AdaptiveAudioDecoder : public AudioDecoder, private JobQueue::JobOwner { bool first_output_received_ = false; bool output_format_checked_ = false; bool first_input_written_ = false; + bool enable_reset_audio_decoder_ = false; }; } // namespace filter