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

Side by Side Diff: media/capture/video/win/video_capture_device_mf_win.cc

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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/win/video_capture_device_mf_win.h" 5 #include "media/capture/video/win/video_capture_device_mf_win.h"
6 6
7 #include <mfapi.h> 7 #include <mfapi.h>
8 #include <mferror.h> 8 #include <mferror.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 STDMETHOD_(ULONG, AddRef)() override { 102 STDMETHOD_(ULONG, AddRef)() override {
103 base::RefCountedThreadSafe<MFReaderCallback>::AddRef(); 103 base::RefCountedThreadSafe<MFReaderCallback>::AddRef();
104 return 1U; 104 return 1U;
105 } 105 }
106 106
107 STDMETHOD_(ULONG, Release)() override { 107 STDMETHOD_(ULONG, Release)() override {
108 base::RefCountedThreadSafe<MFReaderCallback>::Release(); 108 base::RefCountedThreadSafe<MFReaderCallback>::Release();
109 return 1U; 109 return 1U;
110 } 110 }
111 111
112 STDMETHOD(OnReadSample)(HRESULT status, 112 STDMETHOD(OnReadSample)
113 DWORD stream_index, 113 (HRESULT status,
114 DWORD stream_flags, 114 DWORD stream_index,
115 LONGLONG time_stamp, 115 DWORD stream_flags,
116 IMFSample* sample) override { 116 LONGLONG raw_time_stamp,
117 base::TimeTicks stamp(base::TimeTicks::Now()); 117 IMFSample* sample) override {
118 base::TimeTicks reference_time(base::TimeTicks::Now());
119 base::TimeDelta timestamp =
120 base::TimeDelta::FromMicroseconds(raw_time_stamp / 10);
118 if (!sample) { 121 if (!sample) {
119 observer_->OnIncomingCapturedData(NULL, 0, 0, stamp); 122 observer_->OnIncomingCapturedData(NULL, 0, 0, reference_time, timestamp);
120 return S_OK; 123 return S_OK;
121 } 124 }
122 125
123 DWORD count = 0; 126 DWORD count = 0;
124 sample->GetBufferCount(&count); 127 sample->GetBufferCount(&count);
125 128
126 for (DWORD i = 0; i < count; ++i) { 129 for (DWORD i = 0; i < count; ++i) {
127 ScopedComPtr<IMFMediaBuffer> buffer; 130 ScopedComPtr<IMFMediaBuffer> buffer;
128 sample->GetBufferByIndex(i, buffer.Receive()); 131 sample->GetBufferByIndex(i, buffer.Receive());
129 if (buffer.get()) { 132 if (buffer.get()) {
130 DWORD length = 0, max_length = 0; 133 DWORD length = 0, max_length = 0;
131 BYTE* data = NULL; 134 BYTE* data = NULL;
132 buffer->Lock(&data, &max_length, &length); 135 buffer->Lock(&data, &max_length, &length);
133 observer_->OnIncomingCapturedData(data, length, 0, stamp); 136 observer_->OnIncomingCapturedData(data, length, 0, reference_time,
137 timestamp);
134 buffer->Unlock(); 138 buffer->Unlock();
135 } 139 }
136 } 140 }
137 return S_OK; 141 return S_OK;
138 } 142 }
139 143
140 STDMETHOD(OnFlush)(DWORD stream_index) override { 144 STDMETHOD(OnFlush)(DWORD stream_index) override {
141 if (wait_event_) { 145 if (wait_event_) {
142 wait_event_->Signal(); 146 wait_event_->Signal();
143 wait_event_ = NULL; 147 wait_event_ = NULL;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // do not wait at all after getting MEVideoCaptureDeviceRemoved event. 296 // do not wait at all after getting MEVideoCaptureDeviceRemoved event.
293 // See issue/226396. 297 // See issue/226396.
294 if (wait) 298 if (wait)
295 flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs)); 299 flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs));
296 } 300 }
297 301
298 void VideoCaptureDeviceMFWin::OnIncomingCapturedData( 302 void VideoCaptureDeviceMFWin::OnIncomingCapturedData(
299 const uint8_t* data, 303 const uint8_t* data,
300 int length, 304 int length,
301 int rotation, 305 int rotation,
302 const base::TimeTicks& time_stamp) { 306 base::TimeTicks reference_time,
307 base::TimeDelta timestamp) {
303 base::AutoLock lock(lock_); 308 base::AutoLock lock(lock_);
304 if (data && client_.get()) { 309 if (data && client_.get()) {
305 client_->OnIncomingCapturedData(data, length, capture_format_, rotation, 310 client_->OnIncomingCapturedData(data, length, capture_format_, rotation,
306 time_stamp); 311 reference_time, timestamp);
307 } 312 }
308 313
309 if (capture_) { 314 if (capture_) {
310 HRESULT hr = 315 HRESULT hr =
311 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); 316 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL);
312 if (FAILED(hr)) { 317 if (FAILED(hr)) {
313 // If running the *VideoCap* unit tests on repeat, this can sometimes 318 // If running the *VideoCap* unit tests on repeat, this can sometimes
314 // fail with HRESULT_FROM_WINHRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION). 319 // fail with HRESULT_FROM_WINHRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION).
315 // It's not clear to me why this is, but it is possible that it has 320 // It's not clear to me why this is, but it is possible that it has
316 // something to do with this bug: 321 // something to do with this bug:
317 // http://support.microsoft.com/kb/979567 322 // http://support.microsoft.com/kb/979567
318 OnError(FROM_HERE, hr); 323 OnError(FROM_HERE, hr);
319 } 324 }
320 } 325 }
321 } 326 }
322 327
323 void VideoCaptureDeviceMFWin::OnError( 328 void VideoCaptureDeviceMFWin::OnError(
324 const tracked_objects::Location& from_here, 329 const tracked_objects::Location& from_here,
325 HRESULT hr) { 330 HRESULT hr) {
326 if (client_.get()) { 331 if (client_.get()) {
327 client_->OnError( 332 client_->OnError(
328 from_here, 333 from_here,
329 base::StringPrintf("VideoCaptureDeviceMFWin: %s", 334 base::StringPrintf("VideoCaptureDeviceMFWin: %s",
330 logging::SystemErrorCodeToString(hr).c_str())); 335 logging::SystemErrorCodeToString(hr).c_str()));
331 } 336 }
332 } 337 }
333 338
334 } // namespace media 339 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/win/video_capture_device_mf_win.h ('k') | media/capture/video/win/video_capture_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698