Skip to content

Commit

Permalink
[media] Fix OpusAudioDecoder::Reset() on PartialAudio tests
Browse files Browse the repository at this point in the history
This PR (#2501) recreating OpusAUdioDecoder in Reset(). Change to reset a previously initialized state using the #OPUS_RESET_STATE CTL as stated in the opus document.

b/327281974
  • Loading branch information
borongc committed Mar 27, 2024
1 parent f29d2d7 commit d2ba8e8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions starboard/shared/opus/opus_audio_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,20 @@ scoped_refptr<OpusAudioDecoder::DecodedAudio> OpusAudioDecoder::Read(
void OpusAudioDecoder::Reset() {
SB_DCHECK(BelongsToCurrentThread());

TeardownCodec();
InitializeCodec();
if (decoder_) {
int error = opus_multistream_decoder_ctl(decoder_, OPUS_RESET_STATE);
if (error != OPUS_OK) {
SB_LOG(ERROR) << "Failed to reset decoder with error: "
<< opus_strerror(error);

Check warning on line 248 in starboard/shared/opus/opus_audio_decoder.cc

View check run for this annotation

Codecov / codecov/patch

starboard/shared/opus/opus_audio_decoder.cc#L247-L248

Added lines #L247 - L248 were not covered by tests

// If fail to reset opus decoder, re-create it.
TeardownCodec();
InitializeCodec();

Check warning on line 252 in starboard/shared/opus/opus_audio_decoder.cc

View check run for this annotation

Codecov / codecov/patch

starboard/shared/opus/opus_audio_decoder.cc#L251-L252

Added lines #L251 - L252 were not covered by tests
}
SB_DCHECK(decoder_ != NULL);
}

frames_per_au_ = kMaxOpusFramesPerAU;
stream_ended_ = false;
while (!decoded_audios_.empty()) {
decoded_audios_.pop();
Expand Down

0 comments on commit d2ba8e8

Please sign in to comment.