2014-12-10 07:29:08 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/codecs/cng/audio_encoder_cng.h"
|
2014-12-10 07:29:08 +00:00
|
|
|
|
2015-03-10 15:41:26 +00:00
|
|
|
#include <algorithm>
|
2014-12-10 07:29:08 +00:00
|
|
|
#include <limits>
|
2016-02-14 01:10:03 -08:00
|
|
|
#include <memory>
|
2016-03-08 06:01:31 -08:00
|
|
|
#include <utility>
|
2014-12-10 07:29:08 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2015-03-10 15:41:26 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
const int kMaxFrameSizeMs = 60;
|
|
|
|
|
|
2015-09-08 05:57:53 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
2016-03-08 06:01:31 -08:00
|
|
|
AudioEncoderCng::Config::Config() = default;
|
2016-04-15 05:24:56 -07:00
|
|
|
AudioEncoderCng::Config::Config(Config&&) = default;
|
2016-03-08 06:01:31 -08:00
|
|
|
AudioEncoderCng::Config::~Config() = default;
|
|
|
|
|
|
2014-12-10 07:29:08 +00:00
|
|
|
bool AudioEncoderCng::Config::IsOk() const {
|
|
|
|
|
if (num_channels != 1)
|
|
|
|
|
return false;
|
|
|
|
|
if (!speech_encoder)
|
|
|
|
|
return false;
|
2015-02-18 12:00:32 +00:00
|
|
|
if (num_channels != speech_encoder->NumChannels())
|
2014-12-10 07:29:08 +00:00
|
|
|
return false;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
if (sid_frame_interval_ms <
|
|
|
|
|
static_cast<int>(speech_encoder->Max10MsFramesInAPacket() * 10))
|
2014-12-10 07:29:08 +00:00
|
|
|
return false;
|
|
|
|
|
if (num_cng_coefficients > WEBRTC_CNG_MAX_LPC_ORDER ||
|
|
|
|
|
num_cng_coefficients <= 0)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 06:01:31 -08:00
|
|
|
AudioEncoderCng::AudioEncoderCng(Config&& config)
|
2018-04-07 05:17:33 +02:00
|
|
|
: speech_encoder_((static_cast<void>([&] {
|
|
|
|
|
RTC_CHECK(config.IsOk()) << "Invalid configuration.";
|
|
|
|
|
}()),
|
|
|
|
|
std::move(config.speech_encoder))),
|
2014-12-10 07:29:08 +00:00
|
|
|
cng_payload_type_(config.payload_type),
|
|
|
|
|
num_cng_coefficients_(config.num_cng_coefficients),
|
2015-09-08 05:57:53 -07:00
|
|
|
sid_frame_interval_ms_(config.sid_frame_interval_ms),
|
2014-12-10 07:29:08 +00:00
|
|
|
last_frame_active_(true),
|
2016-02-14 01:10:03 -08:00
|
|
|
vad_(config.vad ? std::unique_ptr<Vad>(config.vad)
|
2018-04-07 05:17:33 +02:00
|
|
|
: CreateVad(config.vad_mode)),
|
2016-04-25 07:55:58 -07:00
|
|
|
cng_encoder_(new ComfortNoiseEncoder(SampleRateHz(),
|
|
|
|
|
sid_frame_interval_ms_,
|
2018-04-07 05:17:33 +02:00
|
|
|
num_cng_coefficients_)) {}
|
2014-12-10 07:29:08 +00:00
|
|
|
|
2015-09-08 05:57:53 -07:00
|
|
|
AudioEncoderCng::~AudioEncoderCng() = default;
|
|
|
|
|
|
2015-02-18 12:00:32 +00:00
|
|
|
int AudioEncoderCng::SampleRateHz() const {
|
|
|
|
|
return speech_encoder_->SampleRateHz();
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t AudioEncoderCng::NumChannels() const {
|
2015-01-27 20:53:56 +00:00
|
|
|
return 1;
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-08 05:57:53 -07:00
|
|
|
int AudioEncoderCng::RtpTimestampRateHz() const {
|
|
|
|
|
return speech_encoder_->RtpTimestampRateHz();
|
2015-03-10 15:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t AudioEncoderCng::Num10MsFramesInNextPacket() const {
|
2014-12-10 07:29:08 +00:00
|
|
|
return speech_encoder_->Num10MsFramesInNextPacket();
|
|
|
|
|
}
|
|
|
|
|
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t AudioEncoderCng::Max10MsFramesInAPacket() const {
|
2014-12-10 07:29:08 +00:00
|
|
|
return speech_encoder_->Max10MsFramesInAPacket();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 14:58:34 +02:00
|
|
|
int AudioEncoderCng::GetTargetBitrate() const {
|
|
|
|
|
return speech_encoder_->GetTargetBitrate();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 00:54:32 -08:00
|
|
|
AudioEncoder::EncodedInfo AudioEncoderCng::EncodeImpl(
|
2015-03-19 08:50:26 +00:00
|
|
|
uint32_t rtp_timestamp,
|
2015-11-06 01:21:35 -08:00
|
|
|
rtc::ArrayView<const int16_t> audio,
|
2016-03-01 00:41:31 -08:00
|
|
|
rtc::Buffer* encoded) {
|
2015-05-22 15:13:41 +02:00
|
|
|
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_EQ(speech_buffer_.size(),
|
|
|
|
|
rtp_timestamps_.size() * samples_per_10ms_frame);
|
2015-05-22 15:13:41 +02:00
|
|
|
rtp_timestamps_.push_back(rtp_timestamp);
|
2015-11-06 01:21:35 -08:00
|
|
|
RTC_DCHECK_EQ(samples_per_10ms_frame, audio.size());
|
|
|
|
|
speech_buffer_.insert(speech_buffer_.end(), audio.cbegin(), audio.cend());
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t frames_to_encode = speech_encoder_->Num10MsFramesInNextPacket();
|
|
|
|
|
if (rtp_timestamps_.size() < frames_to_encode) {
|
2015-03-19 08:50:26 +00:00
|
|
|
return EncodedInfo();
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_CHECK_LE(frames_to_encode * 10, kMaxFrameSizeMs)
|
2015-03-10 15:41:26 +00:00
|
|
|
<< "Frame size cannot be larger than " << kMaxFrameSizeMs
|
|
|
|
|
<< " ms when using VAD/CNG.";
|
2014-12-10 07:29:08 +00:00
|
|
|
|
|
|
|
|
// Group several 10 ms blocks per VAD call. Call VAD once or twice using the
|
|
|
|
|
// following split sizes:
|
|
|
|
|
// 10 ms = 10 + 0 ms; 20 ms = 20 + 0 ms; 30 ms = 30 + 0 ms;
|
|
|
|
|
// 40 ms = 20 + 20 ms; 50 ms = 30 + 20 ms; 60 ms = 30 + 30 ms.
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t blocks_in_first_vad_call =
|
2015-05-22 15:13:41 +02:00
|
|
|
(frames_to_encode > 3 ? 3 : frames_to_encode);
|
|
|
|
|
if (frames_to_encode == 4)
|
2014-12-10 07:29:08 +00:00
|
|
|
blocks_in_first_vad_call = 2;
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK_GE(frames_to_encode, blocks_in_first_vad_call);
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
const size_t blocks_in_second_vad_call =
|
2015-05-22 15:13:41 +02:00
|
|
|
frames_to_encode - blocks_in_first_vad_call;
|
2014-12-10 07:29:08 +00:00
|
|
|
|
|
|
|
|
// Check if all of the buffer is passive speech. Start with checking the first
|
|
|
|
|
// block.
|
|
|
|
|
Vad::Activity activity = vad_->VoiceActivity(
|
|
|
|
|
&speech_buffer_[0], samples_per_10ms_frame * blocks_in_first_vad_call,
|
2015-02-18 12:00:32 +00:00
|
|
|
SampleRateHz());
|
2014-12-10 07:29:08 +00:00
|
|
|
if (activity == Vad::kPassive && blocks_in_second_vad_call > 0) {
|
|
|
|
|
// Only check the second block if the first was passive.
|
|
|
|
|
activity = vad_->VoiceActivity(
|
|
|
|
|
&speech_buffer_[samples_per_10ms_frame * blocks_in_first_vad_call],
|
2015-02-18 12:00:32 +00:00
|
|
|
samples_per_10ms_frame * blocks_in_second_vad_call, SampleRateHz());
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-19 08:50:26 +00:00
|
|
|
EncodedInfo info;
|
2014-12-10 07:29:08 +00:00
|
|
|
switch (activity) {
|
|
|
|
|
case Vad::kPassive: {
|
2016-03-01 00:41:31 -08:00
|
|
|
info = EncodePassive(frames_to_encode, encoded);
|
2014-12-10 07:29:08 +00:00
|
|
|
last_frame_active_ = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Vad::kActive: {
|
2016-03-01 00:41:31 -08:00
|
|
|
info = EncodeActive(frames_to_encode, encoded);
|
2014-12-10 07:29:08 +00:00
|
|
|
last_frame_active_ = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Vad::kError: {
|
2015-02-24 14:58:10 +00:00
|
|
|
FATAL(); // Fails only if fed invalid data.
|
2014-12-10 07:29:08 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 15:13:41 +02:00
|
|
|
speech_buffer_.erase(
|
|
|
|
|
speech_buffer_.begin(),
|
|
|
|
|
speech_buffer_.begin() + frames_to_encode * samples_per_10ms_frame);
|
|
|
|
|
rtp_timestamps_.erase(rtp_timestamps_.begin(),
|
|
|
|
|
rtp_timestamps_.begin() + frames_to_encode);
|
2015-03-19 08:50:26 +00:00
|
|
|
return info;
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-08 05:57:53 -07:00
|
|
|
void AudioEncoderCng::Reset() {
|
|
|
|
|
speech_encoder_->Reset();
|
|
|
|
|
speech_buffer_.clear();
|
|
|
|
|
rtp_timestamps_.clear();
|
|
|
|
|
last_frame_active_ = true;
|
|
|
|
|
vad_->Reset();
|
2016-04-25 07:55:58 -07:00
|
|
|
cng_encoder_.reset(new ComfortNoiseEncoder(
|
|
|
|
|
SampleRateHz(), sid_frame_interval_ms_, num_cng_coefficients_));
|
2015-09-08 05:57:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioEncoderCng::SetFec(bool enable) {
|
|
|
|
|
return speech_encoder_->SetFec(enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioEncoderCng::SetDtx(bool enable) {
|
|
|
|
|
return speech_encoder_->SetDtx(enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioEncoderCng::SetApplication(Application application) {
|
|
|
|
|
return speech_encoder_->SetApplication(application);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-08 23:15:33 -07:00
|
|
|
void AudioEncoderCng::SetMaxPlaybackRate(int frequency_hz) {
|
|
|
|
|
speech_encoder_->SetMaxPlaybackRate(frequency_hz);
|
2015-09-08 05:57:53 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-30 06:49:59 -08:00
|
|
|
rtc::ArrayView<std::unique_ptr<AudioEncoder>>
|
|
|
|
|
AudioEncoderCng::ReclaimContainedEncoders() {
|
|
|
|
|
return rtc::ArrayView<std::unique_ptr<AudioEncoder>>(&speech_encoder_, 1);
|
2015-09-08 05:57:53 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-30 06:49:59 -08:00
|
|
|
void AudioEncoderCng::OnReceivedUplinkPacketLossFraction(
|
|
|
|
|
float uplink_packet_loss_fraction) {
|
|
|
|
|
speech_encoder_->OnReceivedUplinkPacketLossFraction(
|
|
|
|
|
uplink_packet_loss_fraction);
|
2015-09-08 05:57:53 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-23 15:29:50 -07:00
|
|
|
void AudioEncoderCng::OnReceivedUplinkRecoverablePacketLossFraction(
|
|
|
|
|
float uplink_recoverable_packet_loss_fraction) {
|
|
|
|
|
speech_encoder_->OnReceivedUplinkRecoverablePacketLossFraction(
|
|
|
|
|
uplink_recoverable_packet_loss_fraction);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 10:17:38 -08:00
|
|
|
void AudioEncoderCng::OnReceivedUplinkBandwidth(
|
|
|
|
|
int target_audio_bitrate_bps,
|
2018-06-19 13:26:36 +02:00
|
|
|
absl::optional<int64_t> bwe_period_ms) {
|
2017-01-12 10:17:38 -08:00
|
|
|
speech_encoder_->OnReceivedUplinkBandwidth(target_audio_bitrate_bps,
|
2017-09-01 10:44:37 +02:00
|
|
|
bwe_period_ms);
|
2016-06-23 03:58:36 -07:00
|
|
|
}
|
|
|
|
|
|
2015-03-19 08:50:26 +00:00
|
|
|
AudioEncoder::EncodedInfo AudioEncoderCng::EncodePassive(
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
size_t frames_to_encode,
|
2016-03-01 00:41:31 -08:00
|
|
|
rtc::Buffer* encoded) {
|
2014-12-10 07:29:08 +00:00
|
|
|
bool force_sid = last_frame_active_;
|
|
|
|
|
bool output_produced = false;
|
2015-03-10 15:41:26 +00:00
|
|
|
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
|
2015-03-19 08:50:26 +00:00
|
|
|
AudioEncoder::EncodedInfo info;
|
2016-03-01 00:41:31 -08:00
|
|
|
|
2016-04-25 07:55:58 -07:00
|
|
|
for (size_t i = 0; i < frames_to_encode; ++i) {
|
|
|
|
|
// It's important not to pass &info.encoded_bytes directly to
|
|
|
|
|
// WebRtcCng_Encode(), since later loop iterations may return zero in
|
|
|
|
|
// that value, in which case we don't want to overwrite any value from
|
|
|
|
|
// an earlier iteration.
|
|
|
|
|
size_t encoded_bytes_tmp =
|
|
|
|
|
cng_encoder_->Encode(rtc::ArrayView<const int16_t>(
|
|
|
|
|
&speech_buffer_[i * samples_per_10ms_frame],
|
|
|
|
|
samples_per_10ms_frame),
|
|
|
|
|
force_sid, encoded);
|
|
|
|
|
|
|
|
|
|
if (encoded_bytes_tmp > 0) {
|
|
|
|
|
RTC_CHECK(!output_produced);
|
|
|
|
|
info.encoded_bytes = encoded_bytes_tmp;
|
|
|
|
|
output_produced = true;
|
|
|
|
|
force_sid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-01 00:41:31 -08:00
|
|
|
|
2015-05-22 15:13:41 +02:00
|
|
|
info.encoded_timestamp = rtp_timestamps_.front();
|
2015-03-19 08:50:26 +00:00
|
|
|
info.payload_type = cng_payload_type_;
|
|
|
|
|
info.send_even_if_empty = true;
|
|
|
|
|
info.speech = false;
|
|
|
|
|
return info;
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-19 08:50:26 +00:00
|
|
|
AudioEncoder::EncodedInfo AudioEncoderCng::EncodeActive(size_t frames_to_encode,
|
2016-03-01 00:41:31 -08:00
|
|
|
rtc::Buffer* encoded) {
|
2015-03-10 15:41:26 +00:00
|
|
|
const size_t samples_per_10ms_frame = SamplesPer10msFrame();
|
2015-03-19 08:50:26 +00:00
|
|
|
AudioEncoder::EncodedInfo info;
|
Update a ton of audio code to use size_t more correctly and in general reduce
use of int16_t/uint16_t.
This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects.
This was be reviewed and approved in pieces:
https://codereview.webrtc.org/1224093003
https://codereview.webrtc.org/1224123002
https://codereview.webrtc.org/1224163002
https://codereview.webrtc.org/1225133003
https://codereview.webrtc.org/1225173002
https://codereview.webrtc.org/1227163003
https://codereview.webrtc.org/1227203003
https://codereview.webrtc.org/1227213002
https://codereview.webrtc.org/1227893002
https://codereview.webrtc.org/1228793004
https://codereview.webrtc.org/1228803003
https://codereview.webrtc.org/1228823002
https://codereview.webrtc.org/1228823003
https://codereview.webrtc.org/1228843002
https://codereview.webrtc.org/1230693002
https://codereview.webrtc.org/1231713002
The change is being landed as TBR to all the folks who reviewed the above.
BUG=chromium:81439
TEST=none
R=andrew@webrtc.org, pbos@webrtc.org
TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher
Review URL: https://codereview.webrtc.org/1230503003 .
Cr-Commit-Position: refs/heads/master@{#9768}
2015-08-24 14:52:23 -07:00
|
|
|
for (size_t i = 0; i < frames_to_encode; ++i) {
|
2015-11-06 01:21:35 -08:00
|
|
|
info =
|
|
|
|
|
speech_encoder_->Encode(rtp_timestamps_.front(),
|
|
|
|
|
rtc::ArrayView<const int16_t>(
|
|
|
|
|
&speech_buffer_[i * samples_per_10ms_frame],
|
|
|
|
|
samples_per_10ms_frame),
|
2016-03-01 00:41:31 -08:00
|
|
|
encoded);
|
2015-06-10 21:15:38 -07:00
|
|
|
if (i + 1 == frames_to_encode) {
|
2016-11-28 15:21:39 -08:00
|
|
|
RTC_CHECK_GT(info.encoded_bytes, 0) << "Encoder didn't deliver data.";
|
2015-05-22 15:13:41 +02:00
|
|
|
} else {
|
2016-11-28 15:21:39 -08:00
|
|
|
RTC_CHECK_EQ(info.encoded_bytes, 0)
|
2015-09-17 00:24:34 -07:00
|
|
|
<< "Encoder delivered data too early.";
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-19 08:50:26 +00:00
|
|
|
return info;
|
2014-12-10 07:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-10 15:41:26 +00:00
|
|
|
size_t AudioEncoderCng::SamplesPer10msFrame() const {
|
|
|
|
|
return rtc::CheckedDivExact(10 * SampleRateHz(), 1000);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-10 07:29:08 +00:00
|
|
|
} // namespace webrtc
|