mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
Set VideoSink listener when enabling MCVR
Before, the listener was set in onReadyToInitializeCodec, which means that it was reset every time a new codec was used. We need to set the listener every time MCVR is enabled (not only the first time), because it might have been set by another renderer. PiperOrigin-RevId: 641825717
This commit is contained in:
parent
82970a6861
commit
2c71150f2b
@ -640,6 +640,40 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
|
|||||||
hasSetShouldUseVideoSink = true;
|
hasSetShouldUseVideoSink = true;
|
||||||
}
|
}
|
||||||
if (shouldUseVideoSink) {
|
if (shouldUseVideoSink) {
|
||||||
|
videoSink.setListener(
|
||||||
|
new VideoSink.Listener() {
|
||||||
|
@Override
|
||||||
|
public void onFirstFrameRendered(VideoSink videoSink) {
|
||||||
|
checkStateNotNull(displaySurface);
|
||||||
|
notifyRenderedFirstFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFrameDropped(VideoSink videoSink) {
|
||||||
|
updateDroppedBufferCounters(
|
||||||
|
/* droppedInputBufferCount= */ 0, /* droppedDecoderBufferCount= */ 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVideoSizeChanged(VideoSink videoSink, VideoSize videoSize) {
|
||||||
|
// TODO: b/292111083 - Report video size change to app. Video size reporting is
|
||||||
|
// removed at the moment to ensure the first frame is rendered, and the video is
|
||||||
|
// rendered after switching on/off the screen.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(
|
||||||
|
VideoSink videoSink, VideoSink.VideoSinkException videoSinkException) {
|
||||||
|
setPendingPlaybackException(
|
||||||
|
createRendererException(
|
||||||
|
videoSinkException,
|
||||||
|
videoSinkException.format,
|
||||||
|
PlaybackException.ERROR_CODE_VIDEO_FRAME_PROCESSING_FAILED));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Pass a direct executor since the callback handling involves posting on the app looper
|
||||||
|
// again, so there's no need to do two hops.
|
||||||
|
directExecutor());
|
||||||
videoSink.onRendererEnabled(mayRenderStartOfStream);
|
videoSink.onRendererEnabled(mayRenderStartOfStream);
|
||||||
} else {
|
} else {
|
||||||
videoFrameReleaseControl.onEnabled(mayRenderStartOfStream);
|
videoFrameReleaseControl.onEnabled(mayRenderStartOfStream);
|
||||||
@ -1065,49 +1099,13 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
|
|||||||
@CallSuper
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
protected void onReadyToInitializeCodec(Format format) throws ExoPlaybackException {
|
protected void onReadyToInitializeCodec(Format format) throws ExoPlaybackException {
|
||||||
if (shouldUseVideoSink) {
|
if (shouldUseVideoSink && !videoSink.isInitialized()) {
|
||||||
if (!videoSink.isInitialized()) {
|
try {
|
||||||
try {
|
videoSink.initialize(format, getClock());
|
||||||
videoSink.initialize(format, getClock());
|
} catch (VideoSink.VideoSinkException e) {
|
||||||
} catch (VideoSink.VideoSinkException e) {
|
throw createRendererException(
|
||||||
throw createRendererException(
|
e, format, PlaybackException.ERROR_CODE_VIDEO_FRAME_PROCESSOR_INIT_FAILED);
|
||||||
e, format, PlaybackException.ERROR_CODE_VIDEO_FRAME_PROCESSOR_INIT_FAILED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
videoSink.setListener(
|
|
||||||
new VideoSink.Listener() {
|
|
||||||
@Override
|
|
||||||
public void onFirstFrameRendered(VideoSink videoSink) {
|
|
||||||
checkStateNotNull(displaySurface);
|
|
||||||
notifyRenderedFirstFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFrameDropped(VideoSink videoSink) {
|
|
||||||
updateDroppedBufferCounters(
|
|
||||||
/* droppedInputBufferCount= */ 0, /* droppedDecoderBufferCount= */ 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onVideoSizeChanged(VideoSink videoSink, VideoSize videoSize) {
|
|
||||||
// TODO: b/292111083 - Report video size change to app. Video size reporting is
|
|
||||||
// removed at the moment to ensure the first frame is rendered, and the video is
|
|
||||||
// rendered after switching on/off the screen.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(
|
|
||||||
VideoSink videoSink, VideoSink.VideoSinkException videoSinkException) {
|
|
||||||
setPendingPlaybackException(
|
|
||||||
createRendererException(
|
|
||||||
videoSinkException,
|
|
||||||
videoSinkException.format,
|
|
||||||
PlaybackException.ERROR_CODE_VIDEO_FRAME_PROCESSING_FAILED));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Pass a direct executor since the callback handling involves posting on the app looper
|
|
||||||
// again, so there's no need to do two hops.
|
|
||||||
directExecutor());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user