- fix opus codec usage

This commit is contained in:
Dmytro Bogovych 2021-06-09 13:06:26 +03:00
parent 61be61b7e3
commit 9479a0f36f
11 changed files with 42 additions and 22 deletions

View File

@ -208,10 +208,13 @@ void AgentImpl::processStart(JsonCpp::Value& /*request*/, JsonCpp::Value &answer
PVariantMap priorityConfig = std::make_shared<VariantMap>();
MT::CodecList& cl = mTerminal->codeclist();
for (int i=0; i<cl.count(); i++)
if (cl.codecAt(i).payloadType() < 96)
priorityConfig->at(i) = i;
// Disable dynamic payload codec types - commented for now
/*if (cl.codecAt(i).payloadType() < 96)
priorityConfig->at(i) = i;
else
priorityConfig->at(i) = -1;
priorityConfig->at(i) = -1;*/
config()[CONFIG_CODEC_PRIORITY] = priorityConfig;

View File

@ -84,7 +84,7 @@
// OPUS codec defines
// #define USE_OPUS_CODEC
#define MT_OPUS_CODEC_PT -1
#define MT_OPUS_CODEC_PT 106
// ILBC codec defines
#define MT_ILBC20_PAYLOADTYPE -1

View File

@ -26,7 +26,7 @@ AudioProvider::AudioProvider(UserAgent& agent, MT::Terminal& terminal)
if (mUserAgent.config().exists(CONFIG_CODEC_PRIORITY))
mCodecPriority.setupFrom(mUserAgent.config()[CONFIG_CODEC_PRIORITY].asVMap());
mSrtpSuite = SRTP_NONE;
setState((int)StreamState::SipRecv | (int)StreamState::SipSend | (int)StreamState::Receiving | (int)StreamState::Sending);
setStateImpl((int)StreamState::SipRecv | (int)StreamState::SipSend | (int)StreamState::Receiving | (int)StreamState::Sending);
}
AudioProvider::~AudioProvider()
@ -182,6 +182,7 @@ void AudioProvider::sessionEstablished(int conntype)
{
RemoteCodec& rc = mAvailableCodecs.front();
mActiveStream->setTransmittingCodec(*rc.mFactory, rc.mRemotePayloadType);
auto codec = dynamic_cast<MT::AudioStream*>(mActiveStream.get())->transmittingCodec();
dynamic_cast<MT::AudioStream*>(mActiveStream.get())->setTelephoneCodec(mRemoteTelephoneCodec);
}
}
@ -271,11 +272,10 @@ bool AudioProvider::processSdpOffer(const resip::SdpContents::Session::Medium& m
return true;
}
void AudioProvider::setState(unsigned state)
{
mState = state;
if (mActiveStream)
mActiveStream->setState(state);
setStateImpl(state);
}
unsigned AudioProvider::state()
@ -381,3 +381,10 @@ void AudioProvider::setupMirror(bool enable)
if (mActiveStream)
mActiveStream->setupMirror(enable);
}
void AudioProvider::setStateImpl(unsigned int state) {
mState = state;
if (mActiveStream)
mActiveStream->setState(state);
}

View File

@ -65,7 +65,8 @@ public:
// myAnswer sets if the answer will be sent after.
bool processSdpOffer(const resip::SdpContents::Session::Medium& media, SdpDirection sdpDirection);
void setState(unsigned state);
void setState(unsigned state) override;
unsigned state();
MT::Statistics getStatistics();
MT::PStream activeStream();
@ -112,6 +113,10 @@ protected:
std::string createCryptoAttribute(SrtpSuite suite);
SrtpSuite processCryptoAttribute(const resip::Data& value, ByteBuffer& key);
void findRfc2833(const resip::SdpContents::Session::Medium::CodecContainer& codecs);
// Implements setState() logic. This allows to be called from constructor (it is not virtual function)
void setStateImpl(unsigned state);
};
#endif

View File

@ -726,7 +726,7 @@ void Session::buildSdp(resip::SdpContents &sdp, SdpDirection sdpDirection)
if (mUserAgent->mConfig[CONFIG_MULTIPLEXING].asBool())
media.addAttribute("rtcp-mux");
// Ask provider about specific information
// Ask provider about specific information - codecs are filled here
provider.updateSdpOffer(media, sdpDirection);
// Add ICE information

View File

@ -402,6 +402,7 @@ PCodec OpusCodec::OpusFactory::create()
result->applyParams(mParams);
PCodec c(result);
mCodecList.push_back(c);
return c;
}

View File

@ -110,6 +110,7 @@ void AudioStream::setDestination(const RtpPair<InternetAddress>& dest)
void AudioStream::setTransmittingCodec(Codec::Factory& factory, int payloadType)
{
ICELogInfo(<< "Selected codec " << factory.name() << "/" << factory.samplerate() << " for transmitting");
Lock l(mMutex);
mTransmittingCodec = factory.create();
mTransmittingPayloadType = payloadType;
@ -145,9 +146,11 @@ void AudioStream::addData(const void* buffer, int bytes)
{
Lock l(mMutex);
codec = mTransmittingCodec.get();
if (!codec)
if (nullptr == codec) {
ICELogDebug(<< "No transmitting codec selected.");
return;
}
}
// Resample
unsigned dstlen = unsigned(float(codec->samplerate() / float(AUDIO_SAMPLERATE)) * bytes);
@ -202,7 +205,7 @@ void AudioStream::addData(const void* buffer, int bytes)
int packetTime = mPacketTime ? mPacketTime : codec->frameTime();
// Make stereo version if required
for (int i=0; i<mCapturedAudio.filled() / mTransmittingCodec->pcmLength(); i++)
for (int i=0; i<mCapturedAudio.filled() / codec->pcmLength(); i++)
{
if (mSendingDump)
mSendingDump->write((const char*)mCapturedAudio.data() + codec->pcmLength() * i, codec->pcmLength());
@ -230,6 +233,7 @@ void AudioStream::addData(const void* buffer, int bytes)
}
}
}
if (processed > 0)
mCapturedAudio.erase(processed);
}

View File

@ -64,7 +64,7 @@ namespace MT
Audio::DataWindow mStereoCapturedAudio;
char mIncomingPcmBuffer[AUDIO_MIC_BUFFER_SIZE]; // Temporary buffer to allow reading from file
char mResampleBuffer[AUDIO_MIC_BUFFER_SIZE*8]; // Temporary buffer to hold data
char mStereoBuffer[AUDIO_MIC_BUFFER_SIZE*8]; // Temporary buffer to hold data converted to stereo
char mStereoBuffer[AUDIO_MIC_BUFFER_SIZE*16]; // Temporary buffer to hold data converted to stereo
PCodec mTransmittingCodec; // Current encoding codec
int mTransmittingPayloadType; // Payload type to mark outgoing packets
int mPacketTime; // Required packet time

View File

@ -128,12 +128,12 @@ CodecList::CodecList(const Settings& settings)
//mFactoryList.push_back(new IsacCodec::IsacFactory16K(mSettings.mIsac16KPayloadType));
//mFactoryList.push_back(new IlbcCodec::IlbcFactory(mSettings.mIlbc20PayloadType, mSettings.mIlbc30PayloadType));
mFactoryList.push_back(new G711Codec::AlawFactory());
mFactoryList.push_back(new G711Codec::UlawFactory());
// mFactoryList.push_back(new G711Codec::AlawFactory());
// mFactoryList.push_back(new G711Codec::UlawFactory());
mFactoryList.push_back(new GsmCodec::GsmFactory(mSettings.mGsmFrPayloadLength == 32 ? GsmCodec::Type::Bytes_32 : GsmCodec::Type::Bytes_33, mSettings.mGsmFrPayloadType));
mFactoryList.push_back(new G722Codec::G722Factory());
mFactoryList.push_back(new G729Codec::G729Factory());
// mFactoryList.push_back(new GsmCodec::GsmFactory(mSettings.mGsmFrPayloadLength == 32 ? GsmCodec::Type::Bytes_32 : GsmCodec::Type::Bytes_33, mSettings.mGsmFrPayloadType));
// mFactoryList.push_back(new G722Codec::G722Factory());
// mFactoryList.push_back(new G729Codec::G729Factory());
#ifndef TARGET_ANDROID
mFactoryList.push_back(new GsmHrCodec::GsmHrFactory(mSettings.mGsmHrPayloadType));
#endif
@ -231,7 +231,7 @@ void CodecListPriority::setupFrom(PVariantMap vmap)
{
Item item;
item.mCodecIndex = i;
item.mPriority = vmap->exists(i) ? vmap->at(i).asInt() : -1;
item.mPriority = vmap->exists(i) ? vmap->at(i).asInt() : 1000; // Non listed codecs will get lower priority
mPriorityList.push_back(item);
}