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

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

Issue 17402002: Reconnect support for DirectShow video capture devices in parallel to MediaFoundation ones. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CaptureApiType wrapped into a CaptureApiClass for default value. 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
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_win.h" 5 #include "media/video/capture/win/video_capture_device_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (mt != NULL) { 141 if (mt != NULL) {
142 FreeMediaType(mt); 142 FreeMediaType(mt);
143 CoTaskMemFree(mt); 143 CoTaskMemFree(mt);
144 } 144 }
145 } 145 }
146 146
147 } // namespace 147 } // namespace
148 148
149 // static 149 // static
150 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { 150 void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
151 Names::iterator it;
152
151 if (VideoCaptureDeviceMFWin::PlatformSupported()) { 153 if (VideoCaptureDeviceMFWin::PlatformSupported()) {
152 VideoCaptureDeviceMFWin::GetDeviceNames(device_names); 154 VideoCaptureDeviceMFWin::GetDeviceNames(device_names);
153 } else {
154 VideoCaptureDeviceWin::GetDeviceNames(device_names);
155 } 155 }
156 // Retrieve the devices with DirectShow (DS) interface. They might (partially)
157 // overlap with the MediaFoundation (MF), so the list has to be consolidated.
158 Names temp_names;
159 VideoCaptureDeviceWin::GetDeviceNames(&temp_names);
160
161 // Merge the DS devices into the MF device list, and next remove
162 // the duplicates, giving priority to the MF "versions".
163 device_names->merge(temp_names);
164 device_names->unique();
156 } 165 }
157 166
158 // static 167 // static
159 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { 168 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
160 VideoCaptureDevice* ret = NULL; 169 VideoCaptureDevice* ret = NULL;
161 if (VideoCaptureDeviceMFWin::PlatformSupported()) { 170 if ((device_name.capture_api_type() == Name::MEDIA_FOUNDATION) &&
171 VideoCaptureDeviceMFWin::PlatformSupported()) {
tommi (sloooow) - chröme 2013/07/03 15:27:26 the second check shouldn't be necessary anymore so
mcasas 2013/07/04 10:40:42 Done.
162 scoped_ptr<VideoCaptureDeviceMFWin> device( 172 scoped_ptr<VideoCaptureDeviceMFWin> device(
163 new VideoCaptureDeviceMFWin(device_name)); 173 new VideoCaptureDeviceMFWin(device_name));
174 DLOG(INFO) << " MediaFoundation Device: " << device_name.name();
164 if (device->Init()) 175 if (device->Init())
165 ret = device.release(); 176 ret = device.release();
166 } else { 177 } else if (device_name.capture_api_type() == Name::DIRECT_SHOW) {
167 scoped_ptr<VideoCaptureDeviceWin> device( 178 scoped_ptr<VideoCaptureDeviceWin> device(
168 new VideoCaptureDeviceWin(device_name)); 179 new VideoCaptureDeviceWin(device_name));
180 DLOG(INFO) << " DirectShow Device: " << device_name.name();
tommi (sloooow) - chröme 2013/07/03 15:27:26 Change all DLOG(INFO)s to DVLOG(1). (we don't use
mcasas 2013/07/04 10:40:42 Done.
169 if (device->Init()) 181 if (device->Init())
170 ret = device.release(); 182 ret = device.release();
183 } else{
184 NOTREACHED() << " Couldn't recognize VideoCaptureDevice type";
171 } 185 }
172 186
173 return ret; 187 return ret;
174 } 188 }
175 189
176 // static 190 // static
177 void VideoCaptureDeviceWin::GetDeviceNames(Names* device_names) { 191 void VideoCaptureDeviceWin::GetDeviceNames(Names* device_names) {
178 DCHECK(device_names); 192 DCHECK(device_names);
179 193
180 ScopedComPtr<ICreateDevEnum> dev_enum; 194 ScopedComPtr<ICreateDevEnum> dev_enum;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 std::string device_name(base::SysWideToUTF8(str_ptr)); 243 std::string device_name(base::SysWideToUTF8(str_ptr));
230 name.Reset(); 244 name.Reset();
231 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0); 245 hr = prop_bag->Read(L"DevicePath", name.Receive(), 0);
232 if (FAILED(hr) || name.type() != VT_BSTR) { 246 if (FAILED(hr) || name.type() != VT_BSTR) {
233 id = device_name; 247 id = device_name;
234 } else { 248 } else {
235 DCHECK_EQ(name.type(), VT_BSTR); 249 DCHECK_EQ(name.type(), VT_BSTR);
236 id = base::SysWideToUTF8(V_BSTR(&name)); 250 id = base::SysWideToUTF8(V_BSTR(&name));
237 } 251 }
238 252
239 device_names->push_back(Name(device_name, id)); 253 device_names->push_back(Name(device_name, id, Name::DIRECT_SHOW));
240 } 254 }
241 } 255 }
242 moniker.Release(); 256 moniker.Release();
243 } 257 }
244 } 258 }
245 259
246 VideoCaptureDeviceWin::VideoCaptureDeviceWin(const Name& device_name) 260 VideoCaptureDeviceWin::VideoCaptureDeviceWin(const Name& device_name)
247 : device_name_(device_name), 261 : device_name_(device_name),
248 state_(kIdle), 262 state_(kIdle),
249 observer_(NULL) { 263 observer_(NULL) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 capability.color = VideoCaptureCapability::kI420; 582 capability.color = VideoCaptureCapability::kI420;
569 } else if (media_type->subtype == MEDIASUBTYPE_IYUV) { 583 } else if (media_type->subtype == MEDIASUBTYPE_IYUV) {
570 // This is identical to kI420. 584 // This is identical to kI420.
571 capability.color = VideoCaptureCapability::kI420; 585 capability.color = VideoCaptureCapability::kI420;
572 } else if (media_type->subtype == MEDIASUBTYPE_RGB24) { 586 } else if (media_type->subtype == MEDIASUBTYPE_RGB24) {
573 capability.color = VideoCaptureCapability::kRGB24; 587 capability.color = VideoCaptureCapability::kRGB24;
574 } else if (media_type->subtype == MEDIASUBTYPE_YUY2) { 588 } else if (media_type->subtype == MEDIASUBTYPE_YUY2) {
575 capability.color = VideoCaptureCapability::kYUY2; 589 capability.color = VideoCaptureCapability::kYUY2;
576 } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { 590 } else if (media_type->subtype == MEDIASUBTYPE_MJPG) {
577 capability.color = VideoCaptureCapability::kMJPEG; 591 capability.color = VideoCaptureCapability::kMJPEG;
592 } else if (media_type->subtype == MEDIASUBTYPE_UYVY) {
593 capability.color = VideoCaptureCapability::kUYVY;
594 } else if (media_type->subtype == MEDIASUBTYPE_ARGB32) {
595 capability.color = VideoCaptureCapability::kARGB;
578 } else { 596 } else {
579 WCHAR guid_str[128]; 597 WCHAR guid_str[128];
580 StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); 598 StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str));
581 DVLOG(2) << "Device support unknown media type " << guid_str; 599 DVLOG(2) << "Device supports (also) an unknown media type " << guid_str;
582 continue; 600 continue;
583 } 601 }
584 capabilities_.Add(capability); 602 capabilities_.Add(capability);
585 } 603 }
586 DeleteMediaType(media_type); 604 DeleteMediaType(media_type);
587 media_type = NULL; 605 media_type = NULL;
588 } 606 }
589 607
590 return !capabilities_.empty(); 608 return !capabilities_.empty();
591 } 609 }
592 610
593 void VideoCaptureDeviceWin::SetErrorState(const char* reason) { 611 void VideoCaptureDeviceWin::SetErrorState(const char* reason) {
594 DCHECK(CalledOnValidThread()); 612 DCHECK(CalledOnValidThread());
595 DVLOG(1) << reason; 613 DVLOG(1) << reason;
596 state_ = kError; 614 state_ = kError;
597 observer_->OnError(); 615 observer_->OnError();
598 } 616 }
599
600 } // namespace media 617 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698