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

Unified Diff: content/browser/media/capture/desktop_capture_device_unittest.cc

Issue 1135823004: Implement all resolution change policies for desktop and tab capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_change_policy_constraints_ITEM1_CR1
Patch Set: Addressed Wez's second round comments. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/capture/desktop_capture_device_unittest.cc
diff --git a/content/browser/media/capture/desktop_capture_device_unittest.cc b/content/browser/media/capture/desktop_capture_device_unittest.cc
index c86ddd3857ec569b9c6a11a54a3d2845b621ecdd..021764ae123f8104324e484cf5df75ffd47260bb 100644
--- a/content/browser/media/capture/desktop_capture_device_unittest.cc
+++ b/content/browser/media/capture/desktop_capture_device_unittest.cc
@@ -4,6 +4,7 @@
#include "content/browser/media/capture/desktop_capture_device.h"
+#include <algorithm>
#include <string>
#include "base/basictypes.h"
@@ -22,8 +23,10 @@ using ::testing::_;
using ::testing::AnyNumber;
using ::testing::DoAll;
using ::testing::Expectation;
+using ::testing::Invoke;
using ::testing::InvokeWithoutArgs;
using ::testing::SaveArg;
+using ::testing::WithArg;
namespace content {
@@ -33,10 +36,10 @@ MATCHER_P2(EqualsCaptureCapability, width, height, "") {
return arg.width == width && arg.height == height;
}
-const int kTestFrameWidth1 = 100;
-const int kTestFrameHeight1 = 100;
-const int kTestFrameWidth2 = 200;
-const int kTestFrameHeight2 = 150;
+const int kTestFrameWidth1 = 500;
+const int kTestFrameHeight1 = 500;
+const int kTestFrameWidth2 = 400;
+const int kTestFrameHeight2 = 300;
const int kFrameRate = 30;
@@ -273,19 +276,27 @@ TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) {
// Test that screen capturer behaves correctly if the source frame size changes
// but the caller cannot cope with variable resolution output.
TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) {
+ // Helper used to check that only one distinct frame size is delivered and
+ // that it exactly matches the configured frame size.
+ struct FormatChecker {
+ static void ExpectAcceptableSize(const media::VideoCaptureFormat& format) {
Wez 2015/05/15 00:55:42 Why is this in a struct rather than being a static
miu 2015/05/15 21:14:01 No particular reason, other than it's only used wi
+ const gfx::Size& size = format.frame_size;
+ EXPECT_EQ(gfx::Size(kTestFrameWidth1, kTestFrameHeight1), size);
+ EXPECT_EQ(kFrameRate, format.frame_rate);
+ EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
+ }
+ };
+
FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
- media::VideoCaptureFormat format;
base::WaitableEvent done_event(false, false);
- int frame_size;
scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
EXPECT_CALL(*client, OnError(_)).Times(0);
EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
- DoAll(SaveArg<1>(&frame_size),
- SaveArg<2>(&format),
+ DoAll(WithArg<2>(Invoke(&FormatChecker::ExpectAcceptableSize)),
InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
media::VideoCaptureParams capture_params;
@@ -293,64 +304,157 @@ TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) {
kTestFrameHeight1);
capture_params.requested_format.frame_rate = kFrameRate;
capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
+ capture_params.resolution_change_policy =
+ media::RESOLUTION_POLICY_FIXED_RESOLUTION;
capture_device_->AllocateAndStart(capture_params, client.Pass());
// Capture at least two frames, to ensure that the source frame size has
- // changed while capturing.
- EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
- done_event.Reset();
- EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
+ // changed to two different sizes while capturing. The mock for
+ // OnIncomingCapturedData() will use FormatChecker to examine the format of
+ // each frame being delivered.
+ for (int i = 0; i < 2; ++i) {
+ EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
+ done_event.Reset();
+ }
capture_device_->StopAndDeAllocate();
+}
- EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
- EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
- EXPECT_EQ(kFrameRate, format.frame_rate);
- EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
+// Test that screen capturer behaves correctly if the source frame size changes,
+// where the video frames sent the the client vary in resolution but maintain
+// the same aspect ratio.
+TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeFixedAspectRatio) {
+ // Helper used to check that only the two test frame sizes, adjusted to the
+ // 16:9 aspect ratio requirement, are delivered to the
+ // OnIncomingCapturedData() callback.
+ class FormatChecker {
+ public:
+ FormatChecker() : frame_count_(0) {}
+
+ void ExpectAcceptableSize(const media::VideoCaptureFormat& format) {
+ if (frame_count_ % 2 == 0) {
+ const gfx::Size expected_size(888, 500);
+ EXPECT_EQ(expected_size, format.frame_size);
+ } else {
+ const gfx::Size expected_size(532, 300);
+ EXPECT_EQ(expected_size, format.frame_size);
+ }
+ ++frame_count_;
+ EXPECT_EQ(kFrameRate, format.frame_rate);
+ EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
+ }
- EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size);
+ private:
+ int frame_count_;
+ };
+
+ FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
+
+ CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
+
+ FormatChecker format_checker;
+ base::WaitableEvent done_event(false, false);
+
+ scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
+ EXPECT_CALL(*client, OnError(_)).Times(0);
+ EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
+ DoAll(WithArg<2>(Invoke(&format_checker,
+ &FormatChecker::ExpectAcceptableSize)),
+ InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
+
+ media::VideoCaptureParams capture_params;
+ const gfx::Size high_def_16_by_9(1920, 1080);
+ ASSERT_GE(high_def_16_by_9.width(),
+ std::max(kTestFrameWidth1, kTestFrameWidth2));
+ ASSERT_GE(high_def_16_by_9.height(),
+ std::max(kTestFrameHeight1, kTestFrameHeight2));
+ capture_params.requested_format.frame_size = high_def_16_by_9;
+ capture_params.requested_format.frame_rate = kFrameRate;
+ capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
+ capture_params.resolution_change_policy =
+ media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO;
+
+ capture_device_->AllocateAndStart(
+ capture_params, client.Pass());
+
+ // Capture at least three frames, to ensure that the source frame size has
+ // changed to two different sizes while capturing. The mock for
+ // OnIncomingCapturedData() will use FormatChecker to examine the format of
+ // each frame being delivered.
+ for (int i = 0; i < 3; ++i) {
+ EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
+ done_event.Reset();
+ }
+
+ capture_device_->StopAndDeAllocate();
}
// Test that screen capturer behaves correctly if the source frame size changes
// and the caller can cope with variable resolution output.
TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) {
+ // Helper used to check that only the two test frame sizes are delivered to
+ // the OnIncomingCapturedData() callback.
+ class FormatChecker {
Wez 2015/05/15 00:55:42 Seems that this could be turned into a parameteriz
miu 2015/05/15 21:14:01 Done. Good point.
+ public:
+ FormatChecker() : frame_count_(0) {}
+
+ void ExpectAcceptableSize(const media::VideoCaptureFormat& format) {
+ if (frame_count_ % 2 == 0) {
+ EXPECT_EQ(gfx::Size(kTestFrameWidth1, kTestFrameHeight1),
+ format.frame_size);
+ } else {
+ EXPECT_EQ(gfx::Size(kTestFrameWidth2, kTestFrameHeight2),
+ format.frame_size);
+ }
+ ++frame_count_;
+ EXPECT_EQ(kFrameRate, format.frame_rate);
+ EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
+ }
+
+ private:
+ int frame_count_;
+ };
+
FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
- media::VideoCaptureFormat format;
+ FormatChecker format_checker;
base::WaitableEvent done_event(false, false);
scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
EXPECT_CALL(*client, OnError(_)).Times(0);
EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
- DoAll(SaveArg<2>(&format),
+ DoAll(WithArg<2>(Invoke(&format_checker,
+ &FormatChecker::ExpectAcceptableSize)),
InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
media::VideoCaptureParams capture_params;
- capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2,
- kTestFrameHeight2);
+ const gfx::Size high_def_16_by_9(1920, 1080);
+ ASSERT_GE(high_def_16_by_9.width(),
+ std::max(kTestFrameWidth1, kTestFrameWidth2));
+ ASSERT_GE(high_def_16_by_9.height(),
+ std::max(kTestFrameHeight1, kTestFrameHeight2));
+ capture_params.requested_format.frame_size = high_def_16_by_9;
capture_params.requested_format.frame_rate = kFrameRate;
capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
+ capture_params.resolution_change_policy =
+ media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT;
capture_device_->AllocateAndStart(
capture_params, client.Pass());
// Capture at least three frames, to ensure that the source frame size has
- // changed at least twice while capturing.
- EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
- done_event.Reset();
- EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
- done_event.Reset();
- EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
+ // changed to two different sizes while capturing. The mock for
+ // OnIncomingCapturedData() will use FormatChecker to examine the format of
+ // each frame being delivered.
+ for (int i = 0; i < 3; ++i) {
+ EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
+ done_event.Reset();
+ }
capture_device_->StopAndDeAllocate();
-
- EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
- EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
- EXPECT_EQ(kFrameRate, format.frame_rate);
- EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
}
// This test verifies that an unpacked frame is converted to a packed frame.

Powered by Google App Engine
This is Rietveld 408576698