Search in sources :

Example 56 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraCaptureSessionImpl method captureBurst.

@Override
public synchronized int captureBurst(List<CaptureRequest> requests, CaptureCallback callback, Handler handler) throws CameraAccessException {
    if (requests == null) {
        throw new IllegalArgumentException("Requests must not be null");
    } else if (requests.isEmpty()) {
        throw new IllegalArgumentException("Requests must have at least one element");
    }
    for (CaptureRequest request : requests) {
        if (request.isReprocess()) {
            if (!isReprocessable()) {
                throw new IllegalArgumentException("This capture session cannot handle " + "reprocess requests");
            } else if (request.getReprocessableSessionId() != mId) {
                throw new IllegalArgumentException("Capture request was created for another " + "session");
            }
        }
    }
    checkNotClosed();
    handler = checkHandler(handler, callback);
    if (DEBUG) {
        CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
        Log.v(TAG, mIdString + "captureBurst - requests " + Arrays.toString(requestArray) + ", callback " + callback + " handler " + handler);
    }
    return addPendingSequence(mDeviceImpl.captureBurst(requests, createCaptureCallbackProxy(handler, callback), mDeviceHandler));
}
Also used : CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 57 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraConstrainedHighSpeedCaptureSessionImpl method createHighSpeedRequestList.

@Override
public List<CaptureRequest> createHighSpeedRequestList(CaptureRequest request) throws CameraAccessException {
    if (request == null) {
        throw new IllegalArgumentException("Input capture request must not be null");
    }
    Collection<Surface> outputSurfaces = request.getTargets();
    Range<Integer> fpsRange = request.get(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE);
    StreamConfigurationMap config = mCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    SurfaceUtils.checkConstrainedHighSpeedSurfaces(outputSurfaces, fpsRange, config);
    // Request list size: to limit the preview to 30fps, need use maxFps/30; to maximize
    // the preview frame rate, should use maxBatch size for that high speed stream
    // configuration. We choose the former for now.
    int requestListSize = fpsRange.getUpper() / 30;
    List<CaptureRequest> requestList = new ArrayList<CaptureRequest>();
    // Prepare the Request builders: need carry over the request controls.
    // First, create a request builder that will only include preview or recording target.
    CameraMetadataNative requestMetadata = new CameraMetadataNative(request.getNativeCopy());
    // Note that after this step, the requestMetadata is mutated (swapped) and can not be used
    // for next request builder creation.
    CaptureRequest.Builder singleTargetRequestBuilder = new CaptureRequest.Builder(requestMetadata, /*reprocess*/
    false, CameraCaptureSession.SESSION_ID_NONE);
    // Overwrite the capture intent to make sure a good value is set.
    Iterator<Surface> iterator = outputSurfaces.iterator();
    Surface firstSurface = iterator.next();
    Surface secondSurface = null;
    if (outputSurfaces.size() == 1 && SurfaceUtils.isSurfaceForHwVideoEncoder(firstSurface)) {
        singleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);
    } else {
        // Video only, or preview + video
        singleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
    }
    singleTargetRequestBuilder.setPartOfCHSRequestList(/*partOfCHSList*/
    true);
    // Second, Create a request builder that will include both preview and recording targets.
    CaptureRequest.Builder doubleTargetRequestBuilder = null;
    if (outputSurfaces.size() == 2) {
        // Have to create a new copy, the original one was mutated after a new
        // CaptureRequest.Builder creation.
        requestMetadata = new CameraMetadataNative(request.getNativeCopy());
        doubleTargetRequestBuilder = new CaptureRequest.Builder(requestMetadata, /*reprocess*/
        false, CameraCaptureSession.SESSION_ID_NONE);
        doubleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
        doubleTargetRequestBuilder.addTarget(firstSurface);
        secondSurface = iterator.next();
        doubleTargetRequestBuilder.addTarget(secondSurface);
        doubleTargetRequestBuilder.setPartOfCHSRequestList(/*partOfCHSList*/
        true);
        // Make sure singleTargetRequestBuilder contains only recording surface for
        // preview + recording case.
        Surface recordingSurface = firstSurface;
        if (!SurfaceUtils.isSurfaceForHwVideoEncoder(recordingSurface)) {
            recordingSurface = secondSurface;
        }
        singleTargetRequestBuilder.addTarget(recordingSurface);
    } else {
        // Single output case: either recording or preview.
        singleTargetRequestBuilder.addTarget(firstSurface);
    }
    // Generate the final request list.
    for (int i = 0; i < requestListSize; i++) {
        if (i == 0 && doubleTargetRequestBuilder != null) {
            // First request should be recording + preview request
            requestList.add(doubleTargetRequestBuilder.build());
        } else {
            requestList.add(singleTargetRequestBuilder.build());
        }
    }
    return Collections.unmodifiableList(requestList);
}
Also used : ArrayList(java.util.ArrayList) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) Surface(android.view.Surface) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 58 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceImpl method submitCaptureRequest.

private int submitCaptureRequest(List<CaptureRequest> requestList, CaptureCallback callback, Handler handler, boolean repeating) throws CameraAccessException {
    // Need a valid handler, or current thread needs to have a looper, if
    // callback is valid
    handler = checkHandler(handler, callback);
    // Make sure that there all requests have at least 1 surface; all surfaces are non-null
    for (CaptureRequest request : requestList) {
        if (request.getTargets().isEmpty()) {
            throw new IllegalArgumentException("Each request must have at least one Surface target");
        }
        for (Surface surface : request.getTargets()) {
            if (surface == null) {
                throw new IllegalArgumentException("Null Surface targets are not allowed");
            }
        }
    }
    synchronized (mInterfaceLock) {
        checkIfCameraClosedOrInError();
        if (repeating) {
            stopRepeating();
        }
        SubmitInfo requestInfo;
        CaptureRequest[] requestArray = requestList.toArray(new CaptureRequest[requestList.size()]);
        requestInfo = mRemoteDevice.submitRequestList(requestArray, repeating);
        if (DEBUG) {
            Log.v(TAG, "last frame number " + requestInfo.getLastFrameNumber());
        }
        if (callback != null) {
            mCaptureCallbackMap.put(requestInfo.getRequestId(), new CaptureCallbackHolder(callback, requestList, handler, repeating, mNextSessionId - 1));
        } else {
            if (DEBUG) {
                Log.d(TAG, "Listen for request " + requestInfo.getRequestId() + " is null");
            }
        }
        if (repeating) {
            if (mRepeatingRequestId != REQUEST_ID_NONE) {
                checkEarlyTriggerSequenceComplete(mRepeatingRequestId, requestInfo.getLastFrameNumber());
            }
            mRepeatingRequestId = requestInfo.getRequestId();
        } else {
            mRequestLastFrameNumbersList.add(new RequestLastFrameNumbersHolder(requestList, requestInfo));
        }
        if (mIdle) {
            mDeviceHandler.post(mCallOnActive);
        }
        mIdle = false;
        return requestInfo.getRequestId();
    }
}
Also used : SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Example 59 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceImpl method setRemoteDevice.

/**
     * Set remote device, which triggers initial onOpened/onUnconfigured callbacks
     *
     * <p>This function may post onDisconnected and throw CAMERA_DISCONNECTED if remoteDevice dies
     * during setup.</p>
     *
     */
public void setRemoteDevice(ICameraDeviceUser remoteDevice) throws CameraAccessException {
    synchronized (mInterfaceLock) {
        // If setRemoteFailure already called, do nothing
        if (mInError)
            return;
        mRemoteDevice = new ICameraDeviceUserWrapper(remoteDevice);
        IBinder remoteDeviceBinder = remoteDevice.asBinder();
        // asBinder returns NULL.
        if (remoteDeviceBinder != null) {
            try {
                remoteDeviceBinder.linkToDeath(this, /*flag*/
                0);
            } catch (RemoteException e) {
                CameraDeviceImpl.this.mDeviceHandler.post(mCallOnDisconnected);
                throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "The camera device has encountered a serious error");
            }
        }
        mDeviceHandler.post(mCallOnOpened);
        mDeviceHandler.post(mCallOnUnconfigured);
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) IBinder(android.os.IBinder) RemoteException(android.os.RemoteException)

Example 60 with CameraAccessException

use of android.hardware.camera2.CameraAccessException in project streaming-android by red5pro.

the class PublishCamera2Test method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.publish_test, container, false);
    preview = (R5VideoView) rootView.findViewById(R.id.videoPreview);
    String b = getActivity().getPackageName();
    // Create the configuration from the values.xml
    R5Configuration config = new R5Configuration(R5StreamProtocol.RTSP, TestContent.GetPropertyString("host"), TestContent.GetPropertyInt("port"), TestContent.GetPropertyString("context"), TestContent.GetPropertyFloat("publish_buffer_time"));
    config.setLicenseKey(TestContent.GetPropertyString("license_key"));
    config.setBundleID(b);
    R5Connection connection = new R5Connection(config);
    // setup a new stream using the connection
    publish = new R5Stream(connection);
    publish.audioController.sampleRate = TestContent.GetPropertyInt("sample_rate");
    // show all logging
    publish.setLogLevel(R5Stream.LOG_LEVEL_DEBUG);
    if (TestContent.GetPropertyBool("audio_on")) {
        // attach a microphone
        R5Microphone mic = new R5Microphone();
        publish.attachMic(mic);
    }
    preview.attachStream(publish);
    CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
    try {
        String[] camList = manager.getCameraIdList();
        for (String id : camList) {
            CameraCharacteristics info = manager.getCameraCharacteristics(id);
            if (info.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
                camOrientation = info.get(CameraCharacteristics.SENSOR_ORIENTATION);
                camInfo = info;
                manager.openCamera(id, new CameraDevice.StateCallback() {

                    @Override
                    public void onOpened(@NonNull CameraDevice camera) {
                        if (preview == null)
                            return;
                        startPublish(camera);
                    }

                    @Override
                    public void onDisconnected(@NonNull CameraDevice camera) {
                    }

                    @Override
                    public void onError(@NonNull CameraDevice camera, int error) {
                    }
                }, null);
                break;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    return rootView;
}
Also used : R5Microphone(com.red5pro.streaming.source.R5Microphone) CameraDevice(android.hardware.camera2.CameraDevice) R5Stream(com.red5pro.streaming.R5Stream) CameraManager(android.hardware.camera2.CameraManager) ImageView(android.widget.ImageView) R5VideoView(com.red5pro.streaming.view.R5VideoView) View(android.view.View) CameraAccessException(android.hardware.camera2.CameraAccessException) R5Configuration(com.red5pro.streaming.config.R5Configuration) R5Connection(com.red5pro.streaming.R5Connection) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics)

Aggregations

ArrayList (java.util.ArrayList)50 Surface (android.view.Surface)42 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)40 CameraAccessException (android.hardware.camera2.CameraAccessException)35 CaptureRequest (android.hardware.camera2.CaptureRequest)35 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)25 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)21 RemoteException (android.os.RemoteException)15 BlockingSessionCallback (com.android.ex.camera2.blocking.BlockingSessionCallback)14 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)12 Size (android.util.Size)11 ICameraService (android.hardware.ICameraService)10 CaptureCallback (android.hardware.camera2.CameraCaptureSession.CaptureCallback)10 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)10 ServiceSpecificException (android.os.ServiceSpecificException)10 CameraManager (android.hardware.camera2.CameraManager)6 NonNull (android.annotation.NonNull)5 CameraInfo (android.hardware.CameraInfo)5 InputConfiguration (android.hardware.camera2.params.InputConfiguration)5 SubmitInfo (android.hardware.camera2.utils.SubmitInfo)5