New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResultWithValue: Doc updates, version bump and code changes #109
Conversation
FullGuide.md
Outdated
return DataCallbackResult::Continue; | ||
} | ||
auto result = stream2.read(audioData, numFrames, timeout); | ||
if (result == Result::OK){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment here why it's possible first to compare result with an value of Result
and then with a number, and what does it mean. Otherwise might look confusing for a person not very familiar with type coercion operator overloading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this update. Have you uploaded it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't hit save in my text editor 🤦♂️ . Fixed now.
src/common/LatencyTuner.cpp
Outdated
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2017 The Android Open Source Project | |||
* Copyright 2018 The Android Open Source Project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that you don't have to update the year when editing existing files. New files need to receive the current year when added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted, thanks for the info.
} | ||
|
||
// When state is Active attempt to change the buffer size if the number of xRuns has increased. | ||
if (mState == State::Active) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous version the code was setting state to Active
and then breaking out of case
. In this edition the behavior changes. Is it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot. I've amended to keep in line with the old behaviour.
With hindsight it might have been better to let @philburk refactor this code. It probably wants splitting into smaller methods.
789ce9e
to
9686322
Compare
v0.11 ResultWithValue - BREAKING CHANGE!
This change (and this one) add a new object
ResultWithValue
and change some of theAudioStream
method signatures in the Oboe library.Why make this change?
Some of the
AudioStream
methods would return a positive (or zero) value if they were successful and a negative value if not. For example, consider the following code which attempts to set a stream's buffer size:The
setBufferSizeInFrames
method is actually returning two pieces of information:The method breaks the single responsibility principle which can lead to inelegant and confusing code. Also, casting an
int32_t
to aResult
is a bug waiting to happen!What's new then?
To solve this problem we added a new object
ResultWithValue
which encapsulates the 2 pieces of information above.You can check whether an operation was successful by comparing the
ResultWithValue
with aResult
(e.g.if (result != Result::OK) { // error }
, or by callingResultWithValue::error()
.The value can be retrieved by calling
ResultWithValue::value()
.The above code can now be made more readable:
Which methods are affected?
The following methods in AudioStream have updated method signatures:
If you are using any of the above methods you'll need to update your code in line with the example above.