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 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 size_t AudioEncoderCng::Max10MsFramesInAPacket() const { | 90 size_t AudioEncoderCng::Max10MsFramesInAPacket() const { |
91 return speech_encoder_->Max10MsFramesInAPacket(); | 91 return speech_encoder_->Max10MsFramesInAPacket(); |
92 } | 92 } |
93 | 93 |
94 int AudioEncoderCng::GetTargetBitrate() const { | 94 int AudioEncoderCng::GetTargetBitrate() const { |
95 return speech_encoder_->GetTargetBitrate(); | 95 return speech_encoder_->GetTargetBitrate(); |
96 } | 96 } |
97 | 97 |
98 AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal( | 98 AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal( |
99 uint32_t rtp_timestamp, | 99 uint32_t rtp_timestamp, |
100 const int16_t* audio, | 100 rtc::ArrayView<const int16_t> audio, |
101 size_t max_encoded_bytes, | 101 size_t max_encoded_bytes, |
102 uint8_t* encoded) { | 102 uint8_t* encoded) { |
103 RTC_CHECK_GE(max_encoded_bytes, | 103 RTC_CHECK_GE(max_encoded_bytes, |
104 static_cast<size_t>(num_cng_coefficients_ + 1)); | 104 static_cast<size_t>(num_cng_coefficients_ + 1)); |
105 const size_t samples_per_10ms_frame = SamplesPer10msFrame(); | 105 const size_t samples_per_10ms_frame = SamplesPer10msFrame(); |
106 RTC_CHECK_EQ(speech_buffer_.size(), | 106 RTC_CHECK_EQ(speech_buffer_.size(), |
107 rtp_timestamps_.size() * samples_per_10ms_frame); | 107 rtp_timestamps_.size() * samples_per_10ms_frame); |
108 rtp_timestamps_.push_back(rtp_timestamp); | 108 rtp_timestamps_.push_back(rtp_timestamp); |
109 for (size_t i = 0; i < samples_per_10ms_frame; ++i) { | 109 RTC_DCHECK_EQ(samples_per_10ms_frame, audio.size()); |
110 speech_buffer_.push_back(audio[i]); | 110 speech_buffer_.insert(speech_buffer_.end(), audio.cbegin(), audio.cend()); |
111 } | |
112 const size_t frames_to_encode = speech_encoder_->Num10MsFramesInNextPacket(); | 111 const size_t frames_to_encode = speech_encoder_->Num10MsFramesInNextPacket(); |
113 if (rtp_timestamps_.size() < frames_to_encode) { | 112 if (rtp_timestamps_.size() < frames_to_encode) { |
114 return EncodedInfo(); | 113 return EncodedInfo(); |
115 } | 114 } |
116 RTC_CHECK_LE(static_cast<int>(frames_to_encode * 10), kMaxFrameSizeMs) | 115 RTC_CHECK_LE(static_cast<int>(frames_to_encode * 10), kMaxFrameSizeMs) |
117 << "Frame size cannot be larger than " << kMaxFrameSizeMs | 116 << "Frame size cannot be larger than " << kMaxFrameSizeMs |
118 << " ms when using VAD/CNG."; | 117 << " ms when using VAD/CNG."; |
119 | 118 |
120 // Group several 10 ms blocks per VAD call. Call VAD once or twice using the | 119 // Group several 10 ms blocks per VAD call. Call VAD once or twice using the |
121 // following split sizes: | 120 // following split sizes: |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return info; | 234 return info; |
236 } | 235 } |
237 | 236 |
238 AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive( | 237 AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive( |
239 size_t frames_to_encode, | 238 size_t frames_to_encode, |
240 size_t max_encoded_bytes, | 239 size_t max_encoded_bytes, |
241 uint8_t* encoded) { | 240 uint8_t* encoded) { |
242 const size_t samples_per_10ms_frame = SamplesPer10msFrame(); | 241 const size_t samples_per_10ms_frame = SamplesPer10msFrame(); |
243 AudioEncoder::EncodedInfo info; | 242 AudioEncoder::EncodedInfo info; |
244 for (size_t i = 0; i < frames_to_encode; ++i) { | 243 for (size_t i = 0; i < frames_to_encode; ++i) { |
245 info = speech_encoder_->Encode( | 244 info = |
246 rtp_timestamps_.front(), &speech_buffer_[i * samples_per_10ms_frame], | 245 speech_encoder_->Encode(rtp_timestamps_.front(), |
247 samples_per_10ms_frame, max_encoded_bytes, encoded); | 246 rtc::ArrayView<const int16_t>( |
| 247 &speech_buffer_[i * samples_per_10ms_frame], |
| 248 samples_per_10ms_frame), |
| 249 max_encoded_bytes, encoded); |
248 if (i + 1 == frames_to_encode) { | 250 if (i + 1 == frames_to_encode) { |
249 RTC_CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data."; | 251 RTC_CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data."; |
250 } else { | 252 } else { |
251 RTC_CHECK_EQ(info.encoded_bytes, 0u) | 253 RTC_CHECK_EQ(info.encoded_bytes, 0u) |
252 << "Encoder delivered data too early."; | 254 << "Encoder delivered data too early."; |
253 } | 255 } |
254 } | 256 } |
255 return info; | 257 return info; |
256 } | 258 } |
257 | 259 |
258 size_t AudioEncoderCng::SamplesPer10msFrame() const { | 260 size_t AudioEncoderCng::SamplesPer10msFrame() const { |
259 return rtc::CheckedDivExact(10 * SampleRateHz(), 1000); | 261 return rtc::CheckedDivExact(10 * SampleRateHz(), 1000); |
260 } | 262 } |
261 | 263 |
262 } // namespace webrtc | 264 } // namespace webrtc |
OLD | NEW |