Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc

Issue 2574123002: Revert of Delete VideoFrame default constructor, and IsZeroSize method. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/optional.h"
17 #include "webrtc/base/timeutils.h" 16 #include "webrtc/base/timeutils.h"
18 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
19 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
20 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" 19 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
21 #include "webrtc/test/frame_utils.h" 20 #include "webrtc/test/frame_utils.h"
22 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
23 #include "webrtc/test/testsupport/fileutils.h" 22 #include "webrtc/test/testsupport/fileutils.h"
24 23
25 namespace webrtc { 24 namespace webrtc {
26 25
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() { 81 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() {
83 if (encode_complete_) { 82 if (encode_complete_) {
84 encode_complete_ = false; 83 encode_complete_ = false;
85 return true; 84 return true;
86 } 85 }
87 return false; 86 return false;
88 } 87 }
89 88
90 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback { 89 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback {
91 public: 90 public:
92 explicit Vp8UnitTestDecodeCompleteCallback(rtc::Optional<VideoFrame>* frame) 91 explicit Vp8UnitTestDecodeCompleteCallback(VideoFrame* frame)
93 : decoded_frame_(frame), decode_complete(false) {} 92 : decoded_frame_(frame), decode_complete(false) {}
94 int32_t Decoded(VideoFrame& frame) override; 93 int32_t Decoded(VideoFrame& frame) override;
95 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override { 94 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override {
96 RTC_NOTREACHED(); 95 RTC_NOTREACHED();
97 return -1; 96 return -1;
98 } 97 }
99 bool DecodeComplete(); 98 bool DecodeComplete();
100 99
101 private: 100 private:
102 rtc::Optional<VideoFrame>* decoded_frame_; 101 VideoFrame* decoded_frame_;
103 bool decode_complete; 102 bool decode_complete;
104 }; 103 };
105 104
106 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() { 105 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() {
107 if (decode_complete) { 106 if (decode_complete) {
108 decode_complete = false; 107 decode_complete = false;
109 return true; 108 return true;
110 } 109 }
111 return false; 110 return false;
112 } 111 }
113 112
114 int Vp8UnitTestDecodeCompleteCallback::Decoded(VideoFrame& image) { 113 int Vp8UnitTestDecodeCompleteCallback::Decoded(VideoFrame& image) {
115 *decoded_frame_ = rtc::Optional<VideoFrame>(image); 114 *decoded_frame_ = image;
116 decode_complete = true; 115 decode_complete = true;
117 return 0; 116 return 0;
118 } 117 }
119 118
120 class TestVp8Impl : public ::testing::Test { 119 class TestVp8Impl : public ::testing::Test {
121 protected: 120 protected:
122 virtual void SetUp() { 121 virtual void SetUp() {
123 encoder_.reset(VP8Encoder::Create()); 122 encoder_.reset(VP8Encoder::Create());
124 decoder_.reset(VP8Decoder::Create()); 123 decoder_.reset(VP8Decoder::Create());
125 memset(&codec_inst_, 0, sizeof(codec_inst_)); 124 memset(&codec_inst_, 0, sizeof(codec_inst_));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return encoded_frame_._length; 177 return encoded_frame_._length;
179 } 178 }
180 } 179 }
181 return 0; 180 return 0;
182 } 181 }
183 182
184 size_t WaitForDecodedFrame() const { 183 size_t WaitForDecodedFrame() const {
185 int64_t startTime = rtc::TimeMillis(); 184 int64_t startTime = rtc::TimeMillis();
186 while (rtc::TimeMillis() - startTime < kMaxWaitDecTimeMs) { 185 while (rtc::TimeMillis() - startTime < kMaxWaitDecTimeMs) {
187 if (decode_complete_callback_->DecodeComplete()) { 186 if (decode_complete_callback_->DecodeComplete()) {
188 return CalcBufferSize(kI420, decoded_frame_->width(), 187 return CalcBufferSize(kI420, decoded_frame_.width(),
189 decoded_frame_->height()); 188 decoded_frame_.height());
190 } 189 }
191 } 190 }
192 return 0; 191 return 0;
193 } 192 }
194 193
195 const int kWidth = 172; 194 const int kWidth = 172;
196 const int kHeight = 144; 195 const int kHeight = 144;
197 196
198 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; 197 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_;
199 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; 198 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_;
200 std::unique_ptr<uint8_t[]> source_buffer_; 199 std::unique_ptr<uint8_t[]> source_buffer_;
201 FILE* source_file_; 200 FILE* source_file_;
202 std::unique_ptr<VideoFrame> input_frame_; 201 std::unique_ptr<VideoFrame> input_frame_;
203 std::unique_ptr<VideoEncoder> encoder_; 202 std::unique_ptr<VideoEncoder> encoder_;
204 std::unique_ptr<VideoDecoder> decoder_; 203 std::unique_ptr<VideoDecoder> decoder_;
205 EncodedImage encoded_frame_; 204 EncodedImage encoded_frame_;
206 rtc::Optional<VideoFrame> decoded_frame_; 205 VideoFrame decoded_frame_;
207 VideoCodec codec_inst_; 206 VideoCodec codec_inst_;
208 TemporalLayersFactory tl_factory_; 207 TemporalLayersFactory tl_factory_;
209 }; 208 };
210 209
211 TEST_F(TestVp8Impl, EncoderParameterTest) { 210 TEST_F(TestVp8Impl, EncoderParameterTest) {
212 strncpy(codec_inst_.plName, "VP8", 31); 211 strncpy(codec_inst_.plName, "VP8", 31);
213 codec_inst_.plType = 126; 212 codec_inst_.plType = 126;
214 codec_inst_.maxBitrate = 0; 213 codec_inst_.maxBitrate = 0;
215 codec_inst_.minBitrate = 0; 214 codec_inst_.minBitrate = 0;
216 codec_inst_.width = 1440; 215 codec_inst_.width = 1440;
(...skipping 29 matching lines...) Expand all
246 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { 245 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) {
247 SetUpEncodeDecode(); 246 SetUpEncodeDecode();
248 encoder_->Encode(*input_frame_, NULL, NULL); 247 encoder_->Encode(*input_frame_, NULL, NULL);
249 EXPECT_GT(WaitForEncodedFrame(), 0u); 248 EXPECT_GT(WaitForEncodedFrame(), 0u);
250 // First frame should be a key frame. 249 // First frame should be a key frame.
251 encoded_frame_._frameType = kVideoFrameKey; 250 encoded_frame_._frameType = kVideoFrameKey;
252 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; 251 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs;
253 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 252 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
254 decoder_->Decode(encoded_frame_, false, NULL)); 253 decoder_->Decode(encoded_frame_, false, NULL));
255 EXPECT_GT(WaitForDecodedFrame(), 0u); 254 EXPECT_GT(WaitForDecodedFrame(), 0u);
256 ASSERT_TRUE(decoded_frame_);
257 // Compute PSNR on all planes (faster than SSIM). 255 // Compute PSNR on all planes (faster than SSIM).
258 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 256 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36);
259 EXPECT_EQ(kTestTimestamp, decoded_frame_->timestamp()); 257 EXPECT_EQ(kTestTimestamp, decoded_frame_.timestamp());
260 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_->ntp_time_ms()); 258 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_.ntp_time_ms());
261 } 259 }
262 260
263 #if defined(WEBRTC_ANDROID) 261 #if defined(WEBRTC_ANDROID)
264 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame 262 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame
265 #else 263 #else
266 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame 264 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame
267 #endif 265 #endif
268 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { 266 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) {
269 SetUpEncodeDecode(); 267 SetUpEncodeDecode();
270 encoder_->Encode(*input_frame_, NULL, NULL); 268 encoder_->Encode(*input_frame_, NULL, NULL);
271 EXPECT_GT(WaitForEncodedFrame(), 0u); 269 EXPECT_GT(WaitForEncodedFrame(), 0u);
272 // Setting complete to false -> should return an error. 270 // Setting complete to false -> should return an error.
273 encoded_frame_._completeFrame = false; 271 encoded_frame_._completeFrame = false;
274 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 272 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
275 decoder_->Decode(encoded_frame_, false, NULL)); 273 decoder_->Decode(encoded_frame_, false, NULL));
276 // Setting complete back to true. Forcing a delta frame. 274 // Setting complete back to true. Forcing a delta frame.
277 encoded_frame_._frameType = kVideoFrameDelta; 275 encoded_frame_._frameType = kVideoFrameDelta;
278 encoded_frame_._completeFrame = true; 276 encoded_frame_._completeFrame = true;
279 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 277 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
280 decoder_->Decode(encoded_frame_, false, NULL)); 278 decoder_->Decode(encoded_frame_, false, NULL));
281 // Now setting a key frame. 279 // Now setting a key frame.
282 encoded_frame_._frameType = kVideoFrameKey; 280 encoded_frame_._frameType = kVideoFrameKey;
283 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 281 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
284 decoder_->Decode(encoded_frame_, false, NULL)); 282 decoder_->Decode(encoded_frame_, false, NULL));
285 ASSERT_TRUE(decoded_frame_); 283 EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36);
286 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
287 } 284 }
288 285
289 } // namespace webrtc 286 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698