use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class MappingTrackSelector method buildTracksInfo.
@VisibleForTesting
static /* package */
TracksInfo buildTracksInfo(@NullableType TrackSelection[] selections, MappedTrackInfo mappedTrackInfo) {
ImmutableList.Builder<TracksInfo.TrackGroupInfo> builder = new ImmutableList.Builder<>();
for (int rendererIndex = 0; rendererIndex < mappedTrackInfo.getRendererCount(); rendererIndex++) {
TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(rendererIndex);
@Nullable TrackSelection trackSelection = selections[rendererIndex];
for (int groupIndex = 0; groupIndex < trackGroupArray.length; groupIndex++) {
TrackGroup trackGroup = trackGroupArray.get(groupIndex);
@C.FormatSupport int[] trackSupport = new int[trackGroup.length];
boolean[] selected = new boolean[trackGroup.length];
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
trackSupport[trackIndex] = mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex);
boolean isTrackSelected = trackSelection != null && trackSelection.getTrackGroup().equals(trackGroup) && trackSelection.indexOf(trackIndex) != C.INDEX_UNSET;
selected[trackIndex] = isTrackSelected;
}
@C.TrackType int trackGroupType = mappedTrackInfo.getRendererType(rendererIndex);
builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
}
}
TrackGroupArray unmappedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
for (int groupIndex = 0; groupIndex < unmappedTrackGroups.length; groupIndex++) {
TrackGroup trackGroup = unmappedTrackGroups.get(groupIndex);
@C.FormatSupport int[] trackSupport = new int[trackGroup.length];
Arrays.fill(trackSupport, C.FORMAT_UNSUPPORTED_TYPE);
// A track group only contains tracks of the same type, thus only consider the first track.
@C.TrackType int trackGroupType = MimeTypes.getTrackType(trackGroup.getFormat(0).sampleMimeType);
// Initialized to false.
boolean[] selected = new boolean[trackGroup.length];
builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
}
return new TracksInfo(builder.build());
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class EventLogger method onTracksChanged.
@Override
public void onTracksChanged(EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
MappedTrackInfo mappedTrackInfo = trackSelector != null ? trackSelector.getCurrentMappedTrackInfo() : null;
if (mappedTrackInfo == null) {
logd(eventTime, "tracks", "[]");
return;
}
logd("tracks [" + getEventTimeString(eventTime));
// Log tracks associated to renderers.
int rendererCount = mappedTrackInfo.getRendererCount();
for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
TrackSelection trackSelection = trackSelections.get(rendererIndex);
if (rendererTrackGroups.length == 0) {
logd(" " + mappedTrackInfo.getRendererName(rendererIndex) + " []");
} else {
logd(" " + mappedTrackInfo.getRendererName(rendererIndex) + " [");
for (int groupIndex = 0; groupIndex < rendererTrackGroups.length; groupIndex++) {
TrackGroup trackGroup = rendererTrackGroups.get(groupIndex);
String adaptiveSupport = getAdaptiveSupportString(trackGroup.length, mappedTrackInfo.getAdaptiveSupport(rendererIndex, groupIndex, /* includeCapabilitiesExceededTracks= */
false));
logd(" Group:" + trackGroup.id + ", adaptive_supported=" + adaptiveSupport + " [");
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
String status = getTrackStatusString(trackSelection, trackGroup, trackIndex);
@Capabilities int capabilities = mappedTrackInfo.getCapabilities(rendererIndex, groupIndex, trackIndex);
String formatSupport = getFormatSupportString(getFormatSupport(capabilities));
String hardwareAccelerationSupport = getHardwareAccelerationSupport(capabilities) == HARDWARE_ACCELERATION_SUPPORTED ? ", accelerated=YES" : "";
String decoderSupport = getDecoderSupport(capabilities) == DECODER_SUPPORT_FALLBACK ? ", fallback=YES" : "";
logd(" " + status + " Track:" + trackIndex + ", " + Format.toLogString(trackGroup.getFormat(trackIndex)) + ", supported=" + formatSupport + hardwareAccelerationSupport + decoderSupport);
}
logd(" ]");
}
// Log metadata for at most one of the tracks selected for the renderer.
if (trackSelection != null) {
for (int selectionIndex = 0; selectionIndex < trackSelection.length(); selectionIndex++) {
Metadata metadata = trackSelection.getFormat(selectionIndex).metadata;
if (metadata != null) {
logd(" Metadata [");
printMetadata(metadata, " ");
logd(" ]");
break;
}
}
}
logd(" ]");
}
}
// Log tracks not associated with a renderer.
TrackGroupArray unassociatedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
if (unassociatedTrackGroups.length > 0) {
logd(" Unmapped [");
for (int groupIndex = 0; groupIndex < unassociatedTrackGroups.length; groupIndex++) {
logd(" Group:" + groupIndex + " [");
TrackGroup trackGroup = unassociatedTrackGroups.get(groupIndex);
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
String status = getTrackStatusString(false);
String formatSupport = getFormatSupportString(C.FORMAT_UNSUPPORTED_TYPE);
logd(" " + status + " Track:" + trackIndex + ", " + Format.toLogString(trackGroup.getFormat(trackIndex)) + ", supported=" + formatSupport);
}
logd(" ]");
}
logd(" ]");
}
logd("]");
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class MergingMediaPeriodTest method prepareMergingPeriod.
private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) throws Exception {
MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
long[] timeOffsetsUs = new long[definitions.length];
for (int i = 0; i < definitions.length; i++) {
MergingPeriodDefinition definition = definitions[i];
timeOffsetsUs[i] = definition.timeOffsetUs;
TrackGroup[] trackGroups = new TrackGroup[definition.formats.length];
for (int j = 0; j < definition.formats.length; j++) {
trackGroups[j] = new TrackGroup(definition.formats[j]);
}
mediaPeriods[i] = new FakeMediaPeriodWithSelectTracksPosition(new TrackGroupArray(trackGroups), new EventDispatcher().withParameters(/* windowIndex= */
i, new MediaPeriodId(/* periodUid= */
i), /* mediaTimeOffsetMs= */
0), /* trackDataFactory= */
(unusedFormat, unusedMediaPeriodId) -> ImmutableList.of(oneByteSample(definition.singleSampleTimeUs, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
}
MergingMediaPeriod mergingMediaPeriod = new MergingMediaPeriod(new DefaultCompositeSequenceableLoaderFactory(), timeOffsetsUs, mediaPeriods);
CountDownLatch prepareCountDown = new CountDownLatch(1);
mergingMediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
prepareCountDown.countDown();
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
mergingMediaPeriod.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
prepareCountDown.await();
return mergingMediaPeriod;
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class MappingTrackSelectorTest method selectTracks_audioAndVideo_sameOrderAsRenderers_mappedToCorrectRenderer.
@Test
public void selectTracks_audioAndVideo_sameOrderAsRenderers_mappedToCorrectRenderer() throws ExoPlaybackException {
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { VIDEO_CAPABILITIES, AUDIO_CAPABILITIES };
TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(/* rendererIndex= */
0, VIDEO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(/* rendererIndex= */
1, AUDIO_TRACK_GROUP);
}
use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.
the class MappingTrackSelectorTest method selectTracks_audioAndVideo_reverseOrderToRenderers_mappedToCorrectRenderer.
@Test
public void selectTracks_audioAndVideo_reverseOrderToRenderers_mappedToCorrectRenderer() throws ExoPlaybackException {
FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
RendererCapabilities[] reverseOrderRendererCapabilities = new RendererCapabilities[] { AUDIO_CAPABILITIES, VIDEO_CAPABILITIES };
trackSelector.selectTracks(reverseOrderRendererCapabilities, trackGroups, periodId, TIMELINE);
trackSelector.assertMappedTrackGroups(/* rendererIndex= */
0, AUDIO_TRACK_GROUP);
trackSelector.assertMappedTrackGroups(/* rendererIndex= */
1, VIDEO_TRACK_GROUP);
}
Aggregations