Skip to content

Commit

Permalink
Add a FrameProcessor flag to drop the processed frame
Browse files Browse the repository at this point in the history
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
  • Loading branch information
claincly authored and marcbaechinger committed Oct 20, 2022
1 parent 4c73241 commit ccab9fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import androidx.media3.common.FrameProcessor;
import androidx.media3.common.SurfaceInfo;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.ColorInfo;
Expand Down Expand Up @@ -180,15 +179,15 @@ public void controlledFrameRelease_withLateFrame_dropsFrame() throws Exception {
}

@Test
public void controlledFrameRelease_withUnsetReleaseTime_dropsFrame() throws Exception {
public void controlledFrameRelease_requestsFrameDropping_dropsFrame() throws Exception {
long originalPresentationTimeUs = 1234;
AtomicLong actualPresentationTimeUs = new AtomicLong();
setupGlEffectsFrameProcessorWithBlankFrameProducer(
/* inputPresentationTimesUs= */ new long[] {originalPresentationTimeUs},
/* onFrameAvailableListener= */ presentationTimeNs -> {
actualPresentationTimeUs.set(presentationTimeNs);
checkNotNull(glEffectsFrameProcessor)
.releaseOutputFrame(/* releaseTimeNs= */ C.TIME_UNSET);
.releaseOutputFrame(FrameProcessor.DROP_OUTPUT_FRAME);
},
/* releaseFramesAutomatically= */ false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ public void releaseOutputFrame(long releaseTimeNs) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ interface Listener {
*/
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();

Expand Down Expand Up @@ -170,9 +173,9 @@ interface Listener {
* {@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);

Expand Down

0 comments on commit ccab9fb

Please sign in to comment.