// This function ensures that egress streams always send real world up // streams. // Note: There are two components of the camera rotation. The rotation of // the capturer relative to the device. I.e. up for the camera might not be // device up. When rotating the device the camera is also rotated. // The former is called orientation and the second is called rotation here. public virtual void compensateCameraRotation() { int cameraOrientation = cameraOrientations[(int)facingOf(usingFrontCamera)]; // The device orientation is the device's rotation relative to its // natural position. int cameraRotation = roundRotation(currentDeviceOrientation); int totalCameraRotation = 0; if (usingFrontCamera) { // The front camera rotates in the opposite direction of the // device. int inverseCameraRotation = (360 - cameraRotation) % 360; totalCameraRotation = (inverseCameraRotation + cameraOrientation) % 360; } else { totalCameraRotation = (cameraRotation + cameraOrientation) % 360; } viEAndroidJavaAPI.SetRotation(cameraId, totalCameraRotation); }