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/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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 ScopedComPtr<IMFMediaType> type; | 232 ScopedComPtr<IMFMediaType> type; |
233 hr = reader_->GetNativeMediaType( | 233 hr = reader_->GetNativeMediaType( |
234 kFirstVideoStream, found_capability.stream_index, type.Receive()); | 234 kFirstVideoStream, found_capability.stream_index, type.Receive()); |
235 if (SUCCEEDED(hr)) { | 235 if (SUCCEEDED(hr)) { |
236 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type.get()); | 236 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type.get()); |
237 if (SUCCEEDED(hr)) { | 237 if (SUCCEEDED(hr)) { |
238 hr = | 238 hr = |
239 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); | 239 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); |
240 if (SUCCEEDED(hr)) { | 240 if (SUCCEEDED(hr)) { |
241 capture_format_ = found_capability.supported_format; | 241 capture_format_ = found_capability.supported_format; |
| 242 client_->OnStarted(); |
242 capture_ = true; | 243 capture_ = true; |
243 return; | 244 return; |
244 } | 245 } |
245 } | 246 } |
246 } | 247 } |
247 } | 248 } |
248 } | 249 } |
249 | 250 |
250 OnError(FROM_HERE, hr); | 251 OnError(FROM_HERE, hr); |
251 } | 252 } |
(...skipping 27 matching lines...) Expand all Loading... |
279 flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs)); | 280 flushed.TimedWait(base::TimeDelta::FromMilliseconds(kFlushTimeOutInMs)); |
280 } | 281 } |
281 | 282 |
282 void VideoCaptureDeviceMFWin::OnIncomingCapturedData( | 283 void VideoCaptureDeviceMFWin::OnIncomingCapturedData( |
283 const uint8_t* data, | 284 const uint8_t* data, |
284 int length, | 285 int length, |
285 int rotation, | 286 int rotation, |
286 base::TimeTicks reference_time, | 287 base::TimeTicks reference_time, |
287 base::TimeDelta timestamp) { | 288 base::TimeDelta timestamp) { |
288 base::AutoLock lock(lock_); | 289 base::AutoLock lock(lock_); |
| 290 if (!capture_) |
| 291 return; |
| 292 |
289 if (data && client_.get()) { | 293 if (data && client_.get()) { |
290 client_->OnIncomingCapturedData(data, length, capture_format_, rotation, | 294 client_->OnIncomingCapturedData(data, length, capture_format_, rotation, |
291 reference_time, timestamp); | 295 reference_time, timestamp); |
292 } | 296 } |
293 | 297 |
294 if (capture_) { | 298 HRESULT hr = |
295 HRESULT hr = | 299 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); |
296 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); | 300 if (FAILED(hr)) { |
297 if (FAILED(hr)) { | 301 // If running the *VideoCap* unit tests on repeat, this can sometimes |
298 // If running the *VideoCap* unit tests on repeat, this can sometimes | 302 // fail with HRESULT_FROM_WINHRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION). |
299 // fail with HRESULT_FROM_WINHRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION). | 303 // It's not clear to me why this is, but it is possible that it has |
300 // It's not clear to me why this is, but it is possible that it has | 304 // something to do with this bug: |
301 // something to do with this bug: | 305 // http://support.microsoft.com/kb/979567 |
302 // http://support.microsoft.com/kb/979567 | 306 OnError(FROM_HERE, hr); |
303 OnError(FROM_HERE, hr); | |
304 } | |
305 } | 307 } |
306 } | 308 } |
307 | 309 |
308 void VideoCaptureDeviceMFWin::OnError( | 310 void VideoCaptureDeviceMFWin::OnError( |
309 const tracked_objects::Location& from_here, | 311 const tracked_objects::Location& from_here, |
310 HRESULT hr) { | 312 HRESULT hr) { |
311 if (client_.get()) { | 313 if (client_.get()) { |
312 client_->OnError( | 314 client_->OnError( |
313 from_here, | 315 from_here, |
314 base::StringPrintf("VideoCaptureDeviceMFWin: %s", | 316 base::StringPrintf("VideoCaptureDeviceMFWin: %s", |
315 logging::SystemErrorCodeToString(hr).c_str())); | 317 logging::SystemErrorCodeToString(hr).c_str())); |
316 } | 318 } |
317 } | 319 } |
318 | 320 |
319 } // namespace media | 321 } // namespace media |
OLD | NEW |