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/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "content/renderer/media/rtc_video_decoder.h" | 9 #include "content/renderer/media/rtc_video_decoder.h" |
10 #include "media/base/gmock_callback_support.h" | 10 #include "media/base/gmock_callback_support.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 EXPECT_CALL(*mock_gpu_factories_, GetTaskRunner()) | 38 EXPECT_CALL(*mock_gpu_factories_, GetTaskRunner()) |
39 .WillRepeatedly(Return(vda_task_runner_)); | 39 .WillRepeatedly(Return(vda_task_runner_)); |
40 EXPECT_CALL(*mock_gpu_factories_, DoCreateVideoDecodeAccelerator()) | 40 EXPECT_CALL(*mock_gpu_factories_, DoCreateVideoDecodeAccelerator()) |
41 .WillRepeatedly(Return(mock_vda_)); | 41 .WillRepeatedly(Return(mock_vda_)); |
42 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) | 42 EXPECT_CALL(*mock_gpu_factories_, CreateSharedMemory(_)) |
43 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); | 43 .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL))); |
44 EXPECT_CALL(*mock_vda_, Initialize(_, _)) | 44 EXPECT_CALL(*mock_vda_, Initialize(_, _)) |
45 .Times(1) | 45 .Times(1) |
46 .WillRepeatedly(Return(true)); | 46 .WillRepeatedly(Return(true)); |
47 EXPECT_CALL(*mock_vda_, Destroy()).Times(1); | 47 EXPECT_CALL(*mock_vda_, Destroy()).Times(1); |
48 rtc_decoder_ = | |
49 RTCVideoDecoder::Create(webrtc::kVideoCodecVP8, mock_gpu_factories_); | |
50 } | 48 } |
51 | 49 |
52 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() OVERRIDE { |
53 VLOG(2) << "TearDown"; | 51 VLOG(2) << "TearDown"; |
54 EXPECT_TRUE(vda_thread_.IsRunning()); | 52 EXPECT_TRUE(vda_thread_.IsRunning()); |
55 RunUntilIdle(); // Wait until all callbascks complete. | 53 RunUntilIdle(); // Wait until all callbascks complete. |
56 vda_task_runner_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); | 54 vda_task_runner_->DeleteSoon(FROM_HERE, rtc_decoder_.release()); |
57 // Make sure the decoder is released before stopping the thread. | 55 // Make sure the decoder is released before stopping the thread. |
58 RunUntilIdle(); | 56 RunUntilIdle(); |
59 vda_thread_.Stop(); | 57 vda_thread_.Stop(); |
60 } | 58 } |
61 | 59 |
62 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE { | 60 virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE { |
63 VLOG(2) << "Decoded"; | 61 VLOG(2) << "Decoded"; |
64 EXPECT_EQ(vda_task_runner_, base::MessageLoopProxy::current()); | 62 EXPECT_EQ(vda_task_runner_, base::MessageLoopProxy::current()); |
65 return WEBRTC_VIDEO_CODEC_OK; | 63 return WEBRTC_VIDEO_CODEC_OK; |
66 } | 64 } |
67 | 65 |
| 66 void CreateDecoder(webrtc::VideoCodecType codec_type) { |
| 67 VLOG(2) << "CreateDecoder"; |
| 68 codec_.codecType = codec_type; |
| 69 rtc_decoder_ = |
| 70 RTCVideoDecoder::Create(codec_type, mock_gpu_factories_); |
| 71 } |
| 72 |
68 void Initialize() { | 73 void Initialize() { |
69 VLOG(2) << "Initialize"; | 74 VLOG(2) << "Initialize"; |
70 codec_.codecType = webrtc::kVideoCodecVP8; | |
71 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1)); | 75 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1)); |
72 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 76 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
73 rtc_decoder_->RegisterDecodeCompleteCallback(this)); | 77 rtc_decoder_->RegisterDecodeCompleteCallback(this)); |
74 } | 78 } |
75 | 79 |
76 void NotifyResetDone() { | 80 void NotifyResetDone() { |
77 VLOG(2) << "NotifyResetDone"; | 81 VLOG(2) << "NotifyResetDone"; |
78 vda_task_runner_->PostTask( | 82 vda_task_runner_->PostTask( |
79 FROM_HERE, | 83 FROM_HERE, |
80 base::Bind(&RTCVideoDecoder::NotifyResetDone, | 84 base::Bind(&RTCVideoDecoder::NotifyResetDone, |
(...skipping 16 matching lines...) Expand all Loading... |
97 base::Thread vda_thread_; | 101 base::Thread vda_thread_; |
98 | 102 |
99 private: | 103 private: |
100 scoped_refptr<base::SingleThreadTaskRunner> vda_task_runner_; | 104 scoped_refptr<base::SingleThreadTaskRunner> vda_task_runner_; |
101 | 105 |
102 base::Lock lock_; | 106 base::Lock lock_; |
103 base::WaitableEvent idle_waiter_; | 107 base::WaitableEvent idle_waiter_; |
104 }; | 108 }; |
105 | 109 |
106 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) { | 110 TEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) { |
| 111 CreateDecoder(webrtc::kVideoCodecVP8); |
107 scoped_ptr<RTCVideoDecoder> null_rtc_decoder( | 112 scoped_ptr<RTCVideoDecoder> null_rtc_decoder( |
108 RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_)); | 113 RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_)); |
109 EXPECT_EQ(NULL, null_rtc_decoder.get()); | 114 EXPECT_EQ(NULL, null_rtc_decoder.get()); |
110 } | 115 } |
111 | 116 |
| 117 TEST_F(RTCVideoDecoderTest, CreateAndInitSucceedsForH264Codec) { |
| 118 CreateDecoder(webrtc::kVideoCodecH264); |
| 119 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1)); |
| 120 } |
| 121 |
112 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { | 122 TEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) { |
113 codec_.codecType = webrtc::kVideoCodecVP8; | 123 CreateDecoder(webrtc::kVideoCodecVP8); |
114 codec_.codecSpecific.VP8.feedbackModeOn = true; | 124 codec_.codecSpecific.VP8.feedbackModeOn = true; |
115 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); | 125 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1)); |
116 } | 126 } |
117 | 127 |
118 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { | 128 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) { |
| 129 CreateDecoder(webrtc::kVideoCodecVP8); |
119 webrtc::EncodedImage input_image; | 130 webrtc::EncodedImage input_image; |
120 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | 131 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
121 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); | 132 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); |
122 } | 133 } |
123 | 134 |
124 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnIncompleteFrame) { | 135 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnIncompleteFrame) { |
| 136 CreateDecoder(webrtc::kVideoCodecVP8); |
125 Initialize(); | 137 Initialize(); |
126 webrtc::EncodedImage input_image; | 138 webrtc::EncodedImage input_image; |
127 input_image._completeFrame = false; | 139 input_image._completeFrame = false; |
128 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 140 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
129 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); | 141 rtc_decoder_->Decode(input_image, false, NULL, NULL, 0)); |
130 } | 142 } |
131 | 143 |
132 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnMissingFrames) { | 144 TEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnMissingFrames) { |
| 145 CreateDecoder(webrtc::kVideoCodecVP8); |
133 Initialize(); | 146 Initialize(); |
134 webrtc::EncodedImage input_image; | 147 webrtc::EncodedImage input_image; |
135 input_image._completeFrame = true; | 148 input_image._completeFrame = true; |
136 bool missingFrames = true; | 149 bool missingFrames = true; |
137 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 150 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
138 rtc_decoder_->Decode(input_image, missingFrames, NULL, NULL, 0)); | 151 rtc_decoder_->Decode(input_image, missingFrames, NULL, NULL, 0)); |
139 } | 152 } |
140 | 153 |
141 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { | 154 TEST_F(RTCVideoDecoderTest, ResetReturnsOk) { |
| 155 CreateDecoder(webrtc::kVideoCodecVP8); |
142 Initialize(); | 156 Initialize(); |
143 EXPECT_CALL(*mock_vda_, Reset()) | 157 EXPECT_CALL(*mock_vda_, Reset()) |
144 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | 158 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); |
145 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); | 159 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset()); |
146 } | 160 } |
147 | 161 |
148 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { | 162 TEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) { |
| 163 CreateDecoder(webrtc::kVideoCodecVP8); |
149 Initialize(); | 164 Initialize(); |
150 EXPECT_CALL(*mock_vda_, Reset()) | 165 EXPECT_CALL(*mock_vda_, Reset()) |
151 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | 166 .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); |
152 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | 167 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); |
153 } | 168 } |
154 | 169 |
155 TEST_F(RTCVideoDecoderTest, InitDecodeAfterRelease) { | 170 TEST_F(RTCVideoDecoderTest, InitDecodeAfterRelease) { |
| 171 CreateDecoder(webrtc::kVideoCodecVP8); |
156 EXPECT_CALL(*mock_vda_, Reset()) | 172 EXPECT_CALL(*mock_vda_, Reset()) |
157 .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); | 173 .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone)); |
158 Initialize(); | 174 Initialize(); |
159 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | 175 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); |
160 Initialize(); | 176 Initialize(); |
161 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); | 177 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release()); |
162 } | 178 } |
163 | 179 |
164 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { | 180 TEST_F(RTCVideoDecoderTest, IsBufferAfterReset) { |
| 181 CreateDecoder(webrtc::kVideoCodecVP8); |
165 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); | 182 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); |
166 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 183 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
167 RTCVideoDecoder::ID_INVALID)); | 184 RTCVideoDecoder::ID_INVALID)); |
168 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, | 185 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2, |
169 RTCVideoDecoder::ID_HALF + 2)); | 186 RTCVideoDecoder::ID_HALF + 2)); |
170 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2, | 187 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2, |
171 RTCVideoDecoder::ID_HALF - 2)); | 188 RTCVideoDecoder::ID_HALF - 2)); |
172 | 189 |
173 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0)); | 190 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0)); |
174 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); | 191 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); |
175 EXPECT_FALSE( | 192 EXPECT_FALSE( |
176 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF - 2)); | 193 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF - 2)); |
177 EXPECT_TRUE( | 194 EXPECT_TRUE( |
178 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF + 2)); | 195 rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF + 2)); |
179 | 196 |
180 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); | 197 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0)); |
181 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 198 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
182 RTCVideoDecoder::ID_HALF - 2)); | 199 RTCVideoDecoder::ID_HALF - 2)); |
183 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 200 EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
184 RTCVideoDecoder::ID_HALF + 2)); | 201 RTCVideoDecoder::ID_HALF + 2)); |
185 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, | 202 EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, |
186 RTCVideoDecoder::ID_LAST)); | 203 RTCVideoDecoder::ID_LAST)); |
187 } | 204 } |
188 | 205 |
189 TEST_F(RTCVideoDecoderTest, IsFirstBufferAfterReset) { | 206 TEST_F(RTCVideoDecoderTest, IsFirstBufferAfterReset) { |
| 207 CreateDecoder(webrtc::kVideoCodecVP8); |
190 EXPECT_TRUE( | 208 EXPECT_TRUE( |
191 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); | 209 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_INVALID)); |
192 EXPECT_FALSE( | 210 EXPECT_FALSE( |
193 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_INVALID)); | 211 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_INVALID)); |
194 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(0, 0)); | 212 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(0, 0)); |
195 EXPECT_TRUE(rtc_decoder_->IsFirstBufferAfterReset(1, 0)); | 213 EXPECT_TRUE(rtc_decoder_->IsFirstBufferAfterReset(1, 0)); |
196 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(2, 0)); | 214 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(2, 0)); |
197 | 215 |
198 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_HALF, | 216 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_HALF, |
199 RTCVideoDecoder::ID_HALF)); | 217 RTCVideoDecoder::ID_HALF)); |
200 EXPECT_TRUE(rtc_decoder_->IsFirstBufferAfterReset( | 218 EXPECT_TRUE(rtc_decoder_->IsFirstBufferAfterReset( |
201 RTCVideoDecoder::ID_HALF + 1, RTCVideoDecoder::ID_HALF)); | 219 RTCVideoDecoder::ID_HALF + 1, RTCVideoDecoder::ID_HALF)); |
202 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset( | 220 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset( |
203 RTCVideoDecoder::ID_HALF + 2, RTCVideoDecoder::ID_HALF)); | 221 RTCVideoDecoder::ID_HALF + 2, RTCVideoDecoder::ID_HALF)); |
204 | 222 |
205 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST, | 223 EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST, |
206 RTCVideoDecoder::ID_LAST)); | 224 RTCVideoDecoder::ID_LAST)); |
207 EXPECT_TRUE( | 225 EXPECT_TRUE( |
208 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); | 226 rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST)); |
209 EXPECT_FALSE( | 227 EXPECT_FALSE( |
210 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST)); | 228 rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST)); |
211 } | 229 } |
212 | 230 |
213 } // content | 231 } // content |
OLD | NEW |