rtp send rtp g711 audio can config duration (#3325)

optimization for this
[issue](https://github.com/ZLMediaKit/ZLMediaKit/issues/3316)
This commit is contained in:
xiongguangjie
2024-03-02 16:40:13 +08:00
committed by GitHub
parent 87cb488b04
commit 06abbd0eb7
7 changed files with 50 additions and 7 deletions

View File

@@ -338,6 +338,7 @@ const string kH265PT = RTP_PROXY_FIELD "h265_pt";
const string kPSPT = RTP_PROXY_FIELD "ps_pt";
const string kOpusPT = RTP_PROXY_FIELD "opus_pt";
const string kGopCache = RTP_PROXY_FIELD "gop_cache";
const string kRtpG711DurMs = RTP_PROXY_FIELD "rtp_g711_dur_ms";
static onceToken token([]() {
mINI::Instance()[kDumpDir] = "";
@@ -348,6 +349,7 @@ static onceToken token([]() {
mINI::Instance()[kPSPT] = 96;
mINI::Instance()[kOpusPT] = 100;
mINI::Instance()[kGopCache] = 1;
mINI::Instance()[kRtpG711DurMs] = 100;
});
} // namespace RtpProxy

View File

@@ -382,6 +382,9 @@ extern const std::string kPSPT;
extern const std::string kOpusPT;
// RtpSender相关功能是否提前开启gop缓存优化级联秒开体验默认开启
extern const std::string kGopCache;
//国标发送g711 rtp 打包时每个包的语音时长是多少默认是100 ms范围为20~180ms (gb28181-2016c.2.4规定)
//最好为20 的倍数程序自动向20的倍数取整
extern const std::string kRtpG711DurMs;
} // namespace RtpProxy
/**

View File

@@ -34,6 +34,12 @@ bool RawEncoderImp::addTrack(const Track::Ptr &track) {
auto ring = std::make_shared<RtpRing::RingType>();
ring->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key) { onRTP(std::move(rtp), true); }));
_rtp_encoder->setRtpRing(std::move(ring));
if (track->getCodecId() == CodecG711A || track->getCodecId() == CodecG711U) {
GET_CONFIG(uint32_t, dur_ms, RtpProxy::kRtpG711DurMs);
Any param;
param.set<uint32_t>(dur_ms);
_rtp_encoder->setOpt(RtpCodec::RTP_ENCODER_PKT_DUR_MS, param);
}
return true;
}

View File

@@ -93,6 +93,17 @@ public:
RtpInfo &getRtpInfo() { return *_rtp_info; }
enum {
RTP_ENCODER_PKT_DUR_MS = 1 // 主要应用于g711 rtp 打包器每个包的时间长度option_value 为int*, option_len 为4
};
/**
* @brief 设置rtp打包器与解包器的相关参数主要应用与g711 rtp 打包器使用方法类似setsockopt
*
* @param opt 设置的选项
* @param param 设置的参数
*/
virtual void setOpt(int opt, const toolkit::Any &param) {};
private:
std::unique_ptr<RtpInfo> _rtp_info;
};