Skip to content

Commit

Permalink
[media] Fix reset AudioDecoder twice when destroying AudioDecoder (#2788
Browse files Browse the repository at this point in the history
)

This PR (#2501) changes to
recreate or flush AudioDecoder in AudioDecoder::Reset(). However, when
destroying AdaptiveAudioDecoder, this causes Cobalt to
destroy->create->destroy AudioDecoder, which is unnecessary. This PR
fixes the extra reset when destroying AudioDecoder.

b/327229953
  • Loading branch information
borongc authored Apr 1, 2024
1 parent eb382f6 commit 02dc352
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ AdaptiveAudioDecoder::AdaptiveAudioDecoder(
}

AdaptiveAudioDecoder::~AdaptiveAudioDecoder() {
Reset();
SB_DCHECK(BelongsToCurrentThread());

if (audio_decoder_) {
TeardownAudioDecoder();
}
ResetInternal();
}

void AdaptiveAudioDecoder::Initialize(const OutputCB& output_cb,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 02dc352

Please sign in to comment.