| OLD | NEW |
| 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 <vector> | 5 #include <vector> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 158 } |
| 159 PopulateVideoFrame(frame.get(), 123); | 159 PopulateVideoFrame(frame.get(), 123); |
| 160 return frame; | 160 return frame; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Requests encoding the |video_frame| and has the resulting frame delivered | 163 // Requests encoding the |video_frame| and has the resulting frame delivered |
| 164 // via a callback that checks for expected results. Returns false if the | 164 // via a callback that checks for expected results. Returns false if the |
| 165 // encoder rejected the request. | 165 // encoder rejected the request. |
| 166 bool EncodeAndCheckDelivery( | 166 bool EncodeAndCheckDelivery( |
| 167 const scoped_refptr<media::VideoFrame>& video_frame, | 167 const scoped_refptr<media::VideoFrame>& video_frame, |
| 168 uint32 frame_id, | 168 uint32_t frame_id, |
| 169 uint32 reference_frame_id) { | 169 uint32_t reference_frame_id) { |
| 170 return video_encoder_->EncodeVideoFrame( | 170 return video_encoder_->EncodeVideoFrame( |
| 171 video_frame, | 171 video_frame, |
| 172 Now(), | 172 Now(), |
| 173 base::Bind(&VideoEncoderTest::DeliverEncodedVideoFrame, | 173 base::Bind(&VideoEncoderTest::DeliverEncodedVideoFrame, |
| 174 base::Unretained(this), | 174 base::Unretained(this), |
| 175 frame_id, | 175 frame_id, |
| 176 reference_frame_id, | 176 reference_frame_id, |
| 177 TimeDeltaToRtpDelta(video_frame->timestamp(), | 177 TimeDeltaToRtpDelta(video_frame->timestamp(), |
| 178 kVideoFrequency), | 178 kVideoFrequency), |
| 179 Now())); | 179 Now())); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 206 operational_status_ == STATUS_INITIALIZED); | 206 operational_status_ == STATUS_INITIALIZED); |
| 207 | 207 |
| 208 // Create the VideoFrameFactory the first time status changes to | 208 // Create the VideoFrameFactory the first time status changes to |
| 209 // STATUS_INITIALIZED. | 209 // STATUS_INITIALIZED. |
| 210 if (operational_status_ == STATUS_INITIALIZED && !video_frame_factory_) | 210 if (operational_status_ == STATUS_INITIALIZED && !video_frame_factory_) |
| 211 video_frame_factory_ = video_encoder_->CreateVideoFrameFactory().Pass(); | 211 video_frame_factory_ = video_encoder_->CreateVideoFrameFactory().Pass(); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Checks that |encoded_frame| matches expected values. This is the method | 214 // Checks that |encoded_frame| matches expected values. This is the method |
| 215 // bound in the callback returned from EncodeAndCheckDelivery(). | 215 // bound in the callback returned from EncodeAndCheckDelivery(). |
| 216 void DeliverEncodedVideoFrame( | 216 void DeliverEncodedVideoFrame(uint32_t expected_frame_id, |
| 217 uint32 expected_frame_id, | 217 uint32_t expected_last_referenced_frame_id, |
| 218 uint32 expected_last_referenced_frame_id, | 218 uint32_t expected_rtp_timestamp, |
| 219 uint32 expected_rtp_timestamp, | 219 const base::TimeTicks& expected_reference_time, |
| 220 const base::TimeTicks& expected_reference_time, | 220 scoped_ptr<SenderEncodedFrame> encoded_frame) { |
| 221 scoped_ptr<SenderEncodedFrame> encoded_frame) { | |
| 222 EXPECT_TRUE(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 221 EXPECT_TRUE(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 223 | 222 |
| 224 EXPECT_EQ(expected_frame_id, encoded_frame->frame_id); | 223 EXPECT_EQ(expected_frame_id, encoded_frame->frame_id); |
| 225 EXPECT_EQ(expected_rtp_timestamp, encoded_frame->rtp_timestamp); | 224 EXPECT_EQ(expected_rtp_timestamp, encoded_frame->rtp_timestamp); |
| 226 EXPECT_EQ(expected_reference_time, encoded_frame->reference_time); | 225 EXPECT_EQ(expected_reference_time, encoded_frame->reference_time); |
| 227 | 226 |
| 228 // The platform encoders are "black boxes" and may choose to vend key frames | 227 // The platform encoders are "black boxes" and may choose to vend key frames |
| 229 // and/or empty data at any time. The software encoders, however, should | 228 // and/or empty data at any time. The software encoders, however, should |
| 230 // strictly adhere to expected behavior. | 229 // strictly adhere to expected behavior. |
| 231 if (is_testing_platform_encoder()) { | 230 if (is_testing_platform_encoder()) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 277 |
| 279 // A simple test to encode ten frames of video, expecting to see one key frame | 278 // A simple test to encode ten frames of video, expecting to see one key frame |
| 280 // followed by nine delta frames. | 279 // followed by nine delta frames. |
| 281 TEST_P(VideoEncoderTest, GeneratesKeyFrameThenOnlyDeltaFrames) { | 280 TEST_P(VideoEncoderTest, GeneratesKeyFrameThenOnlyDeltaFrames) { |
| 282 CreateEncoder(); | 281 CreateEncoder(); |
| 283 SetVEAFactoryAutoRespond(true); | 282 SetVEAFactoryAutoRespond(true); |
| 284 | 283 |
| 285 EXPECT_EQ(0, count_frames_delivered()); | 284 EXPECT_EQ(0, count_frames_delivered()); |
| 286 ExpectVEAResponsesForExternalVideoEncoder(0, 0); | 285 ExpectVEAResponsesForExternalVideoEncoder(0, 0); |
| 287 | 286 |
| 288 uint32 frame_id = 0; | 287 uint32_t frame_id = 0; |
| 289 uint32 reference_frame_id = 0; | 288 uint32_t reference_frame_id = 0; |
| 290 const gfx::Size frame_size(1280, 720); | 289 const gfx::Size frame_size(1280, 720); |
| 291 | 290 |
| 292 // Some encoders drop one or more frames initially while the encoder | 291 // Some encoders drop one or more frames initially while the encoder |
| 293 // initializes. Then, for all encoders, expect one key frame is delivered. | 292 // initializes. Then, for all encoders, expect one key frame is delivered. |
| 294 bool accepted_first_frame = false; | 293 bool accepted_first_frame = false; |
| 295 do { | 294 do { |
| 296 accepted_first_frame = EncodeAndCheckDelivery( | 295 accepted_first_frame = EncodeAndCheckDelivery( |
| 297 CreateTestVideoFrame(frame_size), frame_id, reference_frame_id); | 296 CreateTestVideoFrame(frame_size), frame_id, reference_frame_id); |
| 298 if (!encoder_has_resize_delay()) | 297 if (!encoder_has_resize_delay()) |
| 299 EXPECT_TRUE(accepted_first_frame); | 298 EXPECT_TRUE(accepted_first_frame); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 330 frame_sizes.push_back(gfx::Size(300, 200)); // Shrink both dimensions again. | 329 frame_sizes.push_back(gfx::Size(300, 200)); // Shrink both dimensions again. |
| 331 frame_sizes.push_back(gfx::Size(200, 300)); // Same area. | 330 frame_sizes.push_back(gfx::Size(200, 300)); // Same area. |
| 332 frame_sizes.push_back(gfx::Size(600, 400)); // Grow both dimensions. | 331 frame_sizes.push_back(gfx::Size(600, 400)); // Grow both dimensions. |
| 333 frame_sizes.push_back(gfx::Size(638, 400)); // Shrink only one dimension. | 332 frame_sizes.push_back(gfx::Size(638, 400)); // Shrink only one dimension. |
| 334 frame_sizes.push_back(gfx::Size(638, 398)); // Shrink the other dimension. | 333 frame_sizes.push_back(gfx::Size(638, 398)); // Shrink the other dimension. |
| 335 frame_sizes.push_back(gfx::Size(320, 180)); // Shrink both dimensions again. | 334 frame_sizes.push_back(gfx::Size(320, 180)); // Shrink both dimensions again. |
| 336 frame_sizes.push_back(gfx::Size(322, 180)); // Grow only one dimension. | 335 frame_sizes.push_back(gfx::Size(322, 180)); // Grow only one dimension. |
| 337 frame_sizes.push_back(gfx::Size(322, 182)); // Grow the other dimension. | 336 frame_sizes.push_back(gfx::Size(322, 182)); // Grow the other dimension. |
| 338 frame_sizes.push_back(gfx::Size(1920, 1080)); // Grow both dimensions again. | 337 frame_sizes.push_back(gfx::Size(1920, 1080)); // Grow both dimensions again. |
| 339 | 338 |
| 340 uint32 frame_id = 0; | 339 uint32_t frame_id = 0; |
| 341 | 340 |
| 342 // Encode one frame at each size. For encoders with a resize delay, except no | 341 // Encode one frame at each size. For encoders with a resize delay, except no |
| 343 // frames to be delivered since each frame size change will sprun | 342 // frames to be delivered since each frame size change will sprun |
| 344 // re-initialization of the underlying encoder. Otherwise expect all key | 343 // re-initialization of the underlying encoder. Otherwise expect all key |
| 345 // frames to come out. | 344 // frames to come out. |
| 346 for (const auto& frame_size : frame_sizes) { | 345 for (const auto& frame_size : frame_sizes) { |
| 347 EXPECT_EQ(!encoder_has_resize_delay(), | 346 EXPECT_EQ(!encoder_has_resize_delay(), |
| 348 EncodeAndCheckDelivery(CreateTestVideoFrame(frame_size), frame_id, | 347 EncodeAndCheckDelivery(CreateTestVideoFrame(frame_size), frame_id, |
| 349 frame_id)); | 348 frame_id)); |
| 350 RunTasksAndAdvanceClock(); | 349 RunTasksAndAdvanceClock(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 #endif | 418 #endif |
| 420 return values; | 419 return values; |
| 421 } | 420 } |
| 422 } // namespace | 421 } // namespace |
| 423 | 422 |
| 424 INSTANTIATE_TEST_CASE_P( | 423 INSTANTIATE_TEST_CASE_P( |
| 425 , VideoEncoderTest, ::testing::ValuesIn(DetermineEncodersToTest())); | 424 , VideoEncoderTest, ::testing::ValuesIn(DetermineEncodersToTest())); |
| 426 | 425 |
| 427 } // namespace cast | 426 } // namespace cast |
| 428 } // namespace media | 427 } // namespace media |
| OLD | NEW |