Merge changes from topic "spatializer_device_state_update"
* changes: AudioService: RotationHelper.forceUpdate fix Spatial Audio: Fix display orientation, add fold state
This commit is contained in:
@@ -1313,8 +1313,8 @@ public class AudioService extends IAudioService.Stub
|
||||
intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||
if (mMonitorRotation) {
|
||||
RotationHelper.init(mContext, mAudioHandler,
|
||||
rotationParam -> onRotationUpdate(rotationParam),
|
||||
foldParam -> onFoldUpdate(foldParam));
|
||||
rotation -> onRotationUpdate(rotation),
|
||||
foldState -> onFoldStateUpdate(foldState));
|
||||
}
|
||||
|
||||
intentFilter.addAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
|
||||
@@ -1463,16 +1463,20 @@ public class AudioService extends IAudioService.Stub
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// rotation/fold updates coming from RotationHelper
|
||||
void onRotationUpdate(String rotationParameter) {
|
||||
void onRotationUpdate(Integer rotation) {
|
||||
mSpatializerHelper.setDisplayOrientation((float) (rotation * Math.PI / 180.));
|
||||
// use REPLACE as only the last rotation matters
|
||||
final String rotationParameter = "rotation=" + rotation;
|
||||
sendMsg(mAudioHandler, MSG_ROTATION_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0,
|
||||
/*obj*/ rotationParameter, /*delay*/ 0);
|
||||
}
|
||||
|
||||
void onFoldUpdate(String foldParameter) {
|
||||
void onFoldStateUpdate(Boolean foldState) {
|
||||
mSpatializerHelper.setFoldState(foldState);
|
||||
// use REPLACE as only the last fold state matters
|
||||
final String foldStateParameter = "device_folded=" + (foldState ? "on" : "off");
|
||||
sendMsg(mAudioHandler, MSG_FOLD_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0,
|
||||
/*obj*/ foldParameter, /*delay*/ 0);
|
||||
/*obj*/ foldStateParameter, /*delay*/ 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
@@ -1687,6 +1691,11 @@ public class AudioService extends IAudioService.Stub
|
||||
|
||||
mSpatializerHelper.reset(/* featureEnabled */ mHasSpatializerEffect);
|
||||
|
||||
// Restore rotation information.
|
||||
if (mMonitorRotation) {
|
||||
RotationHelper.forceUpdate();
|
||||
}
|
||||
|
||||
onIndicateSystemReady();
|
||||
// indicate the end of reconfiguration phase to audio HAL
|
||||
AudioSystem.setParameters("restarting=false");
|
||||
|
||||
@@ -55,14 +55,14 @@ class RotationHelper {
|
||||
private static AudioDisplayListener sDisplayListener;
|
||||
private static FoldStateListener sFoldStateListener;
|
||||
/** callback to send rotation updates to AudioSystem */
|
||||
private static Consumer<String> sRotationUpdateCb;
|
||||
private static Consumer<Integer> sRotationCallback;
|
||||
/** callback to send folded state updates to AudioSystem */
|
||||
private static Consumer<String> sFoldUpdateCb;
|
||||
private static Consumer<Boolean> sFoldStateCallback;
|
||||
|
||||
private static final Object sRotationLock = new Object();
|
||||
private static final Object sFoldStateLock = new Object();
|
||||
private static int sDeviceRotation = Surface.ROTATION_0; // R/W synchronized on sRotationLock
|
||||
private static boolean sDeviceFold = true; // R/W synchronized on sFoldStateLock
|
||||
private static Integer sRotation = null; // R/W synchronized on sRotationLock
|
||||
private static Boolean sFoldState = null; // R/W synchronized on sFoldStateLock
|
||||
|
||||
private static Context sContext;
|
||||
private static Handler sHandler;
|
||||
@@ -73,15 +73,15 @@ class RotationHelper {
|
||||
* - sContext != null
|
||||
*/
|
||||
static void init(Context context, Handler handler,
|
||||
Consumer<String> rotationUpdateCb, Consumer<String> foldUpdateCb) {
|
||||
Consumer<Integer> rotationCallback, Consumer<Boolean> foldStateCallback) {
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("Invalid null context");
|
||||
}
|
||||
sContext = context;
|
||||
sHandler = handler;
|
||||
sDisplayListener = new AudioDisplayListener();
|
||||
sRotationUpdateCb = rotationUpdateCb;
|
||||
sFoldUpdateCb = foldUpdateCb;
|
||||
sRotationCallback = rotationCallback;
|
||||
sFoldStateCallback = foldStateCallback;
|
||||
enable();
|
||||
}
|
||||
|
||||
@@ -112,9 +112,9 @@ class RotationHelper {
|
||||
int newRotation = DisplayManagerGlobal.getInstance()
|
||||
.getDisplayInfo(Display.DEFAULT_DISPLAY).rotation;
|
||||
synchronized(sRotationLock) {
|
||||
if (newRotation != sDeviceRotation) {
|
||||
sDeviceRotation = newRotation;
|
||||
publishRotation(sDeviceRotation);
|
||||
if (sRotation == null || sRotation != newRotation) {
|
||||
sRotation = newRotation;
|
||||
publishRotation(sRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,43 +123,52 @@ class RotationHelper {
|
||||
if (DEBUG_ROTATION) {
|
||||
Log.i(TAG, "publishing device rotation =" + rotation + " (x90deg)");
|
||||
}
|
||||
String rotationParam;
|
||||
int rotationDegrees;
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
rotationParam = "rotation=0";
|
||||
rotationDegrees = 0;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
rotationParam = "rotation=90";
|
||||
rotationDegrees = 90;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
rotationParam = "rotation=180";
|
||||
rotationDegrees = 180;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
rotationParam = "rotation=270";
|
||||
rotationDegrees = 270;
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Unknown device rotation");
|
||||
rotationParam = null;
|
||||
rotationDegrees = -1;
|
||||
}
|
||||
if (rotationParam != null) {
|
||||
sRotationUpdateCb.accept(rotationParam);
|
||||
if (rotationDegrees != -1) {
|
||||
sRotationCallback.accept(rotationDegrees);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* publish the change of device folded state if any.
|
||||
*/
|
||||
static void updateFoldState(boolean newFolded) {
|
||||
static void updateFoldState(boolean foldState) {
|
||||
synchronized (sFoldStateLock) {
|
||||
if (sDeviceFold != newFolded) {
|
||||
sDeviceFold = newFolded;
|
||||
String foldParam;
|
||||
if (newFolded) {
|
||||
foldParam = "device_folded=on";
|
||||
} else {
|
||||
foldParam = "device_folded=off";
|
||||
}
|
||||
sFoldUpdateCb.accept(foldParam);
|
||||
if (sFoldState == null || sFoldState != foldState) {
|
||||
sFoldState = foldState;
|
||||
sFoldStateCallback.accept(foldState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* forceUpdate is called when audioserver restarts.
|
||||
*/
|
||||
static void forceUpdate() {
|
||||
synchronized (sRotationLock) {
|
||||
sRotation = null;
|
||||
}
|
||||
updateOrientation(); // We will get at least one orientation update now.
|
||||
synchronized (sFoldStateLock) {
|
||||
if (sFoldState != null) {
|
||||
sFoldStateCallback.accept(sFoldState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,4 +194,4 @@ class RotationHelper {
|
||||
updateOrientation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,7 +1063,7 @@ public class SpatializerHelper {
|
||||
if (transform.length != 6) {
|
||||
throw new IllegalArgumentException("invalid array size" + transform.length);
|
||||
}
|
||||
if (!checkSpatForHeadTracking("setGlobalTransform")) {
|
||||
if (!checkSpatializerForHeadTracking("setGlobalTransform")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -1074,7 +1074,7 @@ public class SpatializerHelper {
|
||||
}
|
||||
|
||||
synchronized void recenterHeadTracker() {
|
||||
if (!checkSpatForHeadTracking("recenterHeadTracker")) {
|
||||
if (!checkSpatializerForHeadTracking("recenterHeadTracker")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -1084,8 +1084,30 @@ public class SpatializerHelper {
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void setDisplayOrientation(float displayOrientation) {
|
||||
if (!checkSpatializer("setDisplayOrientation")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
mSpat.setDisplayOrientation(displayOrientation);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling setDisplayOrientation", e);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void setFoldState(boolean folded) {
|
||||
if (!checkSpatializer("setFoldState")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
mSpat.setFoldState(folded);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error calling setFoldState", e);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void setDesiredHeadTrackingMode(@Spatializer.HeadTrackingModeSet int mode) {
|
||||
if (!checkSpatForHeadTracking("setDesiredHeadTrackingMode")) {
|
||||
if (!checkSpatializerForHeadTracking("setDesiredHeadTrackingMode")) {
|
||||
return;
|
||||
}
|
||||
if (mode != Spatializer.HEAD_TRACKING_MODE_DISABLED) {
|
||||
@@ -1178,7 +1200,7 @@ public class SpatializerHelper {
|
||||
return mHeadTrackerAvailable;
|
||||
}
|
||||
|
||||
private boolean checkSpatForHeadTracking(String funcName) {
|
||||
private boolean checkSpatializer(String funcName) {
|
||||
switch (mState) {
|
||||
case STATE_UNINITIALIZED:
|
||||
case STATE_NOT_SUPPORTED:
|
||||
@@ -1189,14 +1211,18 @@ public class SpatializerHelper {
|
||||
case STATE_ENABLED_AVAILABLE:
|
||||
if (mSpat == null) {
|
||||
// try to recover by resetting the native spatializer state
|
||||
Log.e(TAG, "checkSpatForHeadTracking(): "
|
||||
+ "native spatializer should not be null in state: " + mState);
|
||||
Log.e(TAG, "checkSpatializer(): called from " + funcName
|
||||
+ "(), native spatializer should not be null in state: " + mState);
|
||||
postReset();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return mIsHeadTrackingSupported;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkSpatializerForHeadTracking(String funcName) {
|
||||
return checkSpatializer(funcName) && mIsHeadTrackingSupported;
|
||||
}
|
||||
|
||||
private void dispatchActualHeadTrackingMode(int newMode) {
|
||||
|
||||
Reference in New Issue
Block a user