Add Format.createSampleFormat for common use case

PiperOrigin-RevId: 292562678
This commit is contained in:
olly 2020-01-31 17:49:17 +00:00 committed by Oliver Woodman
parent 04218bdeb8
commit d287e13d9e
19 changed files with 62 additions and 57 deletions

View File

@ -746,6 +746,17 @@ public final class Format implements Parcelable {
/* exoMediaCryptoType= */ null);
}
@SuppressWarnings("deprecation")
public static Format createSampleFormat(@Nullable String id, @Nullable String sampleMimeType) {
return createSampleFormat(id, sampleMimeType, OFFSET_SAMPLE_RELATIVE);
}
/**
* @deprecated Use {@link #createSampleFormat(String, String)} and (for values of {@link
* #subsampleOffsetUs} other than {@link #OFFSET_SAMPLE_RELATIVE}) {@link
* #copyWithSubsampleOffsetUs(long)}.
*/
@Deprecated
public static Format createSampleFormat(
@Nullable String id, @Nullable String sampleMimeType, long subsampleOffsetUs) {
return new Format(
@ -780,6 +791,11 @@ public final class Format implements Parcelable {
/* exoMediaCryptoType= */ null);
}
/**
* @deprecated Most usages should use one of the {@link #createVideoSampleFormat} or {@link
* #createAudioSampleFormat} methods.
*/
@Deprecated
public static Format createSampleFormat(
@Nullable String id,
@Nullable String sampleMimeType,

View File

@ -50,11 +50,9 @@ public final class EventMessage implements Metadata.Entry {
@VisibleForTesting public static final String SCTE35_SCHEME_ID = "urn:scte:scte35:2014:bin";
private static final Format ID3_FORMAT =
Format.createSampleFormat(
/* id= */ null, MimeTypes.APPLICATION_ID3, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_ID3);
private static final Format SCTE35_FORMAT =
Format.createSampleFormat(
/* id= */ null, MimeTypes.APPLICATION_SCTE35, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_SCTE35);
/** The message scheme. */
public final String schemeIdUri;

View File

@ -94,7 +94,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
private static final Map<String, String> ICY_METADATA_HEADERS = createIcyMetadataHeaders();
private static final Format ICY_FORMAT =
Format.createSampleFormat("icy", MimeTypes.APPLICATION_ICY, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat("icy", MimeTypes.APPLICATION_ICY);
private final Uri uri;
private final DataSource dataSource;

View File

@ -47,7 +47,7 @@ import org.robolectric.annotation.Config;
@RunWith(AndroidJUnit4.class)
public class SimpleDecoderAudioRendererTest {
private static final Format FORMAT = Format.createSampleFormat(null, MimeTypes.AUDIO_RAW, 0);
private static final Format FORMAT = Format.createSampleFormat(null, MimeTypes.AUDIO_RAW);
@Mock private AudioSink mockAudioSink;
private SimpleDecoderAudioRenderer audioRenderer;

View File

@ -64,7 +64,7 @@ public class MetadataRendererTest {
0x00, 0x00, 0x00, 0x00)); // CRC_32 (ignored, check happens at extraction).
private static final Format EMSG_FORMAT =
Format.createSampleFormat(null, MimeTypes.APPLICATION_EMSG, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat(null, MimeTypes.APPLICATION_EMSG);
private final EventMessageEncoder eventMessageEncoder = new EventMessageEncoder();

View File

@ -56,17 +56,17 @@ public final class SampleQueueTest {
private static final int ALLOCATION_SIZE = 16;
private static final Format FORMAT_1 = Format.createSampleFormat("1", "mimeType", 0);
private static final Format FORMAT_2 = Format.createSampleFormat("2", "mimeType", 0);
private static final Format FORMAT_1_COPY = Format.createSampleFormat("1", "mimeType", 0);
private static final Format FORMAT_SPLICED = Format.createSampleFormat("spliced", "mimeType", 0);
private static final Format FORMAT_1 =
Format.createSampleFormat("1", "mimeType").copyWithSubsampleOffsetUs(0);
private static final Format FORMAT_2 =
Format.createSampleFormat("2", "mimeType").copyWithSubsampleOffsetUs(0);
private static final Format FORMAT_1_COPY =
Format.createSampleFormat("1", "mimeType").copyWithSubsampleOffsetUs(0);
private static final Format FORMAT_SPLICED =
Format.createSampleFormat("spliced", "mimeType").copyWithSubsampleOffsetUs(0);
private static final Format FORMAT_ENCRYPTED =
Format.createSampleFormat(
/* id= */ "encrypted",
"mimeType",
/* codecs= */ null,
/* bitrate= */ Format.NO_VALUE,
new DrmInitData());
Format.createSampleFormat(/* id= */ "encrypted", "mimeType")
.copyWithDrmInitData(new DrmInitData());
private static final byte[] DATA = TestUtil.buildTestData(ALLOCATION_SIZE * 10);
/*

View File

@ -30,9 +30,9 @@ public final class TrackGroupArrayTest {
@Test
public void testParcelable() {
Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264, 0);
Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC, 0);
Format format3 = Format.createSampleFormat("3", MimeTypes.VIDEO_H264, 0);
Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264);
Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC);
Format format3 = Format.createSampleFormat("3", MimeTypes.VIDEO_H264);
TrackGroup trackGroup1 = new TrackGroup(format1, format2);
TrackGroup trackGroup2 = new TrackGroup(format3);

View File

@ -30,8 +30,8 @@ public final class TrackGroupTest {
@Test
public void testParcelable() {
Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264, 0);
Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC, 0);
Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264);
Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC);
TrackGroup trackGroupToParcel = new TrackGroup(format1, format2);

View File

@ -75,9 +75,7 @@ public final class MappingTrackSelectorTest {
/* selectionFlags= */ 0,
/* language= */ null));
private static final TrackGroup METADATA_TRACK_GROUP =
new TrackGroup(
Format.createSampleFormat(
"metadata", MimeTypes.APPLICATION_ID3, /* subsampleOffsetUs= */ 0));
new TrackGroup(Format.createSampleFormat("metadata", MimeTypes.APPLICATION_ID3));
private static final Timeline TIMELINE = new FakeTimeline(/* windowCount= */ 1);

View File

@ -640,8 +640,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
eventMessageTrackGroupIndex,
cea608TrackGroupIndex);
if (eventMessageTrackGroupIndex != C.INDEX_UNSET) {
Format format = Format.createSampleFormat(firstAdaptationSet.id + ":emsg",
MimeTypes.APPLICATION_EMSG, null, Format.NO_VALUE, null);
Format format =
Format.createSampleFormat(firstAdaptationSet.id + ":emsg", MimeTypes.APPLICATION_EMSG);
trackGroups[eventMessageTrackGroupIndex] = new TrackGroup(format);
trackGroupInfos[eventMessageTrackGroupIndex] =
TrackGroupInfo.embeddedEmsgTrack(adaptationSetIndices, primaryTrackGroupIndex);
@ -659,8 +659,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos, int existingTrackGroupCount) {
for (int i = 0; i < eventStreams.size(); i++) {
EventStream eventStream = eventStreams.get(i);
Format format = Format.createSampleFormat(eventStream.id(), MimeTypes.APPLICATION_EMSG, null,
Format.NO_VALUE, null);
Format format = Format.createSampleFormat(eventStream.id(), MimeTypes.APPLICATION_EMSG);
trackGroups[existingTrackGroupCount] = new TrackGroup(format);
trackGroupInfos[existingTrackGroupCount++] = TrackGroupInfo.mpdEventTrack(i);
}

View File

@ -37,8 +37,8 @@ public final class EventSampleStreamTest {
private static final String SCHEME_ID = "urn:test";
private static final String VALUE = "123";
private static final Format FORMAT = Format.createSampleFormat("urn:test/123",
MimeTypes.APPLICATION_EMSG, null, Format.NO_VALUE, null);
private static final Format FORMAT =
Format.createSampleFormat("urn:test/123", MimeTypes.APPLICATION_EMSG);
private static final byte[] MESSAGE_DATA = new byte[] {1, 2, 3, 4};
private static final long DURATION_MS = 3000;
private static final long TIME_SCALE = 1000;

View File

@ -35,10 +35,11 @@ public class DashManifestTest {
private static final UtcTimingElement DUMMY_UTC_TIMING = new UtcTimingElement("", "");
private static final SingleSegmentBase DUMMY_SEGMENT_BASE = new SingleSegmentBase();
private static final Format DUMMY_FORMAT = Format.createSampleFormat("", "", 0);
private static final Format DUMMY_FORMAT =
Format.createSampleFormat(/* id= */ "", /* sampleMimeType= */ "");
@Test
public void testCopy() throws Exception {
public void testCopy() {
Representation[][][] representations = newRepresentations(3, 2, 3);
DashManifest sourceManifest =
newDashManifest(
@ -97,7 +98,7 @@ public class DashManifestTest {
}
@Test
public void testCopySameAdaptationIndexButDifferentPeriod() throws Exception {
public void testCopySameAdaptationIndexButDifferentPeriod() {
Representation[][][] representations = newRepresentations(2, 1, 1);
DashManifest sourceManifest =
newDashManifest(
@ -117,7 +118,7 @@ public class DashManifestTest {
}
@Test
public void testCopySkipPeriod() throws Exception {
public void testCopySkipPeriod() {
Representation[][][] representations = newRepresentations(3, 2, 3);
DashManifest sourceManifest =
newDashManifest(

View File

@ -813,8 +813,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
parseTextSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId,
language, out);
} else if (childAtomType == Atom.TYPE_camm) {
out.format = Format.createSampleFormat(Integer.toString(trackId),
MimeTypes.APPLICATION_CAMERA_MOTION, null, Format.NO_VALUE, null);
out.format =
Format.createSampleFormat(
Integer.toString(trackId), MimeTypes.APPLICATION_CAMERA_MOTION);
}
stsd.setPosition(childStartPosition + childAtomSize);
}

View File

@ -114,7 +114,7 @@ public class FragmentedMp4Extractor implements Extractor {
private static final byte[] PIFF_SAMPLE_ENCRYPTION_BOX_EXTENDED_TYPE =
new byte[] {-94, 57, 79, 82, 90, -101, 79, 20, -94, 68, 108, 66, 124, 100, -115, -12};
private static final Format EMSG_FORMAT =
Format.createSampleFormat(null, MimeTypes.APPLICATION_EMSG, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat(null, MimeTypes.APPLICATION_EMSG);
// Parser states.
private static final int STATE_READING_ATOM_HEADER = 0;

View File

@ -140,8 +140,8 @@ public final class AdtsReader implements ElementaryStreamReader {
if (exposeId3) {
idGenerator.generateNewId();
id3Output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_METADATA);
id3Output.format(Format.createSampleFormat(idGenerator.getFormatId(),
MimeTypes.APPLICATION_ID3, null, Format.NO_VALUE, null));
id3Output.format(
Format.createSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_ID3));
} else {
id3Output = new DummyTrackOutput();
}

View File

@ -61,8 +61,7 @@ public final class Id3Reader implements ElementaryStreamReader {
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
idGenerator.generateNewId();
output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_METADATA);
output.format(Format.createSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_ID3,
null, Format.NO_VALUE, null));
output.format(Format.createSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_ID3));
}
@Override

View File

@ -42,8 +42,8 @@ public final class SpliceInfoSectionReader implements SectionPayloadReader {
this.timestampAdjuster = timestampAdjuster;
idGenerator.generateNewId();
output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_METADATA);
output.format(Format.createSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_SCTE35,
null, Format.NO_VALUE, null));
output.format(
Format.createSampleFormat(idGenerator.getFormatId(), MimeTypes.APPLICATION_SCTE35));
}
@Override
@ -54,8 +54,9 @@ public final class SpliceInfoSectionReader implements SectionPayloadReader {
// There is not enough information to initialize the timestamp adjuster.
return;
}
output.format(Format.createSampleFormat(null, MimeTypes.APPLICATION_SCTE35,
timestampAdjuster.getTimestampOffsetUs()));
output.format(
Format.createSampleFormat(null, MimeTypes.APPLICATION_SCTE35)
.copyWithSubsampleOffsetUs(timestampAdjuster.getTimestampOffsetUs()));
formatDeclared = true;
}
int sampleSize = sectionData.bytesLeft();

View File

@ -659,13 +659,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
}
TrackGroup id3TrackGroup =
new TrackGroup(
Format.createSampleFormat(
/* id= */ "ID3",
MimeTypes.APPLICATION_ID3,
/* codecs= */ null,
/* bitrate= */ Format.NO_VALUE,
/* drmInitData= */ null));
new TrackGroup(Format.createSampleFormat(/* id= */ "ID3", MimeTypes.APPLICATION_ID3));
muxedTrackGroups.add(id3TrackGroup);
sampleStreamWrapper.prepareWithMasterPlaylistInfo(

View File

@ -1401,11 +1401,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
// TODO(ibaker): Create a Formats util class with common constants like this.
private static final Format ID3_FORMAT =
Format.createSampleFormat(
/* id= */ null, MimeTypes.APPLICATION_ID3, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_ID3);
private static final Format EMSG_FORMAT =
Format.createSampleFormat(
/* id= */ null, MimeTypes.APPLICATION_EMSG, Format.OFFSET_SAMPLE_RELATIVE);
Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_EMSG);
private final EventMessageDecoder emsgDecoder;
private final TrackOutput delegate;