Java 类android.opengl.EGLContext 实例源码

项目:AAVT    文件:EglHelper.java   
public EGLSurface createGLESWithPBuffer(EGLConfigAttrs attrs,EGLContextAttrs ctxAttrs,int width,int height){
    EGLConfig config=getConfig(attrs.surfaceType(EGL14.EGL_PBUFFER_BIT));
    if(config==null){
        log("getConfig failed : "+EGL14.eglGetError());
        return null;
    }
    EGLContext eglContext=createContext(config,EGL14.EGL_NO_CONTEXT,ctxAttrs);
    if(eglContext==EGL14.EGL_NO_CONTEXT){
        log("createContext failed : "+EGL14.eglGetError());
        return null;
    }
    EGLSurface eglSurface=createPBufferSurface(config,width,height);
    if(eglSurface==EGL14.EGL_NO_SURFACE){
        log("createWindowSurface failed : "+EGL14.eglGetError());
        return null;
    }
    if(!EGL14.eglMakeCurrent(mEGLDisplay,eglSurface,eglSurface,eglContext)){
        log("eglMakeCurrent failed : "+EGL14.eglGetError());
        return null;
    }
    return eglSurface;
}
项目:Fatigue-Detection    文件:RenderHandler.java   
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) {
    if (DEBUG) Log.i(TAG, "setEglContext:");
    if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder))
        throw new RuntimeException("unsupported window type:" + surface);
    synchronized (mSync) {
        if (mRequestRelease) return;
        mShard_context = shared_context;
        mTexId = tex_id;
        mSurface = surface;
        mIsRecordable = isRecordable;
        mRequestSetEglContext = true;
        mSync.notifyAll();
        try {
            mSync.wait();
        } catch (final InterruptedException e) {
        }
    }
}
项目:Fatigue-Detection    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    eglDrawer.deInit();

    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    eglDrawer.init();
    eglDrawer.setViewportSize(encoderConfig.mWidth,encoderConfig.mHeight);
}
项目:Fatigue-Detection    文件:TextureMovieEncoder.java   
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
        File outputFile) {
    try {
        MMediaMuxer =new MMediaMuxer(outputFile);
        mVideoEncoder = new VideoEncoderCore(width, height, bitRate, MMediaMuxer);
       // mAudioEncoder = new AudioEncoderCore(MMediaMuxer);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
    mInputWindowSurface.makeCurrent();

    eglDrawer.init();
    eglDrawer.setViewportSize(encoderConfig.mWidth,encoderConfig.mHeight);
}
项目:mpeg-encoder    文件:GLToolsAndroidTest.java   
/**
 * Test for {@link GLTools#setPresentationTime(EGLDisplay, EGLSurface, long)} .
 * @throws Exception by some fails
 */
@Test
public final void testSetPresentationTime() throws Exception {
    final EGLDisplay eglDisplay = GLTools.newDisplay();
    final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true);
    final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig);
    final EGLSurface eglSurface =
            GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);
    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);

    final int txt = GLTools.newTexture(TEXTURE_LEVEL);
    final SurfaceTexture surfaceTexture = new SurfaceTexture(txt, true);
    final Surface surface = new Surface(surfaceTexture);
    final EGLSurface window = GLTools.newSurface(eglDisplay, eglConfig, surface);

    GLTools.setPresentationTime(eglDisplay, window, PRESENTATION_TIME);

    GLTools.closeSurface(eglDisplay, window);
    surface.release();
    surfaceTexture.release();
    GLTools.closeTexture(txt, TEXTURE_LEVEL);

    GLTools.closeSurface(eglDisplay, eglSurface);
    GLTools.closeContext(eglDisplay, eglContext);
    GLTools.closeDisplay(eglDisplay);
}
项目:mpeg-encoder    文件:GLToolsAndroidTest.java   
/**
 * Test for {@link GLTools#newTexture(int)} and {@link GLTools#closeTexture(int, int)}.
 * @throws Exception by some fails
 */
@Test
public final void testTexture() throws Exception {
    final EGLDisplay eglDisplay = GLTools.newDisplay();
    final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true);
    final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig);
    final EGLSurface eglSurface =
            GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);

    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);

    GLTools.closeTexture(GLTools.newTexture(TEXTURE_LEVEL), TEXTURE_LEVEL);

    GLTools.closeSurface(eglDisplay, eglSurface);
    GLTools.closeContext(eglDisplay, eglContext);
    GLTools.closeDisplay(eglDisplay);
}
项目:mpeg-encoder    文件:GLToolsAndroidTest.java   
/**
 * Test for {@link GLTools#newShader(int[])} and {@link GLTools#closeShader(int[])}.
 * @throws Exception by some fails
 */
@Test
public final void testShader() throws Exception {
    final EGLDisplay eglDisplay = GLTools.newDisplay();
    final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true);
    final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig);
    final EGLSurface eglSurface =
            GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);

    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);

    final int[] attrs = new int[5];
    GLTools.newShader(attrs);
    GLTools.closeShader(attrs);

    GLTools.closeSurface(eglDisplay, eglSurface);
    GLTools.closeContext(eglDisplay, eglContext);
    GLTools.closeDisplay(eglDisplay);
}
项目:AppRTC-Android    文件:EglBase14.java   
private static EGLContext createEglContext(
    EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
  if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) {
    throw new RuntimeException("Invalid sharedContext");
  }
  int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
  EGLContext rootContext =
      sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext.egl14Context;
  final EGLContext eglContext;
  synchronized (EglBase.lock) {
    eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0);
  }
  if (eglContext == EGL14.EGL_NO_CONTEXT) {
    throw new RuntimeException(
        "Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError()));
  }
  return eglContext;
}
项目:EditPhoto    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mFullScreen.release(false);
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    // Create new programs and such for the new context.
    mFullScreen = new FullFrameRect(FilterManager.getCameraFilter(mCurrentFilterType, mContext));
}
项目:MegviiFacepp-Android-SDK    文件:RenderHandler.java   
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) {
    if (DEBUG) Log.i(TAG, "setEglContext:");
    if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder))
        throw new RuntimeException("unsupported window type:" + surface);
    synchronized (mSync) {
        if (mRequestRelease) return;
        mShard_context = shared_context;
        mTexId = tex_id;
        mSurface = surface;
        mIsRecordable = isRecordable;
        mRequestSetEglContext = true;
        Matrix.setIdentityM(mMatrix, 0);
        Matrix.setIdentityM(mMatrix, 16);
        mSync.notifyAll();
        try {
            mSync.wait();
        } catch (final InterruptedException e) {
        }
    }
}
项目:AndroidRTC    文件:EglBase14.java   
private static EGLContext createEglContext(
    EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
  if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) {
    throw new RuntimeException("Invalid sharedContext");
  }
  int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
  EGLContext rootContext =
      sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext.egl14Context;
  final EGLContext eglContext;
  synchronized (EglBase.lock) {
    eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0);
  }
  if (eglContext == EGL14.EGL_NO_CONTEXT) {
    throw new RuntimeException(
        "Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError()));
  }
  return eglContext;
}
项目:VideoCRE    文件:EglBase14.java   
private static EGLContext createEglContext(
    EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
  if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) {
    throw new RuntimeException("Invalid sharedContext");
  }
  int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
  EGLContext rootContext =
      sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext.egl14Context;
  final EGLContext eglContext;
  synchronized (EglBase.lock) {
    eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0);
  }
  if (eglContext == EGL14.EGL_NO_CONTEXT) {
    throw new RuntimeException(
        "Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError()));
  }
  return eglContext;
}
项目:EffectCamera    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mInput.destroy();
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    // Create new programs and such for the new context.
    mInput = new MagicCameraInputFilter();
    mInput.init();
    filter = MagicFilterFactory.initFilters(type);
    if(filter != null){
        filter.init();
        filter.onInputSizeChanged(mPreviewWidth, mPreviewHeight);
        filter.onDisplaySizeChanged(mVideoWidth, mVideoHeight);
    }
}
项目:EffectCamera    文件:TextureMovieEncoder.java   
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
        File outputFile) {
    try {
        mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mVideoWidth = width;
    mVideoHeight = height;
    mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
    mInputWindowSurface.makeCurrent();

    mInput = new MagicCameraInputFilter();
    mInput.init();
    filter = MagicFilterFactory.initFilters(type);
    if(filter != null){
        filter.init();
        filter.onInputSizeChanged(mPreviewWidth, mPreviewHeight);
        filter.onDisplaySizeChanged(mVideoWidth, mVideoHeight);
    }
}
项目:VideoMeeting    文件:WebRtcClient.java   
public WebRtcClient(RtcListener listener, String host, PeerConnectionParameters params, EGLContext mEGLcontext) {
    mListener = listener;
    pcParams = params;
    // initializeAndroidGlobals的第一个参数需要是activity或者application
    PeerConnectionFactory.initializeAndroidGlobals(App.getInstance(), true, true,
            params.videoCodecHwAcceleration, mEGLcontext);
    factory = new PeerConnectionFactory();
    MessageHandler messageHandler = new MessageHandler();

    try {
        client = IO.socket(host);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    client.on("id", messageHandler.onId);
    client.on("message", messageHandler.onMessage);
    client.connect(); // connect后,服务端会emit一个id信息,返回该客户端的id

    iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121"));
    iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302"));

    pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
    pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
    pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
}
项目:TimeLapseRecordingSample    文件:RenderHandler.java   
public final void setEglContext(EGLContext shared_context, int tex_id, Object surface, boolean isRecordable) {
    if (DEBUG) Log.i(TAG, "setEglContext:");
    if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder))
        throw new RuntimeException("unsupported window type:" + surface);
    synchronized (mSync) {
        if (mRequestRelease) return;
        mShard_context = shared_context;
        mTexId = tex_id;
        mSurface = surface;
        mIsRecordable = isRecordable;
        mRequestSetEglContext = true;
        mSync.notifyAll();
        try {
            mSync.wait();
        } catch (InterruptedException e) {
        }
    }
}
项目:HardwareEncodingTest    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mFullScreen.release(false);
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    // Create new programs and such for the new context.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
项目:binea_project_for_android    文件:RenderHandler.java   
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) {
    if (DEBUG) Log.i(TAG, "setEglContext:");
    if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder))
        throw new RuntimeException("unsupported window type:" + surface);
    synchronized (mSync) {
        if (mRequestRelease) return;
        mShard_context = shared_context;
        mTexId = tex_id;
        mSurface = surface;
        mIsRecordable = isRecordable;
        mRequestSetEglContext = true;
        mSync.notifyAll();
        try {
            mSync.wait();
        } catch (final InterruptedException e) {
        }
    }
}
项目:binea_project_for_android    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mFullScreen.release(false);
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    // Create new programs and such for the new context.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
项目:binea_project_for_android    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mFullScreen.release(false);
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    // Create new programs and such for the new context.
    mFullScreen = new FullFrameRect(FilterManager.getCameraFilter(mCurrentFilterType, mContext));
}
项目:AndroidPlayground    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mHqInputWindowSurface.releaseEglSurface();
    mFullScreen.release(false);
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    mHqInputWindowSurface.recreate(mEglCore);

    // Create new programs and such for the new context.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
项目:AndroidPlayground    文件:TextureMovieEncoder.java   
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
        File outputFile) {
    try {
        mVideoEncoder = new VideoEncoderCore(width, height, bitRate, outputFile);
        mHqVideoEncoder = new VideoEncoderCore(1280, 720, bitRate,
                new File(Environment.getExternalStorageDirectory(), "camera-test-hq.mp4"));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
    mHqInputWindowSurface = new WindowSurface(mEglCore, mHqVideoEncoder.getInputSurface(), true);

    mInputWindowSurface.makeCurrent();

    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
项目:MediaCodecTest    文件:DecodeWebRTCTest.java   
public void testDecoder(
    final  VideoRenderer.Callbacks renderer,
    final boolean useSurface,
    final EGLContext sharedContext) throws Exception {

    final String encodedIvfFilename = SDCARD_DIR + File.separator + ENCODED_IVF_BASE +
            "_" + WIDTH + "x" + HEIGHT + ".ivf";
    final String outputYuvFilename = null;

    Log.d(TAG, "---------- testSurfaceBasic on thread id: " + Thread.currentThread().getId());
    mLooperRunner = new LooperRunner();
    mLooperRunner.requestStart();
    // Configure and open camera on looper thread
    mLooperRunner.runCallableNoWait( new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            //decode(encodedIvfFilename, useSurface, renderer);
            decodeWebRTC(encodedIvfFilename, useSurface, sharedContext, renderer);
            getAverageCodecTime();
            //VideoRendererGui.printStatistics();
            return null;
        }
    } );

}
项目:PerchBroadcast-Android-SDK    文件:CameraEncoder.java   
/**
 * Called with the display EGLContext current, on Encoder thread
 *
 * @param sharedContext The display EGLContext to be shared with the Encoder Surface's context.
 * @param width         the desired width of the encoder's video output
 * @param height        the desired height of the encoder's video output
 * @param bitRate       the desired bitrate of the video encoder
 * @param muxer         the desired output muxer
 */
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
                            Muxer muxer) throws IOException {
    mVideoEncoder = new VideoEncoderCore(width, height, bitRate, muxer);
    if (mEglCore == null) {
        // This is the first prepare called for this CameraEncoder instance
        mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    }
    if (mInputWindowSurface != null) mInputWindowSurface.release();
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface());
    mInputWindowSurface.makeCurrent();

    if (mFullScreen != null) mFullScreen.release();
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
    mFullScreen.getProgram().setTexSize(width, height);
    mIncomingSizeUpdated = true;
}
项目:cineio-broadcast-android    文件:TextureMovieEncoder.java   
/**
 * Tears down the EGL surface and context we've been using to feed the MediaCodec input
 * surface, and replaces it with a new one that shares with the new context.
 * <p/>
 * This is useful if the old context we were sharing with went away (maybe a GLSurfaceView
 * that got torn down) and we need to hook up with the new one.
 */
private void handleUpdateSharedContext(EGLContext newSharedContext) {
    Log.d(TAG, "handleUpdatedSharedContext " + newSharedContext);

    // Release the EGLSurface and EGLContext.
    mInputWindowSurface.releaseEglSurface();
    mFullScreen.release(false);
    mEglCore.release();

    // Create a new EGLContext and recreate the window surface.
    mEglCore = new EglCore(newSharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface.recreate(mEglCore);
    mInputWindowSurface.makeCurrent();

    // Create new programs and such for the new context.
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
项目:AudioVideoRecordingSample    文件:RenderHandler.java   
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) {
    if (DEBUG) Log.i(TAG, "setEglContext:");
    if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder))
        throw new RuntimeException("unsupported window type:" + surface);
    synchronized (mSync) {
        if (mRequestRelease) return;
        mShard_context = shared_context;
        mTexId = tex_id;
        mSurface = surface;
        mIsRecordable = isRecordable;
        mRequestSetEglContext = true;
        Matrix.setIdentityM(mMatrix, 0);
        Matrix.setIdentityM(mMatrix, 16);
        mSync.notifyAll();
        try {
            mSync.wait();
        } catch (final InterruptedException e) {
        }
    }
}
项目:kickflip-android-sdk    文件:CameraEncoder.java   
/**
 * Called with the display EGLContext current, on Encoder thread
 *
 * @param sharedContext The display EGLContext to be shared with the Encoder Surface's context.
 * @param width         the desired width of the encoder's video output
 * @param height        the desired height of the encoder's video output
 * @param bitRate       the desired bitrate of the video encoder
 * @param muxer         the desired output muxer
 */
private void prepareEncoder(EGLContext sharedContext, int width, int height, int bitRate,
                            Muxer muxer) throws IOException {
    mVideoEncoder = new VideoEncoderCore(width, height, bitRate, muxer);
    if (mEglCore == null) {
        // This is the first prepare called for this CameraEncoder instance
        mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    }
    if (mInputWindowSurface != null) mInputWindowSurface.release();
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface());
    mInputWindowSurface.makeCurrent();

    if (mFullScreen != null) mFullScreen.release();
    mFullScreen = new FullFrameRect(
            new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
    mFullScreen.getProgram().setTexSize(width, height);
    mIncomingSizeUpdated = true;
}
项目:AAVT    文件:EglHelper.java   
public EGLContext createContext(EGLConfig config,EGLContext share,EGLContextAttrs attrs){
    EGLContext context= EGL14.eglCreateContext(mEGLDisplay,config,share,attrs.build(),0);
    if(attrs.isDefault()){
        mEGLContext=context;
    }
    return context;
}
项目:AAVT    文件:EglHelper.java   
public boolean destroyGLES(EGLSurface surface,EGLContext context){
    EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    if(surface!=null){
        EGL14.eglDestroySurface(mEGLDisplay,surface);
    }
    if(context!=null){
        EGL14.eglDestroyContext(mEGLDisplay,context);
    }
    EGL14.eglTerminate(mEGLDisplay);
    log("gl destroy gles");
    return true;
}
项目:Fatigue-Detection    文件:EGLBase.java   
private void init(EGLContext shared_context, final boolean with_depth_buffer, final boolean isRecordable) {
    if (DEBUG) Log.v(TAG, "init:");
       if (mEglDisplay != EGL14.EGL_NO_DISPLAY) {
           throw new RuntimeException("EGL already set up");
       }

       mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
       if (mEglDisplay == EGL14.EGL_NO_DISPLAY) {
           throw new RuntimeException("eglGetDisplay failed");
       }

    final int[] version = new int[2];
       if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) {
        mEglDisplay = null;
           throw new RuntimeException("eglInitialize failed");
       }

    shared_context = shared_context != null ? shared_context : EGL14.EGL_NO_CONTEXT;
       if (mEglContext == EGL14.EGL_NO_CONTEXT) {
           mEglConfig = getConfig(with_depth_buffer, isRecordable);
           if (mEglConfig == null) {
               throw new RuntimeException("chooseConfig failed");
           }
           // create EGL rendering context
        mEglContext = createContext(shared_context);
       }
       // confirm whether the EGL rendering context is successfully created
       final int[] values = new int[1];
       EGL14.eglQueryContext(mEglDisplay, mEglContext, EGL14.EGL_CONTEXT_CLIENT_VERSION, values, 0);
       if (DEBUG) Log.d(TAG, "EGLContext created, client version " + values[0]);
       makeDefault();   // makeCurrent(EGL14.EGL_NO_SURFACE);
}
项目:Fatigue-Detection    文件:EGLBase.java   
private EGLContext createContext(final EGLContext shared_context) {
//      if (DEBUG) Log.v(TAG, "createContext:");

        final int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
        };
        final EGLContext context = EGL14.eglCreateContext(mEglDisplay, mEglConfig, shared_context, attrib_list, 0);
        checkEglError("eglCreateContext");
        return context;
    }
项目:Fatigue-Detection    文件:EglCore.java   
/**
 * Writes the current display, context, and surface to the log.
 */
public static void logCurrent(String msg) {
    EGLDisplay display;
    EGLContext context;
    EGLSurface surface;

    display = EGL14.eglGetCurrentDisplay();
    context = EGL14.eglGetCurrentContext();
    surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW);
    Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context +
            ", surface=" + surface);
}
项目:Fatigue-Detection    文件:TextureMovieEncoder.java   
public EncoderConfig(File outputFile, int width, int height, int bitRate,
        EGLContext sharedEglContext) {
    mOutputFile = outputFile;
    mWidth = width;
    mHeight = height;
    mBitRate = bitRate;
    mEglContext = sharedEglContext;
}
项目:Fatigue-Detection    文件:TextureMovieEncoder.java   
@Override  // runs on encoder thread
public void handleMessage(Message inputMessage) {
    int what = inputMessage.what;
    Object obj = inputMessage.obj;

    TextureMovieEncoder encoder = mWeakEncoder.get();
    if (encoder == null) {
        Log.w(TAG, "EncoderHandler.handleMessage: encoder is null");
        return;
    }

    switch (what) {
        case MSG_START_RECORDING:
            encoder.handleStartRecording((EncoderConfig) obj);
            break;
        case MSG_STOP_RECORDING:
            encoder.handleStopRecording();
            break;
        case MSG_FRAME_AVAILABLE:
            long timestamp = (((long) inputMessage.arg1) << 32) |
                    (((long) inputMessage.arg2) & 0xffffffffL);
            encoder.handleFrameAvailable(timestamp);
            break;
        case MSG_SET_TEXTURE_ID:
            encoder.handleSetTexture(inputMessage.arg1);
            break;
        case MSG_UPDATE_SHARED_CONTEXT:
            encoder.handleUpdateSharedContext((EGLContext) inputMessage.obj);
            break;
        case MSG_QUIT:
            Looper.myLooper().quit();
            break;
        default:
            throw new RuntimeException("Unhandled msg what=" + what);
    }
}
项目:mpeg-encoder    文件:GLTools.java   
/**
 * @param display an EGL display connection instance
 * @return a new EGL rendering context
 **/
@NonNull
public static EGLContext newContext(@NonNull EGLDisplay display, @NonNull EGLConfig config) {
    final EGLContext result = EGL14.eglCreateContext (display, config, EGL14.EGL_NO_CONTEXT,
            new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE }, 0);
    if (result == EGL14.EGL_NO_CONTEXT) {
        logError();
        throw new RuntimeException("Unable to from EGL14 context");
    } else {
        logDebug(getContextString(result) + " created");
        return result;
    }
}
项目:mpeg-encoder    文件:GLTools.java   
/**
 * @param context EGL context
 * @return the EGL context handle
 */
private static long getContextHandle(@NonNull EGLContext context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return getContextHandleLollipop(context);
    } else {
        return getContextHandleBase(context);
    }
}
项目:mpeg-encoder    文件:GLTools.java   
/**
 * Close an EGL rendering context.
 * @param display an EGL display connection instance
 * @param context an EGL rendering context
 */
public static void closeContext(@NonNull EGLDisplay display, @NonNull EGLContext context) {
    if (!EGL14.eglDestroyContext(display, context)) {
        logError();
        throw new RuntimeException("Unable to terminate EGL14 " + getContextString(context));
    } else {
        if (!EGL14.eglReleaseThread()) logError();
        logDebug(getContextString(context) + " destroyed");
    }
}
项目:mpeg-encoder    文件:GLTools.java   
/**
 * Make an EGL rendering context as current.
 * @param display an EGL display connection instance
 * @param surface an EGL rendering surface
 * @param context an EGL rendering context
 */
public static void makeCurrent(@NonNull EGLDisplay display, @NonNull EGLSurface surface,
        @NonNull EGLContext context) {
    if (!EGL14.eglMakeCurrent(display, surface, surface, context)) {
        logError();
        throw new RuntimeException("Unable to make " + getContextString(context) + " current");
    } else {
        logDebug(getContextString(context) + " set as current");
    }
}
项目:mpeg-encoder    文件:GLToolsAndroidTest.java   
/**
 * Test for {@link GLTools#newSurface(EGLDisplay, EGLConfig, int, int)} and
 * {@link GLTools#closeSurface(EGLDisplay, EGLSurface)}.
 * @throws Exception by some fails
 */
@Test
public final void testSurface() throws Exception {
    final EGLDisplay eglDisplay = GLTools.newDisplay();
    final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true);
    final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig);
    GLTools.closeSurface(eglDisplay,
            GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE));
    GLTools.closeContext(eglDisplay, eglContext);
    GLTools.closeDisplay(eglDisplay);
}
项目:mpeg-encoder    文件:GLToolsAndroidTest.java   
/**
 * Test for {@link GLTools#makeCurrent(EGLDisplay, EGLSurface, EGLContext)}.
 * @throws Exception by some fails
 */
@Test
public final void testMakeCurrent() throws Exception {
    final EGLDisplay eglDisplay = GLTools.newDisplay();
    final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true);
    final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig);
    final EGLSurface eglSurface =
            GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);
    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);
    GLTools.closeSurface(eglDisplay, eglSurface);
    GLTools.closeContext(eglDisplay, eglContext);
    GLTools.closeDisplay(eglDisplay);
}