Index: content/browser/media/openh264_unittests.cc |
diff --git a/content/browser/media/openh264_unittests.cc b/content/browser/media/openh264_unittests.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9fb43031e1b16f62709c96d2bd05d32f8253d451 |
--- /dev/null |
+++ b/content/browser/media/openh264_unittests.cc |
@@ -0,0 +1,55 @@ |
+// 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" |
+ |
+#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() { |
+ int shade = 0; |
+ for (size_t i = 0; i < kNumSampleFrames; ++i) { |
+ CreateRgbFrame(&sample_frames_[i], kVideoWidth, kVideoHeight, |
+ shade, shade, shade); |
+ shade += 255 / kNumSampleFrames; |
+ } |
+ } |
+ ~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 |