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

Side by Side Diff: content/renderer/media/video_track_recorder_unittest.cc

Issue 2000003002: Initialize based on frame sizes in VideoTrackRecorder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mrgpu2
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/media/video_track_recorder.h" 5 #include "content/renderer/media/video_track_recorder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "content/child/child_process.h" 17 #include "content/child/child_process.h"
18 #include "content/renderer/media/media_stream_video_track.h" 18 #include "content/renderer/media/media_stream_video_track.h"
19 #include "content/renderer/media/mock_media_stream_video_source.h" 19 #include "content/renderer/media/mock_media_stream_video_source.h"
20 #include "media/base/video_frame.h" 20 #include "media/base/video_frame.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/public/platform/WebString.h" 23 #include "third_party/WebKit/public/platform/WebString.h"
24 #include "third_party/WebKit/public/web/WebHeap.h" 24 #include "third_party/WebKit/public/web/WebHeap.h"
25 25
26 using media::VideoFrame; 26 using media::VideoFrame;
27 using video_track_recorder::kVEAEncoderMinResolutionWidth;
28 using video_track_recorder::kVEAEncoderMinResolutionHeight;
27 29
28 using ::testing::_; 30 using ::testing::_;
29 using ::testing::DoAll; 31 using ::testing::DoAll;
30 using ::testing::InSequence; 32 using ::testing::InSequence;
31 using ::testing::Mock; 33 using ::testing::Mock;
32 using ::testing::Return; 34 using ::testing::Return;
33 using ::testing::SaveArg; 35 using ::testing::SaveArg;
34 using ::testing::TestWithParam; 36 using ::testing::TestWithParam;
35 using ::testing::ValuesIn; 37 using ::testing::ValuesIn;
36 38
37 namespace content { 39 namespace content {
38 40
39 ACTION_P(RunClosure, closure) { 41 ACTION_P(RunClosure, closure) {
40 closure.Run(); 42 closure.Run();
41 } 43 }
42 44
43 const VideoTrackRecorder::CodecId kTrackRecorderTestCodec[] = { 45 const VideoTrackRecorder::CodecId kTrackRecorderTestCodec[] = {
44 VideoTrackRecorder::CodecId::VP8, 46 VideoTrackRecorder::CodecId::VP8,
45 VideoTrackRecorder::CodecId::VP9 47 VideoTrackRecorder::CodecId::VP9
46 #if BUILDFLAG(RTC_USE_H264) 48 #if BUILDFLAG(RTC_USE_H264)
47 , VideoTrackRecorder::CodecId::H264 49 , VideoTrackRecorder::CodecId::H264
48 #endif 50 #endif
49 }; 51 };
52 const gfx::Size kTrackRecorderTestSize[] = {
53 gfx::Size(kVEAEncoderMinResolutionWidth / 2,
54 kVEAEncoderMinResolutionHeight / 2),
55 gfx::Size(kVEAEncoderMinResolutionWidth, kVEAEncoderMinResolutionHeight)};
56 static const int kTrackRecorderTestSizeDiff = 20;
50 57
51 class VideoTrackRecorderTest 58 class VideoTrackRecorderTest
52 : public TestWithParam<VideoTrackRecorder::CodecId> { 59 : public TestWithParam<
60 testing::tuple<VideoTrackRecorder::CodecId, gfx::Size>> {
53 public: 61 public:
54 VideoTrackRecorderTest() 62 VideoTrackRecorderTest()
55 : mock_source_(new MockMediaStreamVideoSource(false)) { 63 : mock_source_(new MockMediaStreamVideoSource(false)) {
56 const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy")); 64 const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy"));
57 blink_source_.initialize(webkit_track_id, 65 blink_source_.initialize(webkit_track_id,
58 blink::WebMediaStreamSource::TypeVideo, 66 blink::WebMediaStreamSource::TypeVideo,
59 webkit_track_id); 67 webkit_track_id);
60 blink_source_.setExtraData(mock_source_); 68 blink_source_.setExtraData(mock_source_);
61 blink_track_.initialize(blink_source_); 69 blink_track_.initialize(blink_source_);
62 70
63 blink::WebMediaConstraints constraints; 71 blink::WebMediaConstraints constraints;
64 constraints.initialize(); 72 constraints.initialize();
65 track_ = new MediaStreamVideoTrack(mock_source_, constraints, 73 track_ = new MediaStreamVideoTrack(mock_source_, constraints,
66 MediaStreamSource::ConstraintsCallback(), 74 MediaStreamSource::ConstraintsCallback(),
67 true /* enabled */); 75 true /* enabled */);
68 blink_track_.setTrackData(track_); 76 blink_track_.setTrackData(track_);
69 77
70 video_track_recorder_.reset(new VideoTrackRecorder( 78 video_track_recorder_.reset(new VideoTrackRecorder(
71 GetParam() /* codec */, blink_track_, 79 testing::get<0>(GetParam()) /* codec */, blink_track_,
72 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo, 80 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo,
73 base::Unretained(this)), 81 base::Unretained(this)),
74 0 /* bits_per_second */)); 82 0 /* bits_per_second */));
75 // Paranoia checks. 83 // Paranoia checks.
76 EXPECT_EQ(blink_track_.source().getExtraData(), 84 EXPECT_EQ(blink_track_.source().getExtraData(),
77 blink_source_.getExtraData()); 85 blink_source_.getExtraData());
78 EXPECT_TRUE(message_loop_.IsCurrent()); 86 EXPECT_TRUE(message_loop_.IsCurrent());
79 } 87 }
80 88
81 ~VideoTrackRecorderTest() { 89 ~VideoTrackRecorderTest() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 131
124 // Construct and destruct all objects, in particular |video_track_recorder_| and 132 // Construct and destruct all objects, in particular |video_track_recorder_| and
125 // its inner object(s). This is a non trivial sequence. 133 // its inner object(s). This is a non trivial sequence.
126 TEST_P(VideoTrackRecorderTest, ConstructAndDestruct) {} 134 TEST_P(VideoTrackRecorderTest, ConstructAndDestruct) {}
127 135
128 // Creates the encoder and encodes 2 frames of the same size; the encoder should 136 // Creates the encoder and encodes 2 frames of the same size; the encoder should
129 // be initialised and produce a keyframe, then a non-keyframe. Finally a frame 137 // be initialised and produce a keyframe, then a non-keyframe. Finally a frame
130 // of larger size is sent and is expected to be encoded as a keyframe. 138 // of larger size is sent and is expected to be encoded as a keyframe.
131 TEST_P(VideoTrackRecorderTest, VideoEncoding) { 139 TEST_P(VideoTrackRecorderTest, VideoEncoding) {
132 // |frame_size| cannot be arbitrarily small, should be reasonable. 140 // |frame_size| cannot be arbitrarily small, should be reasonable.
133 const gfx::Size frame_size(160, 80); 141 const gfx::Size& frame_size = testing::get<1>(GetParam());
134 const scoped_refptr<VideoFrame> video_frame = 142 const scoped_refptr<VideoFrame> video_frame =
135 VideoFrame::CreateBlackFrame(frame_size); 143 VideoFrame::CreateBlackFrame(frame_size);
136 const double kFrameRate = 60.0f; 144 const double kFrameRate = 60.0f;
137 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, 145 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE,
138 kFrameRate); 146 kFrameRate);
139 147
140 InSequence s; 148 InSequence s;
141 const base::TimeTicks timeticks_now = base::TimeTicks::Now(); 149 const base::TimeTicks timeticks_now = base::TimeTicks::Now();
142 base::StringPiece first_frame_encoded_data; 150 base::StringPiece first_frame_encoded_data;
143 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_now, true)) 151 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_now, true))
144 .Times(1) 152 .Times(1)
145 .WillOnce(SaveArg<1>(&first_frame_encoded_data)); 153 .WillOnce(SaveArg<1>(&first_frame_encoded_data));
146 Encode(video_frame, timeticks_now); 154 Encode(video_frame, timeticks_now);
147 155
148 // Send another Video Frame. 156 // Send another Video Frame.
149 const base::TimeTicks timeticks_later = base::TimeTicks::Now(); 157 const base::TimeTicks timeticks_later = base::TimeTicks::Now();
150 base::StringPiece second_frame_encoded_data; 158 base::StringPiece second_frame_encoded_data;
151 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_later, false)) 159 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_later, false))
152 .Times(1) 160 .Times(1)
153 .WillOnce(SaveArg<1>(&second_frame_encoded_data)); 161 .WillOnce(SaveArg<1>(&second_frame_encoded_data));
154 Encode(video_frame, timeticks_later); 162 Encode(video_frame, timeticks_later);
155 163
156 // Send another Video Frame and expect only an DoOnEncodedVideo() callback. 164 // Send another Video Frame and expect only an DoOnEncodedVideo() callback.
157 const gfx::Size frame_size2(180, 80); 165 const gfx::Size frame_size2(frame_size.width() + kTrackRecorderTestSizeDiff,
166 frame_size.height());
158 const scoped_refptr<VideoFrame> video_frame2 = 167 const scoped_refptr<VideoFrame> video_frame2 =
159 VideoFrame::CreateBlackFrame(frame_size2); 168 VideoFrame::CreateBlackFrame(frame_size2);
160 169
161 base::RunLoop run_loop; 170 base::RunLoop run_loop;
162 base::Closure quit_closure = run_loop.QuitClosure(); 171 base::Closure quit_closure = run_loop.QuitClosure();
163 172
164 base::StringPiece third_frame_encoded_data; 173 base::StringPiece third_frame_encoded_data;
165 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true)) 174 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true))
166 .Times(1) 175 .Times(1)
167 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), 176 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data),
168 RunClosure(quit_closure))); 177 RunClosure(quit_closure)));
169 Encode(video_frame2, base::TimeTicks::Now()); 178 Encode(video_frame2, base::TimeTicks::Now());
170 179
171 run_loop.Run(); 180 run_loop.Run();
172 181
173 const size_t kEncodedSizeThreshold = 14; 182 const size_t kEncodedSizeThreshold = 14;
174 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); 183 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold);
175 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); 184 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold);
176 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); 185 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold);
177 186
178 Mock::VerifyAndClearExpectations(this); 187 Mock::VerifyAndClearExpectations(this);
179 } 188 }
180 189
181 INSTANTIATE_TEST_CASE_P(, 190 INSTANTIATE_TEST_CASE_P(,
182 VideoTrackRecorderTest, 191 VideoTrackRecorderTest,
183 ValuesIn(kTrackRecorderTestCodec)); 192 ::testing::Combine(ValuesIn(kTrackRecorderTestCodec),
193 ValuesIn(kTrackRecorderTestSize)));
184 194
185 } // namespace content 195 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698