webrtc是否允许发送rtp逻辑移至基类

This commit is contained in:
ziyue 2021-10-20 16:58:59 +08:00
parent 93c6754fc4
commit 758f1b414e
3 changed files with 5 additions and 17 deletions

View File

@ -33,12 +33,6 @@ void WebRtcPlayer::onStartWebRTC() {
CHECK(_play_src); CHECK(_play_src);
WebRtcTransportImp::onStartWebRTC(); WebRtcTransportImp::onStartWebRTC();
if (canSendRtp()) { 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); _play_src->pause(false);
_reader = _play_src->getRing()->attach(getPoller(), true); _reader = _play_src->getRing()->attach(getPoller(), true);
weak_ptr<WebRtcPlayer> weak_self = static_pointer_cast<WebRtcPlayer>(shared_from_this()); weak_ptr<WebRtcPlayer> weak_self = static_pointer_cast<WebRtcPlayer>(shared_from_this());
@ -49,7 +43,7 @@ void WebRtcPlayer::onStartWebRTC() {
} }
size_t i = 0; size_t i = 0;
pkt->for_each([&](const RtpPacket::Ptr &rtp) { pkt->for_each([&](const RtpPacket::Ptr &rtp) {
strongSelf->beforeSendRtp(rtp, ++i == pkt->size()); strongSelf->onSendRtp(rtp, ++i == pkt->size());
}); });
}); });
_reader->setDetachCB([weak_self]() { _reader->setDetachCB([weak_self]() {
@ -91,10 +85,3 @@ void WebRtcPlayer::onRtcConfigure(RtcConfigure &configure) const {
configure.audio.direction = configure.video.direction = RtpDirection::sendonly; configure.audio.direction = configure.video.direction = RtpDirection::sendonly;
configure.setPlayRtspInfo(_play_src->getSdp()); 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);
}

View File

@ -28,10 +28,8 @@ protected:
private: private:
WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info); WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info);
void beforeSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false);
private: private:
bool _can_send_rtp[TrackMax];
//媒体相关元数据 //媒体相关元数据
MediaInfo _media_info; MediaInfo _media_info;
//播放的rtsp源 //播放的rtsp源

View File

@ -372,7 +372,10 @@ void WebRtcTransportImp::onStartWebRTC() {
track->rtcp_context_send = std::make_shared<RtcpContextForSend>(); track->rtcp_context_send = std::make_shared<RtcpContextForSend>();
//rtp track type --> MediaTrack //rtp track type --> MediaTrack
if (m_answer.direction == RtpDirection::sendonly || m_answer.direction == RtpDirection::sendrecv) {
//该类型的track 才支持发送
_type_to_track[m_answer.type] = track; _type_to_track[m_answer.type] = track;
}
//send ssrc --> MediaTrack //send ssrc --> MediaTrack
_ssrc_to_track[track->answer_ssrc_rtp] = track; _ssrc_to_track[track->answer_ssrc_rtp] = track;
_ssrc_to_track[track->answer_ssrc_rtx] = track; _ssrc_to_track[track->answer_ssrc_rtx] = track;