Rewrite EventLogger to use new track APIs
PiperOrigin-RevId: 425595951
This commit is contained in:
parent
3871396070
commit
f28de9de60
@ -181,7 +181,7 @@ public final class MainActivity extends Activity {
|
|||||||
Assertions.checkNotNull(this.videoProcessingGLSurfaceView);
|
Assertions.checkNotNull(this.videoProcessingGLSurfaceView);
|
||||||
videoProcessingGLSurfaceView.setPlayer(player);
|
videoProcessingGLSurfaceView.setPlayer(player);
|
||||||
Assertions.checkNotNull(playerView).setPlayer(player);
|
Assertions.checkNotNull(playerView).setPlayer(player);
|
||||||
player.addAnalyticsListener(new EventLogger(/* trackSelector= */ null));
|
player.addAnalyticsListener(new EventLogger());
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
.build();
|
.build();
|
||||||
player.setTrackSelectionParameters(trackSelectionParameters);
|
player.setTrackSelectionParameters(trackSelectionParameters);
|
||||||
player.addListener(new PlayerEventListener());
|
player.addListener(new PlayerEventListener());
|
||||||
player.addAnalyticsListener(new EventLogger(trackSelector));
|
player.addAnalyticsListener(new EventLogger());
|
||||||
player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */ true);
|
player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */ true);
|
||||||
player.setPlayWhenReady(startAutoPlay);
|
player.setPlayWhenReady(startAutoPlay);
|
||||||
playerView.setPlayer(player);
|
playerView.setPlayer(player);
|
||||||
|
@ -16,11 +16,6 @@
|
|||||||
package androidx.media3.exoplayer.util;
|
package androidx.media3.exoplayer.util;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Util.getFormatSupportString;
|
import static androidx.media3.common.util.Util.getFormatSupportString;
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.DECODER_SUPPORT_FALLBACK;
|
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.HARDWARE_ACCELERATION_SUPPORTED;
|
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.getDecoderSupport;
|
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.getFormatSupport;
|
|
||||||
import static androidx.media3.exoplayer.RendererCapabilities.getHardwareAccelerationSupport;
|
|
||||||
import static java.lang.Math.min;
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@ -37,23 +32,18 @@ import androidx.media3.common.Player;
|
|||||||
import androidx.media3.common.Player.PlaybackSuppressionReason;
|
import androidx.media3.common.Player.PlaybackSuppressionReason;
|
||||||
import androidx.media3.common.Timeline;
|
import androidx.media3.common.Timeline;
|
||||||
import androidx.media3.common.TrackGroup;
|
import androidx.media3.common.TrackGroup;
|
||||||
import androidx.media3.common.TrackGroupArray;
|
import androidx.media3.common.TracksInfo;
|
||||||
import androidx.media3.common.TrackSelection;
|
|
||||||
import androidx.media3.common.TrackSelectionArray;
|
|
||||||
import androidx.media3.common.VideoSize;
|
import androidx.media3.common.VideoSize;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.exoplayer.DecoderCounters;
|
import androidx.media3.exoplayer.DecoderCounters;
|
||||||
import androidx.media3.exoplayer.DecoderReuseEvaluation;
|
import androidx.media3.exoplayer.DecoderReuseEvaluation;
|
||||||
import androidx.media3.exoplayer.RendererCapabilities;
|
|
||||||
import androidx.media3.exoplayer.RendererCapabilities.AdaptiveSupport;
|
|
||||||
import androidx.media3.exoplayer.RendererCapabilities.Capabilities;
|
|
||||||
import androidx.media3.exoplayer.analytics.AnalyticsListener;
|
import androidx.media3.exoplayer.analytics.AnalyticsListener;
|
||||||
import androidx.media3.exoplayer.drm.DrmSession;
|
import androidx.media3.exoplayer.drm.DrmSession;
|
||||||
import androidx.media3.exoplayer.source.LoadEventInfo;
|
import androidx.media3.exoplayer.source.LoadEventInfo;
|
||||||
import androidx.media3.exoplayer.source.MediaLoadData;
|
import androidx.media3.exoplayer.source.MediaLoadData;
|
||||||
import androidx.media3.exoplayer.trackselection.MappingTrackSelector;
|
import androidx.media3.exoplayer.trackselection.MappingTrackSelector;
|
||||||
import androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo;
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -74,37 +64,51 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
TIME_FORMAT.setGroupingUsed(false);
|
TIME_FORMAT.setGroupingUsed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable private final MappingTrackSelector trackSelector;
|
|
||||||
private final String tag;
|
private final String tag;
|
||||||
private final Timeline.Window window;
|
private final Timeline.Window window;
|
||||||
private final Timeline.Period period;
|
private final Timeline.Period period;
|
||||||
private final long startTimeMs;
|
private final long startTimeMs;
|
||||||
|
|
||||||
/**
|
/** Creates an instance. */
|
||||||
* Creates event logger.
|
public EventLogger() {
|
||||||
*
|
this(DEFAULT_TAG);
|
||||||
* @param trackSelector The mapping track selector used by the player. May be null if detailed
|
|
||||||
* logging of track mapping is not required.
|
|
||||||
*/
|
|
||||||
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
|
|
||||||
this(trackSelector, DEFAULT_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates event logger.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
* @param trackSelector The mapping track selector used by the player. May be null if detailed
|
|
||||||
* logging of track mapping is not required.
|
|
||||||
* @param tag The tag used for logging.
|
* @param tag The tag used for logging.
|
||||||
*/
|
*/
|
||||||
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
|
public EventLogger(String tag) {
|
||||||
this.trackSelector = trackSelector;
|
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
window = new Timeline.Window();
|
window = new Timeline.Window();
|
||||||
period = new Timeline.Period();
|
period = new Timeline.Period();
|
||||||
startTimeMs = SystemClock.elapsedRealtime();
|
startTimeMs = SystemClock.elapsedRealtime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param trackSelector This parameter is ignored.
|
||||||
|
* @deprecated Use {@link EventLogger()}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public EventLogger(@Nullable MappingTrackSelector trackSelector) {
|
||||||
|
this(DEFAULT_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance.
|
||||||
|
*
|
||||||
|
* @param trackSelector This parameter is ignored.
|
||||||
|
* @param tag The tag used for logging.
|
||||||
|
* @deprecated Use {@link EventLogger(String)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public EventLogger(@Nullable MappingTrackSelector trackSelector, String tag) {
|
||||||
|
this(tag);
|
||||||
|
}
|
||||||
|
|
||||||
// AnalyticsListener
|
// AnalyticsListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -258,83 +262,17 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTracksChanged(
|
public void onTracksInfoChanged(EventTime eventTime, TracksInfo tracksInfo) {
|
||||||
EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
|
||||||
MappedTrackInfo mappedTrackInfo =
|
|
||||||
trackSelector != null ? trackSelector.getCurrentMappedTrackInfo() : null;
|
|
||||||
if (mappedTrackInfo == null) {
|
|
||||||
logd(eventTime, "tracks", "[]");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
logd("tracks [" + getEventTimeString(eventTime));
|
logd("tracks [" + getEventTimeString(eventTime));
|
||||||
// Log tracks associated to renderers.
|
// Log tracks associated to renderers.
|
||||||
int rendererCount = mappedTrackInfo.getRendererCount();
|
ImmutableList<TracksInfo.TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
|
||||||
for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
|
for (int groupIndex = 0; groupIndex < trackGroupInfos.size(); groupIndex++) {
|
||||||
TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
|
TracksInfo.TrackGroupInfo trackGroupInfo = trackGroupInfos.get(groupIndex);
|
||||||
TrackSelection trackSelection = trackSelections.get(rendererIndex);
|
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
|
||||||
if (rendererTrackGroups.length == 0) {
|
logd(" group [");
|
||||||
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++) {
|
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
||||||
String status = getTrackStatusString(trackSelection, trackGroup, trackIndex);
|
String status = getTrackStatusString(trackGroupInfo.isTrackSelected(trackIndex));
|
||||||
@Capabilities
|
String formatSupport = getFormatSupportString(trackGroupInfo.getTrackSupport(trackIndex));
|
||||||
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(
|
logd(
|
||||||
" "
|
" "
|
||||||
+ status
|
+ status
|
||||||
@ -347,7 +285,23 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
}
|
}
|
||||||
logd(" ]");
|
logd(" ]");
|
||||||
}
|
}
|
||||||
|
// TODO: Replace this with an override of onMediaMetadataChanged.
|
||||||
|
// Log metadata for at most one of the selected tracks.
|
||||||
|
for (int groupIndex = 0; groupIndex < trackGroupInfos.size(); groupIndex++) {
|
||||||
|
TracksInfo.TrackGroupInfo trackGroupInfo = trackGroupInfos.get(groupIndex);
|
||||||
|
TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
|
||||||
|
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
|
||||||
|
if (!trackGroupInfo.isTrackSelected(trackIndex)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
@Nullable Metadata metadata = trackGroup.getFormat(trackIndex).metadata;
|
||||||
|
if (metadata != null) {
|
||||||
|
logd(" Metadata [");
|
||||||
|
printMetadata(metadata, " ");
|
||||||
logd(" ]");
|
logd(" ]");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logd("]");
|
logd("]");
|
||||||
}
|
}
|
||||||
@ -653,33 +607,8 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getAdaptiveSupportString(
|
private static String getTrackStatusString(boolean selected) {
|
||||||
int trackCount, @AdaptiveSupport int adaptiveSupport) {
|
return selected ? "[X]" : "[ ]";
|
||||||
if (trackCount < 2) {
|
|
||||||
return "N/A";
|
|
||||||
}
|
|
||||||
switch (adaptiveSupport) {
|
|
||||||
case RendererCapabilities.ADAPTIVE_SEAMLESS:
|
|
||||||
return "YES";
|
|
||||||
case RendererCapabilities.ADAPTIVE_NOT_SEAMLESS:
|
|
||||||
return "YES_NOT_SEAMLESS";
|
|
||||||
case RendererCapabilities.ADAPTIVE_NOT_SUPPORTED:
|
|
||||||
return "NO";
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTrackStatusString(
|
|
||||||
@Nullable TrackSelection selection, TrackGroup group, int trackIndex) {
|
|
||||||
return getTrackStatusString(
|
|
||||||
selection != null
|
|
||||||
&& selection.getTrackGroup().equals(group)
|
|
||||||
&& selection.indexOf(trackIndex) != C.INDEX_UNSET);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTrackStatusString(boolean enabled) {
|
|
||||||
return enabled ? "[X]" : "[ ]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getRepeatModeString(@Player.RepeatMode int repeatMode) {
|
private static String getRepeatModeString(@Player.RepeatMode int repeatMode) {
|
||||||
|
@ -138,7 +138,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
|||||||
player = buildExoPlayer(host, surface, trackSelector);
|
player = buildExoPlayer(host, surface, trackSelector);
|
||||||
player.play();
|
player.play();
|
||||||
player.addAnalyticsListener(this);
|
player.addAnalyticsListener(this);
|
||||||
player.addAnalyticsListener(new EventLogger(trackSelector, tag));
|
player.addAnalyticsListener(new EventLogger(tag));
|
||||||
// Schedule any pending actions.
|
// Schedule any pending actions.
|
||||||
actionHandler =
|
actionHandler =
|
||||||
Clock.DEFAULT.createHandler(Util.getCurrentOrMainLooper(), /* callback= */ null);
|
Clock.DEFAULT.createHandler(Util.getCurrentOrMainLooper(), /* callback= */ null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user