OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <string.h> | 11 #include <string.h> |
12 | 12 |
| 13 #include <memory> |
| 14 |
13 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 15 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
14 #include "webrtc/modules/video_processing/include/video_processing.h" | 16 #include "webrtc/modules/video_processing/include/video_processing.h" |
15 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" | 17 #include "webrtc/modules/video_processing/test/video_processing_unittest.h" |
16 #include "webrtc/modules/video_processing/video_denoiser.h" | 18 #include "webrtc/modules/video_processing/video_denoiser.h" |
17 #include "webrtc/test/frame_utils.h" | 19 #include "webrtc/test/frame_utils.h" |
18 | 20 |
19 namespace webrtc { | 21 namespace webrtc { |
20 | 22 |
21 TEST_F(VideoProcessingTest, CopyMem) { | 23 TEST_F(VideoProcessingTest, CopyMem) { |
22 rtc::scoped_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false)); | 24 std::unique_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false)); |
23 rtc::scoped_ptr<DenoiserFilter> df_sse_neon(DenoiserFilter::Create(true)); | 25 std::unique_ptr<DenoiserFilter> df_sse_neon(DenoiserFilter::Create(true)); |
24 uint8_t src[16 * 16], dst[16 * 16]; | 26 uint8_t src[16 * 16], dst[16 * 16]; |
25 for (int i = 0; i < 16; ++i) { | 27 for (int i = 0; i < 16; ++i) { |
26 for (int j = 0; j < 16; ++j) { | 28 for (int j = 0; j < 16; ++j) { |
27 src[i * 16 + j] = i * 16 + j; | 29 src[i * 16 + j] = i * 16 + j; |
28 } | 30 } |
29 } | 31 } |
30 | 32 |
31 memset(dst, 0, 8 * 8); | 33 memset(dst, 0, 8 * 8); |
32 df_c->CopyMem8x8(src, 8, dst, 8); | 34 df_c->CopyMem8x8(src, 8, dst, 8); |
33 EXPECT_EQ(0, memcmp(src, dst, 8 * 8)); | 35 EXPECT_EQ(0, memcmp(src, dst, 8 * 8)); |
34 | 36 |
35 memset(dst, 0, 16 * 16); | 37 memset(dst, 0, 16 * 16); |
36 df_c->CopyMem16x16(src, 16, dst, 16); | 38 df_c->CopyMem16x16(src, 16, dst, 16); |
37 EXPECT_EQ(0, memcmp(src, dst, 16 * 16)); | 39 EXPECT_EQ(0, memcmp(src, dst, 16 * 16)); |
38 | 40 |
39 memset(dst, 0, 8 * 8); | 41 memset(dst, 0, 8 * 8); |
40 df_sse_neon->CopyMem16x16(src, 8, dst, 8); | 42 df_sse_neon->CopyMem16x16(src, 8, dst, 8); |
41 EXPECT_EQ(0, memcmp(src, dst, 8 * 8)); | 43 EXPECT_EQ(0, memcmp(src, dst, 8 * 8)); |
42 | 44 |
43 memset(dst, 0, 16 * 16); | 45 memset(dst, 0, 16 * 16); |
44 df_sse_neon->CopyMem16x16(src, 16, dst, 16); | 46 df_sse_neon->CopyMem16x16(src, 16, dst, 16); |
45 EXPECT_EQ(0, memcmp(src, dst, 16 * 16)); | 47 EXPECT_EQ(0, memcmp(src, dst, 16 * 16)); |
46 } | 48 } |
47 | 49 |
48 TEST_F(VideoProcessingTest, Variance) { | 50 TEST_F(VideoProcessingTest, Variance) { |
49 rtc::scoped_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false)); | 51 std::unique_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false)); |
50 rtc::scoped_ptr<DenoiserFilter> df_sse_neon(DenoiserFilter::Create(true)); | 52 std::unique_ptr<DenoiserFilter> df_sse_neon(DenoiserFilter::Create(true)); |
51 uint8_t src[16 * 16], dst[16 * 16]; | 53 uint8_t src[16 * 16], dst[16 * 16]; |
52 uint32_t sum = 0, sse = 0, var; | 54 uint32_t sum = 0, sse = 0, var; |
53 for (int i = 0; i < 16; ++i) { | 55 for (int i = 0; i < 16; ++i) { |
54 for (int j = 0; j < 16; ++j) { | 56 for (int j = 0; j < 16; ++j) { |
55 src[i * 16 + j] = i * 16 + j; | 57 src[i * 16 + j] = i * 16 + j; |
56 } | 58 } |
57 } | 59 } |
58 // Compute the 16x8 variance of the 16x16 block. | 60 // Compute the 16x8 variance of the 16x16 block. |
59 for (int i = 0; i < 8; ++i) { | 61 for (int i = 0; i < 8; ++i) { |
60 for (int j = 0; j < 16; ++j) { | 62 for (int j = 0; j < 16; ++j) { |
61 sum += (i * 32 + j); | 63 sum += (i * 32 + j); |
62 sse += (i * 32 + j) * (i * 32 + j); | 64 sse += (i * 32 + j) * (i * 32 + j); |
63 } | 65 } |
64 } | 66 } |
65 var = sse - ((sum * sum) >> 7); | 67 var = sse - ((sum * sum) >> 7); |
66 memset(dst, 0, 16 * 16); | 68 memset(dst, 0, 16 * 16); |
67 EXPECT_EQ(var, df_c->Variance16x8(src, 16, dst, 16, &sse)); | 69 EXPECT_EQ(var, df_c->Variance16x8(src, 16, dst, 16, &sse)); |
68 EXPECT_EQ(var, df_sse_neon->Variance16x8(src, 16, dst, 16, &sse)); | 70 EXPECT_EQ(var, df_sse_neon->Variance16x8(src, 16, dst, 16, &sse)); |
69 } | 71 } |
70 | 72 |
71 TEST_F(VideoProcessingTest, MbDenoise) { | 73 TEST_F(VideoProcessingTest, MbDenoise) { |
72 rtc::scoped_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false)); | 74 std::unique_ptr<DenoiserFilter> df_c(DenoiserFilter::Create(false)); |
73 rtc::scoped_ptr<DenoiserFilter> df_sse_neon(DenoiserFilter::Create(true)); | 75 std::unique_ptr<DenoiserFilter> df_sse_neon(DenoiserFilter::Create(true)); |
74 uint8_t running_src[16 * 16], src[16 * 16], dst[16 * 16], dst_ref[16 * 16]; | 76 uint8_t running_src[16 * 16], src[16 * 16], dst[16 * 16], dst_ref[16 * 16]; |
75 | 77 |
76 // Test case: |diff| <= |3 + shift_inc1| | 78 // Test case: |diff| <= |3 + shift_inc1| |
77 for (int i = 0; i < 16; ++i) { | 79 for (int i = 0; i < 16; ++i) { |
78 for (int j = 0; j < 16; ++j) { | 80 for (int j = 0; j < 16; ++j) { |
79 running_src[i * 16 + j] = i * 11 + j; | 81 running_src[i * 16 + j] = i * 11 + j; |
80 src[i * 16 + j] = i * 11 + j + 2; | 82 src[i * 16 + j] = i * 11 + j + 2; |
81 dst_ref[i * 16 + j] = running_src[i * 16 + j]; | 83 dst_ref[i * 16 + j] = running_src[i * 16 + j]; |
82 } | 84 } |
83 } | 85 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 133 } |
132 | 134 |
133 TEST_F(VideoProcessingTest, Denoiser) { | 135 TEST_F(VideoProcessingTest, Denoiser) { |
134 // Create pure C denoiser. | 136 // Create pure C denoiser. |
135 VideoDenoiser denoiser_c(false); | 137 VideoDenoiser denoiser_c(false); |
136 // Create SSE or NEON denoiser. | 138 // Create SSE or NEON denoiser. |
137 VideoDenoiser denoiser_sse_neon(true); | 139 VideoDenoiser denoiser_sse_neon(true); |
138 VideoFrame denoised_frame_c; | 140 VideoFrame denoised_frame_c; |
139 VideoFrame denoised_frame_sse_neon; | 141 VideoFrame denoised_frame_sse_neon; |
140 | 142 |
141 rtc::scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); | 143 std::unique_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); |
142 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == | 144 while (fread(video_buffer.get(), 1, frame_length_, source_file_) == |
143 frame_length_) { | 145 frame_length_) { |
144 // Using ConvertToI420 to add stride to the image. | 146 // Using ConvertToI420 to add stride to the image. |
145 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, | 147 EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, width_, height_, |
146 0, kVideoRotation_0, &video_frame_)); | 148 0, kVideoRotation_0, &video_frame_)); |
147 | 149 |
148 denoiser_c.DenoiseFrame(video_frame_, &denoised_frame_c); | 150 denoiser_c.DenoiseFrame(video_frame_, &denoised_frame_c); |
149 denoiser_sse_neon.DenoiseFrame(video_frame_, &denoised_frame_sse_neon); | 151 denoiser_sse_neon.DenoiseFrame(video_frame_, &denoised_frame_sse_neon); |
150 | 152 |
151 // Denoising results should be the same for C and SSE/NEON denoiser. | 153 // Denoising results should be the same for C and SSE/NEON denoiser. |
152 ASSERT_TRUE(test::FramesEqual(denoised_frame_c, denoised_frame_sse_neon)); | 154 ASSERT_TRUE(test::FramesEqual(denoised_frame_c, denoised_frame_sse_neon)); |
153 } | 155 } |
154 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; | 156 ASSERT_NE(0, feof(source_file_)) << "Error reading source file"; |
155 } | 157 } |
156 | 158 |
157 } // namespace webrtc | 159 } // namespace webrtc |
OLD | NEW |