mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08: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
This commit is contained in:
parent
4c73241058
commit
ccab9fba03
@ -28,7 +28,6 @@ import androidx.media3.common.FrameProcessingException;
|
||||
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;
|
||||
@ -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();
|
||||
|
@ -107,6 +107,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();
|
||||
|
||||
@ -170,9 +173,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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user