Pass audio to AudioEncoder::Encode() in an ArrayView
Instead of in separate pointer and size arguments. Review URL: https://codereview.webrtc.org/1418423010 Cr-Commit-Position: refs/heads/master@{#10535}
This commit is contained in:
@ -97,7 +97,7 @@ int AudioEncoderCng::GetTargetBitrate() const {
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
|
||||
uint32_t rtp_timestamp,
|
||||
const int16_t* audio,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) {
|
||||
RTC_CHECK_GE(max_encoded_bytes,
|
||||
@ -106,9 +106,8 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeInternal(
|
||||
RTC_CHECK_EQ(speech_buffer_.size(),
|
||||
rtp_timestamps_.size() * samples_per_10ms_frame);
|
||||
rtp_timestamps_.push_back(rtp_timestamp);
|
||||
for (size_t i = 0; i < samples_per_10ms_frame; ++i) {
|
||||
speech_buffer_.push_back(audio[i]);
|
||||
}
|
||||
RTC_DCHECK_EQ(samples_per_10ms_frame, audio.size());
|
||||
speech_buffer_.insert(speech_buffer_.end(), audio.cbegin(), audio.cend());
|
||||
const size_t frames_to_encode = speech_encoder_->Num10MsFramesInNextPacket();
|
||||
if (rtp_timestamps_.size() < frames_to_encode) {
|
||||
return EncodedInfo();
|
||||
@ -242,9 +241,12 @@ AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive(
|
||||
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
|
||||
AudioEncoder::EncodedInfo info;
|
||||
for (size_t i = 0; i < frames_to_encode; ++i) {
|
||||
info = speech_encoder_->Encode(
|
||||
rtp_timestamps_.front(), &speech_buffer_[i * samples_per_10ms_frame],
|
||||
samples_per_10ms_frame, max_encoded_bytes, encoded);
|
||||
info =
|
||||
speech_encoder_->Encode(rtp_timestamps_.front(),
|
||||
rtc::ArrayView<const int16_t>(
|
||||
&speech_buffer_[i * samples_per_10ms_frame],
|
||||
samples_per_10ms_frame),
|
||||
max_encoded_bytes, encoded);
|
||||
if (i + 1 == frames_to_encode) {
|
||||
RTC_CHECK_GT(info.encoded_bytes, 0u) << "Encoder didn't deliver data.";
|
||||
} else {
|
||||
|
||||
@ -75,8 +75,10 @@ class AudioEncoderCngTest : public ::testing::Test {
|
||||
|
||||
void Encode() {
|
||||
ASSERT_TRUE(cng_) << "Must call CreateCng() first.";
|
||||
encoded_info_ = cng_->Encode(timestamp_, audio_, num_audio_samples_10ms_,
|
||||
encoded_.size(), &encoded_[0]);
|
||||
encoded_info_ = cng_->Encode(
|
||||
timestamp_,
|
||||
rtc::ArrayView<const int16_t>(audio_, num_audio_samples_10ms_),
|
||||
encoded_.size(), &encoded_[0]);
|
||||
timestamp_ += static_cast<uint32_t>(num_audio_samples_10ms_);
|
||||
}
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ class AudioEncoderCng final : public AudioEncoder {
|
||||
size_t Max10MsFramesInAPacket() const override;
|
||||
int GetTargetBitrate() const override;
|
||||
EncodedInfo EncodeInternal(uint32_t rtp_timestamp,
|
||||
const int16_t* audio,
|
||||
rtc::ArrayView<const int16_t> audio,
|
||||
size_t max_encoded_bytes,
|
||||
uint8_t* encoded) override;
|
||||
void Reset() override;
|
||||
|
||||
Reference in New Issue
Block a user