OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 "webrtc/modules/audio_coding/codecs/ilbc/include/audio_encoder_ilbc.h" | 11 #include "webrtc/modules/audio_coding/codecs/ilbc/include/audio_encoder_ilbc.h" |
12 | 12 |
13 #include <cstring> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
17 #include "webrtc/modules/audio_coding/codecs/ilbc/include/ilbc.h" | 17 #include "webrtc/modules/audio_coding/codecs/ilbc/include/ilbc.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kSampleRateHz = 8000; | 23 const int kSampleRateHz = 8000; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 case 3: case 6: | 84 case 3: case 6: |
85 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. | 85 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. |
86 return 13333; | 86 return 13333; |
87 default: | 87 default: |
88 FATAL(); | 88 FATAL(); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal( | 92 AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal( |
93 uint32_t rtp_timestamp, | 93 uint32_t rtp_timestamp, |
94 const int16_t* audio, | 94 rtc::ArrayView<const int16_t> audio, |
95 size_t max_encoded_bytes, | 95 size_t max_encoded_bytes, |
96 uint8_t* encoded) { | 96 uint8_t* encoded) { |
97 RTC_DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes()); | 97 RTC_DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes()); |
98 | 98 |
99 // Save timestamp if starting a new packet. | 99 // Save timestamp if starting a new packet. |
100 if (num_10ms_frames_buffered_ == 0) | 100 if (num_10ms_frames_buffered_ == 0) |
101 first_timestamp_in_buffer_ = rtp_timestamp; | 101 first_timestamp_in_buffer_ = rtp_timestamp; |
102 | 102 |
103 // Buffer input. | 103 // Buffer input. |
104 std::memcpy(input_buffer_ + kSampleRateHz / 100 * num_10ms_frames_buffered_, | 104 RTC_DCHECK_EQ(static_cast<size_t>(kSampleRateHz / 100), audio.size()); |
105 audio, | 105 std::copy(audio.cbegin(), audio.cend(), |
106 kSampleRateHz / 100 * sizeof(audio[0])); | 106 input_buffer_ + kSampleRateHz / 100 * num_10ms_frames_buffered_); |
107 | 107 |
108 // If we don't yet have enough buffered input for a whole packet, we're done | 108 // If we don't yet have enough buffered input for a whole packet, we're done |
109 // for now. | 109 // for now. |
110 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { | 110 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { |
111 return EncodedInfo(); | 111 return EncodedInfo(); |
112 } | 112 } |
113 | 113 |
114 // Encode buffered input. | 114 // Encode buffered input. |
115 RTC_DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); | 115 RTC_DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); |
116 num_10ms_frames_buffered_ = 0; | 116 num_10ms_frames_buffered_ = 0; |
(...skipping 27 matching lines...) Expand all Loading... |
144 switch (num_10ms_frames_per_packet_) { | 144 switch (num_10ms_frames_per_packet_) { |
145 case 2: return 38; | 145 case 2: return 38; |
146 case 3: return 50; | 146 case 3: return 50; |
147 case 4: return 2 * 38; | 147 case 4: return 2 * 38; |
148 case 6: return 2 * 50; | 148 case 6: return 2 * 50; |
149 default: FATAL(); | 149 default: FATAL(); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 } // namespace webrtc | 153 } // namespace webrtc |
OLD | NEW |