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}
This commit is contained in:
@ -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_;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user