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.Rect; | 9 import android.graphics.Rect; |
10 import android.graphics.SurfaceTexture; | 10 import android.graphics.SurfaceTexture; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 maxZoom = parameters.getZoomRatios().get(parameters.getMaxZoom()); | 331 maxZoom = parameters.getZoomRatios().get(parameters.getMaxZoom()); |
332 currentZoom = 100 + 100 * parameters.getZoom(); | 332 currentZoom = 100 + 100 * parameters.getZoom(); |
333 minZoom = parameters.getZoomRatios().get(0); | 333 minZoom = parameters.getZoomRatios().get(0); |
334 } | 334 } |
335 | 335 |
336 Log.d(TAG, "parameters.getFocusMode(): %s", parameters.getFocusMode()); | 336 Log.d(TAG, "parameters.getFocusMode(): %s", parameters.getFocusMode()); |
337 final String focusMode = parameters.getFocusMode(); | 337 final String focusMode = parameters.getFocusMode(); |
338 | 338 |
339 // Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we ca
n call | 339 // Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we ca
n call |
340 // autoFocus(AutoFocusCallback) to configure region(s) to focus onto. | 340 // autoFocus(AutoFocusCallback) to configure region(s) to focus onto. |
341 int jniFocusMode = AndroidFocusMode.UNAVAILABLE; | 341 int jniFocusMode = AndroidMeteringMode.UNAVAILABLE; |
342 if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_CONTI
NUOUS_VIDEO) | 342 if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_CONTI
NUOUS_VIDEO) |
343 || focusMode.equals( | 343 || focusMode.equals( |
344 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINU
OUS_PICTURE) | 344 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINU
OUS_PICTURE) |
345 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_EDOF)) { | 345 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_EDOF)) { |
346 jniFocusMode = AndroidFocusMode.CONTINUOUS; | 346 jniFocusMode = AndroidMeteringMode.CONTINUOUS; |
347 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_AUTO) | 347 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_AUTO) |
348 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_MACRO)) { | 348 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_MACRO)) { |
349 jniFocusMode = AndroidFocusMode.SINGLE_SHOT; | 349 jniFocusMode = AndroidMeteringMode.SINGLE_SHOT; |
350 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_INFINITY) | 350 } else if (focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_INFINITY) |
351 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_FIXED)) { | 351 || focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MOD
E_FIXED)) { |
352 jniFocusMode = AndroidFocusMode.FIXED; | 352 jniFocusMode = AndroidMeteringMode.FIXED; |
353 } | 353 } |
354 | 354 |
| 355 // Exposure is usually continuously updated except it not available at a
ll, or if the |
| 356 // exposure compensation is locked, in which case we consider it as FIXE
D. |
| 357 int jniExposureMode = parameters.getMaxNumMeteringAreas() == 0 |
| 358 ? AndroidMeteringMode.UNAVAILABLE |
| 359 : AndroidMeteringMode.CONTINUOUS; |
| 360 if (parameters.isAutoExposureLockSupported() && parameters.getAutoExposu
reLock()) { |
| 361 jniExposureMode = AndroidMeteringMode.FIXED; |
| 362 } |
| 363 // TODO(mcasas): https://crbug.com/518807 read the exposure compensation
min and max |
| 364 // values using getMinExposureCompensation() and getMaxExposureCompensat
ion(). |
| 365 |
355 return new PhotoCapabilities(minIso, maxIso, currentIso, maxHeight, minH
eight, | 366 return new PhotoCapabilities(minIso, maxIso, currentIso, maxHeight, minH
eight, |
356 currentSize.height, maxWidth, minWidth, currentSize.width, maxZo
om, minZoom, | 367 currentSize.height, maxWidth, minWidth, currentSize.width, maxZo
om, minZoom, |
357 currentZoom, jniFocusMode); | 368 currentZoom, jniFocusMode, jniExposureMode); |
358 } | 369 } |
359 | 370 |
360 @Override | 371 @Override |
361 public void setPhotoOptions( | 372 public void setPhotoOptions(int zoom, int focusMode, int exposureMode, int w
idth, int height, |
362 int zoom, int focusMode, int width, int height, float[] pointsOfInte
rest2D) { | 373 float[] pointsOfInterest2D) { |
363 android.hardware.Camera.Parameters parameters = getCameraParameters(mCam
era); | 374 android.hardware.Camera.Parameters parameters = getCameraParameters(mCam
era); |
364 | 375 |
365 if (parameters.isZoomSupported() && zoom > 0) { | 376 if (parameters.isZoomSupported() && zoom > 0) { |
366 // |zoomRatios| is an ordered list; need the closest zoom index for
parameters.setZoom() | 377 // |zoomRatios| is an ordered list; need the closest zoom index for
parameters.setZoom() |
367 final List<Integer> zoomRatios = parameters.getZoomRatios(); | 378 final List<Integer> zoomRatios = parameters.getZoomRatios(); |
368 int i = 1; | 379 int i = 1; |
369 for (; i < zoomRatios.size(); ++i) { | 380 for (; i < zoomRatios.size(); ++i) { |
370 if (zoom < zoomRatios.get(i)) { | 381 if (zoom < zoomRatios.get(i)) { |
371 break; | 382 break; |
372 } | 383 } |
373 } | 384 } |
374 parameters.setZoom(i - 1); | 385 parameters.setZoom(i - 1); |
375 } | 386 } |
376 | 387 |
377 if (focusMode == AndroidFocusMode.FIXED) { | 388 if (focusMode == AndroidMeteringMode.FIXED) { |
378 parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MOD
E_FIXED); | 389 parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MOD
E_FIXED); |
379 } else if (focusMode == AndroidFocusMode.SINGLE_SHOT) { | 390 } else if (focusMode == AndroidMeteringMode.SINGLE_SHOT) { |
380 parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MOD
E_AUTO); | 391 parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MOD
E_AUTO); |
381 } else if (focusMode == AndroidFocusMode.CONTINUOUS) { | 392 } else if (focusMode == AndroidMeteringMode.CONTINUOUS) { |
382 parameters.setFocusMode( | 393 parameters.setFocusMode( |
383 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_PIC
TURE); | 394 android.hardware.Camera.Parameters.FOCUS_MODE_CONTINUOUS_PIC
TURE); |
384 } | 395 } |
| 396 |
| 397 if (parameters.isAutoExposureLockSupported()) { |
| 398 if (exposureMode == AndroidMeteringMode.FIXED) { |
| 399 parameters.setAutoExposureLock(true); |
| 400 } else if (exposureMode != AndroidMeteringMode.UNAVAILABLE) { |
| 401 parameters.setAutoExposureLock(false); |
| 402 } |
| 403 } |
| 404 // TODO(mcasas): https://crbug.com/518807 set the exposure compensation. |
| 405 |
385 if (width > 0) mPhotoWidth = width; | 406 if (width > 0) mPhotoWidth = width; |
386 if (height > 0) mPhotoHeight = height; | 407 if (height > 0) mPhotoHeight = height; |
387 | 408 |
388 // Upon new |zoom| configuration, clear up the previous |mAreaOfInterest
| if any. | 409 // Upon new |zoom| configuration, clear up the previous |mAreaOfInterest
| if any. |
389 if (mAreaOfInterest != null && !mAreaOfInterest.rect.isEmpty() && zoom >
0) { | 410 if (mAreaOfInterest != null && !mAreaOfInterest.rect.isEmpty() && zoom >
0) { |
390 mAreaOfInterest = null; | 411 mAreaOfInterest = null; |
391 } | 412 } |
| 413 // Also clear |mAreaOfInterest| if the user sets it as UNAVAILABLE. |
| 414 if (focusMode == AndroidMeteringMode.UNAVAILABLE |
| 415 || exposureMode == AndroidMeteringMode.UNAVAILABLE) { |
| 416 mAreaOfInterest = null; |
| 417 } |
392 | 418 |
393 // Update |mAreaOfInterest| if the camera supports and there are |points
OfInterest2D|. | 419 // Update |mAreaOfInterest| if the camera supports and there are |points
OfInterest2D|. |
394 if (parameters.getMaxNumMeteringAreas() > 0 && pointsOfInterest2D.length
> 0) { | 420 if (parameters.getMaxNumMeteringAreas() > 0 && pointsOfInterest2D.length
> 0) { |
395 assert pointsOfInterest2D.length == 1 : "Only 1 point of interest su
pported"; | 421 assert pointsOfInterest2D.length == 1 : "Only 1 point of interest su
pported"; |
396 assert pointsOfInterest2D[0] <= 1.0 && pointsOfInterest2D[0] >= 0.0; | 422 assert pointsOfInterest2D[0] <= 1.0 && pointsOfInterest2D[0] >= 0.0; |
397 assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; | 423 assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; |
398 // Calculate a Rect of 1/8 the canvas, which is fixed to Rect(-1000,
-1000, 1000, 1000), | 424 // Calculate a Rect of 1/8 the canvas, which is fixed to Rect(-1000,
-1000, 1000, 1000), |
399 // see https://developer.android.com/reference/android/hardware/Came
ra.Area.html | 425 // see https://developer.android.com/reference/android/hardware/Came
ra.Area.html |
400 final int centerX = Math.round(pointsOfInterest2D[0] * 2000) - 1000; | 426 final int centerX = Math.round(pointsOfInterest2D[0] * 2000) - 1000; |
401 final int centerY = Math.round(pointsOfInterest2D[1] * 2000) - 1000; | 427 final int centerY = Math.round(pointsOfInterest2D[1] * 2000) - 1000; |
402 final int regionWidth = 2000 / 8; | 428 final int regionWidth = 2000 / 8; |
403 final int regionHeight = 2000 / 8; | 429 final int regionHeight = 2000 / 8; |
404 final int weight = 1000; | 430 final int weight = 1000; |
405 | 431 |
406 mAreaOfInterest = new android.hardware.Camera.Area( | 432 mAreaOfInterest = new android.hardware.Camera.Area( |
407 new Rect(Math.max(-1000, centerX - regionWidth / 2), | 433 new Rect(Math.max(-1000, centerX - regionWidth / 2), |
408 Math.max(-1000, centerY - regionHeight / 2), | 434 Math.max(-1000, centerY - regionHeight / 2), |
409 Math.min(1000, centerX + regionWidth / 2), | 435 Math.min(1000, centerX + regionWidth / 2), |
410 Math.min(1000, centerY + regionHeight / 2)), | 436 Math.min(1000, centerY + regionHeight / 2)), |
411 weight); | 437 weight); |
412 | 438 |
413 Log.d(TAG, "Area of interest %s", mAreaOfInterest.rect.toString()); | 439 Log.d(TAG, "Area of interest %s", mAreaOfInterest.rect.toString()); |
414 } | 440 } |
415 if (mAreaOfInterest != null) { | 441 if (mAreaOfInterest != null) { |
416 parameters.setFocusAreas(Arrays.asList(mAreaOfInterest)); | 442 parameters.setFocusAreas(Arrays.asList(mAreaOfInterest)); |
| 443 parameters.setMeteringAreas(Arrays.asList(mAreaOfInterest)); |
417 } | 444 } |
418 | 445 |
419 mCamera.setParameters(parameters); | 446 mCamera.setParameters(parameters); |
420 | 447 |
421 if (focusMode != AndroidFocusMode.SINGLE_SHOT) return; | 448 if (focusMode != AndroidMeteringMode.SINGLE_SHOT) return; |
422 mCamera.autoFocus(new android.hardware.Camera.AutoFocusCallback() { | 449 mCamera.autoFocus(new android.hardware.Camera.AutoFocusCallback() { |
423 @Override | 450 @Override |
424 public void onAutoFocus(boolean success, android.hardware.Camera cam
era) { | 451 public void onAutoFocus(boolean success, android.hardware.Camera cam
era) { |
425 Log.d(TAG, "onAutoFocus() finished: %s ", success ? "success" :
"failed"); | 452 Log.d(TAG, "onAutoFocus() finished: %s ", success ? "success" :
"failed"); |
426 } | 453 } |
427 }); | 454 }); |
428 } | 455 } |
429 | 456 |
430 @Override | 457 @Override |
431 public boolean takePhoto(final long callbackId) { | 458 public boolean takePhoto(final long callbackId) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 530 |
504 // Local hook to allow derived classes to fill capture format and modify | 531 // Local hook to allow derived classes to fill capture format and modify |
505 // camera parameters as they see fit. | 532 // camera parameters as they see fit. |
506 abstract void setCaptureParameters(int width, int height, int frameRate, | 533 abstract void setCaptureParameters(int width, int height, int frameRate, |
507 android.hardware.Camera.Parameters cameraParameters); | 534 android.hardware.Camera.Parameters cameraParameters); |
508 | 535 |
509 // Local method to be overriden with the particular setPreviewCallback to be | 536 // Local method to be overriden with the particular setPreviewCallback to be |
510 // used in the implementations. | 537 // used in the implementations. |
511 abstract void setPreviewCallback(android.hardware.Camera.PreviewCallback cb)
; | 538 abstract void setPreviewCallback(android.hardware.Camera.PreviewCallback cb)
; |
512 } | 539 } |
OLD | NEW |