Search in sources :

Example 46 with OutputConfiguration

use of android.hardware.camera2.params.OutputConfiguration in project android_frameworks_base by crdroidandroid.

the class CameraDeviceBinderTest method createDefaultSurface.

private void createDefaultSurface() {
    mImageReader = ImageReader.newInstance(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, ImageFormat.YUV_420_888, MAX_NUM_IMAGES);
    mImageReader.setOnImageAvailableListener(new ImageDropperListener(), mHandler);
    mSurface = mImageReader.getSurface();
    mOutputConfiguration = new OutputConfiguration(mSurface);
}
Also used : OutputConfiguration(android.hardware.camera2.params.OutputConfiguration)

Example 47 with OutputConfiguration

use of android.hardware.camera2.params.OutputConfiguration in project android_frameworks_base by crdroidandroid.

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 48 with OutputConfiguration

use of android.hardware.camera2.params.OutputConfiguration in project android_frameworks_base by crdroidandroid.

the class CameraDeviceImpl method createConstrainedHighSpeedCaptureSession.

@Override
public void createConstrainedHighSpeedCaptureSession(List<Surface> outputs, android.hardware.camera2.CameraCaptureSession.StateCallback callback, Handler handler) throws CameraAccessException {
    if (outputs == null || outputs.size() == 0 || outputs.size() > 2) {
        throw new IllegalArgumentException("Output surface list must not be null and the size must be no more than 2");
    }
    StreamConfigurationMap config = getCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    SurfaceUtils.checkConstrainedHighSpeedSurfaces(outputs, /*fpsRange*/
    null, config);
    List<OutputConfiguration> outConfigurations = new ArrayList<>(outputs.size());
    for (Surface surface : outputs) {
        outConfigurations.add(new OutputConfiguration(surface));
    }
    createCaptureSessionInternal(null, outConfigurations, callback, handler, /*isConstrainedHighSpeed*/
    true);
}
Also used : OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) ArrayList(java.util.ArrayList) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) Surface(android.view.Surface)

Example 49 with OutputConfiguration

use of android.hardware.camera2.params.OutputConfiguration in project android_frameworks_base by crdroidandroid.

the class CameraDeviceImpl method configureStreamsChecked.

/**
     * Attempt to configure the input and outputs; the device goes to idle and then configures the
     * new input and outputs if possible.
     *
     * <p>The configuration may gracefully fail, if input configuration is not supported,
     * if there are too many outputs, if the formats are not supported, or if the sizes for that
     * format is not supported. In this case this function will return {@code false} and the
     * unconfigured callback will be fired.</p>
     *
     * <p>If the configuration succeeds (with 1 or more outputs with or without an input),
     * then the idle callback is fired. Unconfiguring the device always fires the idle callback.</p>
     *
     * @param inputConfig input configuration or {@code null} for no input
     * @param outputs a list of one or more surfaces, or {@code null} to unconfigure
     * @param isConstrainedHighSpeed If the streams configuration is for constrained high speed output.
     * @return whether or not the configuration was successful
     *
     * @throws CameraAccessException if there were any unexpected problems during configuration
     */
public boolean configureStreamsChecked(InputConfiguration inputConfig, List<OutputConfiguration> outputs, boolean isConstrainedHighSpeed) throws CameraAccessException {
    // Treat a null input the same an empty list
    if (outputs == null) {
        outputs = new ArrayList<OutputConfiguration>();
    }
    if (outputs.size() == 0 && inputConfig != null) {
        throw new IllegalArgumentException("cannot configure an input stream without " + "any output streams");
    }
    checkInputConfiguration(inputConfig);
    boolean success = false;
    synchronized (mInterfaceLock) {
        checkIfCameraClosedOrInError();
        // Streams to create
        HashSet<OutputConfiguration> addSet = new HashSet<OutputConfiguration>(outputs);
        // Streams to delete
        List<Integer> deleteList = new ArrayList<Integer>();
        // Determine which streams need to be created, which to be deleted
        for (int i = 0; i < mConfiguredOutputs.size(); ++i) {
            int streamId = mConfiguredOutputs.keyAt(i);
            OutputConfiguration outConfig = mConfiguredOutputs.valueAt(i);
            if (!outputs.contains(outConfig) || outConfig.isDeferredConfiguration()) {
                // Always delete the deferred output configuration when the session
                // is created, as the deferred output configuration doesn't have unique surface
                // related identifies.
                deleteList.add(streamId);
            } else {
                // Don't create a stream previously created
                addSet.remove(outConfig);
            }
        }
        mDeviceHandler.post(mCallOnBusy);
        stopRepeating();
        try {
            waitUntilIdle();
            mRemoteDevice.beginConfigure();
            // reconfigure the input stream if the input configuration is different.
            InputConfiguration currentInputConfig = mConfiguredInput.getValue();
            if (inputConfig != currentInputConfig && (inputConfig == null || !inputConfig.equals(currentInputConfig))) {
                if (currentInputConfig != null) {
                    mRemoteDevice.deleteStream(mConfiguredInput.getKey());
                    mConfiguredInput = new SimpleEntry<Integer, InputConfiguration>(REQUEST_ID_NONE, null);
                }
                if (inputConfig != null) {
                    int streamId = mRemoteDevice.createInputStream(inputConfig.getWidth(), inputConfig.getHeight(), inputConfig.getFormat());
                    mConfiguredInput = new SimpleEntry<Integer, InputConfiguration>(streamId, inputConfig);
                }
            }
            // Delete all streams first (to free up HW resources)
            for (Integer streamId : deleteList) {
                mRemoteDevice.deleteStream(streamId);
                mConfiguredOutputs.delete(streamId);
            }
            // Add all new streams
            for (OutputConfiguration outConfig : outputs) {
                if (addSet.contains(outConfig)) {
                    int streamId = mRemoteDevice.createStream(outConfig);
                    mConfiguredOutputs.put(streamId, outConfig);
                }
            }
            mRemoteDevice.endConfigure(isConstrainedHighSpeed);
            success = true;
        } catch (IllegalArgumentException e) {
            // OK. camera service can reject stream config if it's not supported by HAL
            // This is only the result of a programmer misusing the camera2 api.
            Log.w(TAG, "Stream configuration failed due to: " + e.getMessage());
            return false;
        } catch (CameraAccessException e) {
            if (e.getReason() == CameraAccessException.CAMERA_IN_USE) {
                throw new IllegalStateException("The camera is currently busy." + " You must wait until the previous operation completes.", e);
            }
            throw e;
        } finally {
            if (success && outputs.size() > 0) {
                mDeviceHandler.post(mCallOnIdle);
            } else {
                // Always return to the 'unconfigured' state if we didn't hit a fatal error
                mDeviceHandler.post(mCallOnUnconfigured);
            }
        }
    }
    return success;
}
Also used : ArrayList(java.util.ArrayList) InputConfiguration(android.hardware.camera2.params.InputConfiguration) CameraAccessException(android.hardware.camera2.CameraAccessException) OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) HashSet(java.util.HashSet)

Example 50 with OutputConfiguration

use of android.hardware.camera2.params.OutputConfiguration in project android_frameworks_base by crdroidandroid.

the class CameraDeviceImpl method configureOutputs.

public void configureOutputs(List<Surface> outputs) throws CameraAccessException {
    // Leave this here for backwards compatibility with older code using this directly
    ArrayList<OutputConfiguration> outputConfigs = new ArrayList<>(outputs.size());
    for (Surface s : outputs) {
        outputConfigs.add(new OutputConfiguration(s));
    }
    configureStreamsChecked(/*inputConfig*/
    null, outputConfigs, /*isConstrainedHighSpeed*/
    false);
}
Also used : OutputConfiguration(android.hardware.camera2.params.OutputConfiguration) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Aggregations

OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)50 ArrayList (java.util.ArrayList)35 Surface (android.view.Surface)30 CameraAccessException (android.hardware.camera2.CameraAccessException)10 SurfaceTexture (android.graphics.SurfaceTexture)5 InputConfiguration (android.hardware.camera2.params.InputConfiguration)5 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)5 ServiceSpecificException (android.os.ServiceSpecificException)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 HashSet (java.util.HashSet)5