Search in sources :

Example 11 with SurfaceTexture

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

the class CameraPreviewInput method initWithGLContext.

@Override
protected void initWithGLContext() {
    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];
    camTex = new SurfaceTexture(texture_in);
    camTex.setOnFrameAvailableListener(this);
    boolean failed = true;
    while (failed) {
        try {
            if (camera != null) {
                camera.stopPreview();
                camera.release();
                camera = null;
            }
            camera = createCamera();
            camera.setPreviewTexture(camTex);
            camera.startPreview();
            setRenderSizeToCameraSize();
            failed = false;
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            Log.e("CameraInput", sw.toString());
            if (camera != null) {
                camera.release();
                camera = null;
            }
        }
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 12 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android_frameworks_base by ResurrectionRemix.

the class EGLImpl method eglCreateWindowSurface.

public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) {
    Surface sur = null;
    if (native_window instanceof SurfaceView) {
        SurfaceView surfaceView = (SurfaceView) native_window;
        sur = surfaceView.getHolder().getSurface();
    } else if (native_window instanceof SurfaceHolder) {
        SurfaceHolder holder = (SurfaceHolder) native_window;
        sur = holder.getSurface();
    } else if (native_window instanceof Surface) {
        sur = (Surface) native_window;
    }
    long eglSurfaceId;
    if (sur != null) {
        eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list);
    } else if (native_window instanceof SurfaceTexture) {
        eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, native_window, attrib_list);
    } else {
        throw new java.lang.UnsupportedOperationException("eglCreateWindowSurface() can only be called with an instance of " + "Surface, SurfaceView, SurfaceHolder or SurfaceTexture at the moment.");
    }
    if (eglSurfaceId == 0) {
        return EGL10.EGL_NO_SURFACE;
    }
    return new EGLSurfaceImpl(eglSurfaceId);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceTexture(android.graphics.SurfaceTexture) SurfaceView(android.view.SurfaceView) Surface(android.view.Surface)

Example 13 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android_frameworks_base by ResurrectionRemix.

the class CameraSource method open.

@Override
public void open(FilterContext context) {
    if (mLogVerbose)
        Log.v(TAG, "Opening");
    // Open camera
    mCamera = Camera.open(mCameraId);
    // Set parameters
    getCameraParameters();
    mCamera.setParameters(mCameraParameters);
    // Create frame formats
    createFormats();
    // Bind it to our camera frame
    mCameraFrame = (GLFrame) context.getFrameManager().newBoundFrame(mOutputFormat, GLFrame.EXTERNAL_TEXTURE, 0);
    mSurfaceTexture = new SurfaceTexture(mCameraFrame.getTextureId());
    try {
        mCamera.setPreviewTexture(mSurfaceTexture);
    } catch (IOException e) {
        throw new RuntimeException("Could not bind camera surface texture: " + e.getMessage() + "!");
    }
    // Connect SurfaceTexture to callback
    mSurfaceTexture.setOnFrameAvailableListener(onCameraFrameAvailableListener);
    // Start the preview
    mNewFrameAvailable = false;
    mCamera.startPreview();
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) IOException(java.io.IOException)

Example 14 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android_frameworks_base by ResurrectionRemix.

the class MediaSource method open.

@Override
public void open(FilterContext context) {
    if (mLogVerbose) {
        Log.v(TAG, "Opening MediaSource");
        if (mSelectedIsUrl) {
            Log.v(TAG, "Current URL is " + mSourceUrl);
        } else {
            Log.v(TAG, "Current source is Asset!");
        }
    }
    mMediaFrame = (GLFrame) context.getFrameManager().newBoundFrame(mOutputFormat, GLFrame.EXTERNAL_TEXTURE, 0);
    mSurfaceTexture = new SurfaceTexture(mMediaFrame.getTextureId());
    if (!setupMediaPlayer(mSelectedIsUrl)) {
        throw new RuntimeException("Error setting up MediaPlayer!");
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 15 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android_frameworks_base by ResurrectionRemix.

the class SurfaceTextureSource method open.

@Override
public void open(FilterContext context) {
    if (mLogVerbose)
        Log.v(TAG, "Opening SurfaceTextureSource");
    // Create SurfaceTexture anew each time - it can use substantial memory.
    mSurfaceTexture = new SurfaceTexture(mMediaFrame.getTextureId());
    // Connect SurfaceTexture to callback
    mSurfaceTexture.setOnFrameAvailableListener(onFrameAvailableListener);
    // Connect SurfaceTexture to source
    mSourceListener.onSurfaceTextureSourceReady(mSurfaceTexture);
    mFirstFrame = true;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Aggregations

SurfaceTexture (android.graphics.SurfaceTexture)159 Surface (android.view.Surface)97 SurfaceView (android.view.SurfaceView)18 IOException (java.io.IOException)17 Test (org.junit.Test)16 EGLSurface (android.opengl.EGLSurface)14 SurfaceHolder (android.view.SurfaceHolder)14 Context (android.content.Context)13 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)13 FakeClock (com.google.android.exoplayer2.testutil.FakeClock)13 TextureView (android.view.TextureView)12 PlaybackOutput (com.google.android.exoplayer2.robolectric.PlaybackOutput)12 CapturingRenderersFactory (com.google.android.exoplayer2.testutil.CapturingRenderersFactory)12 Uri (android.net.Uri)9 MediaPlayer (android.media.MediaPlayer)8 OnInfoListener (android.media.MediaPlayer.OnInfoListener)8 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)8 ImageView (android.widget.ImageView)6 ApplicationProvider (androidx.test.core.app.ApplicationProvider)6 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)6