| 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 Logging.e(TAG, "Calling startPreviewOnCameraThread on stopped camera."); | 407 Logging.e(TAG, "Calling startPreviewOnCameraThread on stopped camera."); |
| 408 return; | 408 return; |
| 409 } | 409 } |
| 410 | 410 |
| 411 requestedWidth = width; | 411 requestedWidth = width; |
| 412 requestedHeight = height; | 412 requestedHeight = height; |
| 413 requestedFramerate = framerate; | 413 requestedFramerate = framerate; |
| 414 | 414 |
| 415 // Find closest supported format for |width| x |height| @ |framerate|. | 415 // Find closest supported format for |width| x |height| @ |framerate|. |
| 416 final android.hardware.Camera.Parameters parameters = camera.getParameters()
; | 416 final android.hardware.Camera.Parameters parameters = camera.getParameters()
; |
| 417 for (int[] fpsRange : parameters.getSupportedPreviewFpsRange()) { | 417 final List<CaptureFormat.FramerateRange> supportedFramerates = |
| 418 Logging.d(TAG, "Available fps range: " + | 418 CameraEnumerator.convertFramerates(parameters.getSupportedPreviewFpsRang
e()); |
| 419 fpsRange[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX] + "
:" + | 419 Logging.d(TAG, "Available fps ranges: " + supportedFramerates); |
| 420 fpsRange[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); | 420 |
| 421 final CaptureFormat.FramerateRange bestFpsRange; |
| 422 if (supportedFramerates.isEmpty()) { |
| 423 Logging.w(TAG, "No supported preview fps range"); |
| 424 bestFpsRange = new CaptureFormat.FramerateRange(0, 0); |
| 425 } else { |
| 426 bestFpsRange = CameraEnumerationAndroid.getClosestSupportedFramerateRange( |
| 427 supportedFramerates, framerate); |
| 421 } | 428 } |
| 422 final int[] range = CameraEnumerationAndroid.getFramerateRange(parameters, f
ramerate * 1000); | 429 |
| 423 final android.hardware.Camera.Size previewSize = | 430 final android.hardware.Camera.Size previewSize = |
| 424 CameraEnumerationAndroid.getClosestSupportedSize( | 431 CameraEnumerationAndroid.getClosestSupportedSize( |
| 425 parameters.getSupportedPreviewSizes(), width, height); | 432 parameters.getSupportedPreviewSizes(), width, height); |
| 426 final CaptureFormat captureFormat = new CaptureFormat( | 433 final CaptureFormat captureFormat = new CaptureFormat( |
| 427 previewSize.width, previewSize.height, | 434 previewSize.width, previewSize.height, bestFpsRange); |
| 428 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX], | |
| 429 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); | |
| 430 | 435 |
| 431 // Check if we are already using this capture format, then we don't need to
do anything. | 436 // Check if we are already using this capture format, then we don't need to
do anything. |
| 432 if (captureFormat.isSameFormat(this.captureFormat)) { | 437 if (captureFormat.isSameFormat(this.captureFormat)) { |
| 433 return; | 438 return; |
| 434 } | 439 } |
| 435 | 440 |
| 436 // Update camera parameters. | 441 // Update camera parameters. |
| 437 Logging.d(TAG, "isVideoStabilizationSupported: " + | 442 Logging.d(TAG, "isVideoStabilizationSupported: " + |
| 438 parameters.isVideoStabilizationSupported()); | 443 parameters.isVideoStabilizationSupported()); |
| 439 if (parameters.isVideoStabilizationSupported()) { | 444 if (parameters.isVideoStabilizationSupported()) { |
| 440 parameters.setVideoStabilization(true); | 445 parameters.setVideoStabilization(true); |
| 441 } | 446 } |
| 442 // Note: setRecordingHint(true) actually decrease frame rate on N5. | 447 // Note: setRecordingHint(true) actually decrease frame rate on N5. |
| 443 // parameters.setRecordingHint(true); | 448 // parameters.setRecordingHint(true); |
| 444 if (captureFormat.maxFramerate > 0) { | 449 if (captureFormat.framerate.max > 0) { |
| 445 parameters.setPreviewFpsRange(captureFormat.minFramerate, captureFormat.ma
xFramerate); | 450 parameters.setPreviewFpsRange(captureFormat.framerate.min, captureFormat.f
ramerate.max); |
| 446 } | 451 } |
| 447 parameters.setPreviewSize(captureFormat.width, captureFormat.height); | 452 parameters.setPreviewSize(captureFormat.width, captureFormat.height); |
| 448 | 453 |
| 449 if (!isCapturingToTexture) { | 454 if (!isCapturingToTexture) { |
| 450 parameters.setPreviewFormat(captureFormat.imageFormat); | 455 parameters.setPreviewFormat(captureFormat.imageFormat); |
| 451 } | 456 } |
| 452 // Picture size is for taking pictures and not for preview/video, but we nee
d to set it anyway | 457 // Picture size is for taking pictures and not for preview/video, but we nee
d to set it anyway |
| 453 // as a workaround for an aspect ratio problem on Nexus 7. | 458 // as a workaround for an aspect ratio problem on Nexus 7. |
| 454 final android.hardware.Camera.Size pictureSize = | 459 final android.hardware.Camera.Size pictureSize = |
| 455 CameraEnumerationAndroid.getClosestSupportedSize( | 460 CameraEnumerationAndroid.getClosestSupportedSize( |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // Undo the mirror that the OS "helps" us with. | 664 // Undo the mirror that the OS "helps" us with. |
| 660 // http://developer.android.com/reference/android/hardware/Camera.html#set
DisplayOrientation(int) | 665 // http://developer.android.com/reference/android/hardware/Camera.html#set
DisplayOrientation(int) |
| 661 transformMatrix = | 666 transformMatrix = |
| 662 RendererCommon.multiplyMatrices(transformMatrix, RendererCommon.horizo
ntalFlipMatrix()); | 667 RendererCommon.multiplyMatrices(transformMatrix, RendererCommon.horizo
ntalFlipMatrix()); |
| 663 } | 668 } |
| 664 cameraStatistics.addFrame(); | 669 cameraStatistics.addFrame(); |
| 665 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, | 670 frameObserver.onTextureFrameCaptured(captureFormat.width, captureFormat.heig
ht, oesTextureId, |
| 666 transformMatrix, rotation, timestampNs); | 671 transformMatrix, rotation, timestampNs); |
| 667 } | 672 } |
| 668 } | 673 } |
| OLD | NEW |