Add a Builder for TransformationResult.
PiperOrigin-RevId: 421278099
This commit is contained in:
parent
63a32e85c5
commit
aab4872fc2
@ -43,12 +43,45 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
/** Information about the result of successfully running a transformer. */
|
||||
public static final class TransformationResult {
|
||||
public final String testId;
|
||||
public final long outputSizeBytes;
|
||||
|
||||
private TransformationResult(String testId, long outputSizeBytes) {
|
||||
/** A builder for {@link TransformationResult} instances. */
|
||||
public static final class Builder {
|
||||
private final String testId;
|
||||
@Nullable private Long fileSizeBytes;
|
||||
|
||||
public Builder(String testId) {
|
||||
this.testId = testId;
|
||||
}
|
||||
|
||||
public Builder setFileSizeBytes(long fileSizeBytes) {
|
||||
this.fileSizeBytes = fileSizeBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransformationResult build() {
|
||||
return new TransformationResult(testId, fileSizeBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public final String testId;
|
||||
@Nullable public final Long fileSizeBytes;
|
||||
|
||||
private TransformationResult(String testId, @Nullable Long fileSizeBytes) {
|
||||
this.testId = testId;
|
||||
this.outputSizeBytes = outputSizeBytes;
|
||||
this.fileSizeBytes = fileSizeBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the analysis data from the test.
|
||||
*
|
||||
* <p>If a value was not generated, it will not be part of the return value.
|
||||
*/
|
||||
public String getFormattedAnalysis() {
|
||||
String analysis = "test=" + testId;
|
||||
if (fileSizeBytes != null) {
|
||||
analysis += ", fileSizeBytes=" + fileSizeBytes;
|
||||
}
|
||||
return analysis;
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,9 +141,10 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
long outputSizeBytes = outputVideoFile.length();
|
||||
|
||||
TransformationResult result = new TransformationResult(testId, outputSizeBytes);
|
||||
TransformationResult result =
|
||||
new TransformationResult.Builder(testId).setFileSizeBytes(outputVideoFile.length()).build();
|
||||
|
||||
writeTransformationResultToFile(context, result);
|
||||
return result;
|
||||
}
|
||||
@ -121,16 +155,15 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
createExternalCacheFile(context, /* fileName= */ result.testId + "-result.txt");
|
||||
try (FileWriter fileWriter = new FileWriter(analysisFile)) {
|
||||
String fileContents =
|
||||
"test="
|
||||
+ result.testId
|
||||
result.getFormattedAnalysis()
|
||||
+ ", deviceFingerprint="
|
||||
+ Build.FINGERPRINT
|
||||
+ ", deviceBrand="
|
||||
+ Build.MANUFACTURER
|
||||
+ ", deviceModel="
|
||||
+ Build.MODEL
|
||||
+ ", sdkVersion="
|
||||
+ Build.VERSION.SDK_INT
|
||||
+ ", outputSizeBytes="
|
||||
+ result.outputSizeBytes;
|
||||
+ Build.VERSION.SDK_INT;
|
||||
fileWriter.write(fileContents);
|
||||
}
|
||||
}
|
||||
|
@ -21,19 +21,19 @@ import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import androidx.media3.common.MimeTypes;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.transformer.TransformationRequest;
|
||||
import androidx.media3.transformer.Transformer;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/** Tests repeated transcoding operations (as a stress test and to help reproduce flakiness). */
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@Ignore("Internal - b/206917996")
|
||||
// @Ignore("Internal - b/206917996")
|
||||
public final class RepeatedTranscodeTransformationTest {
|
||||
private static final int TRANSCODE_COUNT = 10;
|
||||
|
||||
@ -55,14 +55,14 @@ public final class RepeatedTranscodeTransformationTest {
|
||||
Set<Long> differentOutputSizesBytes = new HashSet<>();
|
||||
for (int i = 0; i < TRANSCODE_COUNT; i++) {
|
||||
// Use a long video in case an error occurs a while after the start of the video.
|
||||
differentOutputSizesBytes.add(
|
||||
AndroidTestUtil.TransformationResult result =
|
||||
runTransformer(
|
||||
context,
|
||||
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput",
|
||||
transformer,
|
||||
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
|
||||
/* timeoutSeconds= */ 120)
|
||||
.outputSizeBytes);
|
||||
context,
|
||||
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i,
|
||||
transformer,
|
||||
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
|
||||
/* timeoutSeconds= */ 120);
|
||||
differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes));
|
||||
}
|
||||
|
||||
assertWithMessage(
|
||||
@ -89,14 +89,14 @@ public final class RepeatedTranscodeTransformationTest {
|
||||
Set<Long> differentOutputSizesBytes = new HashSet<>();
|
||||
for (int i = 0; i < TRANSCODE_COUNT; i++) {
|
||||
// Use a long video in case an error occurs a while after the start of the video.
|
||||
differentOutputSizesBytes.add(
|
||||
AndroidTestUtil.TransformationResult result =
|
||||
runTransformer(
|
||||
context,
|
||||
/* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput",
|
||||
transformer,
|
||||
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
|
||||
/* timeoutSeconds= */ 120)
|
||||
.outputSizeBytes);
|
||||
context,
|
||||
/* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i,
|
||||
transformer,
|
||||
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
|
||||
/* timeoutSeconds= */ 120);
|
||||
differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes));
|
||||
}
|
||||
|
||||
assertWithMessage(
|
||||
@ -108,7 +108,7 @@ public final class RepeatedTranscodeTransformationTest {
|
||||
@Test
|
||||
public void repeatedTranscodeNoVideo_givesConsistentLengthOutput() throws Exception {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
Transformer transcodingTransformer =
|
||||
Transformer transformer =
|
||||
new Transformer.Builder(context)
|
||||
.setRemoveVideo(true)
|
||||
.setTransformationRequest(
|
||||
@ -120,14 +120,14 @@ public final class RepeatedTranscodeTransformationTest {
|
||||
Set<Long> differentOutputSizesBytes = new HashSet<>();
|
||||
for (int i = 0; i < TRANSCODE_COUNT; i++) {
|
||||
// Use a long video in case an error occurs a while after the start of the video.
|
||||
differentOutputSizesBytes.add(
|
||||
AndroidTestUtil.TransformationResult result =
|
||||
runTransformer(
|
||||
context,
|
||||
/* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput",
|
||||
transcodingTransformer,
|
||||
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
|
||||
/* timeoutSeconds= */ 120)
|
||||
.outputSizeBytes);
|
||||
context,
|
||||
/* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput_" + i,
|
||||
transformer,
|
||||
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
|
||||
/* timeoutSeconds= */ 120);
|
||||
differentOutputSizesBytes.add(Assertions.checkNotNull(result.fileSizeBytes));
|
||||
}
|
||||
|
||||
assertWithMessage(
|
||||
|
Loading…
x
Reference in New Issue
Block a user