OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 |
| 7 #if defined(INCLUDE_OPENH264_UNITTESTS) |
| 8 |
| 9 #include "third_party/openh264/testing/h264_codec_tester.h" |
| 10 #include "third_party/openh264/testing/h264_decoder_impl.h" |
| 11 #include "third_party/openh264/testing/h264_encoder_impl.h" |
| 12 #include "third_party/openh264/testing/i420_utils.h" |
| 13 #include "third_party/webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 14 |
| 15 namespace openh264 { |
| 16 |
| 17 static const unsigned short kVideoWidth = 320; |
| 18 static const unsigned short kVideoHeight = 240; |
| 19 |
| 20 static const size_t kNumSampleFrames = 10; |
| 21 |
| 22 class OpenH264Tests : public testing::Test { |
| 23 protected: |
| 24 OpenH264Tests() { |
| 25 double shade = 0.0; |
| 26 for (size_t i = 0; i < kNumSampleFrames; ++i) { |
| 27 CreateRgbFrame(&sample_frames_[i], kVideoWidth, kVideoHeight, shade, |
| 28 shade, shade); |
| 29 if (kNumSampleFrames > 1) |
| 30 shade += 255.0 / (kNumSampleFrames - 1); |
| 31 } |
| 32 } |
| 33 ~OpenH264Tests() override {} |
| 34 |
| 35 VideoFrame sample_frames_[kNumSampleFrames]; |
| 36 H264CodecTester codec_tester_; |
| 37 }; |
| 38 |
| 39 TEST_F(OpenH264Tests, EncodeDecodeCompareFrames) { |
| 40 const int kNumFrames = 30; |
| 41 |
| 42 ASSERT_TRUE(codec_tester_.Init(kVideoWidth, kVideoHeight)); |
| 43 double avg_ssim = 0.0; |
| 44 for (size_t i = 0; i < kNumFrames; ++i) { |
| 45 VideoFrame* original_frame = &sample_frames_[i % kNumSampleFrames]; |
| 46 ASSERT_TRUE(codec_tester_.Encode(*original_frame)); |
| 47 VideoFrame* decoded_frame = codec_tester_.Decode(); |
| 48 ASSERT_TRUE(decoded_frame != nullptr); |
| 49 |
| 50 avg_ssim += webrtc::I420SSIM(original_frame, decoded_frame); |
| 51 } |
| 52 avg_ssim /= kNumFrames; |
| 53 |
| 54 ASSERT_GE(avg_ssim, 0.9) << "Expected decoded frames to be more similar (on " |
| 55 << "average) to the original frames (SSIM too low)"; |
| 56 } |
| 57 |
| 58 } // namespace openh264 |
| 59 |
| 60 #endif // defined(INCLUDE_OPENH264_UNITTESTS) |
| 61 |
| 62 int main(int argc, char **argv) { |
| 63 ::testing::InitGoogleTest(&argc, argv); |
| 64 return RUN_ALL_TESTS(); |
| 65 } |
OLD | NEW |