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

Side by Side Diff: webrtc/modules/audio_device/fine_audio_buffer.cc

Issue 2706923006: Now using rtc::Buffer in FineAudioBuffer (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_device/fine_audio_buffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 18 matching lines...) Expand all
29 samples_per_10_ms_(static_cast<size_t>(sample_rate_ * 10 / 1000)), 29 samples_per_10_ms_(static_cast<size_t>(sample_rate_ * 10 / 1000)),
30 bytes_per_10_ms_(samples_per_10_ms_ * sizeof(int16_t)), 30 bytes_per_10_ms_(samples_per_10_ms_ * sizeof(int16_t)),
31 playout_cached_buffer_start_(0), 31 playout_cached_buffer_start_(0),
32 playout_cached_bytes_(0), 32 playout_cached_bytes_(0),
33 // Allocate extra space on the recording side to reduce the number of 33 // Allocate extra space on the recording side to reduce the number of
34 // memmove() calls. 34 // memmove() calls.
35 required_record_buffer_size_bytes_( 35 required_record_buffer_size_bytes_(
36 5 * (desired_frame_size_bytes + bytes_per_10_ms_)), 36 5 * (desired_frame_size_bytes + bytes_per_10_ms_)),
37 record_cached_bytes_(0), 37 record_cached_bytes_(0),
38 record_read_pos_(0), 38 record_read_pos_(0),
39 record_write_pos_(0) { 39 record_buffer_(0, required_record_buffer_size_bytes_) {
40 playout_cache_buffer_.reset(new int8_t[bytes_per_10_ms_]); 40 playout_cache_buffer_.reset(new int8_t[bytes_per_10_ms_]);
41 record_cache_buffer_.reset(new int8_t[required_record_buffer_size_bytes_]);
42 memset(record_cache_buffer_.get(), 0, required_record_buffer_size_bytes_);
43 } 41 }
44 42
45 FineAudioBuffer::~FineAudioBuffer() {} 43 FineAudioBuffer::~FineAudioBuffer() {}
46 44
47 size_t FineAudioBuffer::RequiredPlayoutBufferSizeBytes() { 45 size_t FineAudioBuffer::RequiredPlayoutBufferSizeBytes() {
48 // It is possible that we store the desired frame size - 1 samples. Since new 46 // It is possible that we store the desired frame size - 1 samples. Since new
49 // audio frames are pulled in chunks of 10ms we will need a buffer that can 47 // audio frames are pulled in chunks of 10ms we will need a buffer that can
50 // hold desired_frame_size - 1 + 10ms of data. We omit the - 1. 48 // hold desired_frame_size - 1 + 10ms of data. We omit the - 1.
51 return desired_frame_size_bytes_ + bytes_per_10_ms_; 49 return desired_frame_size_bytes_ + bytes_per_10_ms_;
52 } 50 }
53 51
54 void FineAudioBuffer::ResetPlayout() { 52 void FineAudioBuffer::ResetPlayout() {
55 playout_cached_buffer_start_ = 0; 53 playout_cached_buffer_start_ = 0;
56 playout_cached_bytes_ = 0; 54 playout_cached_bytes_ = 0;
57 memset(playout_cache_buffer_.get(), 0, bytes_per_10_ms_); 55 memset(playout_cache_buffer_.get(), 0, bytes_per_10_ms_);
58 } 56 }
59 57
60 void FineAudioBuffer::ResetRecord() { 58 void FineAudioBuffer::ResetRecord() {
61 record_cached_bytes_ = 0; 59 record_cached_bytes_ = 0;
62 record_read_pos_ = 0; 60 record_read_pos_ = 0;
63 record_write_pos_ = 0; 61 record_buffer_.Clear();
64 memset(record_cache_buffer_.get(), 0, required_record_buffer_size_bytes_);
65 } 62 }
66 63
67 void FineAudioBuffer::GetPlayoutData(int8_t* buffer) { 64 void FineAudioBuffer::GetPlayoutData(int8_t* buffer) {
68 if (desired_frame_size_bytes_ <= playout_cached_bytes_) { 65 if (desired_frame_size_bytes_ <= playout_cached_bytes_) {
69 memcpy(buffer, &playout_cache_buffer_.get()[playout_cached_buffer_start_], 66 memcpy(buffer, &playout_cache_buffer_.get()[playout_cached_buffer_start_],
70 desired_frame_size_bytes_); 67 desired_frame_size_bytes_);
71 playout_cached_buffer_start_ += desired_frame_size_bytes_; 68 playout_cached_buffer_start_ += desired_frame_size_bytes_;
72 playout_cached_bytes_ -= desired_frame_size_bytes_; 69 playout_cached_bytes_ -= desired_frame_size_bytes_;
73 RTC_CHECK_LT(playout_cached_buffer_start_ + playout_cached_bytes_, 70 RTC_CHECK_LT(playout_cached_buffer_start_ + playout_cached_bytes_,
74 bytes_per_10_ms_); 71 bytes_per_10_ms_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 memcpy(playout_cache_buffer_.get(), cache_ptr, playout_cached_bytes_); 108 memcpy(playout_cache_buffer_.get(), cache_ptr, playout_cached_bytes_);
112 } 109 }
113 110
114 void FineAudioBuffer::DeliverRecordedData(const int8_t* buffer, 111 void FineAudioBuffer::DeliverRecordedData(const int8_t* buffer,
115 size_t size_in_bytes, 112 size_t size_in_bytes,
116 int playout_delay_ms, 113 int playout_delay_ms,
117 int record_delay_ms) { 114 int record_delay_ms) {
118 // Check if the temporary buffer can store the incoming buffer. If not, 115 // Check if the temporary buffer can store the incoming buffer. If not,
119 // move the remaining (old) bytes to the beginning of the temporary buffer 116 // move the remaining (old) bytes to the beginning of the temporary buffer
120 // and start adding new samples after the old samples. 117 // and start adding new samples after the old samples.
121 if (record_write_pos_ + size_in_bytes > required_record_buffer_size_bytes_) { 118 if (record_buffer_.size() + size_in_bytes > record_buffer_.capacity()) {
122 if (record_cached_bytes_ > 0) { 119 if (record_cached_bytes_ > 0) {
123 memmove(record_cache_buffer_.get(), 120 memmove(record_buffer_.data(),
124 record_cache_buffer_.get() + record_read_pos_, 121 record_buffer_.data() + record_read_pos_,
125 record_cached_bytes_); 122 record_cached_bytes_);
126 } 123 }
127 record_write_pos_ = record_cached_bytes_; 124 record_buffer_.SetSize(record_cached_bytes_);
128 record_read_pos_ = 0; 125 record_read_pos_ = 0;
129 } 126 }
130 // Add recorded samples to a temporary buffer. 127 // Add recorded samples to a temporary buffer.
131 memcpy(record_cache_buffer_.get() + record_write_pos_, buffer, size_in_bytes); 128 record_buffer_.AppendData(buffer, size_in_bytes);
kwiberg-webrtc 2017/02/22 15:25:39 I don't think this is quite right. .capacity() is
henrika_webrtc 2017/02/22 16:30:25 Great comments. Will fix!
132 record_write_pos_ += size_in_bytes;
133 record_cached_bytes_ += size_in_bytes; 129 record_cached_bytes_ += size_in_bytes;
134 // Consume samples in temporary buffer in chunks of 10ms until there is not 130 // Consume samples in temporary buffer in chunks of 10ms until there is not
135 // enough data left. The number of remaining bytes in the cache is given by 131 // enough data left. The number of remaining bytes in the cache is given by
136 // |record_cached_bytes_| after this while loop is done. 132 // |record_cached_bytes_| after this while loop is done.
137 while (record_cached_bytes_ >= bytes_per_10_ms_) { 133 while (record_cached_bytes_ >= bytes_per_10_ms_) {
138 device_buffer_->SetRecordedBuffer( 134 device_buffer_->SetRecordedBuffer(
139 record_cache_buffer_.get() + record_read_pos_, samples_per_10_ms_); 135 record_buffer_.data() + record_read_pos_, samples_per_10_ms_);
140 device_buffer_->SetVQEData(playout_delay_ms, record_delay_ms, 0); 136 device_buffer_->SetVQEData(playout_delay_ms, record_delay_ms, 0);
141 device_buffer_->DeliverRecordedData(); 137 device_buffer_->DeliverRecordedData();
142 // Read next chunk of 10ms data. 138 // Read next chunk of 10ms data.
143 record_read_pos_ += bytes_per_10_ms_; 139 record_read_pos_ += bytes_per_10_ms_;
144 // Reduce number of cached bytes with the consumed amount. 140 // Reduce number of cached bytes with the consumed amount.
145 record_cached_bytes_ -= bytes_per_10_ms_; 141 record_cached_bytes_ -= bytes_per_10_ms_;
146 } 142 }
147 } 143 }
148 144
149 } // namespace webrtc 145 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/fine_audio_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698