diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformationTestResult.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformationTestResult.java index 079f872c78..877ab23cc8 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformationTestResult.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformationTestResult.java @@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.exceptio import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.Format; import com.google.errorprone.annotations.CanIgnoreReturnValue; import org.json.JSONException; import org.json.JSONObject; @@ -194,7 +195,10 @@ public class TransformationTestResult { if (transformationResult.averageVideoBitrate != C.RATE_UNSET_INT) { jsonObject.put("averageVideoBitrate", transformationResult.averageVideoBitrate); } - if (transformationResult.durationMs != C.LENGTH_UNSET) { + if (transformationResult.channelCount != C.LENGTH_UNSET) { + jsonObject.put("channelCount", transformationResult.channelCount); + } + if (transformationResult.durationMs != C.TIME_UNSET) { jsonObject.put("durationMs", transformationResult.durationMs); } if (elapsedTimeMs != C.TIME_UNSET) { @@ -203,6 +207,15 @@ public class TransformationTestResult { if (transformationResult.fileSizeBytes != C.LENGTH_UNSET) { jsonObject.put("fileSizeBytes", transformationResult.fileSizeBytes); } + if (transformationResult.height != C.LENGTH_UNSET) { + jsonObject.put("height", transformationResult.height); + } + if (transformationResult.pcmEncoding != Format.NO_VALUE) { + jsonObject.put("pcmEncoding", transformationResult.pcmEncoding); + } + if (transformationResult.sampleRate != C.RATE_UNSET_INT) { + jsonObject.put("sampleRate", transformationResult.sampleRate); + } if (ssim != TransformationTestResult.SSIM_UNSET) { jsonObject.put("ssim", ssim); } @@ -212,6 +225,9 @@ public class TransformationTestResult { if (transformationResult.videoFrameCount > 0) { jsonObject.put("videoFrameCount", transformationResult.videoFrameCount); } + if (transformationResult.width != C.LENGTH_UNSET) { + jsonObject.put("width", transformationResult.width); + } return jsonObject; } diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationResult.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationResult.java index 0ebec31e56..56d2ea7dde 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationResult.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformationResult.java @@ -19,20 +19,25 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.Format; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Objects; /** Information about the result of a transformation. */ public final class TransformationResult { - /** A builder for {@link TransformationResult} instances. */ public static final class Builder { private long durationMs; private long fileSizeBytes; private int averageAudioBitrate; + private int channelCount; + private @C.PcmEncoding int pcmEncoding; + private int sampleRate; @Nullable private String audioDecoderName; @Nullable private String audioEncoderName; private int averageVideoBitrate; + private int height; + private int width; private int videoFrameCount; @Nullable private String videoDecoderName; @Nullable private String videoEncoderName; @@ -42,7 +47,12 @@ public final class TransformationResult { durationMs = C.TIME_UNSET; fileSizeBytes = C.LENGTH_UNSET; averageAudioBitrate = C.RATE_UNSET_INT; + channelCount = C.LENGTH_UNSET; + pcmEncoding = Format.NO_VALUE; + sampleRate = C.RATE_UNSET_INT; averageVideoBitrate = C.RATE_UNSET_INT; + height = C.LENGTH_UNSET; + width = C.LENGTH_UNSET; } /** @@ -81,6 +91,37 @@ public final class TransformationResult { return this; } + /** + * Sets the channel count. + * + *
Must be positive or {@link C#LENGTH_UNSET}. + */ + @CanIgnoreReturnValue + public Builder setChannelCount(int channelCount) { + checkArgument(channelCount > 0 || channelCount == C.LENGTH_UNSET); + this.channelCount = channelCount; + return this; + } + + /** Sets the {@link C.PcmEncoding}. */ + @CanIgnoreReturnValue + public Builder setPcmEncoding(@C.PcmEncoding int pcmEncoding) { + this.pcmEncoding = pcmEncoding; + return this; + } + + /** + * Sets the sample rate. + * + *
Must be positive or {@link C#RATE_UNSET_INT}. + */ + @CanIgnoreReturnValue + public Builder setSampleRate(int sampleRate) { + checkArgument(sampleRate > 0 || sampleRate == C.RATE_UNSET_INT); + this.sampleRate = sampleRate; + return this; + } + /** Sets the name of the audio decoder used. */ @CanIgnoreReturnValue public Builder setAudioDecoderName(@Nullable String audioDecoderName) { @@ -107,6 +148,30 @@ public final class TransformationResult { return this; } + /** + * Sets the height. + * + *
Must be positive or {@link C#LENGTH_UNSET}. + */ + @CanIgnoreReturnValue + public Builder setHeight(int height) { + checkArgument(height > 0 || height == C.LENGTH_UNSET); + this.height = height; + return this; + } + + /** + * Sets the width. + * + *
Must be positive or {@link C#LENGTH_UNSET}. + */ + @CanIgnoreReturnValue + public Builder setWidth(int width) { + checkArgument(width > 0 || width == C.LENGTH_UNSET); + this.width = width; + return this; + } + /** * Sets the number of video frames. * @@ -146,9 +211,14 @@ public final class TransformationResult { durationMs, fileSizeBytes, averageAudioBitrate, + channelCount, + pcmEncoding, + sampleRate, audioDecoderName, audioEncoderName, averageVideoBitrate, + height, + width, videoFrameCount, videoDecoderName, videoEncoderName, @@ -165,6 +235,12 @@ public final class TransformationResult { * The average bitrate of the audio track data, or {@link C#RATE_UNSET_INT} if unset or unknown. */ public final int averageAudioBitrate; + /** The channel count of the audio, or {@link C#LENGTH_UNSET} if unset or unknown. */ + public final int channelCount; + /* The {@link C.PcmEncoding} of the audio, or {@link Format#NO_VALUE} if unset or unknown. */ + public final @C.PcmEncoding int pcmEncoding; + /** The sample rate of the audio, or {@link C#RATE_UNSET_INT} if unset or unknown. */ + public final int sampleRate; /** The name of the audio decoder used, or {@code null} if none were used. */ @Nullable public final String audioDecoderName; /** The name of the audio encoder used, or {@code null} if none were used. */ @@ -174,6 +250,10 @@ public final class TransformationResult { * The average bitrate of the video track data, or {@link C#RATE_UNSET_INT} if unset or unknown. */ public final int averageVideoBitrate; + /** The height of the video, or {@link C#LENGTH_UNSET} if unset or unknown. */ + public final int height; + /** The width of the video, or {@link C#LENGTH_UNSET} if unset or unknown. */ + public final int width; /** The number of video frames. */ public final int videoFrameCount; /** The name of the video decoder used, or {@code null} if none were used. */ @@ -191,9 +271,14 @@ public final class TransformationResult { long durationMs, long fileSizeBytes, int averageAudioBitrate, + int channelCount, + @C.PcmEncoding int pcmEncoding, + int sampleRate, @Nullable String audioDecoderName, @Nullable String audioEncoderName, int averageVideoBitrate, + int height, + int width, int videoFrameCount, @Nullable String videoDecoderName, @Nullable String videoEncoderName, @@ -201,9 +286,14 @@ public final class TransformationResult { this.durationMs = durationMs; this.fileSizeBytes = fileSizeBytes; this.averageAudioBitrate = averageAudioBitrate; + this.channelCount = channelCount; + this.pcmEncoding = pcmEncoding; + this.sampleRate = sampleRate; this.audioDecoderName = audioDecoderName; this.audioEncoderName = audioEncoderName; this.averageVideoBitrate = averageVideoBitrate; + this.height = height; + this.width = width; this.videoFrameCount = videoFrameCount; this.videoDecoderName = videoDecoderName; this.videoEncoderName = videoEncoderName; @@ -215,9 +305,14 @@ public final class TransformationResult { .setDurationMs(durationMs) .setFileSizeBytes(fileSizeBytes) .setAverageAudioBitrate(averageAudioBitrate) + .setChannelCount(channelCount) + .setPcmEncoding(pcmEncoding) + .setSampleRate(sampleRate) .setAudioDecoderName(audioDecoderName) .setAudioEncoderName(audioEncoderName) .setAverageVideoBitrate(averageVideoBitrate) + .setHeight(height) + .setWidth(width) .setVideoFrameCount(videoFrameCount) .setVideoDecoderName(videoDecoderName) .setVideoEncoderName(videoEncoderName) @@ -236,9 +331,14 @@ public final class TransformationResult { return durationMs == result.durationMs && fileSizeBytes == result.fileSizeBytes && averageAudioBitrate == result.averageAudioBitrate + && channelCount == result.channelCount + && pcmEncoding == result.pcmEncoding + && sampleRate == result.sampleRate && Objects.equals(audioDecoderName, result.audioDecoderName) && Objects.equals(audioEncoderName, result.audioEncoderName) && averageVideoBitrate == result.averageVideoBitrate + && height == result.height + && width == result.width && videoFrameCount == result.videoFrameCount && Objects.equals(videoDecoderName, result.videoDecoderName) && Objects.equals(videoEncoderName, result.videoEncoderName) @@ -250,9 +350,14 @@ public final class TransformationResult { int result = (int) durationMs; result = 31 * result + (int) fileSizeBytes; result = 31 * result + averageAudioBitrate; + result = 31 * result + channelCount; + result = 31 * result + pcmEncoding; + result = 31 * result + sampleRate; result = 31 * result + Objects.hashCode(audioDecoderName); result = 31 * result + Objects.hashCode(audioEncoderName); result = 31 * result + averageVideoBitrate; + result = 31 * result + height; + result = 31 * result + width; result = 31 * result + videoFrameCount; result = 31 * result + Objects.hashCode(videoDecoderName); result = 31 * result + Objects.hashCode(videoEncoderName); diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java index 70800ad44a..ec822ce396 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java @@ -468,11 +468,25 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; public void onTrackEnded( @C.TrackType int trackType, Format format, int averageBitrate, int sampleCount) { if (trackType == C.TRACK_TYPE_AUDIO) { - transformationResultBuilder.setAverageAudioBitrate(averageBitrate); + transformationResultBuilder + .setAverageAudioBitrate(averageBitrate) + .setPcmEncoding(format.pcmEncoding); + if (format.channelCount != Format.NO_VALUE) { + transformationResultBuilder.setChannelCount(format.channelCount); + } + if (format.sampleRate != Format.NO_VALUE) { + transformationResultBuilder.setSampleRate(format.sampleRate); + } } else if (trackType == C.TRACK_TYPE_VIDEO) { transformationResultBuilder - .setVideoFrameCount(sampleCount) - .setAverageVideoBitrate(averageBitrate); + .setAverageVideoBitrate(averageBitrate) + .setVideoFrameCount(sampleCount); + if (format.height != Format.NO_VALUE) { + transformationResultBuilder.setHeight(format.height); + } + if (format.width != Format.NO_VALUE) { + transformationResultBuilder.setWidth(format.width); + } } }