| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 return false; | 186 return false; |
| 187 } | 187 } |
| 188 | 188 |
| 189 VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin( | 189 VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin( |
| 190 const VideoCaptureDeviceDescriptor& device_descriptor) | 190 const VideoCaptureDeviceDescriptor& device_descriptor) |
| 191 : descriptor_(device_descriptor), capture_(0) { | 191 : descriptor_(device_descriptor), capture_(0) { |
| 192 DetachFromThread(); | 192 DETACH_FROM_SEQUENCE(sequence_checker_); |
| 193 } | 193 } |
| 194 | 194 |
| 195 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { | 195 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { |
| 196 DCHECK(CalledOnValidThread()); | 196 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool VideoCaptureDeviceMFWin::Init( | 199 bool VideoCaptureDeviceMFWin::Init( |
| 200 const base::win::ScopedComPtr<IMFMediaSource>& source) { | 200 const base::win::ScopedComPtr<IMFMediaSource>& source) { |
| 201 DCHECK(CalledOnValidThread()); | 201 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 202 DCHECK(!reader_.Get()); | 202 DCHECK(!reader_.Get()); |
| 203 | 203 |
| 204 ScopedComPtr<IMFAttributes> attributes; | 204 ScopedComPtr<IMFAttributes> attributes; |
| 205 MFCreateAttributes(attributes.GetAddressOf(), 1); | 205 MFCreateAttributes(attributes.GetAddressOf(), 1); |
| 206 DCHECK(attributes.Get()); | 206 DCHECK(attributes.Get()); |
| 207 | 207 |
| 208 callback_ = new MFReaderCallback(this); | 208 callback_ = new MFReaderCallback(this); |
| 209 attributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, callback_.get()); | 209 attributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, callback_.get()); |
| 210 | 210 |
| 211 return SUCCEEDED(MFCreateSourceReaderFromMediaSource( | 211 return SUCCEEDED(MFCreateSourceReaderFromMediaSource( |
| 212 source.Get(), attributes.Get(), reader_.GetAddressOf())); | 212 source.Get(), attributes.Get(), reader_.GetAddressOf())); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void VideoCaptureDeviceMFWin::AllocateAndStart( | 215 void VideoCaptureDeviceMFWin::AllocateAndStart( |
| 216 const VideoCaptureParams& params, | 216 const VideoCaptureParams& params, |
| 217 std::unique_ptr<VideoCaptureDevice::Client> client) { | 217 std::unique_ptr<VideoCaptureDevice::Client> client) { |
| 218 DCHECK(CalledOnValidThread()); | 218 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 219 | 219 |
| 220 base::AutoLock lock(lock_); | 220 base::AutoLock lock(lock_); |
| 221 | 221 |
| 222 client_ = std::move(client); | 222 client_ = std::move(client); |
| 223 DCHECK_EQ(capture_, false); | 223 DCHECK_EQ(capture_, false); |
| 224 | 224 |
| 225 CapabilityList capabilities; | 225 CapabilityList capabilities; |
| 226 HRESULT hr = S_OK; | 226 HRESULT hr = S_OK; |
| 227 if (reader_.Get()) { | 227 if (reader_.Get()) { |
| 228 hr = FillCapabilities(reader_.Get(), &capabilities); | 228 hr = FillCapabilities(reader_.Get(), &capabilities); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 OnError(FROM_HERE, hr); | 252 OnError(FROM_HERE, hr); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void VideoCaptureDeviceMFWin::StopAndDeAllocate() { | 255 void VideoCaptureDeviceMFWin::StopAndDeAllocate() { |
| 256 DCHECK(CalledOnValidThread()); | 256 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 257 base::WaitableEvent flushed(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 257 base::WaitableEvent flushed(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 258 base::WaitableEvent::InitialState::NOT_SIGNALED); | 258 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 259 const int kFlushTimeOutInMs = 1000; | 259 const int kFlushTimeOutInMs = 1000; |
| 260 bool wait = false; | 260 bool wait = false; |
| 261 { | 261 { |
| 262 base::AutoLock lock(lock_); | 262 base::AutoLock lock(lock_); |
| 263 if (capture_) { | 263 if (capture_) { |
| 264 capture_ = false; | 264 capture_ = false; |
| 265 callback_->SetSignalOnFlush(&flushed); | 265 callback_->SetSignalOnFlush(&flushed); |
| 266 wait = SUCCEEDED( | 266 wait = SUCCEEDED( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 HRESULT hr) { | 312 HRESULT hr) { |
| 313 if (client_.get()) { | 313 if (client_.get()) { |
| 314 client_->OnError( | 314 client_->OnError( |
| 315 from_here, | 315 from_here, |
| 316 base::StringPrintf("VideoCaptureDeviceMFWin: %s", | 316 base::StringPrintf("VideoCaptureDeviceMFWin: %s", |
| 317 logging::SystemErrorCodeToString(hr).c_str())); | 317 logging::SystemErrorCodeToString(hr).c_str())); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace media | 321 } // namespace media |
| OLD | NEW |