[Libjingle代码分析]对照Jingle的XMPP stanza理解Libjingle的几个关键数据结构

本文详细介绍了音视频通信系统的架构,从SessionManager管理Session开始,深入到Transport、TransportChannel及Port层面,最后到Connection的建立过程。每个层级都有明确的数据管理方式,并与XMPP协议中的元素相对应。

1.

SessionManager管理多个Session:

ExpandedBlockStart.gifclass SessionManager {
  typedef std::map<std::string, Session*> SessionMap;
  SessionMap session_map_;
}

每个Session在SessionManager里通过sid来区分:

session_map_[session->id()] = session;

通过SessionManager::CreateSession(content_type)创建一个Session, 每个Session对应一个content_type:

ExpandedBlockStart.gifclass Session {
  std::string content_type_;
}

content_type目前传入的为"urn:xmpp:jingle:apps:rtp:1", 其实就是<content>下<description>元素的"xmlns"属性值.


2.

一个Session管理多个Transport:

typedef std::map<std::string, TransportProxy*> TransportMap;
ExpandedBlockStart.gifclass Session {
  TransportMap transports_;
}

每个Transport在Session里通过content_name来区分:

transports_[content_name] = transproxy;

通过Session::GetOrCreateTransportProxy(content_name)来创建一个Transport. content_name就是<content>元素的name属性值, 如"audio", "video"等. 比如, 在视频聊天中:

<jingle>
  <content name="audio" creator="initiator">
  </content>
  <content name="video" creator="initiator">
  </content>
</jingle>


3.

一个Transport管理多个Transportchannel:

typedef std::map<std::string, TransportChannelImpl*> ChannelMap;
ExpandedBlockStart.gifclass Transport {
  ChannelMap channels_;

每个Transportchannel通过channel_name来区分:

channels_[name] = channel;

通过 Transport::CreateChannel(name)创建一个Transport, channel_name没有对应的XMPP stanza, 其值有"rtp", "rtcp"等.


4.

一个TransportChannel(主要是P2PTransportChannel)管理多个Port:

ExpandedBlockStart.gifclass P2PTransportChannel {
  std::vector<Port *> ports_;
}

Port分为StunPort, TCPPort, UDPPort等, 与<transport>元素的xmlns属性值(如"urn:xmpp:jingle:transports:ice-udp:1")以及子元素<candidate>的protocol属性值(如"udp")有关.


 

5.

一个Port管理多个Connection:

ExpandedBlockStart.gifclass Port {
  typedef std::map<talk_base::SocketAddress, Connection*> AddressMap;
  AddressMap connections_;
}


 

6.

一个Connection包括一个local_candidate和一个remote_candidate:

class Connection

ExpandedBlockStart.gifclass Connection {
  size_t local_candidate_index_;
  Candidate remote_candidate_;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值