Add getFormat and length to TrackGroupInfo

PiperOrigin-RevId: 428520090
This commit is contained in:
olly 2022-02-14 16:46:44 +00:00 committed by Ian Baker
parent 11f1ebb347
commit c90745d956
6 changed files with 27 additions and 16 deletions

View File

@ -40,12 +40,11 @@ for (TrackGroupInfo groupInfo : tracksInfo.getTrackGroupInfos()) {
@C.TrackType int trackType = groupInfo.getTrackType();
boolean trackInGroupIsSelected = groupInfo.isSelected();
boolean trackInGroupIsSupported = groupInfo.isSupported();
TrackGroup group = groupInfo.getTrackGroup();
for (int i = 0; i < group.length; i++) {
for (int i = 0; i < groupInfo.length; i++) {
// Individual track information.
boolean isSupported = groupInfo.isTrackSupported(i);
boolean isSelected = groupInfo.isTrackSelected(i);
Format trackFormat = group.getFormat(i);
Format trackFormat = groupInfo.getTrackFormat(i);
}
}
~~~

View File

@ -38,12 +38,17 @@ import java.util.List;
/** Information about groups of tracks. */
public final class TracksInfo implements Bundleable {
/**
* Information about a single group of tracks, including the underlying {@link TrackGroup}, the
* {@link C.TrackType type} of tracks it contains, and the level to which each track is supported
* by the player.
*/
public static final class TrackGroupInfo implements Bundleable {
/** The number of tracks in the group. */
public final int length;
private final TrackGroup trackGroup;
private final @C.FormatSupport int[] trackSupport;
private final @C.TrackType int trackType;
@ -62,7 +67,7 @@ public final class TracksInfo implements Bundleable {
@C.FormatSupport int[] trackSupport,
@C.TrackType int trackType,
boolean[] tracksSelected) {
int length = trackGroup.length;
length = trackGroup.length;
checkArgument(length == trackSupport.length && length == tracksSelected.length);
this.trackGroup = trackGroup;
this.trackSupport = trackSupport.clone();
@ -70,11 +75,21 @@ public final class TracksInfo implements Bundleable {
this.trackSelected = tracksSelected.clone();
}
/** Returns the {@link TrackGroup} described by this {@code TrackGroupInfo}. */
/** Returns the underlying {@link TrackGroup}. */
public TrackGroup getTrackGroup() {
return trackGroup;
}
/**
* Returns the {@link Format} for a specified track.
*
* @param trackIndex The index of the track in the {@link TrackGroup}.
* @return The {@link Format} of the track.
*/
public Format getTrackFormat(int trackIndex) {
return trackGroup.getFormat(trackIndex);
}
/**
* Returns the level of support for a specified track.
*

View File

@ -62,7 +62,6 @@ import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer;
import com.google.android.exoplayer2.source.LoadEventInfo;
import com.google.android.exoplayer2.source.MediaLoadData;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.upstream.FileDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.UdpDataSource;
@ -823,10 +822,9 @@ public final class MediaMetricsListener
@Nullable
private static DrmInitData getDrmInitData(ImmutableList<TrackGroupInfo> trackGroupInfos) {
for (TrackGroupInfo trackGroupInfo : trackGroupInfos) {
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
if (trackGroupInfo.isTrackSelected(trackIndex)) {
@Nullable DrmInitData drmInitData = trackGroup.getFormat(trackIndex).drmInitData;
@Nullable DrmInitData drmInitData = trackGroupInfo.getTrackFormat(trackIndex).drmInitData;
if (drmInitData != null) {
return drmInitData;
}

View File

@ -265,9 +265,8 @@ public class EventLogger implements AnalyticsListener {
ImmutableList<TracksInfo.TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
for (int groupIndex = 0; groupIndex < trackGroupInfos.size(); groupIndex++) {
TracksInfo.TrackGroupInfo trackGroupInfo = trackGroupInfos.get(groupIndex);
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
logd(" group [");
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
String status = getTrackStatusString(trackGroupInfo.isTrackSelected(trackIndex));
String formatSupport = getFormatSupportString(trackGroupInfo.getTrackSupport(trackIndex));
logd(
@ -276,7 +275,7 @@ public class EventLogger implements AnalyticsListener {
+ " Track:"
+ trackIndex
+ ", "
+ Format.toLogString(trackGroup.getFormat(trackIndex))
+ Format.toLogString(trackGroupInfo.getTrackFormat(trackIndex))
+ ", supported="
+ formatSupport);
}

View File

@ -7974,7 +7974,7 @@ public final class ExoPlayerTest {
assertThat(timelineAfterError.get().getWindowCount()).isEqualTo(1);
assertThat(mediaItemIndexAfterError.get()).isEqualTo(0);
assertThat(trackInfosAfterError.get().getTrackGroupInfos()).hasSize(1);
assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackGroup().getFormat(0))
assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackFormat(0))
.isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT);
assertThat(trackSelectionsAfterError.get().get(0)).isNull(); // Video renderer.
assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer.

View File

@ -1130,12 +1130,12 @@ public class StyledPlayerControlView extends FrameLayout {
if (trackGroupInfo.getTrackType() != trackType) {
continue;
}
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
if (!trackGroupInfo.isTrackSupported(trackIndex)) {
continue;
}
String trackName = trackNameProvider.getTrackName(trackGroup.getFormat(trackIndex));
String trackName =
trackNameProvider.getTrackName(trackGroupInfo.getTrackFormat(trackIndex));
tracks.add(new TrackInformation(tracksInfo, trackGroupIndex, trackIndex, trackName));
}
}