codecs: add support for g726, rename PCMA & PCMU

GitLab: #694
Change-Id: I74e430b89db2831979b45a56a566d496e0b7936b
This commit is contained in:
Adrien Béraud
2022-06-23 11:53:47 -04:00
parent f663929091
commit a7c048293f
6 changed files with 76 additions and 36 deletions

View File

@ -43,6 +43,9 @@ FFMPEGCONF += \
--disable-muxers \
--enable-muxer=rtp \
--enable-muxer=g722 \
--enable-muxer=g723_1 \
--enable-muxer=g726 \
--enable-muxer=g726le \
--enable-muxer=h263 \
--enable-muxer=h264 \
--enable-muxer=hevc \
@ -67,6 +70,9 @@ FFMPEGCONF += \
--enable-demuxer=wav \
--enable-demuxer=ac3 \
--enable-demuxer=g722 \
--enable-demuxer=g723_1 \
--enable-demuxer=g726 \
--enable-demuxer=g726le \
--enable-demuxer=pcm_mulaw \
--enable-demuxer=pcm_alaw \
--enable-demuxer=pcm_s16be \
@ -89,6 +95,13 @@ FFMPEGCONF += \
FFMPEGCONF += \
--enable-encoder=adpcm_g722 \
--enable-decoder=adpcm_g722 \
--enable-encoder=adpcm_g726 \
--enable-decoder=adpcm_g726 \
--enable-encoder=adpcm_g726le \
--enable-decoder=adpcm_g726le \
--enable-decoder=g729 \
--enable-encoder=g723_1 \
--enable-decoder=g723_1 \
--enable-encoder=rawvideo \
--enable-decoder=rawvideo \
--enable-encoder=libx264 \

View File

@ -35,6 +35,7 @@ namespace jami {
*/
SystemCodecInfo::SystemCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
MediaType mediaType,
@ -45,6 +46,7 @@ SystemCodecInfo::SystemCodecInfo(unsigned codecId,
unsigned maxQuality)
: id(codecId)
, avcodecId(avcodecId)
, longName(longName)
, name(name)
, libName(libName)
, codecType(codecType)
@ -62,6 +64,7 @@ SystemCodecInfo::~SystemCodecInfo() {}
*/
SystemAudioCodecInfo::SystemAudioCodecInfo(unsigned codecId,
unsigned m_avcodecId,
const std::string& longName,
const std::string& m_name,
const std::string& m_libName,
CodecType m_type,
@ -71,6 +74,7 @@ SystemAudioCodecInfo::SystemAudioCodecInfo(unsigned codecId,
unsigned m_payloadType)
: SystemCodecInfo(codecId,
m_avcodecId,
longName,
m_name,
m_libName,
MEDIA_AUDIO,
@ -83,9 +87,9 @@ SystemAudioCodecInfo::SystemAudioCodecInfo(unsigned codecId,
SystemAudioCodecInfo::~SystemAudioCodecInfo() {}
std::map<std::string, std::string>
SystemAudioCodecInfo::getCodecSpecifications()
SystemAudioCodecInfo::getCodecSpecifications() const
{
return {{DRing::Account::ConfProperties::CodecInfo::NAME, name},
return {{DRing::Account::ConfProperties::CodecInfo::NAME, longName},
{DRing::Account::ConfProperties::CodecInfo::TYPE,
(mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
{DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
@ -100,6 +104,7 @@ SystemAudioCodecInfo::getCodecSpecifications()
*/
SystemVideoCodecInfo::SystemVideoCodecInfo(unsigned codecId,
unsigned m_avcodecId,
const std::string& longName,
const std::string& m_name,
const std::string& m_libName,
CodecType m_type,
@ -111,6 +116,7 @@ SystemVideoCodecInfo::SystemVideoCodecInfo(unsigned codecId,
unsigned m_profileId)
: SystemCodecInfo(codecId,
m_avcodecId,
longName,
m_name,
m_libName,
MEDIA_VIDEO,
@ -126,10 +132,10 @@ SystemVideoCodecInfo::SystemVideoCodecInfo(unsigned codecId,
SystemVideoCodecInfo::~SystemVideoCodecInfo() {}
std::map<std::string, std::string>
SystemVideoCodecInfo::getCodecSpecifications()
SystemVideoCodecInfo::getCodecSpecifications() const
{
return {
{DRing::Account::ConfProperties::CodecInfo::NAME, name},
{DRing::Account::ConfProperties::CodecInfo::NAME, longName},
{DRing::Account::ConfProperties::CodecInfo::TYPE,
(mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
{DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
@ -169,9 +175,9 @@ AccountAudioCodecInfo::AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCode
{}
std::map<std::string, std::string>
AccountAudioCodecInfo::getCodecSpecifications()
AccountAudioCodecInfo::getCodecSpecifications() const
{
return {{DRing::Account::ConfProperties::CodecInfo::NAME, systemCodecInfo.name},
return {{DRing::Account::ConfProperties::CodecInfo::NAME, systemCodecInfo.longName},
{DRing::Account::ConfProperties::CodecInfo::TYPE,
(systemCodecInfo.mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
{DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},
@ -208,9 +214,9 @@ AccountVideoCodecInfo::AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCode
{}
std::map<std::string, std::string>
AccountVideoCodecInfo::getCodecSpecifications()
AccountVideoCodecInfo::getCodecSpecifications() const
{
return {{DRing::Account::ConfProperties::CodecInfo::NAME, systemCodecInfo.name},
return {{DRing::Account::ConfProperties::CodecInfo::NAME, systemCodecInfo.longName},
{DRing::Account::ConfProperties::CodecInfo::TYPE,
(systemCodecInfo.mediaType & MEDIA_AUDIO ? "AUDIO" : "VIDEO")},
{DRing::Account::ConfProperties::CodecInfo::BITRATE, std::to_string(bitrate)},

View File

@ -86,6 +86,7 @@ struct SystemCodecInfo
SystemCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
MediaType mediaType,
@ -99,8 +100,9 @@ struct SystemCodecInfo
/* generic codec information */
unsigned id; /* id of the codec used with dbus */
unsigned avcodecId; /* read as AVCodecID libav codec identifier */
std::string name;
unsigned avcodecId; /* AVCodecID libav codec identifier */
std::string longName; /* User-friendly codec name */
std::string name; /* RTP codec name as specified by http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml */
std::string libName;
CodecType codecType;
MediaType mediaType;
@ -123,6 +125,7 @@ struct SystemAudioCodecInfo : SystemCodecInfo
{
SystemAudioCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
CodecType type,
@ -133,7 +136,7 @@ struct SystemAudioCodecInfo : SystemCodecInfo
~SystemAudioCodecInfo();
std::map<std::string, std::string> getCodecSpecifications();
std::map<std::string, std::string> getCodecSpecifications() const;
AudioFormat audioformat {AudioFormat::NONE()};
};
@ -147,6 +150,7 @@ struct SystemVideoCodecInfo : SystemCodecInfo
{
SystemVideoCodecInfo(unsigned codecId,
unsigned avcodecId,
const std::string& longName,
const std::string& name,
const std::string& libName,
CodecType type = CODEC_NONE,
@ -159,7 +163,7 @@ struct SystemVideoCodecInfo : SystemCodecInfo
~SystemVideoCodecInfo();
std::map<std::string, std::string> getCodecSpecifications();
std::map<std::string, std::string> getCodecSpecifications() const;
unsigned frameRate;
unsigned profileId;
@ -186,14 +190,14 @@ struct AccountCodecInfo
unsigned payloadType;
unsigned bitrate;
unsigned quality;
std::map<std::string, std::string> getCodecSpecifications();
std::map<std::string, std::string> getCodecSpecifications() const;
};
struct AccountAudioCodecInfo : AccountCodecInfo
{
AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo);
std::map<std::string, std::string> getCodecSpecifications();
std::map<std::string, std::string> getCodecSpecifications() const;
void setCodecSpecifications(const std::map<std::string, std::string>& details);
/* account custom values */
@ -206,7 +210,7 @@ struct AccountVideoCodecInfo : AccountCodecInfo
AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo);
void setCodecSpecifications(const std::map<std::string, std::string>& details);
std::map<std::string, std::string> getCodecSpecifications();
std::map<std::string, std::string> getCodecSpecifications() const;
/* account custom values */
unsigned frameRate;

View File

@ -64,6 +64,7 @@ SystemCodecContainer::initCodecConfig()
/* Define supported video codec*/
std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_HEVC,
AV_CODEC_ID_HEVC,
"H.265/HEVC",
"H265",
"",
CODEC_ENCODER_DECODER,
@ -73,6 +74,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_H264,
AV_CODEC_ID_H264,
"H.264/AVC",
"H264",
"libx264",
CODEC_ENCODER_DECODER,
@ -83,6 +85,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_VP8,
AV_CODEC_ID_VP8,
"VP8",
"VP8",
"libvpx",
CODEC_ENCODER_DECODER,
defaultBitrate,
@ -92,12 +95,14 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_MPEG4,
AV_CODEC_ID_MPEG4,
"MP4V-ES",
"MP4V-ES",
"mpeg4",
CODEC_ENCODER_DECODER,
defaultBitrate),
std::make_shared<SystemVideoCodecInfo>(AV_CODEC_ID_H263,
AV_CODEC_ID_H263,
"H.263",
"H263-1998",
"h263",
CODEC_ENCODER_DECODER,
@ -109,6 +114,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_OPUS,
AV_CODEC_ID_OPUS,
"Opus",
"opus",
"libopus",
CODEC_ENCODER_DECODER,
@ -119,6 +125,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_ADPCM_G722,
AV_CODEC_ID_ADPCM_G722,
"G.722",
"G722",
"g722",
CODEC_ENCODER_DECODER,
@ -127,8 +134,20 @@ SystemCodecContainer::initCodecConfig()
1,
9),
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_ADPCM_G726,
AV_CODEC_ID_ADPCM_G726,
"G.726",
"G726-32",
"g726",
CODEC_ENCODER_DECODER,
0,
8000,
1,
2),
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_SPEEX | 0x20000000,
AV_CODEC_ID_SPEEX,
"Speex",
"speex",
"libspeex",
CODEC_ENCODER_DECODER,
@ -139,6 +158,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_SPEEX | 0x10000000,
AV_CODEC_ID_SPEEX,
"Speex",
"speex",
"libspeex",
CODEC_ENCODER_DECODER,
@ -149,6 +169,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_SPEEX,
AV_CODEC_ID_SPEEX,
"Speex",
"speex",
"libspeex",
CODEC_ENCODER_DECODER,
@ -159,6 +180,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_PCM_ALAW,
AV_CODEC_ID_PCM_ALAW,
"G.711a",
"PCMA",
"pcm_alaw",
CODEC_ENCODER_DECODER,
@ -169,6 +191,7 @@ SystemCodecContainer::initCodecConfig()
std::make_shared<SystemAudioCodecInfo>(AV_CODEC_ID_PCM_MULAW,
AV_CODEC_ID_PCM_MULAW,
"G.711u",
"PCMU",
"pcm_mulaw",
CODEC_ENCODER_DECODER,
@ -203,28 +226,23 @@ SystemCodecContainer::setActiveH265()
void
SystemCodecContainer::checkInstalledCodecs()
{
AVCodecID codecId;
std::string codecName;
CodecType codecType;
std::stringstream enc_ss;
std::stringstream dec_ss;
std::ostringstream enc_ss;
std::ostringstream dec_ss;
for (const auto& codecIt : availableCodecList_) {
codecId = (AVCodecID) codecIt->avcodecId;
codecName = codecIt->name;
codecType = codecIt->codecType;
AVCodecID codecId = (AVCodecID) codecIt->avcodecId;
CodecType codecType = codecIt->codecType;
if (codecType & CODEC_ENCODER) {
if (avcodec_find_encoder(codecId) != nullptr)
enc_ss << codecName << " ";
enc_ss << codecIt->name << ' ';
else
codecIt->codecType = (CodecType)((unsigned) codecType & ~CODEC_ENCODER);
}
if (codecType & CODEC_DECODER) {
if (avcodec_find_decoder(codecId) != nullptr)
dec_ss << codecName << " ";
dec_ss << codecIt->name << ' ';
else
codecIt->codecType = (CodecType)((unsigned) codecType & ~CODEC_DECODER);
}

View File

@ -86,14 +86,13 @@ Sdp::~Sdp()
}
std::shared_ptr<AccountCodecInfo>
Sdp::findCodecBySpec(const std::string& codec, const unsigned clockrate) const
Sdp::findCodecBySpec(std::string_view codec, const unsigned clockrate) const
{
// TODO : only manage a list?
for (const auto& accountCodec : audio_codec_list_) {
auto audioCodecInfo = std::static_pointer_cast<AccountAudioCodecInfo>(accountCodec);
auto& sysCodecInfo = *static_cast<const SystemAudioCodecInfo*>(
&audioCodecInfo->systemCodecInfo);
if (sysCodecInfo.name.compare(codec) == 0
auto& sysCodecInfo = *static_cast<const SystemAudioCodecInfo*>(&audioCodecInfo->systemCodecInfo);
if (sysCodecInfo.name == codec
and (audioCodecInfo->isPCMG722() ? (clockrate == 8000)
: (sysCodecInfo.audioformat.sample_rate == clockrate)))
return accountCodec;
@ -101,7 +100,7 @@ Sdp::findCodecBySpec(const std::string& codec, const unsigned clockrate) const
for (const auto& accountCodec : video_codec_list_) {
auto sysCodecInfo = accountCodec->systemCodecInfo;
if (sysCodecInfo.name.compare(codec) == 0)
if (sysCodecInfo.name == codec)
return accountCodec;
}
return nullptr;
@ -112,13 +111,13 @@ Sdp::findCodecByPayload(const unsigned payloadType)
{
// TODO : only manage a list?
for (const auto& accountCodec : audio_codec_list_) {
auto sysCodecInfo = accountCodec->systemCodecInfo;
auto& sysCodecInfo = accountCodec->systemCodecInfo;
if (sysCodecInfo.payloadType == payloadType)
return accountCodec;
}
for (const auto& accountCodec : video_codec_list_) {
auto sysCodecInfo = accountCodec->systemCodecInfo;
auto& sysCodecInfo = accountCodec->systemCodecInfo;
if (sysCodecInfo.payloadType == payloadType)
return accountCodec;
}
@ -847,11 +846,11 @@ Sdp::getMediaDescriptions(const pjmedia_sdp_session* session, bool remote) const
descr.enabled = false;
continue;
}
const std::string codec_raw(rtpmap.enc_name.ptr, rtpmap.enc_name.slen);
auto codec_raw = sip_utils::as_view(rtpmap.enc_name);
descr.rtp_clockrate = rtpmap.clock_rate;
descr.codec = findCodecBySpec(codec_raw, rtpmap.clock_rate);
if (not descr.codec) {
JAMI_ERR("Could not find codec %s", codec_raw.c_str());
JAMI_ERR("Could not find codec %.*s", (int)codec_raw.size(), codec_raw.data());
descr.enabled = false;
continue;
}

View File

@ -265,7 +265,7 @@ private:
void addRTCPAttribute(pjmedia_sdp_media* med, uint16_t port);
std::shared_ptr<AccountCodecInfo> findCodecByPayload(const unsigned payloadType);
std::shared_ptr<AccountCodecInfo> findCodecBySpec(const std::string& codecName,
std::shared_ptr<AccountCodecInfo> findCodecBySpec(std::string_view codecName,
const unsigned clockrate = 0) const;
// Data members