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