| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 384 |
| 385 // Find closest supported format for |width| x |height| @ |framerate|. | 385 // Find closest supported format for |width| x |height| @ |framerate|. |
| 386 final android.hardware.Camera.Parameters parameters = camera.getParameters()
; | 386 final android.hardware.Camera.Parameters parameters = camera.getParameters()
; |
| 387 final List<CaptureFormat.FramerateRange> supportedFramerates = | 387 final List<CaptureFormat.FramerateRange> supportedFramerates = |
| 388 Camera1Enumerator.convertFramerates(parameters.getSupportedPreviewFpsRan
ge()); | 388 Camera1Enumerator.convertFramerates(parameters.getSupportedPreviewFpsRan
ge()); |
| 389 Logging.d(TAG, "Available fps ranges: " + supportedFramerates); | 389 Logging.d(TAG, "Available fps ranges: " + supportedFramerates); |
| 390 | 390 |
| 391 final CaptureFormat.FramerateRange fpsRange = | 391 final CaptureFormat.FramerateRange fpsRange = |
| 392 CameraEnumerationAndroid.getClosestSupportedFramerateRange(supportedFram
erates, framerate); | 392 CameraEnumerationAndroid.getClosestSupportedFramerateRange(supportedFram
erates, framerate); |
| 393 | 393 |
| 394 final Size previewSize = CameraEnumerationAndroid.getClosestSupportedSize( | 394 final List<Size> supportedPreviewSizes = |
| 395 Camera1Enumerator.convertSizes(parameters.getSupportedPreviewSizes()), w
idth, height); | 395 Camera1Enumerator.convertSizes(parameters.getSupportedPreviewSizes()); |
| 396 final Size previewSize = |
| 397 CameraEnumerationAndroid.getClosestSupportedSize(supportedPreviewSizes,
width, height); |
| 398 Logging.d(TAG, "Available preview sizes: " + supportedPreviewSizes); |
| 396 | 399 |
| 397 final CaptureFormat captureFormat = | 400 final CaptureFormat captureFormat = |
| 398 new CaptureFormat(previewSize.width, previewSize.height, fpsRange); | 401 new CaptureFormat(previewSize.width, previewSize.height, fpsRange); |
| 399 | 402 |
| 400 // Check if we are already using this capture format, then we don't need to
do anything. | 403 // Check if we are already using this capture format, then we don't need to
do anything. |
| 401 if (captureFormat.equals(this.captureFormat)) { | 404 if (captureFormat.equals(this.captureFormat)) { |
| 402 return; | 405 return; |
| 403 } | 406 } |
| 404 | 407 |
| 405 // Update camera parameters. | 408 // Update camera parameters. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 425 parameters.setPictureSize(pictureSize.width, pictureSize.height); | 428 parameters.setPictureSize(pictureSize.width, pictureSize.height); |
| 426 | 429 |
| 427 // Temporarily stop preview if it's already running. | 430 // Temporarily stop preview if it's already running. |
| 428 if (this.captureFormat != null) { | 431 if (this.captureFormat != null) { |
| 429 camera.stopPreview(); | 432 camera.stopPreview(); |
| 430 // Calling |setPreviewCallbackWithBuffer| with null should clear the inter
nal camera buffer | 433 // Calling |setPreviewCallbackWithBuffer| with null should clear the inter
nal camera buffer |
| 431 // queue, but sometimes we receive a frame with the old resolution after t
his call anyway. | 434 // queue, but sometimes we receive a frame with the old resolution after t
his call anyway. |
| 432 camera.setPreviewCallbackWithBuffer(null); | 435 camera.setPreviewCallbackWithBuffer(null); |
| 433 } | 436 } |
| 434 | 437 |
| 438 List<String> focusModes = parameters.getSupportedFocusModes(); |
| 439 if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_CONTIN
UOUS_VIDEO)) { |
| 440 Logging.d(TAG, "Enable continuous auto focus mode."); |
| 441 parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_CONT
INUOUS_VIDEO); |
| 442 } |
| 443 |
| 435 // (Re)start preview. | 444 // (Re)start preview. |
| 436 Logging.d(TAG, "Start capturing: " + captureFormat); | 445 Logging.d(TAG, "Start capturing: " + captureFormat); |
| 437 this.captureFormat = captureFormat; | 446 this.captureFormat = captureFormat; |
| 438 | 447 |
| 439 List<String> focusModes = parameters.getSupportedFocusModes(); | |
| 440 if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_CONTIN
UOUS_VIDEO)) { | |
| 441 parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_CONT
INUOUS_VIDEO); | |
| 442 } | |
| 443 | |
| 444 camera.setParameters(parameters); | 448 camera.setParameters(parameters); |
| 445 // Calculate orientation manually and send it as CVO instead. | 449 // Calculate orientation manually and send it as CVO instead. |
| 446 camera.setDisplayOrientation(0 /* degrees */); | 450 camera.setDisplayOrientation(0 /* degrees */); |
| 447 if (!isCapturingToTexture) { | 451 if (!isCapturingToTexture) { |
| 448 queuedBuffers.clear(); | 452 queuedBuffers.clear(); |
| 449 final int frameSize = captureFormat.frameSize(); | 453 final int frameSize = captureFormat.frameSize(); |
| 450 for (int i = 0; i < NUMBER_OF_CAPTURE_BUFFERS; ++i) { | 454 for (int i = 0; i < NUMBER_OF_CAPTURE_BUFFERS; ++i) { |
| 451 final ByteBuffer buffer = ByteBuffer.allocateDirect(frameSize); | 455 final ByteBuffer buffer = ByteBuffer.allocateDirect(frameSize); |
| 452 queuedBuffers.add(buffer.array()); | 456 queuedBuffers.add(buffer.array()); |
| 453 camera.addCallbackBuffer(buffer.array()); | 457 camera.addCallbackBuffer(buffer.array()); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 cameraStatistics.addFrame(); | 638 cameraStatistics.addFrame(); |
| 635 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, | 639 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, |
| 636 transformMatrix, rotation, timestampNs); | 640 transformMatrix, rotation, timestampNs); |
| 637 } | 641 } |
| 638 | 642 |
| 639 @Override | 643 @Override |
| 640 public boolean isScreencast() { | 644 public boolean isScreencast() { |
| 641 return false; | 645 return false; |
| 642 } | 646 } |
| 643 } | 647 } |
| OLD | NEW |