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

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

Issue 2362683002: New helper function test::ReadI420Buffer, refactor FrameReader to use it. (Closed)
Patch Set: Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
diff --git a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
index 12dcb7cfc1dfe13f14daf79ec37178aadd1c611b..7df3faef3275d8391d092ec8d26069fd1213c275 100644
--- a/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
+++ b/webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc
@@ -17,6 +17,7 @@
#include "webrtc/base/timeutils.h"
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
+#include "webrtc/test/frame_utils.h"
#include "webrtc/test/testsupport/fileutils.h"
namespace webrtc {
@@ -128,14 +129,11 @@ class TestVp8Impl : public ::testing::Test {
decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get());
// Using a QCIF image (aligned stride (u,v planes) > width).
// Processing only one frame.
- length_source_frame_ = CalcBufferSize(kI420, kWidth, kHeight);
- source_buffer_.reset(new uint8_t[length_source_frame_]);
source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb");
ASSERT_TRUE(source_file_ != NULL);
- // Set input frame.
- ASSERT_EQ(
- fread(source_buffer_.get(), 1, length_source_frame_, source_file_),
- length_source_frame_);
+ rtc::scoped_refptr<VideoFrameBuffer> compact_buffer(
+ test::ReadI420Buffer(kWidth, kHeight, source_file_));
+ ASSERT_TRUE(compact_buffer);
codec_inst_.width = kWidth;
codec_inst_.height = kHeight;
const int kFramerate = 30;
@@ -147,13 +145,15 @@ class TestVp8Impl : public ::testing::Test {
EXPECT_EQ(stride_y, 176);
EXPECT_EQ(stride_uv, 96);
- input_frame_.CreateEmptyFrame(codec_inst_.width, codec_inst_.height,
- stride_y, stride_uv, stride_uv);
- input_frame_.set_timestamp(kTestTimestamp);
- // Using ConvertToI420 to add stride to the image.
- EXPECT_EQ(0, ConvertToI420(kI420, source_buffer_.get(), 0, 0,
- codec_inst_.width, codec_inst_.height, 0,
- kVideoRotation_0, &input_frame_));
+ rtc::scoped_refptr<I420Buffer> stride_buffer(
+ I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv));
+
+ // No scaling in out case, just a copy, to add stride to the image.
+ stride_buffer->ScaleFrom(compact_buffer);
+
+ input_frame_.reset(
+ new VideoFrame(compact_buffer, kVideoRotation_0, 0));
+ input_frame_->set_timestamp(kTestTimestamp);
}
void SetUpEncodeDecode() {
@@ -195,12 +195,11 @@ class TestVp8Impl : public ::testing::Test {
std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_;
std::unique_ptr<uint8_t[]> source_buffer_;
FILE* source_file_;
- VideoFrame input_frame_;
+ std::unique_ptr<VideoFrame> input_frame_;
std::unique_ptr<VideoEncoder> encoder_;
std::unique_ptr<VideoDecoder> decoder_;
EncodedImage encoded_frame_;
VideoFrame decoded_frame_;
- size_t length_source_frame_;
VideoCodec codec_inst_;
};
@@ -237,7 +236,7 @@ TEST_F(TestVp8Impl, EncoderParameterTest) {
#endif
TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) {
SetUpEncodeDecode();
- encoder_->Encode(input_frame_, NULL, NULL);
+ encoder_->Encode(*input_frame_, NULL, NULL);
EXPECT_GT(WaitForEncodedFrame(), 0u);
// First frame should be a key frame.
encoded_frame_._frameType = kVideoFrameKey;
@@ -246,7 +245,7 @@ TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) {
decoder_->Decode(encoded_frame_, false, NULL));
EXPECT_GT(WaitForDecodedFrame(), 0u);
// Compute PSNR on all planes (faster than SSIM).
- EXPECT_GT(I420PSNR(&input_frame_, &decoded_frame_), 36);
+ EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36);
EXPECT_EQ(kTestTimestamp, decoded_frame_.timestamp());
EXPECT_EQ(kTestNtpTimeMs, decoded_frame_.ntp_time_ms());
}
@@ -258,7 +257,7 @@ TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) {
#endif
TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) {
SetUpEncodeDecode();
- encoder_->Encode(input_frame_, NULL, NULL);
+ encoder_->Encode(*input_frame_, NULL, NULL);
EXPECT_GT(WaitForEncodedFrame(), 0u);
// Setting complete to false -> should return an error.
encoded_frame_._completeFrame = false;
@@ -273,7 +272,7 @@ TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) {
encoded_frame_._frameType = kVideoFrameKey;
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
decoder_->Decode(encoded_frame_, false, NULL));
- EXPECT_GT(I420PSNR(&input_frame_, &decoded_frame_), 36);
+ EXPECT_GT(I420PSNR(input_frame_.get(), &decoded_frame_), 36);
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698