Skip to content

Commit

Permalink
Rollback of androidx@a66f08b
Browse files Browse the repository at this point in the history
*** Original commit ***

Add a timer to end a video stream prematurely in ExtTexMgr

***

This has been submitting for more than 1.5hrs. "This presubmit is running slowly because you have been throttled by Build Queue due to using too much of your Product Area's quota."

adding NO_SQ as this is a pure rollback

PiperOrigin-RevId: 539135970
  • Loading branch information
Googler authored and tof-tof committed Jun 9, 2023
1 parent db3e662 commit 5c29abb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ interface Listener {
* <p>Call {@link #setInputFrameInfo} before this method if the {@link FrameInfo} of the new input
* stream differs from that of the current input stream.
*/
// TODO(b/286032822) Merge this and setInputFrameInfo.
// TODO(b/274109008) Merge this and setInputFrameInfo.
void registerInputStream(@InputType int inputType);

/**
Expand All @@ -219,7 +219,6 @@ interface Listener {
*
* <p>Can be called on any thread.
*/
// TODO(b/286032822) Simplify frame and stream registration.
void setInputFrameInfo(FrameInfo inputFrameInfo);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import android.graphics.SurfaceTexture;
import android.view.Surface;
Expand All @@ -27,13 +26,9 @@
import androidx.media3.common.GlTextureInfo;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import androidx.media3.effect.GlShaderProgram.InputListener;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand All @@ -42,23 +37,13 @@
*/
/* package */ final class ExternalTextureManager implements TextureManager {

private static final String TAG = "ExtTexMgr";
private static final String TIMER_THREAD_NAME = "ExtTexMgr:Timer";
/**
* The time out in milliseconds after calling signalEndOfCurrentInputStream after which the input
* stream is considered to have ended, even if not all expected frames have been received from the
* decoder. This has been observed on some decoders.
*/
private static final long SURFACE_TEXTURE_TIMEOUT_MS = 500;

private final VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor;
private final ExternalShaderProgram externalShaderProgram;
private final int externalTexId;
private final Surface surface;
private final SurfaceTexture surfaceTexture;
private final float[] textureTransformMatrix;
private final Queue<FrameInfo> pendingFrames;
private final ScheduledExecutorService forceEndOfStreamExecutorService;

// Incremented on any thread, decremented on the GL thread only.
private final AtomicInteger externalShaderProgramInputCapacity;
Expand All @@ -81,10 +66,6 @@

// TODO(b/238302341) Remove the use of after flush task, block the calling thread instead.
@Nullable private volatile VideoFrameProcessingTask onFlushCompleteTask;
@Nullable private Future<?> forceSignalEndOfStreamFuture;

// Whether to reject frames from the SurfaceTexture. Accessed only on GL thread.
private boolean shouldRejectIncomingFrames;

/**
* Creates a new instance.
Expand All @@ -110,7 +91,6 @@ public ExternalTextureManager(
surfaceTexture = new SurfaceTexture(externalTexId);
textureTransformMatrix = new float[16];
pendingFrames = new ConcurrentLinkedQueue<>();
forceEndOfStreamExecutorService = Util.newSingleThreadScheduledExecutor(TIMER_THREAD_NAME);
externalShaderProgramInputCapacity = new AtomicInteger();
surfaceTexture.setOnFrameAvailableListener(
unused ->
Expand All @@ -121,16 +101,7 @@ public ExternalTextureManager(
numberOfFramesToDropOnBecomingAvailable--;
surfaceTexture.updateTexImage();
maybeExecuteAfterFlushTask();
} else if (shouldRejectIncomingFrames) {
surfaceTexture.updateTexImage();
Log.w(
TAG,
"Dropping frame received on SurfaceTexture after forcing EOS: "
+ surfaceTexture.getTimestamp() / 1000);
} else {
if (currentInputStreamEnded) {
restartForceSignalEndOfStreamTimer();
}
availableFrameCount++;
maybeQueueFrameToExternalShaderProgram();
}
Expand Down Expand Up @@ -167,7 +138,6 @@ public void onInputFrameProcessed(GlTextureInfo inputTexture) {
currentInputStreamEnded = false;
externalShaderProgram.signalEndOfCurrentInputStream();
DebugTraceUtil.recordExternalInputManagerSignalEndOfCurrentInputStream();
cancelForceSignalEndOfStreamTimer();
} else {
maybeQueueFrameToExternalShaderProgram();
}
Expand Down Expand Up @@ -195,7 +165,6 @@ public void onFlush() {
public void registerInputFrame(FrameInfo frame) {
checkState(!inputStreamEnded);
pendingFrames.add(frame);
videoFrameProcessingTaskExecutor.submit(() -> shouldRejectIncomingFrames = false);
}

/**
Expand All @@ -216,10 +185,8 @@ public void signalEndOfCurrentInputStream() {
if (pendingFrames.isEmpty() && currentFrame == null) {
externalShaderProgram.signalEndOfCurrentInputStream();
DebugTraceUtil.recordExternalInputManagerSignalEndOfCurrentInputStream();
cancelForceSignalEndOfStreamTimer();
} else {
currentInputStreamEnded = true;
restartForceSignalEndOfStreamTimer();
}
});
}
Expand All @@ -234,7 +201,6 @@ public void signalEndOfInput() {
public void release() {
surfaceTexture.release();
surface.release();
forceEndOfStreamExecutorService.shutdownNow();
}

private void maybeExecuteAfterFlushTask() {
Expand All @@ -246,36 +212,6 @@ private void maybeExecuteAfterFlushTask() {

// Methods that must be called on the GL thread.

private void restartForceSignalEndOfStreamTimer() {
cancelForceSignalEndOfStreamTimer();
forceSignalEndOfStreamFuture =
forceEndOfStreamExecutorService.schedule(
() -> videoFrameProcessingTaskExecutor.submit(this::forceSignalEndOfStream),
SURFACE_TEXTURE_TIMEOUT_MS,
MILLISECONDS);
}

private void cancelForceSignalEndOfStreamTimer() {
if (forceSignalEndOfStreamFuture != null) {
forceSignalEndOfStreamFuture.cancel(/* mayInterruptIfRunning= */ false);
}
forceSignalEndOfStreamFuture = null;
}

private void forceSignalEndOfStream() {
// Reset because there could be further input streams after the current one ends.
Log.w(
TAG,
Util.formatInvariant(
"Forcing EOS after missing %d frames for %d ms",
pendingFrames.size(), SURFACE_TEXTURE_TIMEOUT_MS));
currentInputStreamEnded = false;
pendingFrames.clear();
currentFrame = null;
shouldRejectIncomingFrames = true;
signalEndOfCurrentInputStream();
}

private void flush() {
// A frame that is registered before flush may arrive after flush.
numberOfFramesToDropOnBecomingAvailable = pendingFrames.size() - availableFrameCount;
Expand Down

0 comments on commit 5c29abb

Please sign in to comment.