voe::Channel: Don't use CodecManager and RentACodec

As a bonus, we also get rid of most uses of CodecInst in voe::Channel.

BUG=webrtc:8396

Change-Id: I20f82274dcec2ad8be6e046b987d7d65a19d0e46
Reviewed-on: https://webrtc-review.googlesource.com/10802
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20354}
This commit is contained in:
Karl Wiberg 2017-10-17 01:02:46 +02:00 committed by Commit Bot
parent 5f5fc6845a
commit 8818237538
4 changed files with 19 additions and 69 deletions

View File

@ -69,7 +69,6 @@ rtc_static_library("voice_engine") {
"../modules:module_api",
"../modules/audio_coding:audio_format_conversion",
"../modules/audio_coding:audio_network_adaptor_config",
"../modules/audio_coding:rent_a_codec",
"../modules/audio_device",
"../modules/audio_processing",
"../modules/bitrate_controller",

View File

@ -848,11 +848,8 @@ bool Channel::SetEncoder(int payload_type,
rtp_codec.channels = encoder->NumChannels();
rtp_codec.rate = 0;
// For audio encoding we need, instead, the actual sample rate of the codec.
// The rest of the information should be the same.
CodecInst send_codec = rtp_codec;
send_codec.plfreq = encoder->SampleRateHz();
cached_send_codec_.emplace(send_codec);
cached_encoder_props_.emplace(
EncoderProps{encoder->SampleRateHz(), encoder->NumChannels()});
if (_rtpRtcpModule->RegisterSendPayload(rtp_codec) != 0) {
_rtpRtcpModule->DeRegisterSendPayload(payload_type);
@ -864,7 +861,6 @@ bool Channel::SetEncoder(int payload_type,
}
audio_coding_->SetEncoder(std::move(encoder));
codec_manager_.UnsetCodecInst();
return true;
}
@ -873,45 +869,14 @@ void Channel::ModifyEncoder(
audio_coding_->ModifyEncoder(modifier);
}
int32_t Channel::GetSendCodec(CodecInst& codec) {
if (cached_send_codec_) {
codec = *cached_send_codec_;
return 0;
} else {
const CodecInst* send_codec = codec_manager_.GetCodecInst();
if (send_codec) {
codec = *send_codec;
return 0;
}
}
return -1;
rtc::Optional<Channel::EncoderProps> Channel::GetEncoderProps() const {
return cached_encoder_props_;
}
int32_t Channel::GetRecCodec(CodecInst& codec) {
return (audio_coding_->ReceiveCodec(&codec));
}
int32_t Channel::SetSendCodec(const CodecInst& codec) {
if (!codec_manager_.RegisterEncoder(codec) ||
!codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) {
LOG(LS_ERROR) << "SetSendCodec() failed to register codec to ACM";
return -1;
}
if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
_rtpRtcpModule->DeRegisterSendPayload(codec.pltype);
if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) {
LOG(LS_ERROR)
<< "SetSendCodec() failed to register codec to RTP/RTCP module";
return -1;
}
}
cached_send_codec_.reset();
return 0;
}
void Channel::SetBitRate(int bitrate_bps, int64_t probing_interval_ms) {
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
if (*encoder) {
@ -1387,19 +1352,12 @@ void Channel::ProcessAndEncodeAudio(const int16_t* audio_data,
if (!encoder_queue_is_active_) {
return;
}
CodecInst codec;
const int result = GetSendCodec(codec);
std::unique_ptr<AudioFrame> audio_frame(new AudioFrame());
// TODO(ossu): Investigate how this could happen. b/62909493
if (result == 0) {
audio_frame->sample_rate_hz_ = std::min(codec.plfreq, sample_rate);
audio_frame->num_channels_ = std::min(number_of_channels, codec.channels);
} else {
audio_frame->sample_rate_hz_ = sample_rate;
audio_frame->num_channels_ = number_of_channels;
LOG(LS_WARNING) << "Unable to get send codec for channel " << ChannelId();
RTC_NOTREACHED();
}
const auto props = GetEncoderProps();
RTC_CHECK(props);
audio_frame->sample_rate_hz_ = std::min(props->sample_rate_hz, sample_rate);
audio_frame->num_channels_ =
std::min(props->num_channels, number_of_channels);
RemixAndResample(audio_data, number_of_frames, number_of_channels,
sample_rate, &input_resampler_, audio_frame.get());
encoder_queue_->PostTask(std::unique_ptr<rtc::QueuedTask>(

View File

@ -20,8 +20,6 @@
#include "api/optional.h"
#include "common_audio/resampler/include/push_resampler.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/audio_coding/acm2/codec_manager.h"
#include "modules/audio_coding/acm2/rent_a_codec.h"
#include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_processing/rms_level.h"
#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
@ -184,9 +182,12 @@ class Channel
void StopSend();
// Codecs
int32_t GetSendCodec(CodecInst& codec);
struct EncoderProps {
int sample_rate_hz;
size_t num_channels;
};
rtc::Optional<EncoderProps> GetEncoderProps() const;
int32_t GetRecCodec(CodecInst& codec);
int32_t SetSendCodec(const CodecInst& codec);
void SetBitRate(int bitrate_bps, int64_t probing_interval_ms);
bool EnableAudioNetworkAdaptor(const std::string& config_string);
void DisableAudioNetworkAdaptor();
@ -380,8 +381,6 @@ class Channel
TelephoneEventHandler* telephone_event_handler_;
std::unique_ptr<RtpRtcp> _rtpRtcpModule;
std::unique_ptr<AudioCodingModule> audio_coding_;
acm2::CodecManager codec_manager_;
acm2::RentACodec rent_a_codec_;
std::unique_ptr<AudioSinkInterface> audio_sink_;
AudioLevel _outputAudioLevel;
// Downsamples to the codec rate if necessary.
@ -441,7 +440,7 @@ class Channel
// TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
rtc::Optional<CodecInst> cached_send_codec_;
rtc::Optional<EncoderProps> cached_encoder_props_;
rtc::ThreadChecker construction_thread_;

View File

@ -70,16 +70,10 @@ void TransmitMixer::GetSendCodecInfo(int* max_sample_rate,
it.Increment()) {
Channel* channel = it.GetChannel();
if (channel->Sending()) {
CodecInst codec;
// TODO(ossu): Investigate how this could happen. b/62909493
if (channel->GetSendCodec(codec) == 0) {
*max_sample_rate = std::max(*max_sample_rate, codec.plfreq);
*max_channels = std::max(*max_channels, codec.channels);
} else {
LOG(LS_WARNING) << "Unable to get send codec for channel "
<< channel->ChannelId();
RTC_NOTREACHED();
}
const auto props = channel->GetEncoderProps();
RTC_CHECK(props);
*max_sample_rate = std::max(*max_sample_rate, props->sample_rate_hz);
*max_channels = std::max(*max_channels, props->num_channels);
}
}
}