OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/timeutils.h" | 16 #include "webrtc/base/timeutils.h" |
17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 19 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
19 #include "webrtc/test/frame_utils.h" | 20 #include "webrtc/test/frame_utils.h" |
20 #include "webrtc/test/gtest.h" | 21 #include "webrtc/test/gtest.h" |
21 #include "webrtc/test/testsupport/fileutils.h" | 22 #include "webrtc/test/testsupport/fileutils.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 | 25 |
25 namespace { | 26 namespace { |
26 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { | 27 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { |
27 *stride_y = 16 * ((width + 15) / 16); | 28 *stride_y = 16 * ((width + 15) / 16); |
28 *stride_uv = 16 * ((width + 31) / 32); | 29 *stride_uv = 16 * ((width + 31) / 32); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 input_frame_.reset( | 155 input_frame_.reset( |
155 new VideoFrame(stride_buffer, kVideoRotation_0, 0)); | 156 new VideoFrame(stride_buffer, kVideoRotation_0, 0)); |
156 input_frame_->set_timestamp(kTestTimestamp); | 157 input_frame_->set_timestamp(kTestTimestamp); |
157 } | 158 } |
158 | 159 |
159 void SetUpEncodeDecode() { | 160 void SetUpEncodeDecode() { |
160 codec_inst_.startBitrate = 300; | 161 codec_inst_.startBitrate = 300; |
161 codec_inst_.maxBitrate = 4000; | 162 codec_inst_.maxBitrate = 4000; |
162 codec_inst_.qpMax = 56; | 163 codec_inst_.qpMax = 56; |
163 codec_inst_.codecSpecific.VP8.denoisingOn = true; | 164 codec_inst_.codecSpecific.VP8.denoisingOn = true; |
| 165 codec_inst_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 166 codec_inst_.codecSpecific.VP8.numberOfTemporalLayers = 1; |
164 | 167 |
165 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 168 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
166 encoder_->InitEncode(&codec_inst_, 1, 1440)); | 169 encoder_->InitEncode(&codec_inst_, 1, 1440)); |
167 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); | 170 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); |
168 } | 171 } |
169 | 172 |
170 size_t WaitForEncodedFrame() const { | 173 size_t WaitForEncodedFrame() const { |
171 int64_t startTime = rtc::TimeMillis(); | 174 int64_t startTime = rtc::TimeMillis(); |
172 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { | 175 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { |
173 if (encode_complete_callback_->EncodeComplete()) { | 176 if (encode_complete_callback_->EncodeComplete()) { |
(...skipping 20 matching lines...) Expand all Loading... |
194 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; | 197 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; |
195 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; | 198 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; |
196 std::unique_ptr<uint8_t[]> source_buffer_; | 199 std::unique_ptr<uint8_t[]> source_buffer_; |
197 FILE* source_file_; | 200 FILE* source_file_; |
198 std::unique_ptr<VideoFrame> input_frame_; | 201 std::unique_ptr<VideoFrame> input_frame_; |
199 std::unique_ptr<VideoEncoder> encoder_; | 202 std::unique_ptr<VideoEncoder> encoder_; |
200 std::unique_ptr<VideoDecoder> decoder_; | 203 std::unique_ptr<VideoDecoder> decoder_; |
201 EncodedImage encoded_frame_; | 204 EncodedImage encoded_frame_; |
202 VideoFrame decoded_frame_; | 205 VideoFrame decoded_frame_; |
203 VideoCodec codec_inst_; | 206 VideoCodec codec_inst_; |
| 207 TemporalLayersFactory tl_factory_; |
204 }; | 208 }; |
205 | 209 |
206 TEST_F(TestVp8Impl, EncoderParameterTest) { | 210 TEST_F(TestVp8Impl, EncoderParameterTest) { |
207 strncpy(codec_inst_.plName, "VP8", 31); | 211 strncpy(codec_inst_.plName, "VP8", 31); |
208 codec_inst_.plType = 126; | 212 codec_inst_.plType = 126; |
209 codec_inst_.maxBitrate = 0; | 213 codec_inst_.maxBitrate = 0; |
210 codec_inst_.minBitrate = 0; | 214 codec_inst_.minBitrate = 0; |
211 codec_inst_.width = 1440; | 215 codec_inst_.width = 1440; |
212 codec_inst_.height = 1080; | 216 codec_inst_.height = 1080; |
213 codec_inst_.maxFramerate = 30; | 217 codec_inst_.maxFramerate = 30; |
214 codec_inst_.startBitrate = 300; | 218 codec_inst_.startBitrate = 300; |
215 codec_inst_.qpMax = 56; | 219 codec_inst_.qpMax = 56; |
216 codec_inst_.codecSpecific.VP8.complexity = kComplexityNormal; | 220 codec_inst_.codecSpecific.VP8.complexity = kComplexityNormal; |
217 codec_inst_.codecSpecific.VP8.numberOfTemporalLayers = 1; | 221 codec_inst_.codecSpecific.VP8.numberOfTemporalLayers = 1; |
| 222 codec_inst_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 223 |
218 // Calls before InitEncode(). | 224 // Calls before InitEncode(). |
219 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | 225 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
220 int bit_rate = 300; | 226 int bit_rate = 300; |
| 227 BitrateAllocation bitrate_allocation; |
| 228 bitrate_allocation.SetBitrate(0, 0, bit_rate * 1000); |
221 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | 229 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
222 encoder_->SetRates(bit_rate, codec_inst_.maxFramerate)); | 230 encoder_->SetRateAllocation(bitrate_allocation, |
| 231 codec_inst_.maxFramerate)); |
223 | 232 |
224 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); | 233 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); |
225 | 234 |
226 // Decoder parameter tests. | 235 // Decoder parameter tests. |
227 // Calls before InitDecode(). | 236 // Calls before InitDecode(). |
228 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 237 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
229 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); | 238 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); |
230 } | 239 } |
231 | 240 |
232 #if defined(WEBRTC_ANDROID) | 241 #if defined(WEBRTC_ANDROID) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 278 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
270 decoder_->Decode(encoded_frame_, false, NULL)); | 279 decoder_->Decode(encoded_frame_, false, NULL)); |
271 // Now setting a key frame. | 280 // Now setting a key frame. |
272 encoded_frame_._frameType = kVideoFrameKey; | 281 encoded_frame_._frameType = kVideoFrameKey; |
273 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 282 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
274 decoder_->Decode(encoded_frame_, false, NULL)); | 283 decoder_->Decode(encoded_frame_, false, NULL)); |
275 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); | 284 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); |
276 } | 285 } |
277 | 286 |
278 } // namespace webrtc | 287 } // namespace webrtc |
OLD | NEW |