Replace onViewportSizeChanged with onSurfaceSizeChanged in AnalyticsListener.
This allows the AnalyticsCollector to register itself as a VideoListener to get these updates automatically instead of relying on the user to provide updates. The ViewportSizeReporter was amended to do the pixel to dp conversion itself. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=199796532
This commit is contained in:
parent
448ce43ddf
commit
fcb9ca7b81
@ -188,6 +188,7 @@ public class SimpleExoPlayer implements ExoPlayer, Player.VideoComponent, Player
|
|||||||
analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
|
analyticsCollector = analyticsCollectorFactory.createAnalyticsCollector(player, clock);
|
||||||
addListener(analyticsCollector);
|
addListener(analyticsCollector);
|
||||||
videoDebugListeners.add(analyticsCollector);
|
videoDebugListeners.add(analyticsCollector);
|
||||||
|
videoListeners.add(analyticsCollector);
|
||||||
audioDebugListeners.add(analyticsCollector);
|
audioDebugListeners.add(analyticsCollector);
|
||||||
addMetadataOutput(analyticsCollector);
|
addMetadataOutput(analyticsCollector);
|
||||||
if (drmSessionManager instanceof DefaultDrmSessionManager) {
|
if (drmSessionManager instanceof DefaultDrmSessionManager) {
|
||||||
@ -1045,8 +1046,12 @@ public class SimpleExoPlayer implements ExoPlayer, Player.VideoComponent, Player
|
|||||||
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
|
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
|
||||||
float pixelWidthHeightRatio) {
|
float pixelWidthHeightRatio) {
|
||||||
for (com.google.android.exoplayer2.video.VideoListener videoListener : videoListeners) {
|
for (com.google.android.exoplayer2.video.VideoListener videoListener : videoListeners) {
|
||||||
videoListener.onVideoSizeChanged(width, height, unappliedRotationDegrees,
|
// Prevent duplicate notification if a listener is both a VideoRendererDebugListener and
|
||||||
pixelWidthHeightRatio);
|
// VideoListener as they have the same method signature.
|
||||||
|
if (!videoDebugListeners.contains(videoListener)) {
|
||||||
|
videoListener.onVideoSizeChanged(
|
||||||
|
width, height, unappliedRotationDegrees, pixelWidthHeightRatio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (VideoRendererEventListener videoDebugListener : videoDebugListeners) {
|
for (VideoRendererEventListener videoDebugListener : videoDebugListeners) {
|
||||||
videoDebugListener.onVideoSizeChanged(width, height, unappliedRotationDegrees,
|
videoDebugListener.onVideoSizeChanged(width, height, unappliedRotationDegrees,
|
||||||
|
@ -38,6 +38,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
|||||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Clock;
|
import com.google.android.exoplayer2.util.Clock;
|
||||||
|
import com.google.android.exoplayer2.video.VideoListener;
|
||||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -58,7 +59,8 @@ public class AnalyticsCollector
|
|||||||
VideoRendererEventListener,
|
VideoRendererEventListener,
|
||||||
MediaSourceEventListener,
|
MediaSourceEventListener,
|
||||||
BandwidthMeter.EventListener,
|
BandwidthMeter.EventListener,
|
||||||
DefaultDrmSessionEventListener {
|
DefaultDrmSessionEventListener,
|
||||||
|
VideoListener {
|
||||||
|
|
||||||
/** Factory for an analytics collector. */
|
/** Factory for an analytics collector. */
|
||||||
public static class Factory {
|
public static class Factory {
|
||||||
@ -145,19 +147,6 @@ public class AnalyticsCollector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify analytics collector that the viewport size changed.
|
|
||||||
*
|
|
||||||
* @param width The new width of the viewport in device-independent pixels (dp).
|
|
||||||
* @param height The new height of the viewport in device-independent pixels (dp).
|
|
||||||
*/
|
|
||||||
public final void notifyViewportSizeChanged(int width, int height) {
|
|
||||||
EventTime eventTime = generatePlayingMediaPeriodEventTime();
|
|
||||||
for (AnalyticsListener listener : listeners) {
|
|
||||||
listener.onViewportSizeChange(eventTime, width, height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the analytics collector for a new media source. Should be called before the player is
|
* Resets the analytics collector for a new media source. Should be called before the player is
|
||||||
* prepared with a new media source.
|
* prepared with a new media source.
|
||||||
@ -284,6 +273,16 @@ public class AnalyticsCollector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onVideoDisabled(DecoderCounters counters) {
|
||||||
|
// The renderers are disabled after we changed the playing media period on the playback thread
|
||||||
|
// but before this change is reported to the app thread.
|
||||||
|
EventTime eventTime = generateLastReportedPlayingMediaPeriodEventTime();
|
||||||
|
for (AnalyticsListener listener : listeners) {
|
||||||
|
listener.onDecoderDisabled(eventTime, C.TRACK_TYPE_VIDEO, counters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onRenderedFirstFrame(Surface surface) {
|
public final void onRenderedFirstFrame(Surface surface) {
|
||||||
EventTime eventTime = generateReadingMediaPeriodEventTime();
|
EventTime eventTime = generateReadingMediaPeriodEventTime();
|
||||||
@ -292,13 +291,18 @@ public class AnalyticsCollector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VideoListener implementation.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onVideoDisabled(DecoderCounters counters) {
|
public final void onRenderedFirstFrame() {
|
||||||
// The renderers are disabled after we changed the playing media period on the playback thread
|
// Do nothing. Already reported in VideoRendererEventListener.onRenderedFirstFrame.
|
||||||
// but before this change is reported to the app thread.
|
}
|
||||||
EventTime eventTime = generateLastReportedPlayingMediaPeriodEventTime();
|
|
||||||
|
@Override
|
||||||
|
public void onSurfaceSizeChanged(int width, int height) {
|
||||||
|
EventTime eventTime = generateReadingMediaPeriodEventTime();
|
||||||
for (AnalyticsListener listener : listeners) {
|
for (AnalyticsListener listener : listeners) {
|
||||||
listener.onDecoderDisabled(eventTime, C.TRACK_TYPE_VIDEO, counters);
|
listener.onSurfaceSizeChanged(eventTime, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,13 +304,15 @@ public interface AnalyticsListener {
|
|||||||
EventTime eventTime, int totalLoadTimeMs, long totalBytesLoaded, long bitrateEstimate);
|
EventTime eventTime, int totalLoadTimeMs, long totalBytesLoaded, long bitrateEstimate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the viewport size of the output surface changed.
|
* Called when the output surface size changed.
|
||||||
*
|
*
|
||||||
* @param eventTime The event time.
|
* @param eventTime The event time.
|
||||||
* @param width The width of the viewport in device-independent pixels (dp).
|
* @param width The surface width in pixels. May be {@link C#LENGTH_UNSET} if unknown, or 0 if the
|
||||||
* @param height The height of the viewport in device-independent pixels (dp).
|
* video is not rendered onto a surface.
|
||||||
|
* @param height The surface height in pixels. May be {@link C#LENGTH_UNSET} if unknown, or 0 if
|
||||||
|
* the video is not rendered onto a surface.
|
||||||
*/
|
*/
|
||||||
void onViewportSizeChange(EventTime eventTime, int width, int height);
|
void onSurfaceSizeChanged(EventTime eventTime, int width, int height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when there is {@link Metadata} associated with the current playback time.
|
* Called when there is {@link Metadata} associated with the current playback time.
|
||||||
|
@ -107,7 +107,7 @@ public abstract class DefaultAnalyticsListener implements AnalyticsListener {
|
|||||||
EventTime eventTime, int totalLoadTimeMs, long totalBytesLoaded, long bitrateEstimate) {}
|
EventTime eventTime, int totalLoadTimeMs, long totalBytesLoaded, long bitrateEstimate) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewportSizeChange(EventTime eventTime, int width, int height) {}
|
public void onSurfaceSizeChanged(EventTime eventTime, int width, int height) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMetadata(EventTime eventTime, Metadata metadata) {}
|
public void onMetadata(EventTime eventTime, Metadata metadata) {}
|
||||||
|
@ -363,8 +363,8 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewportSizeChange(EventTime eventTime, int width, int height) {
|
public void onSurfaceSizeChanged(EventTime eventTime, int width, int height) {
|
||||||
logd(eventTime, "viewportSizeChanged", width + ", " + height);
|
logd(eventTime, "surfaceSizeChanged", width + ", " + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,7 +93,7 @@ public final class AnalyticsCollectorTest {
|
|||||||
private static final int EVENT_MEDIA_PERIOD_RELEASED = 18;
|
private static final int EVENT_MEDIA_PERIOD_RELEASED = 18;
|
||||||
private static final int EVENT_READING_STARTED = 19;
|
private static final int EVENT_READING_STARTED = 19;
|
||||||
private static final int EVENT_BANDWIDTH_ESTIMATE = 20;
|
private static final int EVENT_BANDWIDTH_ESTIMATE = 20;
|
||||||
private static final int EVENT_VIEWPORT_SIZE_CHANGED = 21;
|
private static final int EVENT_SURFACE_SIZE_CHANGED = 21;
|
||||||
private static final int EVENT_METADATA = 23;
|
private static final int EVENT_METADATA = 23;
|
||||||
private static final int EVENT_DECODER_ENABLED = 24;
|
private static final int EVENT_DECODER_ENABLED = 24;
|
||||||
private static final int EVENT_DECODER_INIT = 25;
|
private static final int EVENT_DECODER_INIT = 25;
|
||||||
@ -670,9 +670,6 @@ public final class AnalyticsCollectorTest {
|
|||||||
new PlayerRunnable() {
|
new PlayerRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(SimpleExoPlayer player) {
|
public void run(SimpleExoPlayer player) {
|
||||||
player
|
|
||||||
.getAnalyticsCollector()
|
|
||||||
.notifyViewportSizeChanged(/* width= */ 320, /* height= */ 240);
|
|
||||||
player.getAnalyticsCollector().notifySeekStarted();
|
player.getAnalyticsCollector().notifySeekStarted();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -683,7 +680,6 @@ public final class AnalyticsCollectorTest {
|
|||||||
|
|
||||||
assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(PERIOD_0);
|
assertThat(listener.getEvents(EVENT_SEEK_STARTED)).containsExactly(PERIOD_0);
|
||||||
assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(PERIOD_0);
|
assertThat(listener.getEvents(EVENT_SEEK_PROCESSED)).containsExactly(PERIOD_0);
|
||||||
assertThat(listener.getEvents(EVENT_VIEWPORT_SIZE_CHANGED)).containsExactly(PERIOD_0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TestAnalyticsListener runAnalyticsTest(MediaSource mediaSource) throws Exception {
|
private static TestAnalyticsListener runAnalyticsTest(MediaSource mediaSource) throws Exception {
|
||||||
@ -1014,8 +1010,8 @@ public final class AnalyticsCollectorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewportSizeChange(EventTime eventTime, int width, int height) {
|
public void onSurfaceSizeChanged(EventTime eventTime, int width, int height) {
|
||||||
reportedEvents.add(new ReportedEvent(EVENT_VIEWPORT_SIZE_CHANGED, eventTime));
|
reportedEvents.add(new ReportedEvent(EVENT_SURFACE_SIZE_CHANGED, eventTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user