mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
支持根据情况选择是否发生rtp
This commit is contained in:
parent
c42b678cab
commit
dc485c6211
@ -228,7 +228,7 @@ namespace RTC
|
||||
bool handshakeDoneNow{ false };
|
||||
std::string remoteCert;
|
||||
//最大不超过mtu
|
||||
static constexpr int SslReadBufferSize{ 1600 };
|
||||
static constexpr int SslReadBufferSize{ 2000 };
|
||||
uint8_t sslReadBuffer[SslReadBufferSize];
|
||||
};
|
||||
} // namespace RTC
|
||||
|
@ -59,7 +59,7 @@ namespace RTC
|
||||
// Allocated by this.
|
||||
srtp_t session{ nullptr };
|
||||
//rtp包最大1600
|
||||
static constexpr size_t EncryptBufferSize{ 1600 };
|
||||
static constexpr size_t EncryptBufferSize{ 2000 };
|
||||
uint8_t EncryptBuffer[EncryptBufferSize];
|
||||
DepLibSRTP::Ptr _env;
|
||||
};
|
||||
|
@ -226,23 +226,17 @@ void WebRtcTransportImp::onStartWebRTC() {
|
||||
});
|
||||
}
|
||||
|
||||
uint8_t WebRtcTransportImp::getSendPayloadType(TrackType type) {
|
||||
for (auto &m : getSdp(SdpType::answer).media) {
|
||||
if (m.type == type) {
|
||||
return m.plan[0].pt;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){
|
||||
//需要修改pt
|
||||
if (rtp->type == TrackVideo) {
|
||||
rtp->getHeader()->pt = getSendPayloadType(rtp->type);
|
||||
sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush);
|
||||
} else {
|
||||
|
||||
if (!_send_rtp_pt[rtp->type]) {
|
||||
//忽略,对方不支持该编码类型
|
||||
return;
|
||||
}
|
||||
auto tmp = rtp->getHeader()->pt;
|
||||
//设置pt
|
||||
rtp->getHeader()->pt = _send_rtp_pt[rtp->type];
|
||||
sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush);
|
||||
//还原pt
|
||||
rtp->getHeader()->pt = tmp;
|
||||
}
|
||||
|
||||
bool WebRtcTransportImp::canSendRtp() const{
|
||||
@ -250,7 +244,6 @@ bool WebRtcTransportImp::canSendRtp() const{
|
||||
return sdp.media[0].direction == RtpDirection::sendrecv || sdp.media[0].direction == RtpDirection::sendonly;
|
||||
}
|
||||
|
||||
|
||||
void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{
|
||||
WebRtcTransport::onCheckSdp(type, sdp);
|
||||
if (type != SdpType::answer || !canSendRtp()) {
|
||||
@ -263,19 +256,21 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{
|
||||
}
|
||||
m.rtp_ssrc.ssrc = _src->getSsrc(m.type);
|
||||
m.rtp_ssrc.cname = "zlmediakit-rtc";
|
||||
auto rtsp_media = _rtsp_send_sdp.getMedia(m.type);
|
||||
if (rtsp_media && getCodecId(rtsp_media->plan[0].codec) == getCodecId(m.plan[0].codec)) {
|
||||
_send_rtp_pt[m.type] = m.plan[0].pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
||||
WebRtcTransport::onRtcConfigure(configure);
|
||||
|
||||
RtcSession sdp;
|
||||
sdp.loadFrom(_src->getSdp(), false);
|
||||
_rtsp_send_sdp.loadFrom(_src->getSdp(), false);
|
||||
|
||||
configure.audio.enable = false;
|
||||
configure.video.enable = false;
|
||||
|
||||
for (auto &m : sdp.media) {
|
||||
for (auto &m : _rtsp_send_sdp.media) {
|
||||
switch (m.type) {
|
||||
case TrackVideo: {
|
||||
configure.video.enable = true;
|
||||
|
@ -127,7 +127,6 @@ private:
|
||||
void onDestory() override;
|
||||
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush);
|
||||
SdpAttrCandidate::Ptr getIceCandidate() const;
|
||||
uint8_t getSendPayloadType(TrackType type);
|
||||
bool canSendRtp() const;
|
||||
|
||||
private:
|
||||
@ -135,6 +134,8 @@ private:
|
||||
RtspMediaSource::Ptr _src;
|
||||
RtspMediaSource::RingType::RingReader::Ptr _reader;
|
||||
RtcSession _answer_sdp;
|
||||
mutable RtcSession _rtsp_send_sdp;
|
||||
mutable uint8_t _send_rtp_pt[2] = {0, 0};
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user