Search in sources :

Example 61 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android-gif-drawable by koral--.

the class GifTextureView method onDetachedFromWindow.

@Override
protected void onDetachedFromWindow() {
    mRenderThread.dispose(this, null);
    super.onDetachedFromWindow();
    final SurfaceTexture surfaceTexture = getSurfaceTexture();
    if (surfaceTexture != null) {
        surfaceTexture.release();
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 62 with SurfaceTexture

use of android.graphics.SurfaceTexture in project UltimateAndroid by cymcsg.

the class VideoResourceInput method initWithGLContext.

@Override
protected void initWithGLContext() {
    ready = false;
    try {
        player = MediaPlayer.create(context, id);
    } catch (Exception e) {
        Log.e("VideoPlayer", "Failed to load video");
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Log.e("VideoPlayer", sw.toString());
        player.release();
    }
    setRenderSize(player.getVideoWidth(), player.getVideoHeight());
    super.initWithGLContext();
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    texture_in = textures[0];
    videoTex = new SurfaceTexture(texture_in);
    videoTex.setOnFrameAvailableListener(this);
    Surface surface = new Surface(videoTex);
    player.setSurface(surface);
    ready = true;
    if (startWhenReady) {
        player.start();
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Surface(android.view.Surface)

Example 63 with SurfaceTexture

use of android.graphics.SurfaceTexture in project grafika by google.

the class ContinuousCaptureActivity method surfaceCreated.

// SurfaceHolder.Callback
@Override
public void surfaceCreated(SurfaceHolder holder) {
    Log.d(TAG, "surfaceCreated holder=" + holder);
    // Set up everything that requires an EGL context.
    //
    // We had to wait until we had a surface because you can't make an EGL context current
    // without one, and creating a temporary 1x1 pbuffer is a waste of time.
    //
    // The display surface that we use for the SurfaceView, and the encoder surface we
    // use for video, use the same EGL context.
    mEglCore = new EglCore(null, EglCore.FLAG_RECORDABLE);
    mDisplaySurface = new WindowSurface(mEglCore, holder.getSurface(), false);
    mDisplaySurface.makeCurrent();
    mFullFrameBlit = new FullFrameRect(new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_EXT));
    mTextureId = mFullFrameBlit.createTextureObject();
    mCameraTexture = new SurfaceTexture(mTextureId);
    mCameraTexture.setOnFrameAvailableListener(this);
    Log.d(TAG, "starting camera preview");
    try {
        mCamera.setPreviewTexture(mCameraTexture);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mCamera.startPreview();
    //       (can we guarantee that camera preview size is compatible with AVC video encoder?)
    try {
        mCircEncoder = new CircularEncoder(VIDEO_WIDTH, VIDEO_HEIGHT, 6000000, mCameraPreviewThousandFps / 1000, 7, mHandler);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mEncoderSurface = new WindowSurface(mEglCore, mCircEncoder.getInputSurface(), true);
    updateControls();
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) 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 64 with SurfaceTexture

use of android.graphics.SurfaceTexture in project grafika by google.

the class PlayMovieActivity method clickPlayStop.

/**
     * onClick handler for "play"/"stop" button.
     */
public void clickPlayStop(@SuppressWarnings("unused") View unused) {
    if (mShowStopLabel) {
        Log.d(TAG, "stopping movie");
        stopPlayback();
    // Don't update the controls here -- let the task thread do it after the movie has
    // actually stopped.
    //mShowStopLabel = false;
    //updateControls();
    } else {
        if (mPlayTask != null) {
            Log.w(TAG, "movie already playing");
            return;
        }
        Log.d(TAG, "starting movie");
        SpeedControlCallback callback = new SpeedControlCallback();
        if (((CheckBox) findViewById(R.id.locked60fps_checkbox)).isChecked()) {
            // TODO: consider changing this to be "free running" mode
            callback.setFixedPlaybackRate(60);
        }
        SurfaceTexture st = mTextureView.getSurfaceTexture();
        Surface surface = new Surface(st);
        MoviePlayer player = null;
        try {
            player = new MoviePlayer(new File(getFilesDir(), mMovieFiles[mSelectedMovie]), surface, callback);
        } catch (IOException ioe) {
            Log.e(TAG, "Unable to play movie", ioe);
            surface.release();
            return;
        }
        adjustAspectRatio(player.getVideoWidth(), player.getVideoHeight());
        mPlayTask = new MoviePlayer.PlayTask(player, this);
        if (((CheckBox) findViewById(R.id.loopPlayback_checkbox)).isChecked()) {
            mPlayTask.setLoopMode(true);
        }
        mShowStopLabel = true;
        updateControls();
        mPlayTask.execute();
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) CheckBox(android.widget.CheckBox) IOException(java.io.IOException) File(java.io.File) Surface(android.view.Surface)

Example 65 with SurfaceTexture

use of android.graphics.SurfaceTexture in project platform_frameworks_base by android.

the class TextureView method getHardwareLayer.

HardwareLayer getHardwareLayer() {
    if (mLayer == null) {
        if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) {
            return null;
        }
        mLayer = mAttachInfo.mHardwareRenderer.createTextureLayer();
        boolean createNewSurface = (mSurface == null);
        if (createNewSurface) {
            // Create a new SurfaceTexture for the layer.
            mSurface = new SurfaceTexture(false);
            nCreateNativeWindow(mSurface);
        }
        mLayer.setSurfaceTexture(mSurface);
        mSurface.setDefaultBufferSize(getWidth(), getHeight());
        mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
        if (mListener != null && createNewSurface) {
            mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight());
        }
        mLayer.setLayerPaint(mLayerPaint);
    }
    if (mUpdateSurface) {
        // Someone has requested that we use a specific SurfaceTexture, so
        // tell mLayer about it and set the SurfaceTexture to use the
        // current view size.
        mUpdateSurface = false;
        // Since we are updating the layer, force an update to ensure its
        // parameters are correct (width, height, transform, etc.)
        updateLayer();
        mMatrixChanged = true;
        mLayer.setSurfaceTexture(mSurface);
        mSurface.setDefaultBufferSize(getWidth(), getHeight());
    }
    return mLayer;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Aggregations

SurfaceTexture (android.graphics.SurfaceTexture)99 Surface (android.view.Surface)49 SurfaceView (android.view.SurfaceView)16 IOException (java.io.IOException)16 SurfaceHolder (android.view.SurfaceHolder)14 EGLSurface (android.opengl.EGLSurface)13 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)5 ServiceSpecificException (android.os.ServiceSpecificException)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Size (android.util.Size)5 RequiresPermission (android.support.annotation.RequiresPermission)4 TextureView (android.view.TextureView)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 Camera (android.hardware.Camera)2 WindowManager (android.view.WindowManager)2 FrameLayout (android.widget.FrameLayout)2 ByteBuffer (java.nio.ByteBuffer)2 CalledByNative (org.chromium.base.CalledByNative)2 Size (android.hardware.Camera.Size)1