当前位置:网站首页>webrtc入门:12.Kurento下的RtpEndpoint和WebrtcEndpoint
webrtc入门:12.Kurento下的RtpEndpoint和WebrtcEndpoint
2022-06-27 08:19:00 【go2coding】
在前面的一个章节,做kms的集群时,引入了RtpEndpoint,这个是一个新的类,我们之前使用的都是WebrtcEndpoint,这两个类有什么区别呢?如果直接用WebrtcEndpoint,能不能实现集群的连通呢。
我们来看看,文档中的关于几个重要的Endpoint,继承图如下:

但是从详细的文档上来看,RtpEndpoint和WebrtcEndpoint都是继承BaseRtpEndpoint的。
从文档上来看,RtpEndpoint和WebrtcEndpoint应该区别不大,因为他有一个共同的基类BaseRtpEndpoint。
在对比下两者文档的区别:
RtpEndpoint:
WebRtcEndpoint:

从文档上来看,RtpEndpoint和WebrtcEndpoint 的区别在于 RtpEndpoint可以直接通过SDP就能完成相互的连接,WebrtcEndpoint 要实现连接,不仅仅需要SDP还需要ICE。
也就是RtpEndpoint在设计的时候,就可以通过SDP建立连接,那么在SDP中必将包含着 IP和端口的信息了。
在源代码kms_sdp_agent_create_offer_impl中可以看到生成的SDP,存在在相应的 IP和端口信息。
v=0
o=- 3864705878 3864705878 IN IP4 192.168.100.130
s=Kurento Media Server
c=IN IP4 192.168.100.130
t=0 0
m=audio 5198 RTP/AVPF 96 0 97
a=setup:actpass
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=rtpmap:96 opus/48000/2
a=rtpmap:97 AMR/8000
a=rtcp:5199
a=sendrecv
a=mid:audio0
a=ssrc:1665516295 cname:[email protected]
m=video 1420 RTP/AVPF 102 103
a=setup:actpass
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=rtpmap:102 VP8/90000
a=rtpmap:103 H264/90000
a=fmtp:103 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtcp:1421
a=sendrecv
a=mid:video0
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
a=rtcp-fb:102 goog-remb
a=rtcp-fb:102 ccm fir
a=rtcp-fb:103 nack
a=rtcp-fb:103 nack pli
a=rtcp-fb:103 ccm fir
a=ssrc:2557383214 cname:[email protected]
这样两个 RtpEndpoint 就能够协商连接上。
而WebrtcEndpoint 中生成的SDP,并没有包含IP和端口信息,这一点可以继续的跟进kms_sdp_agent_create_offer_impl,看看到底是为什么。这样的协议,是个浏览器的webrtc一样样的。
那如果使用 WebrtcEndpoint 能否实现集群呢?应该是可以的,但是比起RtpEndpoint自然会复杂一点,因为他涉及到 ICE的步骤了。
如果也需要,可以用下面的代码进行实现。
private synchronized void presenter(final WebSocketSession session, JsonObject jsonMessage)
throws IOException {
if (presenterUserSession == null) {
presenterUserSession = new UserSession(session);
pipeline = kurento.createMediaPipeline();
presenterUserSession.setWebRtcEndpoint(new WebRtcEndpoint.Builder(pipeline).build());
WebRtcEndpoint presenterWebRtc = presenterUserSession.getWebRtcEndpoint();
pipeline_B = kurento.createMediaPipeline();
presenterUserSession.setWebRtcEndpoint_A(new WebRtcEndpoint.Builder(pipeline).build());
WebRtcEndpoint presenterWebRtc_A = presenterUserSession.getWebRtcEndpoint_A();
presenterUserSession.setWebRtcEndpoint_B(new WebRtcEndpoint.Builder(pipeline_B).build());
WebRtcEndpoint presenterWebRtc_B = presenterUserSession.getWebRtcEndpoint_B();
presenterUserSession.getWebRtcEndpoint().connect(presenterWebRtc_A);
String offerString = presenterWebRtc_A.generateOffer();
String sdpAnswerViewer = presenterWebRtc_B.processOffer(offerString);
presenterWebRtc_A.processAnswer(sdpAnswerViewer);
log.info(offerString);
presenterWebRtc_A.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {
@Override
public void onEvent(IceCandidateFoundEvent event) {
log.info("presenterWebRtc_A.addIceCandidateFoundListener");
presenterWebRtc_B.addIceCandidate(event.getCandidate());
}
});
presenterWebRtc_B.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {
@Override
public void onEvent(IceCandidateFoundEvent event) {
log.info("presenterWebRtc_B.addIceCandidateFoundListener");
//presenterWebRtc_A.addIceCandidate(event.getCandidate());
}
});
presenterWebRtc.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {
@Override
public void onEvent(IceCandidateFoundEvent event) {
JsonObject response = new JsonObject();
response.addProperty("id", "iceCandidate");
response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
try {
synchronized (session) {
session.sendMessage(new TextMessage(response.toString()));
}
} catch (IOException e) {
log.debug(e.getMessage());
}
}
});
String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString();
String sdpAnswer = presenterWebRtc.processOffer(sdpOffer);
JsonObject response = new JsonObject();
response.addProperty("id", "presenterResponse");
response.addProperty("response", "accepted");
response.addProperty("sdpAnswer", sdpAnswer);
synchronized (session) {
presenterUserSession.sendMessage(response);
}
presenterWebRtc.gatherCandidates();
presenterWebRtc_A.gatherCandidates();
presenterWebRtc_B.gatherCandidates();
} else {
JsonObject response = new JsonObject();
response.addProperty("id", "presenterResponse");
response.addProperty("response", "rejected");
response.addProperty("message",
"Another user is currently acting as sender. Try again later ...");
session.sendMessage(new TextMessage(response.toString()));
}
}
边栏推荐
- 【c ++ primer 笔记】第3章 字符串、向量和数组
- 直接修改/etc/crontab 文件内容,定时任务不生效
- Refer to | the computer cannot access the Internet after the hotspot is turned on in win11
- 【每日一练】产品卡片动画效果的实现
- Reference | upgrade win11 mobile hotspot can not be opened or connected
- 盲測調查顯示女碼農比男碼農更優秀
- LVGL GUI GUIDER移植代码到STM32
- [batch dos-cmd command - summary and summary] - environment variables, path variables, search file location related instructions - set, path, where, what if there are spaces in the path parameters of
- 招聘需求 视觉工程师
- MATLAB小技巧(18)矩阵分析--熵权法
猜你喜欢

Lvgl GUI guide porting code to stm32

orthofinder直系同源蛋白分析及结果处理

Index +sql exercise optimization

After working in a large factory for ten years with an annual salary of 400000 yuan, I was suddenly laid off. If the company wanted to abandon you, it wouldn't leave any kindness

JVM common garbage collector

Mysql事务中MVCC理解超简单

关联GIS:条条道路通UE5城

Redis installation under Linux
![[c++ primer notes] Chapter 4 expression](/img/cb/d543dd1f461653e9adf399b42d1d26.png)
[c++ primer notes] Chapter 4 expression

ZABBIX deployment instructions (server+win client + switch (H3C))
随机推荐
MATLAB小技巧(18)矩阵分析--熵权法
【论文阅读】Intrinsically semi-supervised methods
All tutor information on one page
SPARQL基础入门练习
Experience record of Luogu's topic brushing
【c ++ primer 笔记】第3章 字符串、向量和数组
Correctly understand MySQL mvcc
Analysis log log
Read datasets iteratively with xgboost
Lvgl GUI guide porting code to stm32
Code source AQS sous - jacent pour la programmation simultanée juc
淘宝虚拟产品开店教程之作图篇
关于el-date-picker点击清空参数变为null的问题
Redis master-slave replication and sentinel mode
[ 扩散模型(Diffusion Model) ]
【批处理DOS-CMD命令-汇总和小结】-输出/显示命令——echo
直接修改/etc/crontab 文件内容,定时任务不生效
期货反向跟单靠谱吗?
游戏资产复用:更快找到所需游戏资产的新方法
(original) custom drawable