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

Unified Diff: third_party/openh264/testing/openh264_unittests.cc

Issue 1446453004: Adding third_party/openh264 build files for encoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use_openh264 = conditional on chrome branding again Created 5 years, 1 month 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: third_party/openh264/testing/openh264_unittests.cc
diff --git a/third_party/openh264/testing/openh264_unittests.cc b/third_party/openh264/testing/openh264_unittests.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38f5f19597f8c26514308e0aa485fbdc08ac4696
--- /dev/null
+++ b/third_party/openh264/testing/openh264_unittests.cc
@@ -0,0 +1,65 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#if defined(INCLUDE_OPENH264_UNITTESTS)
+
+#include "third_party/openh264/testing/h264_codec_tester.h"
+#include "third_party/openh264/testing/h264_decoder_impl.h"
+#include "third_party/openh264/testing/h264_encoder_impl.h"
+#include "third_party/openh264/testing/i420_utils.h"
+#include "third_party/webrtc/common_video/libyuv/include/webrtc_libyuv.h"
+
+namespace openh264 {
+
+static const unsigned short kVideoWidth = 320;
+static const unsigned short kVideoHeight = 240;
+
+static const size_t kNumSampleFrames = 10;
+
+class OpenH264Tests : public testing::Test {
+ protected:
+ OpenH264Tests() {
+ double shade = 0.0;
+ for (size_t i = 0; i < kNumSampleFrames; ++i) {
+ CreateRgbFrame(&sample_frames_[i], kVideoWidth, kVideoHeight, shade,
+ shade, shade);
+ if (kNumSampleFrames > 1)
+ shade += 255.0 / (kNumSampleFrames - 1);
+ }
+ }
+ ~OpenH264Tests() override {}
+
+ VideoFrame sample_frames_[kNumSampleFrames];
+ H264CodecTester codec_tester_;
+};
+
+TEST_F(OpenH264Tests, EncodeDecodeCompareFrames) {
+ const int kNumFrames = 30;
+
+ ASSERT_TRUE(codec_tester_.Init(kVideoWidth, kVideoHeight));
+ double avg_ssim = 0.0;
+ for (size_t i = 0; i < kNumFrames; ++i) {
+ VideoFrame* original_frame = &sample_frames_[i % kNumSampleFrames];
+ ASSERT_TRUE(codec_tester_.Encode(*original_frame));
+ VideoFrame* decoded_frame = codec_tester_.Decode();
+ ASSERT_TRUE(decoded_frame != nullptr);
+
+ avg_ssim += webrtc::I420SSIM(original_frame, decoded_frame);
+ }
+ avg_ssim /= kNumFrames;
+
+ ASSERT_GE(avg_ssim, 0.9) << "Expected decoded frames to be more similar (on "
+ << "average) to the original frames (SSIM too low)";
+}
+
+} // namespace openh264
+
+#endif // defined(INCLUDE_OPENH264_UNITTESTS)
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}

Powered by Google App Engine
This is Rietveld 408576698