[原]libstreaming 源码分析一之RTSP连接

http://m.blog.csdn.net/blog/echoaiya_11109/28234933


libstreaming(github下载网站: https://github.com/fyhertz/libstreaming  )


一、libstreaming概述
 
功能介绍:实现android视频直播的库,主要实现的功能有RTSP协议、H263/H264编码、RTP/RTCP协议打包等。

libstreaming is an API that allows you, with only a few lines of code, to stream the camera and/or microphone of an android powered device using RTP over UDP.

  • Android 4.0 or more recent is required.
  • Supported encoders include H.264, H.263, AAC and AMR.

The first step you will need to achieve to start a streaming session to some peer is called 'signaling'. During this step you will contact the receiver and send a description of the incomming streams. You have three ways to do that with libstreaming.

  • With the RTSP client: if you want to stream to a Wowza Media Server, it's the way to go. The example 3illustrates that use case.
  • With the RTSP server: in that case the phone will act as a RTSP server and wait for a RTSP client to request a stream. This use case is illustated in the example 1.
  • Or you use libstreaming without using the RTSP protocol at all, and signal the session using SDP over a protocol you like. The example 2 illustrates that use case.

The full javadoc documentation of the API is available here:  http://majorkernelpanic.com/libstreaming/doc-v4

二、视频直播模型(图一)


三、example 示例
libstreaming 库的作者提供了3个示例demo,见(一)。
example1 是将libstreaming作为 RTSP server ,在手机上安装并启动net.majorkernelpanic.streaming.rtsp.RtspServer,在PC上用vlc打开rtsp://your rtspserver ip:8086,即可实现视频直播。
example2 是利用其它协议实现视频直播,未研究,此略。
example3 是将libstreaming作为 RTSP client ,通过net.majorkernelpanic.streaming.rtsp.RtspCilent将视频流push到wowza服务器,在PC上用VLC打开rtsp://your wowzastreaming ip:1935/live/test.stream,即可实现视频直播。

注意RtspServer与RtspClient的区别,也就是流媒体pull与push的区别。见下图。





 

因为可能有多个视频采集端,我们需要采集端主动推送视频流至流媒体服务器。
注意:libstreaming中RtspClient协议只能成功连接wowza流媒体服务器,若要rtsp连接至dss,需要修改RtspClient。

四、example3流程

example3只要一个MainActivity.java。主要是为Session、RtspClient设置初值,如分辨率、帧率、编码格式等。
除了MainActivity.java,其他java文件包名均为“net.majorkernelpanic.streaming”。大致流程如下:

(1)开启相机预览

MainActivity.java


Session.java


VideoStream.java:开启相机预览



(2)RTSP连接

MainActivity.java: 点击button “ R.id.start”,进入 toggleStream 方法,关键代码:

前面已经根据输入内容,设置了连接wowza服务器的地址、端口、用户名和密码。


RtspClient.java:发送rtsp协议,关键代码





其中,sendRequestAnnounce() 、 sendRequestSetup() 、 sendRequestRecord() 分别发送RTSP中的 ANNOUNCE、SETUP、RECORD方法至wowza。下面是打印的log:


从log信息可以看出rtsp连接成功,只需在播放端用vlc播放地址:rtsp://wowza ip:1935/live/test.stream 。关于RTSP协议的分析,此处不做详细说明。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值