Use static import for Util.formatInvariant.

In OverlayShaderProgram, this method is used quite a lot, and is the only method from Util.java in this file. Marginally reduce complexity by using a static import instead.

PiperOrigin-RevId: 584828455
This commit is contained in:
huangdarwin 2023-11-23 01:42:57 -08:00 committed by Copybara-Service
parent dc037b22cd
commit 0f040e6c6e
3 changed files with 28 additions and 30 deletions

View File

@ -17,6 +17,7 @@
package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Util.formatInvariant;
import static java.lang.annotation.ElementType.TYPE_USE;
import androidx.annotation.GuardedBy;
@ -25,7 +26,6 @@ import androidx.annotation.StringDef;
import androidx.media3.common.C;
import androidx.media3.common.util.SystemClock;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
@ -191,11 +191,11 @@ public final class DebugTraceUtil {
for (int i = 0; i < EVENT_TYPES.size(); i++) {
String eventType = EVENT_TYPES.get(i);
if (!events.containsKey(eventType)) {
stringBuilder.append(Util.formatInvariant("\"%s\": \"No events logged\",", eventType));
stringBuilder.append(formatInvariant("\"%s\": \"No events logged\",", eventType));
continue;
}
stringBuilder
.append(Util.formatInvariant("\"%s\":{", eventType))
.append(formatInvariant("\"%s\":{", eventType))
.append(checkNotNull(events.get(eventType)))
.append("},");
}
@ -211,7 +211,7 @@ public final class DebugTraceUtil {
for (int i = 0; i < eventLogs.size(); i++) {
EventLog eventLog = eventLogs.get(i);
writer.write(
Util.formatInvariant(
formatInvariant(
"%s\t%d\t%s\t%s\n",
entry.getKey(),
eventLog.eventTimeMs,
@ -246,10 +246,9 @@ public final class DebugTraceUtil {
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(
Util.formatInvariant(
"\"%s@%d", presentationTimeToString(presentationTimeUs), eventTimeMs));
formatInvariant("\"%s@%d", presentationTimeToString(presentationTimeUs), eventTimeMs));
if (extra != null) {
stringBuilder.append(Util.formatInvariant("(%s)", extra));
stringBuilder.append(formatInvariant("(%s)", extra));
}
return stringBuilder.append('"').toString();
}

View File

@ -16,13 +16,13 @@
package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Util.formatInvariant;
import android.opengl.GLES20;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.GlProgram;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size;
import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList;
/** Applies zero or more {@link TextureOverlay}s onto each frame. */
@ -81,19 +81,19 @@ import com.google.common.collect.ImmutableList;
for (int texUnitIndex = 1; texUnitIndex <= overlays.size(); texUnitIndex++) {
TextureOverlay overlay = overlays.get(texUnitIndex - 1);
glProgram.setSamplerTexIdUniform(
Util.formatInvariant("uOverlayTexSampler%d", texUnitIndex),
formatInvariant("uOverlayTexSampler%d", texUnitIndex),
overlay.getTextureId(presentationTimeUs),
texUnitIndex);
glProgram.setFloatsUniform(
Util.formatInvariant("uVertexTransformationMatrix%d", texUnitIndex),
formatInvariant("uVertexTransformationMatrix%d", texUnitIndex),
overlay.getVertexTransformation(presentationTimeUs));
OverlaySettings overlaySettings = overlay.getOverlaySettings(presentationTimeUs);
Size overlaySize = overlay.getTextureSize(presentationTimeUs);
glProgram.setFloatsUniform(
Util.formatInvariant("uTransformationMatrix%d", texUnitIndex),
formatInvariant("uTransformationMatrix%d", texUnitIndex),
samplerOverlayMatrixProvider.getTransformationMatrix(overlaySize, overlaySettings));
glProgram.setFloatUniform(
Util.formatInvariant("uOverlayAlphaScale%d", texUnitIndex), overlaySettings.alphaScale);
formatInvariant("uOverlayAlphaScale%d", texUnitIndex), overlaySettings.alphaScale);
}
glProgram.setSamplerTexIdUniform("uVideoTexSampler0", inputTexId, /* texUnitIndex= */ 0);
@ -128,10 +128,9 @@ import com.google.common.collect.ImmutableList;
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
shader
.append(Util.formatInvariant("uniform mat4 uTransformationMatrix%s;\n", texUnitIndex))
.append(
Util.formatInvariant("uniform mat4 uVertexTransformationMatrix%s;\n", texUnitIndex))
.append(Util.formatInvariant("varying vec2 vOverlayTexSamplingCoord%s;\n", texUnitIndex));
.append(formatInvariant("uniform mat4 uTransformationMatrix%s;\n", texUnitIndex))
.append(formatInvariant("uniform mat4 uVertexTransformationMatrix%s;\n", texUnitIndex))
.append(formatInvariant("varying vec2 vOverlayTexSamplingCoord%s;\n", texUnitIndex));
}
shader
@ -144,13 +143,13 @@ import com.google.common.collect.ImmutableList;
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
shader
.append(Util.formatInvariant(" vec4 aOverlayPosition%d = \n", texUnitIndex))
.append(formatInvariant(" vec4 aOverlayPosition%d = \n", texUnitIndex))
.append(
Util.formatInvariant(
formatInvariant(
" uVertexTransformationMatrix%s * uTransformationMatrix%s * aFramePosition;\n",
texUnitIndex, texUnitIndex))
.append(
Util.formatInvariant(
formatInvariant(
" vOverlayTexSamplingCoord%d = getTexSamplingCoord(aOverlayPosition%d.xy);\n",
texUnitIndex, texUnitIndex));
}
@ -207,9 +206,9 @@ import com.google.common.collect.ImmutableList;
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
shader
.append(Util.formatInvariant("uniform sampler2D uOverlayTexSampler%d;\n", texUnitIndex))
.append(Util.formatInvariant("uniform float uOverlayAlphaScale%d;\n", texUnitIndex))
.append(Util.formatInvariant("varying vec2 vOverlayTexSamplingCoord%d;\n", texUnitIndex));
.append(formatInvariant("uniform sampler2D uOverlayTexSampler%d;\n", texUnitIndex))
.append(formatInvariant("uniform float uOverlayAlphaScale%d;\n", texUnitIndex))
.append(formatInvariant("varying vec2 vOverlayTexSamplingCoord%d;\n", texUnitIndex));
}
shader
@ -221,21 +220,21 @@ import com.google.common.collect.ImmutableList;
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
shader
.append(
Util.formatInvariant(
formatInvariant(
" vec4 electricalOverlayColor%d = getClampToBorderOverlayColor(\n",
texUnitIndex))
.append(
Util.formatInvariant(
formatInvariant(
" uOverlayTexSampler%d, vOverlayTexSamplingCoord%d, uOverlayAlphaScale%d);\n",
texUnitIndex, texUnitIndex, texUnitIndex))
.append(Util.formatInvariant(" vec4 opticalOverlayColor%d = vec4(\n", texUnitIndex))
.append(formatInvariant(" vec4 opticalOverlayColor%d = vec4(\n", texUnitIndex))
.append(
Util.formatInvariant(
formatInvariant(
" applyEotf(electricalOverlayColor%d.rgb), electricalOverlayColor%d.a);\n",
texUnitIndex, texUnitIndex))
.append(" fragColor = mix(\n")
.append(
Util.formatInvariant(
formatInvariant(
" fragColor, opticalOverlayColor%d, getMixAlpha(videoColor.a,"
+ " opticalOverlayColor%d.a));\n",
texUnitIndex, texUnitIndex));

View File

@ -18,6 +18,7 @@ package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Util.formatInvariant;
import android.content.Context;
import android.graphics.Bitmap;
@ -25,7 +26,6 @@ import androidx.media3.common.Format;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
/** Transforms the colors of a frame by applying the same color lookup table to each frame. */
@UnstableApi
@ -45,7 +45,7 @@ public final class SingleColorLut implements ColorLut {
"LUT must have three dimensions.");
checkArgument(
lutCube.length == lutCube[0].length && lutCube.length == lutCube[0][0].length,
Util.formatInvariant(
formatInvariant(
"All three dimensions of a LUT must match, received %d x %d x %d.",
lutCube.length, lutCube[0].length, lutCube[0][0].length));
@ -62,7 +62,7 @@ public final class SingleColorLut implements ColorLut {
public static SingleColorLut createFromBitmap(Bitmap lut) {
checkArgument(
lut.getWidth() * lut.getWidth() == lut.getHeight(),
Util.formatInvariant(
formatInvariant(
"LUT needs to be in a N x N^2 format, received %d x %d.",
lut.getWidth(), lut.getHeight()));
checkArgument(