Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.media; | 5 package org.chromium.media; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.graphics.ImageFormat; | 9 import android.graphics.ImageFormat; |
| 10 import android.graphics.Rect; | 10 import android.graphics.Rect; |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 maxZoom = parameters.getZoomRatios().get(parameters.getMaxZoom()); | 479 maxZoom = parameters.getZoomRatios().get(parameters.getMaxZoom()); |
| 480 currentZoom = parameters.getZoomRatios().get(parameters.getZoom()); | 480 currentZoom = parameters.getZoomRatios().get(parameters.getZoom()); |
| 481 minZoom = parameters.getZoomRatios().get(0); | 481 minZoom = parameters.getZoomRatios().get(0); |
| 482 if (parameters.getZoomRatios().size() > 1) { | 482 if (parameters.getZoomRatios().size() > 1) { |
| 483 stepZoom = parameters.getZoomRatios().get(1) - parameters.getZoo mRatios().get(0); | 483 stepZoom = parameters.getZoomRatios().get(1) - parameters.getZoo mRatios().get(0); |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 builder.setMinZoom(minZoom).setMaxZoom(maxZoom); | 486 builder.setMinZoom(minZoom).setMaxZoom(maxZoom); |
| 487 builder.setCurrentZoom(currentZoom).setStepZoom(stepZoom); | 487 builder.setCurrentZoom(currentZoom).setStepZoom(stepZoom); |
| 488 | 488 |
| 489 Log.d(TAG, "parameters.getFocusMode(): %s", parameters.getFocusMode()); | 489 // Classify the Focus capabilities and state. In CONTINUOUS and SINGLE_S HOT, we can call |
| 490 // autoFocus(AutoFocusCallback) to configure region(s) to focus onto. | |
| 491 final List<String> focusModes = parameters.getSupportedFocusModes(); | |
| 492 assert focusModes != null : "getSupportedFocusModes() should never retur n null"; | |
| 493 ArrayList<Integer> jniFocusModes = new ArrayList<Integer>(0); | |
|
Reilly Grant (use Gerrit)
2017/04/10 18:01:48
Maybe specify an initial capacity of 3?
mcasas
2017/04/10 19:53:37
Done.
| |
| 494 if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_CO NTINUOUS_VIDEO) | |
| 495 || focusModes.contains( | |
| 496 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINU OUS_PICTURE) | |
| 497 || focusModes.contains(android.hardware.Camera.Parameters.FOCUS_ MODE_EDOF)) { | |
| 498 jniFocusModes.add(Integer.valueOf(AndroidMeteringMode.CONTINUOUS)); | |
| 499 } | |
| 500 // FOCUS_MODE_{AUTO,MACRO} do not imply continuously focusing: need auto Focus() trigger. | |
| 501 if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_AU TO) | |
| 502 || focusModes.contains(android.hardware.Camera.Parameters.FOCUS_ MODE_MACRO)) { | |
| 503 jniFocusModes.add(Integer.valueOf(AndroidMeteringMode.SINGLE_SHOT)); | |
| 504 } | |
| 505 if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_IN FINITY) | |
| 506 || focusModes.contains(android.hardware.Camera.Parameters.FOCUS_ MODE_FIXED)) { | |
| 507 jniFocusModes.add(Integer.valueOf(AndroidMeteringMode.FIXED)); | |
| 508 } | |
| 509 builder.setFocusModes(integerArrayListToArray(jniFocusModes)); | |
| 510 | |
| 490 final String focusMode = parameters.getFocusMode(); | 511 final String focusMode = parameters.getFocusMode(); |
| 491 | |
| 492 // Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we ca n call | |
| 493 // autoFocus(AutoFocusCallback) to configure region(s) to focus onto. | |
| 494 int jniFocusMode = AndroidMeteringMode.NONE; | 512 int jniFocusMode = AndroidMeteringMode.NONE; |
| 495 if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_CONTI NUOUS_VIDEO) | 513 if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_CONTI NUOUS_VIDEO) |
| 496 || focusMode.equals( | 514 || focusMode.equals( |
| 497 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINU OUS_PICTURE) | 515 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINU OUS_PICTURE) |
| 498 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_EDOF)) { | 516 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_EDOF)) { |
| 499 jniFocusMode = AndroidMeteringMode.CONTINUOUS; | 517 jniFocusMode = AndroidMeteringMode.CONTINUOUS; |
| 500 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_AUTO) | 518 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_AUTO) |
| 501 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_MACRO)) { | 519 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_MACRO)) { |
| 502 jniFocusMode = AndroidMeteringMode.SINGLE_SHOT; | 520 jniFocusMode = AndroidMeteringMode.SINGLE_SHOT; |
| 503 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_INFINITY) | 521 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_INFINITY) |
| 504 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_FIXED)) { | 522 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD E_FIXED)) { |
| 505 jniFocusMode = AndroidMeteringMode.FIXED; | 523 jniFocusMode = AndroidMeteringMode.FIXED; |
| 506 } | 524 } |
| 507 builder.setFocusMode(jniFocusMode); | 525 builder.setFocusMode(jniFocusMode); |
| 508 | 526 |
| 509 // Exposure is usually continuously updated except it not available at a ll, or if the | 527 // Auto Exposure is the usual capability and state, unless AE is not ava ilable at all, which |
| 510 // exposure compensation is locked, in which case we consider it as FIXE D. | 528 // is signalled by the absence of Metering Areas. Exposure Compensation can also support or |
| 511 int jniExposureMode = parameters.getMaxNumMeteringAreas() == 0 | 529 // be locked, this is equivalent to AndroidMeteringMode.FIXED. |
| 512 ? AndroidMeteringMode.NONE | 530 ArrayList<Integer> jniExposureModes = new ArrayList<Integer>(0); |
|
Reilly Grant (use Gerrit)
2017/04/10 18:01:48
2 here?
mcasas
2017/04/10 19:53:37
Done.
| |
| 513 : AndroidMeteringMode.CONTINUOUS; | 531 if (parameters.getMaxNumMeteringAreas() > 0) { |
| 532 jniExposureModes.add(AndroidMeteringMode.CONTINUOUS); | |
| 533 } | |
| 534 if (parameters.isAutoExposureLockSupported()) { | |
| 535 jniExposureModes.add(AndroidMeteringMode.FIXED); | |
| 536 } | |
| 537 builder.setExposureModes(integerArrayListToArray(jniExposureModes)); | |
| 538 | |
| 539 int jniExposureMode = AndroidMeteringMode.CONTINUOUS; | |
| 514 if (parameters.isAutoExposureLockSupported() && parameters.getAutoExposu reLock()) { | 540 if (parameters.isAutoExposureLockSupported() && parameters.getAutoExposu reLock()) { |
| 515 jniExposureMode = AndroidMeteringMode.FIXED; | 541 jniExposureMode = AndroidMeteringMode.FIXED; |
| 516 } | 542 } |
| 517 builder.setExposureMode(jniExposureMode); | 543 builder.setExposureMode(jniExposureMode); |
| 518 | 544 |
| 519 final float step = parameters.getExposureCompensationStep(); | 545 final float step = parameters.getExposureCompensationStep(); |
| 520 builder.setStepExposureCompensation(step); | 546 builder.setStepExposureCompensation(step); |
| 521 builder.setMinExposureCompensation(parameters.getMinExposureCompensation () * step); | 547 builder.setMinExposureCompensation(parameters.getMinExposureCompensation () * step); |
| 522 builder.setMaxExposureCompensation(parameters.getMaxExposureCompensation () * step); | 548 builder.setMaxExposureCompensation(parameters.getMaxExposureCompensation () * step); |
| 523 builder.setCurrentExposureCompensation(parameters.getExposureCompensatio n() * step); | 549 builder.setCurrentExposureCompensation(parameters.getExposureCompensatio n() * step); |
| 524 | 550 |
| 525 int jniWhiteBalanceMode = AndroidMeteringMode.NONE; | 551 ArrayList<Integer> jniWhiteBalanceModes = new ArrayList<Integer>(0); |
|
Reilly Grant (use Gerrit)
2017/04/10 18:01:48
2 here? (Though, since the default is 10 and we im
mcasas
2017/04/10 19:53:37
Done.
| |
| 526 if (parameters.isAutoWhiteBalanceLockSupported() | 552 List<String> whiteBalanceModes = parameters.getSupportedWhiteBalance(); |
| 527 && parameters.getSupportedWhiteBalance() != null) { | 553 if (whiteBalanceModes != null) { |
| 528 jniWhiteBalanceMode = parameters.getWhiteBalance() | 554 if (!whiteBalanceModes.isEmpty()) { |
| 529 == android.hardware.Camera.Parameters.WHITE_BALANCE_ AUTO | 555 // |!whiteBalanceModes| can have WHITE_BALANCE_AUTO and any valu e in |
|
Reilly Grant (use Gerrit)
2017/04/10 18:01:48
|whiteBalanceModes|
mcasas
2017/04/10 19:53:38
Done.
| |
| 530 ? AndroidMeteringMode.CONTINUOUS | 556 // |COLOR_TEMPERATURES_MAP|; they are all considered CONTINUOUS metering mode. |
| 531 : AndroidMeteringMode.FIXED; | 557 jniWhiteBalanceModes.add(AndroidMeteringMode.CONTINUOUS); |
| 558 } | |
| 559 if (parameters.isAutoWhiteBalanceLockSupported()) { | |
| 560 jniWhiteBalanceModes.add(AndroidMeteringMode.FIXED); | |
| 561 } | |
| 562 } | |
| 563 builder.setWhiteBalanceModes(integerArrayListToArray(jniWhiteBalanceMode s)); | |
| 564 | |
| 565 int jniWhiteBalanceMode = AndroidMeteringMode.CONTINUOUS; | |
| 566 if (parameters.isAutoWhiteBalanceLockSupported() && parameters.getAutoWh iteBalanceLock()) { | |
| 567 jniWhiteBalanceMode = AndroidMeteringMode.FIXED; | |
| 532 } | 568 } |
| 533 builder.setWhiteBalanceMode(jniWhiteBalanceMode); | 569 builder.setWhiteBalanceMode(jniWhiteBalanceMode); |
| 534 | 570 |
| 535 builder.setMinColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(0)); | 571 builder.setMinColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(0)); |
| 536 builder.setMaxColorTemperature( | 572 builder.setMaxColorTemperature( |
| 537 COLOR_TEMPERATURES_MAP.keyAt(COLOR_TEMPERATURES_MAP.size() - 1)) ; | 573 COLOR_TEMPERATURES_MAP.keyAt(COLOR_TEMPERATURES_MAP.size() - 1)) ; |
| 538 if (jniWhiteBalanceMode == AndroidMeteringMode.FIXED) { | 574 if (jniWhiteBalanceMode == AndroidMeteringMode.FIXED) { |
| 539 final int index = COLOR_TEMPERATURES_MAP.indexOfValue(parameters.get WhiteBalance()); | 575 final int index = COLOR_TEMPERATURES_MAP.indexOfValue(parameters.get WhiteBalance()); |
| 540 if (index >= 0) builder.setCurrentColorTemperature(COLOR_TEMPERATURE S_MAP.keyAt(index)); | 576 if (index >= 0) builder.setCurrentColorTemperature(COLOR_TEMPERATURE S_MAP.keyAt(index)); |
| 541 } | 577 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 554 if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MOD E_OFF)) { | 590 if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MOD E_OFF)) { |
| 555 modes.add(Integer.valueOf(AndroidFillLightMode.OFF)); | 591 modes.add(Integer.valueOf(AndroidFillLightMode.OFF)); |
| 556 } | 592 } |
| 557 if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MOD E_AUTO)) { | 593 if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MOD E_AUTO)) { |
| 558 modes.add(Integer.valueOf(AndroidFillLightMode.AUTO)); | 594 modes.add(Integer.valueOf(AndroidFillLightMode.AUTO)); |
| 559 } | 595 } |
| 560 if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MOD E_ON)) { | 596 if (flashModes.contains(android.hardware.Camera.Parameters.FLASH_MOD E_ON)) { |
| 561 modes.add(Integer.valueOf(AndroidFillLightMode.FLASH)); | 597 modes.add(Integer.valueOf(AndroidFillLightMode.FLASH)); |
| 562 } | 598 } |
| 563 | 599 |
| 564 int[] modesAsIntArray = new int[modes.size()]; | 600 builder.setFillLightModes(integerArrayListToArray(modes)); |
| 565 for (int i = 0; i < modes.size(); i++) modesAsIntArray[i] = modes.ge t(i).intValue(); | |
| 566 builder.setFillLightModes(modesAsIntArray); | |
| 567 } | 601 } |
| 568 | 602 |
| 569 return builder.build(); | 603 return builder.build(); |
| 570 } | 604 } |
| 571 | 605 |
| 572 @Override | 606 @Override |
| 573 public void setPhotoOptions(double zoom, int focusMode, int exposureMode, do uble width, | 607 public void setPhotoOptions(double zoom, int focusMode, int exposureMode, do uble width, |
| 574 double height, float[] pointsOfInterest2D, boolean hasExposureCompen sation, | 608 double height, float[] pointsOfInterest2D, boolean hasExposureCompen sation, |
| 575 double exposureCompensation, int whiteBalanceMode, double iso, | 609 double exposureCompensation, int whiteBalanceMode, double iso, |
| 576 boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMo de, | 610 boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMo de, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 } | 648 } |
| 615 // Also clear |mAreaOfInterest| if the user sets it as NONE. | 649 // Also clear |mAreaOfInterest| if the user sets it as NONE. |
| 616 if (focusMode == AndroidMeteringMode.NONE || exposureMode == AndroidMete ringMode.NONE) { | 650 if (focusMode == AndroidMeteringMode.NONE || exposureMode == AndroidMete ringMode.NONE) { |
| 617 mAreaOfInterest = null; | 651 mAreaOfInterest = null; |
| 618 } | 652 } |
| 619 | 653 |
| 620 // Update |mAreaOfInterest| if the camera supports and there are |points OfInterest2D|. | 654 // Update |mAreaOfInterest| if the camera supports and there are |points OfInterest2D|. |
| 621 final boolean pointsOfInterestSupported = | 655 final boolean pointsOfInterestSupported = |
| 622 parameters.getMaxNumMeteringAreas() > 0 || parameters.getMaxNumF ocusAreas() > 0; | 656 parameters.getMaxNumMeteringAreas() > 0 || parameters.getMaxNumF ocusAreas() > 0; |
| 623 if (pointsOfInterestSupported && pointsOfInterest2D.length > 0) { | 657 if (pointsOfInterestSupported && pointsOfInterest2D.length > 0) { |
| 624 assert pointsOfInterest2D.length == 1 : "Only 1 point of interest su pported"; | 658 assert pointsOfInterest2D.length == 2 : "Only 1 point of interest su pported"; |
| 625 assert pointsOfInterest2D[0] <= 1.0 && pointsOfInterest2D[0] >= 0.0; | 659 assert pointsOfInterest2D[0] <= 1.0 && pointsOfInterest2D[0] >= 0.0; |
| 626 assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; | 660 assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; |
| 627 // Calculate a Rect of 1/8 the canvas, which is fixed to Rect(-1000, -1000, 1000, 1000), | 661 // Calculate a Rect of 1/8 the canvas, which is fixed to Rect(-1000, -1000, 1000, 1000), |
| 628 // see https://developer.android.com/reference/android/hardware/Came ra.Area.html | 662 // see https://developer.android.com/reference/android/hardware/Came ra.Area.html |
| 629 final int centerX = Math.round(pointsOfInterest2D[0] * 2000) - 1000; | 663 final int centerX = Math.round(pointsOfInterest2D[0] * 2000) - 1000; |
| 630 final int centerY = Math.round(pointsOfInterest2D[1] * 2000) - 1000; | 664 final int centerY = Math.round(pointsOfInterest2D[1] * 2000) - 1000; |
| 631 final int regionWidth = 2000 / 8; | 665 final int regionWidth = 2000 / 8; |
| 632 final int regionHeight = 2000 / 8; | 666 final int regionHeight = 2000 / 8; |
| 633 final int weight = 1000; | 667 final int weight = 1000; |
| 634 | 668 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 getCameraRotation()); | 825 getCameraRotation()); |
| 792 } | 826 } |
| 793 } finally { | 827 } finally { |
| 794 mPreviewBufferLock.unlock(); | 828 mPreviewBufferLock.unlock(); |
| 795 if (camera != null) { | 829 if (camera != null) { |
| 796 camera.addCallbackBuffer(data); | 830 camera.addCallbackBuffer(data); |
| 797 } | 831 } |
| 798 } | 832 } |
| 799 } | 833 } |
| 800 } | 834 } |
| OLD | NEW |