Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: media/capture/video/android/video_capture_device_android.cc

Issue 2272873002: Android video capture: only use reference time for outbound timestamp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use raw timestamp from camera capture Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 "failed to GetByteArrayElements"; 207 "failed to GetByteArrayElements";
208 return; 208 return;
209 } 209 }
210 210
211 const base::TimeTicks current_time = base::TimeTicks::Now(); 211 const base::TimeTicks current_time = base::TimeTicks::Now();
212 { 212 {
213 base::AutoLock lock(lock_); 213 base::AutoLock lock(lock_);
214 if (!got_first_frame_) { 214 if (!got_first_frame_) {
215 // Set aside one frame allowance for fluctuation. 215 // Set aside one frame allowance for fluctuation.
216 expected_next_frame_time_ = current_time - frame_interval_; 216 expected_next_frame_time_ = current_time - frame_interval_;
217 first_ref_time_ = current_time;
218 got_first_frame_ = true; 217 got_first_frame_ = true;
219 218
220 for (const auto& request : photo_requests_queue_) 219 for (const auto& request : photo_requests_queue_)
221 main_task_runner_->PostTask(FROM_HERE, request); 220 main_task_runner_->PostTask(FROM_HERE, request);
222 photo_requests_queue_.clear(); 221 photo_requests_queue_.clear();
223 } 222 }
224 } 223 }
225 224
226 // Deliver the frame when it doesn't arrive too early. 225 // Deliver the frame when it doesn't arrive too early.
227 if (expected_next_frame_time_ <= current_time) { 226 if (expected_next_frame_time_ <= current_time) {
228 expected_next_frame_time_ += frame_interval_; 227 expected_next_frame_time_ += frame_interval_;
229 228
230 // TODO(qiangchen): Investigate how to get raw timestamp for Android, 229 // TODO(qiangchen): Investigate how to get raw timestamp for Android,
231 // rather than using reference time to calculate timestamp. 230 // rather than using reference time to calculate timestamp.
232 base::AutoLock lock(lock_); 231 base::AutoLock lock(lock_);
233 if (!client_) 232 if (!client_)
234 return; 233 return;
235 client_->OnIncomingCapturedData(reinterpret_cast<uint8_t*>(buffer), length, 234 client_->OnIncomingCapturedData(reinterpret_cast<uint8_t*>(buffer), length,
236 capture_format_, rotation, current_time, 235 capture_format_, rotation, current_time,
237 current_time - first_ref_time_); 236 base::TimeDelta());
miu 2016/08/31 21:09:16 Please plumb-in timestamp here too.
braveyao 2016/08/31 23:01:28 No capture timestamp available here. Maybe better
238 } 237 }
239 238
240 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT); 239 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT);
241 } 240 }
242 241
243 void VideoCaptureDeviceAndroid::OnI420FrameAvailable(JNIEnv* env, 242 void VideoCaptureDeviceAndroid::OnI420FrameAvailable(JNIEnv* env,
244 jobject obj, 243 jobject obj,
245 jobject y_buffer, 244 jobject y_buffer,
246 jint y_stride, 245 jint y_stride,
247 jobject u_buffer, 246 jobject u_buffer,
248 jobject v_buffer, 247 jobject v_buffer,
249 jint uv_row_stride, 248 jint uv_row_stride,
250 jint uv_pixel_stride, 249 jint uv_pixel_stride,
251 jint width, 250 jint width,
252 jint height, 251 jint height,
253 jint rotation) { 252 jint rotation,
253 jlong timestamp) {
254 { 254 {
255 base::AutoLock lock(lock_); 255 base::AutoLock lock(lock_);
256 if (state_ != kConfigured || !client_) 256 if (state_ != kConfigured || !client_)
257 return; 257 return;
258 } 258 }
259 const uint64_t absolute_micro =
miu 2016/08/31 21:09:16 nit: Should be int64_t since both operands are sig
braveyao 2016/08/31 23:01:28 Done.
260 timestamp / base::Time::kNanosecondsPerMicrosecond;
261 const base::TimeDelta start_time =
miu 2016/08/31 21:09:16 naming nit: How about |capture_time|? According to
braveyao 2016/08/31 23:01:28 Done.
262 base::TimeDelta::FromMicroseconds(absolute_micro);
259 263
260 const base::TimeTicks current_time = base::TimeTicks::Now(); 264 const base::TimeTicks current_time = base::TimeTicks::Now();
261 { 265 {
262 base::AutoLock lock(lock_); 266 base::AutoLock lock(lock_);
263 if (!got_first_frame_) { 267 if (!got_first_frame_) {
264 // Set aside one frame allowance for fluctuation. 268 // Set aside one frame allowance for fluctuation.
265 expected_next_frame_time_ = current_time - frame_interval_; 269 expected_next_frame_time_ = current_time - frame_interval_;
266 first_ref_time_ = current_time;
267 got_first_frame_ = true; 270 got_first_frame_ = true;
268 271
269 for (const auto& request : photo_requests_queue_) 272 for (const auto& request : photo_requests_queue_)
270 main_task_runner_->PostTask(FROM_HERE, request); 273 main_task_runner_->PostTask(FROM_HERE, request);
271 photo_requests_queue_.clear(); 274 photo_requests_queue_.clear();
272 } 275 }
273 } 276 }
274 277
275 uint8_t* const y_src = 278 uint8_t* const y_src =
276 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(y_buffer)); 279 reinterpret_cast<uint8_t*>(env->GetDirectBufferAddress(y_buffer));
(...skipping 10 matching lines...) Expand all
287 const int buffer_length = y_plane_length + uv_plane_length * 2; 290 const int buffer_length = y_plane_length + uv_plane_length * 2;
288 std::unique_ptr<uint8_t> buffer(new uint8_t[buffer_length]); 291 std::unique_ptr<uint8_t> buffer(new uint8_t[buffer_length]);
289 292
290 libyuv::Android420ToI420(y_src, y_stride, u_src, uv_row_stride, v_src, 293 libyuv::Android420ToI420(y_src, y_stride, u_src, uv_row_stride, v_src,
291 uv_row_stride, uv_pixel_stride, buffer.get(), width, 294 uv_row_stride, uv_pixel_stride, buffer.get(), width,
292 buffer.get() + y_plane_length, width / 2, 295 buffer.get() + y_plane_length, width / 2,
293 buffer.get() + y_plane_length + uv_plane_length, 296 buffer.get() + y_plane_length + uv_plane_length,
294 width / 2, width, height); 297 width / 2, width, height);
295 298
296 // Deliver the frame when it doesn't arrive too early. 299 // Deliver the frame when it doesn't arrive too early.
297 if (expected_next_frame_time_ <= current_time) { 300 if (expected_next_frame_time_ <= current_time) {
miu 2016/08/31 21:09:16 What happened to the code from the "part I" patch
braveyao 2016/08/31 23:01:28 Can't get you. My 'part I' patch is for content c
miu 2016/09/02 21:49:15 Acknowledged. My misunderstanding. ;-)
298 expected_next_frame_time_ += frame_interval_; 301 expected_next_frame_time_ += frame_interval_;
299 302
300 // TODO(qiangchen): Investigate how to get raw timestamp for Android, 303 // TODO(qiangchen): Investigate how to get raw timestamp for Android,
301 // rather than using reference time to calculate timestamp. 304 // rather than using reference time to calculate timestamp.
302 base::AutoLock lock(lock_); 305 base::AutoLock lock(lock_);
303 if (!client_) 306 if (!client_)
304 return; 307 return;
305 client_->OnIncomingCapturedData(buffer.get(), buffer_length, 308 client_->OnIncomingCapturedData(buffer.get(), buffer_length,
306 capture_format_, rotation, current_time, 309 capture_format_, rotation, current_time,
307 current_time - first_ref_time_); 310 start_time);
308 } 311 }
309 } 312 }
310 313
311 void VideoCaptureDeviceAndroid::OnError(JNIEnv* env, 314 void VideoCaptureDeviceAndroid::OnError(JNIEnv* env,
312 const JavaParamRef<jobject>& obj, 315 const JavaParamRef<jobject>& obj,
313 const JavaParamRef<jstring>& message) { 316 const JavaParamRef<jstring>& message) {
314 SetErrorState(FROM_HERE, 317 SetErrorState(FROM_HERE,
315 base::android::ConvertJavaStringToUTF8(env, message)); 318 base::android::ConvertJavaStringToUTF8(env, message));
316 } 319 }
317 320
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } 489 }
487 } 490 }
488 491
489 Java_VideoCapture_setPhotoOptions( 492 Java_VideoCapture_setPhotoOptions(
490 env, j_capture_, zoom, static_cast<int>(focus_mode), width, height); 493 env, j_capture_, zoom, static_cast<int>(focus_mode), width, height);
491 494
492 callback.Run(true); 495 callback.Run(true);
493 } 496 }
494 497
495 } // namespace media 498 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698