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 11 matching lines...) Expand all Loading... | |
| 22 using base::android::AttachCurrentThread; | 22 using base::android::AttachCurrentThread; |
| 23 using base::android::CheckException; | 23 using base::android::CheckException; |
| 24 using base::android::GetClass; | 24 using base::android::GetClass; |
| 25 using base::android::JavaParamRef; | 25 using base::android::JavaParamRef; |
| 26 using base::android::MethodID; | 26 using base::android::MethodID; |
| 27 using base::android::JavaRef; | 27 using base::android::JavaRef; |
| 28 using base::android::ScopedJavaLocalRef; | 28 using base::android::ScopedJavaLocalRef; |
| 29 | 29 |
| 30 namespace media { | 30 namespace media { |
| 31 | 31 |
| 32 namespace { | |
| 33 | |
| 34 mojom::MeteringMode ToMojomMeteringMode( | |
| 35 PhotoCapabilities::AndroidMeteringMode android_mode) { | |
| 36 if (android_mode == PhotoCapabilities::AndroidMeteringMode::FIXED) | |
| 37 return mojom::MeteringMode::MANUAL; | |
| 38 else if (android_mode == PhotoCapabilities::AndroidMeteringMode::SINGLE_SHOT) | |
| 39 return mojom::MeteringMode::SINGLE_SHOT; | |
| 40 else if (android_mode == PhotoCapabilities::AndroidMeteringMode::CONTINUOUS) | |
| 41 return mojom::MeteringMode::CONTINUOUS; | |
| 42 return mojom::MeteringMode::UNAVAILABLE; | |
| 43 } | |
| 44 | |
| 45 PhotoCapabilities::AndroidMeteringMode ToAndroidMeteringMode( | |
| 46 mojom::MeteringMode mojom_mode) { | |
| 47 if (mojom_mode == mojom::MeteringMode::MANUAL) | |
| 48 return PhotoCapabilities::AndroidMeteringMode::FIXED; | |
| 49 else if (mojom_mode == mojom::MeteringMode::SINGLE_SHOT) | |
| 50 return PhotoCapabilities::AndroidMeteringMode::SINGLE_SHOT; | |
| 51 else if (mojom_mode == mojom::MeteringMode::CONTINUOUS) | |
| 52 return PhotoCapabilities::AndroidMeteringMode::CONTINUOUS; | |
| 53 return PhotoCapabilities::AndroidMeteringMode::UNAVAILABLE; | |
| 54 } | |
|
Reilly Grant (use Gerrit)
2016/08/24 18:14:03
Use switch statements for these functions?
mcasas
2016/08/24 18:36:23
Ooops yes, done.
| |
| 55 | |
| 56 } // anonymous namespace | |
| 57 | |
| 32 // static | 58 // static |
| 33 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { | 59 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { |
| 34 return RegisterNativesImpl(env); | 60 return RegisterNativesImpl(env); |
| 35 } | 61 } |
| 36 | 62 |
| 37 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid( | 63 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid( |
| 38 const VideoCaptureDeviceDescriptor& device_descriptor) | 64 const VideoCaptureDeviceDescriptor& device_descriptor) |
| 39 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 65 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 40 state_(kIdle), | 66 state_(kIdle), |
| 41 got_first_frame_(false), | 67 got_first_frame_(false), |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 photo_capabilities->height->max = caps.getMaxHeight(); | 453 photo_capabilities->height->max = caps.getMaxHeight(); |
| 428 photo_capabilities->height->min = caps.getMinHeight(); | 454 photo_capabilities->height->min = caps.getMinHeight(); |
| 429 photo_capabilities->width = mojom::Range::New(); | 455 photo_capabilities->width = mojom::Range::New(); |
| 430 photo_capabilities->width->current = caps.getCurrentWidth(); | 456 photo_capabilities->width->current = caps.getCurrentWidth(); |
| 431 photo_capabilities->width->max = caps.getMaxWidth(); | 457 photo_capabilities->width->max = caps.getMaxWidth(); |
| 432 photo_capabilities->width->min = caps.getMinWidth(); | 458 photo_capabilities->width->min = caps.getMinWidth(); |
| 433 photo_capabilities->zoom = mojom::Range::New(); | 459 photo_capabilities->zoom = mojom::Range::New(); |
| 434 photo_capabilities->zoom->current = caps.getCurrentZoom(); | 460 photo_capabilities->zoom->current = caps.getCurrentZoom(); |
| 435 photo_capabilities->zoom->max = caps.getMaxZoom(); | 461 photo_capabilities->zoom->max = caps.getMaxZoom(); |
| 436 photo_capabilities->zoom->min = caps.getMinZoom(); | 462 photo_capabilities->zoom->min = caps.getMinZoom(); |
| 437 switch (caps.getFocusMode()) { | 463 photo_capabilities->focus_mode = ToMojomMeteringMode(caps.getFocusMode()); |
| 438 case PhotoCapabilities::AndroidFocusMode::UNAVAILABLE: | 464 photo_capabilities->exposure_mode = |
| 439 photo_capabilities->focus_mode = mojom::FocusMode::UNAVAILABLE; | 465 ToMojomMeteringMode(caps.getExposureMode()); |
| 440 break; | 466 |
| 441 case PhotoCapabilities::AndroidFocusMode::FIXED: | |
| 442 photo_capabilities->focus_mode = mojom::FocusMode::MANUAL; | |
| 443 break; | |
| 444 case PhotoCapabilities::AndroidFocusMode::SINGLE_SHOT: | |
| 445 photo_capabilities->focus_mode = mojom::FocusMode::SINGLE_SHOT; | |
| 446 break; | |
| 447 case PhotoCapabilities::AndroidFocusMode::CONTINUOUS: | |
| 448 photo_capabilities->focus_mode = mojom::FocusMode::CONTINUOUS; | |
| 449 break; | |
| 450 } | |
| 451 callback.Run(std::move(photo_capabilities)); | 467 callback.Run(std::move(photo_capabilities)); |
| 452 } | 468 } |
| 453 | 469 |
| 454 void VideoCaptureDeviceAndroid::DoSetPhotoOptions( | 470 void VideoCaptureDeviceAndroid::DoSetPhotoOptions( |
| 455 mojom::PhotoSettingsPtr settings, | 471 mojom::PhotoSettingsPtr settings, |
| 456 SetPhotoOptionsCallback callback) { | 472 SetPhotoOptionsCallback callback) { |
| 457 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 473 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 458 #if DCHECK_IS_ON() | 474 #if DCHECK_IS_ON() |
| 459 { | 475 { |
| 460 base::AutoLock lock(lock_); | 476 base::AutoLock lock(lock_); |
| 461 DCHECK_EQ(kConfigured, state_); | 477 DCHECK_EQ(kConfigured, state_); |
| 462 DCHECK(got_first_frame_); | 478 DCHECK(got_first_frame_); |
| 463 } | 479 } |
| 464 #endif | 480 #endif |
| 465 JNIEnv* env = AttachCurrentThread(); | 481 JNIEnv* env = AttachCurrentThread(); |
| 466 | 482 |
| 467 const int width = settings->has_width ? settings->width : 0; | 483 const int width = settings->has_width ? settings->width : 0; |
| 468 const int height = settings->has_height ? settings->height : 0; | 484 const int height = settings->has_height ? settings->height : 0; |
| 469 const int zoom = settings->has_zoom ? settings->zoom : 0; | 485 const int zoom = settings->has_zoom ? settings->zoom : 0; |
| 470 | 486 |
| 471 PhotoCapabilities::AndroidFocusMode focus_mode = | 487 const PhotoCapabilities::AndroidMeteringMode focus_mode = |
| 472 PhotoCapabilities::AndroidFocusMode::UNAVAILABLE; | 488 settings->has_focus_mode |
| 473 if (settings->has_focus_mode) { | 489 ? ToAndroidMeteringMode(settings->focus_mode) |
| 474 switch (settings->focus_mode) { | 490 : PhotoCapabilities::AndroidMeteringMode::NOT_SET; |
| 475 case mojom::FocusMode::MANUAL: | 491 |
| 476 focus_mode = PhotoCapabilities::AndroidFocusMode::FIXED; | 492 const PhotoCapabilities::AndroidMeteringMode exposure_mode = |
| 477 break; | 493 settings->has_exposure_mode |
| 478 case mojom::FocusMode::SINGLE_SHOT: | 494 ? ToAndroidMeteringMode(settings->exposure_mode) |
| 479 focus_mode = PhotoCapabilities::AndroidFocusMode::SINGLE_SHOT; | 495 : PhotoCapabilities::AndroidMeteringMode::NOT_SET; |
| 480 break; | |
| 481 case mojom::FocusMode::CONTINUOUS: | |
| 482 focus_mode = PhotoCapabilities::AndroidFocusMode::CONTINUOUS; | |
| 483 break; | |
| 484 case mojom::FocusMode::UNAVAILABLE: | |
| 485 focus_mode = PhotoCapabilities::AndroidFocusMode::UNAVAILABLE; | |
| 486 break; | |
| 487 } | |
| 488 } | |
| 489 | 496 |
| 490 std::vector<float> points_of_interest_marshalled; | 497 std::vector<float> points_of_interest_marshalled; |
| 491 for (const auto& point : settings->points_of_interest) { | 498 for (const auto& point : settings->points_of_interest) { |
| 492 points_of_interest_marshalled.push_back(point->x); | 499 points_of_interest_marshalled.push_back(point->x); |
| 493 points_of_interest_marshalled.push_back(point->y); | 500 points_of_interest_marshalled.push_back(point->y); |
| 494 } | 501 } |
| 495 ScopedJavaLocalRef<jfloatArray> points_of_interest = | 502 ScopedJavaLocalRef<jfloatArray> points_of_interest = |
| 496 base::android::ToJavaFloatArray(env, points_of_interest_marshalled); | 503 base::android::ToJavaFloatArray(env, points_of_interest_marshalled); |
| 497 | 504 |
| 498 Java_VideoCapture_setPhotoOptions(env, j_capture_, zoom, | 505 Java_VideoCapture_setPhotoOptions( |
| 499 static_cast<int>(focus_mode), width, height, | 506 env, j_capture_, zoom, static_cast<int>(focus_mode), |
| 500 points_of_interest); | 507 static_cast<int>(exposure_mode), width, height, points_of_interest); |
| 501 | 508 |
| 502 callback.Run(true); | 509 callback.Run(true); |
| 503 } | 510 } |
| 504 | 511 |
| 505 } // namespace media | 512 } // namespace media |
| OLD | NEW |