2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-05-29 17:33:13 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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-08-05 16:22:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-08 19:19:59 +00:00
|
|
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
2015-11-18 22:31:24 +01:00
|
|
|
#include "webrtc/modules/video_processing/include/video_processing.h"
|
|
|
|
|
#include "webrtc/modules/video_processing/test/video_processing_unittest.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/tick_util.h"
|
2013-01-08 19:19:59 +00:00
|
|
|
#include "webrtc/test/testsupport/fileutils.h"
|
2015-06-10 13:24:48 +02:00
|
|
|
#include "webrtc/test/testsupport/gtest_disable.h"
|
2011-12-16 10:31:38 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-06-10 13:24:48 +02:00
|
|
|
TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(Deflickering))
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
enum { NumRuns = 30 };
|
2013-04-09 13:38:10 +00:00
|
|
|
uint32_t frameNum = 0;
|
2013-10-03 16:42:41 +00:00
|
|
|
const uint32_t frame_rate = 15;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
int64_t min_runtime = 0;
|
|
|
|
|
int64_t avg_runtime = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Close automatically opened Foreman.
|
2013-10-03 16:42:41 +00:00
|
|
|
fclose(source_file_);
|
2011-12-16 10:31:38 +00:00
|
|
|
const std::string input_file =
|
|
|
|
|
webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv");
|
2013-10-03 16:42:41 +00:00
|
|
|
source_file_ = fopen(input_file.c_str(), "rb");
|
|
|
|
|
ASSERT_TRUE(source_file_ != NULL) <<
|
2011-12-16 10:31:38 +00:00
|
|
|
"Cannot read input file: " << input_file << "\n";
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2011-12-16 10:31:38 +00:00
|
|
|
const std::string output_file =
|
|
|
|
|
webrtc::test::OutputPath() + "deflicker_output_cif_short.yuv";
|
|
|
|
|
FILE* deflickerFile = fopen(output_file.c_str(), "wb");
|
|
|
|
|
ASSERT_TRUE(deflickerFile != NULL) <<
|
|
|
|
|
"Could not open output file: " << output_file << "\n";
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
printf("\nRun time [us / frame]:\n");
|
2015-02-26 14:34:55 +00:00
|
|
|
rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
|
2013-10-03 16:42:41 +00:00
|
|
|
for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
TickTime t0;
|
|
|
|
|
TickTime t1;
|
2013-10-03 16:42:41 +00:00
|
|
|
TickInterval acc_ticks;
|
2013-04-09 13:38:10 +00:00
|
|
|
uint32_t timeStamp = 1;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
frameNum = 0;
|
2013-10-03 16:42:41 +00:00
|
|
|
while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
|
|
|
|
|
frame_length_)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
frameNum++;
|
2015-03-09 17:07:31 +00:00
|
|
|
EXPECT_EQ(
|
|
|
|
|
0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
|
|
|
|
|
height_, 0, kVideoRotation_0, &video_frame_));
|
2013-10-03 16:42:41 +00:00
|
|
|
video_frame_.set_timestamp(timeStamp);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-05-29 17:33:13 +00:00
|
|
|
t0 = TickTime::Now();
|
2011-07-07 08:21:25 +00:00
|
|
|
VideoProcessingModule::FrameStats stats;
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
|
|
|
|
|
ASSERT_EQ(0, vpm_->Deflickering(&video_frame_, &stats));
|
2011-07-07 08:21:25 +00:00
|
|
|
t1 = TickTime::Now();
|
2013-10-03 16:42:41 +00:00
|
|
|
acc_ticks += (t1 - t0);
|
2012-05-29 17:33:13 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
if (run_idx == 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2015-05-29 17:21:40 -07:00
|
|
|
if (PrintVideoFrame(video_frame_, deflickerFile) < 0) {
|
2012-05-29 17:33:13 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-10-03 16:42:41 +00:00
|
|
|
timeStamp += (90000 / frame_rate);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-10-03 16:42:41 +00:00
|
|
|
ASSERT_NE(0, feof(source_file_)) << "Error reading source file";
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
printf("%u\n", static_cast<int>(acc_ticks.Microseconds() / frameNum));
|
|
|
|
|
if (acc_ticks.Microseconds() < min_runtime || run_idx == 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2013-10-03 16:42:41 +00:00
|
|
|
min_runtime = acc_ticks.Microseconds();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-10-03 16:42:41 +00:00
|
|
|
avg_runtime += acc_ticks.Microseconds();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
rewind(source_file_);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-12-16 10:31:38 +00:00
|
|
|
ASSERT_EQ(0, fclose(deflickerFile));
|
|
|
|
|
// TODO(kjellander): Add verification of deflicker output file.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-05-29 17:33:13 +00:00
|
|
|
printf("\nAverage run time = %d us / frame\n",
|
2013-10-03 16:42:41 +00:00
|
|
|
static_cast<int>(avg_runtime / frameNum / NumRuns));
|
2012-05-29 17:33:13 +00:00
|
|
|
printf("Min run time = %d us / frame\n\n",
|
2013-10-03 16:42:41 +00:00
|
|
|
static_cast<int>(min_runtime / frameNum));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-12-16 10:31:38 +00:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|