-
Notifications
You must be signed in to change notification settings - Fork 565
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
Implement getFramesRead for OpenSL ES OUTPUT #89
Conversation
and getFramesWritten for OpenSL ES INPUT. Query position in milliseconds from OpenSL ES. Use MonotonicCounter to build 64-bit frame counter from 32-bit internal counter. Fixes Issue #81
} | ||
|
||
private: | ||
int64_t mCounter64 = 0; |
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.
Maybe should be atomic.
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.
Atomicity isn't for free--there are costs on synchronizing CPU caches. Also, in update32
we seem to update both 32-bit and 64-bit counters in one transaction. This will require making the whole pair to be atomic.
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.
Is there an std::atomic way to do that or do you just mean to use a mutex?
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.
Make a struct and put it into std::atomic
. Depending on different conditions it may use a mutex internally, you can check that with is_lock_free
function: http://en.cppreference.com/w/cpp/atomic/atomic/is_lock_free
For two counters, it should usually be lock-free, unless it's a 32-bit ARM CPU and the fields alignment is wrong.
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.
Mikhail and I talked. The caller is only updating the internal data from one thread at a time. So I will document that this is not thread-safe and require caller to guarantee synchronization.
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.
Done
} | ||
return result; | ||
} | ||
|
||
int64_t AudioInputStreamOpenSLES::getFramesWritten() const { | ||
int64_t millis64 = mPositionMillis.get(); |
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.
Extract common function and call from OutputStream
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.
Done
mPositionMillis.reset32(); // OpenSL ES resets its millisecond position when stopped. | ||
int64_t framesWritten = getFramesWritten(); | ||
if (framesWritten >= 0) { | ||
setFramesRead(framesWritten); |
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.
This is supposed to prevent drift but does not seem to be working.
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.
Is no longer drifting.
@@ -0,0 +1,110 @@ | |||
/* | |||
* Copyright 2016 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.
2018
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.
The code was written in 2016. I copied it from inside AAudio.
src/common/MonotonicCounter.h
Outdated
/** | ||
* Round 64-bit counter up to a multiple of the period. | ||
* | ||
* @param period might be, for example, a buffer capacity |
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.
Specify that it has to be a positive integer.
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.
Done
} | ||
|
||
private: | ||
int64_t mCounter64 = 0; |
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.
Atomicity isn't for free--there are costs on synchronizing CPU caches. Also, in update32
we seem to update both 32-bit and 64-bit counters in one transaction. This will require making the whole pair to be atomic.
|
||
int64_t AudioStreamOpenSLES::getFramesProcessedByServer() const { | ||
int64_t millis64 = mPositionMillis.get(); | ||
int64_t framesRead = millis64 * getSampleRate() / kMillisPerSecond; |
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.
change to framesProcessed
and getFramesWritten for OpenSL ES INPUT.
Query position in milliseconds from OpenSL ES.
Use MonotonicCounter to build 64-bit frame counter from
32-bit internal counter.
Fixes Issue #81