mirror of
https://github.com/androidx/media.git
synced 2025-05-07 15:40:37 +08:00
Add plumbing for decoderReleased analytics events
A subsequent CL will plumb a release reason through these event paths. PiperOrigin-RevId: 338655603
This commit is contained in:
parent
485949b56c
commit
e5434ff4d3
@ -215,9 +215,9 @@ public interface Renderer extends PlayerMessage.Target {
|
|||||||
@IntDef({STATE_DISABLED, STATE_ENABLED, STATE_STARTED})
|
@IntDef({STATE_DISABLED, STATE_ENABLED, STATE_STARTED})
|
||||||
@interface State {}
|
@interface State {}
|
||||||
/**
|
/**
|
||||||
* The renderer is disabled. A renderer in this state may hold resources that it requires for
|
* The renderer is disabled. A renderer in this state will not proactively acquire resources that
|
||||||
* rendering (e.g. media decoders), for use if it's subsequently enabled. {@link #reset()} can be
|
* it requires for rendering (e.g., media decoders), but may continue to hold any that it already
|
||||||
* called to force the renderer to release these resources.
|
* has. {@link #reset()} can be called to force the renderer to release such resources.
|
||||||
*/
|
*/
|
||||||
int STATE_DISABLED = 0;
|
int STATE_DISABLED = 0;
|
||||||
/**
|
/**
|
||||||
|
@ -2285,6 +2285,13 @@ public class SimpleExoPlayer extends BasePlayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVideoDecoderReleased(String decoderName) {
|
||||||
|
for (VideoRendererEventListener videoDebugListener : videoDebugListeners) {
|
||||||
|
videoDebugListener.onVideoDecoderReleased(decoderName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVideoDisabled(DecoderCounters counters) {
|
public void onVideoDisabled(DecoderCounters counters) {
|
||||||
for (VideoRendererEventListener videoDebugListener : videoDebugListeners) {
|
for (VideoRendererEventListener videoDebugListener : videoDebugListeners) {
|
||||||
@ -2351,6 +2358,13 @@ public class SimpleExoPlayer extends BasePlayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAudioDecoderReleased(String decoderName) {
|
||||||
|
for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
|
||||||
|
audioDebugListener.onAudioDecoderReleased(decoderName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAudioDisabled(DecoderCounters counters) {
|
public void onAudioDisabled(DecoderCounters counters) {
|
||||||
for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
|
for (AudioRendererEventListener audioDebugListener : audioDebugListeners) {
|
||||||
|
@ -220,6 +220,12 @@ public class AnalyticsCollector
|
|||||||
listener.onAudioUnderrun(eventTime, bufferSize, bufferSizeMs, elapsedSinceLastFeedMs));
|
listener.onAudioUnderrun(eventTime, bufferSize, bufferSizeMs, elapsedSinceLastFeedMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onAudioDecoderReleased(String decoderName) {
|
||||||
|
EventTime eventTime = generateReadingMediaPeriodEventTime();
|
||||||
|
listeners.sendEvent(listener -> listener.onAudioDecoderReleased(eventTime, decoderName));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public final void onAudioDisabled(DecoderCounters counters) {
|
public final void onAudioDisabled(DecoderCounters counters) {
|
||||||
@ -307,6 +313,12 @@ public class AnalyticsCollector
|
|||||||
listeners.sendEvent(listener -> listener.onDroppedVideoFrames(eventTime, count, elapsedMs));
|
listeners.sendEvent(listener -> listener.onDroppedVideoFrames(eventTime, count, elapsedMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onVideoDecoderReleased(String decoderName) {
|
||||||
|
EventTime eventTime = generateReadingMediaPeriodEventTime();
|
||||||
|
listeners.sendEvent(listener -> listener.onVideoDecoderReleased(eventTime, decoderName));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public final void onVideoDisabled(DecoderCounters counters) {
|
public final void onVideoDisabled(DecoderCounters counters) {
|
||||||
|
@ -512,6 +512,14 @@ public interface AnalyticsListener {
|
|||||||
default void onAudioUnderrun(
|
default void onAudioUnderrun(
|
||||||
EventTime eventTime, int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {}
|
EventTime eventTime, int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an audio renderer releases a decoder.
|
||||||
|
*
|
||||||
|
* @param eventTime The event time.
|
||||||
|
* @param decoderName The decoder that was released.
|
||||||
|
*/
|
||||||
|
default void onAudioDecoderReleased(EventTime eventTime, String decoderName) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an audio renderer is disabled.
|
* Called when an audio renderer is disabled.
|
||||||
*
|
*
|
||||||
@ -600,6 +608,14 @@ public interface AnalyticsListener {
|
|||||||
*/
|
*/
|
||||||
default void onDroppedVideoFrames(EventTime eventTime, int droppedFrames, long elapsedMs) {}
|
default void onDroppedVideoFrames(EventTime eventTime, int droppedFrames, long elapsedMs) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a video renderer releases a decoder.
|
||||||
|
*
|
||||||
|
* @param eventTime The event time.
|
||||||
|
* @param decoderName The decoder that was released.
|
||||||
|
*/
|
||||||
|
default void onVideoDecoderReleased(EventTime eventTime, String decoderName) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a video renderer is disabled.
|
* Called when a video renderer is disabled.
|
||||||
*
|
*
|
||||||
|
@ -87,6 +87,13 @@ public interface AudioRendererEventListener {
|
|||||||
*/
|
*/
|
||||||
default void onAudioUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {}
|
default void onAudioUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a decoder is released.
|
||||||
|
*
|
||||||
|
* @param decoderName The decoder that was released.
|
||||||
|
*/
|
||||||
|
default void onAudioDecoderReleased(String decoderName) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the renderer is disabled.
|
* Called when the renderer is disabled.
|
||||||
*
|
*
|
||||||
@ -184,6 +191,13 @@ public interface AudioRendererEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Invokes {@link AudioRendererEventListener#onAudioDecoderReleased(String)}. */
|
||||||
|
public void decoderReleased(String decoderName) {
|
||||||
|
if (handler != null) {
|
||||||
|
handler.post(() -> castNonNull(listener).onAudioDecoderReleased(decoderName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Invokes {@link AudioRendererEventListener#onAudioDisabled(DecoderCounters)}. */
|
/** Invokes {@link AudioRendererEventListener#onAudioDisabled(DecoderCounters)}. */
|
||||||
public void disabled(DecoderCounters counters) {
|
public void disabled(DecoderCounters counters) {
|
||||||
counters.ensureUpdated();
|
counters.ensureUpdated();
|
||||||
|
@ -632,9 +632,10 @@ public abstract class DecoderAudioRenderer<
|
|||||||
decoderReinitializationState = REINITIALIZATION_STATE_NONE;
|
decoderReinitializationState = REINITIALIZATION_STATE_NONE;
|
||||||
decoderReceivedBuffers = false;
|
decoderReceivedBuffers = false;
|
||||||
if (decoder != null) {
|
if (decoder != null) {
|
||||||
decoder.release();
|
|
||||||
decoder = null;
|
|
||||||
decoderCounters.decoderReleaseCount++;
|
decoderCounters.decoderReleaseCount++;
|
||||||
|
decoder.release();
|
||||||
|
eventDispatcher.decoderReleased(decoder.getName());
|
||||||
|
decoder = null;
|
||||||
}
|
}
|
||||||
setDecoderDrmSession(null);
|
setDecoderDrmSession(null);
|
||||||
}
|
}
|
||||||
|
@ -391,6 +391,11 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
|||||||
eventDispatcher.decoderInitialized(name, initializedTimestampMs, initializationDurationMs);
|
eventDispatcher.decoderInitialized(name, initializedTimestampMs, initializationDurationMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCodecReleased(String name) {
|
||||||
|
eventDispatcher.decoderReleased(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
||||||
super.onInputFormatChanged(formatHolder);
|
super.onInputFormatChanged(formatHolder);
|
||||||
|
@ -745,6 +745,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
if (codec != null) {
|
if (codec != null) {
|
||||||
decoderCounters.decoderReleaseCount++;
|
decoderCounters.decoderReleaseCount++;
|
||||||
codec.release();
|
codec.release();
|
||||||
|
onCodecReleased(codecInfo.name);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
codec = null;
|
codec = null;
|
||||||
@ -1384,6 +1385,17 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a {@link MediaCodec} has been released.
|
||||||
|
*
|
||||||
|
* <p>The default implementation is a no-op.
|
||||||
|
*
|
||||||
|
* @param name The name of the codec that was released.
|
||||||
|
*/
|
||||||
|
protected void onCodecReleased(String name) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a new {@link Format} is read from the upstream {@link MediaPeriod}.
|
* Called when a new {@link Format} is read from the upstream {@link MediaPeriod}.
|
||||||
*
|
*
|
||||||
|
@ -342,6 +342,11 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
/* throwable= */ null);
|
/* throwable= */ null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAudioDecoderReleased(EventTime eventTime, String decoderName) {
|
||||||
|
logd(eventTime, "audioDecoderReleased", decoderName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAudioDisabled(EventTime eventTime, DecoderCounters counters) {
|
public void onAudioDisabled(EventTime eventTime, DecoderCounters counters) {
|
||||||
logd(eventTime, "audioDisabled");
|
logd(eventTime, "audioDisabled");
|
||||||
@ -397,6 +402,11 @@ public class EventLogger implements AnalyticsListener {
|
|||||||
logd(eventTime, "droppedFrames", Integer.toString(count));
|
logd(eventTime, "droppedFrames", Integer.toString(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVideoDecoderReleased(EventTime eventTime, String decoderName) {
|
||||||
|
logd(eventTime, "videoDecoderReleased", decoderName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVideoDisabled(EventTime eventTime, DecoderCounters counters) {
|
public void onVideoDisabled(EventTime eventTime, DecoderCounters counters) {
|
||||||
logd(eventTime, "videoDisabled");
|
logd(eventTime, "videoDisabled");
|
||||||
|
@ -311,22 +311,6 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
|
|||||||
super.onStreamChanged(formats, startPositionUs, offsetUs);
|
super.onStreamChanged(formats, startPositionUs, offsetUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a decoder has been created and configured.
|
|
||||||
*
|
|
||||||
* <p>The default implementation is a no-op.
|
|
||||||
*
|
|
||||||
* @param name The name of the decoder that was initialized.
|
|
||||||
* @param initializedTimestampMs {@link SystemClock#elapsedRealtime()} when initialization
|
|
||||||
* finished.
|
|
||||||
* @param initializationDurationMs The time taken to initialize the decoder, in milliseconds.
|
|
||||||
*/
|
|
||||||
@CallSuper
|
|
||||||
protected void onDecoderInitialized(
|
|
||||||
String name, long initializedTimestampMs, long initializationDurationMs) {
|
|
||||||
eventDispatcher.decoderInitialized(name, initializedTimestampMs, initializationDurationMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flushes the decoder.
|
* Flushes the decoder.
|
||||||
*
|
*
|
||||||
@ -358,9 +342,10 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
|
|||||||
decoderReceivedBuffers = false;
|
decoderReceivedBuffers = false;
|
||||||
buffersInCodecCount = 0;
|
buffersInCodecCount = 0;
|
||||||
if (decoder != null) {
|
if (decoder != null) {
|
||||||
decoder.release();
|
|
||||||
decoder = null;
|
|
||||||
decoderCounters.decoderReleaseCount++;
|
decoderCounters.decoderReleaseCount++;
|
||||||
|
decoder.release();
|
||||||
|
eventDispatcher.decoderReleased(decoder.getName());
|
||||||
|
decoder = null;
|
||||||
}
|
}
|
||||||
setDecoderDrmSession(null);
|
setDecoderDrmSession(null);
|
||||||
}
|
}
|
||||||
@ -690,7 +675,7 @@ public abstract class DecoderVideoRenderer extends BaseRenderer {
|
|||||||
decoder = createDecoder(inputFormat, mediaCrypto);
|
decoder = createDecoder(inputFormat, mediaCrypto);
|
||||||
setDecoderOutputMode(outputMode);
|
setDecoderOutputMode(outputMode);
|
||||||
long decoderInitializedTimestamp = SystemClock.elapsedRealtime();
|
long decoderInitializedTimestamp = SystemClock.elapsedRealtime();
|
||||||
onDecoderInitialized(
|
eventDispatcher.decoderInitialized(
|
||||||
decoder.getName(),
|
decoder.getName(),
|
||||||
decoderInitializedTimestamp,
|
decoderInitializedTimestamp,
|
||||||
decoderInitializedTimestamp - decoderInitializingTimestamp);
|
decoderInitializedTimestamp - decoderInitializingTimestamp);
|
||||||
|
@ -616,6 +616,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
Assertions.checkNotNull(getCodecInfo()).isHdr10PlusOutOfBandMetadataSupported();
|
Assertions.checkNotNull(getCodecInfo()).isHdr10PlusOutOfBandMetadataSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCodecReleased(String name) {
|
||||||
|
eventDispatcher.decoderReleased(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
|
||||||
super.onInputFormatChanged(formatHolder);
|
super.onInputFormatChanged(formatHolder);
|
||||||
|
@ -120,6 +120,13 @@ public interface VideoRendererEventListener {
|
|||||||
*/
|
*/
|
||||||
default void onRenderedFirstFrame(@Nullable Surface surface) {}
|
default void onRenderedFirstFrame(@Nullable Surface surface) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a decoder is released.
|
||||||
|
*
|
||||||
|
* @param decoderName The decoder that was released.
|
||||||
|
*/
|
||||||
|
default void onVideoDecoderReleased(String decoderName) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the renderer is disabled.
|
* Called when the renderer is disabled.
|
||||||
*
|
*
|
||||||
@ -211,6 +218,13 @@ public interface VideoRendererEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Invokes {@link VideoRendererEventListener#onVideoDecoderReleased(String)}. */
|
||||||
|
public void decoderReleased(String decoderName) {
|
||||||
|
if (handler != null) {
|
||||||
|
handler.post(() -> castNonNull(listener).onVideoDecoderReleased(decoderName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Invokes {@link VideoRendererEventListener#onVideoDisabled(DecoderCounters)}. */
|
/** Invokes {@link VideoRendererEventListener#onVideoDisabled(DecoderCounters)}. */
|
||||||
public void disabled(DecoderCounters counters) {
|
public void disabled(DecoderCounters counters) {
|
||||||
counters.ensureUpdated();
|
counters.ensureUpdated();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user