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

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

Issue 17846002: Refactor the VideoCaptureDevice::Name struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 5 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 | Annotate | Revision Log
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/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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 HRESULT hr; 261 HRESULT hr;
262 for (UINT32 i = 0; i < count; ++i) { 262 for (UINT32 i = 0; i < count; ++i) {
263 UINT32 name_size, id_size; 263 UINT32 name_size, id_size;
264 ScopedCoMem<wchar_t> name, id; 264 ScopedCoMem<wchar_t> name, id;
265 if (SUCCEEDED(hr = devices[i]->GetAllocatedString( 265 if (SUCCEEDED(hr = devices[i]->GetAllocatedString(
266 MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &name, &name_size)) && 266 MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &name, &name_size)) &&
267 SUCCEEDED(hr = devices[i]->GetAllocatedString( 267 SUCCEEDED(hr = devices[i]->GetAllocatedString(
268 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id, 268 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id,
269 &id_size))) { 269 &id_size))) {
270 std::wstring name_w(name, name_size), id_w(id, id_size); 270 std::wstring name_w(name, name_size), id_w(id, id_size);
271 Name device; 271 Name device(base::SysWideToUTF8(name_w), base::SysWideToUTF8(id_w));
272 device.device_name = base::SysWideToUTF8(name_w);
273 device.unique_id = base::SysWideToUTF8(id_w);
274 device_names->push_back(device); 272 device_names->push_back(device);
275 } else { 273 } else {
276 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; 274 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr;
277 } 275 }
278 devices[i]->Release(); 276 devices[i]->Release();
279 } 277 }
280 } 278 }
281 279
282 VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin(const Name& device_name) 280 VideoCaptureDeviceMFWin::VideoCaptureDeviceMFWin(const Name& device_name)
283 : name_(device_name), observer_(NULL), capture_(0) { 281 : name_(device_name), observer_(NULL), capture_(0) {
284 DetachFromThread(); 282 DetachFromThread();
285 } 283 }
286 284
287 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() { 285 VideoCaptureDeviceMFWin::~VideoCaptureDeviceMFWin() {
288 DCHECK(CalledOnValidThread()); 286 DCHECK(CalledOnValidThread());
289 } 287 }
290 288
291 bool VideoCaptureDeviceMFWin::Init() { 289 bool VideoCaptureDeviceMFWin::Init() {
292 DCHECK(CalledOnValidThread()); 290 DCHECK(CalledOnValidThread());
293 DCHECK(!reader_); 291 DCHECK(!reader_);
294 292
295 ScopedComPtr<IMFMediaSource> source; 293 ScopedComPtr<IMFMediaSource> source;
296 if (!CreateVideoCaptureDevice(name_.unique_id.c_str(), source.Receive())) 294 if (!CreateVideoCaptureDevice(name_.id().c_str(), source.Receive()))
297 return false; 295 return false;
298 296
299 ScopedComPtr<IMFAttributes> attributes; 297 ScopedComPtr<IMFAttributes> attributes;
300 MFCreateAttributes(attributes.Receive(), 1); 298 MFCreateAttributes(attributes.Receive(), 1);
301 DCHECK(attributes); 299 DCHECK(attributes);
302 300
303 callback_ = new MFReaderCallback(this); 301 callback_ = new MFReaderCallback(this);
304 attributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, callback_.get()); 302 attributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, callback_.get());
305 303
306 return SUCCEEDED(MFCreateSourceReaderFromMediaSource(source, attributes, 304 return SUCCEEDED(MFCreateSourceReaderFromMediaSource(source, attributes,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 428 }
431 } 429 }
432 430
433 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { 431 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) {
434 DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr; 432 DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr;
435 if (observer_) 433 if (observer_)
436 observer_->OnError(); 434 observer_->OnError();
437 } 435 }
438 436
439 } // namespace media 437 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/video_capture_device_unittest.cc ('k') | media/video/capture/win/video_capture_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698