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 "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/timeutils.h" | 17 #include "webrtc/base/timeutils.h" |
18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
19 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 19 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 20 #include "webrtc/test/frame_utils.h" |
20 #include "webrtc/test/testsupport/fileutils.h" | 21 #include "webrtc/test/testsupport/fileutils.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 namespace { | 25 namespace { |
25 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { | 26 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { |
26 *stride_y = 16 * ((width + 15) / 16); | 27 *stride_y = 16 * ((width + 15) / 16); |
27 *stride_uv = 16 * ((width + 31) / 32); | 28 *stride_uv = 16 * ((width + 31) / 32); |
28 } | 29 } |
29 | 30 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 decoder_.reset(VP8Decoder::Create()); | 122 decoder_.reset(VP8Decoder::Create()); |
122 memset(&codec_inst_, 0, sizeof(codec_inst_)); | 123 memset(&codec_inst_, 0, sizeof(codec_inst_)); |
123 encode_complete_callback_.reset( | 124 encode_complete_callback_.reset( |
124 new Vp8UnitTestEncodeCompleteCallback(&encoded_frame_, 0, NULL)); | 125 new Vp8UnitTestEncodeCompleteCallback(&encoded_frame_, 0, NULL)); |
125 decode_complete_callback_.reset( | 126 decode_complete_callback_.reset( |
126 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_)); | 127 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_)); |
127 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); | 128 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); |
128 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); | 129 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); |
129 // Using a QCIF image (aligned stride (u,v planes) > width). | 130 // Using a QCIF image (aligned stride (u,v planes) > width). |
130 // Processing only one frame. | 131 // Processing only one frame. |
131 length_source_frame_ = CalcBufferSize(kI420, kWidth, kHeight); | |
132 source_buffer_.reset(new uint8_t[length_source_frame_]); | |
133 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); | 132 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); |
134 ASSERT_TRUE(source_file_ != NULL); | 133 ASSERT_TRUE(source_file_ != NULL); |
135 // Set input frame. | 134 rtc::scoped_refptr<VideoFrameBuffer> compact_buffer( |
136 ASSERT_EQ( | 135 test::ReadI420Buffer(kWidth, kHeight, source_file_)); |
137 fread(source_buffer_.get(), 1, length_source_frame_, source_file_), | 136 ASSERT_TRUE(compact_buffer); |
138 length_source_frame_); | |
139 codec_inst_.width = kWidth; | 137 codec_inst_.width = kWidth; |
140 codec_inst_.height = kHeight; | 138 codec_inst_.height = kHeight; |
141 const int kFramerate = 30; | 139 const int kFramerate = 30; |
142 codec_inst_.maxFramerate = kFramerate; | 140 codec_inst_.maxFramerate = kFramerate; |
143 // Setting aligned stride values. | 141 // Setting aligned stride values. |
144 int stride_uv; | 142 int stride_uv; |
145 int stride_y; | 143 int stride_y; |
146 Calc16ByteAlignedStride(codec_inst_.width, &stride_y, &stride_uv); | 144 Calc16ByteAlignedStride(codec_inst_.width, &stride_y, &stride_uv); |
147 EXPECT_EQ(stride_y, 176); | 145 EXPECT_EQ(stride_y, 176); |
148 EXPECT_EQ(stride_uv, 96); | 146 EXPECT_EQ(stride_uv, 96); |
149 | 147 |
150 input_frame_.CreateEmptyFrame(codec_inst_.width, codec_inst_.height, | 148 rtc::scoped_refptr<I420Buffer> stride_buffer( |
151 stride_y, stride_uv, stride_uv); | 149 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); |
152 input_frame_.set_timestamp(kTestTimestamp); | 150 |
153 // Using ConvertToI420 to add stride to the image. | 151 // No scaling in out case, just a copy, to add stride to the image. |
154 EXPECT_EQ(0, ConvertToI420(kI420, source_buffer_.get(), 0, 0, | 152 stride_buffer->ScaleFrom(compact_buffer); |
155 codec_inst_.width, codec_inst_.height, 0, | 153 |
156 kVideoRotation_0, &input_frame_)); | 154 input_frame_.reset( |
| 155 new VideoFrame(compact_buffer, kVideoRotation_0, 0)); |
| 156 input_frame_->set_timestamp(kTestTimestamp); |
157 } | 157 } |
158 | 158 |
159 void SetUpEncodeDecode() { | 159 void SetUpEncodeDecode() { |
160 codec_inst_.startBitrate = 300; | 160 codec_inst_.startBitrate = 300; |
161 codec_inst_.maxBitrate = 4000; | 161 codec_inst_.maxBitrate = 4000; |
162 codec_inst_.qpMax = 56; | 162 codec_inst_.qpMax = 56; |
163 codec_inst_.codecSpecific.VP8.denoisingOn = true; | 163 codec_inst_.codecSpecific.VP8.denoisingOn = true; |
164 | 164 |
165 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 165 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
166 encoder_->InitEncode(&codec_inst_, 1, 1440)); | 166 encoder_->InitEncode(&codec_inst_, 1, 1440)); |
(...skipping 21 matching lines...) Expand all Loading... |
188 return 0; | 188 return 0; |
189 } | 189 } |
190 | 190 |
191 const int kWidth = 172; | 191 const int kWidth = 172; |
192 const int kHeight = 144; | 192 const int kHeight = 144; |
193 | 193 |
194 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; | 194 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; |
195 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; | 195 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; |
196 std::unique_ptr<uint8_t[]> source_buffer_; | 196 std::unique_ptr<uint8_t[]> source_buffer_; |
197 FILE* source_file_; | 197 FILE* source_file_; |
198 VideoFrame input_frame_; | 198 std::unique_ptr<VideoFrame> input_frame_; |
199 std::unique_ptr<VideoEncoder> encoder_; | 199 std::unique_ptr<VideoEncoder> encoder_; |
200 std::unique_ptr<VideoDecoder> decoder_; | 200 std::unique_ptr<VideoDecoder> decoder_; |
201 EncodedImage encoded_frame_; | 201 EncodedImage encoded_frame_; |
202 VideoFrame decoded_frame_; | 202 VideoFrame decoded_frame_; |
203 size_t length_source_frame_; | |
204 VideoCodec codec_inst_; | 203 VideoCodec codec_inst_; |
205 }; | 204 }; |
206 | 205 |
207 TEST_F(TestVp8Impl, EncoderParameterTest) { | 206 TEST_F(TestVp8Impl, EncoderParameterTest) { |
208 strncpy(codec_inst_.plName, "VP8", 31); | 207 strncpy(codec_inst_.plName, "VP8", 31); |
209 codec_inst_.plType = 126; | 208 codec_inst_.plType = 126; |
210 codec_inst_.maxBitrate = 0; | 209 codec_inst_.maxBitrate = 0; |
211 codec_inst_.minBitrate = 0; | 210 codec_inst_.minBitrate = 0; |
212 codec_inst_.width = 1440; | 211 codec_inst_.width = 1440; |
213 codec_inst_.height = 1080; | 212 codec_inst_.height = 1080; |
(...skipping 16 matching lines...) Expand all Loading... |
230 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); | 229 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); |
231 } | 230 } |
232 | 231 |
233 #if defined(WEBRTC_ANDROID) | 232 #if defined(WEBRTC_ANDROID) |
234 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode | 233 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode |
235 #else | 234 #else |
236 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode | 235 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode |
237 #endif | 236 #endif |
238 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { | 237 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { |
239 SetUpEncodeDecode(); | 238 SetUpEncodeDecode(); |
240 encoder_->Encode(input_frame_, NULL, NULL); | 239 encoder_->Encode(*input_frame_, NULL, NULL); |
241 EXPECT_GT(WaitForEncodedFrame(), 0u); | 240 EXPECT_GT(WaitForEncodedFrame(), 0u); |
242 // First frame should be a key frame. | 241 // First frame should be a key frame. |
243 encoded_frame_._frameType = kVideoFrameKey; | 242 encoded_frame_._frameType = kVideoFrameKey; |
244 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; | 243 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; |
245 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 244 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
246 decoder_->Decode(encoded_frame_, false, NULL)); | 245 decoder_->Decode(encoded_frame_, false, NULL)); |
247 EXPECT_GT(WaitForDecodedFrame(), 0u); | 246 EXPECT_GT(WaitForDecodedFrame(), 0u); |
248 // Compute PSNR on all planes (faster than SSIM). | 247 // Compute PSNR on all planes (faster than SSIM). |
249 EXPECT_GT(I420PSNR(&input_frame_, &decoded_frame_), 36); | 248 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); |
250 EXPECT_EQ(kTestTimestamp, decoded_frame_.timestamp()); | 249 EXPECT_EQ(kTestTimestamp, decoded_frame_.timestamp()); |
251 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_.ntp_time_ms()); | 250 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_.ntp_time_ms()); |
252 } | 251 } |
253 | 252 |
254 #if defined(WEBRTC_ANDROID) | 253 #if defined(WEBRTC_ANDROID) |
255 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame | 254 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame |
256 #else | 255 #else |
257 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame | 256 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame |
258 #endif | 257 #endif |
259 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { | 258 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { |
260 SetUpEncodeDecode(); | 259 SetUpEncodeDecode(); |
261 encoder_->Encode(input_frame_, NULL, NULL); | 260 encoder_->Encode(*input_frame_, NULL, NULL); |
262 EXPECT_GT(WaitForEncodedFrame(), 0u); | 261 EXPECT_GT(WaitForEncodedFrame(), 0u); |
263 // Setting complete to false -> should return an error. | 262 // Setting complete to false -> should return an error. |
264 encoded_frame_._completeFrame = false; | 263 encoded_frame_._completeFrame = false; |
265 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 264 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
266 decoder_->Decode(encoded_frame_, false, NULL)); | 265 decoder_->Decode(encoded_frame_, false, NULL)); |
267 // Setting complete back to true. Forcing a delta frame. | 266 // Setting complete back to true. Forcing a delta frame. |
268 encoded_frame_._frameType = kVideoFrameDelta; | 267 encoded_frame_._frameType = kVideoFrameDelta; |
269 encoded_frame_._completeFrame = true; | 268 encoded_frame_._completeFrame = true; |
270 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, | 269 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, |
271 decoder_->Decode(encoded_frame_, false, NULL)); | 270 decoder_->Decode(encoded_frame_, false, NULL)); |
272 // Now setting a key frame. | 271 // Now setting a key frame. |
273 encoded_frame_._frameType = kVideoFrameKey; | 272 encoded_frame_._frameType = kVideoFrameKey; |
274 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 273 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
275 decoder_->Decode(encoded_frame_, false, NULL)); | 274 decoder_->Decode(encoded_frame_, false, NULL)); |
276 EXPECT_GT(I420PSNR(&input_frame_, &decoded_frame_), 36); | 275 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36); |
277 } | 276 } |
278 | 277 |
279 } // namespace webrtc | 278 } // namespace webrtc |
OLD | NEW |