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

(cherry picked from commit 02dc352)
  • Loading branch information
borongc committed Apr 3, 2024
1 parent a99c34e commit 25388da
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 25388da

Please sign in to comment.