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" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 #include "media/cast/cast_defines.h" | 12 #include "media/cast/cast_defines.h" |
13 #include "media/cast/cast_environment.h" | 13 #include "media/cast/cast_environment.h" |
| 14 #include "media/cast/common/rtp_time.h" |
14 #include "media/cast/sender/fake_video_encode_accelerator_factory.h" | 15 #include "media/cast/sender/fake_video_encode_accelerator_factory.h" |
15 #include "media/cast/sender/video_frame_factory.h" | 16 #include "media/cast/sender/video_frame_factory.h" |
16 #include "media/cast/sender/video_encoder.h" | 17 #include "media/cast/sender/video_encoder.h" |
17 #include "media/cast/test/fake_single_thread_task_runner.h" | 18 #include "media/cast/test/fake_single_thread_task_runner.h" |
18 #include "media/cast/test/utility/default_config.h" | 19 #include "media/cast/test/utility/default_config.h" |
19 #include "media/cast/test/utility/video_utility.h" | 20 #include "media/cast/test/utility/video_utility.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
23 #include "media/cast/sender/h264_vt_encoder.h" | 24 #include "media/cast/sender/h264_vt_encoder.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 162 } |
162 | 163 |
163 // Requests encoding the |video_frame| and has the resulting frame delivered | 164 // Requests encoding the |video_frame| and has the resulting frame delivered |
164 // via a callback that checks for expected results. Returns false if the | 165 // via a callback that checks for expected results. Returns false if the |
165 // encoder rejected the request. | 166 // encoder rejected the request. |
166 bool EncodeAndCheckDelivery( | 167 bool EncodeAndCheckDelivery( |
167 const scoped_refptr<media::VideoFrame>& video_frame, | 168 const scoped_refptr<media::VideoFrame>& video_frame, |
168 uint32 frame_id, | 169 uint32 frame_id, |
169 uint32 reference_frame_id) { | 170 uint32 reference_frame_id) { |
170 return video_encoder_->EncodeVideoFrame( | 171 return video_encoder_->EncodeVideoFrame( |
171 video_frame, | 172 video_frame, Now(), |
172 Now(), | |
173 base::Bind(&VideoEncoderTest::DeliverEncodedVideoFrame, | 173 base::Bind(&VideoEncoderTest::DeliverEncodedVideoFrame, |
174 base::Unretained(this), | 174 base::Unretained(this), frame_id, reference_frame_id, |
175 frame_id, | 175 RtpTimeTicks::FromTimeDelta(video_frame->timestamp(), |
176 reference_frame_id, | 176 kVideoFrequency), |
177 TimeDeltaToRtpDelta(video_frame->timestamp(), | |
178 kVideoFrequency), | |
179 Now())); | 177 Now())); |
180 } | 178 } |
181 | 179 |
182 // If the implementation of |video_encoder_| is ExternalVideoEncoder, check | 180 // If the implementation of |video_encoder_| is ExternalVideoEncoder, check |
183 // that the VEA factory has responded (by running the callbacks) a specific | 181 // that the VEA factory has responded (by running the callbacks) a specific |
184 // number of times. Otherwise, check that the VEA factory is inactive. | 182 // number of times. Otherwise, check that the VEA factory is inactive. |
185 void ExpectVEAResponsesForExternalVideoEncoder( | 183 void ExpectVEAResponsesForExternalVideoEncoder( |
186 int vea_response_count, | 184 int vea_response_count, |
187 int shm_response_count) const { | 185 int shm_response_count) const { |
188 if (!vea_factory_) | 186 if (!vea_factory_) |
(...skipping 17 matching lines...) Expand all Loading... |
206 operational_status_ == STATUS_INITIALIZED); | 204 operational_status_ == STATUS_INITIALIZED); |
207 | 205 |
208 // Create the VideoFrameFactory the first time status changes to | 206 // Create the VideoFrameFactory the first time status changes to |
209 // STATUS_INITIALIZED. | 207 // STATUS_INITIALIZED. |
210 if (operational_status_ == STATUS_INITIALIZED && !video_frame_factory_) | 208 if (operational_status_ == STATUS_INITIALIZED && !video_frame_factory_) |
211 video_frame_factory_ = video_encoder_->CreateVideoFrameFactory().Pass(); | 209 video_frame_factory_ = video_encoder_->CreateVideoFrameFactory().Pass(); |
212 } | 210 } |
213 | 211 |
214 // Checks that |encoded_frame| matches expected values. This is the method | 212 // Checks that |encoded_frame| matches expected values. This is the method |
215 // bound in the callback returned from EncodeAndCheckDelivery(). | 213 // bound in the callback returned from EncodeAndCheckDelivery(). |
216 void DeliverEncodedVideoFrame( | 214 void DeliverEncodedVideoFrame(uint32 expected_frame_id, |
217 uint32 expected_frame_id, | 215 uint32 expected_last_referenced_frame_id, |
218 uint32 expected_last_referenced_frame_id, | 216 RtpTimeTicks expected_rtp_timestamp, |
219 uint32 expected_rtp_timestamp, | 217 const base::TimeTicks& expected_reference_time, |
220 const base::TimeTicks& expected_reference_time, | 218 scoped_ptr<SenderEncodedFrame> encoded_frame) { |
221 scoped_ptr<SenderEncodedFrame> encoded_frame) { | |
222 EXPECT_TRUE(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 219 EXPECT_TRUE(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
223 | 220 |
224 EXPECT_EQ(expected_frame_id, encoded_frame->frame_id); | 221 EXPECT_EQ(expected_frame_id, encoded_frame->frame_id); |
225 EXPECT_EQ(expected_rtp_timestamp, encoded_frame->rtp_timestamp); | 222 EXPECT_EQ(expected_rtp_timestamp, encoded_frame->rtp_timestamp); |
226 EXPECT_EQ(expected_reference_time, encoded_frame->reference_time); | 223 EXPECT_EQ(expected_reference_time, encoded_frame->reference_time); |
227 | 224 |
228 // The platform encoders are "black boxes" and may choose to vend key frames | 225 // 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 | 226 // and/or empty data at any time. The software encoders, however, should |
230 // strictly adhere to expected behavior. | 227 // strictly adhere to expected behavior. |
231 if (is_testing_platform_encoder()) { | 228 if (is_testing_platform_encoder()) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 #endif | 416 #endif |
420 return values; | 417 return values; |
421 } | 418 } |
422 } // namespace | 419 } // namespace |
423 | 420 |
424 INSTANTIATE_TEST_CASE_P( | 421 INSTANTIATE_TEST_CASE_P( |
425 , VideoEncoderTest, ::testing::ValuesIn(DetermineEncodersToTest())); | 422 , VideoEncoderTest, ::testing::ValuesIn(DetermineEncodersToTest())); |
426 | 423 |
427 } // namespace cast | 424 } // namespace cast |
428 } // namespace media | 425 } // namespace media |
OLD | NEW |