OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 #include <assert.h> | |
12 | |
13 #include <algorithm> // Access to min. | 11 #include <algorithm> // Access to min. |
14 | 12 |
| 13 #include "webrtc/base/checks.h" |
15 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 14 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
16 | 15 |
17 namespace webrtc { | 16 namespace webrtc { |
18 | 17 |
19 size_t SyncBuffer::FutureLength() const { | 18 size_t SyncBuffer::FutureLength() const { |
20 return Size() - next_index_; | 19 return Size() - next_index_; |
21 } | 20 } |
22 | 21 |
23 void SyncBuffer::PushBack(const AudioMultiVector& append_this) { | 22 void SyncBuffer::PushBack(const AudioMultiVector& append_this) { |
24 size_t samples_added = append_this.Size(); | 23 size_t samples_added = append_this.Size(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 position = std::min(position, Size()); // Cap |position| in the valid range. | 63 position = std::min(position, Size()); // Cap |position| in the valid range. |
65 length = std::min(length, Size() - position); | 64 length = std::min(length, Size() - position); |
66 AudioMultiVector::OverwriteAt(insert_this, length, position); | 65 AudioMultiVector::OverwriteAt(insert_this, length, position); |
67 } | 66 } |
68 | 67 |
69 void SyncBuffer::ReplaceAtIndex(const AudioMultiVector& insert_this, | 68 void SyncBuffer::ReplaceAtIndex(const AudioMultiVector& insert_this, |
70 size_t position) { | 69 size_t position) { |
71 ReplaceAtIndex(insert_this, insert_this.Size(), position); | 70 ReplaceAtIndex(insert_this, insert_this.Size(), position); |
72 } | 71 } |
73 | 72 |
74 size_t SyncBuffer::GetNextAudioInterleaved(size_t requested_len, | 73 void SyncBuffer::GetNextAudioInterleaved(size_t requested_len, |
75 int16_t* output) { | 74 AudioFrame* output) { |
76 if (!output) { | 75 RTC_DCHECK(output); |
77 assert(false); | 76 const size_t samples_to_read = std::min(FutureLength(), requested_len); |
78 return 0; | 77 output->Reset(); |
79 } | 78 const size_t tot_samples_read = |
80 size_t samples_to_read = std::min(FutureLength(), requested_len); | 79 ReadInterleavedFromIndex(next_index_, samples_to_read, output->data_); |
81 ReadInterleavedFromIndex(next_index_, samples_to_read, output); | 80 const size_t samples_read_per_channel = tot_samples_read / Channels(); |
82 next_index_ += samples_to_read; | 81 next_index_ += samples_read_per_channel; |
83 return samples_to_read; | 82 output->interleaved_ = true; |
| 83 output->num_channels_ = Channels(); |
| 84 output->samples_per_channel_ = samples_read_per_channel; |
84 } | 85 } |
85 | 86 |
86 void SyncBuffer::IncreaseEndTimestamp(uint32_t increment) { | 87 void SyncBuffer::IncreaseEndTimestamp(uint32_t increment) { |
87 end_timestamp_ += increment; | 88 end_timestamp_ += increment; |
88 } | 89 } |
89 | 90 |
90 void SyncBuffer::Flush() { | 91 void SyncBuffer::Flush() { |
91 Zeros(Size()); | 92 Zeros(Size()); |
92 next_index_ = Size(); | 93 next_index_ = Size(); |
93 end_timestamp_ = 0; | 94 end_timestamp_ = 0; |
94 dtmf_index_ = 0; | 95 dtmf_index_ = 0; |
95 } | 96 } |
96 | 97 |
97 void SyncBuffer::set_next_index(size_t value) { | 98 void SyncBuffer::set_next_index(size_t value) { |
98 // Cannot set |next_index_| larger than the size of the buffer. | 99 // Cannot set |next_index_| larger than the size of the buffer. |
99 next_index_ = std::min(value, Size()); | 100 next_index_ = std::min(value, Size()); |
100 } | 101 } |
101 | 102 |
102 void SyncBuffer::set_dtmf_index(size_t value) { | 103 void SyncBuffer::set_dtmf_index(size_t value) { |
103 // Cannot set |dtmf_index_| larger than the size of the buffer. | 104 // Cannot set |dtmf_index_| larger than the size of the buffer. |
104 dtmf_index_ = std::min(value, Size()); | 105 dtmf_index_ = std::min(value, Size()); |
105 } | 106 } |
106 | 107 |
107 } // namespace webrtc | 108 } // namespace webrtc |
OLD | NEW |