mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
Add a FrameProcessor flag to drop the processed frame
This mode is supported by using `C.TIME_UNSET` (which is a negative value). The
new logic decouples the value of `C.TIME_UNSET` and the frame dropping
behaviour.
PiperOrigin-RevId: 479368880
(cherry picked from commit 26be9ae885)
This commit is contained in:
parent
506653bbcc
commit
8b193f2bb9
3 changed files with 10 additions and 6 deletions
|
|
@ -109,6 +109,9 @@ public interface FrameProcessor {
|
|||
*/
|
||||
long RELEASE_OUTPUT_FRAME_IMMEDIATELY = -1;
|
||||
|
||||
/** Indicates the frame should be dropped after {@link #releaseOutputFrame(long)} is invoked. */
|
||||
long DROP_OUTPUT_FRAME = -2;
|
||||
|
||||
/** Returns the input {@link Surface}, where {@link FrameProcessor} consumes input frames from. */
|
||||
Surface getInputSurface();
|
||||
|
||||
|
|
@ -172,9 +175,9 @@ public interface FrameProcessor {
|
|||
* {@linkplain Listener#onOutputFrameAvailable(long) available}.
|
||||
*
|
||||
* @param releaseTimeNs The release time to use for the frame, in nanoseconds. Use {@link
|
||||
* C#TIME_UNSET} to drop the frame, or {@link #RELEASE_OUTPUT_FRAME_IMMEDIATELY} to release
|
||||
* the frame immediately. If {@code releaseTimeNs} is after {@link System#nanoTime()} at the
|
||||
* time of the release, the frame is also dropped.
|
||||
* #DROP_OUTPUT_FRAME} to drop the frame, or {@link #RELEASE_OUTPUT_FRAME_IMMEDIATELY} to
|
||||
* release the frame immediately. If {@code releaseTimeNs} is after {@link System#nanoTime()}
|
||||
* at the time of the release, the frame is also dropped.
|
||||
*/
|
||||
void releaseOutputFrame(long releaseTimeNs);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import android.graphics.PixelFormat;
|
||||
import android.media.Image;
|
||||
import android.media.ImageReader;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.ColorInfo;
|
||||
import androidx.media3.common.DebugViewProvider;
|
||||
import androidx.media3.common.FrameInfo;
|
||||
|
|
@ -180,7 +179,7 @@ public final class GlEffectsFrameProcessorFrameReleaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void controlledFrameRelease_withUnsetReleaseTime_dropsFrame() throws Exception {
|
||||
public void controlledFrameRelease_requestsFrameDropping_dropsFrame() throws Exception {
|
||||
long originalPresentationTimeUs = 1234;
|
||||
AtomicLong actualPresentationTimeUs = new AtomicLong();
|
||||
setupGlEffectsFrameProcessorWithBlankFrameProducer(
|
||||
|
|
@ -188,7 +187,7 @@ public final class GlEffectsFrameProcessorFrameReleaseTest {
|
|||
/* onFrameAvailableListener= */ presentationTimeNs -> {
|
||||
actualPresentationTimeUs.set(presentationTimeNs);
|
||||
checkNotNull(glEffectsFrameProcessor)
|
||||
.releaseOutputFrame(/* releaseTimeNs= */ C.TIME_UNSET);
|
||||
.releaseOutputFrame(FrameProcessor.DROP_OUTPUT_FRAME);
|
||||
},
|
||||
/* releaseFramesAutomatically= */ false);
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
if (releaseTimeNs == FrameProcessor.RELEASE_OUTPUT_FRAME_IMMEDIATELY) {
|
||||
dropLateFrame = false;
|
||||
releaseTimeNs = System.nanoTime();
|
||||
} else if (releaseTimeNs == FrameProcessor.DROP_OUTPUT_FRAME) {
|
||||
releaseTimeNs = C.TIME_UNSET;
|
||||
}
|
||||
|
||||
Pair<TextureInfo, Long> oldestAvailableFrame = availableFrames.remove();
|
||||
|
|
|
|||
Loading…
Reference in a new issue