From 0b9180aa4ff399ca3fedf96280025f2d408d0303 Mon Sep 17 00:00:00 2001 From: kimvde Date: Thu, 11 Apr 2024 00:51:55 -0700 Subject: [PATCH] Clean-ups in VideoSinkProvider Javadoc PiperOrigin-RevId: 623737397 --- .../video/CompositingVideoSinkProvider.java | 98 ++++++++--------- .../exoplayer/video/VideoSinkProvider.java | 103 +++++++++--------- 2 files changed, 98 insertions(+), 103 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java index fdeb2e2345..6111657e91 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/CompositingVideoSinkProvider.java @@ -241,6 +241,42 @@ public final class CompositingVideoSinkProvider // VideoSinkProvider methods + @Override + public void setVideoFrameReleaseControl(VideoFrameReleaseControl videoFrameReleaseControl) { + checkState(!isInitialized()); + this.videoFrameReleaseControl = videoFrameReleaseControl; + videoFrameRenderControl = + new VideoFrameRenderControl(/* frameRenderer= */ this, videoFrameReleaseControl); + } + + @Override + @Nullable + public VideoFrameReleaseControl getVideoFrameReleaseControl() { + return videoFrameReleaseControl; + } + + @Override + public void setClock(Clock clock) { + checkState(!isInitialized()); + this.clock = clock; + } + + @Override + public void setVideoEffects(List videoEffects) { + this.videoEffects = videoEffects; + if (isInitialized()) { + checkStateNotNull(videoSinkImpl).setVideoEffects(videoEffects); + } + } + + @Override + public void setPendingVideoEffects(List videoEffects) { + this.videoEffects = videoEffects; + if (isInitialized()) { + checkStateNotNull(videoSinkImpl).setPendingVideoEffects(videoEffects); + } + } + @Override public void initialize(Format sourceFormat) throws VideoSink.VideoSinkException { checkState(state == STATE_CREATED); @@ -291,44 +327,11 @@ public final class CompositingVideoSinkProvider return state == STATE_INITIALIZED; } - @Override - public void release() { - if (state == STATE_RELEASED) { - return; - } - - if (handler != null) { - handler.removeCallbacksAndMessages(/* token= */ null); - } - - if (videoGraph != null) { - videoGraph.release(); - } - currentSurfaceAndSize = null; - state = STATE_RELEASED; - } - @Override public VideoSink getSink() { return checkStateNotNull(videoSinkImpl); } - @Override - public void setVideoEffects(List videoEffects) { - this.videoEffects = videoEffects; - if (isInitialized()) { - checkStateNotNull(videoSinkImpl).setVideoEffects(videoEffects); - } - } - - @Override - public void setPendingVideoEffects(List videoEffects) { - this.videoEffects = videoEffects; - if (isInitialized()) { - checkStateNotNull(videoSinkImpl).setPendingVideoEffects(videoEffects); - } - } - @Override public void setStreamOffsetUs(long streamOffsetUs) { checkStateNotNull(videoSinkImpl).setStreamOffsetUs(streamOffsetUs); @@ -346,14 +349,6 @@ public final class CompositingVideoSinkProvider outputSurface, outputResolution.getWidth(), outputResolution.getHeight()); } - @Override - public void setVideoFrameReleaseControl(VideoFrameReleaseControl videoFrameReleaseControl) { - checkState(!isInitialized()); - this.videoFrameReleaseControl = videoFrameReleaseControl; - videoFrameRenderControl = - new VideoFrameRenderControl(/* frameRenderer= */ this, videoFrameReleaseControl); - } - @Override public void clearOutputSurfaceInfo() { maybeSetOutputSurfaceInfo( @@ -369,15 +364,20 @@ public final class CompositingVideoSinkProvider } @Override - @Nullable - public VideoFrameReleaseControl getVideoFrameReleaseControl() { - return videoFrameReleaseControl; - } + public void release() { + if (state == STATE_RELEASED) { + return; + } - @Override - public void setClock(Clock clock) { - checkState(!isInitialized()); - this.clock = clock; + if (handler != null) { + handler.removeCallbacksAndMessages(/* token= */ null); + } + + if (videoGraph != null) { + videoGraph.release(); + } + currentSurfaceAndSize = null; + state = STATE_RELEASED; } // VideoGraph.Listener diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/VideoSinkProvider.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/VideoSinkProvider.java index 63fc19a0e2..2bc65552b0 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/VideoSinkProvider.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/VideoSinkProvider.java @@ -29,67 +29,14 @@ import org.checkerframework.checker.nullness.qual.Nullable; @UnstableApi public interface VideoSinkProvider { - /** - * Initializes the provider for video frame processing. Can be called up to one time and only - * after video effects are {@linkplain #setVideoEffects(List) set}. - * - * @param sourceFormat The format of the compressed video. - * @throws VideoSink.VideoSinkException If enabling the provider failed. - */ - void initialize(Format sourceFormat) throws VideoSink.VideoSinkException; - - /** Returns whether this provider is initialized for frame processing. */ - boolean isInitialized(); - - /** Releases the sink provider. */ - void release(); - - /** Returns a {@link VideoSink} to forward video frames for processing. */ - VideoSink getSink(); - - /** Sets video effects on this provider to apply immediately. */ - void setVideoEffects(List videoEffects); - - /** - * Sets video effects on this provider to apply when the next stream is {@linkplain - * VideoSink#registerInputStream(int, Format) registered} on the {@link #getSink() VideoSink}. - */ - void setPendingVideoEffects(List videoEffects); - - /** - * Sets the offset, in microseconds, that is added to the video frames presentation timestamps - * from the player. - * - *

Must be called after the sink provider is {@linkplain #initialize(Format) initialized}. - */ - void setStreamOffsetUs(long streamOffsetUs); - - /** - * Sets the output surface info. - * - *

Must be called after the sink provider is {@linkplain #initialize(Format) initialized}. - */ - void setOutputSurfaceInfo(Surface outputSurface, Size outputResolution); - /** * Sets the {@link VideoFrameReleaseControl} that will be used for releasing of video frames * during rendering. * - *

Must be called before, not after, the sink provider is {@linkplain #initialize(Format) - * initialized}. + *

Must be called before the sink provider is {@linkplain #initialize(Format) initialized}. */ void setVideoFrameReleaseControl(VideoFrameReleaseControl videoFrameReleaseControl); - /** - * Clears the set output surface info. - * - *

Must be called after the sink provider is {@linkplain #initialize(Format) initialized}. - */ - void clearOutputSurfaceInfo(); - - /** Sets a {@link VideoFrameMetadataListener} which is used in the returned {@link VideoSink}. */ - void setVideoFrameMetadataListener(VideoFrameMetadataListener videoFrameMetadataListener); - /** * Returns the {@link VideoFrameReleaseControl} that will be used for releasing of video frames * during rendering. @@ -105,4 +52,52 @@ public interface VideoSinkProvider { *

Must be called before the sink provider is {@linkplain #initialize(Format) initialized}. */ void setClock(Clock clock); + + /** Sets video effects on this provider to apply immediately. */ + void setVideoEffects(List videoEffects); + + /** + * Sets video effects on this provider to apply when the next stream is {@linkplain + * VideoSink#registerInputStream(int, Format) registered} on the {@link #getSink() VideoSink}. + */ + void setPendingVideoEffects(List videoEffects); + + /** + * Initializes the provider for video frame processing. Can be called up to one time and only + * after video effects are {@linkplain #setVideoEffects(List) set}. + * + * @param sourceFormat The format of the compressed video. + * @throws VideoSink.VideoSinkException If enabling the provider failed. + */ + void initialize(Format sourceFormat) throws VideoSink.VideoSinkException; + + /** Returns whether this provider is initialized for frame processing. */ + boolean isInitialized(); + + /** + * Returns a {@link VideoSink} to forward video frames for processing. + * + *

Must be called after the sink provider is {@linkplain #initialize(Format) initialized}. + */ + VideoSink getSink(); + + /** + * Sets the offset, in microseconds, that is added to the video frames presentation timestamps + * from the player. + * + *

Must be called after the sink provider is {@linkplain #initialize(Format) initialized}. + */ + void setStreamOffsetUs(long streamOffsetUs); + + /** Sets the output surface info. */ + void setOutputSurfaceInfo(Surface outputSurface, Size outputResolution); + + /** Clears the set output surface info. */ + void clearOutputSurfaceInfo(); + + /** Sets a {@link VideoFrameMetadataListener} which is used in the returned {@link VideoSink}. */ + void setVideoFrameMetadataListener(VideoFrameMetadataListener videoFrameMetadataListener); + + /** Releases the sink provider. */ + void release(); }