Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick PR #3020: [media] Add a switch to enable resetting audio decoder #3376

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion starboard/android/shared/player_components_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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", "<not provided>")
<< ".";

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(): "
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading