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