mirror of
https://github.com/samsonjs/media.git
synced 2026-03-30 10:15:48 +00:00
Split configureOutputSize into setInputSize and getOutputSize.
This makes it easier (smaller CL diff) to merge output size configuration and initialize() in a follow-up. PiperOrigin-RevId: 438543247
This commit is contained in:
parent
d8e5e2de7a
commit
70cffd8cca
10 changed files with 119 additions and 89 deletions
|
|
@ -89,6 +89,7 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
|
|||
private final Context context;
|
||||
private final Matrix transformationMatrix;
|
||||
|
||||
private @MonotonicNonNull Size size;
|
||||
private @MonotonicNonNull GlProgram glProgram;
|
||||
|
||||
/**
|
||||
|
|
@ -105,8 +106,13 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Size configureOutputSize(int inputWidth, int inputHeight) {
|
||||
return new Size(inputWidth, inputHeight);
|
||||
public void setInputSize(int inputWidth, int inputHeight) {
|
||||
size = new Size(inputWidth, inputHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getOutputSize() {
|
||||
return checkStateNotNull(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
private final Context context;
|
||||
private final boolean enableExperimentalHdrEditing;
|
||||
|
||||
private @MonotonicNonNull Size size;
|
||||
private @MonotonicNonNull GlProgram glProgram;
|
||||
|
||||
public ExternalCopyFrameProcessor(Context context, boolean enableExperimentalHdrEditing) {
|
||||
|
|
@ -59,8 +60,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
}
|
||||
|
||||
@Override
|
||||
public Size configureOutputSize(int inputWidth, int inputHeight) {
|
||||
return new Size(inputWidth, inputHeight);
|
||||
public void setInputSize(int inputWidth, int inputHeight) {
|
||||
size = new Size(inputWidth, inputHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getOutputSize() {
|
||||
return checkStateNotNull(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import android.opengl.EGLDisplay;
|
|||
import android.opengl.EGLExt;
|
||||
import android.opengl.EGLSurface;
|
||||
import android.opengl.GLES20;
|
||||
import android.util.Pair;
|
||||
import android.util.Size;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceView;
|
||||
|
|
@ -79,6 +78,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
private volatile boolean releaseRequested;
|
||||
|
||||
private boolean inputStreamEnded;
|
||||
private final Size inputSize;
|
||||
/** Wraps the {@link #inputSurfaceTexture}. */
|
||||
private @MonotonicNonNull Surface inputSurface;
|
||||
/** Associated with an OpenGL external texture. */
|
||||
|
|
@ -100,11 +100,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
* <p>The {@link ExternalCopyFrameProcessor} writes to the first framebuffer.
|
||||
*/
|
||||
private final int[] framebuffers;
|
||||
/** The input {@link Size} of each of the {@code frameProcessors}. */
|
||||
private final ImmutableList<Size> inputSizes;
|
||||
|
||||
private int outputWidth;
|
||||
private int outputHeight;
|
||||
private Size outputSize;
|
||||
/**
|
||||
* Wraps the output {@link Surface} that is populated with the output of the final {@link
|
||||
* GlFrameProcessor} for each frame.
|
||||
|
|
@ -154,30 +151,27 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
singleThreadExecutorService = Util.newSingleThreadExecutor(THREAD_NAME);
|
||||
futures = new ConcurrentLinkedQueue<>();
|
||||
pendingFrameCount = new AtomicInteger();
|
||||
inputSize = new Size(inputWidth, inputHeight);
|
||||
textureTransformMatrix = new float[16];
|
||||
externalCopyFrameProcessor =
|
||||
new ExternalCopyFrameProcessor(context, enableExperimentalHdrEditing);
|
||||
framebuffers = new int[frameProcessors.size()];
|
||||
Pair<ImmutableList<Size>, Size> sizes =
|
||||
configureFrameProcessorSizes(inputWidth, inputHeight, frameProcessors);
|
||||
inputSizes = sizes.first;
|
||||
outputWidth = sizes.second.getWidth();
|
||||
outputHeight = sizes.second.getHeight();
|
||||
configureFrameProcessorSizes(inputSize, frameProcessors);
|
||||
outputSize = frameProcessors.isEmpty() ? inputSize : getLast(frameProcessors).getOutputSize();
|
||||
debugPreviewWidth = C.LENGTH_UNSET;
|
||||
debugPreviewHeight = C.LENGTH_UNSET;
|
||||
}
|
||||
|
||||
/** Returns the output {@link Size}. */
|
||||
public Size getOutputSize() {
|
||||
return new Size(outputWidth, outputHeight);
|
||||
return outputSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the {@code FrameProcessorChain} to process frames to the specified output targets.
|
||||
*
|
||||
* <p>This method may only be called once and may override the {@linkplain
|
||||
* GlFrameProcessor#configureOutputSize(int, int) output size} of the final {@link
|
||||
* GlFrameProcessor}.
|
||||
* GlFrameProcessor#setInputSize(int, int) output size} of the final {@link GlFrameProcessor}.
|
||||
*
|
||||
* @param outputSurface The output {@link Surface}.
|
||||
* @param outputWidth The output width, in pixels.
|
||||
|
|
@ -196,8 +190,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
checkState(inputSurface == null, "The FrameProcessorChain has already been configured.");
|
||||
// TODO(b/218488308): Don't override output size for encoder fallback. Instead allow the final
|
||||
// GlFrameProcessor to be re-configured or append another GlFrameProcessor.
|
||||
this.outputWidth = outputWidth;
|
||||
this.outputHeight = outputHeight;
|
||||
outputSize = new Size(outputWidth, outputHeight);
|
||||
|
||||
if (debugSurfaceView != null) {
|
||||
debugPreviewWidth = debugSurfaceView.getWidth();
|
||||
|
|
@ -387,15 +380,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
}
|
||||
|
||||
inputExternalTexId = GlUtil.createExternalTexture();
|
||||
Size inputSize = inputSizes.get(0);
|
||||
externalCopyFrameProcessor.configureOutputSize(inputSize.getWidth(), inputSize.getHeight());
|
||||
externalCopyFrameProcessor.setInputSize(inputSize.getWidth(), inputSize.getHeight());
|
||||
externalCopyFrameProcessor.initialize(inputExternalTexId);
|
||||
|
||||
Size intermediateSize = inputSize;
|
||||
for (int i = 0; i < frameProcessors.size(); i++) {
|
||||
inputSize = inputSizes.get(i);
|
||||
int inputTexId = GlUtil.createTexture(inputSize.getWidth(), inputSize.getHeight());
|
||||
int inputTexId =
|
||||
GlUtil.createTexture(intermediateSize.getWidth(), intermediateSize.getHeight());
|
||||
framebuffers[i] = GlUtil.createFboForTexture(inputTexId);
|
||||
frameProcessors.get(i).initialize(inputTexId);
|
||||
intermediateSize = frameProcessors.get(i).getOutputSize();
|
||||
}
|
||||
// Return something because only Callables not Runnables can throw checked exceptions.
|
||||
return null;
|
||||
|
|
@ -414,15 +408,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
checkStateNotNull(eglDisplay);
|
||||
|
||||
if (frameProcessors.isEmpty()) {
|
||||
GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight);
|
||||
GlUtil.focusEglSurface(
|
||||
eglDisplay, eglContext, eglSurface, outputSize.getWidth(), outputSize.getHeight());
|
||||
} else {
|
||||
GlUtil.focusFramebuffer(
|
||||
eglDisplay,
|
||||
eglContext,
|
||||
eglSurface,
|
||||
framebuffers[0],
|
||||
inputSizes.get(0).getWidth(),
|
||||
inputSizes.get(0).getHeight());
|
||||
inputSize.getWidth(),
|
||||
inputSize.getHeight());
|
||||
}
|
||||
inputSurfaceTexture.updateTexImage();
|
||||
inputSurfaceTexture.getTransformMatrix(textureTransformMatrix);
|
||||
|
|
@ -433,19 +428,20 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
externalCopyFrameProcessor.updateProgramAndDraw(presentationTimeUs);
|
||||
|
||||
for (int i = 0; i < frameProcessors.size() - 1; i++) {
|
||||
Size outputSize = inputSizes.get(i + 1);
|
||||
Size intermediateSize = frameProcessors.get(i).getOutputSize();
|
||||
GlUtil.focusFramebuffer(
|
||||
eglDisplay,
|
||||
eglContext,
|
||||
eglSurface,
|
||||
framebuffers[i + 1],
|
||||
outputSize.getWidth(),
|
||||
outputSize.getHeight());
|
||||
intermediateSize.getWidth(),
|
||||
intermediateSize.getHeight());
|
||||
clearOutputFrame();
|
||||
frameProcessors.get(i).updateProgramAndDraw(presentationTimeUs);
|
||||
}
|
||||
if (!frameProcessors.isEmpty()) {
|
||||
GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight);
|
||||
GlUtil.focusEglSurface(
|
||||
eglDisplay, eglContext, eglSurface, outputSize.getWidth(), outputSize.getHeight());
|
||||
clearOutputFrame();
|
||||
getLast(frameProcessors).updateProgramAndDraw(presentationTimeUs);
|
||||
}
|
||||
|
|
@ -474,26 +470,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
/**
|
||||
* Configures the input and output {@linkplain Size sizes} of a list of {@link GlFrameProcessor
|
||||
* GlFrameProcessors}.
|
||||
*
|
||||
* @param inputWidth The width of frames passed to the first {@link GlFrameProcessor}, in pixels.
|
||||
* @param inputHeight The height of frames passed to the first {@link GlFrameProcessor}, in
|
||||
* pixels.
|
||||
* @param frameProcessors The {@link GlFrameProcessor GlFrameProcessors}.
|
||||
* @return The input {@link Size} of each {@link GlFrameProcessor} and the output {@link Size} of
|
||||
* the final {@link GlFrameProcessor}.
|
||||
*/
|
||||
private static Pair<ImmutableList<Size>, Size> configureFrameProcessorSizes(
|
||||
int inputWidth, int inputHeight, List<GlFrameProcessor> frameProcessors) {
|
||||
Size size = new Size(inputWidth, inputHeight);
|
||||
if (frameProcessors.isEmpty()) {
|
||||
return Pair.create(ImmutableList.of(size), size);
|
||||
}
|
||||
|
||||
ImmutableList.Builder<Size> inputSizes = new ImmutableList.Builder<>();
|
||||
private static void configureFrameProcessorSizes(
|
||||
Size inputSize, List<GlFrameProcessor> frameProcessors) {
|
||||
for (int i = 0; i < frameProcessors.size(); i++) {
|
||||
inputSizes.add(size);
|
||||
size = frameProcessors.get(i).configureOutputSize(size.getWidth(), size.getHeight());
|
||||
frameProcessors.get(i).setInputSize(inputSize.getWidth(), inputSize.getHeight());
|
||||
inputSize = frameProcessors.get(i).getOutputSize();
|
||||
}
|
||||
return Pair.create(inputSizes.build(), size);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.io.IOException;
|
|||
*
|
||||
* <ol>
|
||||
* <li>The constructor, for implementation-specific arguments.
|
||||
* <li>{@link #configureOutputSize(int, int)}, to configure based on input dimensions.
|
||||
* <li>{@link #setInputSize(int, int)}, to configure based on input dimensions.
|
||||
* <li>{@link #initialize(int)}, to set up graphics initialization.
|
||||
* <li>{@link #updateProgramAndDraw(long)}, to process one frame.
|
||||
* <li>{@link #release()}, upon conclusion of processing.
|
||||
|
|
@ -38,13 +38,24 @@ public interface GlFrameProcessor {
|
|||
// using a placeholder surface until the encoder surface is known. If so, convert
|
||||
// configureOutputSize to a simple getter.
|
||||
|
||||
/**
|
||||
* Sets the input size of frames processed through {@link #updateProgramAndDraw(long)}.
|
||||
*
|
||||
* <p>This method must be called before {@link #initialize(int)} and does not use OpenGL, as
|
||||
* calling this method without a current OpenGL context is allowed.
|
||||
*
|
||||
* <p>After setting the input size, the output size can be obtained using {@link
|
||||
* #getOutputSize()}.
|
||||
*/
|
||||
void setInputSize(int inputWidth, int inputHeight);
|
||||
|
||||
/**
|
||||
* Returns the output {@link Size} of frames processed through {@link
|
||||
* #updateProgramAndDraw(long)}.
|
||||
*
|
||||
* <p>This method must be called before {@link #initialize(int)} and does not use OpenGL.
|
||||
* <p>Must call {@link #setInputSize(int, int)} before calling this method.
|
||||
*/
|
||||
Size configureOutputSize(int inputWidth, int inputHeight);
|
||||
Size getOutputSize();
|
||||
|
||||
/**
|
||||
* Does any initialization necessary such as loading and compiling a GLSL shader programs.
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
|
|||
private int inputWidth;
|
||||
private int inputHeight;
|
||||
private int outputRotationDegrees;
|
||||
private @MonotonicNonNull Size outputSize;
|
||||
private @MonotonicNonNull Matrix transformationMatrix;
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +107,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
|
|||
*
|
||||
* <p>Return values may be {@code 0} or {@code 90} degrees.
|
||||
*
|
||||
* <p>This method can only be called after {@link #configureOutputSize(int, int)}.
|
||||
* <p>This method can only be called after {@link #setInputSize(int, int)}.
|
||||
*/
|
||||
public int getOutputRotationDegrees() {
|
||||
checkState(outputRotationDegrees != C.LENGTH_UNSET);
|
||||
|
|
@ -114,7 +115,7 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Size configureOutputSize(int inputWidth, int inputHeight) {
|
||||
public void setInputSize(int inputWidth, int inputHeight) {
|
||||
this.inputWidth = inputWidth;
|
||||
this.inputHeight = inputHeight;
|
||||
transformationMatrix = new Matrix();
|
||||
|
|
@ -136,18 +137,23 @@ public final class PresentationFrameProcessor implements GlFrameProcessor {
|
|||
// TODO(b/201293185): After fragment shader transformations are implemented, put
|
||||
// postRotate in a later GlFrameProcessor.
|
||||
transformationMatrix.postRotate(outputRotationDegrees);
|
||||
return new Size(displayHeight, displayWidth);
|
||||
outputSize = new Size(displayHeight, displayWidth);
|
||||
} else {
|
||||
outputRotationDegrees = 0;
|
||||
return new Size(displayWidth, displayHeight);
|
||||
outputSize = new Size(displayWidth, displayHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getOutputSize() {
|
||||
return checkStateNotNull(outputSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(int inputTexId) throws IOException {
|
||||
checkStateNotNull(transformationMatrix);
|
||||
advancedFrameProcessor = new AdvancedFrameProcessor(context, transformationMatrix);
|
||||
advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
advancedFrameProcessor.initialize(inputTexId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
|
|||
private @MonotonicNonNull AdvancedFrameProcessor advancedFrameProcessor;
|
||||
private int inputWidth;
|
||||
private int inputHeight;
|
||||
private @MonotonicNonNull Size outputSize;
|
||||
private @MonotonicNonNull Matrix adjustedTransformationMatrix;
|
||||
|
||||
/**
|
||||
|
|
@ -125,13 +126,14 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Size configureOutputSize(int inputWidth, int inputHeight) {
|
||||
public void setInputSize(int inputWidth, int inputHeight) {
|
||||
this.inputWidth = inputWidth;
|
||||
this.inputHeight = inputHeight;
|
||||
adjustedTransformationMatrix = new Matrix(transformationMatrix);
|
||||
|
||||
if (transformationMatrix.isIdentity()) {
|
||||
return new Size(inputWidth, inputHeight);
|
||||
outputSize = new Size(inputWidth, inputHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
float inputAspectRatio = (float) inputWidth / inputHeight;
|
||||
|
|
@ -161,17 +163,19 @@ public final class ScaleToFitFrameProcessor implements GlFrameProcessor {
|
|||
float xScale = (xMax - xMin) / ndcWidthAndHeight;
|
||||
float yScale = (yMax - yMin) / ndcWidthAndHeight;
|
||||
adjustedTransformationMatrix.postScale(1f / xScale, 1f / yScale);
|
||||
outputSize = new Size(Math.round(inputWidth * xScale), Math.round(inputHeight * yScale));
|
||||
}
|
||||
|
||||
int outputWidth = Math.round(inputWidth * xScale);
|
||||
int outputHeight = Math.round(inputHeight * yScale);
|
||||
return new Size(outputWidth, outputHeight);
|
||||
@Override
|
||||
public Size getOutputSize() {
|
||||
return checkStateNotNull(outputSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(int inputTexId) throws IOException {
|
||||
checkStateNotNull(adjustedTransformationMatrix);
|
||||
advancedFrameProcessor = new AdvancedFrameProcessor(context, adjustedTransformationMatrix);
|
||||
advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
advancedFrameProcessor.initialize(inputTexId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,27 +27,28 @@ import org.junit.runner.RunWith;
|
|||
/**
|
||||
* Unit tests for {@link AdvancedFrameProcessor}.
|
||||
*
|
||||
* <p>See {@link AdvancedFrameProcessorPixelTest} for pixel tests testing {@link
|
||||
* <p>See {@code AdvancedFrameProcessorPixelTest} for pixel tests testing {@link
|
||||
* AdvancedFrameProcessor} given a transformation matrix.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public final class AdvancedFrameProcessorTest {
|
||||
@Test
|
||||
public void getOutputDimensions_withIdentityMatrix_leavesDimensionsUnchanged() {
|
||||
public void getOutputSize_withIdentityMatrix_leavesSizeUnchanged() {
|
||||
Matrix identityMatrix = new Matrix();
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
AdvancedFrameProcessor advancedFrameProcessor =
|
||||
new AdvancedFrameProcessor(getApplicationContext(), identityMatrix);
|
||||
|
||||
Size outputSize = advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = advancedFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOutputDimensions_withTransformationMatrix_leavesDimensionsUnchanged() {
|
||||
public void getOutputSize_withTransformationMatrix_leavesSizeUnchanged() {
|
||||
Matrix transformationMatrix = new Matrix();
|
||||
transformationMatrix.postRotate(/* degrees= */ 90);
|
||||
transformationMatrix.postScale(/* sx= */ .5f, /* sy= */ 1.2f);
|
||||
|
|
@ -56,7 +57,8 @@ public final class AdvancedFrameProcessorTest {
|
|||
AdvancedFrameProcessor advancedFrameProcessor =
|
||||
new AdvancedFrameProcessor(getApplicationContext(), transformationMatrix);
|
||||
|
||||
Size outputSize = advancedFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
advancedFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = advancedFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||
|
|
|
|||
|
|
@ -139,7 +139,10 @@ public final class FrameProcessorChainTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Size configureOutputSize(int inputWidth, int inputHeight) {
|
||||
public void setInputSize(int inputWidth, int inputHeight) {}
|
||||
|
||||
@Override
|
||||
public Size getOutputSize() {
|
||||
return outputSize;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@ import org.junit.runner.RunWith;
|
|||
@RunWith(AndroidJUnit4.class)
|
||||
public final class PresentationFrameProcessorTest {
|
||||
@Test
|
||||
public void configureOutputSize_noEditsLandscape_leavesFramesUnchanged() {
|
||||
public void getOutputSize_noEditsLandscape_leavesFramesUnchanged() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
PresentationFrameProcessor presentationFrameProcessor =
|
||||
new PresentationFrameProcessor.Builder(getApplicationContext()).build();
|
||||
|
||||
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = presentationFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0);
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||
|
|
@ -47,13 +48,14 @@ public final class PresentationFrameProcessorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_noEditsSquare_leavesFramesUnchanged() {
|
||||
public void getOutputSize_noEditsSquare_leavesFramesUnchanged() {
|
||||
int inputWidth = 150;
|
||||
int inputHeight = 150;
|
||||
PresentationFrameProcessor presentationFrameProcessor =
|
||||
new PresentationFrameProcessor.Builder(getApplicationContext()).build();
|
||||
|
||||
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = presentationFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0);
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||
|
|
@ -61,13 +63,14 @@ public final class PresentationFrameProcessorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_noEditsPortrait_flipsOrientation() {
|
||||
public void getOutputSize_noEditsPortrait_flipsOrientation() {
|
||||
int inputWidth = 150;
|
||||
int inputHeight = 200;
|
||||
PresentationFrameProcessor presentationFrameProcessor =
|
||||
new PresentationFrameProcessor.Builder(getApplicationContext()).build();
|
||||
|
||||
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = presentationFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(90);
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputHeight);
|
||||
|
|
@ -75,7 +78,7 @@ public final class PresentationFrameProcessorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_setResolution_changesDimensions() {
|
||||
public void getOutputSize_setResolution_changesDimensions() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
int requestedHeight = 300;
|
||||
|
|
@ -84,7 +87,8 @@ public final class PresentationFrameProcessorTest {
|
|||
.setResolution(requestedHeight)
|
||||
.build();
|
||||
|
||||
Size outputSize = presentationFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
presentationFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = presentationFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(presentationFrameProcessor.getOutputRotationDegrees()).isEqualTo(0);
|
||||
assertThat(outputSize.getWidth()).isEqualTo(requestedHeight * inputWidth / inputHeight);
|
||||
|
|
@ -96,7 +100,7 @@ public final class PresentationFrameProcessorTest {
|
|||
PresentationFrameProcessor presentationFrameProcessor =
|
||||
new PresentationFrameProcessor.Builder(getApplicationContext()).build();
|
||||
|
||||
// configureOutputSize not called before initialize.
|
||||
// configureOutputSize not called before getOutputRotationDegrees.
|
||||
assertThrows(IllegalStateException.class, presentationFrameProcessor::getOutputRotationDegrees);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,13 +34,14 @@ import org.junit.runner.RunWith;
|
|||
public final class ScaleToFitFrameProcessorTest {
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_noEdits_leavesFramesUnchanged() {
|
||||
public void getOutputSize_noEdits_leavesFramesUnchanged() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
ScaleToFitFrameProcessor scaleToFitFrameProcessor =
|
||||
new ScaleToFitFrameProcessor.Builder(getApplicationContext()).build();
|
||||
|
||||
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||
|
|
@ -58,7 +59,7 @@ public final class ScaleToFitFrameProcessorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_scaleNarrow_decreasesWidth() {
|
||||
public void getOutputSize_scaleNarrow_decreasesWidth() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
ScaleToFitFrameProcessor scaleToFitFrameProcessor =
|
||||
|
|
@ -66,14 +67,15 @@ public final class ScaleToFitFrameProcessorTest {
|
|||
.setScale(/* scaleX= */ .5f, /* scaleY= */ 1f)
|
||||
.build();
|
||||
|
||||
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(Math.round(inputWidth * .5f));
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_scaleWide_increasesWidth() {
|
||||
public void getOutputSize_scaleWide_increasesWidth() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
ScaleToFitFrameProcessor scaleToFitFrameProcessor =
|
||||
|
|
@ -81,14 +83,15 @@ public final class ScaleToFitFrameProcessorTest {
|
|||
.setScale(/* scaleX= */ 2f, /* scaleY= */ 1f)
|
||||
.build();
|
||||
|
||||
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth * 2);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputHeight);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputDimensions_scaleTall_increasesHeight() {
|
||||
public void getOutputSize_scaleTall_increasesHeight() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
ScaleToFitFrameProcessor scaleToFitFrameProcessor =
|
||||
|
|
@ -96,14 +99,15 @@ public final class ScaleToFitFrameProcessorTest {
|
|||
.setScale(/* scaleX= */ 1f, /* scaleY= */ 2f)
|
||||
.build();
|
||||
|
||||
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputWidth);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputHeight * 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_rotate90_swapsDimensions() {
|
||||
public void getOutputSize_rotate90_swapsDimensions() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
ScaleToFitFrameProcessor scaleToFitFrameProcessor =
|
||||
|
|
@ -111,14 +115,15 @@ public final class ScaleToFitFrameProcessorTest {
|
|||
.setRotationDegrees(90)
|
||||
.build();
|
||||
|
||||
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(inputHeight);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(inputWidth);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureOutputSize_rotate45_changesDimensions() {
|
||||
public void getOutputSize_rotate45_changesDimensions() {
|
||||
int inputWidth = 200;
|
||||
int inputHeight = 150;
|
||||
ScaleToFitFrameProcessor scaleToFitFrameProcessor =
|
||||
|
|
@ -127,7 +132,8 @@ public final class ScaleToFitFrameProcessorTest {
|
|||
.build();
|
||||
long expectedOutputWidthHeight = 247;
|
||||
|
||||
Size outputSize = scaleToFitFrameProcessor.configureOutputSize(inputWidth, inputHeight);
|
||||
scaleToFitFrameProcessor.setInputSize(inputWidth, inputHeight);
|
||||
Size outputSize = scaleToFitFrameProcessor.getOutputSize();
|
||||
|
||||
assertThat(outputSize.getWidth()).isEqualTo(expectedOutputWidthHeight);
|
||||
assertThat(outputSize.getHeight()).isEqualTo(expectedOutputWidthHeight);
|
||||
|
|
|
|||
Loading…
Reference in a new issue