当前位置:网站首页>Getting started with webrtc: 12 Rtendpoint and webrtcendpoint under kurento
Getting started with webrtc: 12 Rtendpoint and webrtcendpoint under kurento
2022-06-27 08:33:00 【go2coding】
In the previous chapter , do kms When the cluster of , Introduced RtpEndpoint, This is a new class , What we used before was WebrtcEndpoint, What is the difference between the two classes ? If you use it directly WebrtcEndpoint, Can the cluster be connected .
Let's see , There are several important in the document Endpoint, The inheritance diagram is as follows :

But from the detailed documentation ,RtpEndpoint and WebrtcEndpoint They are all inherited. BaseRtpEndpoint Of .
From the documentation ,RtpEndpoint and WebrtcEndpoint There should be little difference , Because it has a common base class BaseRtpEndpoint.
Compare the difference between the two documents :
RtpEndpoint:
WebRtcEndpoint:

From the documentation ,RtpEndpoint and WebrtcEndpoint The difference is that RtpEndpoint You can go directly through SDP You can connect with each other ,WebrtcEndpoint To connect , It's not just necessary SDP It also needs to be ICE.
That is to say RtpEndpoint In design , You can go through SDP Establishing a connection , So in SDP It must contain IP And port information .
In source code kms_sdp_agent_create_offer_impl You can see the generated SDP, Exist in the corresponding IP And port information .
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]
These two RtpEndpoint You can negotiate the connection .
and WebrtcEndpoint Generated in the SDP, Not included IP And port information , This can be followed up kms_sdp_agent_create_offer_impl, See why . Such an agreement , It's a browser webrtc All the same .
Then if you use WebrtcEndpoint Can you implement cluster ? It should be possible , But rather than RtpEndpoint Naturally, it will be more complicated , Because he involves ICE The steps are .
If you also need , It can be implemented with the following code .
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()));
}
}
边栏推荐
- 支付宝微信支付业务流程图
- VIM from dislike to dependence (20) -- global command
- Refer to | the computer cannot access the Internet after the hotspot is turned on in win11
- MATLAB小技巧(19)矩阵分析--主成分分析
- 不会初始化类的几种Case
- 直接修改/etc/crontab 文件内容,定时任务不生效
- Lvgl GUI guide porting code to stm32
- Etcd tutorial - Chapter 5 etcd etcdctl usage
- ServletConfig与ServletContext
- Redis configuration file details
猜你喜欢

支付宝微信支付业务流程图

JVM层次上的对象的创建过程和内存布局

A classic interview question covering 4 hot topics
![[13. number and bit operation of 1 in binary]](/img/53/024f9742d1936fe6f96f4676cea00e.png)
[13. number and bit operation of 1 in binary]

vim 从嫌弃到依赖(20)——global 命令

Read datasets iteratively with xgboost
![[batch dos-cmd command - summary and summary] - output / display command - echo](/img/44/cddad70eeb756db15c19100c25c61a.png)
[batch dos-cmd command - summary and summary] - output / display command - echo

Enumeration? Constructor? Interview demo

数字IC-1.9 吃透通信协议中状态机的代码编写套路

Rust async: SMOL source code analysis -executor
随机推荐
2022.06.26(LC_6100_统计放置房子的方式数)
[batch dos-cmd command - summary and summary] - map folder to virtual disk - subst
Lvgl description 3 about the use of lvgl Guide
SPARQL基础入门练习
Redis configuration file details
UE5神通--POI解决方案
AQS underlying source code of concurrent programming JUC
JS EventListener
I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!
lvgl 说明3关于lvgl guider的使用
orthofinder直系同源蛋白分析及结果处理
枚举?构造器?面试Demo
[ 扩散模型(Diffusion Model) ]
MySQL lock details
How much memory does the data type occupy? LongVsObject
浏览器的markdown插件显示不了图片
vim 从嫌弃到依赖(20)——global 命令
How much do you know about the cause of amplifier distortion?
[notes on c++ primer] Chapter 3 string, vector and array
05 observer mode