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" |
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/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "jni/VideoCapture_jni.h" | 15 #include "jni/VideoCapture_jni.h" |
15 #include "media/capture/video/android/photo_capabilities.h" | 16 #include "media/capture/video/android/photo_capabilities.h" |
16 #include "media/capture/video/android/video_capture_device_factory_android.h" | 17 #include "media/capture/video/android/video_capture_device_factory_android.h" |
17 | 18 |
18 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
19 using base::android::CheckException; | 20 using base::android::CheckException; |
20 using base::android::GetClass; | 21 using base::android::GetClass; |
21 using base::android::MethodID; | 22 using base::android::MethodID; |
22 using base::android::JavaRef; | 23 using base::android::JavaRef; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 if (state_ != kCapturing) | 144 if (state_ != kCapturing) |
144 return; | 145 return; |
145 } | 146 } |
146 | 147 |
147 JNIEnv* env = AttachCurrentThread(); | 148 JNIEnv* env = AttachCurrentThread(); |
148 | 149 |
149 // Make copy on the heap so we can pass the pointer through JNI. | 150 // Make copy on the heap so we can pass the pointer through JNI. |
150 std::unique_ptr<TakePhotoCallback> heap_callback( | 151 std::unique_ptr<TakePhotoCallback> heap_callback( |
151 new TakePhotoCallback(std::move(callback))); | 152 new TakePhotoCallback(std::move(callback))); |
152 const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); | 153 const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); |
153 if (!Java_VideoCapture_takePhoto(env, j_capture_.obj(), callback_id)) | 154 if (!Java_VideoCapture_takePhoto(env, j_capture_.obj(), callback_id, |
| 155 next_photo_resolution_.width(), |
| 156 next_photo_resolution_.height())) |
154 return; | 157 return; |
155 | 158 |
156 { | 159 { |
157 base::AutoLock lock(photo_callbacks_lock_); | 160 base::AutoLock lock(photo_callbacks_lock_); |
158 photo_callbacks_.push_back(std::move(heap_callback)); | 161 photo_callbacks_.push_back(std::move(heap_callback)); |
159 } | 162 } |
160 } | 163 } |
161 | 164 |
162 void VideoCaptureDeviceAndroid::GetPhotoCapabilities( | 165 void VideoCaptureDeviceAndroid::GetPhotoCapabilities( |
163 GetPhotoCapabilitiesCallback callback) { | 166 GetPhotoCapabilitiesCallback callback) { |
164 JNIEnv* env = AttachCurrentThread(); | 167 JNIEnv* env = AttachCurrentThread(); |
165 | 168 |
166 PhotoCapabilities caps( | 169 PhotoCapabilities caps( |
167 Java_VideoCapture_getPhotoCapabilities(env, j_capture_.obj())); | 170 Java_VideoCapture_getPhotoCapabilities(env, j_capture_.obj())); |
168 | 171 |
169 // TODO(mcasas): Manual member copying sucks, consider adding typemapping from | 172 // TODO(mcasas): Manual member copying sucks, consider adding typemapping from |
170 // PhotoCapabilities to mojom::PhotoCapabilitiesPtr, https://crbug.com/622002. | 173 // PhotoCapabilities to mojom::PhotoCapabilitiesPtr, https://crbug.com/622002. |
171 mojom::PhotoCapabilitiesPtr photo_capabilities = | 174 mojom::PhotoCapabilitiesPtr photo_capabilities = |
172 mojom::PhotoCapabilities::New(); | 175 mojom::PhotoCapabilities::New(); |
| 176 photo_capabilities->iso = mojom::Range::New(); |
| 177 photo_capabilities->iso->current = caps.getCurrentIso(); |
| 178 photo_capabilities->iso->max = caps.getMaxIso(); |
| 179 photo_capabilities->iso->min = caps.getMinIso(); |
| 180 photo_capabilities->height = mojom::Range::New(); |
| 181 photo_capabilities->height->current = caps.getCurrentHeight(); |
| 182 photo_capabilities->height->max = caps.getMaxHeight(); |
| 183 photo_capabilities->height->min = caps.getMinHeight(); |
| 184 photo_capabilities->width = mojom::Range::New(); |
| 185 photo_capabilities->width->current = caps.getCurrentWidth(); |
| 186 photo_capabilities->width->max = caps.getMaxWidth(); |
| 187 photo_capabilities->width->min = caps.getMinWidth(); |
173 photo_capabilities->zoom = mojom::Range::New(); | 188 photo_capabilities->zoom = mojom::Range::New(); |
174 photo_capabilities->zoom->current = caps.getCurrentZoom(); | 189 photo_capabilities->zoom->current = caps.getCurrentZoom(); |
175 photo_capabilities->zoom->max = caps.getMaxZoom(); | 190 photo_capabilities->zoom->max = caps.getMaxZoom(); |
176 photo_capabilities->zoom->min = caps.getMinZoom(); | 191 photo_capabilities->zoom->min = caps.getMinZoom(); |
177 photo_capabilities->focus_mode = caps.getAutoFocusInUse() | 192 photo_capabilities->focus_mode = caps.getAutoFocusInUse() |
178 ? mojom::FocusMode::AUTO | 193 ? mojom::FocusMode::AUTO |
179 : mojom::FocusMode::MANUAL; | 194 : mojom::FocusMode::MANUAL; |
180 callback.Run(std::move(photo_capabilities)); | 195 callback.Run(std::move(photo_capabilities)); |
181 } | 196 } |
182 | 197 |
183 void VideoCaptureDeviceAndroid::SetPhotoOptions( | 198 void VideoCaptureDeviceAndroid::SetPhotoOptions( |
184 mojom::PhotoSettingsPtr settings, | 199 mojom::PhotoSettingsPtr settings, |
185 SetPhotoOptionsCallback callback) { | 200 SetPhotoOptionsCallback callback) { |
186 JNIEnv* env = AttachCurrentThread(); | 201 JNIEnv* env = AttachCurrentThread(); |
| 202 // |width| and/or |height| are kept for the next TakePhoto()s. |
| 203 if (settings->has_width || settings->has_height) |
| 204 next_photo_resolution_.SetSize(0, 0); |
| 205 if (settings->has_width) { |
| 206 next_photo_resolution_.set_width( |
| 207 base::saturated_cast<int>(settings->width)); |
| 208 } |
| 209 if (settings->has_height) { |
| 210 next_photo_resolution_.set_height( |
| 211 base::saturated_cast<int>(settings->height)); |
| 212 } |
| 213 |
187 if (settings->has_zoom) | 214 if (settings->has_zoom) |
188 Java_VideoCapture_setZoom(env, j_capture_.obj(), settings->zoom); | 215 Java_VideoCapture_setZoom(env, j_capture_.obj(), settings->zoom); |
189 callback.Run(true); | 216 callback.Run(true); |
190 } | 217 } |
191 | 218 |
192 void VideoCaptureDeviceAndroid::OnFrameAvailable( | 219 void VideoCaptureDeviceAndroid::OnFrameAvailable( |
193 JNIEnv* env, | 220 JNIEnv* env, |
194 const JavaParamRef<jobject>& obj, | 221 const JavaParamRef<jobject>& obj, |
195 const JavaParamRef<jbyteArray>& data, | 222 const JavaParamRef<jbyteArray>& data, |
196 jint length, | 223 jint length, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 const tracked_objects::Location& from_here, | 315 const tracked_objects::Location& from_here, |
289 const std::string& reason) { | 316 const std::string& reason) { |
290 { | 317 { |
291 base::AutoLock lock(lock_); | 318 base::AutoLock lock(lock_); |
292 state_ = kError; | 319 state_ = kError; |
293 } | 320 } |
294 client_->OnError(from_here, reason); | 321 client_->OnError(from_here, reason); |
295 } | 322 } |
296 | 323 |
297 } // namespace media | 324 } // namespace media |
OLD | NEW |