From c7633fb5bb5c0a2f0b360f779240ed0c6ab8024a Mon Sep 17 00:00:00 2001 From: Johnny Date: Tue, 12 Oct 2021 15:34:36 +0800 Subject: [PATCH] =?UTF-8?q?Refine(webrtc/sdp):=20=E7=A7=BB=E9=99=A4getSdp(?= =?UTF-8?q?SdpType=20type)=E3=80=82=E7=9B=B8=E8=BE=83=E8=80=8C=E8=A8=80?= =?UTF-8?q?=EF=BC=8C=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8=5Foffer=5Fsdp=20?= =?UTF-8?q?=E5=92=8C=20=5Fanswer=5Fsdp=20=E6=9B=B4=E5=A5=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcTransport.cpp | 24 ++++++++---------------- webrtc/WebRtcTransport.h | 5 ++--- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 2b74ea8c..94dc5a81 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -137,14 +137,6 @@ void WebRtcTransport::onSendSockData(const char *buf, size_t len, bool flush){ onSendSockData(buf, len, (struct sockaddr_in *) tuple, flush); } -const RtcSession& WebRtcTransport::getSdp(SdpType type) const{ - switch (type) { - case SdpType::offer: return *_offer_sdp; - case SdpType::answer: return *_answer_sdp; - default: throw std::invalid_argument("不识别的sdp类型"); - } -} - RTC::TransportTuple* WebRtcTransport::getSelectedTuple() const{ return _ice_server->GetSelectedTuple(); } @@ -409,7 +401,7 @@ bool WebRtcTransportImp::canSendRtp() const{ if (!_play_src) { return false; } - for (auto &m : getSdp(SdpType::answer).media) { + for (auto &m : _answer_sdp->media) { if (m.direction == RtpDirection::sendrecv || m.direction == RtpDirection::sendonly) { return true; } @@ -421,7 +413,7 @@ bool WebRtcTransportImp::canRecvRtp() const{ if (!_push_src) { return false; } - for (auto &m : getSdp(SdpType::answer).media) { + for (auto &m : _answer_sdp->media) { if (m.direction == RtpDirection::sendrecv || m.direction == RtpDirection::recvonly) { return true; } @@ -431,8 +423,8 @@ bool WebRtcTransportImp::canRecvRtp() const{ void WebRtcTransportImp::onStartWebRTC() { //获取ssrc和pt相关信息,届时收到rtp和rtcp时分别可以根据pt和ssrc找到相关的信息 - for (auto &m_answer : getSdp(SdpType::answer).media) { - auto m_offer = getSdp(SdpType::offer).getMedia(m_answer.type); + for (auto &m_answer : _answer_sdp->media) { + auto m_offer = _offer_sdp->getMedia(m_answer.type); auto track = std::make_shared(); track->media = &m_answer; @@ -484,13 +476,13 @@ void WebRtcTransportImp::onStartWebRTC() { } if (canRecvRtp()) { - _push_src->setSdp(getSdp(SdpType::answer).toRtspSdp()); - _simulcast = getSdp(SdpType::answer).supportSimulcast(); + _push_src->setSdp(_answer_sdp->toRtspSdp()); + _simulcast = _answer_sdp->supportSimulcast(); } if (canSendRtp()) { RtcSession rtsp_send_sdp; rtsp_send_sdp.loadFrom(_play_src->getSdp(), false); - for (auto &m : getSdp(SdpType::answer).media) { + for (auto &m : _answer_sdp->media) { if (m.type == TrackApplication) { continue; } @@ -886,7 +878,7 @@ void WebRtcTransportImp::onSortedRtp(MediaTrack &track, const string &rid, RtpPa //开启remb,则发送remb包调节比特率 GET_CONFIG(size_t, remb_bit_rate, RTC::kRembBitRate); - if (remb_bit_rate && getSdp(SdpType::answer).supportRtcpFb(SdpConst::kRembRtcpFb)) { + if (remb_bit_rate && _answer_sdp->supportRtcpFb(SdpConst::kRembRtcpFb)) { sendRtcpRemb(rtp->getSSRC(), remb_bit_rate); } } diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index 069c0cda..b6aa5c4a 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -116,7 +116,8 @@ protected: virtual void onBeforeEncryptRtcp(const char *buf, int &len, void *ctx) = 0; protected: - const RtcSession& getSdp(SdpType type) const; + RtcSession::Ptr _offer_sdp; + RtcSession::Ptr _answer_sdp; RTC::TransportTuple* getSelectedTuple() const; void sendRtcpRemb(uint32_t ssrc, size_t bit_rate); void sendRtcpPli(uint32_t ssrc); @@ -133,8 +134,6 @@ private: std::shared_ptr _dtls_transport; std::shared_ptr _srtp_session_send; std::shared_ptr _srtp_session_recv; - RtcSession::Ptr _offer_sdp; - RtcSession::Ptr _answer_sdp; Ticker _ticker; };