To accommodate some downstream WebRTC users we need to loosen
the coupling between our code and the //third_party/protobuf.
This includes using typedefs to define strings instead of
assuming std::string.
After this refactoring it will be possible to link with other
protobuf implementations than the current one.
We moved the PRESUBMIT check to another CL [1]. The goal of this
presubmit is to avoid the direct usage of google::protobuf outside
of the webrtc/base/protobuf_utils.h header file.
[1] - https://codereview.webrtc.org/2753823003/
BUG=webrtc:7340
NOTRY=True
Review-Url: https://codereview.webrtc.org/2747863003
Cr-Commit-Position: refs/heads/master@{#17466}
diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn
index 36f5575..84545dd 100644
--- a/webrtc/modules/audio_processing/BUILD.gn
+++ b/webrtc/modules/audio_processing/BUILD.gn
@@ -232,6 +232,7 @@
"../..:webrtc_common",
"../../audio/utility:audio_frame_operations",
"../../base:gtest_prod",
+ "../../base:protobuf_utils",
"../audio_coding:isac",
]
public_deps = [
@@ -524,6 +525,7 @@
":audioproc_test_utils",
"../..:webrtc_common",
"../../base:gtest_prod",
+ "../../base:protobuf_utils",
"../../base:rtc_base",
"../../base:rtc_base_approved",
"../../common_audio:common_audio",
@@ -656,8 +658,10 @@
deps = [
":audio_processing",
":audioproc_test_utils",
+ "../../base:protobuf_utils",
"//testing/gtest",
]
+
if (rtc_enable_intelligibility_enhancer) {
defines = [ "WEBRTC_INTELLIGIBILITY_ENHANCER=1" ]
} else {
@@ -678,6 +682,7 @@
":audioproc_protobuf_utils",
":audioproc_test_utils",
"../..:webrtc_common",
+ "../../base:protobuf_utils",
"../../base:rtc_base_approved",
"../../common_audio",
"../../system_wrappers:system_wrappers_default",
@@ -702,6 +707,7 @@
":audioproc_debug_proto",
":audioproc_protobuf_utils",
":audioproc_test_utils",
+ "../../base:protobuf_utils",
"../../base:rtc_base_approved",
"../../common_audio:common_audio",
"../../system_wrappers",
@@ -817,6 +823,7 @@
deps = [
":audioproc_debug_proto",
"../..:webrtc_common",
+ "../../base:protobuf_utils",
"../../base:rtc_base_approved",
]
}
diff --git a/webrtc/modules/audio_processing/audio_processing_impl.cc b/webrtc/modules/audio_processing/audio_processing_impl.cc
index 1f73c59..56da282 100644
--- a/webrtc/modules/audio_processing/audio_processing_impl.cc
+++ b/webrtc/modules/audio_processing/audio_processing_impl.cc
@@ -1879,11 +1879,11 @@
audioproc::Init* msg = debug_dump_.capture.event_msg->mutable_init();
msg->set_sample_rate(formats_.api_format.input_stream().sample_rate_hz());
- msg->set_num_input_channels(static_cast<google::protobuf::int32>(
+ msg->set_num_input_channels(static_cast<int32_t>(
formats_.api_format.input_stream().num_channels()));
- msg->set_num_output_channels(static_cast<google::protobuf::int32>(
+ msg->set_num_output_channels(static_cast<int32_t>(
formats_.api_format.output_stream().num_channels()));
- msg->set_num_reverse_channels(static_cast<google::protobuf::int32>(
+ msg->set_num_reverse_channels(static_cast<int32_t>(
formats_.api_format.reverse_input_stream().num_channels()));
msg->set_reverse_sample_rate(
formats_.api_format.reverse_input_stream().sample_rate_hz());
@@ -1953,7 +1953,7 @@
}
config.set_experiments_description(experiments_description);
- std::string serialized_config = config.SerializeAsString();
+ ProtoString serialized_config = config.SerializeAsString();
if (!forced &&
debug_dump_.capture.last_serialized_config == serialized_config) {
return kNoError;
diff --git a/webrtc/modules/audio_processing/audio_processing_impl.h b/webrtc/modules/audio_processing/audio_processing_impl.h
index 01b640f..2b6e6f6 100644
--- a/webrtc/modules/audio_processing/audio_processing_impl.h
+++ b/webrtc/modules/audio_processing/audio_processing_impl.h
@@ -13,13 +13,13 @@
#include <list>
#include <memory>
-#include <string>
#include <vector>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/function_view.h"
#include "webrtc/base/gtest_prod_util.h"
#include "webrtc/base/ignore_wundef.h"
+#include "webrtc/base/protobuf_utils.h"
#include "webrtc/base/swap_queue.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/modules/audio_processing/audio_buffer.h"
@@ -29,7 +29,7 @@
#include "webrtc/system_wrappers/include/file_wrapper.h"
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
-// Files generated at build-time by the protobuf compiler.
+// *.pb.h files are generated at build-time by the protobuf compiler.
RTC_PUSH_IGNORING_WUNDEF()
#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
#include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
@@ -200,10 +200,10 @@
ApmDebugDumpThreadState();
~ApmDebugDumpThreadState();
std::unique_ptr<audioproc::Event> event_msg; // Protobuf message.
- std::string event_str; // Memory for protobuf serialization.
+ ProtoString event_str; // Memory for protobuf serialization.
// Serialized string of last saved APM configuration.
- std::string last_serialized_config;
+ ProtoString last_serialized_config;
};
struct ApmDebugDumpState {
diff --git a/webrtc/modules/audio_processing/audio_processing_unittest.cc b/webrtc/modules/audio_processing/audio_processing_unittest.cc
index b52acce..814eea9 100644
--- a/webrtc/modules/audio_processing/audio_processing_unittest.cc
+++ b/webrtc/modules/audio_processing/audio_processing_unittest.cc
@@ -20,6 +20,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/gtest_prod_util.h"
#include "webrtc/base/ignore_wundef.h"
+#include "webrtc/base/protobuf_utils.h"
#include "webrtc/common_audio/include/audio_util.h"
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/common_audio/resampler/push_sinc_resampler.h"
@@ -58,7 +59,7 @@
// file. This is the typical case. When the file should be updated, it can
// be set to true with the command-line switch --write_ref_data.
bool write_ref_data = false;
-const google::protobuf::int32 kChannels[] = {1, 2};
+const int32_t kChannels[] = {1, 2};
const int kSampleRates[] = {8000, 16000, 32000, 48000};
#if defined(WEBRTC_AUDIOPROC_FIXED_PROFILE)
@@ -230,7 +231,7 @@
#endif
void OpenFileAndWriteMessage(const std::string filename,
- const ::google::protobuf::MessageLite& msg) {
+ const MessageLite& msg) {
FILE* file = fopen(filename.c_str(), "wb");
ASSERT_TRUE(file != NULL);
@@ -299,8 +300,7 @@
remove(kv.second.c_str());
}
-void OpenFileAndReadMessage(std::string filename,
- ::google::protobuf::MessageLite* msg) {
+void OpenFileAndReadMessage(std::string filename, MessageLite* msg) {
FILE* file = fopen(filename.c_str(), "rb");
ASSERT_TRUE(file != NULL);
ReadMessageFromFile(file, msg);
diff --git a/webrtc/modules/audio_processing/test/protobuf_utils.cc b/webrtc/modules/audio_processing/test/protobuf_utils.cc
index c18a13e..cb8adf9 100644
--- a/webrtc/modules/audio_processing/test/protobuf_utils.cc
+++ b/webrtc/modules/audio_processing/test/protobuf_utils.cc
@@ -30,7 +30,7 @@
}
// Returns true on success, false on error or end-of-file.
-bool ReadMessageFromFile(FILE* file, ::google::protobuf::MessageLite* msg) {
+bool ReadMessageFromFile(FILE* file, MessageLite* msg) {
std::unique_ptr<uint8_t[]> bytes;
size_t size = ReadMessageBytesFromFile(file, &bytes);
if (!size)
diff --git a/webrtc/modules/audio_processing/test/protobuf_utils.h b/webrtc/modules/audio_processing/test/protobuf_utils.h
index e132c94..8941338 100644
--- a/webrtc/modules/audio_processing/test/protobuf_utils.h
+++ b/webrtc/modules/audio_processing/test/protobuf_utils.h
@@ -14,6 +14,7 @@
#include <memory>
#include "webrtc/base/ignore_wundef.h"
+#include "webrtc/base/protobuf_utils.h"
RTC_PUSH_IGNORING_WUNDEF()
#include "webrtc/modules/audio_processing/debug.pb.h"
@@ -26,7 +27,7 @@
size_t ReadMessageBytesFromFile(FILE* file, std::unique_ptr<uint8_t[]>* bytes);
// Returns true on success, false on error or end-of-file.
-bool ReadMessageFromFile(FILE* file, ::google::protobuf::MessageLite* msg);
+bool ReadMessageFromFile(FILE* file, MessageLite* msg);
} // namespace webrtc