Commit 90de454e by kimvde Committed by microkatz

Adapt TransformationResult for multi-asset

PiperOrigin-RevId: 506898392
parent 937fcf9c
......@@ -26,6 +26,7 @@ import android.os.Build;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.util.Log;
......@@ -36,6 +37,7 @@ import com.google.common.collect.ImmutableList;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -502,6 +504,31 @@ public final class AndroidTestUtil {
}
/**
* Creates a {@link JSONArray} from {@link TransformationResult.ProcessedInput processed inputs}.
*
* @param processedInputs The list of {@link TransformationResult.ProcessedInput} instances.
* @return A {@link JSONArray} containing {@link JSONObject} instances representing the {@link
* TransformationResult.ProcessedInput} instances.
*/
public static JSONArray processedInputsAsJsonArray(
ImmutableList<TransformationResult.ProcessedInput> processedInputs) throws JSONException {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < processedInputs.size(); i++) {
TransformationResult.ProcessedInput processedInput = processedInputs.get(i);
JSONObject jsonObject = new JSONObject();
@Nullable
MediaItem.LocalConfiguration localConfiguration = processedInput.mediaItem.localConfiguration;
if (localConfiguration != null) {
jsonObject.put("mediaItemUri", localConfiguration.uri);
}
jsonObject.putOpt("audioDecoderName", processedInput.audioDecoderName);
jsonObject.putOpt("videoDecoderName", processedInput.videoDecoderName);
jsonArray.put(jsonObject);
}
return jsonArray;
}
/**
* Creates a {@link JSONObject} from the {@link Exception}.
*
* <p>If the exception is a {@link TransformationException}, {@code errorCode} is included.
......
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.exceptionAsJsonObject;
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.processedInputsAsJsonArray;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
......@@ -156,19 +157,22 @@ public class TransformationTestResult {
public JSONObject asJsonObject() throws JSONException {
JSONObject jsonObject =
new JSONObject()
.putOpt("audioDecoderName", transformationResult.audioDecoderName)
.putOpt("audioEncoderName", transformationResult.audioEncoderName)
.putOpt(
"fallbackDetails", fallbackDetails != null ? fallbackDetails.asJsonObject() : null)
.putOpt("filePath", filePath)
.putOpt("colorInfo", transformationResult.colorInfo)
.putOpt("videoDecoderName", transformationResult.videoDecoderName)
.putOpt("videoEncoderName", transformationResult.videoEncoderName)
.putOpt(
"testException",
exceptionAsJsonObject(transformationResult.transformationException))
.putOpt("analysisException", exceptionAsJsonObject(analysisException));
if (!transformationResult.processedInputs.isEmpty()) {
jsonObject.put(
"processedInputs", processedInputsAsJsonArray(transformationResult.processedInputs));
}
if (transformationResult.averageAudioBitrate != C.RATE_UNSET_INT) {
jsonObject.put("averageAudioBitrate", transformationResult.averageAudioBitrate);
}
......
......@@ -32,6 +32,7 @@ import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.video.ColorInfo;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.List;
......@@ -52,10 +53,12 @@ import java.util.concurrent.atomic.AtomicLong;
private final Listener compositeAssetLoaderListener;
private final Map<Integer, SampleConsumer> sampleConsumersByTrackType;
private final Map<Integer, OnMediaItemChangedListener> mediaItemChangedListenersByTrackType;
private final ImmutableList.Builder<TransformationResult.ProcessedInput> processedInputsBuilder;
private final AtomicLong totalDurationUs;
private final AtomicInteger nonEndedTracks;
private AssetLoader currentAssetLoader;
private int processedInputsSize;
private volatile long currentDurationUs;
......@@ -72,6 +75,7 @@ import java.util.concurrent.atomic.AtomicLong;
handler = clock.createHandler(looper, /* callback= */ null);
sampleConsumersByTrackType = new HashMap<>();
mediaItemChangedListenersByTrackType = new HashMap<>();
processedInputsBuilder = new ImmutableList.Builder<>();
totalDurationUs = new AtomicLong();
nonEndedTracks = new AtomicInteger();
// It's safe to use "this" because we don't start the AssetLoader before exiting the
......@@ -105,10 +109,18 @@ import java.util.concurrent.atomic.AtomicLong;
@Override
public ImmutableMap<Integer, String> getDecoderNames() {
// TODO(b/252537210): update TransformationResult to contain all the decoders used.
return currentAssetLoader.getDecoderNames();
}
/**
* Returns the partially or entirely {@linkplain TransformationResult.ProcessedInput processed
* inputs}.
*/
public ImmutableList<TransformationResult.ProcessedInput> getProcessedInputs() {
addCurrentProcessedInput();
return processedInputsBuilder.build();
}
@Override
public void release() {
currentAssetLoader.release();
......@@ -193,6 +205,18 @@ import java.util.concurrent.atomic.AtomicLong;
compositeAssetLoaderListener.onError(exception);
}
private void addCurrentProcessedInput() {
int currentMediaItemIndex = this.currentMediaItemIndex.get();
if (currentMediaItemIndex >= processedInputsSize) {
MediaItem mediaItem = editedMediaItems.get(currentMediaItemIndex).mediaItem;
ImmutableMap<Integer, String> decoders = currentAssetLoader.getDecoderNames();
processedInputsBuilder.add(
new TransformationResult.ProcessedInput(
mediaItem, decoders.get(C.TRACK_TYPE_AUDIO), decoders.get(C.TRACK_TYPE_VIDEO)));
processedInputsSize++;
}
}
private final class SampleConsumerWrapper implements SampleConsumer {
private final SampleConsumer sampleConsumer;
......@@ -270,6 +294,7 @@ import java.util.concurrent.atomic.AtomicLong;
totalDurationUs.addAndGet(currentDurationUs);
handler.post(
() -> {
addCurrentProcessedInput();
currentAssetLoader.release();
EditedMediaItem editedMediaItem =
editedMediaItems.get(currentMediaItemIndex.incrementAndGet());
......
......@@ -43,7 +43,7 @@ import com.google.android.exoplayer2.util.Effect;
import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Size;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableList;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -243,10 +243,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private void endInternal(
@EndReason int endReason, @Nullable TransformationException transformationException) {
ImmutableMap<Integer, String> decoderNames = compositeAssetLoader.getDecoderNames();
ImmutableList<TransformationResult.ProcessedInput> processedInputs =
compositeAssetLoader.getProcessedInputs();
transformationResultBuilder
.setAudioDecoderName(decoderNames.get(C.TRACK_TYPE_AUDIO))
.setVideoDecoderName(decoderNames.get(C.TRACK_TYPE_VIDEO))
.setProcessedInputs(processedInputs)
.setAudioEncoderName(encoderFactory.getAudioEncoderName())
.setVideoEncoderName(encoderFactory.getVideoEncoderName());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment