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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 HRESULT FillCapabilities(IMFSourceReader* source, | 60 HRESULT FillCapabilities(IMFSourceReader* source, |
61 CapabilityList* capabilities) { | 61 CapabilityList* capabilities) { |
62 DWORD stream_index = 0; | 62 DWORD stream_index = 0; |
63 ScopedComPtr<IMFMediaType> type; | 63 ScopedComPtr<IMFMediaType> type; |
64 HRESULT hr; | 64 HRESULT hr; |
65 while (SUCCEEDED(hr = source->GetNativeMediaType( | 65 while (SUCCEEDED(hr = source->GetNativeMediaType( |
66 kFirstVideoStream, stream_index, type.Receive()))) { | 66 kFirstVideoStream, stream_index, type.GetAddressOf()))) { |
67 VideoCaptureFormat format; | 67 VideoCaptureFormat format; |
68 if (FillFormat(type.Get(), &format)) | 68 if (FillFormat(type.Get(), &format)) |
69 capabilities->emplace_back(stream_index, format); | 69 capabilities->emplace_back(stream_index, format); |
70 type.Reset(); | 70 type.Reset(); |
71 ++stream_index; | 71 ++stream_index; |
72 } | 72 } |
73 | 73 |
74 if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES)) | 74 if (capabilities->empty() && (SUCCEEDED(hr) || hr == MF_E_NO_MORE_TYPES)) |
75 hr = HRESULT_FROM_WIN32(ERROR_EMPTY); | 75 hr = HRESULT_FROM_WIN32(ERROR_EMPTY); |
76 | 76 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 if (!sample) { | 116 if (!sample) { |
117 observer_->OnIncomingCapturedData(NULL, 0, 0, reference_time, timestamp); | 117 observer_->OnIncomingCapturedData(NULL, 0, 0, reference_time, timestamp); |
118 return S_OK; | 118 return S_OK; |
119 } | 119 } |
120 | 120 |
121 DWORD count = 0; | 121 DWORD count = 0; |
122 sample->GetBufferCount(&count); | 122 sample->GetBufferCount(&count); |
123 | 123 |
124 for (DWORD i = 0; i < count; ++i) { | 124 for (DWORD i = 0; i < count; ++i) { |
125 ScopedComPtr<IMFMediaBuffer> buffer; | 125 ScopedComPtr<IMFMediaBuffer> buffer; |
126 sample->GetBufferByIndex(i, buffer.Receive()); | 126 sample->GetBufferByIndex(i, buffer.GetAddressOf()); |
127 if (buffer.Get()) { | 127 if (buffer.Get()) { |
128 DWORD length = 0, max_length = 0; | 128 DWORD length = 0, max_length = 0; |
129 BYTE* data = NULL; | 129 BYTE* data = NULL; |
130 buffer->Lock(&data, &max_length, &length); | 130 buffer->Lock(&data, &max_length, &length); |
131 observer_->OnIncomingCapturedData(data, length, 0, reference_time, | 131 observer_->OnIncomingCapturedData(data, length, 0, reference_time, |
132 timestamp); | 132 timestamp); |
133 buffer->Unlock(); | 133 buffer->Unlock(); |
134 } | 134 } |
135 } | 135 } |
136 return S_OK; | 136 return S_OK; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { | 195 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { |
196 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
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(CalledOnValidThread()); |
202 DCHECK(!reader_.Get()); | 202 DCHECK(!reader_.Get()); |
203 | 203 |
204 ScopedComPtr<IMFAttributes> attributes; | 204 ScopedComPtr<IMFAttributes> attributes; |
205 MFCreateAttributes(attributes.Receive(), 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_.Receive())); | 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(CalledOnValidThread()); |
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); |
229 if (SUCCEEDED(hr)) { | 229 if (SUCCEEDED(hr)) { |
230 const CapabilityWin found_capability = | 230 const CapabilityWin found_capability = |
231 GetBestMatchedCapability(params.requested_format, capabilities); | 231 GetBestMatchedCapability(params.requested_format, capabilities); |
232 ScopedComPtr<IMFMediaType> type; | 232 ScopedComPtr<IMFMediaType> type; |
233 hr = reader_->GetNativeMediaType( | 233 hr = reader_->GetNativeMediaType(kFirstVideoStream, |
234 kFirstVideoStream, found_capability.stream_index, type.Receive()); | 234 found_capability.stream_index, |
| 235 type.GetAddressOf()); |
235 if (SUCCEEDED(hr)) { | 236 if (SUCCEEDED(hr)) { |
236 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type.Get()); | 237 hr = reader_->SetCurrentMediaType(kFirstVideoStream, NULL, type.Get()); |
237 if (SUCCEEDED(hr)) { | 238 if (SUCCEEDED(hr)) { |
238 hr = | 239 hr = |
239 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); | 240 reader_->ReadSample(kFirstVideoStream, 0, NULL, NULL, NULL, NULL); |
240 if (SUCCEEDED(hr)) { | 241 if (SUCCEEDED(hr)) { |
241 capture_format_ = found_capability.supported_format; | 242 capture_format_ = found_capability.supported_format; |
242 client_->OnStarted(); | 243 client_->OnStarted(); |
243 capture_ = true; | 244 capture_ = true; |
244 return; | 245 return; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 HRESULT hr) { | 312 HRESULT hr) { |
312 if (client_.get()) { | 313 if (client_.get()) { |
313 client_->OnError( | 314 client_->OnError( |
314 from_here, | 315 from_here, |
315 base::StringPrintf("VideoCaptureDeviceMFWin: %s", | 316 base::StringPrintf("VideoCaptureDeviceMFWin: %s", |
316 logging::SystemErrorCodeToString(hr).c_str())); | 317 logging::SystemErrorCodeToString(hr).c_str())); |
317 } | 318 } |
318 } | 319 } |
319 | 320 |
320 } // namespace media | 321 } // namespace media |
OLD | NEW |