Search in sources :

Example 1 with SurfaceTexture

use of android.graphics.SurfaceTexture in project VideoPlayerManager by danylovolokh.

the class VideoPlayerView method createNewPlayerInstance.

public void createNewPlayerInstance() {
    if (SHOW_LOGS)
        Logger.v(TAG, ">> createNewPlayerInstance");
    if (SHOW_LOGS)
        Logger.v(TAG, "createNewPlayerInstance main Looper " + Looper.getMainLooper());
    if (SHOW_LOGS)
        Logger.v(TAG, "createNewPlayerInstance my Looper " + Looper.myLooper());
    checkThread();
    synchronized (mReadyForPlaybackIndicator) {
        mMediaPlayer = new MediaPlayerWrapperImpl();
        mReadyForPlaybackIndicator.setVideoSize(null, null);
        mReadyForPlaybackIndicator.setFailedToPrepareUiForPlayback(false);
        if (mReadyForPlaybackIndicator.isSurfaceTextureAvailable()) {
            SurfaceTexture texture = getSurfaceTexture();
            if (SHOW_LOGS)
                Logger.v(TAG, "texture " + texture);
            mMediaPlayer.setSurfaceTexture(texture);
        } else {
            if (SHOW_LOGS)
                Logger.v(TAG, "texture not available");
        }
        mMediaPlayer.setMainThreadMediaPlayerListener(this);
        mMediaPlayer.setVideoStateListener(this);
    }
    if (SHOW_LOGS)
        Logger.v(TAG, "<< createNewPlayerInstance");
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 2 with SurfaceTexture

use of android.graphics.SurfaceTexture in project material-camera by afollestad.

the class Camera2Fragment method startPreview.

private void startPreview() {
    if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize)
        return;
    try {
        if (!mInterface.useStillshot()) {
            if (!setUpMediaRecorder()) {
                return;
            }
        }
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        assert texture != null;
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        List<Surface> surfaces = new ArrayList<>();
        Surface previewSurface = new Surface(texture);
        surfaces.add(previewSurface);
        if (mInterface.useStillshot()) {
            mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            mPreviewBuilder.addTarget(previewSurface);
            surfaces.add(mImageReader.getSurface());
        } else {
            mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
            mPreviewBuilder.addTarget(previewSurface);
            Surface recorderSurface = mMediaRecorder.getSurface();
            surfaces.add(recorderSurface);
            mPreviewBuilder.addTarget(recorderSurface);
        }
        mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {

            @Override
            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                if (mCameraDevice == null) {
                    return;
                }
                mPreviewSession = cameraCaptureSession;
                updatePreview();
            }

            @Override
            public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
                throwError(new Exception("Camera configuration failed"));
            }
        }, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) SurfaceTexture(android.graphics.SurfaceTexture) ArrayList(java.util.ArrayList) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) IOException(java.io.IOException) CameraAccessException(android.hardware.camera2.CameraAccessException) Surface(android.view.Surface)

Example 3 with SurfaceTexture

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

the class ElectronBeam method captureScreenshotTextureAndSetViewport.

private boolean captureScreenshotTextureAndSetViewport() {
    if (!attachEglContext()) {
        return false;
    }
    try {
        if (!mTexNamesGenerated) {
            GLES10.glGenTextures(1, mTexNames, 0);
            if (checkGlErrors("glGenTextures")) {
                return false;
            }
            mTexNamesGenerated = true;
        }
        final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
        final Surface s = new Surface(st);
        try {
            SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
        } finally {
            s.release();
        }
        st.updateTexImage();
        st.getTransformMatrix(mTexMatrix);
        // Set up texture coordinates for a quad.
        // We might need to change this if the texture ends up being
        // a different size from the display for some reason.
        mTexCoordBuffer.put(0, 0f);
        mTexCoordBuffer.put(1, 0f);
        mTexCoordBuffer.put(2, 0f);
        mTexCoordBuffer.put(3, 1f);
        mTexCoordBuffer.put(4, 1f);
        mTexCoordBuffer.put(5, 1f);
        mTexCoordBuffer.put(6, 1f);
        mTexCoordBuffer.put(7, 0f);
        // Set up our viewport.
        GLES10.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
        GLES10.glMatrixMode(GLES10.GL_PROJECTION);
        GLES10.glLoadIdentity();
        GLES10.glOrthof(0, mDisplayWidth, 0, mDisplayHeight, 0, 1);
        GLES10.glMatrixMode(GLES10.GL_MODELVIEW);
        GLES10.glLoadIdentity();
        GLES10.glMatrixMode(GLES10.GL_TEXTURE);
        GLES10.glLoadIdentity();
        GLES10.glLoadMatrixf(mTexMatrix, 0);
    } finally {
        detachEglContext();
    }
    return true;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) Surface(android.view.Surface) EGLSurface(android.opengl.EGLSurface)

Example 4 with SurfaceTexture

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

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 5 with SurfaceTexture

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

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)

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