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(); @C.TrackType int trackType = groupInfo.getTrackType();
boolean trackInGroupIsSelected = groupInfo.isSelected(); boolean trackInGroupIsSelected = groupInfo.isSelected();
boolean trackInGroupIsSupported = groupInfo.isSupported(); boolean trackInGroupIsSupported = groupInfo.isSupported();
TrackGroup group = groupInfo.getTrackGroup(); for (int i = 0; i < groupInfo.length; i++) {
for (int i = 0; i < group.length; i++) {
// Individual track information. // Individual track information.
boolean isSupported = groupInfo.isTrackSupported(i); boolean isSupported = groupInfo.isTrackSupported(i);
boolean isSelected = groupInfo.isTrackSelected(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. */ /** Information about groups of tracks. */
public final class TracksInfo implements Bundleable { public final class TracksInfo implements Bundleable {
/** /**
* Information about a single group of tracks, including the underlying {@link TrackGroup}, the * 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 * {@link C.TrackType type} of tracks it contains, and the level to which each track is supported
* by the player. * by the player.
*/ */
public static final class TrackGroupInfo implements Bundleable { public static final class TrackGroupInfo implements Bundleable {
/** The number of tracks in the group. */
public final int length;
private final TrackGroup trackGroup; private final TrackGroup trackGroup;
private final @C.FormatSupport int[] trackSupport; private final @C.FormatSupport int[] trackSupport;
private final @C.TrackType int trackType; private final @C.TrackType int trackType;
@ -62,7 +67,7 @@ public final class TracksInfo implements Bundleable {
@C.FormatSupport int[] trackSupport, @C.FormatSupport int[] trackSupport,
@C.TrackType int trackType, @C.TrackType int trackType,
boolean[] tracksSelected) { boolean[] tracksSelected) {
int length = trackGroup.length; length = trackGroup.length;
checkArgument(length == trackSupport.length && length == tracksSelected.length); checkArgument(length == trackSupport.length && length == tracksSelected.length);
this.trackGroup = trackGroup; this.trackGroup = trackGroup;
this.trackSupport = trackSupport.clone(); this.trackSupport = trackSupport.clone();
@ -70,11 +75,21 @@ public final class TracksInfo implements Bundleable {
this.trackSelected = tracksSelected.clone(); this.trackSelected = tracksSelected.clone();
} }
/** Returns the {@link TrackGroup} described by this {@code TrackGroupInfo}. */ /** Returns the underlying {@link TrackGroup}. */
public TrackGroup getTrackGroup() { public TrackGroup getTrackGroup() {
return trackGroup; 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. * 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.LoadEventInfo;
import com.google.android.exoplayer2.source.MediaLoadData; import com.google.android.exoplayer2.source.MediaLoadData;
import com.google.android.exoplayer2.source.MediaSource; 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.FileDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.UdpDataSource; import com.google.android.exoplayer2.upstream.UdpDataSource;
@ -823,10 +822,9 @@ public final class MediaMetricsListener
@Nullable @Nullable
private static DrmInitData getDrmInitData(ImmutableList<TrackGroupInfo> trackGroupInfos) { private static DrmInitData getDrmInitData(ImmutableList<TrackGroupInfo> trackGroupInfos) {
for (TrackGroupInfo trackGroupInfo : trackGroupInfos) { for (TrackGroupInfo trackGroupInfo : trackGroupInfos) {
TrackGroup trackGroup = trackGroupInfo.getTrackGroup(); for (int trackIndex = 0; trackIndex < trackGroupInfo.length; trackIndex++) {
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
if (trackGroupInfo.isTrackSelected(trackIndex)) { if (trackGroupInfo.isTrackSelected(trackIndex)) {
@Nullable DrmInitData drmInitData = trackGroup.getFormat(trackIndex).drmInitData; @Nullable DrmInitData drmInitData = trackGroupInfo.getTrackFormat(trackIndex).drmInitData;
if (drmInitData != null) { if (drmInitData != null) {
return drmInitData; return drmInitData;
} }

View File

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

View File

@ -7974,7 +7974,7 @@ public final class ExoPlayerTest {
assertThat(timelineAfterError.get().getWindowCount()).isEqualTo(1); assertThat(timelineAfterError.get().getWindowCount()).isEqualTo(1);
assertThat(mediaItemIndexAfterError.get()).isEqualTo(0); assertThat(mediaItemIndexAfterError.get()).isEqualTo(0);
assertThat(trackInfosAfterError.get().getTrackGroupInfos()).hasSize(1); 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); .isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT);
assertThat(trackSelectionsAfterError.get().get(0)).isNull(); // Video renderer. assertThat(trackSelectionsAfterError.get().get(0)).isNull(); // Video renderer.
assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer. assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer.

View File

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