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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 } | 123 } |
124 | 124 |
125 size_t AudioEncoderOpus::Max10MsFramesInAPacket() const { | 125 size_t AudioEncoderOpus::Max10MsFramesInAPacket() const { |
126 return Num10msFramesPerPacket(); | 126 return Num10msFramesPerPacket(); |
127 } | 127 } |
128 | 128 |
129 int AudioEncoderOpus::GetTargetBitrate() const { | 129 int AudioEncoderOpus::GetTargetBitrate() const { |
130 return config_.bitrate_bps; | 130 return config_.bitrate_bps; |
131 } | 131 } |
132 | 132 |
133 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( | 133 AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( |
hlundin-webrtc
2016/02/29 12:46:47
Order no longer matches that of the .h file. I do
ossu
2016/02/29 13:23:01
Acknowledged.
| |
134 uint32_t rtp_timestamp, | 134 uint32_t rtp_timestamp, |
135 rtc::ArrayView<const int16_t> audio, | 135 rtc::ArrayView<const int16_t> audio, |
136 size_t max_encoded_bytes, | 136 rtc::Buffer* encoded) { |
137 uint8_t* encoded) { | 137 |
138 if (input_buffer_.empty()) | 138 if (input_buffer_.empty()) |
139 first_timestamp_in_buffer_ = rtp_timestamp; | 139 first_timestamp_in_buffer_ = rtp_timestamp; |
140 RTC_DCHECK_EQ(SamplesPer10msFrame(), audio.size()); | 140 |
141 input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); | 141 input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend()); |
142 if (input_buffer_.size() < | 142 if (input_buffer_.size() < |
143 (Num10msFramesPerPacket() * SamplesPer10msFrame())) { | 143 (Num10msFramesPerPacket() * SamplesPer10msFrame())) { |
144 return EncodedInfo(); | 144 return EncodedInfo(); |
145 } | 145 } |
146 RTC_CHECK_EQ(input_buffer_.size(), | 146 RTC_CHECK_EQ(input_buffer_.size(), |
147 Num10msFramesPerPacket() * SamplesPer10msFrame()); | 147 Num10msFramesPerPacket() * SamplesPer10msFrame()); |
148 int status = WebRtcOpus_Encode( | 148 |
149 inst_, &input_buffer_[0], | 149 const size_t max_encoded_bytes = MaxEncodedBytes(); |
150 rtc::CheckedDivExact(input_buffer_.size(), config_.num_channels), | 150 EncodedInfo info; |
151 rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded); | 151 info.encoded_bytes = |
152 RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. | 152 encoded->AppendData( |
153 max_encoded_bytes, [&] (rtc::ArrayView<uint8_t> encoded) { | |
154 int status = WebRtcOpus_Encode( | |
155 inst_, &input_buffer_[0], | |
156 rtc::CheckedDivExact(input_buffer_.size(), | |
157 config_.num_channels), | |
158 rtc::saturated_cast<int16_t>(max_encoded_bytes), | |
159 encoded.data()); | |
160 | |
161 RTC_CHECK_GE(status, 0); // Fails only if fed invalid data. | |
162 | |
163 return static_cast<size_t>(status); | |
164 }); | |
153 input_buffer_.clear(); | 165 input_buffer_.clear(); |
154 EncodedInfo info; | 166 |
155 info.encoded_bytes = static_cast<size_t>(status); | |
156 info.encoded_timestamp = first_timestamp_in_buffer_; | 167 info.encoded_timestamp = first_timestamp_in_buffer_; |
157 info.payload_type = config_.payload_type; | 168 info.payload_type = config_.payload_type; |
158 info.send_even_if_empty = true; // Allows Opus to send empty packets. | 169 info.send_even_if_empty = true; // Allows Opus to send empty packets. |
159 info.speech = (status > 0); | 170 info.speech = (info.encoded_bytes > 0); |
160 return info; | 171 return info; |
161 } | 172 } |
162 | 173 |
163 void AudioEncoderOpus::Reset() { | 174 void AudioEncoderOpus::Reset() { |
164 RTC_CHECK(RecreateEncoderInstance(config_)); | 175 RTC_CHECK(RecreateEncoderInstance(config_)); |
165 } | 176 } |
166 | 177 |
167 bool AudioEncoderOpus::SetFec(bool enable) { | 178 bool AudioEncoderOpus::SetFec(bool enable) { |
168 auto conf = config_; | 179 auto conf = config_; |
169 conf.fec_enabled = enable; | 180 conf.fec_enabled = enable; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); | 258 RTC_CHECK_EQ(0, WebRtcOpus_DisableDtx(inst_)); |
248 } | 259 } |
249 RTC_CHECK_EQ(0, | 260 RTC_CHECK_EQ(0, |
250 WebRtcOpus_SetPacketLossRate( | 261 WebRtcOpus_SetPacketLossRate( |
251 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); | 262 inst_, static_cast<int32_t>(packet_loss_rate_ * 100 + .5))); |
252 config_ = config; | 263 config_ = config; |
253 return true; | 264 return true; |
254 } | 265 } |
255 | 266 |
256 } // namespace webrtc | 267 } // namespace webrtc |
OLD | NEW |