Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/media/media_internals.h" | 5 #include "content/browser/media/media_internals.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/stringprintf.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "media/audio/audio_parameters.h" | 14 #include "media/audio/audio_parameters.h" |
| 14 #include "media/base/channel_layout.h" | 15 #include "media/base/channel_layout.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/geometry/size.h" | |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 const int kTestComponentID = 0; | 20 const int kTestComponentID = 0; |
| 19 const char kTestDeviceID[] = "test-device-id"; | 21 const char kTestDeviceID[] = "test-device-id"; |
| 20 | 22 |
| 21 // This class encapsulates a MediaInternals reference. It also has some useful | 23 // This class encapsulates a MediaInternals reference. It also has some useful |
| 22 // methods to receive a callback, deserialize its associated data and expect | 24 // methods to receive a callback, deserialize its associated data and expect |
| 23 // integer/string values. | 25 // integer/string values. |
| 24 class MediaInternalsTestBase { | 26 class MediaInternalsTestBase { |
| 25 public: | 27 public: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 102 } |
| 101 | 103 |
| 102 virtual ~MediaInternalsVideoCaptureDeviceTest() { | 104 virtual ~MediaInternalsVideoCaptureDeviceTest() { |
| 103 media_internals_->RemoveUpdateCallback(update_cb_); | 105 media_internals_->RemoveUpdateCallback(update_cb_); |
| 104 } | 106 } |
| 105 | 107 |
| 106 protected: | 108 protected: |
| 107 MediaInternals::UpdateCallback update_cb_; | 109 MediaInternals::UpdateCallback update_cb_; |
| 108 }; | 110 }; |
| 109 | 111 |
| 112 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 113 TEST_F(MediaInternalsVideoCaptureDeviceTest, | |
| 114 AllCaptureApiTypesHaveProperStringRepresentation) { | |
| 115 typedef media::VideoCaptureDevice::Name VideoCaptureDeviceName; | |
| 116 typedef std::map<VideoCaptureDeviceName::CaptureApiType, std::string> | |
| 117 CaptureApiTypeStringMap; | |
| 118 CaptureApiTypeStringMap m; | |
| 119 #if defined(OS_WIN) | |
| 120 m[VideoCaptureDeviceName::MEDIA_FOUNDATION] = "MEDIA_FOUNDATION"; | |
| 121 m[VideoCaptureDeviceName::DIRECT_SHOW] = "DIRECT_SHOW"; | |
| 122 m[VideoCaptureDeviceName::DIRECT_SHOW_WDM_CROSSBAR] = | |
| 123 "DIRECT_SHOW_WDM_CROSSBAR"; | |
|
xhwang
2014/10/21 19:07:49
Since these are strings, does it make sense to mak
burnik
2014/10/21 19:37:11
Done.
| |
| 124 #elif defined(OS_MACOSX) | |
| 125 m[VideoCaptureDeviceName::AVFOUNDATION] = "AVFOUNDATION"; | |
| 126 m[VideoCaptureDeviceName::QTKIT] = "QTKIT"; | |
| 127 m[VideoCaptureDeviceName::DECKLINK] = "DECKLINK"; | |
| 128 #endif | |
| 129 EXPECT_EQ(media::VideoCaptureDevice::Name::API_TYPE_UNKNOWN, m.size()); | |
| 130 for (CaptureApiTypeStringMap::iterator it = m.begin(); it != m.end(); ++it) { | |
| 131 const VideoCaptureDeviceName device_name("dummy", "dummy", it->first); | |
| 132 EXPECT_EQ(it->second, device_name.GetCaptureApiTypeString()); | |
| 133 } | |
| 134 } | |
| 135 #endif | |
| 136 | |
| 137 TEST_F(MediaInternalsVideoCaptureDeviceTest, | |
| 138 VideoCaptureFormatStringIsInExpectedFormat) { | |
| 139 // Since media internals will send video capture capabilities to JavaScript in | |
| 140 // an expected format and there are no public methods for accessing the | |
| 141 // resolutions, frame rates or pixel formats, this test checks that the format | |
| 142 // has not changed. If the test fails because of the changed format, it should | |
| 143 // be updated at the same time as the media internals JS files. | |
| 144 const float kFrameRate = 30.0f; | |
| 145 const gfx::Size kFrameSize(1280, 720); | |
| 146 const media::VideoPixelFormat kPixelFormat = media::PIXEL_FORMAT_I420; | |
| 147 const media::VideoCaptureFormat capture_format( | |
| 148 kFrameSize, kFrameRate, kPixelFormat); | |
| 149 const std::string expected_string = | |
| 150 base::StringPrintf("resolution: %s, fps: %f, pixel format: %s", | |
| 151 kFrameSize.ToString().c_str(), | |
| 152 kFrameRate, | |
| 153 media::VideoCaptureFormat::PixelFormatToString( | |
| 154 kPixelFormat).c_str()); | |
| 155 EXPECT_EQ(expected_string, capture_format.ToString()); | |
| 156 } | |
| 157 | |
| 110 TEST_F(MediaInternalsVideoCaptureDeviceTest, | 158 TEST_F(MediaInternalsVideoCaptureDeviceTest, |
| 111 NotifyVideoCaptureDeviceCapabilitiesEnumerated) { | 159 NotifyVideoCaptureDeviceCapabilitiesEnumerated) { |
| 112 const int kWidth = 1280; | 160 const int kWidth = 1280; |
| 113 const int kHeight = 720; | 161 const int kHeight = 720; |
| 114 const float kFrameRate = 30.0f; | 162 const float kFrameRate = 30.0f; |
| 115 const media::VideoPixelFormat kPixelFormat = media::PIXEL_FORMAT_I420; | 163 const media::VideoPixelFormat kPixelFormat = media::PIXEL_FORMAT_I420; |
| 116 const media::VideoCaptureFormat format_hd({kWidth, kHeight}, | 164 const media::VideoCaptureFormat format_hd({kWidth, kHeight}, |
| 117 kFrameRate, kPixelFormat); | 165 kFrameRate, kPixelFormat); |
| 118 media::VideoCaptureFormats formats{}; | 166 media::VideoCaptureFormats formats{}; |
| 119 formats.push_back(format_hd); | 167 formats.push_back(format_hd); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 142 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | 190 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 143 ExpectString("id", "/dev/dummy"); | 191 ExpectString("id", "/dev/dummy"); |
| 144 #else | 192 #else |
| 145 ExpectString("id", "dummy"); | 193 ExpectString("id", "dummy"); |
| 146 #endif | 194 #endif |
| 147 ExpectString("name", "dummy"); | 195 ExpectString("name", "dummy"); |
| 148 base::ListValue expected_list; | 196 base::ListValue expected_list; |
| 149 expected_list.AppendString(format_hd.ToString()); | 197 expected_list.AppendString(format_hd.ToString()); |
| 150 ExpectListOfStrings("formats", expected_list); | 198 ExpectListOfStrings("formats", expected_list); |
| 151 #if defined(OS_MACOSX) | 199 #if defined(OS_MACOSX) |
| 152 ExpectInt("captureApi", media::VideoCaptureDevice::Name::QTKIT); | 200 ExpectString("captureApi", "QTKIT"); |
| 153 #elif defined(OS_WIN) | 201 #elif defined(OS_WIN) |
| 154 ExpectInt("captureApi", media::VideoCaptureDevice::Name::DIRECT_SHOW); | 202 ExpectString("captureApi", "DIRECT_SHOW"); |
| 155 #endif | 203 #endif |
| 156 } | 204 } |
| 157 | 205 |
| 158 class MediaInternalsAudioLogTest | 206 class MediaInternalsAudioLogTest |
| 159 : public MediaInternalsTestBase, | 207 : public MediaInternalsTestBase, |
| 160 public testing::TestWithParam<media::AudioLogFactory::AudioComponent> { | 208 public testing::TestWithParam<media::AudioLogFactory::AudioComponent> { |
| 161 public: | 209 public: |
| 162 MediaInternalsAudioLogTest() : | 210 MediaInternalsAudioLogTest() : |
| 163 update_cb_(base::Bind(&MediaInternalsAudioLogTest::UpdateCallbackImpl, | 211 update_cb_(base::Bind(&MediaInternalsAudioLogTest::UpdateCallbackImpl, |
| 164 base::Unretained(this))), | 212 base::Unretained(this))), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 ExpectStatus("closed"); | 282 ExpectStatus("closed"); |
| 235 } | 283 } |
| 236 | 284 |
| 237 INSTANTIATE_TEST_CASE_P( | 285 INSTANTIATE_TEST_CASE_P( |
| 238 MediaInternalsAudioLogTest, MediaInternalsAudioLogTest, testing::Values( | 286 MediaInternalsAudioLogTest, MediaInternalsAudioLogTest, testing::Values( |
| 239 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, | 287 media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, |
| 240 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, | 288 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, |
| 241 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); | 289 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); |
| 242 | 290 |
| 243 } // namespace content | 291 } // namespace content |
| OLD | NEW |