Search in sources :

Example 76 with SurfaceTexture

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

the class SurfaceTextureRenderer method configureSurfaces.

/**
     * Set a collection of output {@link Surface}s that can be drawn to.
     *
     * @param surfaces a {@link Collection} of surfaces.
     */
public void configureSurfaces(Collection<Pair<Surface, Size>> surfaces) {
    releaseEGLContext();
    if (surfaces == null || surfaces.size() == 0) {
        Log.w(TAG, "No output surfaces configured for GL drawing.");
        return;
    }
    for (Pair<Surface, Size> p : surfaces) {
        Surface s = p.first;
        Size surfaceSize = p.second;
        // If pixel conversions aren't handled by egl, use a pbuffer
        try {
            EGLSurfaceHolder holder = new EGLSurfaceHolder();
            holder.surface = s;
            holder.width = surfaceSize.getWidth();
            holder.height = surfaceSize.getHeight();
            if (LegacyCameraDevice.needsConversion(s)) {
                mConversionSurfaces.add(holder);
                // LegacyCameraDevice is the producer of surfaces if it's not handled by EGL,
                // so LegacyCameraDevice needs to connect to the surfaces.
                LegacyCameraDevice.connectSurface(s);
            } else {
                mSurfaces.add(holder);
            }
        } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
            Log.w(TAG, "Surface abandoned, skipping configuration... ", e);
        }
    }
    // Set up egl display
    configureEGLContext();
    // Set up regular egl surfaces if needed
    if (mSurfaces.size() > 0) {
        configureEGLOutputSurfaces(mSurfaces);
    }
    // Set up pbuffer surface if needed
    if (mConversionSurfaces.size() > 0) {
        configureEGLPbufferSurfaces(mConversionSurfaces);
    }
    makeCurrent((mSurfaces.size() > 0) ? mSurfaces.get(0).eglSurface : mConversionSurfaces.get(0).eglSurface);
    initializeGLState();
    mSurfaceTexture = new SurfaceTexture(getTextureId());
    // Set up performance tracking if enabled
    if (SystemProperties.getBoolean(LEGACY_PERF_PROPERTY, false)) {
        setupGlTiming();
    }
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) Size(android.util.Size) EGLSurface(android.opengl.EGLSurface) Surface(android.view.Surface)

Example 77 with SurfaceTexture

use of android.graphics.SurfaceTexture in project android_packages_apps_Camera by CyanogenMod.

the class VideoModule method startPreview.

private void startPreview() {
    Log.v(TAG, "startPreview");
    mActivity.mCameraDevice.setErrorCallback(mErrorCallback);
    if (mPreviewing == true) {
        stopPreview();
        if (effectsActive() && mEffectsRecorder != null) {
            mEffectsRecorder.release();
            mEffectsRecorder = null;
        }
    }
    setDisplayOrientation();
    mActivity.mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation);
    setCameraParameters();
    try {
        if (!effectsActive()) {
            if (ApiHelper.HAS_SURFACE_TEXTURE) {
                SurfaceTexture sT = null;
                if (Util.mSwitchCamera) {
                    sT = Util.newSurfaceLayer(mCameraDisplayOrientation, mParameters, mActivity);
                } else {
                    sT = ((CameraScreenNail) mActivity.mCameraScreenNail).getSurfaceTexture();
                }
                mActivity.mCameraDevice.setPreviewTextureAsync(sT);
            } else {
                mActivity.mCameraDevice.setPreviewDisplayAsync(mPreviewSurfaceView.getHolder());
            }
            mActivity.mCameraDevice.startPreviewAsync();
        } else {
            initializeEffectsPreview();
            mEffectsRecorder.startPreview();
        }
    } catch (Throwable ex) {
        closeCamera();
        throw new RuntimeException("startPreview failed", ex);
    }
    mPreviewing = true;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture)

Example 78 with SurfaceTexture

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

the class CameraDeviceBinderTest method testCreateStreamTwo.

@SmallTest
public void testCreateStreamTwo() throws Exception {
    // Create first stream
    int streamId = mCameraUser.createStream(mOutputConfiguration);
    assertEquals(0, streamId);
    try {
        mCameraUser.createStream(mOutputConfiguration);
        fail("Created same stream twice");
    } catch (ServiceSpecificException e) {
        assertEquals("Created same stream twice", ICameraService.ERROR_ALREADY_EXISTS, e.errorCode);
    }
    // Create second stream with a different surface.
    SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */
    0);
    surfaceTexture.setDefaultBufferSize(640, 480);
    Surface surface2 = new Surface(surfaceTexture);
    OutputConfiguration output2 = new OutputConfiguration(surface2);
    int streamId2 = mCameraUser.createStream(output2);
    assertEquals(1, streamId2);
    // Clean up streams
    mCameraUser.deleteStream(streamId);
    mCameraUser.deleteStream(streamId2);
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) SurfaceTexture(android.graphics.SurfaceTexture) OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) Surface(android.view.Surface) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 79 with SurfaceTexture

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

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

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

the class CameraDeviceBinderTest method testCreateStreamTwo.

@SmallTest
public void testCreateStreamTwo() throws Exception {
    // Create first stream
    int streamId = mCameraUser.createStream(mOutputConfiguration);
    assertEquals(0, streamId);
    try {
        mCameraUser.createStream(mOutputConfiguration);
        fail("Created same stream twice");
    } catch (ServiceSpecificException e) {
        assertEquals("Created same stream twice", ICameraService.ERROR_ALREADY_EXISTS, e.errorCode);
    }
    // Create second stream with a different surface.
    SurfaceTexture surfaceTexture = new SurfaceTexture(/* ignored */
    0);
    surfaceTexture.setDefaultBufferSize(640, 480);
    Surface surface2 = new Surface(surfaceTexture);
    OutputConfiguration output2 = new OutputConfiguration(surface2);
    int streamId2 = mCameraUser.createStream(output2);
    assertEquals(1, streamId2);
    // Clean up streams
    mCameraUser.deleteStream(streamId);
    mCameraUser.deleteStream(streamId2);
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) SurfaceTexture(android.graphics.SurfaceTexture) OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) Surface(android.view.Surface) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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