基于kurento的RtpEndpoint元素实现的loopback

来源:互联网 发布:vue引入第三方js 编辑:程序博客网 时间:2024/06/05 00:52

一,背景

目前为了实现webrtc与传统的sip客户端进行视频通讯,信令方案到不是问题,主要问题在于解决webrtc的SRTP与sip的RTP数据的转换,调研多种方案,决定采用kurento的方案,其中RtpEndpoint能实现转换功能,同时考虑到后期的特效处理,kurento还是很有优势的。


二,RtpEndpoint介绍

官方介绍如下:

The RtpEndpoint is a full-duplex mediaelement with the capability of sending and receiving RTP/RTCP flows. TheRtpEndpoint supports several audio and video codecs including H.264, H.263,OPUS, AMR, SPEEX and others. From the client perspective, the RtpEndpoint iscapable of initiating outgoing calls (offering an SDP for negotiating) orreceiving incoming calls (ansering with a negotiated SDP from an offered SDP).From the media server infrastructure perspective, the RtpEndpoint provides asource media pad, where the RTP media comming from the network is madeavailable to other media elements and a sink pad, where other elements can feedthe outcoming media that the RtpEndpoint will generate to the remote peer.


三,问题与解决方法

网上和官方关于WebrtcEndpoint等element的测试程序较多,但关于RtpEndpoint的示例相对较少。对于初学者,对kurento的架构和相关API的使用方法不甚理解,导致开发走如误区。所以要尽可能的多看官方的示例代码和搭建DEMO环境演示,对理解kurento的功能和使用方法有很大的帮助。

当前我的需求是需要使用的RtpEndpoint的双向数据通讯,至于RtpEndpoint的输出,有相关示例很明确,可参考https://github.com/godka/kurento-rtmp,此示例是将browser的视频数据通过RtpEndpoint转成RTP数据后发送到ffmpeg的RTMP服务中,浏览器测试页面的RTMP stream窗口就是从ffmpeg推送过来的视频流,使用其它播放器客户端如VLC也可实现,具体URL服务端log中会有,如:rtmp://192.168.0.105/live/127.0.0.1:55000。

而RtpEndpoint的数据接收相对来说麻烦一些,没有找到相关的示例,靠自己去摸索、理解和猜测,最后终于达到目标实现了经过RtpEndpoint的loopback数据回传功能,到达预期。Browser:webrtc---->Kurento:WebrtcEndpoint---->Kurento:RtpEndpoint(0)------>Kurento:RtpEndpoint(1)------->Kurento:WebrtcEndpoint---->Browser:webrtc。

为了方便,我基于官方的kurento-tutorial-java/kurento-hello-world测试示例基础上修改的, 请到https://github.com/Kurento/kurento-tutorial-java下载。

修改位置:在kurento-tutorial-java/src/main/java/org/kurento/tutorial/helloworld/HelloWorldHandler.java,文件在start函数前面修改成如下:

MediaPipeline pipeline = kurento.createMediaPipeline();WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(pipeline).build();

RtpEndpoint rtpEndpoint = new RtpEndpoint.Builder(pipeline).build();webRtcEndpoint.connect(rtpEndpoint);RtpEndpoint rtpEndpoint1 = new RtpEndpoint.Builder(pipeline).build();rtpEndpoint1.connect(webRtcEndpoint);String genOffer = rtpEndpoint1.generateOffer();String answer = rtpEndpoint.processOffer(genOffer);rtpEndpoint1.processAnswer(answer);MyLog.info(TAG, "\ngenOffer:\n" + genOffer+"\n\nanswer:\n"+answer);

特别要注意上面的红色部分

修改完成重新编译运行,就会看到效果





阅读全文
0 0
原创粉丝点击