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

Side by Side Diff: services/video_capture/fake_device_unittest.cc

Issue 2486543002: [Mojo Video Capture] Add test ReceiveFramesFromFakeCaptureDevice (Closed)
Patch Set: mcasas comments Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "media/base/video_frame.h"
8 #include "media/mojo/common/media_type_converters.h"
7 #include "services/video_capture/fake_device_test.h" 9 #include "services/video_capture/fake_device_test.h"
8 #include "services/video_capture/mock_video_frame_receiver.h" 10 #include "services/video_capture/mock_video_frame_receiver.h"
9 #include "services/video_capture/public/cpp/video_capture_settings.h" 11 #include "services/video_capture/public/cpp/video_capture_settings.h"
10 #include "services/video_capture/public/interfaces/video_capture_device_factory. mojom.h" 12 #include "services/video_capture/public/interfaces/video_capture_device_factory. mojom.h"
11 #include "services/video_capture/video_capture_service_test.h" 13 #include "services/video_capture/video_capture_service_test.h"
12 14
13 using testing::_; 15 using testing::_;
16 using testing::Invoke;
14 using testing::InvokeWithoutArgs; 17 using testing::InvokeWithoutArgs;
15 18
19 namespace {
20
21 struct FrameInfo {
22 gfx::Size size;
23 media::VideoPixelFormat pixel_format;
24 media::VideoFrame::StorageType storage_type;
25 bool is_mappable;
26 base::TimeDelta timestamp;
27 };
28
29 } // anonymous namespace
30
16 namespace video_capture { 31 namespace video_capture {
17 32
18 TEST_F(FakeDeviceTest, FrameCallbacksArrive) { 33 TEST_F(FakeDeviceTest, FrameCallbacksArrive) {
19 VideoCaptureSettings arbitrary_requested_settings; 34 VideoCaptureSettings arbitrary_requested_settings;
20 arbitrary_requested_settings.format.frame_size.SetSize(640, 480); 35 arbitrary_requested_settings.format.frame_size.SetSize(640, 480);
21 arbitrary_requested_settings.format.frame_rate = 15; 36 arbitrary_requested_settings.format.frame_rate = 15;
22 arbitrary_requested_settings.resolution_change_policy = 37 arbitrary_requested_settings.resolution_change_policy =
23 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 38 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
24 arbitrary_requested_settings.power_line_frequency = 39 arbitrary_requested_settings.power_line_frequency =
25 media::PowerLineFrequency::FREQUENCY_DEFAULT; 40 media::PowerLineFrequency::FREQUENCY_DEFAULT;
(...skipping 10 matching lines...) Expand all
36 if (num_frames_arrived >= kNumFramesToWaitFor) { 51 if (num_frames_arrived >= kNumFramesToWaitFor) {
37 wait_loop.Quit(); 52 wait_loop.Quit();
38 } 53 }
39 })); 54 }));
40 55
41 fake_device_proxy_->Start(arbitrary_requested_settings, 56 fake_device_proxy_->Start(arbitrary_requested_settings,
42 std::move(receiver_proxy)); 57 std::move(receiver_proxy));
43 wait_loop.Run(); 58 wait_loop.Run();
44 } 59 }
45 60
61 // Tests that frames received from a fake capture device match the requested
62 // format and have increasing timestamps.
63 TEST_F(FakeDeviceTest, ReceiveFramesFromFakeCaptureDevice) {
64 // Set up a mock VideoFrameReceiver
mcasas 2016/11/10 01:21:25 Superfluous?
chfremer 2016/11/10 04:41:35 Done.
65 base::RunLoop wait_loop;
66 mojom::VideoFrameReceiverPtr receiver_proxy;
67 constexpr int num_frames_to_receive = 2;
68 FrameInfo received_frame_infos[num_frames_to_receive];
69 int received_frame_count = 0;
mcasas 2016/11/10 01:21:25 nit: You could use a |num_frames_remaining| instea
chfremer 2016/11/10 04:41:35 Tried your suggestion, but turns out we need the c
70 MockVideoFrameReceiver receiver(mojo::GetProxy(&receiver_proxy));
71 EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_))
72 .WillRepeatedly(
73 Invoke([&received_frame_infos, &received_frame_count,
74 &num_frames_to_receive, &wait_loop](
75 const media::mojom::VideoFramePtr* frame) {
76 if (received_frame_count >= num_frames_to_receive)
77 return;
78 auto video_frame = frame->To<scoped_refptr<media::VideoFrame>>();
79 auto& frame_info = received_frame_infos[received_frame_count];
80 frame_info.pixel_format = video_frame->format();
81 frame_info.storage_type = video_frame->storage_type();
82 frame_info.is_mappable = video_frame->IsMappable();
83 frame_info.size = video_frame->natural_size();
84 frame_info.timestamp = video_frame->timestamp();
85 received_frame_count += 1;
86 if (received_frame_count == num_frames_to_receive)
87 wait_loop.Quit();
88 }));
89
90 fake_device_proxy_->Start(
91 requestable_settings_, std::move(receiver_proxy));
92
93 wait_loop.Run();
94
95 base::TimeDelta previous_timestamp;
96 for (int i = 0; i < num_frames_to_receive; i++) {
97 auto& frame_info = received_frame_infos[i];
98 // Service is expected to always output I420
99 EXPECT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format);
100 // Service is expected to always use STORAGE_MOJO_SHARED_BUFFER
101 EXPECT_EQ(media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER,
102 frame_info.storage_type);
103 EXPECT_TRUE(frame_info.is_mappable);
104 EXPECT_EQ(requestable_settings_.format.frame_size,
105 frame_info.size);
106 // Timestamps are expected to increase
107 if (i > 0)
108 EXPECT_GT(frame_info.timestamp, previous_timestamp);
109 previous_timestamp = frame_info.timestamp;
110 }
111 }
112
46 } // namespace video_capture 113 } // namespace video_capture
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698