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

Unified Diff: webrtc/modules/audio_coding/codecs/audio_encoder.cc

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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/audio_encoder.cc
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.cc b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
index e99fc30995995dea55ba1bcae4347b784e4691f3..2384bf092995ade391006ebadd2fa68cb17d10c2 100644
--- a/webrtc/modules/audio_coding/codecs/audio_encoder.cc
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
@@ -26,17 +26,69 @@ int AudioEncoder::RtpTimestampRateHz() const {
AudioEncoder::EncodedInfo AudioEncoder::Encode(
uint32_t rtp_timestamp,
rtc::ArrayView<const int16_t> audio,
+ rtc::Buffer* encoded) {
+ TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
+
+ // ossu: I've seen this expressed in several different ways in checks inside
+ // ossu: EncodeInternal in implementations. Should this not suffice?
kwiberg-webrtc 2016/02/25 00:29:04 Well, maybe. But having an assert close to the cod
ossu 2016/02/25 15:58:46 Acknowledged.
+ RTC_CHECK_EQ(audio.size(),
+ static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
+
+ EncodedInfo info;
+ info = EncodeInternal(rtp_timestamp, audio, encoded);
+ return info;
kwiberg-webrtc 2016/02/25 00:29:04 You can eliminate the local variable and turn thes
ossu 2016/02/25 10:39:51 I believe I split this up while debugging and neve
kwiberg-webrtc 2016/02/25 12:24:25 The backwards-compatible EncodeInternal is only ca
ossu 2016/02/25 15:58:46 Ah, yes. Right you are!
+}
+
+AudioEncoder::EncodedInfo AudioEncoder::Encode(
+ uint32_t rtp_timestamp,
+ rtc::ArrayView<const int16_t> audio,
+ size_t max_encoded_bytes,
+ uint8_t* encoded) {
+ return DEPRECATED_Encode(rtp_timestamp, audio, max_encoded_bytes, encoded);
+}
+
+AudioEncoder::EncodedInfo AudioEncoder::DEPRECATED_Encode(
+ uint32_t rtp_timestamp,
+ rtc::ArrayView<const int16_t> audio,
size_t max_encoded_bytes,
uint8_t* encoded) {
TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
RTC_CHECK_EQ(audio.size(),
static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
EncodedInfo info =
- EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded);
+ EncodeInternal(rtp_timestamp, audio,
+ max_encoded_bytes, encoded);
RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes);
return info;
}
+AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal(
+ uint32_t rtp_timestamp,
+ rtc::ArrayView<const int16_t> audio,
+ rtc::Buffer* encoded)
+{
+ EncodedInfo info;
+ encoded->AppendData(MaxEncodedBytes(), [&] (rtc::ArrayView<uint8_t> encoded) {
+ info = EncodeInternal(rtp_timestamp, audio,
+ encoded.size(), encoded.data());
+ return info.encoded_bytes;
+ });
+ return info;
+}
+
+AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal(
+ uint32_t rtp_timestamp,
+ rtc::ArrayView<const int16_t> audio,
+ size_t max_encoded_bytes,
+ uint8_t* encoded)
+{
+ rtc::Buffer temp_buffer;
+ EncodedInfo info = EncodeInternal(rtp_timestamp, audio, &temp_buffer);
+ RTC_DCHECK_LE(temp_buffer.size(), max_encoded_bytes);
+ std::memcpy(encoded, temp_buffer.data(), info.encoded_bytes);
+ return info;
+}
+
bool AudioEncoder::SetFec(bool enable) {
return !enable;
}

Powered by Google App Engine
This is Rietveld 408576698