Chromium Code Reviews| 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..253c935c65ac0b04c5fd23f984f7205fc9f8751d |
| --- /dev/null |
| +++ b/content/browser/media/openh264_unittests.cc |
| @@ -0,0 +1,56 @@ |
| +// 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" |
|
Dirk Pranke
2015/11/19 02:46:56
does this actually have anything to do w/ content?
phoglund_chromium
2015/11/19 12:39:24
Most of the WebRTC code is in content/ and execute
hbos_chromium
2015/11/19 13:00:43
content_unittests has several WebRTC unittests (so
|
| + |
| +#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 |