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" | |
20 #include "webrtc/test/frame_utils.h" | 19 #include "webrtc/test/frame_utils.h" |
21 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
22 #include "webrtc/test/testsupport/fileutils.h" | 21 #include "webrtc/test/testsupport/fileutils.h" |
23 | 22 |
24 namespace webrtc { | 23 namespace webrtc { |
25 | 24 |
26 namespace { | 25 namespace { |
27 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { | 26 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { |
28 *stride_y = 16 * ((width + 15) / 16); | 27 *stride_y = 16 * ((width + 15) / 16); |
29 *stride_uv = 16 * ((width + 31) / 32); | 28 *stride_uv = 16 * ((width + 31) / 32); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 input_frame_.reset( | 154 input_frame_.reset( |
156 new VideoFrame(stride_buffer, kVideoRotation_0, 0)); | 155 new VideoFrame(stride_buffer, kVideoRotation_0, 0)); |
157 input_frame_->set_timestamp(kTestTimestamp); | 156 input_frame_->set_timestamp(kTestTimestamp); |
158 } | 157 } |
159 | 158 |
160 void SetUpEncodeDecode() { | 159 void SetUpEncodeDecode() { |
161 codec_inst_.startBitrate = 300; | 160 codec_inst_.startBitrate = 300; |
162 codec_inst_.maxBitrate = 4000; | 161 codec_inst_.maxBitrate = 4000; |
163 codec_inst_.qpMax = 56; | 162 codec_inst_.qpMax = 56; |
164 codec_inst_.VP8()->denoisingOn = true; | 163 codec_inst_.VP8()->denoisingOn = true; |
165 codec_inst_.VP8()->tl_factory = &tl_factory_; | |
166 codec_inst_.VP8()->numberOfTemporalLayers = 1; | |
167 | 164 |
168 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 165 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
169 encoder_->InitEncode(&codec_inst_, 1, 1440)); | 166 encoder_->InitEncode(&codec_inst_, 1, 1440)); |
170 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); | 167 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); |
171 } | 168 } |
172 | 169 |
173 size_t WaitForEncodedFrame() const { | 170 size_t WaitForEncodedFrame() const { |
174 int64_t startTime = rtc::TimeMillis(); | 171 int64_t startTime = rtc::TimeMillis(); |
175 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { | 172 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { |
176 if (encode_complete_callback_->EncodeComplete()) { | 173 if (encode_complete_callback_->EncodeComplete()) { |
(...skipping 20 matching lines...) Expand all Loading... |
197 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; | 194 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; |
198 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; | 195 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; |
199 std::unique_ptr<uint8_t[]> source_buffer_; | 196 std::unique_ptr<uint8_t[]> source_buffer_; |
200 FILE* source_file_; | 197 FILE* source_file_; |
201 std::unique_ptr<VideoFrame> input_frame_; | 198 std::unique_ptr<VideoFrame> input_frame_; |
202 std::unique_ptr<VideoEncoder> encoder_; | 199 std::unique_ptr<VideoEncoder> encoder_; |
203 std::unique_ptr<VideoDecoder> decoder_; | 200 std::unique_ptr<VideoDecoder> decoder_; |
204 EncodedImage encoded_frame_; | 201 EncodedImage encoded_frame_; |
205 VideoFrame decoded_frame_; | 202 VideoFrame decoded_frame_; |
206 VideoCodec codec_inst_; | 203 VideoCodec codec_inst_; |
207 TemporalLayersFactory tl_factory_; | |
208 }; | 204 }; |
209 | 205 |
210 TEST_F(TestVp8Impl, EncoderParameterTest) { | 206 TEST_F(TestVp8Impl, EncoderParameterTest) { |
211 strncpy(codec_inst_.plName, "VP8", 31); | 207 strncpy(codec_inst_.plName, "VP8", 31); |
212 codec_inst_.plType = 126; | 208 codec_inst_.plType = 126; |
213 codec_inst_.maxBitrate = 0; | 209 codec_inst_.maxBitrate = 0; |
214 codec_inst_.minBitrate = 0; | 210 codec_inst_.minBitrate = 0; |
215 codec_inst_.width = 1440; | 211 codec_inst_.width = 1440; |
216 codec_inst_.height = 1080; | 212 codec_inst_.height = 1080; |
217 codec_inst_.maxFramerate = 30; | 213 codec_inst_.maxFramerate = 30; |
218 codec_inst_.startBitrate = 300; | 214 codec_inst_.startBitrate = 300; |
219 codec_inst_.qpMax = 56; | 215 codec_inst_.qpMax = 56; |
220 codec_inst_.VP8()->complexity = kComplexityNormal; | 216 codec_inst_.VP8()->complexity = kComplexityNormal; |
221 codec_inst_.VP8()->numberOfTemporalLayers = 1; | 217 codec_inst_.VP8()->numberOfTemporalLayers = 1; |
222 codec_inst_.VP8()->tl_factory = &tl_factory_; | |
223 // Calls before InitEncode(). | 218 // Calls before InitEncode(). |
224 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | 219 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
225 int bit_rate = 300; | 220 int bit_rate = 300; |
226 BitrateAllocation bitrate_allocation; | |
227 bitrate_allocation.SetBitrate(0, 0, bit_rate * 1000); | |
228 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | 221 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
229 encoder_->SetRateAllocation(bitrate_allocation, | 222 encoder_->SetRates(bit_rate, codec_inst_.maxFramerate)); |
230 codec_inst_.maxFramerate)); | |
231 | 223 |
232 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); | 224 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); |
233 | 225 |
234 // Decoder parameter tests. | 226 // Decoder parameter tests. |
235 // Calls before InitDecode(). | 227 // Calls before InitDecode(). |
236 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 228 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
237 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); | 229 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); |
238 } | 230 } |
239 | 231 |
240 #if defined(WEBRTC_ANDROID) | 232 #if defined(WEBRTC_ANDROID) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 269 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
278 decoder_->Decode(encoded_frame_, false, NULL)); | 270 decoder_->Decode(encoded_frame_, false, NULL)); |
279 // Now setting a key frame. | 271 // Now setting a key frame. |
280 encoded_frame_._frameType = kVideoFrameKey; | 272 encoded_frame_._frameType = kVideoFrameKey; |
281 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 273 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
282 decoder_->Decode(encoded_frame_, false, NULL)); | 274 decoder_->Decode(encoded_frame_, false, NULL)); |
283 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); | 275 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); |
284 } | 276 } |
285 | 277 |
286 } // namespace webrtc | 278 } // namespace webrtc |
OLD | NEW |