mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make Format's constructor take the Builder as argument
Which saves the large parameter list. PiperOrigin-RevId: 327619725
This commit is contained in:
parent
e2fc5c2190
commit
a673eec845
2 changed files with 69 additions and 133 deletions
|
|
@ -592,37 +592,7 @@ public final class Format implements Parcelable {
|
||||||
// Build.
|
// Build.
|
||||||
|
|
||||||
public Format build() {
|
public Format build() {
|
||||||
return new Format(
|
return new Format(/* builder= */ this);
|
||||||
id,
|
|
||||||
label,
|
|
||||||
language,
|
|
||||||
selectionFlags,
|
|
||||||
roleFlags,
|
|
||||||
averageBitrate,
|
|
||||||
peakBitrate,
|
|
||||||
codecs,
|
|
||||||
metadata,
|
|
||||||
containerMimeType,
|
|
||||||
sampleMimeType,
|
|
||||||
maxInputSize,
|
|
||||||
initializationData,
|
|
||||||
drmInitData,
|
|
||||||
subsampleOffsetUs,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
frameRate,
|
|
||||||
rotationDegrees,
|
|
||||||
pixelWidthHeightRatio,
|
|
||||||
projectionData,
|
|
||||||
stereoMode,
|
|
||||||
colorInfo,
|
|
||||||
channelCount,
|
|
||||||
sampleRate,
|
|
||||||
pcmEncoding,
|
|
||||||
encoderDelay,
|
|
||||||
encoderPadding,
|
|
||||||
accessibilityChannel,
|
|
||||||
exoMediaCryptoType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1211,86 +1181,51 @@ public final class Format implements Parcelable {
|
||||||
return new Builder().setId(id).setSampleMimeType(sampleMimeType).build();
|
return new Builder().setId(id).setSampleMimeType(sampleMimeType).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some fields are deprecated but they're still assigned below.
|
private Format(Builder builder) {
|
||||||
/* package */ Format(
|
id = builder.id;
|
||||||
@Nullable String id,
|
label = builder.label;
|
||||||
@Nullable String label,
|
language = Util.normalizeLanguageCode(builder.language);
|
||||||
@Nullable String language,
|
selectionFlags = builder.selectionFlags;
|
||||||
@C.SelectionFlags int selectionFlags,
|
roleFlags = builder.roleFlags;
|
||||||
@C.RoleFlags int roleFlags,
|
averageBitrate = builder.averageBitrate;
|
||||||
int averageBitrate,
|
peakBitrate = builder.peakBitrate;
|
||||||
int peakBitrate,
|
bitrate = peakBitrate != NO_VALUE ? peakBitrate : averageBitrate;
|
||||||
@Nullable String codecs,
|
codecs = builder.codecs;
|
||||||
@Nullable Metadata metadata,
|
metadata = builder.metadata;
|
||||||
// Container specific.
|
|
||||||
@Nullable String containerMimeType,
|
|
||||||
// Sample specific.
|
|
||||||
@Nullable String sampleMimeType,
|
|
||||||
int maxInputSize,
|
|
||||||
@Nullable List<byte[]> initializationData,
|
|
||||||
@Nullable DrmInitData drmInitData,
|
|
||||||
long subsampleOffsetUs,
|
|
||||||
// Video specific.
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
float frameRate,
|
|
||||||
int rotationDegrees,
|
|
||||||
float pixelWidthHeightRatio,
|
|
||||||
@Nullable byte[] projectionData,
|
|
||||||
@C.StereoMode int stereoMode,
|
|
||||||
@Nullable ColorInfo colorInfo,
|
|
||||||
// Audio specific.
|
|
||||||
int channelCount,
|
|
||||||
int sampleRate,
|
|
||||||
@C.PcmEncoding int pcmEncoding,
|
|
||||||
int encoderDelay,
|
|
||||||
int encoderPadding,
|
|
||||||
// Text specific.
|
|
||||||
int accessibilityChannel,
|
|
||||||
// Provided by source.
|
|
||||||
@Nullable Class<? extends ExoMediaCrypto> exoMediaCryptoType) {
|
|
||||||
this.id = id;
|
|
||||||
this.label = label;
|
|
||||||
this.language = Util.normalizeLanguageCode(language);
|
|
||||||
this.selectionFlags = selectionFlags;
|
|
||||||
this.roleFlags = roleFlags;
|
|
||||||
this.averageBitrate = averageBitrate;
|
|
||||||
this.peakBitrate = peakBitrate;
|
|
||||||
this.bitrate = peakBitrate != NO_VALUE ? peakBitrate : averageBitrate;
|
|
||||||
this.codecs = codecs;
|
|
||||||
this.metadata = metadata;
|
|
||||||
// Container specific.
|
// Container specific.
|
||||||
this.containerMimeType = containerMimeType;
|
containerMimeType = builder.containerMimeType;
|
||||||
// Sample specific.
|
// Sample specific.
|
||||||
this.sampleMimeType = sampleMimeType;
|
sampleMimeType = builder.sampleMimeType;
|
||||||
this.maxInputSize = maxInputSize;
|
maxInputSize = builder.maxInputSize;
|
||||||
this.initializationData =
|
initializationData =
|
||||||
initializationData == null ? Collections.emptyList() : initializationData;
|
builder.initializationData == null ? Collections.emptyList() : builder.initializationData;
|
||||||
this.drmInitData = drmInitData;
|
drmInitData = builder.drmInitData;
|
||||||
this.subsampleOffsetUs = subsampleOffsetUs;
|
subsampleOffsetUs = builder.subsampleOffsetUs;
|
||||||
// Video specific.
|
// Video specific.
|
||||||
this.width = width;
|
width = builder.width;
|
||||||
this.height = height;
|
height = builder.height;
|
||||||
this.frameRate = frameRate;
|
frameRate = builder.frameRate;
|
||||||
this.rotationDegrees = rotationDegrees == NO_VALUE ? 0 : rotationDegrees;
|
rotationDegrees = builder.rotationDegrees == NO_VALUE ? 0 : builder.rotationDegrees;
|
||||||
this.pixelWidthHeightRatio = pixelWidthHeightRatio == NO_VALUE ? 1 : pixelWidthHeightRatio;
|
pixelWidthHeightRatio =
|
||||||
this.projectionData = projectionData;
|
builder.pixelWidthHeightRatio == NO_VALUE ? 1 : builder.pixelWidthHeightRatio;
|
||||||
this.stereoMode = stereoMode;
|
projectionData = builder.projectionData;
|
||||||
this.colorInfo = colorInfo;
|
stereoMode = builder.stereoMode;
|
||||||
|
colorInfo = builder.colorInfo;
|
||||||
// Audio specific.
|
// Audio specific.
|
||||||
this.channelCount = channelCount;
|
channelCount = builder.channelCount;
|
||||||
this.sampleRate = sampleRate;
|
sampleRate = builder.sampleRate;
|
||||||
this.pcmEncoding = pcmEncoding;
|
pcmEncoding = builder.pcmEncoding;
|
||||||
this.encoderDelay = encoderDelay == NO_VALUE ? 0 : encoderDelay;
|
encoderDelay = builder.encoderDelay == NO_VALUE ? 0 : builder.encoderDelay;
|
||||||
this.encoderPadding = encoderPadding == NO_VALUE ? 0 : encoderPadding;
|
encoderPadding = builder.encoderPadding == NO_VALUE ? 0 : builder.encoderPadding;
|
||||||
// Text specific.
|
// Text specific.
|
||||||
this.accessibilityChannel = accessibilityChannel;
|
accessibilityChannel = builder.accessibilityChannel;
|
||||||
// Provided by source.
|
// Provided by source.
|
||||||
if (exoMediaCryptoType == null && drmInitData != null) {
|
if (builder.exoMediaCryptoType == null && drmInitData != null) {
|
||||||
// Encrypted content must always have a non-null exoMediaCryptoType.
|
// Encrypted content must always have a non-null exoMediaCryptoType.
|
||||||
exoMediaCryptoType = UnsupportedMediaCrypto.class;
|
exoMediaCryptoType = UnsupportedMediaCrypto.class;
|
||||||
|
} else {
|
||||||
|
exoMediaCryptoType = builder.exoMediaCryptoType;
|
||||||
}
|
}
|
||||||
this.exoMediaCryptoType = exoMediaCryptoType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some fields are deprecated but they're still assigned below.
|
// Some fields are deprecated but they're still assigned below.
|
||||||
|
|
|
||||||
|
|
@ -90,37 +90,38 @@ public final class FormatTest {
|
||||||
C.COLOR_TRANSFER_SDR,
|
C.COLOR_TRANSFER_SDR,
|
||||||
new byte[] {1, 2, 3, 4, 5, 6, 7});
|
new byte[] {1, 2, 3, 4, 5, 6, 7});
|
||||||
|
|
||||||
return new Format(
|
return new Format.Builder()
|
||||||
"id",
|
.setId("id")
|
||||||
"label",
|
.setLabel("label")
|
||||||
"language",
|
.setLanguage("language")
|
||||||
C.SELECTION_FLAG_DEFAULT,
|
.setSelectionFlags(C.SELECTION_FLAG_DEFAULT)
|
||||||
C.ROLE_FLAG_MAIN,
|
.setRoleFlags(C.ROLE_FLAG_MAIN)
|
||||||
/* averageBitrate= */ 1024,
|
.setAverageBitrate(1024)
|
||||||
/* peakBitrate= */ 2048,
|
.setPeakBitrate(2048)
|
||||||
"codec",
|
.setCodecs("codec")
|
||||||
metadata,
|
.setMetadata(metadata)
|
||||||
/* containerMimeType= */ MimeTypes.VIDEO_MP4,
|
.setContainerMimeType(MimeTypes.VIDEO_MP4)
|
||||||
/* sampleMimeType= */ MimeTypes.VIDEO_H264,
|
.setSampleMimeType(MimeTypes.VIDEO_H264)
|
||||||
/* maxInputSize= */ 5000,
|
.setMaxInputSize(5000)
|
||||||
initializationData,
|
.setInitializationData(initializationData)
|
||||||
drmInitData,
|
.setDrmInitData(drmInitData)
|
||||||
Format.OFFSET_SAMPLE_RELATIVE,
|
.setSubsampleOffsetUs(Format.OFFSET_SAMPLE_RELATIVE)
|
||||||
/* width= */ 1920,
|
.setWidth(1920)
|
||||||
/* height= */ 1080,
|
.setHeight(1080)
|
||||||
/* frameRate= */ 24,
|
.setFrameRate(24)
|
||||||
/* rotationDegrees= */ 90,
|
.setRotationDegrees(90)
|
||||||
/* pixelWidthHeightRatio= */ 4,
|
.setPixelWidthHeightRatio(4)
|
||||||
projectionData,
|
.setProjectionData(projectionData)
|
||||||
C.STEREO_MODE_TOP_BOTTOM,
|
.setStereoMode(C.STEREO_MODE_TOP_BOTTOM)
|
||||||
colorInfo,
|
.setColorInfo(colorInfo)
|
||||||
/* channelCount= */ 6,
|
.setChannelCount(6)
|
||||||
/* sampleRate= */ 44100,
|
.setSampleRate(44100)
|
||||||
C.ENCODING_PCM_24BIT,
|
.setPcmEncoding(C.ENCODING_PCM_24BIT)
|
||||||
/* encoderDelay= */ 1001,
|
.setEncoderDelay(1001)
|
||||||
/* encoderPadding= */ 1002,
|
.setEncoderPadding(1002)
|
||||||
/* accessibilityChannel= */ 2,
|
.setAccessibilityChannel(2)
|
||||||
/* exoMediaCryptoType= */ ExoMediaCrypto.class);
|
.setExoMediaCryptoType(ExoMediaCrypto.class)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generates an array of random bytes with the specified length. */
|
/** Generates an array of random bytes with the specified length. */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue