libstreaming 源码分析一之RTSP连接
来源:互联网 发布:东华大学网络教育平台 编辑:程序博客网 时间:2024/06/05 08:20
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
- libstreaming 源码分析一之RTSP连接
- libstreaming 源码分析一之RTSP连接
- [原]libstreaming 源码分析一之RTSP连接
- libstreaming源码分析二之MediaRecorder编码
- libstreaming源码分析二之MediaRecorder编码
- libstreaming源码分析三之H264 RTP打包
- libstreaming源码分析三之H264 RTP打包
- Android(2.3+)源码分析MediaPlayer之RTSP
- vlc源码分析之RTSP会话流程
- Android(2.3+)源码分析MediaPlayer之RTSP
- 使用Spydroid(libstreaming)作为rtsp server
- 使用Spydroid(libstreaming)作为rtsp server
- 使用Spydroid(libstreaming)作为rtsp server
- vlc源码分析(一) RTSP会话流程
- Android 源码分析之基于NuPlayer的RTSP流媒体协议
- Android 源码分析之基于NuPlayer的RTSP流媒体协议
- FFmpeg之Rtsp分析(一):Pause和seek
- RTSP 协议分析 (一)
- INI文件操作
- 基本排序系列之希尔排序
- log_file_name_convert的更改与ORA-01516和ORA-01275
- Apache Kafka:下一代分布式消息系统
- webBrowser 清空cookie
- libstreaming 源码分析一之RTSP连接
- iphone5、xcode4.5
- redis 下key的过期时间详解:expire
- oracle 游标详解
- Q编程6:Qt日志处理方法(qInstallMsgHandler函数)简单实用
- mysql数据库恢复(*frm)文件
- libstreaming源码分析二之MediaRecorder编码
- 苹果公司Swift语言将掀起革命
- 初学php html javascript后小总结