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:
parent
dc037b22cd
commit
0f040e6c6e
@ -17,6 +17,7 @@
|
|||||||
package androidx.media3.effect;
|
package androidx.media3.effect;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
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 static java.lang.annotation.ElementType.TYPE_USE;
|
||||||
|
|
||||||
import androidx.annotation.GuardedBy;
|
import androidx.annotation.GuardedBy;
|
||||||
@ -25,7 +26,6 @@ import androidx.annotation.StringDef;
|
|||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.util.SystemClock;
|
import androidx.media3.common.util.SystemClock;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.common.util.Util;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -191,11 +191,11 @@ public final class DebugTraceUtil {
|
|||||||
for (int i = 0; i < EVENT_TYPES.size(); i++) {
|
for (int i = 0; i < EVENT_TYPES.size(); i++) {
|
||||||
String eventType = EVENT_TYPES.get(i);
|
String eventType = EVENT_TYPES.get(i);
|
||||||
if (!events.containsKey(eventType)) {
|
if (!events.containsKey(eventType)) {
|
||||||
stringBuilder.append(Util.formatInvariant("\"%s\": \"No events logged\",", eventType));
|
stringBuilder.append(formatInvariant("\"%s\": \"No events logged\",", eventType));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
stringBuilder
|
stringBuilder
|
||||||
.append(Util.formatInvariant("\"%s\":{", eventType))
|
.append(formatInvariant("\"%s\":{", eventType))
|
||||||
.append(checkNotNull(events.get(eventType)))
|
.append(checkNotNull(events.get(eventType)))
|
||||||
.append("},");
|
.append("},");
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ public final class DebugTraceUtil {
|
|||||||
for (int i = 0; i < eventLogs.size(); i++) {
|
for (int i = 0; i < eventLogs.size(); i++) {
|
||||||
EventLog eventLog = eventLogs.get(i);
|
EventLog eventLog = eventLogs.get(i);
|
||||||
writer.write(
|
writer.write(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
"%s\t%d\t%s\t%s\n",
|
"%s\t%d\t%s\t%s\n",
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
eventLog.eventTimeMs,
|
eventLog.eventTimeMs,
|
||||||
@ -246,10 +246,9 @@ public final class DebugTraceUtil {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append(
|
stringBuilder.append(
|
||||||
Util.formatInvariant(
|
formatInvariant("\"%s@%d", presentationTimeToString(presentationTimeUs), eventTimeMs));
|
||||||
"\"%s@%d", presentationTimeToString(presentationTimeUs), eventTimeMs));
|
|
||||||
if (extra != null) {
|
if (extra != null) {
|
||||||
stringBuilder.append(Util.formatInvariant("(%s)", extra));
|
stringBuilder.append(formatInvariant("(%s)", extra));
|
||||||
}
|
}
|
||||||
return stringBuilder.append('"').toString();
|
return stringBuilder.append('"').toString();
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
package androidx.media3.effect;
|
package androidx.media3.effect;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
|
import static androidx.media3.common.util.Util.formatInvariant;
|
||||||
|
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.util.GlProgram;
|
import androidx.media3.common.util.GlProgram;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
import androidx.media3.common.util.Size;
|
import androidx.media3.common.util.Size;
|
||||||
import androidx.media3.common.util.Util;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
/** Applies zero or more {@link TextureOverlay}s onto each frame. */
|
/** 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++) {
|
for (int texUnitIndex = 1; texUnitIndex <= overlays.size(); texUnitIndex++) {
|
||||||
TextureOverlay overlay = overlays.get(texUnitIndex - 1);
|
TextureOverlay overlay = overlays.get(texUnitIndex - 1);
|
||||||
glProgram.setSamplerTexIdUniform(
|
glProgram.setSamplerTexIdUniform(
|
||||||
Util.formatInvariant("uOverlayTexSampler%d", texUnitIndex),
|
formatInvariant("uOverlayTexSampler%d", texUnitIndex),
|
||||||
overlay.getTextureId(presentationTimeUs),
|
overlay.getTextureId(presentationTimeUs),
|
||||||
texUnitIndex);
|
texUnitIndex);
|
||||||
glProgram.setFloatsUniform(
|
glProgram.setFloatsUniform(
|
||||||
Util.formatInvariant("uVertexTransformationMatrix%d", texUnitIndex),
|
formatInvariant("uVertexTransformationMatrix%d", texUnitIndex),
|
||||||
overlay.getVertexTransformation(presentationTimeUs));
|
overlay.getVertexTransformation(presentationTimeUs));
|
||||||
OverlaySettings overlaySettings = overlay.getOverlaySettings(presentationTimeUs);
|
OverlaySettings overlaySettings = overlay.getOverlaySettings(presentationTimeUs);
|
||||||
Size overlaySize = overlay.getTextureSize(presentationTimeUs);
|
Size overlaySize = overlay.getTextureSize(presentationTimeUs);
|
||||||
glProgram.setFloatsUniform(
|
glProgram.setFloatsUniform(
|
||||||
Util.formatInvariant("uTransformationMatrix%d", texUnitIndex),
|
formatInvariant("uTransformationMatrix%d", texUnitIndex),
|
||||||
samplerOverlayMatrixProvider.getTransformationMatrix(overlaySize, overlaySettings));
|
samplerOverlayMatrixProvider.getTransformationMatrix(overlaySize, overlaySettings));
|
||||||
glProgram.setFloatUniform(
|
glProgram.setFloatUniform(
|
||||||
Util.formatInvariant("uOverlayAlphaScale%d", texUnitIndex), overlaySettings.alphaScale);
|
formatInvariant("uOverlayAlphaScale%d", texUnitIndex), overlaySettings.alphaScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
glProgram.setSamplerTexIdUniform("uVideoTexSampler0", inputTexId, /* texUnitIndex= */ 0);
|
glProgram.setSamplerTexIdUniform("uVideoTexSampler0", inputTexId, /* texUnitIndex= */ 0);
|
||||||
@ -128,10 +128,9 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
||||||
shader
|
shader
|
||||||
.append(Util.formatInvariant("uniform mat4 uTransformationMatrix%s;\n", texUnitIndex))
|
.append(formatInvariant("uniform mat4 uTransformationMatrix%s;\n", texUnitIndex))
|
||||||
.append(
|
.append(formatInvariant("uniform mat4 uVertexTransformationMatrix%s;\n", texUnitIndex))
|
||||||
Util.formatInvariant("uniform mat4 uVertexTransformationMatrix%s;\n", texUnitIndex))
|
.append(formatInvariant("varying vec2 vOverlayTexSamplingCoord%s;\n", texUnitIndex));
|
||||||
.append(Util.formatInvariant("varying vec2 vOverlayTexSamplingCoord%s;\n", texUnitIndex));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shader
|
shader
|
||||||
@ -144,13 +143,13 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
||||||
shader
|
shader
|
||||||
.append(Util.formatInvariant(" vec4 aOverlayPosition%d = \n", texUnitIndex))
|
.append(formatInvariant(" vec4 aOverlayPosition%d = \n", texUnitIndex))
|
||||||
.append(
|
.append(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
" uVertexTransformationMatrix%s * uTransformationMatrix%s * aFramePosition;\n",
|
" uVertexTransformationMatrix%s * uTransformationMatrix%s * aFramePosition;\n",
|
||||||
texUnitIndex, texUnitIndex))
|
texUnitIndex, texUnitIndex))
|
||||||
.append(
|
.append(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
" vOverlayTexSamplingCoord%d = getTexSamplingCoord(aOverlayPosition%d.xy);\n",
|
" vOverlayTexSamplingCoord%d = getTexSamplingCoord(aOverlayPosition%d.xy);\n",
|
||||||
texUnitIndex, texUnitIndex));
|
texUnitIndex, texUnitIndex));
|
||||||
}
|
}
|
||||||
@ -207,9 +206,9 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
||||||
shader
|
shader
|
||||||
.append(Util.formatInvariant("uniform sampler2D uOverlayTexSampler%d;\n", texUnitIndex))
|
.append(formatInvariant("uniform sampler2D uOverlayTexSampler%d;\n", texUnitIndex))
|
||||||
.append(Util.formatInvariant("uniform float uOverlayAlphaScale%d;\n", texUnitIndex))
|
.append(formatInvariant("uniform float uOverlayAlphaScale%d;\n", texUnitIndex))
|
||||||
.append(Util.formatInvariant("varying vec2 vOverlayTexSamplingCoord%d;\n", texUnitIndex));
|
.append(formatInvariant("varying vec2 vOverlayTexSamplingCoord%d;\n", texUnitIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
shader
|
shader
|
||||||
@ -221,21 +220,21 @@ import com.google.common.collect.ImmutableList;
|
|||||||
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
|
||||||
shader
|
shader
|
||||||
.append(
|
.append(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
" vec4 electricalOverlayColor%d = getClampToBorderOverlayColor(\n",
|
" vec4 electricalOverlayColor%d = getClampToBorderOverlayColor(\n",
|
||||||
texUnitIndex))
|
texUnitIndex))
|
||||||
.append(
|
.append(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
" uOverlayTexSampler%d, vOverlayTexSamplingCoord%d, uOverlayAlphaScale%d);\n",
|
" uOverlayTexSampler%d, vOverlayTexSamplingCoord%d, uOverlayAlphaScale%d);\n",
|
||||||
texUnitIndex, texUnitIndex, texUnitIndex))
|
texUnitIndex, texUnitIndex, texUnitIndex))
|
||||||
.append(Util.formatInvariant(" vec4 opticalOverlayColor%d = vec4(\n", texUnitIndex))
|
.append(formatInvariant(" vec4 opticalOverlayColor%d = vec4(\n", texUnitIndex))
|
||||||
.append(
|
.append(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
" applyEotf(electricalOverlayColor%d.rgb), electricalOverlayColor%d.a);\n",
|
" applyEotf(electricalOverlayColor%d.rgb), electricalOverlayColor%d.a);\n",
|
||||||
texUnitIndex, texUnitIndex))
|
texUnitIndex, texUnitIndex))
|
||||||
.append(" fragColor = mix(\n")
|
.append(" fragColor = mix(\n")
|
||||||
.append(
|
.append(
|
||||||
Util.formatInvariant(
|
formatInvariant(
|
||||||
" fragColor, opticalOverlayColor%d, getMixAlpha(videoColor.a,"
|
" fragColor, opticalOverlayColor%d, getMixAlpha(videoColor.a,"
|
||||||
+ " opticalOverlayColor%d.a));\n",
|
+ " opticalOverlayColor%d.a));\n",
|
||||||
texUnitIndex, texUnitIndex));
|
texUnitIndex, texUnitIndex));
|
||||||
|
@ -18,6 +18,7 @@ package androidx.media3.effect;
|
|||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
|
import static androidx.media3.common.util.Util.formatInvariant;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@ -25,7 +26,6 @@ import androidx.media3.common.Format;
|
|||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
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. */
|
/** Transforms the colors of a frame by applying the same color lookup table to each frame. */
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
@ -45,7 +45,7 @@ public final class SingleColorLut implements ColorLut {
|
|||||||
"LUT must have three dimensions.");
|
"LUT must have three dimensions.");
|
||||||
checkArgument(
|
checkArgument(
|
||||||
lutCube.length == lutCube[0].length && lutCube.length == lutCube[0][0].length,
|
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.",
|
"All three dimensions of a LUT must match, received %d x %d x %d.",
|
||||||
lutCube.length, lutCube[0].length, lutCube[0][0].length));
|
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) {
|
public static SingleColorLut createFromBitmap(Bitmap lut) {
|
||||||
checkArgument(
|
checkArgument(
|
||||||
lut.getWidth() * lut.getWidth() == lut.getHeight(),
|
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 needs to be in a N x N^2 format, received %d x %d.",
|
||||||
lut.getWidth(), lut.getHeight()));
|
lut.getWidth(), lut.getHeight()));
|
||||||
checkArgument(
|
checkArgument(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user