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); /* 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( public static Format createSampleFormat(
@Nullable String id, @Nullable String sampleMimeType, long subsampleOffsetUs) { @Nullable String id, @Nullable String sampleMimeType, long subsampleOffsetUs) {
return new Format( return new Format(
@ -780,6 +791,11 @@ public final class Format implements Parcelable {
/* exoMediaCryptoType= */ null); /* exoMediaCryptoType= */ null);
} }
/**
* @deprecated Most usages should use one of the {@link #createVideoSampleFormat} or {@link
* #createAudioSampleFormat} methods.
*/
@Deprecated
public static Format createSampleFormat( public static Format createSampleFormat(
@Nullable String id, @Nullable String id,
@Nullable String sampleMimeType, @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"; @VisibleForTesting public static final String SCTE35_SCHEME_ID = "urn:scte:scte35:2014:bin";
private static final Format ID3_FORMAT = private static final Format ID3_FORMAT =
Format.createSampleFormat( Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_ID3);
/* id= */ null, MimeTypes.APPLICATION_ID3, Format.OFFSET_SAMPLE_RELATIVE);
private static final Format SCTE35_FORMAT = private static final Format SCTE35_FORMAT =
Format.createSampleFormat( Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_SCTE35);
/* id= */ null, MimeTypes.APPLICATION_SCTE35, Format.OFFSET_SAMPLE_RELATIVE);
/** The message scheme. */ /** The message scheme. */
public final String schemeIdUri; 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 Map<String, String> ICY_METADATA_HEADERS = createIcyMetadataHeaders();
private static final Format ICY_FORMAT = 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 Uri uri;
private final DataSource dataSource; private final DataSource dataSource;

View File

@ -47,7 +47,7 @@ import org.robolectric.annotation.Config;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class SimpleDecoderAudioRendererTest { 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; @Mock private AudioSink mockAudioSink;
private SimpleDecoderAudioRenderer audioRenderer; private SimpleDecoderAudioRenderer audioRenderer;

View File

@ -64,7 +64,7 @@ public class MetadataRendererTest {
0x00, 0x00, 0x00, 0x00)); // CRC_32 (ignored, check happens at extraction). 0x00, 0x00, 0x00, 0x00)); // CRC_32 (ignored, check happens at extraction).
private static final Format EMSG_FORMAT = 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(); 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 int ALLOCATION_SIZE = 16;
private static final Format FORMAT_1 = Format.createSampleFormat("1", "mimeType", 0); private static final Format FORMAT_1 =
private static final Format FORMAT_2 = Format.createSampleFormat("2", "mimeType", 0); Format.createSampleFormat("1", "mimeType").copyWithSubsampleOffsetUs(0);
private static final Format FORMAT_1_COPY = Format.createSampleFormat("1", "mimeType", 0); private static final Format FORMAT_2 =
private static final Format FORMAT_SPLICED = Format.createSampleFormat("spliced", "mimeType", 0); 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 = private static final Format FORMAT_ENCRYPTED =
Format.createSampleFormat( Format.createSampleFormat(/* id= */ "encrypted", "mimeType")
/* id= */ "encrypted", .copyWithDrmInitData(new DrmInitData());
"mimeType",
/* codecs= */ null,
/* bitrate= */ Format.NO_VALUE,
new DrmInitData());
private static final byte[] DATA = TestUtil.buildTestData(ALLOCATION_SIZE * 10); private static final byte[] DATA = TestUtil.buildTestData(ALLOCATION_SIZE * 10);
/* /*

View File

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

View File

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

View File

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

View File

@ -640,8 +640,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
eventMessageTrackGroupIndex, eventMessageTrackGroupIndex,
cea608TrackGroupIndex); cea608TrackGroupIndex);
if (eventMessageTrackGroupIndex != C.INDEX_UNSET) { if (eventMessageTrackGroupIndex != C.INDEX_UNSET) {
Format format = Format.createSampleFormat(firstAdaptationSet.id + ":emsg", Format format =
MimeTypes.APPLICATION_EMSG, null, Format.NO_VALUE, null); Format.createSampleFormat(firstAdaptationSet.id + ":emsg", MimeTypes.APPLICATION_EMSG);
trackGroups[eventMessageTrackGroupIndex] = new TrackGroup(format); trackGroups[eventMessageTrackGroupIndex] = new TrackGroup(format);
trackGroupInfos[eventMessageTrackGroupIndex] = trackGroupInfos[eventMessageTrackGroupIndex] =
TrackGroupInfo.embeddedEmsgTrack(adaptationSetIndices, primaryTrackGroupIndex); TrackGroupInfo.embeddedEmsgTrack(adaptationSetIndices, primaryTrackGroupIndex);
@ -659,8 +659,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos, int existingTrackGroupCount) { TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos, int existingTrackGroupCount) {
for (int i = 0; i < eventStreams.size(); i++) { for (int i = 0; i < eventStreams.size(); i++) {
EventStream eventStream = eventStreams.get(i); EventStream eventStream = eventStreams.get(i);
Format format = Format.createSampleFormat(eventStream.id(), MimeTypes.APPLICATION_EMSG, null, Format format = Format.createSampleFormat(eventStream.id(), MimeTypes.APPLICATION_EMSG);
Format.NO_VALUE, null);
trackGroups[existingTrackGroupCount] = new TrackGroup(format); trackGroups[existingTrackGroupCount] = new TrackGroup(format);
trackGroupInfos[existingTrackGroupCount++] = TrackGroupInfo.mpdEventTrack(i); 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 SCHEME_ID = "urn:test";
private static final String VALUE = "123"; private static final String VALUE = "123";
private static final Format FORMAT = Format.createSampleFormat("urn:test/123", private static final Format FORMAT =
MimeTypes.APPLICATION_EMSG, null, Format.NO_VALUE, null); Format.createSampleFormat("urn:test/123", MimeTypes.APPLICATION_EMSG);
private static final byte[] MESSAGE_DATA = new byte[] {1, 2, 3, 4}; private static final byte[] MESSAGE_DATA = new byte[] {1, 2, 3, 4};
private static final long DURATION_MS = 3000; private static final long DURATION_MS = 3000;
private static final long TIME_SCALE = 1000; 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 UtcTimingElement DUMMY_UTC_TIMING = new UtcTimingElement("", "");
private static final SingleSegmentBase DUMMY_SEGMENT_BASE = new SingleSegmentBase(); 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 @Test
public void testCopy() throws Exception { public void testCopy() {
Representation[][][] representations = newRepresentations(3, 2, 3); Representation[][][] representations = newRepresentations(3, 2, 3);
DashManifest sourceManifest = DashManifest sourceManifest =
newDashManifest( newDashManifest(
@ -97,7 +98,7 @@ public class DashManifestTest {
} }
@Test @Test
public void testCopySameAdaptationIndexButDifferentPeriod() throws Exception { public void testCopySameAdaptationIndexButDifferentPeriod() {
Representation[][][] representations = newRepresentations(2, 1, 1); Representation[][][] representations = newRepresentations(2, 1, 1);
DashManifest sourceManifest = DashManifest sourceManifest =
newDashManifest( newDashManifest(
@ -117,7 +118,7 @@ public class DashManifestTest {
} }
@Test @Test
public void testCopySkipPeriod() throws Exception { public void testCopySkipPeriod() {
Representation[][][] representations = newRepresentations(3, 2, 3); Representation[][][] representations = newRepresentations(3, 2, 3);
DashManifest sourceManifest = DashManifest sourceManifest =
newDashManifest( newDashManifest(

View File

@ -813,8 +813,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
parseTextSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId, parseTextSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, trackId,
language, out); language, out);
} else if (childAtomType == Atom.TYPE_camm) { } else if (childAtomType == Atom.TYPE_camm) {
out.format = Format.createSampleFormat(Integer.toString(trackId), out.format =
MimeTypes.APPLICATION_CAMERA_MOTION, null, Format.NO_VALUE, null); Format.createSampleFormat(
Integer.toString(trackId), MimeTypes.APPLICATION_CAMERA_MOTION);
} }
stsd.setPosition(childStartPosition + childAtomSize); 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 = 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}; new byte[] {-94, 57, 79, 82, 90, -101, 79, 20, -94, 68, 108, 66, 124, 100, -115, -12};
private static final Format EMSG_FORMAT = private static final Format EMSG_FORMAT =
Format.createSampleFormat(null, MimeTypes.APPLICATION_EMSG, Format.OFFSET_SAMPLE_RELATIVE); Format.createSampleFormat(null, MimeTypes.APPLICATION_EMSG);
// Parser states. // Parser states.
private static final int STATE_READING_ATOM_HEADER = 0; private static final int STATE_READING_ATOM_HEADER = 0;

View File

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

View File

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

View File

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

View File

@ -659,13 +659,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
} }
TrackGroup id3TrackGroup = TrackGroup id3TrackGroup =
new TrackGroup( new TrackGroup(Format.createSampleFormat(/* id= */ "ID3", MimeTypes.APPLICATION_ID3));
Format.createSampleFormat(
/* id= */ "ID3",
MimeTypes.APPLICATION_ID3,
/* codecs= */ null,
/* bitrate= */ Format.NO_VALUE,
/* drmInitData= */ null));
muxedTrackGroups.add(id3TrackGroup); muxedTrackGroups.add(id3TrackGroup);
sampleStreamWrapper.prepareWithMasterPlaylistInfo( 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. // TODO(ibaker): Create a Formats util class with common constants like this.
private static final Format ID3_FORMAT = private static final Format ID3_FORMAT =
Format.createSampleFormat( Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_ID3);
/* id= */ null, MimeTypes.APPLICATION_ID3, Format.OFFSET_SAMPLE_RELATIVE);
private static final Format EMSG_FORMAT = private static final Format EMSG_FORMAT =
Format.createSampleFormat( Format.createSampleFormat(/* id= */ null, MimeTypes.APPLICATION_EMSG);
/* id= */ null, MimeTypes.APPLICATION_EMSG, Format.OFFSET_SAMPLE_RELATIVE);
private final EventMessageDecoder emsgDecoder; private final EventMessageDecoder emsgDecoder;
private final TrackOutput delegate; private final TrackOutput delegate;