Skip to content

Commit

Permalink
Cherry pick PR #1776: [android] Handle error in MinRequiredFramesTest…
Browse files Browse the repository at this point in the history
…er (#1851)

Refer to the original PR: youtube/cobalt#1776

b/175822670

Co-authored-by: Jason <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and jasonzhangxx committed Oct 26, 2023
1 parent 0fa7078 commit 607fe01
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions starboard/android/shared/audio_sink_min_required_frames_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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<MinRequiredFramesTester*>(context);
tester->has_error_ = true;
}

void MinRequiredFramesTester::UpdateSourceStatus(int* frames_in_buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class MinRequiredFramesTester {
std::vector<const TestTask> 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_;
Expand Down

0 comments on commit 607fe01

Please sign in to comment.