Skip to content

Commit 907383d

Browse files
author
chenyouwei
committed
feat:新增调用降噪的相关函数
1 parent dccf264 commit 907383d

21 files changed

+6705
-3
lines changed

libwebrtc/CMakeLists.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Sets the minimum version of CMake required to build the native
2+
# library. You should either keep the default value or only pass a
3+
# value of 3.4.0 or lower.
4+
5+
cmake_minimum_required(VERSION 3.4.1)
6+
7+
# Creates and names a library, sets it as either STATIC
8+
# or SHARED, and provides the relative paths to its source code.
9+
# You can define multiple libraries, and CMake builds it for you.
10+
# Gradle automatically packages shared libraries with your APK.
11+
12+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic")
13+
14+
include_directories(${PROJECT_SOURCE_DIR}/include)
15+
16+
add_definitions(-DFIXED_POINT -DUSE_KISS_FFT -DHAVE_CONFIG_H)
17+
18+
add_library( # Sets the name of the library.
19+
WRtcAudio
20+
21+
# Sets the library as a shared library.
22+
SHARED
23+
24+
# Provides a relative path to your source file(s).
25+
# Associated headers in the same location as their source
26+
# file are automatically included.
27+
src/main/cpp/web_rtc.cpp
28+
29+
src/main/cpp/ns/noise_suppression.c
30+
src/main/cpp/ns/fft4g.c
31+
src/main/cpp/ns/ns_core.c
32+
src/main/cpp/ns/dot_product_with_scale.cc
33+
src/main/cpp/ns/checks.cc
34+
)
35+
36+
37+
# Searches for a specified prebuilt library and stores the path as a
38+
# variable. Because system libraries are included in the search path by
39+
# default, you only need to specify the name of the public NDK library
40+
# you want to add. CMake verifies that the library exists before
41+
# completing its build.
42+
43+
find_library( # Sets the name of the path variable.
44+
log-lib
45+
46+
# Specifies the name of the NDK library that
47+
# you want CMake to locate.
48+
log)
49+
50+
# Specifies libraries CMake should link to your target library. You
51+
# can link multiple libraries, such as libraries you define in the
52+
# build script, prebuilt third-party libraries, or system libraries.
53+
54+
target_link_libraries( # Specifies the target library.
55+
WRtcAudio
56+
57+
# Links the target library to the log library
58+
# included in the NDK.
59+
${log-lib})

libwebrtc/build.gradle

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ android {
1212

1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
consumerProguardFiles 'consumer-rules.pro'
15+
16+
externalNativeBuild {
17+
cmake {
18+
cppFlags "-std=c++11"
19+
}
20+
}
21+
22+
ndk {
23+
abiFilters "armeabi-v7a"
24+
}
25+
compileOptions {
26+
sourceCompatibility = 1.8
27+
targetCompatibility = 1.8
28+
}
1529
}
1630

1731
buildTypes {
@@ -21,6 +35,12 @@ android {
2135
}
2236
}
2337

38+
39+
externalNativeBuild {
40+
cmake {
41+
path "CMakeLists.txt"
42+
}
43+
}
2444
}
2545

2646
dependencies {
@@ -30,6 +50,6 @@ dependencies {
3050
testImplementation 'junit:junit:4.12'
3151
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3252
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
33-
implementation 'org.webrtc:google-webrtc:1.0.28513'
34-
implementation 'org.java-websocket:Java-WebSocket:1.4.0'
53+
implementation "io.reactivex.rxjava2:rxjava:2.1.12"
54+
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
3555
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef NDKDEMO_ANDROID_LOG_PRINT_H
2+
#define NDKDEMO_ANDROID_LOG_PRINT_H
3+
4+
#endif //NDKDEMO_ANDROID_LOG_PRINT_H
5+
6+
#include <android/log.h>
7+
8+
//#define IS_DEBUG
9+
10+
#ifdef IS_DEBUG
11+
12+
#define LOG_TAG ("SWS_LOG_TEST")
13+
14+
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
15+
16+
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
17+
18+
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
19+
20+
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
21+
22+
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
23+
24+
#else
25+
26+
#define LOGV(LOG_TAG, ...) NULL
27+
28+
#define LOGD(LOG_TAG, ...) NULL
29+
30+
#define LOGI(LOG_TAG, ...) NULL
31+
32+
#define LOGW(LOG_TAG, ...) NULL
33+
34+
#define LOGE(LOG_TAG, ...) NULL
35+
36+
#endif
37+
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* Copyright 2006 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+
// Most of this was borrowed (with minor modifications) from V8's and Chromium's
12+
// src/base/logging.cc.
13+
14+
#include <cstdarg>
15+
#include <cstdio>
16+
#include <cstdlib>
17+
18+
#if defined(WEBRTC_ANDROID)
19+
#define RTC_LOG_TAG_ANDROID "rtc"
20+
#include <android/log.h> // NOLINT
21+
#endif
22+
23+
#if defined(WEBRTC_WIN)
24+
#include <windows.h>
25+
#endif
26+
27+
#if defined(WEBRTC_WIN)
28+
#define LAST_SYSTEM_ERROR (::GetLastError())
29+
#elif defined(__native_client__) && __native_client__
30+
#define LAST_SYSTEM_ERROR (0)
31+
#elif defined(WEBRTC_POSIX)
32+
#include <errno.h>
33+
#define LAST_SYSTEM_ERROR (errno)
34+
#endif // WEBRTC_WIN
35+
36+
#include "./checks.h"
37+
38+
namespace {
39+
#if defined(__GNUC__)
40+
__attribute__((__format__(__printf__, 2, 3)))
41+
#endif
42+
void AppendFormat(std::string* s, const char* fmt, ...) {
43+
va_list args, copy;
44+
va_start(args, fmt);
45+
va_copy(copy, args);
46+
const int predicted_length = std::vsnprintf(nullptr, 0, fmt, copy);
47+
va_end(copy);
48+
49+
if (predicted_length > 0) {
50+
const size_t size = s->size();
51+
s->resize(size + predicted_length);
52+
// Pass "+ 1" to vsnprintf to include space for the '\0'.
53+
std::vsnprintf(&((*s)[size]), predicted_length + 1, fmt, args);
54+
}
55+
va_end(args);
56+
}
57+
} // namespace
58+
59+
namespace rtc {
60+
namespace webrtc_checks_impl {
61+
62+
// Reads one argument from args, appends it to s and advances fmt.
63+
// Returns true iff an argument was sucessfully parsed.
64+
bool ParseArg(va_list* args, const CheckArgType** fmt, std::string* s) {
65+
if (**fmt == CheckArgType::kEnd)
66+
return false;
67+
68+
switch (**fmt) {
69+
case CheckArgType::kInt:
70+
AppendFormat(s, "%d", va_arg(*args, int));
71+
break;
72+
case CheckArgType::kLong:
73+
AppendFormat(s, "%ld", va_arg(*args, long));
74+
break;
75+
case CheckArgType::kLongLong:
76+
AppendFormat(s, "%lld", va_arg(*args, long long));
77+
break;
78+
case CheckArgType::kUInt:
79+
AppendFormat(s, "%u", va_arg(*args, unsigned));
80+
break;
81+
case CheckArgType::kULong:
82+
AppendFormat(s, "%lu", va_arg(*args, unsigned long));
83+
break;
84+
case CheckArgType::kULongLong:
85+
AppendFormat(s, "%llu", va_arg(*args, unsigned long long));
86+
break;
87+
case CheckArgType::kDouble:
88+
AppendFormat(s, "%g", va_arg(*args, double));
89+
break;
90+
case CheckArgType::kLongDouble:
91+
AppendFormat(s, "%Lg", va_arg(*args, long double));
92+
break;
93+
case CheckArgType::kCharP:
94+
s->append(va_arg(*args, const char*));
95+
break;
96+
case CheckArgType::kStdString:
97+
s->append(*va_arg(*args, const std::string*));
98+
break;
99+
case CheckArgType::kStringView: {
100+
const absl::string_view sv = *va_arg(*args, const absl::string_view*);
101+
s->append(sv.data(), sv.size());
102+
break;
103+
}
104+
case CheckArgType::kVoidP:
105+
AppendFormat(s, "%p", va_arg(*args, const void*));
106+
break;
107+
default:
108+
s->append("[Invalid CheckArgType]");
109+
return false;
110+
}
111+
(*fmt)++;
112+
return true;
113+
}
114+
115+
RTC_NORETURN void FatalLog(const char* file,
116+
int line,
117+
const char* message,
118+
const CheckArgType* fmt,
119+
...) {
120+
va_list args;
121+
va_start(args, fmt);
122+
123+
std::string s;
124+
AppendFormat(&s,
125+
"\n\n"
126+
"#\n"
127+
"# Fatal error in: %s, line %d\n"
128+
"# last system error: %u\n"
129+
"# Check failed: %s",
130+
file, line, LAST_SYSTEM_ERROR, message);
131+
132+
if (*fmt == CheckArgType::kCheckOp) {
133+
// This log message was generated by RTC_CHECK_OP, so we have to complete
134+
// the error message using the operands that have been passed as the first
135+
// two arguments.
136+
fmt++;
137+
138+
std::string s1, s2;
139+
if (ParseArg(&args, &fmt, &s1) && ParseArg(&args, &fmt, &s2))
140+
AppendFormat(&s, " (%s vs. %s)\n# ", s1.c_str(), s2.c_str());
141+
} else {
142+
s.append("\n# ");
143+
}
144+
145+
// Append all the user-supplied arguments to the message.
146+
while (ParseArg(&args, &fmt, &s))
147+
;
148+
149+
va_end(args);
150+
151+
const char* output = s.c_str();
152+
153+
#if defined(WEBRTC_ANDROID)
154+
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output);
155+
#endif
156+
157+
fflush(stdout);
158+
fprintf(stderr, "%s", output);
159+
fflush(stderr);
160+
abort();
161+
}
162+
163+
} // namespace webrtc_checks_impl
164+
} // namespace rtc
165+
166+
// Function to call from the C version of the RTC_CHECK and RTC_DCHECK macros.
167+
RTC_NORETURN void rtc_FatalMessage(const char* file, int line,
168+
const char* msg) {
169+
static constexpr rtc::webrtc_checks_impl::CheckArgType t[] = {
170+
rtc::webrtc_checks_impl::CheckArgType::kEnd};
171+
FatalLog(file, line, msg, t);
172+
}

0 commit comments

Comments
 (0)