Skip to content

Commit

Permalink
Gop缓冲区大小改成可按协议配置
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdxc committed Dec 26, 2024
1 parent 490b035 commit 15a944d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ const string kKeepAliveSecond = RTSP_FIELD "keepAliveSecond";
const string kDirectProxy = RTSP_FIELD "directProxy";
const string kLowLatency = RTSP_FIELD"lowLatency";
const string kRtpTransportType = RTSP_FIELD"rtpTransportType";
const string kRingSize = RTSP_FIELD "ringSize";

static onceToken token([]() {
// 默认Md5方式认证 [AUTO-TRANSLATED:6155d989]
Expand All @@ -252,6 +253,7 @@ static onceToken token([]() {
mINI::Instance()[kDirectProxy] = 1;
mINI::Instance()[kLowLatency] = 0;
mINI::Instance()[kRtpTransportType] = -1;
mINI::Instance()[kRingSize] = 2048;
});
} // namespace Rtsp

Expand All @@ -263,12 +265,13 @@ const string kHandshakeSecond = RTMP_FIELD "handshakeSecond";
const string kKeepAliveSecond = RTMP_FIELD "keepAliveSecond";
const string kDirectProxy = RTMP_FIELD "directProxy";
const string kEnhanced = RTMP_FIELD "enhanced";

const string kRingSize = RTMP_FIELD "ringSize";
static onceToken token([]() {
mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15;
mINI::Instance()[kDirectProxy] = 1;
mINI::Instance()[kEnhanced] = 0;
mINI::Instance()[kRingSize] = 1024;
});
} // namespace Rtmp

Expand All @@ -285,13 +288,15 @@ const string kAudioMtuSize = RTP_FIELD "audioMtuSize";
const string kRtpMaxSize = RTP_FIELD "rtpMaxSize";
const string kLowLatency = RTP_FIELD "lowLatency";
const string kH264StapA = RTP_FIELD "h264_stap_a";
const string kRingSize = RTP_FIELD "ringSize";

static onceToken token([]() {
mINI::Instance()[kVideoMtuSize] = 1400;
mINI::Instance()[kAudioMtuSize] = 600;
mINI::Instance()[kRtpMaxSize] = 10;
mINI::Instance()[kLowLatency] = 0;
mINI::Instance()[kH264StapA] = 1;
mINI::Instance()[kRingSize] = 2048;
});
} // namespace Rtp

Expand Down
3 changes: 3 additions & 0 deletions src/Common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ extern const std::string kLowLatency;
// 迫使客户端重新SETUP并切换到对应协议。目前支持FFMPEG和VLC [AUTO-TRANSLATED:45f9cddb]
// Force the client to re-SETUP and switch to the corresponding protocol. Currently supports FFMPEG and VLC
extern const std::string kRtpTransportType;
extern const std::string kRingSize;
} // namespace Rtsp

// //////////RTMP服务器配置/////////// [AUTO-TRANSLATED:8de6f41f]
Expand All @@ -444,6 +445,7 @@ extern const std::string kDirectProxy;
// h265-rtmp是否采用增强型(或者国内扩展) [AUTO-TRANSLATED:4a52d042]
// Whether h265-rtmp uses enhanced (or domestic extension)
extern const std::string kEnhanced;
extern const std::string kRingSize;
} // namespace Rtmp

// //////////RTP配置/////////// [AUTO-TRANSLATED:23cbcb86]
Expand All @@ -464,6 +466,7 @@ extern const std::string kLowLatency;
// H264 rtp打包模式是否采用stap-a模式(为了在老版本浏览器上兼容webrtc)还是采用Single NAL unit packet per H.264 模式 [AUTO-TRANSLATED:30632378]
// Whether H264 RTP packaging mode uses stap-a mode (for compatibility with webrtc on older browsers) or Single NAL unit packet per H.264 mode
extern const std::string kH264StapA;
extern const std::string kRingSize;
} // namespace Rtp

// //////////组播配置/////////// [AUTO-TRANSLATED:dc39b9d6]
Expand Down
4 changes: 3 additions & 1 deletion src/Rtmp/RtmpMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "RtmpMuxer.h"
#include "Extension/Factory.h"
#include "Common/config.h"

namespace mediakit {

Expand All @@ -19,7 +20,8 @@ RtmpMuxer::RtmpMuxer(const TitleMeta::Ptr &title) {
} else {
_metadata = title->getMetadata();
}
_rtmp_ring = std::make_shared<RtmpRing::RingType>();
GET_CONFIG(int, ringSize, Rtmp::kRingSize);
_rtmp_ring = std::make_shared<RtmpRing::RingType>(ringSize);
}

bool RtmpMuxer::addTrack(const Track::Ptr &track) {
Expand Down
3 changes: 2 additions & 1 deletion src/Rtp/PSEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ PSEncoderImp::PSEncoderImp(uint32_t ssrc, uint8_t payload_type, bool ps_or_ts) :
}
}
_rtp_encoder->setRtpInfo(ssrc, video_mtu, 90000, payload_type);
auto ring = std::make_shared<RtpRing::RingType>();
GET_CONFIG(int, ringSize, Rtp::kRingSize);
auto ring = std::make_shared<RtpRing::RingType>(ringSize);
ring->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key) { onRTP(std::move(rtp), is_key); }));
_rtp_encoder->setRtpRing(std::move(ring));
InfoL << this << " " << ssrc;
Expand Down
5 changes: 3 additions & 2 deletions src/Rtp/RawEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ RawEncoderImp::~RawEncoderImp() {
}

bool RawEncoderImp::addTrack(const Track::Ptr &track) {
GET_CONFIG(int, ringSize, Rtp::kRingSize);
if (_send_audio && track->getTrackType() == TrackType::TrackAudio && !_rtp_encoder) { // audio
_rtp_encoder = createRtpEncoder(track);
auto ring = std::make_shared<RtpRing::RingType>();
auto ring = std::make_shared<RtpRing::RingType>(ringSize);
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) {
Expand All @@ -45,7 +46,7 @@ bool RawEncoderImp::addTrack(const Track::Ptr &track) {

if (!_send_audio && track->getTrackType() == TrackType::TrackVideo && !_rtp_encoder) {
_rtp_encoder = createRtpEncoder(track);
auto ring = std::make_shared<RtpRing::RingType>();
auto ring = std::make_shared<RtpRing::RingType>(ringSize);
ring->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key) { onRTP(std::move(rtp), is_key); }));
_rtp_encoder->setRtpRing(std::move(ring));
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/Rtsp/RtspMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title) {
_live = title->getDuration() == 0;
_sdp = title->getSdp();
}
_rtpRing = std::make_shared<RtpRing::RingType>();
GET_CONFIG(int, ringSize, Rtsp::kRingSize);
_rtpRing = std::make_shared<RtpRing::RingType>(ringSize);
_rtpInterceptor = std::make_shared<RtpRing::RingType>();
_rtpInterceptor->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr in, bool is_key) {
onRtp(std::move(in), is_key);
Expand Down
28 changes: 28 additions & 0 deletions www/webassist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,15 @@
v-model="serverConfig.rtmp.keepAliveSecond"></el-input>
</div>
</div>
<div class="conf_item">
<div class="conf_item_label">
Gop缓冲大小
</div>
<div class="conf_item_value">
<el-input type="text"
v-model="serverConfig.rtmp.ringSize"></el-input>
</div>
</div>
</div>
</el-col>
</el-row>
Expand Down Expand Up @@ -2056,6 +2065,16 @@
v-model="serverConfig.rtsp.handshakeSecond"></el-input>
</div>
</div>
<div class="conf_item">
<div class="conf_item_label">

Gop缓冲大小
</div>
<div class="conf_item_value">
<el-input type="text"
v-model="serverConfig.rtsp.ringSize"></el-input>
</div>
</div>
<div class="conf_item">
<div class="conf_item_label">
直接代理模式
Expand Down Expand Up @@ -2124,6 +2143,15 @@
<el-input type="text" v-model="serverConfig.rtp.rtpMaxSize"></el-input>
</div>
</div>
<div class="conf_item">
<div class="conf_item_label">
Gop缓冲大小
</div>
<div class="conf_item_value">
<el-input type="text"
v-model="serverConfig.rtp.ringSize"></el-input>
</div>
</div>
<div class="conf_item">
<div class="conf_item_label">
<el-tooltip effect="dark" placement="bottom-start">
Expand Down

0 comments on commit 15a944d

Please sign in to comment.