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 <queue> | 5 #include <queue> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
11 #include "base/test/launcher/unit_test_launcher.h" | 11 #include "base/test/launcher/unit_test_launcher.h" |
12 #include "base/test/power_monitor_test_base.h" | 12 #include "base/test/power_monitor_test_base.h" |
13 #include "base/test/simple_test_tick_clock.h" | 13 #include "base/test/simple_test_tick_clock.h" |
14 #include "base/test/test_suite.h" | 14 #include "base/test/test_suite.h" |
15 #include "media/base/cdm_context.h" | 15 #include "media/base/cdm_context.h" |
16 #include "media/base/decoder_buffer.h" | 16 #include "media/base/decoder_buffer.h" |
17 #include "media/base/media.h" | 17 #include "media/base/media.h" |
18 #include "media/base/media_switches.h" | 18 #include "media/base/media_switches.h" |
19 #include "media/base/media_util.h" | 19 #include "media/base/media_util.h" |
20 #include "media/cast/cast_defines.h" | 20 #include "media/cast/common/rtp_time.h" |
21 #include "media/cast/constants.h" | 21 #include "media/cast/constants.h" |
22 #include "media/cast/sender/h264_vt_encoder.h" | 22 #include "media/cast/sender/h264_vt_encoder.h" |
23 #include "media/cast/sender/video_frame_factory.h" | 23 #include "media/cast/sender/video_frame_factory.h" |
24 #include "media/cast/test/utility/default_config.h" | 24 #include "media/cast/test/utility/default_config.h" |
25 #include "media/cast/test/utility/video_utility.h" | 25 #include "media/cast/test/utility/video_utility.h" |
26 #include "media/ffmpeg/ffmpeg_common.h" | 26 #include "media/ffmpeg/ffmpeg_common.h" |
27 #include "media/filters/ffmpeg_glue.h" | 27 #include "media/filters/ffmpeg_glue.h" |
28 #include "media/filters/ffmpeg_video_decoder.h" | 28 #include "media/filters/ffmpeg_video_decoder.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 class MetadataRecorder : public base::RefCountedThreadSafe<MetadataRecorder> { | 81 class MetadataRecorder : public base::RefCountedThreadSafe<MetadataRecorder> { |
82 public: | 82 public: |
83 MetadataRecorder() : count_frames_delivered_(0) {} | 83 MetadataRecorder() : count_frames_delivered_(0) {} |
84 | 84 |
85 int count_frames_delivered() const { return count_frames_delivered_; } | 85 int count_frames_delivered() const { return count_frames_delivered_; } |
86 | 86 |
87 void PushExpectation(uint32 expected_frame_id, | 87 void PushExpectation(uint32 expected_frame_id, |
88 uint32 expected_last_referenced_frame_id, | 88 uint32 expected_last_referenced_frame_id, |
89 uint32 expected_rtp_timestamp, | 89 RtpTimeTicks expected_rtp_timestamp, |
90 const base::TimeTicks& expected_reference_time) { | 90 const base::TimeTicks& expected_reference_time) { |
91 expectations_.push(Expectation{expected_frame_id, | 91 expectations_.push(Expectation{expected_frame_id, |
92 expected_last_referenced_frame_id, | 92 expected_last_referenced_frame_id, |
93 expected_rtp_timestamp, | 93 expected_rtp_timestamp, |
94 expected_reference_time}); | 94 expected_reference_time}); |
95 } | 95 } |
96 | 96 |
97 void CompareFrameWithExpected(scoped_ptr<SenderEncodedFrame> encoded_frame) { | 97 void CompareFrameWithExpected(scoped_ptr<SenderEncodedFrame> encoded_frame) { |
98 ASSERT_LT(0u, expectations_.size()); | 98 ASSERT_LT(0u, expectations_.size()); |
99 auto e = expectations_.front(); | 99 auto e = expectations_.front(); |
(...skipping 15 matching lines...) Expand all Loading... |
115 | 115 |
116 private: | 116 private: |
117 friend class base::RefCountedThreadSafe<MetadataRecorder>; | 117 friend class base::RefCountedThreadSafe<MetadataRecorder>; |
118 virtual ~MetadataRecorder() {} | 118 virtual ~MetadataRecorder() {} |
119 | 119 |
120 int count_frames_delivered_; | 120 int count_frames_delivered_; |
121 | 121 |
122 struct Expectation { | 122 struct Expectation { |
123 uint32 expected_frame_id; | 123 uint32 expected_frame_id; |
124 uint32 expected_last_referenced_frame_id; | 124 uint32 expected_last_referenced_frame_id; |
125 uint32 expected_rtp_timestamp; | 125 RtpTimeTicks expected_rtp_timestamp; |
126 base::TimeTicks expected_reference_time; | 126 base::TimeTicks expected_reference_time; |
127 }; | 127 }; |
128 std::queue<Expectation> expectations_; | 128 std::queue<Expectation> expectations_; |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(MetadataRecorder); | 130 DISALLOW_COPY_AND_ASSIGN(MetadataRecorder); |
131 }; | 131 }; |
132 | 132 |
133 class EndToEndFrameChecker | 133 class EndToEndFrameChecker |
134 : public base::RefCountedThreadSafe<EndToEndFrameChecker> { | 134 : public base::RefCountedThreadSafe<EndToEndFrameChecker> { |
135 public: | 135 public: |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 // static | 280 // static |
281 scoped_refptr<media::VideoFrame> H264VideoToolboxEncoderTest::frame_; | 281 scoped_refptr<media::VideoFrame> H264VideoToolboxEncoderTest::frame_; |
282 VideoSenderConfig H264VideoToolboxEncoderTest::video_sender_config_; | 282 VideoSenderConfig H264VideoToolboxEncoderTest::video_sender_config_; |
283 | 283 |
284 TEST_F(H264VideoToolboxEncoderTest, CheckFrameMetadataSequence) { | 284 TEST_F(H264VideoToolboxEncoderTest, CheckFrameMetadataSequence) { |
285 scoped_refptr<MetadataRecorder> metadata_recorder(new MetadataRecorder()); | 285 scoped_refptr<MetadataRecorder> metadata_recorder(new MetadataRecorder()); |
286 VideoEncoder::FrameEncodedCallback cb = base::Bind( | 286 VideoEncoder::FrameEncodedCallback cb = base::Bind( |
287 &MetadataRecorder::CompareFrameWithExpected, metadata_recorder.get()); | 287 &MetadataRecorder::CompareFrameWithExpected, metadata_recorder.get()); |
288 | 288 |
289 metadata_recorder->PushExpectation( | 289 metadata_recorder->PushExpectation( |
290 0, 0, TimeDeltaToRtpDelta(frame_->timestamp(), kVideoFrequency), | 290 0, 0, RtpTimeTicks::FromTimeDelta(frame_->timestamp(), kVideoFrequency), |
291 clock_->NowTicks()); | 291 clock_->NowTicks()); |
292 EXPECT_TRUE(encoder_->EncodeVideoFrame(frame_, clock_->NowTicks(), cb)); | 292 EXPECT_TRUE(encoder_->EncodeVideoFrame(frame_, clock_->NowTicks(), cb)); |
293 message_loop_.RunUntilIdle(); | 293 message_loop_.RunUntilIdle(); |
294 | 294 |
295 for (uint32 frame_id = 1; frame_id < 10; ++frame_id) { | 295 for (uint32 frame_id = 1; frame_id < 10; ++frame_id) { |
296 AdvanceClockAndVideoFrameTimestamp(); | 296 AdvanceClockAndVideoFrameTimestamp(); |
297 metadata_recorder->PushExpectation( | 297 metadata_recorder->PushExpectation( |
298 frame_id, frame_id - 1, | 298 frame_id, frame_id - 1, |
299 TimeDeltaToRtpDelta(frame_->timestamp(), kVideoFrequency), | 299 RtpTimeTicks::FromTimeDelta(frame_->timestamp(), kVideoFrequency), |
300 clock_->NowTicks()); | 300 clock_->NowTicks()); |
301 EXPECT_TRUE(encoder_->EncodeVideoFrame(frame_, clock_->NowTicks(), cb)); | 301 EXPECT_TRUE(encoder_->EncodeVideoFrame(frame_, clock_->NowTicks(), cb)); |
302 } | 302 } |
303 | 303 |
304 encoder_.reset(); | 304 encoder_.reset(); |
305 message_loop_.RunUntilIdle(); | 305 message_loop_.RunUntilIdle(); |
306 | 306 |
307 EXPECT_EQ(10, metadata_recorder->count_frames_delivered()); | 307 EXPECT_EQ(10, metadata_recorder->count_frames_delivered()); |
308 } | 308 } |
309 | 309 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 gfx::Size(kVideoWidth, kVideoHeight), base::TimeDelta())); | 409 gfx::Size(kVideoWidth, kVideoHeight), base::TimeDelta())); |
410 | 410 |
411 // After a power resume event, the factory should produce frames right away | 411 // After a power resume event, the factory should produce frames right away |
412 // because the encoder re-initializes on its own. | 412 // because the encoder re-initializes on its own. |
413 power_source_->GenerateResumeEvent(); | 413 power_source_->GenerateResumeEvent(); |
414 CreateFrameAndMemsetPlane(video_frame_factory.get()); | 414 CreateFrameAndMemsetPlane(video_frame_factory.get()); |
415 } | 415 } |
416 | 416 |
417 } // namespace cast | 417 } // namespace cast |
418 } // namespace media | 418 } // namespace media |
OLD | NEW |