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

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

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

Powered by Google App Engine
This is Rietveld 408576698