Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "media/capture/video/android/video_capture_device_android.h" | 5 #include "media/capture/video/android/video_capture_device_android.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 DCHECK_EQ(kConfigured, state_); | 382 DCHECK_EQ(kConfigured, state_); |
| 383 DCHECK(got_first_frame_); | 383 DCHECK(got_first_frame_); |
| 384 } | 384 } |
| 385 #endif | 385 #endif |
| 386 JNIEnv* env = AttachCurrentThread(); | 386 JNIEnv* env = AttachCurrentThread(); |
| 387 | 387 |
| 388 // Make copy on the heap so we can pass the pointer through JNI. | 388 // Make copy on the heap so we can pass the pointer through JNI. |
| 389 std::unique_ptr<TakePhotoCallback> heap_callback( | 389 std::unique_ptr<TakePhotoCallback> heap_callback( |
| 390 new TakePhotoCallback(std::move(callback))); | 390 new TakePhotoCallback(std::move(callback))); |
| 391 const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); | 391 const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); |
| 392 if (!Java_VideoCapture_takePhoto(env, j_capture_.obj(), callback_id, | 392 if (!Java_VideoCapture_takePhoto(env, j_capture_.obj(), callback_id)) |
| 393 next_photo_resolution_.width(), | |
| 394 next_photo_resolution_.height())) | |
| 395 return; | 393 return; |
| 396 | 394 |
| 397 { | 395 { |
| 398 base::AutoLock lock(photo_callbacks_lock_); | 396 base::AutoLock lock(photo_callbacks_lock_); |
| 399 photo_callbacks_.push_back(std::move(heap_callback)); | 397 photo_callbacks_.push_back(std::move(heap_callback)); |
| 400 } | 398 } |
| 401 } | 399 } |
| 402 | 400 |
| 403 void VideoCaptureDeviceAndroid::DoGetPhotoCapabilities( | 401 void VideoCaptureDeviceAndroid::DoGetPhotoCapabilities( |
| 404 GetPhotoCapabilitiesCallback callback) { | 402 GetPhotoCapabilitiesCallback callback) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 428 photo_capabilities->height->max = caps.getMaxHeight(); | 426 photo_capabilities->height->max = caps.getMaxHeight(); |
| 429 photo_capabilities->height->min = caps.getMinHeight(); | 427 photo_capabilities->height->min = caps.getMinHeight(); |
| 430 photo_capabilities->width = mojom::Range::New(); | 428 photo_capabilities->width = mojom::Range::New(); |
| 431 photo_capabilities->width->current = caps.getCurrentWidth(); | 429 photo_capabilities->width->current = caps.getCurrentWidth(); |
| 432 photo_capabilities->width->max = caps.getMaxWidth(); | 430 photo_capabilities->width->max = caps.getMaxWidth(); |
| 433 photo_capabilities->width->min = caps.getMinWidth(); | 431 photo_capabilities->width->min = caps.getMinWidth(); |
| 434 photo_capabilities->zoom = mojom::Range::New(); | 432 photo_capabilities->zoom = mojom::Range::New(); |
| 435 photo_capabilities->zoom->current = caps.getCurrentZoom(); | 433 photo_capabilities->zoom->current = caps.getCurrentZoom(); |
| 436 photo_capabilities->zoom->max = caps.getMaxZoom(); | 434 photo_capabilities->zoom->max = caps.getMaxZoom(); |
| 437 photo_capabilities->zoom->min = caps.getMinZoom(); | 435 photo_capabilities->zoom->min = caps.getMinZoom(); |
| 438 photo_capabilities->focus_mode = caps.getAutoFocusInUse() | 436 switch (caps.getFocusMode()) { |
| 439 ? mojom::FocusMode::AUTO | 437 case PhotoCapabilities::ANDROID_FOCUS_MODE_UNAVAILABLE: |
| 440 : mojom::FocusMode::MANUAL; | 438 photo_capabilities->focus_mode = mojom::FocusMode::UNAVAILABLE; |
| 439 break; | |
| 440 case PhotoCapabilities::ANDROID_FOCUS_MODE_FIXED: | |
| 441 photo_capabilities->focus_mode = mojom::FocusMode::MANUAL; | |
| 442 break; | |
| 443 case PhotoCapabilities::ANDROID_FOCUS_MODE_SINGLE_SHOT: | |
| 444 photo_capabilities->focus_mode = mojom::FocusMode::SINGLE_SHOT; | |
| 445 break; | |
| 446 case PhotoCapabilities::ANDROID_FOCUS_MODE_CONTINUOUS: | |
| 447 photo_capabilities->focus_mode = mojom::FocusMode::CONTINUOUS; | |
| 448 break; | |
| 449 default: | |
|
Reilly Grant (use Gerrit)
2016/08/15 20:28:18
Use an enum class and you won't need a default cas
mcasas
2016/08/15 21:08:54
Done.
| |
| 450 NOTREACHED(); | |
| 451 } | |
| 441 callback.Run(std::move(photo_capabilities)); | 452 callback.Run(std::move(photo_capabilities)); |
| 442 } | 453 } |
| 443 | 454 |
| 444 void VideoCaptureDeviceAndroid::DoSetPhotoOptions( | 455 void VideoCaptureDeviceAndroid::DoSetPhotoOptions( |
| 445 mojom::PhotoSettingsPtr settings, | 456 mojom::PhotoSettingsPtr settings, |
| 446 SetPhotoOptionsCallback callback) { | 457 SetPhotoOptionsCallback callback) { |
| 447 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 458 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 448 #if DCHECK_IS_ON() | 459 #if DCHECK_IS_ON() |
| 449 { | 460 { |
| 450 base::AutoLock lock(lock_); | 461 base::AutoLock lock(lock_); |
| 451 DCHECK_EQ(kConfigured, state_); | 462 DCHECK_EQ(kConfigured, state_); |
| 452 DCHECK(got_first_frame_); | 463 DCHECK(got_first_frame_); |
| 453 } | 464 } |
| 454 #endif | 465 #endif |
| 455 JNIEnv* env = AttachCurrentThread(); | 466 JNIEnv* env = AttachCurrentThread(); |
| 456 | 467 |
| 457 // |width| and/or |height| are kept for the next TakePhoto()s. | 468 const int width = settings->has_width ? settings->width : 0; |
| 458 if (settings->has_width || settings->has_height) | 469 const int height = settings->has_height ? settings->height : 0; |
| 459 next_photo_resolution_.SetSize(0, 0); | 470 const int zoom = settings->has_zoom ? settings->zoom : 0; |
| 460 if (settings->has_width) { | 471 |
| 461 next_photo_resolution_.set_width( | 472 PhotoCapabilities::AndroidFocusMode focus_mode = |
| 462 base::saturated_cast<int>(settings->width)); | 473 PhotoCapabilities::ANDROID_FOCUS_MODE_UNAVAILABLE; |
| 463 } | 474 if (settings->has_focus_mode) { |
| 464 if (settings->has_height) { | 475 switch (settings->focus_mode) { |
| 465 next_photo_resolution_.set_height( | 476 case mojom::FocusMode::MANUAL: |
| 466 base::saturated_cast<int>(settings->height)); | 477 focus_mode = PhotoCapabilities::ANDROID_FOCUS_MODE_FIXED; |
| 478 break; | |
| 479 case mojom::FocusMode::SINGLE_SHOT: | |
| 480 focus_mode = PhotoCapabilities::ANDROID_FOCUS_MODE_SINGLE_SHOT; | |
| 481 break; | |
| 482 case mojom::FocusMode::CONTINUOUS: | |
| 483 focus_mode = PhotoCapabilities::ANDROID_FOCUS_MODE_CONTINUOUS; | |
| 484 break; | |
| 485 case mojom::FocusMode::UNAVAILABLE: | |
| 486 focus_mode = PhotoCapabilities::ANDROID_FOCUS_MODE_UNAVAILABLE; | |
| 487 break; | |
| 488 default: | |
| 489 NOTREACHED(); | |
| 490 } | |
| 467 } | 491 } |
| 468 | 492 |
| 469 if (settings->has_zoom) | 493 Java_VideoCapture_setPhotoOptions(env, j_capture_.obj(), zoom, focus_mode, |
| 470 Java_VideoCapture_setZoom(env, j_capture_.obj(), settings->zoom); | 494 width, height); |
| 471 | 495 |
| 472 callback.Run(true); | 496 callback.Run(true); |
| 473 } | 497 } |
| 474 | 498 |
| 475 } // namespace media | 499 } // namespace media |
| OLD | NEW |