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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 "failed to GetByteArrayElements"; | 245 "failed to GetByteArrayElements"; |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 | 248 |
| 249 const base::TimeTicks current_time = base::TimeTicks::Now(); | 249 const base::TimeTicks current_time = base::TimeTicks::Now(); |
| 250 { | 250 { |
| 251 base::AutoLock lock(lock_); | 251 base::AutoLock lock(lock_); |
| 252 if (!got_first_frame_) { | 252 if (!got_first_frame_) { |
| 253 // Set aside one frame allowance for fluctuation. | 253 // Set aside one frame allowance for fluctuation. |
| 254 expected_next_frame_time_ = current_time - frame_interval_; | 254 expected_next_frame_time_ = current_time - frame_interval_; |
| 255 first_ref_time_ = current_time; | |
| 256 got_first_frame_ = true; | 255 got_first_frame_ = true; |
| 257 | 256 |
| 258 for (const auto& request : photo_requests_queue_) | 257 for (const auto& request : photo_requests_queue_) |
| 259 main_task_runner_->PostTask(FROM_HERE, request); | 258 main_task_runner_->PostTask(FROM_HERE, request); |
| 260 photo_requests_queue_.clear(); | 259 photo_requests_queue_.clear(); |
| 261 } | 260 } |
| 262 } | 261 } |
| 263 | 262 |
| 264 // Deliver the frame when it doesn't arrive too early. | 263 // Deliver the frame when it doesn't arrive too early. |
| 265 if (expected_next_frame_time_ <= current_time) { | 264 if (expected_next_frame_time_ <= current_time) { |
| 266 expected_next_frame_time_ += frame_interval_; | 265 expected_next_frame_time_ += frame_interval_; |
| 267 | 266 |
| 268 // TODO(qiangchen): Investigate how to get raw timestamp for Android, | 267 // TODO(qiangchen): Investigate how to get raw timestamp for Android, |
| 269 // rather than using reference time to calculate timestamp. | 268 // rather than using reference time to calculate timestamp. |
| 270 base::AutoLock lock(lock_); | 269 base::AutoLock lock(lock_); |
| 271 if (!client_) | 270 if (!client_) |
| 272 return; | 271 return; |
| 273 client_->OnIncomingCapturedData(reinterpret_cast<uint8_t*>(buffer), length, | 272 client_->OnIncomingCapturedData(reinterpret_cast<uint8_t*>(buffer), length, |
| 274 capture_format_, rotation, current_time, | 273 capture_format_, rotation, current_time, |
| 275 current_time - first_ref_time_); | 274 base::TimeDelta()); |
|
miu
2016/09/02 21:49:15
I'm pretty sure this could throw off consumers of
braveyao
2016/09/02 23:25:53
Done.
| |
| 276 } | 275 } |
| 277 | 276 |
| 278 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT); | 277 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT); |
| 279 } | 278 } |
| 280 | 279 |
| 281 void VideoCaptureDeviceAndroid::OnI420FrameAvailable(JNIEnv* env, | 280 void VideoCaptureDeviceAndroid::OnI420FrameAvailable(JNIEnv* env, |
| 282 jobject obj, | 281 jobject obj, |
| 283 jobject y_buffer, | 282 jobject y_buffer, |
| 284 jint y_stride, | 283 jint y_stride, |
| 285 jobject u_buffer, | 284 jobject u_buffer, |
| 286 jobject v_buffer, | 285 jobject v_buffer, |
| 287 jint uv_row_stride, | 286 jint uv_row_stride, |
| 288 jint uv_pixel_stride, | 287 jint uv_pixel_stride, |
| 289 jint width, | 288 jint width, |
| 290 jint height, | 289 jint height, |
| 291 jint rotation) { | 290 jint rotation, |
| 291 jlong timestamp) { | |
| 292 { | 292 { |
| 293 base::AutoLock lock(lock_); | 293 base::AutoLock lock(lock_); |
| 294 if (state_ != kConfigured || !client_) | 294 if (state_ != kConfigured || !client_) |
| 295 return; | 295 return; |
| 296 } | 296 } |
| 297 const int64_t absolute_micro = | |
| 298 timestamp / base::Time::kNanosecondsPerMicrosecond; | |
| 299 const base::TimeDelta capture_time = | |
| 300 base::TimeDelta::FromMicroseconds(absolute_micro); | |
| 297 | 301 |
| 298 const base::TimeTicks current_time = base::TimeTicks::Now(); | 302 const base::TimeTicks current_time = base::TimeTicks::Now(); |
| 299 { | 303 { |
| 300 base::AutoLock lock(lock_); | 304 base::AutoLock lock(lock_); |
| 301 if (!got_first_frame_) { | 305 if (!got_first_frame_) { |
| 302 // Set aside one frame allowance for fluctuation. | 306 // Set aside one frame allowance for fluctuation. |
| 303 expected_next_frame_time_ = current_time - frame_interval_; | 307 expected_next_frame_time_ = current_time - frame_interval_; |
| 304 first_ref_time_ = current_time; | |
| 305 got_first_frame_ = true; | 308 got_first_frame_ = true; |
| 306 | 309 |
| 307 for (const auto& request : photo_requests_queue_) | 310 for (const auto& request : photo_requests_queue_) |
| 308 main_task_runner_->PostTask(FROM_HERE, request); | 311 main_task_runner_->PostTask(FROM_HERE, request); |
| 309 photo_requests_queue_.clear(); | 312 photo_requests_queue_.clear(); |
| 310 } | 313 } |
| 311 } | 314 } |
| 312 | 315 |
| 313 uint8_t* const y_src = | 316 uint8_t* const y_src = |
| 314 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(y_buffer)); | 317 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(y_buffer)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 335 if (expected_next_frame_time_ <= current_time) { | 338 if (expected_next_frame_time_ <= current_time) { |
| 336 expected_next_frame_time_ += frame_interval_; | 339 expected_next_frame_time_ += frame_interval_; |
| 337 | 340 |
| 338 // TODO(qiangchen): Investigate how to get raw timestamp for Android, | 341 // TODO(qiangchen): Investigate how to get raw timestamp for Android, |
| 339 // rather than using reference time to calculate timestamp. | 342 // rather than using reference time to calculate timestamp. |
| 340 base::AutoLock lock(lock_); | 343 base::AutoLock lock(lock_); |
| 341 if (!client_) | 344 if (!client_) |
| 342 return; | 345 return; |
| 343 client_->OnIncomingCapturedData(buffer.get(), buffer_length, | 346 client_->OnIncomingCapturedData(buffer.get(), buffer_length, |
| 344 capture_format_, rotation, current_time, | 347 capture_format_, rotation, current_time, |
| 345 current_time - first_ref_time_); | 348 capture_time); |
| 346 } | 349 } |
| 347 } | 350 } |
| 348 | 351 |
| 349 void VideoCaptureDeviceAndroid::OnError(JNIEnv* env, | 352 void VideoCaptureDeviceAndroid::OnError(JNIEnv* env, |
| 350 const JavaParamRef<jobject>& obj, | 353 const JavaParamRef<jobject>& obj, |
| 351 const JavaParamRef<jstring>& message) { | 354 const JavaParamRef<jstring>& message) { |
| 352 SetErrorState(FROM_HERE, | 355 SetErrorState(FROM_HERE, |
| 353 base::android::ConvertJavaStringToUTF8(env, message)); | 356 base::android::ConvertJavaStringToUTF8(env, message)); |
| 354 } | 357 } |
| 355 | 358 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 | 528 |
| 526 Java_VideoCapture_setPhotoOptions( | 529 Java_VideoCapture_setPhotoOptions( |
| 527 env, j_capture_, zoom, static_cast<int>(focus_mode), | 530 env, j_capture_, zoom, static_cast<int>(focus_mode), |
| 528 static_cast<int>(exposure_mode), width, height, points_of_interest, | 531 static_cast<int>(exposure_mode), width, height, points_of_interest, |
| 529 settings->has_exposure_compensation, exposure_compensation); | 532 settings->has_exposure_compensation, exposure_compensation); |
| 530 | 533 |
| 531 callback.Run(true); | 534 callback.Run(true); |
| 532 } | 535 } |
| 533 | 536 |
| 534 } // namespace media | 537 } // namespace media |
| OLD | NEW |