Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1814)

Unified Diff: webrtc/modules/audio_device/fine_audio_buffer.cc

Issue 1254883002: Refactor the AudioDevice for iOS and improve the performance and stability (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Extended unit test for FineAudioBuffer with recorded data Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_device/fine_audio_buffer.cc
diff --git a/webrtc/modules/audio_device/android/fine_audio_buffer.cc b/webrtc/modules/audio_device/fine_audio_buffer.cc
similarity index 59%
rename from webrtc/modules/audio_device/android/fine_audio_buffer.cc
rename to webrtc/modules/audio_device/fine_audio_buffer.cc
index 37f994b800b1b987f82224ab19249e26aa75598b..3419b2560757d8d244d129785db00beb303a79ce 100644
--- a/webrtc/modules/audio_device/android/fine_audio_buffer.cc
+++ b/webrtc/modules/audio_device/fine_audio_buffer.cc
@@ -8,13 +8,14 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "webrtc/modules/audio_device/android/fine_audio_buffer.h"
+#include "webrtc/modules/audio_device/fine_audio_buffer.h"
#include <memory.h>
#include <stdio.h>
#include <algorithm>
#include "webrtc/base/checks.h"
+#include "webrtc/base/logging.h"
#include "webrtc/modules/audio_device/audio_device_buffer.h"
namespace webrtc {
@@ -28,21 +29,38 @@ FineAudioBuffer::FineAudioBuffer(AudioDeviceBuffer* device_buffer,
samples_per_10_ms_(static_cast<size_t>(sample_rate_ * 10 / 1000)),
bytes_per_10_ms_(samples_per_10_ms_ * sizeof(int16_t)),
cached_buffer_start_(0),
- cached_bytes_(0) {
+ cached_bytes_(0),
tkchin_webrtc 2015/09/01 20:54:49 nit: consider naming this playout_cached_bytes_
henrika_webrtc 2015/09/03 13:44:41 Done.
+ record_cached_bytes_(0) {
cache_buffer_.reset(new int8_t[bytes_per_10_ms_]);
tkchin_webrtc 2015/09/01 20:54:49 nit: consider naming this playout_cache_buffer_ to
henrika_webrtc 2015/09/03 13:44:41 Done.
+ record_cache_buffer_.reset(
+ new int8_t[desired_frame_size_bytes + bytes_per_10_ms_]);
tkchin_webrtc 2015/09/01 20:54:49 nit: pull out size into a local var since it's the
henrika_webrtc 2015/09/03 13:44:41 Thanks. Done.
+ memset(record_cache_buffer_.get(), 0,
+ desired_frame_size_bytes + bytes_per_10_ms_);
}
FineAudioBuffer::~FineAudioBuffer() {
}
-size_t FineAudioBuffer::RequiredBufferSizeBytes() {
+size_t FineAudioBuffer::RequiredPlayoutBufferSizeBytes() {
// It is possible that we store the desired frame size - 1 samples. Since new
// audio frames are pulled in chunks of 10ms we will need a buffer that can
// hold desired_frame_size - 1 + 10ms of data. We omit the - 1.
return desired_frame_size_bytes_ + bytes_per_10_ms_;
}
-void FineAudioBuffer::GetBufferData(int8_t* buffer) {
+void FineAudioBuffer::ResetPlayout() {
+ cached_buffer_start_ = 0;
+ cached_bytes_ = 0;
+ memset(cache_buffer_.get(), 0, bytes_per_10_ms_);
+}
+
+void FineAudioBuffer::ResetRecord() {
+ record_cached_bytes_ = 0;
+ memset(record_cache_buffer_.get(), 0,
+ desired_frame_size_bytes_ + bytes_per_10_ms_);
+}
+
+void FineAudioBuffer::GetPlayoutData(int8_t* buffer) {
if (desired_frame_size_bytes_ <= cached_bytes_) {
memcpy(buffer, &cache_buffer_.get()[cached_buffer_start_],
desired_frame_size_bytes_);
@@ -69,7 +87,7 @@ void FineAudioBuffer::GetBufferData(int8_t* buffer) {
}
unwritten_buffer += bytes_per_10_ms_;
CHECK_GE(bytes_left, 0);
- bytes_left -= bytes_per_10_ms_;
+ bytes_left -= static_cast<int>(bytes_per_10_ms_);
}
CHECK_LE(bytes_left, 0);
// Put the samples that were written to |buffer| but are not used in the
@@ -77,7 +95,7 @@ void FineAudioBuffer::GetBufferData(int8_t* buffer) {
size_t cache_location = desired_frame_size_bytes_;
int8_t* cache_ptr = &buffer[cache_location];
cached_bytes_ = number_of_requests * bytes_per_10_ms_ -
- (desired_frame_size_bytes_ - cached_bytes_);
+ (desired_frame_size_bytes_ - cached_bytes_);
// If cached_bytes_ is larger than the cache buffer, uninitialized memory
// will be read.
CHECK_LE(cached_bytes_, bytes_per_10_ms_);
@@ -86,4 +104,31 @@ void FineAudioBuffer::GetBufferData(int8_t* buffer) {
memcpy(cache_buffer_.get(), cache_ptr, cached_bytes_);
}
+void FineAudioBuffer::DeliverRecordedData(const int8_t* buffer,
+ size_t size_in_bytes,
+ int playout_delay_ms,
+ int record_delay_ms) {
+ CHECK_EQ(size_in_bytes, desired_frame_size_bytes_);
+ // Store the recorded sampled in a temporary buffer.
+ memcpy(record_cache_buffer_.get() + record_cached_bytes_, buffer,
+ size_in_bytes);
+ record_cached_bytes_ += size_in_bytes;
+ // Ensure that we don't write outside the boundaries.
+ CHECK_LE(record_cached_bytes_, desired_frame_size_bytes_ + bytes_per_10_ms_);
+ // Consume samples in temporary buffer in chunks of 10ms until there is not
+ // enough data left. Any remaining part is moved to the beginning of the
+ // temporary buffer and |record_cached_bytes_| points to the first byte where
+ // new data can be stored.
+ while (record_cached_bytes_ >= bytes_per_10_ms_) {
+ device_buffer_->SetRecordedBuffer(record_cache_buffer_.get(),
+ samples_per_10_ms_);
+ device_buffer_->SetVQEData(playout_delay_ms, record_delay_ms, 0);
+ device_buffer_->DeliverRecordedData();
+ memmove(record_cache_buffer_.get(),
tkchin_webrtc 2015/09/01 20:54:49 Isn't this expensive? Performs a copy of all remai
henrika_webrtc 2015/09/03 13:44:41 I have modified the existing scheme by extending t
+ record_cache_buffer_.get() + bytes_per_10_ms_,
+ record_cached_bytes_ - bytes_per_10_ms_);
+ record_cached_bytes_ -= bytes_per_10_ms_;
+ }
+}
+
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698