Java Code Examples for android.hardware.camera2.CameraCaptureSession#setRepeatingRequest()

The following examples show how to use android.hardware.camera2.CameraCaptureSession#setRepeatingRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraPluginActivity.java    From unity-android-native-camera with MIT License 5 votes vote down vote up
@Override
public void onConfigured(CameraCaptureSession session) {
    CameraPluginActivity.this._captureSession = session;
    try {
        session.setRepeatingRequest(createCaptureRequest(), null, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: OpenStrategy.java    From Chinese-number-gestures-recognition with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: CloseStrategy.java    From Chinese-number-gestures-recognition with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_OFF);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: AutoStrategy.java    From Chinese-number-gestures-recognition with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: KeepOpenStrategy.java    From Chinese-number-gestures-recognition with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_ON);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: OpenStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: CloseStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_OFF);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: AutoStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: KeepOpenStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_ON);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: Camera2Input.java    From EZFilter with MIT License 5 votes vote down vote up
@Override
public void onConfigured(CameraCaptureSession session) {
    mCameraCaptureSession = session;
    try {
        // 自动对焦
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        // 自动闪光灯
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        CaptureRequest previewRequest = mPreviewRequestBuilder.build();
        session.setRepeatingRequest(previewRequest, null, mPreviewHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: Camera2Session.java    From webrtc_android with MIT License 4 votes vote down vote up
@Override
public void onConfigured(CameraCaptureSession session) {
    checkIsOnCameraThread();
    Logging.d(TAG, "Camera capture session configured.");
    captureSession = session;
    try {
        /*
         * The viable options for video capture requests are:
         * TEMPLATE_PREVIEW: High frame rate is given priority over the highest-quality
         *   post-processing.
         * TEMPLATE_RECORD: Stable frame rate is used, and post-processing is set for recording
         *   quality.
         */
        final CaptureRequest.Builder captureRequestBuilder =
                cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
        // Set auto exposure fps range.
        captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
                new Range<Integer>(captureFormat.framerate.min / fpsUnitFactor,
                        captureFormat.framerate.max / fpsUnitFactor));
        captureRequestBuilder.set(
                CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
        captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
        chooseStabilizationMode(captureRequestBuilder);
        chooseFocusMode(captureRequestBuilder);

        captureRequestBuilder.addTarget(surface);
        session.setRepeatingRequest(
                captureRequestBuilder.build(), new CameraCaptureCallback(), cameraThreadHandler);
    } catch (CameraAccessException e) {
        reportError("Failed to start capture request. " + e);
        return;
    }

    surfaceTextureHelper.startListening((VideoFrame frame) -> {
        checkIsOnCameraThread();

        if (state != SessionState.RUNNING) {
            Logging.d(TAG, "Texture frame captured but camera is no longer running.");
            return;
        }

        if (!firstFrameReported) {
            firstFrameReported = true;
            final int startTimeMs =
                    (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - constructionTimeNs);
            camera2StartTimeMsHistogram.addSample(startTimeMs);
        }

        // Undo the mirror that the OS "helps" us with.
        // http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
        // Also, undo camera orientation, we report it as rotation instead.
        final VideoFrame modifiedFrame =
                new VideoFrame(CameraSession.createTextureBufferWithModifiedTransformMatrix(
                        (TextureBufferImpl) frame.getBuffer(),
                        /* mirror= */ isCameraFrontFacing,
                        /* rotation= */ -cameraOrientation),
                        /* rotation= */ getFrameOrientation(), frame.getTimestampNs());
        events.onFrameCaptured(Camera2Session.this, modifiedFrame);
        modifiedFrame.release();
    });
    Logging.d(TAG, "Camera device successfully started.");
    callback.onDone(Camera2Session.this);
}
 
Example 12
Source File: Camera2Session.java    From VideoCRE with MIT License 4 votes vote down vote up
@Override
public void onConfigured(CameraCaptureSession session) {
  checkIsOnCameraThread();
  Logging.d(TAG, "Camera capture session configured.");
  captureSession = session;
  try {
    /*
     * The viable options for video capture requests are:
     * TEMPLATE_PREVIEW: High frame rate is given priority over the highest-quality
     *   post-processing.
     * TEMPLATE_RECORD: Stable frame rate is used, and post-processing is set for recording
     *   quality.
     */
    final CaptureRequest.Builder captureRequestBuilder =
        cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
    // Set auto exposure fps range.
    captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,
        new Range<Integer>(captureFormat.framerate.min / fpsUnitFactor,
            captureFormat.framerate.max / fpsUnitFactor));
    captureRequestBuilder.set(
        CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
    captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
    chooseStabilizationMode(captureRequestBuilder);
    chooseFocusMode(captureRequestBuilder);

    captureRequestBuilder.addTarget(surface);
    if (mediaRecorderSurface != null) {
      Logging.d(TAG, "Add MediaRecorder surface to CaptureRequest.Builder");
      captureRequestBuilder.addTarget(mediaRecorderSurface);
    }
    session.setRepeatingRequest(
        captureRequestBuilder.build(), new CameraCaptureCallback(), cameraThreadHandler);
  } catch (CameraAccessException e) {
    reportError("Failed to start capture request. " + e);
    return;
  }

  surfaceTextureHelper.startListening(
      new SurfaceTextureHelper.OnTextureFrameAvailableListener() {
        @Override
        public void onTextureFrameAvailable(
            int oesTextureId, float[] transformMatrix, long timestampNs) {
          checkIsOnCameraThread();

          if (state != SessionState.RUNNING) {
            Logging.d(TAG, "Texture frame captured but camera is no longer running.");
            surfaceTextureHelper.returnTextureFrame();
            return;
          }

          if (!firstFrameReported) {
            firstFrameReported = true;
            final int startTimeMs =
                (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - constructionTimeNs);
            //camera2StartTimeMsHistogram.addSample(startTimeMs);
          }

          int rotation = getFrameOrientation();

          // make sure it appears in right orientation and flip using GlRectDrawer

          //if (isCameraFrontFacing) {
          //  // Undo the mirror that the OS "helps" us with.
          //  // http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
          //  transformMatrix = RendererCommon.multiplyMatrices(
          //      transformMatrix, RendererCommon.horizontalFlipMatrix());
          //}
          //
          //// Undo camera orientation - we report it as rotation instead.
          //transformMatrix =
          //    RendererCommon.rotateTextureMatrix(transformMatrix, -cameraOrientation);

          events.onTextureFrameCaptured(Camera2Session.this, captureFormat.width,
              captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs);
        }
      });
  Logging.d(TAG, "Camera device successfully started.");
  callback.onDone(Camera2Session.this);
}