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

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h

Issue 1725143003: Changed AudioEncoder::Encode to take an rtc::Buffer* instead of uint8_t* and a maximum size. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reverted unnecessary change to buffer_unittest.cc Created 4 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
OLDNEW
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 int AudioEncoderIsacT<T>::GetTargetBitrate() const { 110 int AudioEncoderIsacT<T>::GetTargetBitrate() const {
111 if (config_.adaptive_mode) 111 if (config_.adaptive_mode)
112 return -1; 112 return -1;
113 return config_.bit_rate == 0 ? kDefaultBitRate : config_.bit_rate; 113 return config_.bit_rate == 0 ? kDefaultBitRate : config_.bit_rate;
114 } 114 }
115 115
116 template <typename T> 116 template <typename T>
117 AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeInternal( 117 AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeInternal(
118 uint32_t rtp_timestamp, 118 uint32_t rtp_timestamp,
119 rtc::ArrayView<const int16_t> audio, 119 rtc::ArrayView<const int16_t> audio,
120 size_t max_encoded_bytes, 120 rtc::Buffer* encoded) {
121 uint8_t* encoded) {
122 if (!packet_in_progress_) { 121 if (!packet_in_progress_) {
123 // Starting a new packet; remember the timestamp for later. 122 // Starting a new packet; remember the timestamp for later.
124 packet_in_progress_ = true; 123 packet_in_progress_ = true;
125 packet_timestamp_ = rtp_timestamp; 124 packet_timestamp_ = rtp_timestamp;
126 } 125 }
127 if (bwinfo_) { 126 if (bwinfo_) {
128 IsacBandwidthInfo bwinfo = bwinfo_->Get(); 127 IsacBandwidthInfo bwinfo = bwinfo_->Get();
129 T::SetBandwidthInfo(isac_state_, &bwinfo); 128 T::SetBandwidthInfo(isac_state_, &bwinfo);
130 } 129 }
131 int r = T::Encode(isac_state_, audio.data(), encoded);
132 RTC_CHECK_GE(r, 0) << "Encode failed (error code "
133 << T::GetErrorCode(isac_state_) << ")";
134 130
135 // T::Encode doesn't allow us to tell it the size of the output 131 size_t encoded_bytes =
136 // buffer. All we can do is check for an overrun after the fact. 132 encoded->AppendData(kSufficientEncodeBufferSizeBytes,
137 RTC_CHECK_LE(static_cast<size_t>(r), max_encoded_bytes); 133 [&] (rtc::ArrayView<uint8_t> encoded) {
ossu 2016/02/24 13:24:34 This check should now be covered by the overrun ch
kwiberg-webrtc 2016/02/25 00:29:04 Acknowledged.
134 int r = T::Encode(isac_state_, audio.data(),
135 encoded.data());
138 136
139 if (r == 0) 137 RTC_CHECK_GE(r, 0) << "Encode failed (error code "
138 << T::GetErrorCode(isac_state_) << ")";
kwiberg-webrtc 2016/02/25 00:29:04 Indentation looks off. Did you run clang-format?
ossu 2016/02/25 10:39:51 I did not, though I've been using google-c-style.e
139
140 return (r >= 0) ? static_cast<size_t>(r) : 0;
kwiberg-webrtc 2016/02/25 00:29:04 Just static_cast<size_t>(r) will do, because of th
ossu 2016/02/25 10:39:51 Acknowledged.
141 });
142
143 if (encoded_bytes == 0)
140 return EncodedInfo(); 144 return EncodedInfo();
141 145
142 // Got enough input to produce a packet. Return the saved timestamp from 146 // Got enough input to produce a packet. Return the saved timestamp from
143 // the first chunk of input that went into the packet. 147 // the first chunk of input that went into the packet.
144 packet_in_progress_ = false; 148 packet_in_progress_ = false;
145 EncodedInfo info; 149 EncodedInfo info;
146 info.encoded_bytes = r; 150 info.encoded_bytes = encoded_bytes;
147 info.encoded_timestamp = packet_timestamp_; 151 info.encoded_timestamp = packet_timestamp_;
148 info.payload_type = config_.payload_type; 152 info.payload_type = config_.payload_type;
149 return info; 153 return info;
150 } 154 }
151 155
152 template <typename T> 156 template <typename T>
153 void AudioEncoderIsacT<T>::Reset() { 157 void AudioEncoderIsacT<T>::Reset() {
154 RecreateEncoderInstance(config_); 158 RecreateEncoderInstance(config_);
155 } 159 }
156 160
(...skipping 25 matching lines...) Expand all
182 // we get an encoding that isn't bit-for-bit identical with what a combined 186 // we get an encoding that isn't bit-for-bit identical with what a combined
183 // encoder+decoder object produces. 187 // encoder+decoder object produces.
184 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); 188 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz));
185 189
186 config_ = config; 190 config_ = config;
187 } 191 }
188 192
189 } // namespace webrtc 193 } // namespace webrtc
190 194
191 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ 195 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698