| 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 "device/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" |
| 11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "device/capture/video/android/photo_capabilities.h" |
| 16 #include "device/capture/video/android/video_capture_device_factory_android.h" |
| 15 #include "jni/VideoCapture_jni.h" | 17 #include "jni/VideoCapture_jni.h" |
| 16 #include "media/capture/video/android/photo_capabilities.h" | |
| 17 #include "media/capture/video/android/video_capture_device_factory_android.h" | |
| 18 #include "third_party/libyuv/include/libyuv.h" | 18 #include "third_party/libyuv/include/libyuv.h" |
| 19 | 19 |
| 20 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
| 21 using base::android::CheckException; | 21 using base::android::CheckException; |
| 22 using base::android::GetClass; | 22 using base::android::GetClass; |
| 23 using base::android::MethodID; | 23 using base::android::MethodID; |
| 24 using base::android::JavaRef; | 24 using base::android::JavaRef; |
| 25 using base::android::ScopedJavaLocalRef; | 25 using base::android::ScopedJavaLocalRef; |
| 26 | 26 |
| 27 namespace media { | 27 namespace device { |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { | 30 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { |
| 31 return RegisterNativesImpl(env); | 31 return RegisterNativesImpl(env); |
| 32 } | 32 } |
| 33 | 33 |
| 34 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid( | 34 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid( |
| 35 const VideoCaptureDeviceDescriptor& device_descriptor) | 35 const VideoCaptureDeviceDescriptor& device_descriptor) |
| 36 : state_(kIdle), | 36 : state_(kIdle), |
| 37 got_first_frame_(false), | 37 got_first_frame_(false), |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 void VideoCaptureDeviceAndroid::GetPhotoCapabilities( | 161 void VideoCaptureDeviceAndroid::GetPhotoCapabilities( |
| 162 GetPhotoCapabilitiesCallback callback) { | 162 GetPhotoCapabilitiesCallback callback) { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 163 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 JNIEnv* env = AttachCurrentThread(); | 164 JNIEnv* env = AttachCurrentThread(); |
| 165 | 165 |
| 166 PhotoCapabilities caps( | 166 PhotoCapabilities caps( |
| 167 Java_VideoCapture_getPhotoCapabilities(env, j_capture_.obj())); | 167 Java_VideoCapture_getPhotoCapabilities(env, j_capture_.obj())); |
| 168 | 168 |
| 169 // TODO(mcasas): Manual member copying sucks, consider adding typemapping from | 169 // TODO(mcasas): Manual member copying sucks, consider adding typemapping from |
| 170 // PhotoCapabilities to mojom::PhotoCapabilitiesPtr, https://crbug.com/622002. | 170 // PhotoCapabilities to media::mojom::PhotoCapabilitiesPtr, |
| 171 mojom::PhotoCapabilitiesPtr photo_capabilities = | 171 // https://crbug.com/622002. |
| 172 mojom::PhotoCapabilities::New(); | 172 media::mojom::PhotoCapabilitiesPtr photo_capabilities = |
| 173 photo_capabilities->iso = mojom::Range::New(); | 173 media::mojom::PhotoCapabilities::New(); |
| 174 photo_capabilities->iso = media::mojom::Range::New(); |
| 174 photo_capabilities->iso->current = caps.getCurrentIso(); | 175 photo_capabilities->iso->current = caps.getCurrentIso(); |
| 175 photo_capabilities->iso->max = caps.getMaxIso(); | 176 photo_capabilities->iso->max = caps.getMaxIso(); |
| 176 photo_capabilities->iso->min = caps.getMinIso(); | 177 photo_capabilities->iso->min = caps.getMinIso(); |
| 177 photo_capabilities->height = mojom::Range::New(); | 178 photo_capabilities->height = media::mojom::Range::New(); |
| 178 photo_capabilities->height->current = caps.getCurrentHeight(); | 179 photo_capabilities->height->current = caps.getCurrentHeight(); |
| 179 photo_capabilities->height->max = caps.getMaxHeight(); | 180 photo_capabilities->height->max = caps.getMaxHeight(); |
| 180 photo_capabilities->height->min = caps.getMinHeight(); | 181 photo_capabilities->height->min = caps.getMinHeight(); |
| 181 photo_capabilities->width = mojom::Range::New(); | 182 photo_capabilities->width = media::mojom::Range::New(); |
| 182 photo_capabilities->width->current = caps.getCurrentWidth(); | 183 photo_capabilities->width->current = caps.getCurrentWidth(); |
| 183 photo_capabilities->width->max = caps.getMaxWidth(); | 184 photo_capabilities->width->max = caps.getMaxWidth(); |
| 184 photo_capabilities->width->min = caps.getMinWidth(); | 185 photo_capabilities->width->min = caps.getMinWidth(); |
| 185 photo_capabilities->zoom = mojom::Range::New(); | 186 photo_capabilities->zoom = media::mojom::Range::New(); |
| 186 photo_capabilities->zoom->current = caps.getCurrentZoom(); | 187 photo_capabilities->zoom->current = caps.getCurrentZoom(); |
| 187 photo_capabilities->zoom->max = caps.getMaxZoom(); | 188 photo_capabilities->zoom->max = caps.getMaxZoom(); |
| 188 photo_capabilities->zoom->min = caps.getMinZoom(); | 189 photo_capabilities->zoom->min = caps.getMinZoom(); |
| 189 photo_capabilities->focus_mode = caps.getAutoFocusInUse() | 190 photo_capabilities->focus_mode = caps.getAutoFocusInUse() |
| 190 ? mojom::FocusMode::AUTO | 191 ? media::mojom::FocusMode::AUTO |
| 191 : mojom::FocusMode::MANUAL; | 192 : media::mojom::FocusMode::MANUAL; |
| 192 callback.Run(std::move(photo_capabilities)); | 193 callback.Run(std::move(photo_capabilities)); |
| 193 } | 194 } |
| 194 | 195 |
| 195 void VideoCaptureDeviceAndroid::SetPhotoOptions( | 196 void VideoCaptureDeviceAndroid::SetPhotoOptions( |
| 196 mojom::PhotoSettingsPtr settings, | 197 media::mojom::PhotoSettingsPtr settings, |
| 197 SetPhotoOptionsCallback callback) { | 198 SetPhotoOptionsCallback callback) { |
| 198 DCHECK(thread_checker_.CalledOnValidThread()); | 199 DCHECK(thread_checker_.CalledOnValidThread()); |
| 199 JNIEnv* env = AttachCurrentThread(); | 200 JNIEnv* env = AttachCurrentThread(); |
| 200 // |width| and/or |height| are kept for the next TakePhoto()s. | 201 // |width| and/or |height| are kept for the next TakePhoto()s. |
| 201 if (settings->has_width || settings->has_height) | 202 if (settings->has_width || settings->has_height) |
| 202 next_photo_resolution_.SetSize(0, 0); | 203 next_photo_resolution_.SetSize(0, 0); |
| 203 if (settings->has_width) { | 204 if (settings->has_width) { |
| 204 next_photo_resolution_.set_width( | 205 next_photo_resolution_.set_width( |
| 205 base::saturated_cast<int>(settings->width)); | 206 base::saturated_cast<int>(settings->width)); |
| 206 } | 207 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 const auto reference_it = | 342 const auto reference_it = |
| 342 std::find_if(photo_callbacks_.begin(), photo_callbacks_.end(), | 343 std::find_if(photo_callbacks_.begin(), photo_callbacks_.end(), |
| 343 [cb](const std::unique_ptr<TakePhotoCallback>& callback) { | 344 [cb](const std::unique_ptr<TakePhotoCallback>& callback) { |
| 344 return callback.get() == cb; | 345 return callback.get() == cb; |
| 345 }); | 346 }); |
| 346 if (reference_it == photo_callbacks_.end()) { | 347 if (reference_it == photo_callbacks_.end()) { |
| 347 NOTREACHED() << "|callback_id| not found."; | 348 NOTREACHED() << "|callback_id| not found."; |
| 348 return; | 349 return; |
| 349 } | 350 } |
| 350 | 351 |
| 351 mojom::BlobPtr blob = mojom::Blob::New(); | 352 media::mojom::BlobPtr blob = media::mojom::Blob::New(); |
| 352 base::android::JavaByteArrayToByteVector(env, data.obj(), &blob->data); | 353 base::android::JavaByteArrayToByteVector(env, data.obj(), &blob->data); |
| 353 blob->mime_type = blob->data.empty() ? "" : "image/jpeg"; | 354 blob->mime_type = blob->data.empty() ? "" : "image/jpeg"; |
| 354 cb->Run(std::move(blob)); | 355 cb->Run(std::move(blob)); |
| 355 | 356 |
| 356 photo_callbacks_.erase(reference_it); | 357 photo_callbacks_.erase(reference_it); |
| 357 } | 358 } |
| 358 | 359 |
| 359 VideoPixelFormat VideoCaptureDeviceAndroid::GetColorspace() { | 360 VideoPixelFormat VideoCaptureDeviceAndroid::GetColorspace() { |
| 360 JNIEnv* env = AttachCurrentThread(); | 361 JNIEnv* env = AttachCurrentThread(); |
| 361 const int current_capture_colorspace = | 362 const int current_capture_colorspace = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 378 const std::string& reason) { | 379 const std::string& reason) { |
| 379 { | 380 { |
| 380 base::AutoLock lock(lock_); | 381 base::AutoLock lock(lock_); |
| 381 state_ = kError; | 382 state_ = kError; |
| 382 if (!client_) | 383 if (!client_) |
| 383 return; | 384 return; |
| 384 client_->OnError(from_here, reason); | 385 client_->OnError(from_here, reason); |
| 385 } | 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 } // namespace media | 389 } // namespace device |
| OLD | NEW |