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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 if (state_ != kCapturing) | 143 if (state_ != kCapturing) |
144 return; | 144 return; |
145 } | 145 } |
146 | 146 |
147 JNIEnv* env = AttachCurrentThread(); | 147 JNIEnv* env = AttachCurrentThread(); |
148 | 148 |
149 // Make copy on the heap so we can pass the pointer through JNI. | 149 // Make copy on the heap so we can pass the pointer through JNI. |
150 std::unique_ptr<TakePhotoCallback> heap_callback( | 150 std::unique_ptr<TakePhotoCallback> heap_callback( |
151 new TakePhotoCallback(std::move(callback))); | 151 new TakePhotoCallback(std::move(callback))); |
152 const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); | 152 const intptr_t callback_id = reinterpret_cast<intptr_t>(heap_callback.get()); |
153 if (!Java_VideoCapture_takePhoto(env, j_capture_.obj(), callback_id)) | 153 if (!Java_VideoCapture_takePhoto(env, j_capture_.obj(), callback_id, |
154 next_photo_resolution_.width(), | |
155 next_photo_resolution_.height())) | |
154 return; | 156 return; |
155 | 157 |
156 { | 158 { |
157 base::AutoLock lock(photo_callbacks_lock_); | 159 base::AutoLock lock(photo_callbacks_lock_); |
158 photo_callbacks_.push_back(std::move(heap_callback)); | 160 photo_callbacks_.push_back(std::move(heap_callback)); |
159 } | 161 } |
160 } | 162 } |
161 | 163 |
162 void VideoCaptureDeviceAndroid::GetPhotoCapabilities( | 164 void VideoCaptureDeviceAndroid::GetPhotoCapabilities( |
163 GetPhotoCapabilitiesCallback callback) { | 165 GetPhotoCapabilitiesCallback callback) { |
164 JNIEnv* env = AttachCurrentThread(); | 166 JNIEnv* env = AttachCurrentThread(); |
165 | 167 |
166 PhotoCapabilities caps( | 168 PhotoCapabilities caps( |
167 Java_VideoCapture_getPhotoCapabilities(env, j_capture_.obj())); | 169 Java_VideoCapture_getPhotoCapabilities(env, j_capture_.obj())); |
168 | 170 |
169 // TODO(mcasas): Manual member copying sucks, consider adding typemapping from | 171 // TODO(mcasas): Manual member copying sucks, consider adding typemapping from |
170 // PhotoCapabilities to mojom::PhotoCapabilitiesPtr, https://crbug.com/622002. | 172 // PhotoCapabilities to mojom::PhotoCapabilitiesPtr, https://crbug.com/622002. |
171 mojom::PhotoCapabilitiesPtr photo_capabilities = | 173 mojom::PhotoCapabilitiesPtr photo_capabilities = |
172 mojom::PhotoCapabilities::New(); | 174 mojom::PhotoCapabilities::New(); |
175 photo_capabilities->iso = mojom::Range::New(); | |
176 photo_capabilities->iso->current = caps.getCurrentIso(); | |
177 photo_capabilities->iso->max = caps.getMaxIso(); | |
178 photo_capabilities->iso->min = caps.getMinIso(); | |
179 photo_capabilities->height = mojom::Range::New(); | |
180 photo_capabilities->height->current = caps.getCurrentHeight(); | |
181 photo_capabilities->height->max = caps.getMaxHeight(); | |
182 photo_capabilities->height->min = caps.getMinHeight(); | |
183 photo_capabilities->width = mojom::Range::New(); | |
184 photo_capabilities->width->current = caps.getCurrentWidth(); | |
185 photo_capabilities->width->max = caps.getMaxWidth(); | |
186 photo_capabilities->width->min = caps.getMinWidth(); | |
173 photo_capabilities->zoom = mojom::Range::New(); | 187 photo_capabilities->zoom = mojom::Range::New(); |
174 photo_capabilities->zoom->current = caps.getCurrentZoom(); | 188 photo_capabilities->zoom->current = caps.getCurrentZoom(); |
175 photo_capabilities->zoom->max = caps.getMaxZoom(); | 189 photo_capabilities->zoom->max = caps.getMaxZoom(); |
176 photo_capabilities->zoom->min = caps.getMinZoom(); | 190 photo_capabilities->zoom->min = caps.getMinZoom(); |
177 photo_capabilities->focus_mode = caps.getAutoFocusInUse() | 191 photo_capabilities->focus_mode = caps.getAutoFocusInUse() |
178 ? mojom::FocusMode::AUTO | 192 ? mojom::FocusMode::AUTO |
179 : mojom::FocusMode::MANUAL; | 193 : mojom::FocusMode::MANUAL; |
180 callback.Run(std::move(photo_capabilities)); | 194 callback.Run(std::move(photo_capabilities)); |
181 } | 195 } |
182 | 196 |
183 void VideoCaptureDeviceAndroid::SetPhotoOptions( | 197 void VideoCaptureDeviceAndroid::SetPhotoOptions( |
184 mojom::PhotoSettingsPtr settings, | 198 mojom::PhotoSettingsPtr settings, |
185 SetPhotoOptionsCallback callback) { | 199 SetPhotoOptionsCallback callback) { |
186 JNIEnv* env = AttachCurrentThread(); | 200 JNIEnv* env = AttachCurrentThread(); |
201 // |width| and/or |height| are kept for the next TakePhoto()s. | |
202 if (settings->has_width || settings->has_height) | |
203 next_photo_resolution_.SetSize(0, 0); | |
204 if (settings->has_width) | |
205 next_photo_resolution_.set_width(settings->width); | |
dcheng
2016/07/22 04:45:29
What happens if settings->width overflows int?
mcasas
2016/07/22 16:46:32
gfx::Size::set_{width,height}() clamps negative nu
dcheng
2016/07/22 18:07:23
Right, it just ... seems a bit odd.
I suppose we
mcasas
2016/07/22 23:16:27
Using base::saturated_cast<int>() now.
(Note that
| |
206 if (settings->has_height) | |
207 next_photo_resolution_.set_height(settings->height); | |
208 | |
187 if (settings->has_zoom) | 209 if (settings->has_zoom) |
188 Java_VideoCapture_setZoom(env, j_capture_.obj(), settings->zoom); | 210 Java_VideoCapture_setZoom(env, j_capture_.obj(), settings->zoom); |
189 callback.Run(true); | 211 callback.Run(true); |
190 } | 212 } |
191 | 213 |
192 void VideoCaptureDeviceAndroid::OnFrameAvailable( | 214 void VideoCaptureDeviceAndroid::OnFrameAvailable( |
193 JNIEnv* env, | 215 JNIEnv* env, |
194 const JavaParamRef<jobject>& obj, | 216 const JavaParamRef<jobject>& obj, |
195 const JavaParamRef<jbyteArray>& data, | 217 const JavaParamRef<jbyteArray>& data, |
196 jint length, | 218 jint length, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 const tracked_objects::Location& from_here, | 310 const tracked_objects::Location& from_here, |
289 const std::string& reason) { | 311 const std::string& reason) { |
290 { | 312 { |
291 base::AutoLock lock(lock_); | 313 base::AutoLock lock(lock_); |
292 state_ = kError; | 314 state_ = kError; |
293 } | 315 } |
294 client_->OnError(from_here, reason); | 316 client_->OnError(from_here, reason); |
295 } | 317 } |
296 | 318 |
297 } // namespace media | 319 } // namespace media |
OLD | NEW |