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

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

Issue 2486543002: [Mojo Video Capture] Add test ReceiveFramesFromFakeCaptureDevice (Closed)
Patch Set: 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
16 namespace video_capture { 19 namespace video_capture {
17 20
18 TEST_F(FakeDeviceTest, FrameCallbacksArrive) { 21 TEST_F(FakeDeviceTest, FrameCallbacksArrive) {
19 VideoCaptureSettings arbitrary_requested_settings; 22 VideoCaptureSettings arbitrary_requested_settings;
20 arbitrary_requested_settings.format.frame_size.SetSize(640, 480); 23 arbitrary_requested_settings.format.frame_size.SetSize(640, 480);
21 arbitrary_requested_settings.format.frame_rate = 15; 24 arbitrary_requested_settings.format.frame_rate = 15;
22 arbitrary_requested_settings.resolution_change_policy = 25 arbitrary_requested_settings.resolution_change_policy =
23 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 26 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
(...skipping 12 matching lines...) Expand all
36 if (num_frames_arrived >= kNumFramesToWaitFor) { 39 if (num_frames_arrived >= kNumFramesToWaitFor) {
37 wait_loop.Quit(); 40 wait_loop.Quit();
38 } 41 }
39 })); 42 }));
40 43
41 fake_device_proxy_->Start(arbitrary_requested_settings, 44 fake_device_proxy_->Start(arbitrary_requested_settings,
42 std::move(receiver_proxy)); 45 std::move(receiver_proxy));
43 wait_loop.Run(); 46 wait_loop.Run();
44 } 47 }
45 48
49 struct FrameInfo {
50 gfx::Size size;
51 media::VideoPixelFormat pixel_format;
52 media::VideoFrame::StorageType storage_type;
53 bool is_mappable;
54 base::TimeDelta timestamp;
55 };
mcasas 2016/11/09 23:50:29 Move this struct to an anonymous namespace inside
chfremer 2016/11/10 00:28:48 Done.
56
57 // Tests that frames received from a fake capture device match the requested
58 // format and have increasing timestamps.
59 TEST_F(FakeDeviceTest, ReceiveFramesFromFakeCaptureDevice) {
60 // Set up a mock VideoFrameReceiver
61 base::RunLoop wait_loop;
62 mojom::VideoFrameReceiverPtr receiver_proxy;
63 constexpr int num_frames_to_receive = 2;
64 FrameInfo received_frame_infos[num_frames_to_receive];
65 int received_frame_count = 0;
66 MockVideoFrameReceiver receiver(mojo::GetProxy(&receiver_proxy));
67 EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_))
68 .WillRepeatedly(
69 Invoke([&received_frame_infos, &received_frame_count,
70 &num_frames_to_receive, &wait_loop](
71 const media::mojom::VideoFramePtr* frame) {
72 if (received_frame_count >= num_frames_to_receive) {
73 return;
74 }
mcasas 2016/11/09 23:50:29 No {} for one-line bodies. Same for l.84, l.106
chfremer 2016/11/10 00:28:48 Done.
75 auto video_frame = frame->To<scoped_refptr<media::VideoFrame>>();
76 auto& frame_info = received_frame_infos[received_frame_count];
77 frame_info.pixel_format = video_frame->format();
78 frame_info.storage_type = video_frame->storage_type();
79 frame_info.is_mappable = video_frame->IsMappable();
80 frame_info.size = video_frame->natural_size();
81 frame_info.timestamp = video_frame->timestamp();
82 received_frame_count += 1;
83 if (received_frame_count == num_frames_to_receive) {
84 wait_loop.Quit();
85 }
86 }));
87
88 fake_device_proxy_->Start(
89 requestable_settings_, std::move(receiver_proxy));
90
91 wait_loop.Run();
92
93 base::TimeDelta previous_timestamp;
94 for (int i = 0; i < num_frames_to_receive; i++) {
95 auto& frame_info = received_frame_infos[i];
96 // Service is expected to always output I420
97 ASSERT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format);
98 // Service is expected to always use STORAGE_MOJO_SHARED_BUFFER
99 ASSERT_EQ(media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER,
100 frame_info.storage_type);
101 ASSERT_TRUE(frame_info.is_mappable);
102 ASSERT_EQ(requestable_settings_.format.frame_size,
103 frame_info.size);
104 // Timestamps are expected to increase
105 if (i > 0) {
106 ASSERT_GT(frame_info.timestamp, previous_timestamp);
mcasas 2016/11/09 23:50:29 nit: ASSERT_* will stop the test in its tracks, wh
chfremer 2016/11/10 00:28:48 Very nice. I didn't know about EXPECT_*. Thanks. D
107 }
108 previous_timestamp = frame_info.timestamp;
109 }
110 }
111
46 } // namespace video_capture 112 } // namespace video_capture
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698