Move CNG/RED payload type extraction to Rent-A-Codec
BUG=webrtc:5028 Review URL: https://codereview.webrtc.org/1450883002 Cr-Commit-Position: refs/heads/master@{#10691}
This commit is contained in:
parent
49a6c99d1f
commit
e1a27d48ad
@ -132,33 +132,16 @@ const CodecInst kEmptyCodecInst = {-1, "noCodecRegistered", 0, 0, 0, 0};
|
||||
} // namespace
|
||||
|
||||
CodecManager::CodecManager()
|
||||
: cng_nb_pltype_(255),
|
||||
cng_wb_pltype_(255),
|
||||
cng_swb_pltype_(255),
|
||||
cng_fb_pltype_(255),
|
||||
red_nb_pltype_(255),
|
||||
dtx_enabled_(false),
|
||||
: dtx_enabled_(false),
|
||||
vad_mode_(VADNormal),
|
||||
send_codec_inst_(kEmptyCodecInst),
|
||||
red_enabled_(false),
|
||||
codec_fec_enabled_(false),
|
||||
encoder_is_opus_(false) {
|
||||
// Register the default payload type for RED and for CNG at sampling rates of
|
||||
// 8, 16, 32 and 48 kHz.
|
||||
// Register the default payload types for RED and CNG.
|
||||
for (const CodecInst& ci : RentACodec::Database()) {
|
||||
if (IsCodecRED(ci) && ci.plfreq == 8000) {
|
||||
red_nb_pltype_ = static_cast<uint8_t>(ci.pltype);
|
||||
} else if (IsCodecCN(ci)) {
|
||||
if (ci.plfreq == 8000) {
|
||||
cng_nb_pltype_ = static_cast<uint8_t>(ci.pltype);
|
||||
} else if (ci.plfreq == 16000) {
|
||||
cng_wb_pltype_ = static_cast<uint8_t>(ci.pltype);
|
||||
} else if (ci.plfreq == 32000) {
|
||||
cng_swb_pltype_ = static_cast<uint8_t>(ci.pltype);
|
||||
} else if (ci.plfreq == 48000) {
|
||||
cng_fb_pltype_ = static_cast<uint8_t>(ci.pltype);
|
||||
}
|
||||
}
|
||||
RentACodec::RegisterCngPayloadType(&cng_payload_types_, ci);
|
||||
RentACodec::RegisterRedPayloadType(&red_payload_types_, ci);
|
||||
}
|
||||
thread_checker_.DetachFromThread();
|
||||
}
|
||||
@ -175,58 +158,27 @@ int CodecManager::RegisterEncoder(const CodecInst& send_codec) {
|
||||
}
|
||||
|
||||
int dummy_id = 0;
|
||||
// RED can be registered with other payload type. If not registered a default
|
||||
// payload type is used.
|
||||
if (IsCodecRED(send_codec)) {
|
||||
// TODO(tlegrand): Remove this check. Already taken care of in
|
||||
// ACMCodecDB::CodecNumber().
|
||||
// Check if the payload-type is valid
|
||||
if (!RentACodec::IsPayloadTypeValid(send_codec.pltype)) {
|
||||
switch (RentACodec::RegisterRedPayloadType(&red_payload_types_, send_codec)) {
|
||||
case RentACodec::RegistrationResult::kOk:
|
||||
return 0;
|
||||
case RentACodec::RegistrationResult::kBadFreq:
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
|
||||
"Invalid payload-type %d for %s.", send_codec.pltype,
|
||||
send_codec.plname);
|
||||
"RegisterSendCodec() failed, invalid frequency for RED"
|
||||
" registration");
|
||||
return -1;
|
||||
}
|
||||
// Set RED payload type.
|
||||
if (send_codec.plfreq == 8000) {
|
||||
red_nb_pltype_ = static_cast<uint8_t>(send_codec.pltype);
|
||||
} else {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
|
||||
"RegisterSendCodec() failed, invalid frequency for RED "
|
||||
"registration");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
case RentACodec::RegistrationResult::kSkip:
|
||||
break;
|
||||
}
|
||||
|
||||
// CNG can be registered with other payload type. If not registered the
|
||||
// default payload types from codec database will be used.
|
||||
if (IsCodecCN(send_codec)) {
|
||||
// CNG is registered.
|
||||
switch (send_codec.plfreq) {
|
||||
case 8000: {
|
||||
cng_nb_pltype_ = static_cast<uint8_t>(send_codec.pltype);
|
||||
return 0;
|
||||
}
|
||||
case 16000: {
|
||||
cng_wb_pltype_ = static_cast<uint8_t>(send_codec.pltype);
|
||||
return 0;
|
||||
}
|
||||
case 32000: {
|
||||
cng_swb_pltype_ = static_cast<uint8_t>(send_codec.pltype);
|
||||
return 0;
|
||||
}
|
||||
case 48000: {
|
||||
cng_fb_pltype_ = static_cast<uint8_t>(send_codec.pltype);
|
||||
return 0;
|
||||
}
|
||||
default: {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
|
||||
"RegisterSendCodec() failed, invalid frequency for CNG "
|
||||
"registration");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
switch (RentACodec::RegisterCngPayloadType(&cng_payload_types_, send_codec)) {
|
||||
case RentACodec::RegistrationResult::kOk:
|
||||
return 0;
|
||||
case RentACodec::RegistrationResult::kBadFreq:
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
|
||||
"RegisterSendCodec() failed, invalid frequency for CNG"
|
||||
" registration");
|
||||
return -1;
|
||||
case RentACodec::RegistrationResult::kSkip:
|
||||
break;
|
||||
}
|
||||
|
||||
// Set Stereo, and make sure VAD and DTX is turned off.
|
||||
@ -418,34 +370,20 @@ AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) {
|
||||
return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr;
|
||||
}
|
||||
|
||||
int CodecManager::CngPayloadType(int sample_rate_hz) const {
|
||||
switch (sample_rate_hz) {
|
||||
case 8000:
|
||||
return cng_nb_pltype_;
|
||||
case 16000:
|
||||
return cng_wb_pltype_;
|
||||
case 32000:
|
||||
return cng_swb_pltype_;
|
||||
case 48000:
|
||||
return cng_fb_pltype_;
|
||||
default:
|
||||
FATAL() << sample_rate_hz << " Hz is not supported";
|
||||
return -1;
|
||||
}
|
||||
int CodecManager::CngPayloadType(int rtp_timestamp_rate_hz) const {
|
||||
RTC_CHECK(rtp_timestamp_rate_hz == 8000 || rtp_timestamp_rate_hz == 16000 ||
|
||||
rtp_timestamp_rate_hz == 32000 || rtp_timestamp_rate_hz == 48000)
|
||||
<< rtp_timestamp_rate_hz << " Hz is not supported";
|
||||
auto it = cng_payload_types_.find(rtp_timestamp_rate_hz);
|
||||
return it == cng_payload_types_.end() ? -1 : it->second;
|
||||
}
|
||||
|
||||
int CodecManager::RedPayloadType(int sample_rate_hz) const {
|
||||
switch (sample_rate_hz) {
|
||||
case 8000:
|
||||
return red_nb_pltype_;
|
||||
case 16000:
|
||||
case 32000:
|
||||
case 48000:
|
||||
return -1;
|
||||
default:
|
||||
FATAL() << sample_rate_hz << " Hz is not supported";
|
||||
return -1;
|
||||
}
|
||||
int CodecManager::RedPayloadType(int rtp_timestamp_rate_hz) const {
|
||||
RTC_CHECK(rtp_timestamp_rate_hz == 8000 || rtp_timestamp_rate_hz == 16000 ||
|
||||
rtp_timestamp_rate_hz == 32000 || rtp_timestamp_rate_hz == 48000)
|
||||
<< rtp_timestamp_rate_hz << " Hz is not supported";
|
||||
auto it = red_payload_types_.find(rtp_timestamp_rate_hz);
|
||||
return it == red_payload_types_.end() ? -1 : it->second;
|
||||
}
|
||||
|
||||
void CodecManager::RentEncoderStack(AudioEncoder* speech_encoder,
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#ifndef WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_CODEC_MANAGER_H_
|
||||
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_CODEC_MANAGER_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/optional.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
@ -69,17 +71,17 @@ class CodecManager final {
|
||||
void RentEncoderStack(AudioEncoder* speech_encoder, int sample_rate_hz);
|
||||
|
||||
rtc::ThreadChecker thread_checker_;
|
||||
uint8_t cng_nb_pltype_;
|
||||
uint8_t cng_wb_pltype_;
|
||||
uint8_t cng_swb_pltype_;
|
||||
uint8_t cng_fb_pltype_;
|
||||
uint8_t red_nb_pltype_;
|
||||
bool dtx_enabled_;
|
||||
ACMVADMode vad_mode_;
|
||||
CodecInst send_codec_inst_;
|
||||
bool red_enabled_;
|
||||
bool codec_fec_enabled_;
|
||||
RentACodec rent_a_codec_;
|
||||
|
||||
// Maps from RTP timestamp rate (in Hz) to payload type.
|
||||
std::map<int, int> cng_payload_types_;
|
||||
std::map<int, int> red_payload_types_;
|
||||
|
||||
bool encoder_is_opus_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(CodecManager);
|
||||
|
||||
@ -107,6 +107,37 @@ rtc::Optional<NetEqDecoder> RentACodec::NetEqDecoderFromCodecId(
|
||||
: ned);
|
||||
}
|
||||
|
||||
RentACodec::RegistrationResult RentACodec::RegisterCngPayloadType(
|
||||
std::map<int, int>* pt_map,
|
||||
const CodecInst& codec_inst) {
|
||||
if (STR_CASE_CMP(codec_inst.plname, "CN") != 0)
|
||||
return RegistrationResult::kSkip;
|
||||
switch (codec_inst.plfreq) {
|
||||
case 8000:
|
||||
case 16000:
|
||||
case 32000:
|
||||
case 48000:
|
||||
(*pt_map)[codec_inst.plfreq] = codec_inst.pltype;
|
||||
return RegistrationResult::kOk;
|
||||
default:
|
||||
return RegistrationResult::kBadFreq;
|
||||
}
|
||||
}
|
||||
|
||||
RentACodec::RegistrationResult RentACodec::RegisterRedPayloadType(
|
||||
std::map<int, int>* pt_map,
|
||||
const CodecInst& codec_inst) {
|
||||
if (STR_CASE_CMP(codec_inst.plname, "RED") != 0)
|
||||
return RegistrationResult::kSkip;
|
||||
switch (codec_inst.plfreq) {
|
||||
case 8000:
|
||||
(*pt_map)[codec_inst.plfreq] = codec_inst.pltype;
|
||||
return RegistrationResult::kOk;
|
||||
default:
|
||||
return RegistrationResult::kBadFreq;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns a new speech encoder, or null on error.
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#define WEBRTC_MODULES_AUDIO_CODING_MAIN_ACM2_RENT_A_CODEC_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <map>
|
||||
|
||||
#include "webrtc/base/array_view.h"
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
@ -181,6 +182,16 @@ class RentACodec {
|
||||
static rtc::Optional<NetEqDecoder> NetEqDecoderFromCodecId(CodecId codec_id,
|
||||
int num_channels);
|
||||
|
||||
// Parse codec_inst and extract payload types. If the given CodecInst was for
|
||||
// the wrong sort of codec, return kSkip; otherwise, if the rate was illegal,
|
||||
// return kBadFreq; otherwise, update the given RTP timestamp rate (Hz) ->
|
||||
// payload type map and return kOk.
|
||||
enum class RegistrationResult { kOk, kSkip, kBadFreq };
|
||||
static RegistrationResult RegisterCngPayloadType(std::map<int, int>* pt_map,
|
||||
const CodecInst& codec_inst);
|
||||
static RegistrationResult RegisterRedPayloadType(std::map<int, int>* pt_map,
|
||||
const CodecInst& codec_inst);
|
||||
|
||||
RentACodec();
|
||||
~RentACodec();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user