| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 ~VideoTrackRecorderTest() { | 89 ~VideoTrackRecorderTest() { |
| 90 blink_track_.reset(); | 90 blink_track_.reset(); |
| 91 blink_source_.reset(); | 91 blink_source_.reset(); |
| 92 video_track_recorder_.reset(); | 92 video_track_recorder_.reset(); |
| 93 blink::WebHeap::collectAllGarbageForTesting(); | 93 blink::WebHeap::collectAllGarbageForTesting(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 MOCK_METHOD4(DoOnEncodedVideo, | 96 MOCK_METHOD4(DoOnEncodedVideo, |
| 97 void(const scoped_refptr<VideoFrame>& frame, | 97 void(const media::WebmMuxer::VideoParameters& params, |
| 98 std::string encoded_data, | 98 std::string encoded_data, |
| 99 base::TimeTicks timestamp, | 99 base::TimeTicks timestamp, |
| 100 bool keyframe)); | 100 bool keyframe)); |
| 101 void OnEncodedVideo(const scoped_refptr<VideoFrame>& video_frame, | 101 void OnEncodedVideo(const media::WebmMuxer::VideoParameters& params, |
| 102 std::unique_ptr<std::string> encoded_data, | 102 std::unique_ptr<std::string> encoded_data, |
| 103 base::TimeTicks timestamp, | 103 base::TimeTicks timestamp, |
| 104 bool is_key_frame) { | 104 bool is_key_frame) { |
| 105 DoOnEncodedVideo(video_frame, *encoded_data, timestamp, is_key_frame); | 105 DoOnEncodedVideo(params, *encoded_data, timestamp, is_key_frame); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void Encode(const scoped_refptr<VideoFrame>& frame, | 108 void Encode(const scoped_refptr<VideoFrame>& frame, |
| 109 base::TimeTicks capture_time) { | 109 base::TimeTicks capture_time) { |
| 110 EXPECT_TRUE(message_loop_.IsCurrent()); | 110 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 111 video_track_recorder_->OnVideoFrameForTesting(frame, capture_time); | 111 video_track_recorder_->OnVideoFrameForTesting(frame, capture_time); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 114 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
| 115 // and Sources below into believing they are on the right threads. | 115 // and Sources below into believing they are on the right threads. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 141 const gfx::Size& frame_size = testing::get<1>(GetParam()); | 141 const gfx::Size& frame_size = testing::get<1>(GetParam()); |
| 142 const scoped_refptr<VideoFrame> video_frame = | 142 const scoped_refptr<VideoFrame> video_frame = |
| 143 VideoFrame::CreateBlackFrame(frame_size); | 143 VideoFrame::CreateBlackFrame(frame_size); |
| 144 const double kFrameRate = 60.0f; | 144 const double kFrameRate = 60.0f; |
| 145 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, | 145 video_frame->metadata()->SetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 146 kFrameRate); | 146 kFrameRate); |
| 147 | 147 |
| 148 InSequence s; | 148 InSequence s; |
| 149 const base::TimeTicks timeticks_now = base::TimeTicks::Now(); | 149 const base::TimeTicks timeticks_now = base::TimeTicks::Now(); |
| 150 base::StringPiece first_frame_encoded_data; | 150 base::StringPiece first_frame_encoded_data; |
| 151 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_now, true)) | 151 EXPECT_CALL(*this, DoOnEncodedVideo(_, _, timeticks_now, true)) |
| 152 .Times(1) | 152 .Times(1) |
| 153 .WillOnce(SaveArg<1>(&first_frame_encoded_data)); | 153 .WillOnce(SaveArg<1>(&first_frame_encoded_data)); |
| 154 Encode(video_frame, timeticks_now); | 154 Encode(video_frame, timeticks_now); |
| 155 | 155 |
| 156 // Send another Video Frame. | 156 // Send another Video Frame. |
| 157 const base::TimeTicks timeticks_later = base::TimeTicks::Now(); | 157 const base::TimeTicks timeticks_later = base::TimeTicks::Now(); |
| 158 base::StringPiece second_frame_encoded_data; | 158 base::StringPiece second_frame_encoded_data; |
| 159 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame, _, timeticks_later, false)) | 159 EXPECT_CALL(*this, DoOnEncodedVideo(_, _, timeticks_later, false)) |
| 160 .Times(1) | 160 .Times(1) |
| 161 .WillOnce(SaveArg<1>(&second_frame_encoded_data)); | 161 .WillOnce(SaveArg<1>(&second_frame_encoded_data)); |
| 162 Encode(video_frame, timeticks_later); | 162 Encode(video_frame, timeticks_later); |
| 163 | 163 |
| 164 // Send another Video Frame and expect only an DoOnEncodedVideo() callback. | 164 // Send another Video Frame and expect only an DoOnEncodedVideo() callback. |
| 165 const gfx::Size frame_size2(frame_size.width() + kTrackRecorderTestSizeDiff, | 165 const gfx::Size frame_size2(frame_size.width() + kTrackRecorderTestSizeDiff, |
| 166 frame_size.height()); | 166 frame_size.height()); |
| 167 const scoped_refptr<VideoFrame> video_frame2 = | 167 const scoped_refptr<VideoFrame> video_frame2 = |
| 168 VideoFrame::CreateBlackFrame(frame_size2); | 168 VideoFrame::CreateBlackFrame(frame_size2); |
| 169 | 169 |
| 170 base::RunLoop run_loop; | 170 base::RunLoop run_loop; |
| 171 base::Closure quit_closure = run_loop.QuitClosure(); | 171 base::Closure quit_closure = run_loop.QuitClosure(); |
| 172 | 172 |
| 173 base::StringPiece third_frame_encoded_data; | 173 base::StringPiece third_frame_encoded_data; |
| 174 EXPECT_CALL(*this, DoOnEncodedVideo(video_frame2, _, _, true)) | 174 EXPECT_CALL(*this, DoOnEncodedVideo(_, _, _, true)) |
| 175 .Times(1) | 175 .Times(1) |
| 176 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), | 176 .WillOnce(DoAll(SaveArg<1>(&third_frame_encoded_data), |
| 177 RunClosure(quit_closure))); | 177 RunClosure(quit_closure))); |
| 178 Encode(video_frame2, base::TimeTicks::Now()); | 178 Encode(video_frame2, base::TimeTicks::Now()); |
| 179 | 179 |
| 180 run_loop.Run(); | 180 run_loop.Run(); |
| 181 | 181 |
| 182 const size_t kEncodedSizeThreshold = 14; | 182 const size_t kEncodedSizeThreshold = 14; |
| 183 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); | 183 EXPECT_GE(first_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 184 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); | 184 EXPECT_GE(second_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 185 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); | 185 EXPECT_GE(third_frame_encoded_data.size(), kEncodedSizeThreshold); |
| 186 | 186 |
| 187 Mock::VerifyAndClearExpectations(this); | 187 Mock::VerifyAndClearExpectations(this); |
| 188 } | 188 } |
| 189 | 189 |
| 190 INSTANTIATE_TEST_CASE_P(, | 190 INSTANTIATE_TEST_CASE_P(, |
| 191 VideoTrackRecorderTest, | 191 VideoTrackRecorderTest, |
| 192 ::testing::Combine(ValuesIn(kTrackRecorderTestCodec), | 192 ::testing::Combine(ValuesIn(kTrackRecorderTestCodec), |
| 193 ValuesIn(kTrackRecorderTestSize))); | 193 ValuesIn(kTrackRecorderTestSize))); |
| 194 | 194 |
| 195 } // namespace content | 195 } // namespace content |
| OLD | NEW |