OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/bind.h" | |
6 #include "base/message_loop.h" | |
7 #include "base/synchronization/waitable_event.h" | |
8 #include "base/threading/thread.h" | |
9 #include "content/renderer/media/rtc_video_decoder.h" | |
10 #include "media/base/gmock_callback_support.h" | |
11 #include "media/filters/gpu_video_decoder.h" | |
12 #include "media/filters/mock_gpu_video_decoder_factories.h" | |
13 #include "media/video/mock_video_decode_accelerator.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 using ::testing::_; | |
17 using ::testing::Invoke; | |
18 using ::testing::Return; | |
19 using ::testing::SaveArg; | |
20 using ::testing::WithArgs; | |
21 | |
22 namespace content { | |
23 | |
24 class RTCVideoDecoderTest | |
25 : public ::testing::Test, | |
26 webrtc::DecodedImageCallback { | |
27 public: | |
28 RTCVideoDecoderTest() | |
29 : mock_gpu_factories_(new media::MockGpuVideoDecoderFactories), | |
30 num_delivered_frames_(0), | |
31 vda_thread_("vda_thread"), | |
32 idle_waiter_(false,false) { | |
Pawel Osciak
2013/06/12 23:38:22
s/,/, /
wuchengli
2013/06/13 10:28:07
Done.
| |
33 memset(&codec_, 0, sizeof(codec_)); | |
34 } | |
35 | |
36 virtual void SetUp() OVERRIDE { | |
37 ASSERT_TRUE(vda_thread_.Start()); | |
38 vda_loop_proxy_ = vda_thread_.message_loop_proxy(); | |
39 EXPECT_CALL(*mock_gpu_factories_, GetMessageLoop()) | |
40 .WillOnce(Return(vda_loop_proxy_)); | |
41 rtc_decoder_.reset(new RTCVideoDecoder(mock_gpu_factories_)); | |
42 } | |
43 | |
44 virtual void TearDown() OVERRIDE { | |
45 vda_thread_.Stop(); | |
46 } | |
47 | |
48 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) | |
49 OVERRIDE { | |
50 EXPECT_EQ(vda_loop_proxy_, base::MessageLoopProxy::current()); | |
51 VLOG(2) << "Decoded"; | |
52 ++num_delivered_frames_; | |
53 return WEBRTC_VIDEO_CODEC_OK; | |
54 } | |
55 | |
56 void Initialize() { | |
57 VLOG(2) << "Initialize"; | |
58 mock_vda_ = new media::MockVideoDecodeAccelerator; | |
59 EXPECT_CALL( | |
60 *mock_gpu_factories_, | |
61 CreateVideoDecodeAccelerator(media::VP8PROFILE_MAIN, _)) | |
62 .WillOnce(Return(mock_vda_)); | |
63 codec_.codecType = webrtc::kVideoCodecVP8; | |
64 EXPECT_EQ(true, rtc_decoder_->Initialize(codec_.codecType)); | |
65 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1)); | |
66 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
67 rtc_decoder_->RegisterDecodeCompleteCallback(this)); | |
68 } | |
69 | |
70 void NotifyResetDone() { | |
71 VLOG(2) << "NotifyResetDone"; | |
72 vda_loop_proxy_->PostTask( | |
73 FROM_HERE, | |
74 base::Bind(&RTCVideoDecoder::NotifyResetDone, | |
75 base::Unretained(rtc_decoder_.get()))); | |
76 } | |
77 | |
78 void RunUntilIdle() { | |
79 vda_loop_proxy_->PostTask( | |
80 FROM_HERE, | |
81 base::Bind(&RTCVideoDecoderTest::NotifyIdle, base::Unretained(this))); | |
82 idle_waiter_.Wait(); | |
83 } | |
84 | |
85 void NotifyIdle() { | |
86 idle_waiter_.Signal(); | |
87 } | |
88 | |
89 protected: | |
90 media::MockGpuVideoDecoderFactories* mock_gpu_factories_; | |
91 media::MockVideoDecodeAccelerator* mock_vda_; | |
Ami GONE FROM CHROMIUM
2013/06/11 23:48:05
scoped_ptr for this and the previous?
wuchengli
2013/06/13 10:28:07
RTCVideoDecoder takes the ownership but the test s
| |
92 scoped_ptr<RTCVideoDecoder> rtc_decoder_; | |
93 webrtc::VideoCodec codec_; | |
94 int num_delivered_frames_; | |
95 | |
96 private: | |
97 scoped_refptr<base::MessageLoopProxy> vda_loop_proxy_; | |
98 base::Thread vda_thread_; | |
99 | |
100 base::Lock lock_; | |
101 base::WaitableEvent idle_waiter_; | |
102 }; | |
103 | |
104 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { | |
105 codec_.codecType = webrtc::kVideoCodecVP8; | |
106 codec_.codecSpecific.VP8.feedbackModeOn = true; | |
107 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); | |
108 } | |
109 | |
110 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { | |
111 webrtc::EncodedImage input_image; | |
112 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | |
113 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); | |
114 } | |
115 | |
116 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnIncompleteFrame) { | |
117 Initialize(); | |
118 webrtc::EncodedImage input_image; | |
119 input_image._completeFrame = false; | |
120 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | |
121 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); | |
122 } | |
123 | |
124 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnMissingFrames) { | |
125 Initialize(); | |
126 webrtc::EncodedImage input_image; | |
127 input_image._completeFrame = true; | |
128 bool missingFrames = true; | |
129 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | |
130 rtc_decoder_->Decode(input_image, missingFrames, NULL, NULL, 0)); | |
131 } | |
132 | |
133 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { | |
134 Initialize(); | |
135 EXPECT_CALL(*mock_vda_, Reset()) | |
136 .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | |
137 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); | |
138 } | |
139 | |
140 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { | |
141 Initialize(); | |
142 EXPECT_CALL(*mock_vda_, Destroy()); | |
143 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | |
144 } | |
145 | |
146 } // content | |
OLD | NEW |