Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 closure.Run(); | 40 closure.Run(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 const VideoTrackRecorder::CodecId kTrackRecorderTestCodec[] = { | 43 const VideoTrackRecorder::CodecId kTrackRecorderTestCodec[] = { |
| 44 VideoTrackRecorder::CodecId::VP8, | 44 VideoTrackRecorder::CodecId::VP8, |
| 45 VideoTrackRecorder::CodecId::VP9 | 45 VideoTrackRecorder::CodecId::VP9 |
| 46 #if BUILDFLAG(RTC_USE_H264) | 46 #if BUILDFLAG(RTC_USE_H264) |
| 47 , VideoTrackRecorder::CodecId::H264 | 47 , VideoTrackRecorder::CodecId::H264 |
| 48 #endif | 48 #endif |
| 49 }; | 49 }; |
| 50 const gfx::Size kTrackRecorderTestSize[] = {gfx::Size(160, 80), | |
| 51 gfx::Size(640, 480)}; | |
|
mcasas
2016/07/08 22:59:27
Link these two to |kVEAEncoderMinResolutionWidth|
emircan
2016/07/12 01:00:35
I put them in .h file in video_track_recorder name
| |
| 52 static const int kTrackRecorderTestSizeDiff = 20; | |
| 50 | 53 |
| 51 class VideoTrackRecorderTest | 54 class VideoTrackRecorderTest |
| 52 : public TestWithParam<VideoTrackRecorder::CodecId> { | 55 : public TestWithParam< |
| 56 testing::tuple<VideoTrackRecorder::CodecId, gfx::Size>> { | |
| 53 public: | 57 public: |
| 54 VideoTrackRecorderTest() | 58 VideoTrackRecorderTest() |
| 55 : mock_source_(new MockMediaStreamVideoSource(false)) { | 59 : mock_source_(new MockMediaStreamVideoSource(false)) { |
| 56 const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy")); | 60 const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy")); |
| 57 blink_source_.initialize(webkit_track_id, | 61 blink_source_.initialize(webkit_track_id, |
| 58 blink::WebMediaStreamSource::TypeVideo, | 62 blink::WebMediaStreamSource::TypeVideo, |
| 59 webkit_track_id); | 63 webkit_track_id); |
| 60 blink_source_.setExtraData(mock_source_); | 64 blink_source_.setExtraData(mock_source_); |
| 61 blink_track_.initialize(blink_source_); | 65 blink_track_.initialize(blink_source_); |
| 62 | 66 |
| 63 blink::WebMediaConstraints constraints; | 67 blink::WebMediaConstraints constraints; |
| 64 constraints.initialize(); | 68 constraints.initialize(); |
| 65 track_ = new MediaStreamVideoTrack(mock_source_, constraints, | 69 track_ = new MediaStreamVideoTrack(mock_source_, constraints, |
| 66 MediaStreamSource::ConstraintsCallback(), | 70 MediaStreamSource::ConstraintsCallback(), |
| 67 true /* enabled */); | 71 true /* enabled */); |
| 68 blink_track_.setTrackData(track_); | 72 blink_track_.setTrackData(track_); |
| 69 | 73 |
| 70 video_track_recorder_.reset(new VideoTrackRecorder( | 74 video_track_recorder_.reset(new VideoTrackRecorder( |
| 71 GetParam() /* codec */, blink_track_, | 75 testing::get<0>(GetParam()) /* codec */, blink_track_, |
| 72 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo, | 76 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo, |
| 73 base::Unretained(this)), | 77 base::Unretained(this)), |
| 74 0 /* bits_per_second */)); | 78 0 /* bits_per_second */)); |
| 75 // Paranoia checks. | 79 // Paranoia checks. |
| 76 EXPECT_EQ(blink_track_.source().getExtraData(), | 80 EXPECT_EQ(blink_track_.source().getExtraData(), |
| 77 blink_source_.getExtraData()); | 81 blink_source_.getExtraData()); |
| 78 EXPECT_TRUE(message_loop_.IsCurrent()); | 82 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 79 } | 83 } |
| 80 | 84 |
| 81 ~VideoTrackRecorderTest() { | 85 ~VideoTrackRecorderTest() { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 98 } | 102 } |
| 99 | 103 |
| 100 void Encode(const scoped_refptr<VideoFrame>& frame, | 104 void Encode(const scoped_refptr<VideoFrame>& frame, |
| 101 base::TimeTicks capture_time) { | 105 base::TimeTicks capture_time) { |
| 102 EXPECT_TRUE(message_loop_.IsCurrent()); | 106 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 103 video_track_recorder_->OnVideoFrameForTesting(frame, capture_time); | 107 video_track_recorder_->OnVideoFrameForTesting(frame, capture_time); |
| 104 } | 108 } |
| 105 | 109 |
| 106 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 110 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 107 // and Sources below into believing they are on the right threads. | 111 // and Sources below into believing they are on the right threads. |
| 108 const base::MessageLoopForUI message_loop_; | 112 base::MessageLoopForUI message_loop_; |
|
mcasas
2016/07/08 22:59:27
Restore const?
| |
| 109 const ChildProcess child_process_; | 113 const ChildProcess child_process_; |
| 110 | 114 |
| 111 // All members are non-const due to the series of initialize() calls needed. | 115 // All members are non-const due to the series of initialize() calls needed. |
| 112 // |mock_source_| is owned by |blink_source_|, |track_| by |blink_track_|. | 116 // |mock_source_| is owned by |blink_source_|, |track_| by |blink_track_|. |
| 113 MockMediaStreamVideoSource* mock_source_; | 117 MockMediaStreamVideoSource* mock_source_; |
| 114 blink::WebMediaStreamSource blink_source_; | 118 blink::WebMediaStreamSource blink_source_; |
| 115 MediaStreamVideoTrack* track_; | 119 MediaStreamVideoTrack* track_; |
| 116 blink::WebMediaStreamTrack blink_track_; | 120 blink::WebMediaStreamTrack blink_track_; |
| 117 | 121 |
| 118 std::unique_ptr<VideoTrackRecorder> video_track_recorder_; | 122 std::unique_ptr<VideoTrackRecorder> video_track_recorder_; |
| 119 | 123 |
| 120 private: | 124 private: |
| 121 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorderTest); | 125 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorderTest); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 // Construct and destruct all objects, in particular |video_track_recorder_| and | 128 // Construct and destruct all objects, in particular |video_track_recorder_| and |
| 125 // its inner object(s). This is a non trivial sequence. | 129 // its inner object(s). This is a non trivial sequence. |
| 126 TEST_P(VideoTrackRecorderTest, ConstructAndDestruct) {} | 130 TEST_P(VideoTrackRecorderTest, ConstructAndDestruct) {} |
| 127 | 131 |
| 128 // Creates the encoder and encodes 2 frames of the same size; the encoder should | 132 // 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 | 133 // 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. | 134 // of larger size is sent and is expected to be encoded as a keyframe. |
| 131 TEST_P(VideoTrackRecorderTest, VideoEncoding) { | 135 TEST_P(VideoTrackRecorderTest, VideoEncoding) { |
| 132 // |frame_size| cannot be arbitrarily small, should be reasonable. | 136 // |frame_size| cannot be arbitrarily small, should be reasonable. |
| 133 const gfx::Size frame_size(160, 80); | 137 const gfx::Size& frame_size = testing::get<1>(GetParam()); |
| 134 const scoped_refptr<VideoFrame> video_frame = | 138 const scoped_refptr<VideoFrame> video_frame = |
| 135 VideoFrame::CreateBlackFrame(frame_size); | 139 VideoFrame::CreateBlackFrame(frame_size); |
| 136 const double kFrameRate = 60.0f; | 140 const double kFrameRate = 60.0f; |
| 137 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 141 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 138 kFrameRate); | 142 kFrameRate); |
| 139 | 143 |
| 140 InSequence s; | 144 InSequence s; |
| 141 const base::TimeTicks timeticks_now = base::TimeTicks::Now(); | 145 const base::TimeTicks timeticks_now = base::TimeTicks::Now(); |
| 142 base::StringPiece first_frame_encoded_data; | 146 base::StringPiece first_frame_encoded_data; |
| 143 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_now, true)) | 147 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_now, true)) |
| 144 .Times(1) | 148 .Times(1) |
| 145 .WillOnce(SaveArg<1>(&first_frame_encoded_data)); | 149 .WillOnce(SaveArg<1>(&first_frame_encoded_data)); |
| 146 Encode(video_frame, timeticks_now); | 150 Encode(video_frame, timeticks_now); |
| 151 message_loop_.RunUntilIdle(); | |
| 147 | 152 |
| 148 // Send another Video Frame. | 153 // Send another Video Frame. |
| 149 const base::TimeTicks timeticks_later = base::TimeTicks::Now(); | 154 const base::TimeTicks timeticks_later = base::TimeTicks::Now(); |
| 150 base::StringPiece second_frame_encoded_data; | 155 base::StringPiece second_frame_encoded_data; |
| 151 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_later, false)) | 156 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_later, false)) |
| 152 .Times(1) | 157 .Times(1) |
| 153 .WillOnce(SaveArg<1>(&second_frame_encoded_data)); | 158 .WillOnce(SaveArg<1>(&second_frame_encoded_data)); |
| 154 Encode(video_frame, timeticks_later); | 159 Encode(video_frame, timeticks_later); |
| 155 | 160 |
| 156 // Send another Video Frame and expect only an DoOnEncodedVideo() callback. | 161 // Send another Video Frame and expect only an DoOnEncodedVideo() callback. |
| 157 const gfx::Size frame_size2(180, 80); | 162 const gfx::Size frame_size2(frame_size.width() + kTrackRecorderTestSizeDiff, |
| 163 frame_size.height()); | |
| 158 const scoped_refptr<VideoFrame> video_frame2 = | 164 const scoped_refptr<VideoFrame> video_frame2 = |
| 159 VideoFrame::CreateBlackFrame(frame_size2); | 165 VideoFrame::CreateBlackFrame(frame_size2); |
| 160 | 166 |
| 161 base::RunLoop run_loop; | 167 base::RunLoop run_loop; |
| 162 base::Closure quit_closure = run_loop.QuitClosure(); | 168 base::Closure quit_closure = run_loop.QuitClosure(); |
| 163 | 169 |
| 164 base::StringPiece third_frame_encoded_data; | 170 base::StringPiece third_frame_encoded_data; |
| 165 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true)) | 171 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true)) |
| 166 .Times(1) | 172 .Times(1) |
| 167 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), | 173 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), |
| 168 RunClosure(quit_closure))); | 174 RunClosure(quit_closure))); |
| 169 Encode(video_frame2, base::TimeTicks::Now()); | 175 Encode(video_frame2, base::TimeTicks::Now()); |
| 170 | 176 |
| 171 run_loop.Run(); | 177 run_loop.Run(); |
| 172 | 178 |
| 173 const size_t kEncodedSizeThreshold = 14; | 179 const size_t kEncodedSizeThreshold = 14; |
| 174 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); | 180 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 175 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); | 181 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 176 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); | 182 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 177 | 183 |
| 178 Mock::VerifyAndClearExpectations(this); | 184 Mock::VerifyAndClearExpectations(this); |
| 179 } | 185 } |
| 180 | 186 |
| 181 INSTANTIATE_TEST_CASE_P(, | 187 INSTANTIATE_TEST_CASE_P(, |
| 182 VideoTrackRecorderTest, | 188 VideoTrackRecorderTest, |
| 183 ValuesIn(kTrackRecorderTestCodec)); | 189 ::testing::Combine(ValuesIn(kTrackRecorderTestCodec), |
| 190 ValuesIn(kTrackRecorderTestSize))); | |
| 184 | 191 |
| 185 } // namespace content | 192 } // namespace content |
| OLD | NEW |