aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Wiberg <kwiberg@webrtc.org>2015-04-23 13:53:22 +0200
committerKarl Wiberg <kwiberg@webrtc.org>2015-04-23 11:53:02 +0000
commit92f9eacd1353f04df61c9b52046fb34572742f6a (patch)
tree71cd3269de837f6c8bef0cb1a41a1b5a351d422e
parent261f644ce3ea239871516679abfd14dd5e8da784 (diff)
downloadwebrtc-92f9eacd1353f04df61c9b52046fb34572742f6a.tar.gz
g722 and red encoders: Use rtc::Buffer instead of scoped_ptr<uint8_t[]>
It's a win for red, and a toss-up for g722 since it never resizes its buffer. R=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45219005 Cr-Commit-Position: refs/heads/master@{#9067}
-rw-r--r--webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc16
-rw-r--r--webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h5
-rw-r--r--webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc13
-rw-r--r--webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h4
4 files changed, 17 insertions, 21 deletions
diff --git a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc
index 68e8e084a1..a9fa25f0ef 100644
--- a/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc
+++ b/webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc
@@ -38,14 +38,14 @@ AudioEncoderG722::AudioEncoderG722(const Config& config)
num_10ms_frames_buffered_(0),
first_timestamp_in_buffer_(0),
encoders_(new EncoderState[num_channels_]),
- interleave_buffer_(new uint8_t[2 * num_channels_]) {
+ interleave_buffer_(2 * num_channels_) {
CHECK_EQ(config.frame_size_ms % 10, 0)
<< "Frame size must be an integer multiple of 10 ms.";
const int samples_per_channel =
kSampleRateHz / 100 * num_10ms_frames_per_packet_;
for (int i = 0; i < num_channels_; ++i) {
encoders_[i].speech_buffer.reset(new int16_t[samples_per_channel]);
- encoders_[i].encoded_buffer.reset(new uint8_t[samples_per_channel / 2]);
+ encoders_[i].encoded_buffer.SetSize(samples_per_channel / 2);
}
}
@@ -105,7 +105,7 @@ AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal(
for (int i = 0; i < num_channels_; ++i) {
const int encoded = WebRtcG722_Encode(
encoders_[i].encoder, encoders_[i].speech_buffer.get(),
- samples_per_channel, encoders_[i].encoded_buffer.get());
+ samples_per_channel, encoders_[i].encoded_buffer.data<uint8_t>());
CHECK_GE(encoded, 0);
CHECK_EQ(encoded, samples_per_channel / 2);
}
@@ -115,13 +115,13 @@ AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal(
// significant half first.
for (int i = 0; i < samples_per_channel / 2; ++i) {
for (int j = 0; j < num_channels_; ++j) {
- uint8_t two_samples = encoders_[j].encoded_buffer[i];
- interleave_buffer_[j] = two_samples >> 4;
- interleave_buffer_[num_channels_ + j] = two_samples & 0xf;
+ uint8_t two_samples = encoders_[j].encoded_buffer.data()[i];
+ interleave_buffer_.data()[j] = two_samples >> 4;
+ interleave_buffer_.data()[num_channels_ + j] = two_samples & 0xf;
}
for (int j = 0; j < num_channels_; ++j)
- encoded[i * num_channels_ + j] =
- interleave_buffer_[2 * j] << 4 | interleave_buffer_[2 * j + 1];
+ encoded[i * num_channels_ + j] = interleave_buffer_.data()[2 * j] << 4 |
+ interleave_buffer_.data()[2 * j + 1];
}
EncodedInfo info;
info.encoded_bytes = samples_per_channel / 2 * num_channels_;
diff --git a/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h b/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h
index b1be6b952e..ba6e5dde67 100644
--- a/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h
+++ b/webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h
@@ -11,6 +11,7 @@
#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_INCLUDE_AUDIO_ENCODER_G722_H_
#define WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_INCLUDE_AUDIO_ENCODER_G722_H_
+#include "webrtc/base/buffer.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
@@ -48,7 +49,7 @@ class AudioEncoderG722 : public AudioEncoder {
struct EncoderState {
G722EncInst* encoder;
rtc::scoped_ptr<int16_t[]> speech_buffer; // Queued up for encoding.
- rtc::scoped_ptr<uint8_t[]> encoded_buffer; // Already encoded.
+ rtc::Buffer encoded_buffer; // Already encoded.
EncoderState();
~EncoderState();
};
@@ -61,7 +62,7 @@ class AudioEncoderG722 : public AudioEncoder {
int num_10ms_frames_buffered_;
uint32_t first_timestamp_in_buffer_;
const rtc::scoped_ptr<EncoderState[]> encoders_;
- const rtc::scoped_ptr<uint8_t[]> interleave_buffer_;
+ rtc::Buffer interleave_buffer_;
};
} // namespace webrtc
diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc
index 86f1158d9d..cc657a6838 100644
--- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc
+++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.cc
@@ -18,8 +18,7 @@ namespace webrtc {
AudioEncoderCopyRed::AudioEncoderCopyRed(const Config& config)
: speech_encoder_(config.speech_encoder),
- red_payload_type_(config.payload_type),
- secondary_allocated_(0) {
+ red_payload_type_(config.payload_type) {
CHECK(speech_encoder_) << "Speech encoder not provided.";
}
@@ -79,18 +78,14 @@ AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeInternal(
info.redundant.push_back(info);
DCHECK_EQ(info.redundant.size(), 1u);
if (secondary_info_.encoded_bytes > 0) {
- memcpy(&encoded[info.encoded_bytes], secondary_encoded_.get(),
+ memcpy(&encoded[info.encoded_bytes], secondary_encoded_.data(),
secondary_info_.encoded_bytes);
info.redundant.push_back(secondary_info_);
DCHECK_EQ(info.redundant.size(), 2u);
}
// Save primary to secondary.
- if (secondary_allocated_ < info.encoded_bytes) {
- secondary_encoded_.reset(new uint8_t[info.encoded_bytes]);
- secondary_allocated_ = info.encoded_bytes;
- }
- CHECK(secondary_encoded_);
- memcpy(secondary_encoded_.get(), encoded, info.encoded_bytes);
+ secondary_encoded_.SetSize(info.encoded_bytes);
+ memcpy(secondary_encoded_.data(), encoded, info.encoded_bytes);
secondary_info_ = info;
DCHECK_EQ(info.speech, info.redundant[0].speech);
}
diff --git a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h
index fd92d52457..99e5ee2a3e 100644
--- a/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h
+++ b/webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h
@@ -13,6 +13,7 @@
#include <vector>
+#include "webrtc/base/buffer.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
@@ -53,8 +54,7 @@ class AudioEncoderCopyRed : public AudioEncoder {
private:
AudioEncoder* speech_encoder_;
int red_payload_type_;
- rtc::scoped_ptr<uint8_t[]> secondary_encoded_;
- size_t secondary_allocated_;
+ rtc::Buffer secondary_encoded_;
EncodedInfoLeaf secondary_info_;
};