mirror of
https://github.com/androidx/media.git
synced 2025-05-12 01:59:50 +08:00
Support android.opengl.Matrix in AdvancedFrameProcessor.
This allows apps to use AdvancedFrameProcessor to apply transformations in 3D space. This functionality is not used in transformer otherwise. PiperOrigin-RevId: 439313406
This commit is contained in:
parent
3d93484402
commit
1cbdad34a2
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.transformer;
|
||||
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
||||
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
|
||||
|
||||
import android.content.Context;
|
||||
@ -44,7 +45,8 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
|
||||
private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_copy_es2.glsl";
|
||||
|
||||
/**
|
||||
* Returns a 4x4, column-major Matrix float array, from an input {@link Matrix}.
|
||||
* Returns a 4x4, column-major {@link android.opengl.Matrix} float array, from an input {@link
|
||||
* Matrix}.
|
||||
*
|
||||
* <p>This is useful for converting to the 4x4 column-major format commonly used in OpenGL.
|
||||
*/
|
||||
@ -85,7 +87,7 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
|
||||
}
|
||||
|
||||
private final Context context;
|
||||
private final Matrix transformationMatrix;
|
||||
private final float[] transformationMatrix;
|
||||
|
||||
private @MonotonicNonNull Size size;
|
||||
private @MonotonicNonNull GlProgram glProgram;
|
||||
@ -94,13 +96,27 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param context The {@link Context}.
|
||||
* @param transformationMatrix The transformation matrix to apply to each frame. Operations are
|
||||
* done on normalized device coordinates (-1 to 1 on x and y), and no automatic adjustments
|
||||
* are applied on the transformation matrix.
|
||||
* @param transformationMatrix The transformation {@link Matrix} to apply to each frame.
|
||||
* Operations are done on normalized device coordinates (-1 to 1 on x and y), and no automatic
|
||||
* adjustments are applied on the transformation matrix.
|
||||
*/
|
||||
public AdvancedFrameProcessor(Context context, Matrix transformationMatrix) {
|
||||
this(context, getGlMatrixArray(transformationMatrix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param context The {@link Context}.
|
||||
* @param transformationMatrix The 4x4 transformation {@link android.opengl.Matrix} to apply to
|
||||
* each frame. Operations are done on normalized device coordinates (-1 to 1 on x and y), and
|
||||
* no automatic adjustments are applied on the transformation matrix.
|
||||
*/
|
||||
public AdvancedFrameProcessor(Context context, float[] transformationMatrix) {
|
||||
checkArgument(
|
||||
transformationMatrix.length == 16, "A 4x4 transformation matrix must have 16 elements.");
|
||||
this.context = context;
|
||||
this.transformationMatrix = new Matrix(transformationMatrix);
|
||||
this.transformationMatrix = transformationMatrix.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,7 +131,7 @@ public final class AdvancedFrameProcessor implements GlFrameProcessor {
|
||||
"aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT);
|
||||
glProgram.setBufferAttribute(
|
||||
"aTexSamplingCoord", GlUtil.getTextureCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT);
|
||||
glProgram.setFloatsUniform("uTransformationMatrix", getGlMatrixArray(transformationMatrix));
|
||||
glProgram.setFloatsUniform("uTransformationMatrix", transformationMatrix);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.transformer;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AdvancedFrameProcessor}.
|
||||
*
|
||||
* <p>See {@code AdvancedFrameProcessorPixelTest} for pixel tests testing {@link
|
||||
* AdvancedFrameProcessor} given a transformation matrix.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public final class AdvancedFrameProcessorTest {
|
||||
|
||||
@Test
|
||||
public void construct_withInvalidMatrixSize_throwsException() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new AdvancedFrameProcessor(getApplicationContext(), new float[4]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void construct_withValidMatrixSize_completesSucessfully() {
|
||||
new AdvancedFrameProcessor(getApplicationContext(), new float[16]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user