| OLD | NEW |
| 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/video/capture/win/video_capture_device_mf_win.h" | 5 #include "media/video/capture/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 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 STDMETHOD_(ULONG, Release)() { | 201 STDMETHOD_(ULONG, Release)() { |
| 202 base::RefCountedThreadSafe<MFReaderCallback>::Release(); | 202 base::RefCountedThreadSafe<MFReaderCallback>::Release(); |
| 203 return 1U; | 203 return 1U; |
| 204 } | 204 } |
| 205 | 205 |
| 206 STDMETHOD(OnReadSample)(HRESULT status, DWORD stream_index, | 206 STDMETHOD(OnReadSample)(HRESULT status, DWORD stream_index, |
| 207 DWORD stream_flags, LONGLONG time_stamp, IMFSample* sample) { | 207 DWORD stream_flags, LONGLONG time_stamp, IMFSample* sample) { |
| 208 base::TimeTicks stamp(base::TimeTicks::Now()); | 208 base::TimeTicks stamp(base::TimeTicks::Now()); |
| 209 if (!sample) { | 209 if (!sample) { |
| 210 observer_->OnIncomingCapturedFrame(NULL, 0, stamp, 0); | 210 observer_->OnIncomingCapturedData(NULL, 0, 0, stamp); |
| 211 return S_OK; | 211 return S_OK; |
| 212 } | 212 } |
| 213 | 213 |
| 214 DWORD count = 0; | 214 DWORD count = 0; |
| 215 sample->GetBufferCount(&count); | 215 sample->GetBufferCount(&count); |
| 216 | 216 |
| 217 for (DWORD i = 0; i < count; ++i) { | 217 for (DWORD i = 0; i < count; ++i) { |
| 218 ScopedComPtr<IMFMediaBuffer> buffer; | 218 ScopedComPtr<IMFMediaBuffer> buffer; |
| 219 sample->GetBufferByIndex(i, buffer.Receive()); | 219 sample->GetBufferByIndex(i, buffer.Receive()); |
| 220 if (buffer) { | 220 if (buffer) { |
| 221 DWORD length = 0, max_length = 0; | 221 DWORD length = 0, max_length = 0; |
| 222 BYTE* data = NULL; | 222 BYTE* data = NULL; |
| 223 buffer->Lock(&data, &max_length, &length); | 223 buffer->Lock(&data, &max_length, &length); |
| 224 observer_->OnIncomingCapturedFrame(data, length, stamp, 0); | 224 observer_->OnIncomingCapturedData(data, length, 0, stamp); |
| 225 buffer->Unlock(); | 225 buffer->Unlock(); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 return S_OK; | 228 return S_OK; |
| 229 } | 229 } |
| 230 | 230 |
| 231 STDMETHOD(OnFlush)(DWORD stream_index) { | 231 STDMETHOD(OnFlush)(DWORD stream_index) { |
| 232 if (wait_event_) { | 232 if (wait_event_) { |
| 233 wait_event_->Signal(); | 233 wait_event_->Signal(); |
| 234 wait_event_ = NULL; | 234 wait_event_ = NULL; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 // If the device has been unplugged, the Flush() won't trigger the event | 453 // If the device has been unplugged, the Flush() won't trigger the event |
| 454 // and a timeout will happen. | 454 // and a timeout will happen. |
| 455 // TODO(tommi): Hook up the IMFMediaEventGenerator notifications API and | 455 // TODO(tommi): Hook up the IMFMediaEventGenerator notifications API and |
| 456 // do not wait at all after getting MEVideoCaptureDeviceRemoved event. | 456 // do not wait at all after getting MEVideoCaptureDeviceRemoved event. |
| 457 // See issue/226396. | 457 // See issue/226396. |
| 458 if (wait) | 458 if (wait) |
| 459 flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs)); | 459 flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void VideoCaptureDeviceMFWin::OnIncomingCapturedFrame( | 462 void VideoCaptureDeviceMFWin::OnIncomingCapturedData( |
| 463 const uint8* data, | 463 const uint8* data, |
| 464 int length, | 464 int length, |
| 465 const base::TimeTicks& time_stamp, | 465 const base::TimeTicks& time_stamp, |
| 466 int rotation) { | 466 int rotation) { |
| 467 base::AutoLock lock(lock_); | 467 base::AutoLock lock(lock_); |
| 468 if (data && client_.get()) | 468 if (data && client_.get()) |
| 469 client_->OnIncomingCapturedFrame(data, | 469 client_->OnIncomingCapturedData( |
| 470 length, | 470 data, length, time_stamp, rotation, capture_format_); |
| 471 time_stamp, | |
| 472 rotation, | |
| 473 capture_format_); | |
| 474 | 471 |
| 475 if (capture_) { | 472 if (capture_) { |
| 476 HRESULT hr = reader_->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, | 473 HRESULT hr = reader_->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, |
| 477 NULL, NULL, NULL, NULL); | 474 NULL, NULL, NULL, NULL); |
| 478 if (FAILED(hr)) { | 475 if (FAILED(hr)) { |
| 479 // If running the *VideoCap* unit tests on repeat, this can sometimes | 476 // If running the *VideoCap* unit tests on repeat, this can sometimes |
| 480 // fail with HRESULT_FROM_WINHRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION). | 477 // fail with HRESULT_FROM_WINHRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION). |
| 481 // It's not clear to me why this is, but it is possible that it has | 478 // It's not clear to me why this is, but it is possible that it has |
| 482 // something to do with this bug: | 479 // something to do with this bug: |
| 483 // http://support.microsoft.com/kb/979567 | 480 // http://support.microsoft.com/kb/979567 |
| 484 OnError(hr); | 481 OnError(hr); |
| 485 } | 482 } |
| 486 } | 483 } |
| 487 } | 484 } |
| 488 | 485 |
| 489 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { | 486 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { |
| 490 std::string log_msg = base::StringPrintf("VideoCaptureDeviceMFWin: %x", hr); | 487 std::string log_msg = base::StringPrintf("VideoCaptureDeviceMFWin: %x", hr); |
| 491 DLOG(ERROR) << log_msg; | 488 DLOG(ERROR) << log_msg; |
| 492 if (client_.get()) | 489 if (client_.get()) |
| 493 client_->OnError(log_msg); | 490 client_->OnError(log_msg); |
| 494 } | 491 } |
| 495 | 492 |
| 496 } // namespace media | 493 } // namespace media |
| OLD | NEW |