VolumeShaper: Improve restore
Consider whether VolumeShaper has been started or not when
restoring (position). If the VolumeShaper hasn't been started
we restore in that state. If it has been started already,
we advance to the end assuming the duration has been played out.
Test: CTS and headset / kill audioserver
Bug: 37536598
Change-Id: I4b55dca6f6a859563fd20bad4c8f67d2c92321c0
diff --git a/include/media/VolumeShaper.h b/include/media/VolumeShaper.h
index 4ddb8d3..1282124 100644
--- a/include/media/VolumeShaper.h
+++ b/include/media/VolumeShaper.h
@@ -528,6 +528,10 @@
mDelayXOffset = xOffset;
}
+ bool isStarted() const {
+ return mStartFrame >= 0;
+ }
+
std::pair<T /* volume */, bool /* active */> getVolume(
int64_t trackFrameCount, double trackSampleRate) {
if ((getFlags() & VolumeShaper::Operation::FLAG_DELAY) != 0) {
@@ -752,6 +756,8 @@
return it->getState();
}
+ // getVolume() is not const, as it updates internal state.
+ // Once called, any VolumeShapers not already started begin running.
std::pair<T /* volume */, bool /* active */> getVolume(int64_t trackFrameCount) {
AutoMutex _l(mLock);
mLastFrame = trackFrameCount;
@@ -768,6 +774,14 @@
return mLastVolume;
}
+ // Used by a client side VolumeHandler to ensure all the VolumeShapers
+ // indicate that they have been started. Upon a change in audioserver
+ // output sink, this information is used for restoration of the server side
+ // VolumeHandler.
+ void setStarted() {
+ (void)getVolume(mLastFrame); // getVolume() will start the individual VolumeShapers.
+ }
+
std::pair<T /* volume */, bool /* active */> getLastVolume() const {
AutoMutex _l(mLock);
return mLastVolume;
@@ -784,14 +798,12 @@
return ss.str();
}
- void forall(const std::function<VolumeShaper::Status (
- const sp<VolumeShaper::Configuration> &configuration,
- const sp<VolumeShaper::Operation> &operation)> &lambda) {
+ void forall(const std::function<VolumeShaper::Status (const VolumeShaper &)> &lambda) {
AutoMutex _l(mLock);
VS_LOG("forall: mVolumeShapers.size() %zu", mVolumeShapers.size());
for (const auto &shaper : mVolumeShapers) {
- VS_LOG("forall applying lambda");
- (void)lambda(shaper.mConfiguration, shaper.mOperation);
+ VolumeShaper::Status status = lambda(shaper);
+ VS_LOG("forall applying lambda on shaper (%p): %d", &shaper, (int)status);
}
}