use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class DefaultTrackSelectorTest method selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage.
/**
* Tests that track selector will prefer tracks that are within renderer's capabilities over track
* that have both language matching preferred audio given by {@link Parameters} and {@link
* C#SELECTION_FLAG_DEFAULT}, but exceed renderer's capabilities.
*/
@Test
public void selectTracksPreferTrackWithinCapabilitiesOverSelectionFlagAndPreferredLanguage() throws Exception {
Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
Format exceededDefaultSelectionEnFormat = formatBuilder.setId("exceededFormat").setSelectionFlags(C.SELECTION_FLAG_DEFAULT).setLanguage("eng").build();
Format supportedFrFormat = formatBuilder.setId("supportedFormat").setSelectionFlags(0).setLanguage("fra").build();
TrackGroupArray trackGroups = wrapFormats(exceededDefaultSelectionEnFormat, supportedFrFormat);
Map<String, Integer> mappedCapabilities = new HashMap<>();
mappedCapabilities.put(exceededDefaultSelectionEnFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
mappedCapabilities.put(supportedFrFormat.id, FORMAT_HANDLED);
RendererCapabilities mappedAudioRendererCapabilities = new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredAudioLanguage("eng"));
TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { mappedAudioRendererCapabilities }, trackGroups, periodId, TIMELINE);
assertFixedSelection(result.selections[0], trackGroups, supportedFrFormat);
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class SampleQueueTest method writeTestData.
/**
* Writes the specified test data to {@code sampleQueue}.
*/
@SuppressWarnings("ReferenceEquality")
private void writeTestData(byte[] data, int[] sampleSizes, int[] sampleOffsets, long[] sampleTimestamps, Format[] sampleFormats, int[] sampleFlags) {
sampleQueue.sampleData(new ParsableByteArray(data), data.length);
Format format = null;
for (int i = 0; i < sampleTimestamps.length; i++) {
if (sampleFormats[i] != format) {
sampleQueue.format(sampleFormats[i]);
format = sampleFormats[i];
}
sampleQueue.sampleMetadata(sampleTimestamps[i], sampleFlags[i], sampleSizes[i], sampleOffsets[i], (sampleFlags[i] & C.BUFFER_FLAG_ENCRYPTED) != 0 ? CRYPTO_DATA : null);
}
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class SampleQueueTest method multipleFormatsDeduplicated.
@Test
public void multipleFormatsDeduplicated() {
sampleQueue.format(FORMAT_1);
sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
sampleQueue.sampleMetadata(0, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
// Writing multiple formats should not cause a format change on the read side, provided the last
// format to be written is equal to the format of the previous sample.
sampleQueue.format(FORMAT_2);
sampleQueue.format(FORMAT_1_COPY);
sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
sampleQueue.sampleMetadata(1000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
assertReadFormat(false, FORMAT_1);
assertReadSample(0, /* isKeyFrame= */
true, /* isDecodeOnly= */
false, /* isEncrypted= */
false, DATA, /* offset= */
0, ALLOCATION_SIZE);
// Assert the second sample is read without a format change.
assertReadSample(1000, /* isKeyFrame= */
true, /* isDecodeOnly= */
false, /* isEncrypted= */
false, DATA, /* offset= */
0, ALLOCATION_SIZE);
// The same applies if the queue is empty when the formats are written.
sampleQueue.format(FORMAT_2);
sampleQueue.format(FORMAT_1);
sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
sampleQueue.sampleMetadata(2000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
// Assert the third sample is read without a format change.
assertReadSample(2000, /* isKeyFrame= */
true, /* isDecodeOnly= */
false, /* isEncrypted= */
false, DATA, /* offset= */
0, ALLOCATION_SIZE);
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class SampleQueueTest method readSingleSamples.
@Test
public void readSingleSamples() {
sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
assertAllocationCount(1);
// Nothing to read.
assertNoSamplesToRead(null);
sampleQueue.format(FORMAT_1);
// Read the format.
assertReadFormat(false, FORMAT_1);
// Nothing to read.
assertNoSamplesToRead(FORMAT_1);
sampleQueue.sampleMetadata(1000, C.BUFFER_FLAG_KEY_FRAME, ALLOCATION_SIZE, 0, null);
// If formatRequired, should read the format rather than the sample.
assertReadFormat(true, FORMAT_1);
// Otherwise should read the sample.
assertReadSample(1000, /* isKeyFrame= */
true, /* isDecodeOnly= */
false, /* isEncrypted= */
false, DATA, /* offset= */
0, ALLOCATION_SIZE);
// Allocation should still be held.
assertAllocationCount(1);
sampleQueue.discardToRead();
// The allocation should have been released.
assertAllocationCount(0);
// Nothing to read.
assertNoSamplesToRead(FORMAT_1);
// Write a second sample followed by one byte that does not belong to it.
sampleQueue.sampleData(new ParsableByteArray(DATA), ALLOCATION_SIZE);
sampleQueue.sampleMetadata(2000, 0, ALLOCATION_SIZE - 1, 1, null);
// If formatRequired, should read the format rather than the sample.
assertReadFormat(true, FORMAT_1);
// Read the sample.
assertReadSample(2000, /* isKeyFrame= */
false, /* isDecodeOnly= */
false, /* isEncrypted= */
false, DATA, /* offset= */
0, ALLOCATION_SIZE - 1);
// Allocation should still be held.
assertAllocationCount(1);
sampleQueue.discardToRead();
// The last byte written to the sample queue may belong to a sample whose metadata has yet to be
// written, so an allocation should still be held.
assertAllocationCount(1);
// Write metadata for a third sample containing the remaining byte.
sampleQueue.sampleMetadata(3000, 0, 1, 0, null);
// If formatRequired, should read the format rather than the sample.
assertReadFormat(true, FORMAT_1);
// Read the sample.
assertReadSample(3000, /* isKeyFrame= */
false, /* isDecodeOnly= */
false, /* isEncrypted= */
false, DATA, ALLOCATION_SIZE - 1, 1);
// Allocation should still be held.
assertAllocationCount(1);
sampleQueue.discardToRead();
// The allocation should have been released.
assertAllocationCount(0);
}
use of com.google.android.exoplayer2.Format in project ExoPlayer by google.
the class SampleQueueTest method setStartTimeUs_notAllSamplesAreSyncSamples_discardsOnReadSide.
@Test
public void setStartTimeUs_notAllSamplesAreSyncSamples_discardsOnReadSide() {
// The format uses a MIME type for which MimeTypes.allSamplesAreSyncSamples() is false.
Format format = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).build();
Format[] sampleFormats = new Format[SAMPLE_SIZES.length];
Arrays.fill(sampleFormats, format);
sampleQueue.setStartTimeUs(LAST_SAMPLE_TIMESTAMP);
writeTestData();
assertThat(sampleQueue.getReadIndex()).isEqualTo(0);
assertReadTestData(/* startFormat= */
null, /* firstSampleIndex= */
0, /* sampleCount= */
SAMPLE_TIMESTAMPS.length, /* sampleOffsetUs= */
0, /* decodeOnlyUntilUs= */
LAST_SAMPLE_TIMESTAMP);
}
Aggregations