本文主要是介绍mediasoup源码分析(七)transport传输,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
transport传输
- 一、Tansport 转发到Producer
- 二、RtpStreamRecv 处理收到的包
- 三、数据传输到Router,再分发到Consumer
- tips
一、Tansport 转发到Producer
Transport收到数据packet后,会解析出packet中所带的ssrc字段,然后基于ssrc找到该数据的Producer。
Transport::ReceiveRtpPacket
{// Get the associated Producer.RTC::Producer* producer = this->rtpListener.GetProducer(packet);//基于包中的ssrc选出Producer
}
Produer也是基于ssrc找到RtpStreamRecv
//生产者接收到rtp包,数据发送者类
Producer::ReceiveRtpPacketResult Producer::ReceiveRtpPacket(RTC::RtpPacket* packet)
{// Count number of RTP streams. 基于ssrc获取与该包相关的流管理类RTC::RtpStreamRecvauto numRtpStreamsBefore = this->mapSsrcRtpStream.size();auto* rtpStream = GetRtpStream(packet);// Media packet. 判断接收包和与之关联的流的SSRC是否相等,即得保证该包属于该流if (packet->GetSsrc() == rtpStream->GetSsrc()){result = ReceiveRtpPacketResult::MEDIA;// Process the packet.if (!rtpStream->ReceivePacket(packet)){}}this->listener->OnProducerRtpPacketReceived(this, packet);
}
二、RtpStreamRecv 处理收到的包
//流处理接收到的包 这块的逻辑是核心也非常重要,先列出来,后面会单独讲解
bool RtpStreamRecv::ReceivePacket(RTC::RtpPacket* packet)
{//nack 处理 //jitter更新//重传包更新//新包更新
}
三、数据传输到Router,再分发到Consumer
//RtpStreamRecv处理完手机后,数据包又回传到Transport
//此处的listener是Router
inline void Transport::OnProducerRtpPacketReceived()
{this->listener->OnTransportProducerRtpPacketReceived(this, producer, packet);
}
//数据传输到Router
inline void Router::OnTransportProducerRtpPacketReceived(RTC::Transport* /*transport*/, RTC::Producer* producer, RTC::RtpPacket* packet)
{//路由中维护生成者和所有消费者的map关联关系auto& consumers = this->mapProducerConsumers.at(producer);//把数据发给每一个消费者for (auto* consumer : consumers){// Update MID RTP extension value.const auto& mid = consumer->GetRtpParameters().mid;if (!mid.empty())packet->UpdateMid(mid);consumer->SendRtpPacket(packet);}
}
tips
更多关于mediasoup的文章可以进入我的专栏查看
http://t.csdnimg.cn/3UQeL
这篇关于mediasoup源码分析(七)transport传输的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!