| Index: webrtc/api/android/java/src/org/webrtc/RendererCommon.java
|
| diff --git a/webrtc/api/android/java/src/org/webrtc/RendererCommon.java b/webrtc/api/android/java/src/org/webrtc/RendererCommon.java
|
| index 3cec5b0cd3e48752cbf300110562c1a6f0b69ad8..8eb046128dc7edf18e8b2efa7aa6654fc45b620b 100644
|
| --- a/webrtc/api/android/java/src/org/webrtc/RendererCommon.java
|
| +++ b/webrtc/api/android/java/src/org/webrtc/RendererCommon.java
|
| @@ -13,6 +13,7 @@ package org.webrtc;
|
| import android.graphics.Point;
|
| import android.opengl.GLES20;
|
| import android.opengl.Matrix;
|
| +import android.view.View;
|
|
|
| import java.nio.ByteBuffer;
|
|
|
| @@ -103,6 +104,56 @@ public class RendererCommon {
|
| }
|
| }
|
|
|
| + /**
|
| + * Helper class for determining layout size based on layout requirements, scaling type, and video
|
| + * aspect ratio.
|
| + */
|
| + public static class VideoLayoutMeasure {
|
| + // The scaling type determines how the video will fill the allowed layout area in measure(). It
|
| + // can be specified separately for the case when video has matched orientation with layout size
|
| + // and when there is an orientation mismatch.
|
| + private ScalingType scalingTypeMatchOrientation = ScalingType.SCALE_ASPECT_BALANCED;
|
| + private ScalingType scalingTypeMismatchOrientation = ScalingType.SCALE_ASPECT_BALANCED;
|
| +
|
| + public void setScalingType(ScalingType scalingType) {
|
| + this.scalingTypeMatchOrientation = scalingType;
|
| + this.scalingTypeMismatchOrientation = scalingType;
|
| + }
|
| +
|
| + public void setScalingType(
|
| + ScalingType scalingTypeMatchOrientation, ScalingType scalingTypeMismatchOrientation) {
|
| + this.scalingTypeMatchOrientation = scalingTypeMatchOrientation;
|
| + this.scalingTypeMismatchOrientation = scalingTypeMismatchOrientation;
|
| + }
|
| +
|
| + public Point measure(int widthSpec, int heightSpec, int frameWidth, int frameHeight) {
|
| + // Calculate max allowed layout size.
|
| + final int maxWidth = View.getDefaultSize(Integer.MAX_VALUE, widthSpec);
|
| + final int maxHeight = View.getDefaultSize(Integer.MAX_VALUE, heightSpec);
|
| + if (frameWidth == 0 || frameHeight == 0 || maxWidth == 0 || maxHeight == 0) {
|
| + return new Point(maxWidth, maxHeight);
|
| + }
|
| + // Calculate desired display size based on scaling type, video aspect ratio,
|
| + // and maximum layout size.
|
| + final float frameAspect = frameWidth / (float) frameHeight;
|
| + final float displayAspect = maxWidth / (float) maxHeight;
|
| + final RendererCommon.ScalingType scalingType = (frameAspect > 1.0f) == (displayAspect > 1.0f)
|
| + ? scalingTypeMatchOrientation
|
| + : scalingTypeMismatchOrientation;
|
| + final Point layoutSize =
|
| + RendererCommon.getDisplaySize(scalingType, frameAspect, maxWidth, maxHeight);
|
| +
|
| + // If the measure specification is forcing a specific size - yield.
|
| + if (View.MeasureSpec.getMode(widthSpec) == View.MeasureSpec.EXACTLY) {
|
| + layoutSize.x = maxWidth;
|
| + }
|
| + if (View.MeasureSpec.getMode(heightSpec) == View.MeasureSpec.EXACTLY) {
|
| + layoutSize.y = maxHeight;
|
| + }
|
| + return layoutSize;
|
| + }
|
| + }
|
| +
|
| // Types of video scaling:
|
| // SCALE_ASPECT_FIT - video frame is scaled to fit the size of the view by
|
| // maintaining the aspect ratio (black borders may be displayed).
|
|
|