• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include <vector>
11 
12 #include "api/scoped_refptr.h"
13 #include "rtc_tools/frame_analyzer/reference_less_video_analysis_lib.h"
14 #include "rtc_tools/video_file_reader.h"
15 #include "test/gtest.h"
16 #include "test/testsupport/file_utils.h"
17 
18 class ReferenceLessVideoAnalysisTest : public ::testing::Test {
19  public:
SetUp()20   void SetUp() override {
21     video = webrtc::test::OpenY4mFile(
22         webrtc::test::ResourcePath("reference_less_video_test_file", "y4m"));
23     ASSERT_TRUE(video);
24   }
25 
26   rtc::scoped_refptr<webrtc::test::Video> video;
27   std::vector<double> psnr_per_frame;
28   std::vector<double> ssim_per_frame;
29 };
30 
TEST_F(ReferenceLessVideoAnalysisTest,MatchComputedMetrics)31 TEST_F(ReferenceLessVideoAnalysisTest, MatchComputedMetrics) {
32   compute_metrics(video, &psnr_per_frame, &ssim_per_frame);
33   EXPECT_EQ(74, (int)psnr_per_frame.size());
34 
35   ASSERT_NEAR(27.2f, psnr_per_frame[1], 0.1f);
36   ASSERT_NEAR(24.9f, psnr_per_frame[5], 0.1f);
37 
38   ASSERT_NEAR(0.9f, ssim_per_frame[1], 0.1f);
39   ASSERT_NEAR(0.9f, ssim_per_frame[5], 0.1f);
40 }
41 
TEST_F(ReferenceLessVideoAnalysisTest,MatchIdenticalFrameClusters)42 TEST_F(ReferenceLessVideoAnalysisTest, MatchIdenticalFrameClusters) {
43   compute_metrics(video, &psnr_per_frame, &ssim_per_frame);
44   std::vector<int> identical_frame_clusters =
45       find_frame_clusters(psnr_per_frame, ssim_per_frame);
46   EXPECT_EQ(5, (int)identical_frame_clusters.size());
47   EXPECT_EQ(1, identical_frame_clusters[0]);
48   EXPECT_EQ(1, identical_frame_clusters[4]);
49 }
50