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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 namespace media { | 30 namespace media { |
31 namespace cast { | 31 namespace cast { |
32 | 32 |
33 class VideoEncoderTest | 33 class VideoEncoderTest |
34 : public ::testing::TestWithParam<std::pair<Codec, bool>> { | 34 : public ::testing::TestWithParam<std::pair<Codec, bool>> { |
35 protected: | 35 protected: |
36 VideoEncoderTest() | 36 VideoEncoderTest() |
37 : testing_clock_(new base::SimpleTestTickClock()), | 37 : testing_clock_(new base::SimpleTestTickClock()), |
38 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)), | 38 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)), |
39 cast_environment_(new CastEnvironment( | 39 cast_environment_( |
40 scoped_ptr<base::TickClock>(testing_clock_).Pass(), | 40 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_), |
41 task_runner_, | 41 task_runner_, |
42 task_runner_, | 42 task_runner_, |
43 task_runner_)), | 43 task_runner_)), |
44 video_config_(GetDefaultVideoSenderConfig()), | 44 video_config_(GetDefaultVideoSenderConfig()), |
45 operational_status_(STATUS_UNINITIALIZED), | 45 operational_status_(STATUS_UNINITIALIZED), |
46 count_frames_delivered_(0) { | 46 count_frames_delivered_(0) { |
47 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); | 47 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); |
48 first_frame_time_ = testing_clock_->NowTicks(); | 48 first_frame_time_ = testing_clock_->NowTicks(); |
49 } | 49 } |
50 | 50 |
51 ~VideoEncoderTest() override {} | 51 ~VideoEncoderTest() override {} |
52 | 52 |
53 void SetUp() final { | 53 void SetUp() final { |
54 video_config_.codec = GetParam().first; | 54 video_config_.codec = GetParam().first; |
55 video_config_.use_external_encoder = GetParam().second; | 55 video_config_.use_external_encoder = GetParam().second; |
56 | 56 |
57 if (video_config_.use_external_encoder) | 57 if (video_config_.use_external_encoder) |
58 vea_factory_.reset(new FakeVideoEncodeAcceleratorFactory(task_runner_)); | 58 vea_factory_.reset(new FakeVideoEncodeAcceleratorFactory(task_runner_)); |
59 } | 59 } |
60 | 60 |
61 void TearDown() final { | 61 void TearDown() final { |
62 video_encoder_.reset(); | 62 video_encoder_.reset(); |
63 RunTasksAndAdvanceClock(); | 63 RunTasksAndAdvanceClock(); |
64 } | 64 } |
65 | 65 |
66 void CreateEncoder() { | 66 void CreateEncoder() { |
67 ASSERT_EQ(STATUS_UNINITIALIZED, operational_status_); | 67 ASSERT_EQ(STATUS_UNINITIALIZED, operational_status_); |
68 video_config_.max_number_of_video_buffers_used = 1; | 68 video_config_.max_number_of_video_buffers_used = 1; |
69 video_encoder_ = VideoEncoder::Create( | 69 video_encoder_ = VideoEncoder::Create( |
70 cast_environment_, | 70 cast_environment_, video_config_, |
71 video_config_, | |
72 base::Bind(&VideoEncoderTest::OnOperationalStatusChange, | 71 base::Bind(&VideoEncoderTest::OnOperationalStatusChange, |
73 base::Unretained(this)), | 72 base::Unretained(this)), |
74 base::Bind( | 73 base::Bind( |
75 &FakeVideoEncodeAcceleratorFactory::CreateVideoEncodeAccelerator, | 74 &FakeVideoEncodeAcceleratorFactory::CreateVideoEncodeAccelerator, |
76 base::Unretained(vea_factory_.get())), | 75 base::Unretained(vea_factory_.get())), |
77 base::Bind(&FakeVideoEncodeAcceleratorFactory::CreateSharedMemory, | 76 base::Bind(&FakeVideoEncodeAcceleratorFactory::CreateSharedMemory, |
78 base::Unretained(vea_factory_.get()))).Pass(); | 77 base::Unretained(vea_factory_.get()))); |
79 RunTasksAndAdvanceClock(); | 78 RunTasksAndAdvanceClock(); |
80 if (is_encoder_present()) | 79 if (is_encoder_present()) |
81 ASSERT_EQ(STATUS_INITIALIZED, operational_status_); | 80 ASSERT_EQ(STATUS_INITIALIZED, operational_status_); |
82 } | 81 } |
83 | 82 |
84 bool is_encoder_present() const { | 83 bool is_encoder_present() const { |
85 return !!video_encoder_; | 84 return !!video_encoder_; |
86 } | 85 } |
87 | 86 |
88 bool is_testing_software_vp8_encoder() const { | 87 bool is_testing_software_vp8_encoder() const { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 DVLOG(1) << "OnOperationalStatusChange: from " << operational_status_ | 204 DVLOG(1) << "OnOperationalStatusChange: from " << operational_status_ |
206 << " to " << status; | 205 << " to " << status; |
207 operational_status_ = status; | 206 operational_status_ = status; |
208 | 207 |
209 EXPECT_TRUE(operational_status_ == STATUS_CODEC_REINIT_PENDING || | 208 EXPECT_TRUE(operational_status_ == STATUS_CODEC_REINIT_PENDING || |
210 operational_status_ == STATUS_INITIALIZED); | 209 operational_status_ == STATUS_INITIALIZED); |
211 | 210 |
212 // Create the VideoFrameFactory the first time status changes to | 211 // Create the VideoFrameFactory the first time status changes to |
213 // STATUS_INITIALIZED. | 212 // STATUS_INITIALIZED. |
214 if (operational_status_ == STATUS_INITIALIZED && !video_frame_factory_) | 213 if (operational_status_ == STATUS_INITIALIZED && !video_frame_factory_) |
215 video_frame_factory_ = video_encoder_->CreateVideoFrameFactory().Pass(); | 214 video_frame_factory_ = video_encoder_->CreateVideoFrameFactory(); |
216 } | 215 } |
217 | 216 |
218 // Checks that |encoded_frame| matches expected values. This is the method | 217 // Checks that |encoded_frame| matches expected values. This is the method |
219 // bound in the callback returned from EncodeAndCheckDelivery(). | 218 // bound in the callback returned from EncodeAndCheckDelivery(). |
220 void DeliverEncodedVideoFrame(uint32_t expected_frame_id, | 219 void DeliverEncodedVideoFrame(uint32_t expected_frame_id, |
221 uint32_t expected_last_referenced_frame_id, | 220 uint32_t expected_last_referenced_frame_id, |
222 uint32_t expected_rtp_timestamp, | 221 uint32_t expected_rtp_timestamp, |
223 const base::TimeTicks& expected_reference_time, | 222 const base::TimeTicks& expected_reference_time, |
224 scoped_ptr<SenderEncodedFrame> encoded_frame) { | 223 scoped_ptr<SenderEncodedFrame> encoded_frame) { |
225 EXPECT_TRUE(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 224 EXPECT_TRUE(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 #endif | 421 #endif |
423 return values; | 422 return values; |
424 } | 423 } |
425 } // namespace | 424 } // namespace |
426 | 425 |
427 INSTANTIATE_TEST_CASE_P( | 426 INSTANTIATE_TEST_CASE_P( |
428 , VideoEncoderTest, ::testing::ValuesIn(DetermineEncodersToTest())); | 427 , VideoEncoderTest, ::testing::ValuesIn(DetermineEncodersToTest())); |
429 | 428 |
430 } // namespace cast | 429 } // namespace cast |
431 } // namespace media | 430 } // namespace media |
OLD | NEW |