mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Update GlObjectsProvider to cover creating surface.
PiperOrigin-RevId: 516300480
This commit is contained in:
parent
bc873536f3
commit
82c9479dd2
3 changed files with 54 additions and 10 deletions
|
|
@ -18,6 +18,7 @@ package androidx.media3.common;
|
|||
|
||||
import android.opengl.EGLContext;
|
||||
import android.opengl.EGLDisplay;
|
||||
import android.opengl.EGLSurface;
|
||||
import androidx.annotation.IntRange;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.media3.common.util.GlUtil;
|
||||
|
|
@ -41,6 +42,26 @@ public interface GlObjectsProvider {
|
|||
return GlUtil.createEglContext(eglDisplay, openGlVersion, configAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequiresApi(17)
|
||||
public EGLSurface createEglSurface(
|
||||
EGLDisplay eglDisplay,
|
||||
Object surface,
|
||||
@C.ColorTransfer int colorTransfer,
|
||||
boolean isEncoderInputSurface)
|
||||
throws GlException {
|
||||
return GlUtil.createEglSurface(eglDisplay, surface, colorTransfer, isEncoderInputSurface);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequiresApi(17)
|
||||
public EGLSurface createFocusedPlaceholderEglSurface(
|
||||
EGLContext eglContext, EGLDisplay eglDisplay, int[] configAttributes)
|
||||
throws GlException {
|
||||
return GlUtil.createFocusedPlaceholderEglSurface(
|
||||
eglContext, eglDisplay, configAttributes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlTextureInfo createBuffersForTexture(int texId, int width, int height)
|
||||
throws GlException {
|
||||
|
|
@ -68,6 +89,23 @@ public interface GlObjectsProvider {
|
|||
EGLDisplay eglDisplay, @IntRange(from = 2, to = 3) int openGlVersion, int[] configAttributes)
|
||||
throws GlException;
|
||||
|
||||
// TODO(b/271433904): Remove default implementations once photos have implemented these methods.
|
||||
@RequiresApi(17)
|
||||
default EGLSurface createEglSurface(
|
||||
EGLDisplay eglDisplay,
|
||||
Object surface,
|
||||
@C.ColorTransfer int colorTransfer,
|
||||
boolean isEncoderInputSurface)
|
||||
throws GlException {
|
||||
return GlUtil.createEglSurface(eglDisplay, surface, colorTransfer, isEncoderInputSurface);
|
||||
}
|
||||
|
||||
@RequiresApi(17)
|
||||
default EGLSurface createFocusedPlaceholderEglSurface(
|
||||
EGLContext eglContext, EGLDisplay eglDisplay, int[] configAttributes) throws GlException {
|
||||
return GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link GlTextureInfo} containing the identifiers of the newly created buffers.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
|||
ColorInfo.isTransferHdr(inputColorInfo) || ColorInfo.isTransferHdr(outputColorInfo) ? 3 : 2;
|
||||
EGLContext eglContext =
|
||||
glObjectsProvider.createEglContext(eglDisplay, openGlVersion, configAttributes);
|
||||
GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes);
|
||||
glObjectsProvider.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes);
|
||||
|
||||
// Not releaseFramesAutomatically means outputting to a display surface. HDR display surfaces
|
||||
// require the BT2020 PQ GL extension.
|
||||
|
|
@ -424,7 +424,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
|||
isInputTextureExternal,
|
||||
releaseFramesAutomatically,
|
||||
executor,
|
||||
listener);
|
||||
listener,
|
||||
glObjectsProvider);
|
||||
setGlObjectProviderOnShaderPrograms(shaderPrograms, glObjectsProvider);
|
||||
VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor =
|
||||
new VideoFrameProcessingTaskExecutor(singleThreadExecutorService, listener);
|
||||
|
|
@ -462,7 +463,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
|||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
Executor executor,
|
||||
Listener listener)
|
||||
Listener listener,
|
||||
GlObjectsProvider glObjectsProvider)
|
||||
throws VideoFrameProcessingException {
|
||||
ImmutableList.Builder<GlShaderProgram> shaderProgramListBuilder = new ImmutableList.Builder<>();
|
||||
ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder =
|
||||
|
|
@ -535,7 +537,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
|||
isInputTextureExternal,
|
||||
releaseFramesAutomatically,
|
||||
executor,
|
||||
listener));
|
||||
listener,
|
||||
glObjectsProvider));
|
||||
return shaderProgramListBuilder.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
boolean isInputTextureExternal,
|
||||
boolean releaseFramesAutomatically,
|
||||
Executor videoFrameProcessorListenerExecutor,
|
||||
VideoFrameProcessor.Listener videoFrameProcessorListener) {
|
||||
VideoFrameProcessor.Listener videoFrameProcessorListener,
|
||||
GlObjectsProvider glObjectsProvider) {
|
||||
this.context = context;
|
||||
this.matrixTransformations = matrixTransformations;
|
||||
this.rgbMatrices = rgbMatrices;
|
||||
|
|
@ -130,10 +131,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
this.releaseFramesAutomatically = releaseFramesAutomatically;
|
||||
this.videoFrameProcessorListenerExecutor = videoFrameProcessorListenerExecutor;
|
||||
this.videoFrameProcessorListener = videoFrameProcessorListener;
|
||||
this.glObjectsProvider = glObjectsProvider;
|
||||
|
||||
textureTransformMatrix = GlUtil.create4x4IdentityMatrix();
|
||||
streamOffsetUsQueue = new ConcurrentLinkedQueue<>();
|
||||
glObjectsProvider = GlObjectsProvider.DEFAULT;
|
||||
inputListener = new InputListener() {};
|
||||
availableFrames = new ConcurrentLinkedQueue<>();
|
||||
}
|
||||
|
|
@ -375,7 +376,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
@Nullable EGLSurface outputEglSurface = this.outputEglSurface;
|
||||
if (outputEglSurface == null) {
|
||||
outputEglSurface =
|
||||
GlUtil.createEglSurface(
|
||||
glObjectsProvider.createEglSurface(
|
||||
eglDisplay,
|
||||
outputSurfaceInfo.surface,
|
||||
outputColorInfo.colorTransfer,
|
||||
|
|
@ -472,7 +473,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
checkNotNull(debugSurfaceViewWrapper).outputColorTransfer);
|
||||
defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs);
|
||||
defaultShaderProgram.setOutputColorTransfer(configuredColorTransfer);
|
||||
});
|
||||
},
|
||||
glObjectsProvider);
|
||||
} catch (VideoFrameProcessingException | GlUtil.GlException e) {
|
||||
Log.d(TAG, "Error rendering to debug preview", e);
|
||||
}
|
||||
|
|
@ -546,7 +548,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
*
|
||||
* <p>Must be called on the GL thread.
|
||||
*/
|
||||
public synchronized void maybeRenderToSurfaceView(VideoFrameProcessingTask renderingTask)
|
||||
public synchronized void maybeRenderToSurfaceView(
|
||||
VideoFrameProcessingTask renderingTask, GlObjectsProvider glObjectsProvider)
|
||||
throws GlUtil.GlException, VideoFrameProcessingException {
|
||||
if (surface == null) {
|
||||
return;
|
||||
|
|
@ -554,7 +557,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
|
||||
if (eglSurface == null) {
|
||||
eglSurface =
|
||||
GlUtil.createEglSurface(
|
||||
glObjectsProvider.createEglSurface(
|
||||
eglDisplay, surface, outputColorTransfer, /* isEncoderInputSurface= */ false);
|
||||
}
|
||||
EGLSurface eglSurface = this.eglSurface;
|
||||
|
|
|
|||
Loading…
Reference in a new issue