audioproc_f: input AEC dump as string, output audio to vector
This CL adds the following options:
pass an input AEC dump as a string (currently, the tool can only accept a path to an AEC dump file)
write the processed capture samples to a given vector
Bug: webrtc:10808
Change-Id: I02863c97ec3cd8c03ade2ea8521836f2e7417050
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145208
Commit-Queue: Sonia-Florina Horchidan <soniahorchidan@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Reviewed-by: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Ivo Creusen <ivoc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28826}
diff --git a/modules/audio_processing/test/protobuf_utils.cc b/modules/audio_processing/test/protobuf_utils.cc
index f3c97ee..3042bce 100644
--- a/modules/audio_processing/test/protobuf_utils.cc
+++ b/modules/audio_processing/test/protobuf_utils.cc
@@ -10,8 +10,31 @@
#include "modules/audio_processing/test/protobuf_utils.h"
+#include "absl/memory/memory.h"
#include "rtc_base/system/arch.h"
+namespace {
+// Allocates new memory in the memory owned by the unique_ptr to fit the raw
+// message and returns the number of bytes read when having a string stream as
+// input.
+size_t ReadMessageBytesFromString(std::stringstream* input,
+ std::unique_ptr<uint8_t[]>* bytes) {
+ int32_t size = 0;
+ input->read(reinterpret_cast<char*>(&size), sizeof(int32_t));
+ int32_t size_read = input->gcount();
+ if (size_read != sizeof(int32_t))
+ return 0;
+ if (size <= 0)
+ return 0;
+
+ *bytes = absl::make_unique<uint8_t[]>(size);
+ input->read(reinterpret_cast<char*>(bytes->get()),
+ size * sizeof((*bytes)[0]));
+ size_read = input->gcount();
+ return size_read == size ? size : 0;
+}
+} // namespace
+
namespace webrtc {
size_t ReadMessageBytesFromFile(FILE* file, std::unique_ptr<uint8_t[]>* bytes) {
@@ -26,7 +49,7 @@
if (size <= 0)
return 0;
- bytes->reset(new uint8_t[size]);
+ *bytes = absl::make_unique<uint8_t[]>(size);
return fread(bytes->get(), sizeof((*bytes)[0]), size, file);
}
@@ -41,4 +64,15 @@
return msg->ParseFromArray(bytes.get(), size);
}
+// Returns true on success, false on error or end of string stream.
+bool ReadMessageFromString(std::stringstream* input, MessageLite* msg) {
+ std::unique_ptr<uint8_t[]> bytes;
+ size_t size = ReadMessageBytesFromString(input, &bytes);
+ if (!size)
+ return false;
+
+ msg->Clear();
+ return msg->ParseFromArray(bytes.get(), size);
+}
+
} // namespace webrtc