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

Side by Side Diff: remoting/host/video_frame_recorder_unittest.cc

Issue 468613002: Readability review. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "remoting/host/video_frame_recorder.h" 5 #include "remoting/host/video_frame_recorder.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "remoting/codec/video_encoder_verbatim.h" 10 #include "remoting/codec/video_encoder_verbatim.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
13 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 13 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" 14 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 17
18 // Define equality operator for DesktopFrame to allow use of EXPECT_EQ(). 18 // Define equality operator for DesktopFrame to allow use of EXPECT_EQ().
19 static bool operator==(const DesktopFrame& a, 19 static bool operator==(const DesktopFrame& a,
20 const DesktopFrame& b) { 20 const DesktopFrame& b) {
21 if ((a.size().equals(b.size())) && 21 if ((a.size().equals(b.size())) &&
22 (a.updated_region().Equals(b.updated_region())) && 22 (a.updated_region().Equals(b.updated_region())) &&
23 (a.dpi().equals(b.dpi()))) { 23 (a.dpi().equals(b.dpi()))) {
Peter Kasting 2014/08/22 06:38:31 Nit: Reversing this conditional takes no more LOC
Wez 2014/08/25 23:23:13 Done.
24 for (int i = 0; i < a.size().height(); ++i) { 24 for (int i = 0; i < a.size().height(); ++i) {
25 if (memcmp(a.data() + a.stride() * i, 25 if (memcmp(a.data() + a.stride() * i,
26 b.data() + b.stride() * i, 26 b.data() + b.stride() * i,
27 a.size().width() * DesktopFrame::kBytesPerPixel) != 0) { 27 a.size().width() * DesktopFrame::kBytesPerPixel) != 0) {
28 return false; 28 return false;
29 } 29 }
30 } 30 }
31 return true; 31 return true;
32 } 32 }
33 return false; 33 return false;
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 namespace remoting { 38 namespace remoting {
39 39
40 const int64_t kMaxContentBytes = 10 * 1024 * 1024; 40 const int64_t kMaxContentBytes = 10 * 1024 * 1024;
Peter Kasting 2014/08/22 06:38:31 Nit: Again, define these in the most local scopes
Wez 2014/08/25 23:23:13 Done.
41 const int kWidth = 640; 41 const int kWidth = 640;
42 const int kHeight = 480; 42 const int kHeight = 480;
43 const int kTestFrameCount = 6; 43 const int kTestFrameCount = 6;
44 44
45 class VideoFrameRecorderTest : public testing::Test { 45 class VideoFrameRecorderTest : public testing::Test {
46 public: 46 public:
47 VideoFrameRecorderTest(); 47 VideoFrameRecorderTest();
48 48
49 virtual void SetUp() OVERRIDE; 49 virtual void SetUp() OVERRIDE;
50 virtual void TearDown() OVERRIDE; 50 virtual void TearDown() OVERRIDE;
51 51
52 void CreateAndWrapEncoder(); 52 void CreateAndWrapEncoder();
Peter Kasting 2014/08/22 06:38:30 Comments?
Wez 2014/08/25 23:23:13 Done.
53 scoped_ptr<webrtc::DesktopFrame> CreateNextFrame(); 53 scoped_ptr<webrtc::DesktopFrame> CreateNextFrame();
54 void CreateTestFrames(); 54 void CreateTestFrames();
55 void EncodeTestFrames(); 55 void EncodeTestFrames();
56 void EncodeDummyFrame(); 56 void EncodeDummyFrame();
57 void StartRecording(); 57 void StartRecording();
58 void VerifyTestFrames(); 58 void VerifyTestFrames();
59 59
60 protected: 60 protected:
Peter Kasting 2014/08/22 06:38:31 Nit: Again, try to avoid protected members if poss
Wez 2014/08/25 23:23:13 Again, since this is a test base, protected feels
61 base::MessageLoop message_loop_; 61 base::MessageLoop message_loop_;
62 62
63 scoped_ptr<VideoFrameRecorder> recorder_; 63 scoped_ptr<VideoFrameRecorder> recorder_;
64 scoped_ptr<VideoEncoder> encoder_; 64 scoped_ptr<VideoEncoder> encoder_;
65 65
66 std::list<webrtc::DesktopFrame*> test_frames_; 66 std::list<webrtc::DesktopFrame*> test_frames_;
Peter Kasting 2014/08/22 06:38:31 Nit: Consider a typedef for this so you can use it
Wez 2014/08/25 23:23:13 Done.
67 int frame_count_; 67 int frame_count_;
68 }; 68 };
Peter Kasting 2014/08/22 06:38:31 Nit: DISALLOW_COPY_AND_ASSIGN
69 69
70 VideoFrameRecorderTest::VideoFrameRecorderTest() : frame_count_(0) {} 70 VideoFrameRecorderTest::VideoFrameRecorderTest() : frame_count_(0) {}
71 71
72 void VideoFrameRecorderTest::SetUp() { 72 void VideoFrameRecorderTest::SetUp() {
73 recorder_.reset(new VideoFrameRecorder()); 73 recorder_.reset(new VideoFrameRecorder());
74 recorder_->SetMaxContentBytes(kMaxContentBytes); 74 recorder_->SetMaxContentBytes(kMaxContentBytes);
75 } 75 }
76 76
77 void VideoFrameRecorderTest::TearDown() { 77 void VideoFrameRecorderTest::TearDown() {
78 ASSERT_TRUE(test_frames_.empty()); 78 ASSERT_TRUE(test_frames_.empty());
(...skipping 25 matching lines...) Expand all
104 memset(frame->data(), frame_count_, frame->stride() * kHeight); 104 memset(frame->data(), frame_count_, frame->stride() * kHeight);
105 frame->set_dpi(webrtc::DesktopVector(frame_count_, frame_count_)); 105 frame->set_dpi(webrtc::DesktopVector(frame_count_, frame_count_));
106 frame->mutable_updated_region()->SetRect( 106 frame->mutable_updated_region()->SetRect(
107 webrtc::DesktopRect::MakeWH(frame_count_, frame_count_)); 107 webrtc::DesktopRect::MakeWH(frame_count_, frame_count_));
108 ++frame_count_; 108 ++frame_count_;
109 109
110 return frame.Pass(); 110 return frame.Pass();
111 } 111 }
112 112
113 void VideoFrameRecorderTest::CreateTestFrames() { 113 void VideoFrameRecorderTest::CreateTestFrames() {
114 for (int i=0; i < kTestFrameCount; ++i) { 114 for (int i=0; i < kTestFrameCount; ++i) {
Peter Kasting 2014/08/22 06:38:31 Nit: Spaces around '=' Super-tiny nit: Since it's
Wez 2014/08/25 23:23:12 Done, although I tend to prefer int over size_t on
115 test_frames_.push_back(CreateNextFrame().release()); 115 test_frames_.push_back(CreateNextFrame().release());
116 } 116 }
117 } 117 }
118 118
119 void VideoFrameRecorderTest::EncodeTestFrames() { 119 void VideoFrameRecorderTest::EncodeTestFrames() {
120 std::list<webrtc::DesktopFrame*>::iterator i; 120 std::list<webrtc::DesktopFrame*>::iterator i;
Peter Kasting 2014/08/22 06:38:30 Nit: Declare iterators in the loop declaration unl
Wez 2014/08/25 23:23:12 Done.
121 for (i = test_frames_.begin(); i != test_frames_.end(); ++i) { 121 for (i = test_frames_.begin(); i != test_frames_.end(); ++i) {
122 scoped_ptr<VideoPacket> packet = encoder_->Encode(*(*i)); 122 scoped_ptr<VideoPacket> packet = encoder_->Encode(*(*i));
Peter Kasting 2014/08/22 06:38:31 Nit: "scoped_ptr<VideoPacket> packet = " unnecessa
Wez 2014/08/25 23:23:13 Done. In theory Encode() could return a NULL poin
123 123
124 // Process tasks to let the recorder pick up the frame. 124 // Process tasks to let the recorder pick up the frame.
125 base::RunLoop().RunUntilIdle(); 125 base::RunLoop().RunUntilIdle();
126 } 126 }
127 } 127 }
128 128
129 void VideoFrameRecorderTest::EncodeDummyFrame() { 129 void VideoFrameRecorderTest::EncodeDummyFrame() {
130 webrtc::BasicDesktopFrame dummy_frame(webrtc::DesktopSize(kWidth, kHeight)); 130 webrtc::BasicDesktopFrame dummy_frame(webrtc::DesktopSize(kWidth, kHeight));
131 scoped_ptr<VideoPacket> packet = encoder_->Encode(dummy_frame); 131 scoped_ptr<VideoPacket> packet = encoder_->Encode(dummy_frame);
132 base::RunLoop().RunUntilIdle(); 132 base::RunLoop().RunUntilIdle();
(...skipping 18 matching lines...) Expand all
151 } 151 }
152 152
153 EXPECT_FALSE(recorder_->NextFrame()); 153 EXPECT_FALSE(recorder_->NextFrame());
154 } 154 }
155 155
156 // Basic test that creating & tearing down VideoFrameRecorder doesn't crash. 156 // Basic test that creating & tearing down VideoFrameRecorder doesn't crash.
157 TEST_F(VideoFrameRecorderTest, CreateDestroy) { 157 TEST_F(VideoFrameRecorderTest, CreateDestroy) {
158 } 158 }
159 159
160 // Basic test that creating, starting, stopping and destroying a 160 // Basic test that creating, starting, stopping and destroying a
161 // VideoFrameRecorder don't end the world. 161 // VideoFrameRecorder don't end the world.
Peter Kasting 2014/08/22 06:38:31 Nit: don't end the world -> doesn't crash (or some
Wez 2014/08/25 23:23:12 Done.
162 TEST_F(VideoFrameRecorderTest, StartStop) { 162 TEST_F(VideoFrameRecorderTest, StartStop) {
163 StartRecording(); 163 StartRecording();
164 recorder_->SetEnableRecording(false); 164 recorder_->SetEnableRecording(false);
165 } 165 }
166 166
167 // Test that tearing down the VideoFrameRecorder while the VideoEncoder 167 // Test that tearing down the VideoFrameRecorder while the VideoEncoder
168 // wrapper exists doesn't crash. 168 // wrapper exists doesn't crash.
169 TEST_F(VideoFrameRecorderTest, DestroyVideoFrameRecorderFirst) { 169 TEST_F(VideoFrameRecorderTest, DestroyVideoFrameRecorderFirst) {
170 CreateAndWrapEncoder(); 170 CreateAndWrapEncoder();
171 171
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // Verify that the recorded frames match the ones passed to the encoder. 211 // Verify that the recorded frames match the ones passed to the encoder.
212 VerifyTestFrames(); 212 VerifyTestFrames();
213 } 213 }
214 214
215 // Test that when asked to record more frames than the maximum content bytes 215 // Test that when asked to record more frames than the maximum content bytes
216 // limit allows, the first encoded frames are dropped. 216 // limit allows, the first encoded frames are dropped.
217 TEST_F(VideoFrameRecorderTest, MaxContentBytesEnforced) { 217 TEST_F(VideoFrameRecorderTest, MaxContentBytesEnforced) {
218 CreateAndWrapEncoder(); 218 CreateAndWrapEncoder();
219 219
220 // Configure a maximum content size sufficient for five and a half frames. 220 // Configure a maximum content size sufficient for five and a half frames.
221 int64 frame_bytes = kWidth * kHeight * webrtc::DesktopFrame::kBytesPerPixel; 221 int64 frame_bytes = kWidth * kHeight * webrtc::DesktopFrame::kBytesPerPixel;
Peter Kasting 2014/08/22 06:38:30 Optional: const
Wez 2014/08/25 23:23:13 Done.
222 recorder_->SetMaxContentBytes((frame_bytes * 11) / 2); 222 recorder_->SetMaxContentBytes((frame_bytes * 11) / 2);
223 223
224 // Start the recorder, so that the wrapper will push frames to it. 224 // Start the recorder, so that the wrapper will push frames to it.
225 StartRecording(); 225 StartRecording();
226 226
227 // Create frames, store them and pass them to the encoder. 227 // Create frames, store them and pass them to the encoder.
228 CreateTestFrames(); 228 CreateTestFrames();
229 EncodeTestFrames(); 229 EncodeTestFrames();
230 230
231 // Only five of the supplied frames should have been recorded. 231 // Only five of the supplied frames should have been recorded.
232 while (test_frames_.size() > 5) { 232 while (test_frames_.size() > 5) {
233 scoped_ptr<webrtc::DesktopFrame> frame(test_frames_.front()); 233 scoped_ptr<webrtc::DesktopFrame> frame(test_frames_.front());
234 test_frames_.pop_front(); 234 test_frames_.pop_front();
235 } 235 }
236 236
237 // Verify that the recorded frames match the ones passed to the encoder. 237 // Verify that the recorded frames match the ones passed to the encoder.
238 VerifyTestFrames(); 238 VerifyTestFrames();
239 } 239 }
240 240
241 // Test that when asked to record more frames than the maximum content bytes 241 // Test that when asked to record more frames than the maximum content bytes
242 // limit allows, the first encoded frames are dropped. 242 // limit allows, the first encoded frames are dropped.
Peter Kasting 2014/08/22 06:38:31 This comment is the same as on the previous testca
Wez 2014/08/25 23:23:13 Done.
243 TEST_F(VideoFrameRecorderTest, ContentBytesUpdatedByNextFrame) { 243 TEST_F(VideoFrameRecorderTest, ContentBytesUpdatedByNextFrame) {
244 CreateAndWrapEncoder(); 244 CreateAndWrapEncoder();
245 245
246 // Configure a maximum content size sufficient for kTestFrameCount frames. 246 // Configure a maximum content size sufficient for kTestFrameCount frames.
247 int64 frame_bytes = kWidth * kHeight * webrtc::DesktopFrame::kBytesPerPixel; 247 int64 frame_bytes = kWidth * kHeight * webrtc::DesktopFrame::kBytesPerPixel;
248 recorder_->SetMaxContentBytes(frame_bytes * kTestFrameCount); 248 recorder_->SetMaxContentBytes(frame_bytes * kTestFrameCount);
249 249
250 // Start the recorder, so that the wrapper will push frames to it. 250 // Start the recorder, so that the wrapper will push frames to it.
251 StartRecording(); 251 StartRecording();
252 252
(...skipping 20 matching lines...) Expand all
273 EncodeTestFrames(); 273 EncodeTestFrames();
274 274
275 // Clear the list of expected test frames, since none should be recorded. 275 // Clear the list of expected test frames, since none should be recorded.
276 STLDeleteElements(&test_frames_); 276 STLDeleteElements(&test_frames_);
277 277
278 // Verify that the recorded frames match the ones passed to the encoder. 278 // Verify that the recorded frames match the ones passed to the encoder.
279 VerifyTestFrames(); 279 VerifyTestFrames();
280 } 280 }
281 281
282 } // namespace remoting 282 } // namespace remoting
283
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698