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

Side by Side Diff: media/capture/video/mac/video_capture_device_decklink_mac.mm

Issue 1983193002: Decouple capture timestamp and reference time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve Comments Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/mac/video_capture_device_decklink_mac.h" 5 #include "media/capture/video/mac/video_capture_device_decklink_mac.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Weak reference to the captured frames client, used also for error messages 85 // Weak reference to the captured frames client, used also for error messages
86 // and logging. Initialized on construction and used until cleared by calling 86 // and logging. Initialized on construction and used until cleared by calling
87 // ResetVideoCaptureDeviceReference(). 87 // ResetVideoCaptureDeviceReference().
88 media::VideoCaptureDeviceDeckLinkMac* frame_receiver_; 88 media::VideoCaptureDeviceDeckLinkMac* frame_receiver_;
89 89
90 // This is used to control the video capturing device input interface. 90 // This is used to control the video capturing device input interface.
91 ScopedDeckLinkPtr<IDeckLinkInput> decklink_input_; 91 ScopedDeckLinkPtr<IDeckLinkInput> decklink_input_;
92 // |decklink_| represents a physical device attached to the host. 92 // |decklink_| represents a physical device attached to the host.
93 ScopedDeckLinkPtr<IDeckLink> decklink_; 93 ScopedDeckLinkPtr<IDeckLink> decklink_;
94 94
95 base::TimeTicks first_ref_time_;
96
95 // Checks for Device (a.k.a. Audio) thread. 97 // Checks for Device (a.k.a. Audio) thread.
96 base::ThreadChecker thread_checker_; 98 base::ThreadChecker thread_checker_;
97 99
98 friend class scoped_refptr<DeckLinkCaptureDelegate>; 100 friend class scoped_refptr<DeckLinkCaptureDelegate>;
99 friend class base::RefCountedThreadSafe<DeckLinkCaptureDelegate>; 101 friend class base::RefCountedThreadSafe<DeckLinkCaptureDelegate>;
100 102
101 ~DeckLinkCaptureDelegate() override; 103 ~DeckLinkCaptureDelegate() override;
102 104
103 DISALLOW_COPY_AND_ASSIGN(DeckLinkCaptureDelegate); 105 DISALLOW_COPY_AND_ASSIGN(DeckLinkCaptureDelegate);
104 }; 106 };
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 break; 251 break;
250 default: 252 default:
251 SendErrorString(FROM_HERE, "Unsupported pixel format"); 253 SendErrorString(FROM_HERE, "Unsupported pixel format");
252 break; 254 break;
253 } 255 }
254 256
255 const media::VideoCaptureFormat capture_format( 257 const media::VideoCaptureFormat capture_format(
256 gfx::Size(video_frame->GetWidth(), video_frame->GetHeight()), 258 gfx::Size(video_frame->GetWidth(), video_frame->GetHeight()),
257 0.0f, // Frame rate is not needed for captured data callback. 259 0.0f, // Frame rate is not needed for captured data callback.
258 pixel_format); 260 pixel_format);
261 base::TimeTicks now = base::TimeTicks::Now();
262 if (first_ref_time_.is_null())
263 first_ref_time_ = now;
259 base::AutoLock lock(lock_); 264 base::AutoLock lock(lock_);
260 if (frame_receiver_) { 265 if (frame_receiver_) {
266 const BMDTimeScale micros_time_scale = base::Time::kMicrosecondsPerSecond;
267 BMDTimeValue frame_time;
268 BMDTimeValue frame_duration;
269 base::TimeDelta timestamp;
270 if (SUCCEEDED(video_frame->GetStreamTime(&frame_time, &frame_duration,
271 micros_time_scale))) {
272 timestamp = base::TimeDelta::FromMicroseconds(frame_time);
273 } else {
274 timestamp = now - first_ref_time_;
275 }
261 frame_receiver_->OnIncomingCapturedData( 276 frame_receiver_->OnIncomingCapturedData(
262 video_data, video_frame->GetRowBytes() * video_frame->GetHeight(), 277 video_data, video_frame->GetRowBytes() * video_frame->GetHeight(),
263 capture_format, 278 capture_format,
264 0, // Rotation. 279 0, // Rotation.
265 base::TimeTicks::Now()); 280 now, timestamp);
266 } 281 }
267 return S_OK; 282 return S_OK;
268 } 283 }
269 284
270 HRESULT DeckLinkCaptureDelegate::QueryInterface(REFIID iid, void** ppv) { 285 HRESULT DeckLinkCaptureDelegate::QueryInterface(REFIID iid, void** ppv) {
271 DCHECK(thread_checker_.CalledOnValidThread()); 286 DCHECK(thread_checker_.CalledOnValidThread());
272 CFUUIDBytes iunknown = CFUUIDGetUUIDBytes(IUnknownUUID); 287 CFUUIDBytes iunknown = CFUUIDGetUUIDBytes(IUnknownUUID);
273 if (memcmp(&iid, &iunknown, sizeof(REFIID)) == 0 || 288 if (memcmp(&iid, &iunknown, sizeof(REFIID)) == 0 ||
274 memcmp(&iid, &IID_IDeckLinkInputCallback, sizeof(REFIID)) == 0) { 289 memcmp(&iid, &IID_IDeckLinkInputCallback, sizeof(REFIID)) == 0) {
275 *ppv = static_cast<IDeckLinkInputCallback*>(this); 290 *ppv = static_cast<IDeckLinkInputCallback*>(this);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 459
445 VideoCaptureDeviceDeckLinkMac::~VideoCaptureDeviceDeckLinkMac() { 460 VideoCaptureDeviceDeckLinkMac::~VideoCaptureDeviceDeckLinkMac() {
446 decklink_capture_delegate_->ResetVideoCaptureDeviceReference(); 461 decklink_capture_delegate_->ResetVideoCaptureDeviceReference();
447 } 462 }
448 463
449 void VideoCaptureDeviceDeckLinkMac::OnIncomingCapturedData( 464 void VideoCaptureDeviceDeckLinkMac::OnIncomingCapturedData(
450 const uint8_t* data, 465 const uint8_t* data,
451 size_t length, 466 size_t length,
452 const VideoCaptureFormat& frame_format, 467 const VideoCaptureFormat& frame_format,
453 int rotation, // Clockwise. 468 int rotation, // Clockwise.
454 base::TimeTicks timestamp) { 469 base::TimeTicks reference_time,
470 base::TimeDelta timestamp) {
455 base::AutoLock lock(lock_); 471 base::AutoLock lock(lock_);
456 if (client_) { 472 if (client_) {
457 client_->OnIncomingCapturedData(data, length, frame_format, rotation, 473 client_->OnIncomingCapturedData(data, length, frame_format, rotation,
458 timestamp); 474 reference_time, timestamp);
459 } 475 }
460 } 476 }
461 477
462 void VideoCaptureDeviceDeckLinkMac::SendErrorString( 478 void VideoCaptureDeviceDeckLinkMac::SendErrorString(
463 const tracked_objects::Location& from_here, 479 const tracked_objects::Location& from_here,
464 const std::string& reason) { 480 const std::string& reason) {
465 DCHECK(thread_checker_.CalledOnValidThread()); 481 DCHECK(thread_checker_.CalledOnValidThread());
466 base::AutoLock lock(lock_); 482 base::AutoLock lock(lock_);
467 if (client_) 483 if (client_)
468 client_->OnError(from_here, reason); 484 client_->OnError(from_here, reason);
(...skipping 14 matching lines...) Expand all
483 if (decklink_capture_delegate_.get()) 499 if (decklink_capture_delegate_.get())
484 decklink_capture_delegate_->AllocateAndStart(params); 500 decklink_capture_delegate_->AllocateAndStart(params);
485 } 501 }
486 502
487 void VideoCaptureDeviceDeckLinkMac::StopAndDeAllocate() { 503 void VideoCaptureDeviceDeckLinkMac::StopAndDeAllocate() {
488 if (decklink_capture_delegate_.get()) 504 if (decklink_capture_delegate_.get())
489 decklink_capture_delegate_->StopAndDeAllocate(); 505 decklink_capture_delegate_->StopAndDeAllocate();
490 } 506 }
491 507
492 } // namespace media 508 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/mac/video_capture_device_decklink_mac.h ('k') | media/capture/video/mac/video_capture_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698