From 758f1b414eb23fd542dd6c14b98716c2435230e3 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Wed, 20 Oct 2021 16:58:59 +0800 Subject: [PATCH] =?UTF-8?q?webrtc=E6=98=AF=E5=90=A6=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E5=8F=91=E9=80=81rtp=E9=80=BB=E8=BE=91=E7=A7=BB=E8=87=B3?= =?UTF-8?q?=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcPlayer.cpp | 15 +-------------- webrtc/WebRtcPlayer.h | 2 -- webrtc/WebRtcTransport.cpp | 5 ++++- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/webrtc/WebRtcPlayer.cpp b/webrtc/WebRtcPlayer.cpp index 7531332d..1bd8b513 100644 --- a/webrtc/WebRtcPlayer.cpp +++ b/webrtc/WebRtcPlayer.cpp @@ -33,12 +33,6 @@ void WebRtcPlayer::onStartWebRTC() { CHECK(_play_src); WebRtcTransportImp::onStartWebRTC(); if (canSendRtp()) { - //确保该rtp codec类型对方支持 - memset(_can_send_rtp, 0, sizeof(_can_send_rtp)); - for (auto &m : _answer_sdp->media) { - _can_send_rtp[m.type] = m.direction == RtpDirection::sendonly || m.direction == RtpDirection::sendrecv; - } - _play_src->pause(false); _reader = _play_src->getRing()->attach(getPoller(), true); weak_ptr weak_self = static_pointer_cast(shared_from_this()); @@ -49,7 +43,7 @@ void WebRtcPlayer::onStartWebRTC() { } size_t i = 0; pkt->for_each([&](const RtpPacket::Ptr &rtp) { - strongSelf->beforeSendRtp(rtp, ++i == pkt->size()); + strongSelf->onSendRtp(rtp, ++i == pkt->size()); }); }); _reader->setDetachCB([weak_self]() { @@ -91,10 +85,3 @@ void WebRtcPlayer::onRtcConfigure(RtcConfigure &configure) const { configure.audio.direction = configure.video.direction = RtpDirection::sendonly; configure.setPlayRtspInfo(_play_src->getSdp()); } - -void WebRtcPlayer::beforeSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx) { - if (!_can_send_rtp[rtp->type]) { - return; - } - onSendRtp(rtp, flush, rtx); -} diff --git a/webrtc/WebRtcPlayer.h b/webrtc/WebRtcPlayer.h index ade67388..beb25ef2 100644 --- a/webrtc/WebRtcPlayer.h +++ b/webrtc/WebRtcPlayer.h @@ -28,10 +28,8 @@ protected: private: WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info); - void beforeSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false); private: - bool _can_send_rtp[TrackMax]; //媒体相关元数据 MediaInfo _media_info; //播放的rtsp源 diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index c7a8106f..28ce411c 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -372,7 +372,10 @@ void WebRtcTransportImp::onStartWebRTC() { track->rtcp_context_send = std::make_shared(); //rtp track type --> MediaTrack - _type_to_track[m_answer.type] = track; + if (m_answer.direction == RtpDirection::sendonly || m_answer.direction == RtpDirection::sendrecv) { + //该类型的track 才支持发送 + _type_to_track[m_answer.type] = track; + } //send ssrc --> MediaTrack _ssrc_to_track[track->answer_ssrc_rtp] = track; _ssrc_to_track[track->answer_ssrc_rtx] = track;