2011-12-05 13:03:38 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-27 08:02:22 +00:00
|
|
|
#include "webrtc/test/testsupport/metrics/video_metrics.h"
|
2011-12-05 13:03:38 +00:00
|
|
|
|
2013-05-27 08:02:22 +00:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
#include "webrtc/test/testsupport/fileutils.h"
|
2013-08-02 16:53:47 +00:00
|
|
|
#include "webrtc/test/testsupport/gtest_disable.h"
|
2011-12-05 13:03:38 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
static const char* kEmptyFileName = "video_metrics_unittest_empty_file.tmp";
|
|
|
|
|
static const char* kNonExistingFileName = "video_metrics_unittest_non_existing";
|
|
|
|
|
static const int kWidth = 352;
|
|
|
|
|
static const int kHeight = 288;
|
|
|
|
|
|
|
|
|
|
static const int kMissingReferenceFileReturnCode = -1;
|
|
|
|
|
static const int kMissingTestFileReturnCode = -2;
|
|
|
|
|
static const int kEmptyFileReturnCode = -3;
|
2012-01-04 08:09:32 +00:00
|
|
|
static const double kPsnrPerfectResult = 48.0;
|
2011-12-05 13:03:38 +00:00
|
|
|
static const double kSsimPerfectResult = 1.0;
|
|
|
|
|
|
|
|
|
|
class VideoMetricsTest: public testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
VideoMetricsTest() {
|
2012-01-04 08:09:32 +00:00
|
|
|
video_file_ = webrtc::test::ResourcePath("foreman_cif_short", "yuv");
|
2011-12-05 13:03:38 +00:00
|
|
|
}
|
|
|
|
|
virtual ~VideoMetricsTest() {}
|
|
|
|
|
void SetUp() {
|
|
|
|
|
// Create an empty file:
|
|
|
|
|
FILE* dummy = fopen(kEmptyFileName, "wb");
|
|
|
|
|
fclose(dummy);
|
|
|
|
|
}
|
|
|
|
|
void TearDown() {
|
2013-08-05 16:22:53 +00:00
|
|
|
remove(kEmptyFileName);
|
2011-12-05 13:03:38 +00:00
|
|
|
}
|
2012-01-04 08:09:32 +00:00
|
|
|
webrtc::test::QualityMetricsResult psnr_result_;
|
|
|
|
|
webrtc::test::QualityMetricsResult ssim_result_;
|
|
|
|
|
std::string video_file_;
|
2011-12-05 13:03:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Tests that it is possible to run with the same reference as test file
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest,
|
|
|
|
|
DISABLED_ON_ANDROID(ReturnsPerfectResultForIdenticalFilesPSNR)) {
|
2012-01-04 08:09:32 +00:00
|
|
|
EXPECT_EQ(0, I420PSNRFromFiles(video_file_.c_str(), video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &psnr_result_));
|
|
|
|
|
EXPECT_EQ(kPsnrPerfectResult, psnr_result_.average);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest,
|
|
|
|
|
DISABLED_ON_ANDROID(ReturnsPerfectResultForIdenticalFilesSSIM)) {
|
2012-01-04 08:09:32 +00:00
|
|
|
EXPECT_EQ(0, I420SSIMFromFiles(video_file_.c_str(), video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
|
|
|
|
EXPECT_EQ(kSsimPerfectResult, ssim_result_.average);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest,
|
|
|
|
|
DISABLED_ON_ANDROID(ReturnsPerfectResultForIdenticalFilesBothMetrics)) {
|
2012-01-04 08:09:32 +00:00
|
|
|
EXPECT_EQ(0, I420MetricsFromFiles(video_file_.c_str(), video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &psnr_result_,
|
|
|
|
|
&ssim_result_));
|
|
|
|
|
EXPECT_EQ(kPsnrPerfectResult, psnr_result_.average);
|
|
|
|
|
EXPECT_EQ(kSsimPerfectResult, ssim_result_.average);
|
2011-12-05 13:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tests that the right return code is given when the reference file is missing.
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(MissingReferenceFilePSNR)) {
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kMissingReferenceFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420PSNRFromFiles(kNonExistingFileName, video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(MissingReferenceFileSSIM)) {
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kMissingReferenceFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420SSIMFromFiles(kNonExistingFileName, video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(MissingReferenceFileBothMetrics)) {
|
2012-01-04 08:09:32 +00:00
|
|
|
EXPECT_EQ(kMissingReferenceFileReturnCode,
|
|
|
|
|
I420MetricsFromFiles(kNonExistingFileName, video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight,
|
|
|
|
|
&psnr_result_, &ssim_result_));
|
2011-12-05 13:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tests that the right return code is given when the test file is missing.
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(MissingTestFilePSNR)) {
|
2012-01-04 08:09:32 +00:00
|
|
|
EXPECT_EQ(kMissingTestFileReturnCode,
|
|
|
|
|
I420PSNRFromFiles(video_file_.c_str(), kNonExistingFileName,
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(MissingTestFileSSIM)) {
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kMissingTestFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420SSIMFromFiles(video_file_.c_str(), kNonExistingFileName,
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(MissingTestFileBothMetrics)) {
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kMissingTestFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420MetricsFromFiles(video_file_.c_str(), kNonExistingFileName,
|
|
|
|
|
kWidth, kHeight,
|
|
|
|
|
&psnr_result_, &ssim_result_));
|
2011-12-05 13:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tests that the method can be executed with empty files.
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(EmptyFilesPSNR)) {
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kEmptyFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420PSNRFromFiles(kEmptyFileName, video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kEmptyFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420PSNRFromFiles(video_file_.c_str(), kEmptyFileName,
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(EmptyFilesSSIM)) {
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kEmptyFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420SSIMFromFiles(kEmptyFileName, video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
2011-12-05 13:03:38 +00:00
|
|
|
EXPECT_EQ(kEmptyFileReturnCode,
|
2012-01-04 08:09:32 +00:00
|
|
|
I420SSIMFromFiles(video_file_.c_str(), kEmptyFileName,
|
|
|
|
|
kWidth, kHeight, &ssim_result_));
|
2011-12-05 13:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-02 16:53:47 +00:00
|
|
|
TEST_F(VideoMetricsTest, DISABLED_ON_ANDROID(EmptyFilesBothMetrics)) {
|
2012-01-04 08:09:32 +00:00
|
|
|
EXPECT_EQ(kEmptyFileReturnCode,
|
|
|
|
|
I420MetricsFromFiles(kEmptyFileName, video_file_.c_str(),
|
|
|
|
|
kWidth, kHeight,
|
|
|
|
|
&psnr_result_, &ssim_result_));
|
|
|
|
|
EXPECT_EQ(kEmptyFileReturnCode,
|
|
|
|
|
I420MetricsFromFiles(video_file_.c_str(), kEmptyFileName,
|
|
|
|
|
kWidth, kHeight,
|
|
|
|
|
&psnr_result_, &ssim_result_));
|
|
|
|
|
}
|
2011-12-05 13:03:38 +00:00
|
|
|
|
2013-08-27 12:10:09 +00:00
|
|
|
// Dummy test to get at least one test in this executable for Android
|
|
|
|
|
// (otherwise gtest will fail execution on Android).
|
|
|
|
|
// TODO(kjellander): Remove when the other tests have been fixed for
|
|
|
|
|
// Android.
|
|
|
|
|
TEST_F(VideoMetricsTest, DummyTest) {
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-04 08:09:32 +00:00
|
|
|
} // namespace webrtc
|