Skip to content

Commit

Permalink
Cherry pick PR #2845: [media] Recreate codec to ensure new codec in P…
Browse files Browse the repository at this point in the history
…artialAudio tests (#2907)

Refer to the original PR: #2845

AudioDecoder::Reset() may use flush() to reset codec, which could fail
in PartialAudio tests on tvos and android with aac, ec3, and ac3 inputs.
Recreating codec ensures the outputs are the same in the tests.

b/329526479

Co-authored-by: Bo-Rong Chen <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and borongc authored Apr 12, 2024
1 parent d0bba1a commit 713d81c
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,31 @@ class AudioDecoderTest
}
}

void ResetDecoder() {
audio_decoder_->Reset();
void ResetInternal() {
can_accept_more_input_ = true;
last_input_buffer_ = nullptr;
decoded_audios_.clear();
written_inputs_.clear();
eos_written_ = false;
decoded_audio_sample_rate_ = 0;
first_output_received_ = false;
{
ScopedLock scoped_lock(event_queue_mutex_);
event_queue_.clear();
}
}

void ResetDecoder() {
audio_decoder_->Reset();
ResetInternal();
}

void RecreateDecoder() {
// TODO(b/332955827): Investigate the output difference after flush() codec.
audio_decoder_.reset();
audio_renderer_sink_.reset();
ResetInternal();
SetUp();
}

void WaitForDecodedAudio() {
Expand Down Expand Up @@ -724,7 +741,7 @@ TEST_P(AudioDecoderTest, PartialAudio) {
++number_of_input_to_write) {
SB_LOG(INFO) << "Testing " << number_of_input_to_write
<< " access units for partial audio.";
ResetDecoder();
RecreateDecoder();

// Decode InputBuffers without partial audio and use the output as reference
for (int i = 0; i < number_of_input_to_write; ++i) {
Expand Down Expand Up @@ -766,7 +783,7 @@ TEST_P(AudioDecoderTest, PartialAudio) {
decoded_audio_sample_rate_) /
4;

ResetDecoder();
RecreateDecoder();

for (int i = 0; i < number_of_input_to_write; ++i) {
SbTime duration_to_discard_from_front = i == 0 ? duration_to_discard : 0;
Expand Down Expand Up @@ -817,12 +834,12 @@ TEST_P(AudioDecoderTest, PartialAudio) {
(frames_per_access_unit / 4 - 1) * bytes_per_frame;
auto reference_search_end = reference_decoded_audio->data() +
reference_decoded_audio->size_in_bytes();
auto offset_in_bytes =
std::search(reference_search_begin, reference_search_end,
partial_decoded_audio->data(),
partial_decoded_audio->data() +
partial_decoded_audio->size_in_bytes()) -
reference_search_begin;
auto offset_index = std::search(
reference_search_begin, reference_search_end,
partial_decoded_audio->data(),
partial_decoded_audio->data() + partial_decoded_audio->size_in_bytes());
ASSERT_FALSE(offset_index == reference_search_end);
auto offset_in_bytes = offset_index - reference_search_begin;
auto offset_in_frames = offset_in_bytes / bytes_per_frame;

constexpr int kEpsilonInFrames = 2;
Expand Down

0 comments on commit 713d81c

Please sign in to comment.