Added functional variants of Buffer::SetData and Buffer::AppendData.
They are invoked with the maximum size of the data to be added, and a
callable that generates that data, like this:
buffer.AppendData(10, [] (rtc::ArrayView<uint8_t> av) {
for (uint8_t i = 0; i != 5; ++i)
av[i] = i;
return 5;
});
The callable returns the number of bytes actually written, and the
final Buffer size will be adjusted accordingly. SetData and AppendData
both return the number of bytes added (i.e. the return value of the
callable).
These versions will be useful when converting AudioEncoder::Encode to use Buffer rather than raw pointers.
Also added a few tests for the new functionality.
Review URL: https://codereview.webrtc.org/1717273002
Cr-Commit-Position: refs/heads/master@{#11733}
diff --git a/webrtc/base/bufferqueue.cc b/webrtc/base/bufferqueue.cc
index 1ac57ab..9c2324e 100644
--- a/webrtc/base/bufferqueue.cc
+++ b/webrtc/base/bufferqueue.cc
@@ -10,6 +10,8 @@
#include "webrtc/base/bufferqueue.h"
+#include <algorithm>
+
namespace rtc {
BufferQueue::BufferQueue(size_t capacity, size_t default_size)