From 607fe01d2e742537e870b5b5e338e634e88b832d Mon Sep 17 00:00:00 2001 From: cobalt-github-releaser-bot <95661244+cobalt-github-releaser-bot@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:35:13 -0700 Subject: [PATCH] Cherry pick PR #1776: [android] Handle error in MinRequiredFramesTester (#1851) Refer to the original PR: https://github.com/youtube/cobalt/pull/1776 b/175822670 Co-authored-by: Jason --- .../audio_sink_min_required_frames_tester.cc | 15 ++++++++++++--- .../audio_sink_min_required_frames_tester.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/starboard/android/shared/audio_sink_min_required_frames_tester.cc b/starboard/android/shared/audio_sink_min_required_frames_tester.cc index b8139a284a429..1d156b9ae1f82 100644 --- a/starboard/android/shared/audio_sink_min_required_frames_tester.cc +++ b/starboard/android/shared/audio_sink_min_required_frames_tester.cc @@ -113,6 +113,7 @@ void MinRequiredFramesTester::TesterThreadFunc() { frame_buffers[0] = silence_buffer.data(); // Set default values. + has_error_ = false; min_required_frames_ = task.default_required_frames; total_consumed_frames_ = 0; last_underrun_count_ = -1; @@ -148,6 +149,13 @@ void MinRequiredFramesTester::TesterThreadFunc() { min_required_frames_ = max_required_frames_; } + if (has_error_) { + SB_LOG(ERROR) << "There's an error while running the test. Fallback to " + "max required frames " + << max_required_frames_ << "."; + min_required_frames_ = max_required_frames_; + } + if (start_threshold > min_required_frames_) { SB_LOG(INFO) << "Audio sink min required frames is overwritten from " << min_required_frames_ << " to audio track start threshold " @@ -197,9 +205,10 @@ void MinRequiredFramesTester::ErrorFunc(bool capability_changed, const std::string& error_message, void* context) { SB_LOG(ERROR) << "Error occurred while writing frames: " << error_message; - // TODO: Handle errors during minimum frames test, maybe by terminating the - // test earlier. - SB_NOTREACHED(); + + MinRequiredFramesTester* tester = + static_cast(context); + tester->has_error_ = true; } void MinRequiredFramesTester::UpdateSourceStatus(int* frames_in_buffer, diff --git a/starboard/android/shared/audio_sink_min_required_frames_tester.h b/starboard/android/shared/audio_sink_min_required_frames_tester.h index 669217aca4ec0..934bdb977fb3e 100644 --- a/starboard/android/shared/audio_sink_min_required_frames_tester.h +++ b/starboard/android/shared/audio_sink_min_required_frames_tester.h @@ -107,6 +107,7 @@ class MinRequiredFramesTester { std::vector test_tasks_; AudioTrackAudioSink* audio_sink_ = nullptr; int min_required_frames_; + std::atomic_bool has_error_; // Used only by audio sink thread. int total_consumed_frames_;