• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2015 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 
11 #include "modules/video_processing/util/denoiser_filter.h"
12 
13 #include "modules/video_processing/util/denoiser_filter_c.h"
14 #include "rtc_base/checks.h"
15 #include "rtc_base/system/arch.h"
16 #include "system_wrappers/include/cpu_features_wrapper.h"
17 
18 #if defined(WEBRTC_ARCH_X86_FAMILY)
19 #include "modules/video_processing/util/denoiser_filter_sse2.h"
20 #elif defined(WEBRTC_HAS_NEON)
21 #include "modules/video_processing/util/denoiser_filter_neon.h"
22 #endif
23 
24 namespace webrtc {
25 
26 const int kMotionMagnitudeThreshold = 8 * 3;
27 const int kSumDiffThreshold = 96;
28 const int kSumDiffThresholdHigh = 448;
29 
Create(bool runtime_cpu_detection,CpuType * cpu_type)30 std::unique_ptr<DenoiserFilter> DenoiserFilter::Create(
31     bool runtime_cpu_detection,
32     CpuType* cpu_type) {
33   std::unique_ptr<DenoiserFilter> filter;
34 
35   if (cpu_type != nullptr)
36     *cpu_type = CPU_NOT_NEON;
37   if (runtime_cpu_detection) {
38 // If we know the minimum architecture at compile time, avoid CPU detection.
39 #if defined(WEBRTC_ARCH_X86_FAMILY)
40 #if defined(__SSE2__)
41     filter.reset(new DenoiserFilterSSE2());
42 #else
43     // x86 CPU detection required.
44     if (WebRtc_GetCPUInfo(kSSE2)) {
45       filter.reset(new DenoiserFilterSSE2());
46     } else {
47       filter.reset(new DenoiserFilterC());
48     }
49 #endif
50 #elif defined(WEBRTC_HAS_NEON)
51     filter.reset(new DenoiserFilterNEON());
52     if (cpu_type != nullptr)
53       *cpu_type = CPU_NEON;
54 #else
55     filter.reset(new DenoiserFilterC());
56 #endif
57   } else {
58     filter.reset(new DenoiserFilterC());
59   }
60 
61   RTC_DCHECK(filter.get() != nullptr);
62   return filter;
63 }
64 
65 }  // namespace webrtc
66