bool MediaStream::setRemoteSdp(std::shared_ptr<SdpInfo> sdp) { ELOG_DEBUG("%s message: setting remote SDP", toLog()); if (!sending_) { return true; } remote_sdp_ = sdp; if (remote_sdp_->videoBandwidth != 0) { ELOG_DEBUG("%s message: Setting remote BW, maxVideoBW: %u", toLog(), remote_sdp_->videoBandwidth); this->rtcp_processor_->setMaxVideoBW(remote_sdp_->videoBandwidth*1000); } if (pipeline_initialized_) { pipeline_->notifyUpdate(); return true; } bundle_ = remote_sdp_->isBundle; auto video_ssrc_list_it = remote_sdp_->video_ssrc_map.find(getLabel()); if (video_ssrc_list_it != remote_sdp_->video_ssrc_map.end()) { setVideoSourceSSRCList(video_ssrc_list_it->second); } auto audio_ssrc_it = remote_sdp_->audio_ssrc_map.find(getLabel()); if (audio_ssrc_it != remote_sdp_->audio_ssrc_map.end()) { setAudioSourceSSRC(audio_ssrc_it->second); } if (getVideoSourceSSRCList().empty() || (getVideoSourceSSRCList().size() == 1 && getVideoSourceSSRCList()[0] == 0)) { std::vector<uint32_t> default_ssrc_list; default_ssrc_list.push_back(kDefaultVideoSinkSSRC); setVideoSourceSSRCList(default_ssrc_list); } if (getAudioSourceSSRC() == 0) { setAudioSourceSSRC(kDefaultAudioSinkSSRC); } audio_enabled_ = remote_sdp_->hasAudio; video_enabled_ = remote_sdp_->hasVideo; rtcp_processor_->addSourceSsrc(getAudioSourceSSRC()); std::for_each(video_source_ssrc_list_.begin(), video_source_ssrc_list_.end(), [this] (uint32_t new_ssrc){ rtcp_processor_->addSourceSsrc(new_ssrc); }); initializePipeline(); return true; }
bool MediaStream::setRemoteSdp(std::shared_ptr<SdpInfo> sdp) { ELOG_DEBUG("%s message: setting remote SDP", toLog()); remote_sdp_ = sdp; if (remote_sdp_->videoBandwidth != 0) { ELOG_DEBUG("%s message: Setting remote BW, maxVideoBW: %u", toLog(), remote_sdp_->videoBandwidth); this->rtcp_processor_->setMaxVideoBW(remote_sdp_->videoBandwidth*1000); } if (pipeline_initialized_) { pipeline_->notifyUpdate(); return true; } bundle_ = remote_sdp_->isBundle; setVideoSourceSSRCList(remote_sdp_->video_ssrc_list); setAudioSourceSSRC(remote_sdp_->audio_ssrc); audio_enabled_ = remote_sdp_->hasAudio; video_enabled_ = remote_sdp_->hasVideo; rtcp_processor_->addSourceSsrc(getAudioSourceSSRC()); std::for_each(video_source_ssrc_list_.begin(), video_source_ssrc_list_.end(), [this] (uint32_t new_ssrc){ rtcp_processor_->addSourceSsrc(new_ssrc); }); initializePipeline(); return true; }
void MediaStream::setTransportInfo(std::string audio_info, std::string video_info) { if (video_enabled_) { uint32_t video_sink_ssrc = getVideoSinkSSRC(); uint32_t video_source_ssrc = getVideoSourceSSRC(); if (video_sink_ssrc != kDefaultVideoSinkSSRC) { stats_->getNode()[video_sink_ssrc].insertStat("clientHostType", StringStat{video_info}); } if (video_source_ssrc != 0) { stats_->getNode()[video_source_ssrc].insertStat("clientHostType", StringStat{video_info}); } } if (audio_enabled_) { uint32_t audio_sink_ssrc = getAudioSinkSSRC(); uint32_t audio_source_ssrc = getAudioSourceSSRC(); if (audio_sink_ssrc != kDefaultAudioSinkSSRC) { stats_->getNode()[audio_sink_ssrc].insertStat("clientHostType", StringStat{audio_info}); } if (audio_source_ssrc != 0) { stats_->getNode()[audio_source_ssrc].insertStat("clientHostType", StringStat{audio_info}); } } }
void MediaStream::read(std::shared_ptr<DataPacket> packet) { char* buf = packet->data; int len = packet->length; // PROCESS RTCP RtpHeader *head = reinterpret_cast<RtpHeader*> (buf); RtcpHeader *chead = reinterpret_cast<RtcpHeader*> (buf); uint32_t recvSSRC = 0; if (!chead->isRtcp()) { recvSSRC = head->getSSRC(); } else if (chead->packettype == RTCP_Sender_PT) { // Sender Report recvSSRC = chead->getSSRC(); } // DELIVER FEEDBACK (RR, FEEDBACK PACKETS) if (chead->isFeedback()) { if (fb_sink_ != nullptr && should_send_feedback_) { fb_sink_->deliverFeedback(std::move(packet)); } } else { // RTP or RTCP Sender Report if (bundle_) { // Check incoming SSRC // Deliver data if (isVideoSourceSSRC(recvSSRC)) { parseIncomingPayloadType(buf, len, VIDEO_PACKET); video_sink_->deliverVideoData(std::move(packet)); } else if (isAudioSourceSSRC(recvSSRC)) { parseIncomingPayloadType(buf, len, AUDIO_PACKET); audio_sink_->deliverAudioData(std::move(packet)); } else { ELOG_DEBUG("%s read video unknownSSRC: %u, localVideoSSRC: %u, localAudioSSRC: %u", toLog(), recvSSRC, this->getVideoSourceSSRC(), this->getAudioSourceSSRC()); } } else { if (packet->type == AUDIO_PACKET && audio_sink_ != nullptr) { parseIncomingPayloadType(buf, len, AUDIO_PACKET); // Firefox does not send SSRC in SDP if (getAudioSourceSSRC() == 0) { ELOG_DEBUG("%s discoveredAudioSourceSSRC:%u", toLog(), recvSSRC); this->setAudioSourceSSRC(recvSSRC); } audio_sink_->deliverAudioData(std::move(packet)); } else if (packet->type == VIDEO_PACKET && video_sink_ != nullptr) { parseIncomingPayloadType(buf, len, VIDEO_PACKET); // Firefox does not send SSRC in SDP if (getVideoSourceSSRC() == 0) { ELOG_DEBUG("%s discoveredVideoSourceSSRC:%u", toLog(), recvSSRC); this->setVideoSourceSSRC(recvSSRC); } // change ssrc for RTP packets, don't touch here if RTCP video_sink_->deliverVideoData(std::move(packet)); } } // if not bundle } // if not Feedback }