| 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 22 matching lines...) Expand all Loading... |
| 33 using ::testing::SaveArg; | 33 using ::testing::SaveArg; |
| 34 using ::testing::TestWithParam; | 34 using ::testing::TestWithParam; |
| 35 using ::testing::ValuesIn; | 35 using ::testing::ValuesIn; |
| 36 | 36 |
| 37 namespace content { | 37 namespace content { |
| 38 | 38 |
| 39 ACTION_P(RunClosure, closure) { | 39 ACTION_P(RunClosure, closure) { |
| 40 closure.Run(); | 40 closure.Run(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 const bool kTrackRecorderTestUseVp9OrNot[] = {false, true}; | 43 const VideoTrackRecorder::CodecId kTrackRecorderTestCodec[] = { |
| 44 VideoTrackRecorder::CodecId::VP8, VideoTrackRecorder::CodecId::VP9, |
| 45 VideoTrackRecorder::CodecId::H264}; |
| 44 | 46 |
| 45 class VideoTrackRecorderTest : public TestWithParam<bool> { | 47 class VideoTrackRecorderTest |
| 48 : public TestWithParam<VideoTrackRecorder::CodecId> { |
| 46 public: | 49 public: |
| 47 VideoTrackRecorderTest() | 50 VideoTrackRecorderTest() |
| 48 : mock_source_(new MockMediaStreamVideoSource(false)) { | 51 : mock_source_(new MockMediaStreamVideoSource(false)) { |
| 49 const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy")); | 52 const blink::WebString webkit_track_id(base::UTF8ToUTF16("dummy")); |
| 50 blink_source_.initialize(webkit_track_id, | 53 blink_source_.initialize(webkit_track_id, |
| 51 blink::WebMediaStreamSource::TypeVideo, | 54 blink::WebMediaStreamSource::TypeVideo, |
| 52 webkit_track_id); | 55 webkit_track_id); |
| 53 blink_source_.setExtraData(mock_source_); | 56 blink_source_.setExtraData(mock_source_); |
| 54 blink_track_.initialize(blink_source_); | 57 blink_track_.initialize(blink_source_); |
| 55 | 58 |
| 56 blink::WebMediaConstraints constraints; | 59 blink::WebMediaConstraints constraints; |
| 57 constraints.initialize(); | 60 constraints.initialize(); |
| 58 track_ = new MediaStreamVideoTrack(mock_source_, constraints, | 61 track_ = new MediaStreamVideoTrack(mock_source_, constraints, |
| 59 MediaStreamSource::ConstraintsCallback(), | 62 MediaStreamSource::ConstraintsCallback(), |
| 60 true /* enabled */); | 63 true /* enabled */); |
| 61 blink_track_.setExtraData(track_); | 64 blink_track_.setExtraData(track_); |
| 62 | 65 |
| 63 video_track_recorder_.reset(new VideoTrackRecorder( | 66 video_track_recorder_.reset(new VideoTrackRecorder( |
| 64 GetParam() /* use_vp9 */, blink_track_, | 67 GetParam() /* codec */, blink_track_, |
| 65 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo, | 68 base::Bind(&VideoTrackRecorderTest::OnEncodedVideo, |
| 66 base::Unretained(this)), | 69 base::Unretained(this)), |
| 67 0 /* bits_per_second */)); | 70 0 /* bits_per_second */)); |
| 68 // Paranoia checks. | 71 // Paranoia checks. |
| 69 EXPECT_EQ(blink_track_.source().getExtraData(), | 72 EXPECT_EQ(blink_track_.source().getExtraData(), |
| 70 blink_source_.getExtraData()); | 73 blink_source_.getExtraData()); |
| 71 EXPECT_TRUE(message_loop_.IsCurrent()); | 74 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 72 } | 75 } |
| 73 | 76 |
| 74 ~VideoTrackRecorderTest() { | 77 ~VideoTrackRecorderTest() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 159 |
| 157 base::StringPiece third_frame_encoded_data; | 160 base::StringPiece third_frame_encoded_data; |
| 158 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true)) | 161 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true)) |
| 159 .Times(1) | 162 .Times(1) |
| 160 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), | 163 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), |
| 161 RunClosure(quit_closure))); | 164 RunClosure(quit_closure))); |
| 162 Encode(video_frame2, base::TimeTicks::Now()); | 165 Encode(video_frame2, base::TimeTicks::Now()); |
| 163 | 166 |
| 164 run_loop.Run(); | 167 run_loop.Run(); |
| 165 | 168 |
| 166 const size_t kEncodedSizeThreshold = 18; | 169 const size_t kEncodedSizeThreshold = 14; |
| 167 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); | 170 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 168 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); | 171 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 169 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); | 172 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 170 | 173 |
| 171 Mock::VerifyAndClearExpectations(this); | 174 Mock::VerifyAndClearExpectations(this); |
| 172 } | 175 } |
| 173 | 176 |
| 174 INSTANTIATE_TEST_CASE_P(, | 177 INSTANTIATE_TEST_CASE_P(, |
| 175 VideoTrackRecorderTest, | 178 VideoTrackRecorderTest, |
| 176 ValuesIn(kTrackRecorderTestUseVp9OrNot)); | 179 ValuesIn(kTrackRecorderTestCodec)); |
| 177 | 180 |
| 178 } // namespace content | 181 } // namespace content |
| OLD | NEW |