Skip to content

Commit

Permalink
[media] Add a switch to enable resetting audio decoder (#3020)
Browse files Browse the repository at this point in the history
1. Make resetting audio decoder configurable from web app.
2. This can be enabled by using MIME attribute
"enableresetaudiodecoder=true".

b/327229953

(cherry picked from commit 3ef72cd)
  • Loading branch information
borongc authored and anonymous1-me committed Apr 22, 2024
1 parent 7664e9a commit af0eded
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
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 @@ -382,6 +387,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 @@ -431,7 +452,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

0 comments on commit af0eded

Please sign in to comment.