diff options
author | mcasas@chromium.org <mcasas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-05 19:23:30 +0000 |
---|---|---|
committer | mcasas@chromium.org <mcasas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-05 19:23:30 +0000 |
commit | 5cba2ea5aaa1de1398a282f36096fec5aecce4e1 (patch) | |
tree | aedca040ed858bbb6c33137e44888b5156fe534e /media | |
parent | a2c24fa69e3bb3f1eedb12cf40fda3e80d70cd08 (diff) | |
download | chromium_src-5cba2ea5aaa1de1398a282f36096fec5aecce4e1.zip chromium_src-5cba2ea5aaa1de1398a282f36096fec5aecce4e1.tar.gz chromium_src-5cba2ea5aaa1de1398a282f36096fec5aecce4e1.tar.bz2 |
Reconnect support for DirectShow video capture devices in parallel to MediaFoundation ones - UNITTESTS
https://codereview.chromium.org/17402002/ broke the build - sorting out unittests for XP platforms
BUG=144465
Review URL: https://chromiumcodereview.appspot.com/18529004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210320 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
5 files changed, 77 insertions, 10 deletions
diff --git a/media/video/capture/video_capture_device.h b/media/video/capture/video_capture_device.h index e5be413..f571a76 100644 --- a/media/video/capture/video_capture_device.h +++ b/media/video/capture/video_capture_device.h @@ -15,6 +15,7 @@ #include <list> #include <string> +#include "base/logging.h" #include "base/time/time.h" #include "media/base/media_export.h" #include "media/video/capture/video_capture_types.h" @@ -36,6 +37,20 @@ class MEDIA_EXPORT VideoCaptureDevice { Name() {} Name(const std::string& name, const std::string& id) : device_name_(name), unique_id_(id) {} + +#if defined(OS_WIN) + // Windows targets Capture Api type: it can only be set on construction. + enum CaptureApiType { + MEDIA_FOUNDATION, + DIRECT_SHOW, + API_TYPE_UNKNOWN + }; + + Name(const std::string& name, + const std::string& id, + const CaptureApiType api_type) + : device_name_(name), unique_id_(id), capture_api_class_(api_type) {} +#endif // if defined(OS_WIN) ~Name() {} // Friendly name of a device @@ -55,9 +70,33 @@ class MEDIA_EXPORT VideoCaptureDevice { return unique_id_ < other.id(); } +#if defined(OS_WIN) + CaptureApiType capture_api_type() const { + return capture_api_class_.capture_api_type(); + } +#endif // if defined(OS_WIN) + private: std::string device_name_; std::string unique_id_; +#if defined(OS_WIN) + // This class wraps the CaptureApiType, so it has a by default value if not + // inititalized, and I (mcasas) do a DCHECK on reading its value. + class CaptureApiClass{ + public: + CaptureApiClass(): capture_api_type_(API_TYPE_UNKNOWN) {} + CaptureApiClass(const CaptureApiType api_type) + : capture_api_type_(api_type) {} + CaptureApiType capture_api_type() const { + DCHECK_NE(capture_api_type_, API_TYPE_UNKNOWN); + return capture_api_type_; + } + private: + CaptureApiType capture_api_type_; + }; + + CaptureApiClass capture_api_class_; +#endif // if defined(OS_WIN) // Allow generated copy constructor and assignment. }; diff --git a/media/video/capture/video_capture_device_unittest.cc b/media/video/capture/video_capture_device_unittest.cc index 696c51c..724d3c0 100644 --- a/media/video/capture/video_capture_device_unittest.cc +++ b/media/video/capture/video_capture_device_unittest.cc @@ -15,6 +15,7 @@ #if defined(OS_WIN) #include "base/win/scoped_com_initializer.h" +#include "media/video/capture/win/video_capture_device_mf_win.h" #endif #if defined(OS_ANDROID) @@ -127,7 +128,15 @@ class VideoCaptureDeviceTest : public testing::Test { }; TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { +#if defined(OS_WIN) + VideoCaptureDevice::Name::CaptureApiType api_type = + VideoCaptureDeviceMFWin::PlatformSupported() + ? VideoCaptureDevice::Name::MEDIA_FOUNDATION + : VideoCaptureDevice::Name::DIRECT_SHOW; + VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); +#else VideoCaptureDevice::Name device_name("jibberish", "jibberish"); +#endif VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); EXPECT_TRUE(device == NULL); } @@ -144,7 +153,7 @@ TEST_F(VideoCaptureDeviceTest, CaptureVGA) { ASSERT_FALSE(device.get() == NULL); // Get info about the new resolution. - EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30, _)) + EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, _, _)) .Times(1); EXPECT_CALL(*frame_observer_, OnErr()) diff --git a/media/video/capture/win/video_capture_device_mf_win.cc b/media/video/capture/win/video_capture_device_mf_win.cc index d27598b..5633e3d 100644 --- a/media/video/capture/win/video_capture_device_mf_win.cc +++ b/media/video/capture/win/video_capture_device_mf_win.cc @@ -268,7 +268,8 @@ void VideoCaptureDeviceMFWin::GetDeviceNames(Names* device_names) { MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id, &id_size))) { std::wstring name_w(name, name_size), id_w(id, id_size); - Name device(base::SysWideToUTF8(name_w), base::SysWideToUTF8(id_w)); + Name device(base::SysWideToUTF8(name_w), base::SysWideToUTF8(id_w), + Name::MEDIA_FOUNDATION); device_names->push_back(device); } else { DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; diff --git a/media/video/capture/win/video_capture_device_mf_win.h b/media/video/capture/win/video_capture_device_mf_win.h index bfe55f6..e3a87e4 100644 --- a/media/video/capture/win/video_capture_device_mf_win.h +++ b/media/video/capture/win/video_capture_device_mf_win.h @@ -17,6 +17,7 @@ #include "base/synchronization/lock.h" #include "base/threading/non_thread_safe.h" #include "base/win/scoped_comptr.h" +#include "media/base/media_export.h" #include "media/video/capture/video_capture_device.h" interface IMFSourceReader; @@ -25,7 +26,7 @@ namespace media { class MFReaderCallback; -class VideoCaptureDeviceMFWin +class MEDIA_EXPORT VideoCaptureDeviceMFWin : public base::NonThreadSafe, public VideoCaptureDevice { public: diff --git a/media/video/capture/win/video_capture_device_win.cc b/media/video/capture/win/video_capture_device_win.cc index 2066066..32ac70c 100644 --- a/media/video/capture/win/video_capture_device_win.cc +++ b/media/video/capture/win/video_capture_device_win.cc @@ -148,26 +148,40 @@ void DeleteMediaType(AM_MEDIA_TYPE* mt) { // static void VideoCaptureDevice::GetDeviceNames(Names* device_names) { + Names::iterator it; + if (VideoCaptureDeviceMFWin::PlatformSupported()) { VideoCaptureDeviceMFWin::GetDeviceNames(device_names); - } else { - VideoCaptureDeviceWin::GetDeviceNames(device_names); } + // Retrieve the devices with DirectShow (DS) interface. They might (partially) + // overlap with the MediaFoundation (MF), so the list has to be consolidated. + Names temp_names; + VideoCaptureDeviceWin::GetDeviceNames(&temp_names); + + // Merge the DS devices into the MF device list, and next remove + // the duplicates, giving priority to the MF "versions". + device_names->merge(temp_names); + device_names->unique(); } // static VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { VideoCaptureDevice* ret = NULL; - if (VideoCaptureDeviceMFWin::PlatformSupported()) { + if (device_name.capture_api_type() == Name::MEDIA_FOUNDATION) { + DCHECK(VideoCaptureDeviceMFWin::PlatformSupported()); scoped_ptr<VideoCaptureDeviceMFWin> device( new VideoCaptureDeviceMFWin(device_name)); + DVLOG(1) << " MediaFoundation Device: " << device_name.name(); if (device->Init()) ret = device.release(); - } else { + } else if (device_name.capture_api_type() == Name::DIRECT_SHOW) { scoped_ptr<VideoCaptureDeviceWin> device( new VideoCaptureDeviceWin(device_name)); + DVLOG(1) << " DirectShow Device: " << device_name.name(); if (device->Init()) ret = device.release(); + } else{ + NOTREACHED() << " Couldn't recognize VideoCaptureDevice type"; } return ret; @@ -236,7 +250,7 @@ void VideoCaptureDeviceWin::GetDeviceNames(Names* device_names) { id = base::SysWideToUTF8(V_BSTR(&name)); } - device_names->push_back(Name(device_name, id)); + device_names->push_back(Name(device_name, id, Name::DIRECT_SHOW)); } } moniker.Release(); @@ -575,10 +589,14 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() { capability.color = VideoCaptureCapability::kYUY2; } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { capability.color = VideoCaptureCapability::kMJPEG; + } else if (media_type->subtype == MEDIASUBTYPE_UYVY) { + capability.color = VideoCaptureCapability::kUYVY; + } else if (media_type->subtype == MEDIASUBTYPE_ARGB32) { + capability.color = VideoCaptureCapability::kARGB; } else { WCHAR guid_str[128]; StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); - DVLOG(2) << "Device support unknown media type " << guid_str; + DVLOG(2) << "Device supports (also) an unknown media type " << guid_str; continue; } capabilities_.Add(capability); @@ -596,5 +614,4 @@ void VideoCaptureDeviceWin::SetErrorState(const char* reason) { state_ = kError; observer_->OnError(); } - } // namespace media |