mirror of
https://github.com/androidx/media.git
synced 2025-05-04 14:10:40 +08:00
Add audio and video values from Format to TransformationResult.
PiperOrigin-RevId: 500789076
This commit is contained in:
parent
8ad26c0d8b
commit
8cac27a77c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user