private void updateTransform()

in AmazonKinesisVideoDemoApp/src/main/java/com/amazonaws/kinesisvideo/demoapp/fragment/StreamingFragment.java [226:267]


    private void updateTransform(int width, int height) {
        if (width != 0 && height != 0 && mTextureView != null && cameraPreviewSize != null) {
            Log.d(TAG, "Updating the matrix with width=" + width + ", height=" + height);
            Matrix transformationMatrix = new Matrix();
            RectF inputRectF = new RectF(0, 0, mTextureView.getWidth(), mTextureView.getHeight());
            RectF outputRectF = new RectF(0, 0, cameraPreviewSize.getHeight(), cameraPreviewSize.getWidth()); // since it's offset by 90, the width and height are switched
            // see https://source.android.com/compatibility/android-cdd#7_5_5_camera_orientation for more info
            float centerX = inputRectF.centerX();
            float centerY = inputRectF.centerY();
            outputRectF.offset(centerX - outputRectF.centerX(),
                    centerY - outputRectF.centerY());
            transformationMatrix.setRectToRect(inputRectF, outputRectF, Matrix.ScaleToFit.FILL);
            Log.d(TAG, "inputRectF: " + inputRectF.toShortString());
            Log.d(TAG, "outputRectF: " + outputRectF.toShortString());

            if (mShouldMaintainAspectRatio) {
                float scale1, scale2;
                if (mRotation % 180 == 0) {
                    scale1 = (float) height / cameraPreviewSize.getWidth();
                    scale2 = (float) width / cameraPreviewSize.getHeight();
                } else {
                    scale1 = (float) height / cameraPreviewSize.getHeight();
                    scale2 = (float) width / cameraPreviewSize.getWidth();
                }
                float scale = mShouldFillScreen ? Math.max(scale1, scale2) : Math.min(scale1, scale2);
                transformationMatrix.postScale(scale, scale, centerX, centerY);
            }
            transformationMatrix.postRotate(mRotation, centerX, centerY);

            mTextureView.setTransform(transformationMatrix);

            if (mIsMirrored) {
                // https://source.android.com/compatibility/android-cdd#7_5_2_front-facing_camera
                // Front-facing camera is mirrored by default. You need to mirror it again to un-mirror it.
                if ((mConfiguration.getCameraFacing() == CameraCharacteristics.LENS_FACING_FRONT) == (mRotation % 180 == 0)) {
                    mTextureView.setScaleX(-1);
                } else {
                    mTextureView.setScaleY(-1);
                }
            }
        }
    }