diff options
author | Phil Burk <philburk@mobileer.com> | 2022-09-23 15:46:00 -0700 |
---|---|---|
committer | Phil Burk <philburk@mobileer.com> | 2022-11-14 15:30:32 +0000 |
commit | a3e62ecdcc0a1404f9bd78d59f15941b77d5e1ea (patch) | |
tree | ed24a2b1c465f59c6c4f466d8148c86ef2b6d9ff | |
parent | 0fe6460b461f6dab2e163fb9af5e7e88b47c1c43 (diff) | |
download | oboe-a3e62ecdcc0a1404f9bd78d59f15941b77d5e1ea.tar.gz |
Retry if open or start fails.
-rw-r--r-- | samples/hello-oboe/src/main/cpp/HelloOboeEngine.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/samples/hello-oboe/src/main/cpp/HelloOboeEngine.cpp b/samples/hello-oboe/src/main/cpp/HelloOboeEngine.cpp index 755762f9..7cbcbacd 100644 --- a/samples/hello-oboe/src/main/cpp/HelloOboeEngine.cpp +++ b/samples/hello-oboe/src/main/cpp/HelloOboeEngine.cpp @@ -133,11 +133,14 @@ void HelloOboeEngine::restart() { oboe::Result HelloOboeEngine::start() { std::lock_guard<std::mutex> lock(mLock); oboe::Result result = oboe::Result::OK; - // It is possible for a stream's device to become disconnected between the Open and the Start. + // It is possible for a stream's device to become disconnected during thew open or between + // the Open and the Start. // So if it fails to start, close the old stream and try again. int tryCount = 0; - bool startFailed = false; do { + if (tryCount > 0) { + usleep(20 * 1000); // Sleep between tries to give the system time to settle. + } mIsLatencyDetectionSupported = false; result = openPlaybackStream(); if (result == oboe::Result::OK){ @@ -155,16 +158,14 @@ oboe::Result HelloOboeEngine::start() { LOGE("Error starting playback stream. Error: %s", oboe::convertToText(result)); mStream->close(); mStream.reset(); - startFailed = true; } else { mIsLatencyDetectionSupported = (mStream->getTimestamp((CLOCK_MONOTONIC)) != oboe::Result::ErrorUnimplemented); - startFailed = false; } } else { LOGE("Error creating playback stream. Error: %s", oboe::convertToText(result)); } - } while (tryCount++ < 3 && startFailed); + } while (result != oboe::Result::OK && tryCount++ < 3); return result; } |