aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/video_processing/main/test/unit_test/deflickering_test.cc
blob: 83d09ef486c395a391b4a53603384442534e1ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 *  Copyright (c) 2012 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.
 */

#include <stdio.h>
#include <stdlib.h>

#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#include "webrtc/modules/video_processing/main/interface/video_processing.h"
#include "webrtc/modules/video_processing/main/test/unit_test/video_processing_unittest.h"
#include "webrtc/system_wrappers/include/tick_util.h"
#include "webrtc/test/testsupport/fileutils.h"
#include "webrtc/test/testsupport/gtest_disable.h"

namespace webrtc {

TEST_F(VideoProcessingModuleTest, DISABLED_ON_IOS(Deflickering))
{
    enum { NumRuns = 30 };
    uint32_t frameNum = 0;
    const uint32_t frame_rate = 15;

    int64_t min_runtime = 0;
    int64_t avg_runtime = 0;

    // Close automatically opened Foreman.
    fclose(source_file_);
    const std::string input_file =
        webrtc::test::ResourcePath("deflicker_before_cif_short", "yuv");
    source_file_  = fopen(input_file.c_str(), "rb");
    ASSERT_TRUE(source_file_ != NULL) <<
        "Cannot read input file: " << input_file << "\n";

    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";

    printf("\nRun time [us / frame]:\n");
    rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]);
    for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++)
    {
        TickTime t0;
        TickTime t1;
        TickInterval acc_ticks;
        uint32_t timeStamp = 1;

        frameNum = 0;
        while (fread(video_buffer.get(), 1, frame_length_, source_file_) ==
               frame_length_)
        {
            frameNum++;
            EXPECT_EQ(
                0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_,
                                 height_, 0, kVideoRotation_0, &video_frame_));
            video_frame_.set_timestamp(timeStamp);

            t0 = TickTime::Now();
            VideoProcessingModule::FrameStats stats;
            ASSERT_EQ(0, vpm_->GetFrameStats(&stats, video_frame_));
            ASSERT_EQ(0, vpm_->Deflickering(&video_frame_, &stats));
            t1 = TickTime::Now();
            acc_ticks += (t1 - t0);

            if (run_idx == 0)
            {
              if (PrintVideoFrame(video_frame_, deflickerFile) < 0) {
                return;
              }
            }
            timeStamp += (90000 / frame_rate);
        }
        ASSERT_NE(0, feof(source_file_)) << "Error reading source file";

        printf("%u\n", static_cast<int>(acc_ticks.Microseconds() / frameNum));
        if (acc_ticks.Microseconds() < min_runtime || run_idx == 0)
        {
            min_runtime = acc_ticks.Microseconds();
        }
        avg_runtime += acc_ticks.Microseconds();

        rewind(source_file_);
    }
    ASSERT_EQ(0, fclose(deflickerFile));
    // TODO(kjellander): Add verification of deflicker output file.

    printf("\nAverage run time = %d us / frame\n",
        static_cast<int>(avg_runtime / frameNum / NumRuns));
    printf("Min run time = %d us / frame\n\n",
        static_cast<int>(min_runtime / frameNum));
}

}  // namespace webrtc