PlayerBase volume: make it a volume multiplier
Make PlayerBase / PlayerProxy volume control act as a multiplier,
not as an override of the volume set by the subclass
Bug: 78930229
Test: see test app in bug
Change-Id: I4c189425282c1a709648e0be14791c3382e83e82
diff --git a/media/java/android/media/PlayerBase.java b/media/java/android/media/PlayerBase.java
index fbe5152..2e7cb95 100644
--- a/media/java/android/media/PlayerBase.java
+++ b/media/java/android/media/PlayerBase.java
@@ -52,6 +52,10 @@
// parameters of the player that affect AppOps
protected AudioAttributes mAttributes;
+
+ // volumes of the subclass "player volumes", as seen by the client of the subclass
+ // (e.g. what was passed in AudioTrack.setVolume(float)). The actual volume applied is
+ // the combination of the player volume, and the PlayerBase pan and volume multipliers
protected float mLeftVolume = 1.0f;
protected float mRightVolume = 1.0f;
protected float mAuxEffectSendLevel = 0.0f;
@@ -79,6 +83,8 @@
private float mPanMultiplierL = 1.0f;
@GuardedBy("mLock")
private float mPanMultiplierR = 1.0f;
+ @GuardedBy("mLock")
+ private float mVolMultiplier = 1.0f;
/**
* Constructor. Must be given audio attributes, as they are required for AppOps.
@@ -199,18 +205,33 @@
mPanMultiplierR = 1.0f + p;
}
}
- baseSetVolume(mLeftVolume, mRightVolume);
+ updatePlayerVolume();
+ }
+
+ private void updatePlayerVolume() {
+ final float finalLeftVol, finalRightVol;
+ final boolean isRestricted;
+ synchronized (mLock) {
+ finalLeftVol = mVolMultiplier * mLeftVolume * mPanMultiplierL;
+ finalRightVol = mVolMultiplier * mRightVolume * mPanMultiplierR;
+ isRestricted = isRestricted_sync();
+ }
+ playerSetVolume(isRestricted /*muting*/, finalLeftVol, finalRightVol);
+ }
+
+ void setVolumeMultiplier(float vol) {
+ synchronized (mLock) {
+ this.mVolMultiplier = vol;
+ }
+ updatePlayerVolume();
}
void baseSetVolume(float leftVolume, float rightVolume) {
- final boolean isRestricted;
synchronized (mLock) {
mLeftVolume = leftVolume;
mRightVolume = rightVolume;
- isRestricted = isRestricted_sync();
}
- playerSetVolume(isRestricted/*muting*/,
- leftVolume * mPanMultiplierL, rightVolume * mPanMultiplierR);
+ updatePlayerVolume();
}
int baseSetAuxEffectSendLevel(float level) {
@@ -466,7 +487,7 @@
public void setVolume(float vol) {
final PlayerBase pb = mWeakPB.get();
if (pb != null) {
- pb.baseSetVolume(vol, vol);
+ pb.setVolumeMultiplier(vol);
}
}