88import androidx .annotation .GuardedBy ;
99import androidx .annotation .NonNull ;
1010
11- import com .otaliastudios .opengl .draw .EglDrawable ;
12- import com .otaliastudios .opengl .draw .EglRect ;
13- import com .otaliastudios .opengl .program .EglTextureProgram ;
14- import com .otaliastudios .opengl .scene .EglScene ;
11+ import com .otaliastudios .opengl .draw .GlRect ;
12+ import com .otaliastudios .opengl .program .GlTextureProgram ;
1513import com .otaliastudios .transcoder .internal .Logger ;
1614
1715/**
@@ -36,17 +34,13 @@ public class VideoDecoderOutput {
3634 private SurfaceTexture mSurfaceTexture ;
3735 private Surface mSurface ;
3836
39- private EglScene mScene ;
40- private EglTextureProgram mProgram ;
41- private EglDrawable mDrawable ;
37+ private GlTextureProgram mProgram ;
38+ private GlRect mDrawable ;
4239
4340 private float mScaleX = 1F ;
4441 private float mScaleY = 1F ;
4542 private int mRotation = 0 ;
4643
47- private int mTextureId ;
48- private float [] mTextureTransform = new float [16 ];
49-
5044 @ GuardedBy ("mFrameAvailableLock" )
5145 private boolean mFrameAvailable ;
5246 private final Object mFrameAvailableLock = new Object ();
@@ -56,16 +50,14 @@ public class VideoDecoderOutput {
5650 * new one). Creates a Surface that can be passed to MediaCodec.configure().
5751 */
5852 public VideoDecoderOutput () {
59- mScene = new EglScene ();
60- mProgram = new EglTextureProgram ();
61- mDrawable = new EglRect ();
62- mTextureId = mProgram .createTexture ();
53+ mProgram = new GlTextureProgram ();
54+ mDrawable = new GlRect ();
6355
6456 // Even if we don't access the SurfaceTexture after the constructor returns, we
6557 // still need to keep a reference to it. The Surface doesn't retain a reference
6658 // at the Java level, so if we don't either then the object can get GCed, which
6759 // causes the native finalizer to run.
68- mSurfaceTexture = new SurfaceTexture (mTextureId );
60+ mSurfaceTexture = new SurfaceTexture (mProgram . getTextureId () );
6961 mSurfaceTexture .setOnFrameAvailableListener (new SurfaceTexture .OnFrameAvailableListener () {
7062 @ Override
7163 public void onFrameAvailable (SurfaceTexture surfaceTexture ) {
@@ -123,7 +115,6 @@ public void release() {
123115 mSurfaceTexture = null ;
124116 mDrawable = null ;
125117 mProgram = null ;
126- mScene = null ;
127118 }
128119
129120 /**
@@ -166,21 +157,21 @@ private void awaitNewFrame() {
166157 * Draws the data from SurfaceTexture onto the current EGL surface.
167158 */
168159 private void drawNewFrame () {
169- mSurfaceTexture .getTransformMatrix (mTextureTransform );
160+ mSurfaceTexture .getTransformMatrix (mProgram . getTextureTransform () );
170161 // Invert the scale.
171162 float glScaleX = 1F / mScaleX ;
172163 float glScaleY = 1F / mScaleY ;
173164 // Compensate before scaling.
174165 float glTranslX = (1F - glScaleX ) / 2F ;
175166 float glTranslY = (1F - glScaleY ) / 2F ;
176- Matrix .translateM (mTextureTransform , 0 , glTranslX , glTranslY , 0 );
167+ Matrix .translateM (mProgram . getTextureTransform () , 0 , glTranslX , glTranslY , 0 );
177168 // Scale.
178- Matrix .scaleM (mTextureTransform , 0 , glScaleX , glScaleY , 1 );
169+ Matrix .scaleM (mProgram . getTextureTransform () , 0 , glScaleX , glScaleY , 1 );
179170 // Apply rotation.
180- Matrix .translateM (mTextureTransform , 0 , 0.5F , 0.5F , 0 );
181- Matrix .rotateM (mTextureTransform , 0 , mRotation , 0 , 0 , 1 );
182- Matrix .translateM (mTextureTransform , 0 , -0.5F , -0.5F , 0 );
171+ Matrix .translateM (mProgram . getTextureTransform () , 0 , 0.5F , 0.5F , 0 );
172+ Matrix .rotateM (mProgram . getTextureTransform () , 0 , mRotation , 0 , 0 , 1 );
173+ Matrix .translateM (mProgram . getTextureTransform () , 0 , -0.5F , -0.5F , 0 );
183174 // Draw.
184- mScene . drawTexture (mDrawable , mProgram , mTextureId , mTextureTransform );
175+ mProgram . draw (mDrawable );
185176 }
186177}
0 commit comments