mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Move VideoSink config to dedicated method
This is to improve readability of MediaCodecVideoRenderer.onEnabled PiperOrigin-RevId: 742246092
This commit is contained in:
parent
25c1760b17
commit
f8b1dcc33b
@ -881,62 +881,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
|
|||||||
// Configure the VideoSink every time the renderer is enabled, in case the parameters have
|
// Configure the VideoSink every time the renderer is enabled, in case the parameters have
|
||||||
// been overridden by another renderer. Also configure the VideoSink with the parameters that
|
// been overridden by another renderer. Also configure the VideoSink with the parameters that
|
||||||
// have been set on the renderer before creating the VideoSink.
|
// have been set on the renderer before creating the VideoSink.
|
||||||
videoSink.setListener(
|
configureVideoSink();
|
||||||
new VideoSink.Listener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFrameAvailableForRendering() {
|
|
||||||
@Nullable WakeupListener wakeupListener = getWakeupListener();
|
|
||||||
if (wakeupListener != null) {
|
|
||||||
wakeupListener.onWakeup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFirstFrameRendered() {
|
|
||||||
if (displaySurface != null) {
|
|
||||||
notifyRenderedFirstFrame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFrameDropped() {
|
|
||||||
if (displaySurface != null) {
|
|
||||||
updateDroppedBufferCounters(
|
|
||||||
/* droppedInputBufferCount= */ 0, /* droppedDecoderBufferCount= */ 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onVideoSizeChanged(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.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());
|
|
||||||
if (frameMetadataListener != null) {
|
|
||||||
videoSink.setVideoFrameMetadataListener(frameMetadataListener);
|
|
||||||
}
|
|
||||||
if (displaySurface != null && !outputResolution.equals(Size.UNKNOWN)) {
|
|
||||||
videoSink.setOutputSurfaceInfo(displaySurface, outputResolution);
|
|
||||||
}
|
|
||||||
videoSink.setChangeFrameRateStrategy(changeFrameRateStrategy);
|
|
||||||
videoSink.setPlaybackSpeed(getPlaybackSpeed());
|
|
||||||
if (videoEffects != null) {
|
|
||||||
videoSink.setVideoEffects(videoEffects);
|
|
||||||
}
|
|
||||||
nextVideoSinkFirstFrameReleaseInstruction =
|
nextVideoSinkFirstFrameReleaseInstruction =
|
||||||
mayRenderStartOfStream
|
mayRenderStartOfStream
|
||||||
? RELEASE_FIRST_FRAME_IMMEDIATELY
|
? RELEASE_FIRST_FRAME_IMMEDIATELY
|
||||||
@ -952,6 +897,66 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresNonNull("videoSink")
|
||||||
|
private void configureVideoSink() {
|
||||||
|
videoSink.setListener(
|
||||||
|
new VideoSink.Listener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFrameAvailableForRendering() {
|
||||||
|
@Nullable WakeupListener wakeupListener = getWakeupListener();
|
||||||
|
if (wakeupListener != null) {
|
||||||
|
wakeupListener.onWakeup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFirstFrameRendered() {
|
||||||
|
if (displaySurface != null) {
|
||||||
|
notifyRenderedFirstFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFrameDropped() {
|
||||||
|
if (displaySurface != null) {
|
||||||
|
updateDroppedBufferCounters(
|
||||||
|
/* droppedInputBufferCount= */ 0, /* droppedDecoderBufferCount= */ 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onVideoSizeChanged(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.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());
|
||||||
|
if (frameMetadataListener != null) {
|
||||||
|
videoSink.setVideoFrameMetadataListener(frameMetadataListener);
|
||||||
|
}
|
||||||
|
if (displaySurface != null && !outputResolution.equals(Size.UNKNOWN)) {
|
||||||
|
videoSink.setOutputSurfaceInfo(displaySurface, outputResolution);
|
||||||
|
}
|
||||||
|
videoSink.setChangeFrameRateStrategy(changeFrameRateStrategy);
|
||||||
|
videoSink.setPlaybackSpeed(getPlaybackSpeed());
|
||||||
|
if (videoEffects != null) {
|
||||||
|
videoSink.setVideoEffects(videoEffects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Creates a {@link PlaybackVideoGraphWrapper} instance. */
|
/** Creates a {@link PlaybackVideoGraphWrapper} instance. */
|
||||||
protected PlaybackVideoGraphWrapper createPlaybackVideoGraphWrapper(
|
protected PlaybackVideoGraphWrapper createPlaybackVideoGraphWrapper(
|
||||||
Context context, VideoFrameReleaseControl videoFrameReleaseControl) {
|
Context context, VideoFrameReleaseControl videoFrameReleaseControl) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user