Search in sources :

Example 1 with EglCore

use of com.android.grafika.gles.EglCore in project grafika by google.

the class TextureMovieEncoder method prepareEncoder.

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);
    }
    mEglCore = new EglCore(sharedContext, EglCore.FLAG_RECORDABLE);
    mInputWindowSurface = new WindowSurface(mEglCore, mVideoEncoder.getInputSurface(), true);
    mInputWindowSurface.makeCurrent();
    mFullScreen = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
}
Also used : FullFrameRect(com.android.grafika.gles.FullFrameRect) Texture2dProgram(com.android.grafika.gles.Texture2dProgram) EglCore(com.android.grafika.gles.EglCore) IOException(java.io.IOException) WindowSurface(com.android.grafika.gles.WindowSurface)

Example 2 with EglCore

use of com.android.grafika.gles.EglCore in project grafika by google.

the class GeneratedMovie method prepareEncoder.

/**
     * Prepares the video encoder, muxer, and an EGL input surface.
     */
protected void prepareEncoder(String mimeType, int width, int height, int bitRate, int framesPerSecond, File outputFile) throws IOException {
    mBufferInfo = new MediaCodec.BufferInfo();
    MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
    // Set some properties.  Failing to specify some of these can cause the MediaCodec
    // configure() call to throw an unhelpful exception.
    format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
    format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, framesPerSecond);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
    if (VERBOSE)
        Log.d(TAG, "format: " + format);
    // Create a MediaCodec encoder, and configure it with our format.  Get a Surface
    // we can use for input and wrap it with a class that handles the EGL work.
    mEncoder = MediaCodec.createEncoderByType(mimeType);
    mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    Log.v(TAG, "encoder is " + mEncoder.getCodecInfo().getName());
    Surface surface;
    try {
        surface = mEncoder.createInputSurface();
    } catch (IllegalStateException ise) {
        // TODO: failure message should come out of strings.xml for i18n
        if (isSoftwareCodec(mEncoder)) {
            throw new RuntimeException("Can't use input surface with software codec: " + mEncoder.getCodecInfo().getName(), ise);
        } else {
            throw new RuntimeException("Failed to create input surface", ise);
        }
    }
    mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
    mInputSurface = new WindowSurface(mEglCore, surface, true);
    mInputSurface.makeCurrent();
    mEncoder.start();
    // the raw H.264 elementary stream we get from MediaCodec into a .mp4 file.
    if (VERBOSE)
        Log.d(TAG, "output will go to " + outputFile);
    mMuxer = new MediaMuxer(outputFile.toString(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    mTrackIndex = -1;
    mMuxerStarted = false;
}
Also used : MediaFormat(android.media.MediaFormat) MediaCodec(android.media.MediaCodec) EglCore(com.android.grafika.gles.EglCore) MediaMuxer(android.media.MediaMuxer) WindowSurface(com.android.grafika.gles.WindowSurface) WindowSurface(com.android.grafika.gles.WindowSurface) Surface(android.view.Surface)

Example 3 with EglCore

use of com.android.grafika.gles.EglCore in project grafika by google.

the class MultiSurfaceActivity method drawRectSurface.

/**
     * Clears the surface, then draws some alpha-blended rectangles with GL.
     * <p>
     * Creates a temporary EGL context just for the duration of the call.
     */
private void drawRectSurface(Surface surface, int left, int top, int width, int height) {
    EglCore eglCore = new EglCore();
    WindowSurface win = new WindowSurface(eglCore, surface, false);
    win.makeCurrent();
    GLES20.glClearColor(0, 0, 0, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    for (int i = 0; i < 4; i++) {
        int x, y, w, h;
        if (width < height) {
            // vertical
            w = width / 4;
            h = height;
            x = left + w * i;
            y = top;
        } else {
            // horizontal
            w = width;
            h = height / 4;
            x = left;
            y = top + h * i;
        }
        GLES20.glScissor(x, y, w, h);
        switch(i) {
            case // 50% blue at 25% alpha, pre-multiplied
            0:
                GLES20.glClearColor(0.0f, 0.0f, 0.125f, 0.25f);
                break;
            case // 100% blue at 25% alpha, pre-multiplied
            1:
                GLES20.glClearColor(0.0f, 0.0f, 0.25f, 0.25f);
                break;
            case // 200% blue at 25% alpha, pre-multiplied (should get clipped)
            2:
                GLES20.glClearColor(0.0f, 0.0f, 0.5f, 0.25f);
                break;
            case // 100% white at 25% alpha, pre-multiplied
            3:
                GLES20.glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
                break;
        }
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    }
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    win.swapBuffers();
    win.release();
    eglCore.release();
}
Also used : EglCore(com.android.grafika.gles.EglCore) WindowSurface(com.android.grafika.gles.WindowSurface) Paint(android.graphics.Paint)

Example 4 with EglCore

use of com.android.grafika.gles.EglCore in project grafika by google.

the class PlayMovieSurfaceActivity method clearSurface.

/**
     * Clears the playback surface to black.
     */
private void clearSurface(Surface surface) {
    // We need to do this with OpenGL ES (*not* Canvas -- the "software render" bits
    // are sticky).  We can't stay connected to the Surface after we're done because
    // that'd prevent the video encoder from attaching.
    //
    // If the Surface is resized to be larger, the new portions will be black, so
    // clearing to something other than black may look weird unless we do the clear
    // post-resize.
    EglCore eglCore = new EglCore();
    WindowSurface win = new WindowSurface(eglCore, surface, false);
    win.makeCurrent();
    GLES20.glClearColor(0, 0, 0, 0);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    win.swapBuffers();
    win.release();
    eglCore.release();
}
Also used : EglCore(com.android.grafika.gles.EglCore) WindowSurface(com.android.grafika.gles.WindowSurface)

Example 5 with EglCore

use of com.android.grafika.gles.EglCore in project grafika by google.

the class TextureMovieEncoder method handleUpdateSharedContext.

/**
     * 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));
}
Also used : FullFrameRect(com.android.grafika.gles.FullFrameRect) Texture2dProgram(com.android.grafika.gles.Texture2dProgram) EglCore(com.android.grafika.gles.EglCore)

Aggregations

EglCore (com.android.grafika.gles.EglCore)7 WindowSurface (com.android.grafika.gles.WindowSurface)5 FullFrameRect (com.android.grafika.gles.FullFrameRect)3 Texture2dProgram (com.android.grafika.gles.Texture2dProgram)3 IOException (java.io.IOException)2 Paint (android.graphics.Paint)1 SurfaceTexture (android.graphics.SurfaceTexture)1 MediaCodec (android.media.MediaCodec)1 MediaFormat (android.media.MediaFormat)1 MediaMuxer (android.media.MediaMuxer)1 Surface (android.view.Surface)1 OffscreenSurface (com.android.grafika.gles.OffscreenSurface)1