OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | |
5 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/test/simple_test_tick_clock.h" | |
8 #include "base/time/tick_clock.h" | |
9 #include "media/cast/cast_config.h" | |
6 #include "media/cast/cast_defines.h" | 10 #include "media/cast/cast_defines.h" |
11 #include "media/cast/cast_environment.h" | |
12 #include "media/cast/cast_receiver.h" | |
13 #include "media/cast/test/fake_task_runner.h" | |
7 #include "media/cast/video_receiver/video_decoder.h" | 14 #include "media/cast/video_receiver/video_decoder.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
9 | 16 |
10 namespace media { | 17 namespace media { |
11 namespace cast { | 18 namespace cast { |
12 | 19 |
13 using testing::_; | 20 using testing::_; |
14 | 21 |
15 // Random frame size for testing. | 22 // Random frame size for testing. |
16 const int kFrameSize = 2345; | 23 const int kFrameSize = 2345; |
24 static const int64 kStartMillisecond = GG_INT64_C(1245); | |
Alpha Left Google
2013/11/06 02:22:06
nit: This doesn't need to be static right?
mikhal
2013/11/06 18:29:16
Keeping for consistency - Static through out the c
| |
25 | |
26 class DecodeTestFrameCallback : | |
Alpha Left Google
2013/11/06 02:22:06
Put this in an anonymous namespace otherwise it mi
mikhal
2013/11/06 18:29:16
Done.
| |
27 public base::RefCountedThreadSafe<DecodeTestFrameCallback> { | |
28 public: | |
29 DecodeTestFrameCallback() {} | |
30 | |
31 void DecodeComplete(scoped_ptr<I420VideoFrame> decoded_frame, | |
32 const base::TimeTicks& render_time) {} | |
33 protected: | |
34 virtual ~DecodeTestFrameCallback() {} | |
35 private: | |
36 friend class base::RefCountedThreadSafe<DecodeTestFrameCallback>; | |
37 }; | |
17 | 38 |
18 class VideoDecoderTest : public ::testing::Test { | 39 class VideoDecoderTest : public ::testing::Test { |
19 protected: | 40 protected: |
20 VideoDecoderTest() { | 41 VideoDecoderTest() |
42 : task_runner_(new test::FakeTaskRunner(&testing_clock_)), | |
43 cast_environment_(new CastEnvironment(&testing_clock_, task_runner_, | |
44 task_runner_, task_runner_, task_runner_, task_runner_)), | |
45 test_callback_(new DecodeTestFrameCallback()) { | |
Alpha Left Google
2013/11/06 02:22:06
nit: indentation is incorrect.
mikhal
2013/11/06 18:29:16
Done.
| |
21 // Configure to vp8. | 46 // Configure to vp8. |
22 config_.codec = kVp8; | 47 config_.codec = kVp8; |
23 config_.use_external_decoder = false; | 48 config_.use_external_decoder = false; |
24 decoder_.reset(new VideoDecoder(config_)); | 49 decoder_.reset(new VideoDecoder(config_, cast_environment_)); |
50 testing_clock_.Advance( | |
51 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | |
25 } | 52 } |
26 | 53 |
27 virtual ~VideoDecoderTest() {} | 54 virtual ~VideoDecoderTest() {} |
28 | 55 |
29 scoped_ptr<VideoDecoder> decoder_; | 56 scoped_ptr<VideoDecoder> decoder_; |
30 VideoReceiverConfig config_; | 57 VideoReceiverConfig config_; |
58 base::SimpleTestTickClock testing_clock_; | |
59 scoped_refptr<test::FakeTaskRunner> task_runner_; | |
60 scoped_refptr<CastEnvironment> cast_environment_; | |
61 scoped_refptr<DecodeTestFrameCallback> test_callback_; | |
31 }; | 62 }; |
32 | 63 |
33 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. | 64 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. |
34 TEST_F(VideoDecoderTest, DISABLED_SizeZero) { | 65 TEST_F(VideoDecoderTest, DISABLED_SizeZero) { |
35 EncodedVideoFrame encoded_frame; | 66 EncodedVideoFrame encoded_frame; |
36 I420VideoFrame video_frame; | |
37 base::TimeTicks render_time; | 67 base::TimeTicks render_time; |
38 encoded_frame.codec = kVp8; | 68 encoded_frame.codec = kVp8; |
39 | 69 VideoFrameDecodedCallback frame_decoded_callback = |
70 base::Bind(&DecodeTestFrameCallback::DecodeComplete, test_callback_); | |
40 EXPECT_DEATH( | 71 EXPECT_DEATH( |
41 decoder_->DecodeVideoFrame(&encoded_frame, render_time, &video_frame), | 72 decoder_->DecodeVideoFrame(&encoded_frame, render_time, |
42 "Empty video frame"); | 73 frame_decoded_callback), "Empty video frame"); |
Alpha Left Google
2013/11/06 02:22:06
nit: indentation is incorrect, this should align w
| |
43 } | 74 } |
44 | 75 |
45 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. | 76 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind. |
46 TEST_F(VideoDecoderTest, DISABLED_InvalidCodec) { | 77 TEST_F(VideoDecoderTest, DISABLED_InvalidCodec) { |
47 EncodedVideoFrame encoded_frame; | 78 EncodedVideoFrame encoded_frame; |
48 I420VideoFrame video_frame; | |
49 base::TimeTicks render_time; | 79 base::TimeTicks render_time; |
50 encoded_frame.data.assign(kFrameSize, 0); | 80 encoded_frame.data.assign(kFrameSize, 0); |
51 encoded_frame.codec = kExternalVideo; | 81 encoded_frame.codec = kExternalVideo; |
82 VideoFrameDecodedCallback frame_decoded_callback = | |
83 base::Bind(&DecodeTestFrameCallback::DecodeComplete, test_callback_); | |
52 EXPECT_DEATH( | 84 EXPECT_DEATH( |
53 decoder_->DecodeVideoFrame(&encoded_frame, render_time, &video_frame), | 85 decoder_->DecodeVideoFrame(&encoded_frame, render_time, |
54 "Invalid codec"); | 86 frame_decoded_callback), "Invalid codec"); |
Alpha Left Google
2013/11/06 02:22:06
nit: indentation is incorrect, it should align wit
mikhal
2013/11/06 18:29:16
Done.
| |
55 } | 87 } |
56 | 88 |
57 // TODO(pwestin): Test decoding a real frame. | 89 // TODO(pwestin): Test decoding a real frame. |
58 | 90 |
59 } // namespace cast | 91 } // namespace cast |
60 } // namespace media | 92 } // namespace media |
OLD | NEW |