Example #1
0
            public void SwapBuffers()
            {
                CheckIsNotReleased();
                if (_eglSurface == EGL14.EglNoSurface)
                {
                    throw new RuntimeException("No EGLSurface - can't swap buffers");
                }

                lock (EglBase.Lock)
                {
                    EGL14.EglSwapBuffers(_eglDisplay, _eglSurface);
                }
            }
Example #2
0
            public void SwapBuffers(long timeStampNs)
            {
                CheckIsNotReleased();
                if (_eglSurface == EGL14.EglNoSurface)
                {
                    throw new RuntimeException("No EGLSurface - can't swap buffers");
                }

                lock (EglBase.Lock)
                {
                    EGLExt.EglPresentationTimeANDROID(_eglDisplay, _eglSurface, timeStampNs);
                    EGL14.EglSwapBuffers(_eglDisplay, _eglSurface);
                }
            }
        public void AddFrame(byte[] image)
        {
            Debug.WriteLine($"Sending frame {frameIndex} to encoder");

            long presentationTime = ComputePresentationTimeNsec(frameIndex++);

            EGLExt.EglPresentationTimeANDROID(eglDisplay, eglSurface, presentationTime);
            CheckEglError();

            EGL14.EglSwapBuffers(eglDisplay, eglSurface);
            CheckEglError();

            DrainEncoder(videoEncoder, videoBufferInfo, videoTrackIndex, false);
        }
 public void swapBuffer()
 {
     EGL14.EglSwapBuffers(mEGLDisplay, mEGLSurface);
 }
 /**
  * Calls eglSwapBuffers. Use this to "publish" the current frame.
  */
 public bool SwapBuffers()
 {
     return(EGL14.EglSwapBuffers(_EGLDisplay, _EGLSurface));
 }
Example #6
0
 public override void Run()
 {
     if (mSurfaceView.mHasGLContext.Get())
     {
         return;
     }
     mEGLDisplay = EGL14.EglGetDisplay(EGL14.EglDefaultDisplay);
     int[] version = new int[2];
     EGL14.EglInitialize(mEGLDisplay, version, 0, version, 1);
     EGLConfig eglConfig = chooseEglConfig(mEGLDisplay);
     mEGLContext = EGL14
             .EglCreateContext(mEGLDisplay, eglConfig, EGL14.EglNoContext,
                     new int[] { EGL14.EglContextClientVersion, 2, EGL14.EglNone }, 0);
     int[] surfaceAttribs = {
                 EGL14.EglNone
         };
     mEGLSurface = EGL14
             .EglCreateWindowSurface(mEGLDisplay, eglConfig, mSurfaceView,
                     surfaceAttribs, 0);
     EGL14.EglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
     // guarantee to only report surface as created once GL context
     // associated with the surface has been created, and call on the GL thread
     // NOT the main thread but BEFORE the codec surface is attached to the GL context
     RendererCallbacks result;
     if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
     {
         result.onSurfaceCreated();
     }
     mSurfaceView.mMediaSurfaceCreated.Set(false);
     GLES20.GlClearColor(0.1f, 0.1f, 0.1f, 1.0f);
     mSurfaceView.mHasGLContext.Set(true);
     if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
     {
         result.onContextCreated();
     }
     mLoop.Set(true);
     while (mLoop.Get())
     {
         if (!mSurfaceView.mPaused)
         {
             bool shouldRender = false;
             //we're just rendering when requested, so check that no one
             //has requested and if not, just continue
             if (mSurfaceView.mRenderMode.Get() == (int)Rendermode.WhenDirty)
             {
                 if (mSurfaceView.mRenderRequested.Get())
                 {
                     mSurfaceView.mRenderRequested.Set(false);
                     shouldRender = true;
                 }
             }
             else
             {
                 shouldRender = true;
             }
             if (mSurfaceView.mSizeChange.Get())
             {
                 GLES20.GlViewport(0, 0, mSurfaceView.mWidth, mSurfaceView.mHeight);
                 if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
                 {
                     result.onSurfaceChanged(mSurfaceView.mWidth, mSurfaceView.mHeight);
                 }
                 mSurfaceView.mSizeChange.Set(false);
             }
             if (shouldRender)
             {
                 if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
                 {
                     result.onPreDrawFrame();
                 }
                 if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
                 {
                     result.onDrawScreen();
                 }
                 EGL14.EglSwapBuffers(mEGLDisplay, mEGLSurface);
                 if (mSurfaceView.mIsRecording.Get())
                 {
                     if (!mSurfaceView.mMediaSurfaceCreated.Get())
                     {
                         mEGLSurfaceMedia = EGL14
                             .EglCreateWindowSurface(mEGLDisplay, eglConfig, mSurfaceView.mSurface,
                                     surfaceAttribs, 0);
                         mSurfaceView.mMediaSurfaceCreated.Set(true);
                     }
                     EGL14.EglMakeCurrent(mEGLDisplay, mEGLSurfaceMedia, mEGLSurfaceMedia,
                             mEGLContext);
                     if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
                     {
                         GLES20.GlViewport(0, 0, mSurfaceView.mOutWidth, mSurfaceView.mOutHeight);
                         //EGLExt.EglPresentationTimeANDROID(mEGLDisplay, mEGLSurfaceMedia, (JavaSystem.CurrentTimeMillis() - RecordableSurfaceView.mStartTimeMillisecs) * 1000L *1000L);
                         result.onDrawRecording();
                         GLES20.GlViewport(0, 0, mSurfaceView.mWidth, mSurfaceView.mHeight);
                     }
                     EGL14.EglSwapBuffers(mEGLDisplay, mEGLSurfaceMedia);
                     EGL14.EglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface,
                             mEGLContext);
                 }
             }
             while (mRunnableQueue.Count > 0)
             {
                 Runnable ev = mRunnableQueue.First.Value;
                 mRunnableQueue.RemoveFirst();
                 ev.Run();
             }
         }
         /*
         try
         {
             Thread.Sleep((long)(1f / 120.0f * 1000f));
         }
         catch (InterruptedException intex) // THIS IS KEY TO BLACKOUT BUG, THIS CATCH NEVER HAPPENS AND SO THE OLD SURFACE IS NEVER NUKED / REMADE mHasGLContext NEVER SET TO FALSE
         {
             if (mSurfaceView.mRendererCallbacksWeakReference != null && mSurfaceView.mRendererCallbacksWeakReference.TryGetTarget(out result))
             {
                 result.onSurfaceDestroyed();
             }
             if (mEGLDisplay != null)
             {
                 EGL14.EglMakeCurrent(mEGLDisplay, EGL14.EglNoSurface,
                         EGL14.EglNoSurface,
                         EGL14.EglNoContext);
                 if (mEGLSurface != null)
                 {
                     EGL14.EglDestroySurface(mEGLDisplay, mEGLSurface);
                 }
                 if (mEGLSurfaceMedia != null)
                 {
                     EGL14.EglDestroySurface(mEGLDisplay, mEGLSurfaceMedia);
                 }
                 EGL14.EglDestroyContext(mEGLDisplay, mEGLContext);
                 mSurfaceView.mHasGLContext.Set(false);
                 EGL14.EglReleaseThread();
                 EGL14.EglTerminate(mEGLDisplay);
                 mSurfaceView.mSurface.Release();
             }
             return;
         }*/
     }
 }