RUBY 模拟rtsp消息
require 'rtsp/client'
require 'log_switch'
require 'socket' RTSP::Client.log? # => false
RTSP::Client.log = true
client = RTSP::Client.new "rtsp://10.0.10.200:8557/H264" client.server_uri # => #<URI::Generic:0x00000100ba4db0 URL:rtsp://64.202.98.91:554/sa.sdp>
client.session_state # => :init
client.cseq # => 1
client.connection.do_capture # => true
client.connection.interleave # => false
client.connection.timeout # => 30
client.capturer.ip_addressing_type # => :unicast
client.capturer.rtp_port # => 6970
client.capturer.capture_file # => #<File:/var/folders/tg/j9jxvvfs4qn9cg4vztzyy2gc0000gp/T/rtp_capture.raw-59901-1l8dgv2>
client.capturer.transport_protocol # => :UDP response = client.options
response.class # => RTSP::Response
response.code # => 200
response.message # => "OK"
client.cseq # => 2 response = client.describe
response.body.class # => SDP::Description
response.content_type # => "application/sdp"
#response.server # => "DSS/5.5 (Build/489.7; Platform/Linux; Release/Darwin; )"
client.aggregate_control_track # => "rtsp://64.202.98.91:554/sa.sdp/"
client.media_control_tracks # => ["rtsp://64.202.98.91:554/sa.sdp/trackID=1"]
client.cseq # => 3 response = client.setup(client.media_control_tracks.first)
response.session[:session_id] # => 7098486223178290313
client.session[:session_id] # => 7098486223178290313
client.cseq # => 4
client.session_state # => :ready response = client.play(client.aggregate_control_track)
response.range # => "npt=now="
response.rtp_info # => "url=rtsp://64.202.98.91:554/sa.sdp/trackID=1"
client.session_state # => :playing # Wait while the video streams
sleep 5
#
client.pause(client.aggregate_control_track)
client.session_state # => :ready
#
# # Wait while the video is paused
sleep 2
#
client.teardown(client.aggregate_control_track)
client.session[:session_id] # => 0
client.session_state # => :init
执行后,如下:
[root@localhost script]# ruby rtsp.rb
[2017-03-31 15:17:49 +0800] Sending OPTIONS to rtsp://10.0.10.200:8557/H264
[2017-03-31 15:17:49 +0800] OPTIONS rtsp://10.0.10.200:8557/H264 RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 1
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 1
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Sending DESCRIBE to rtsp://10.0.10.200:8557/H264
[2017-03-31 15:17:49 +0800] DESCRIBE rtsp://10.0.10.200:8557/H264 RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 2
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800] Accept: application/sdp
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 2
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Content-Base: rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:49 +0800] Content-Type: application/sdp
[2017-03-31 15:17:49 +0800] Content-Length: 615
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] v=0
[2017-03-31 15:17:49 +0800] o=- 1489133093616171 1 IN IP4 10.0.10.200
[2017-03-31 15:17:49 +0800] s=RTSP/RTP stream from IPNC
[2017-03-31 15:17:49 +0800] i=H264
[2017-03-31 15:17:49 +0800] t=0 0
[2017-03-31 15:17:49 +0800] a=tool:LIVE555 Streaming Media v2014.09.11
[2017-03-31 15:17:49 +0800] a=type:broadcast
[2017-03-31 15:17:49 +0800] a=control:*
[2017-03-31 15:17:49 +0800] a=range:npt=0-
[2017-03-31 15:17:49 +0800] a=x-qt-text-nam:RTSP/RTP stream from IPNC
[2017-03-31 15:17:49 +0800] a=x-qt-text-inf:H264
[2017-03-31 15:17:49 +0800] m=video 0 RTP/AVP 96
[2017-03-31 15:17:49 +0800] c=IN IP4 0.0.0.0
[2017-03-31 15:17:49 +0800] b=AS:12000
[2017-03-31 15:17:49 +0800] a=rtpmap:96 H264/90000
[2017-03-31 15:17:49 +0800] a=fmtp:96 packetization-mode=1;profile-level-id=640032;sprop-parameter-sets=J2QAMq2EBUViuKxUcQgKisVxWKjiECSFITk8nyfk/k/J8nm5s00IEkKQnJ5Pk/J/J+T5PNzZphcqAeAIn5ZsgAAB9AAA6mBwAAAPQkAAAPQkBe91hAAAAAE=,KP4Brg==
[2017-03-31 15:17:49 +0800] a=control:track1
[2017-03-31 15:17:49 +0800] m=audio 0 RTP/AVP 0
[2017-03-31 15:17:49 +0800] c=IN IP4 0.0.0.0
[2017-03-31 15:17:49 +0800] b=AS:64
[2017-03-31 15:17:49 +0800] a=control:track2
[2017-03-31 15:17:49 +0800] Sending SETUP to rtsp://10.0.10.200:8557/H264/track1
[2017-03-31 15:17:49 +0800] SETUP rtsp://10.0.10.200:8557/H264/track1 RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 3
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800] Transport: RTP/AVP;unicast;client_port=6970-6971
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 3
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Transport: RTP/AVP;unicast;destination=172.17.3.54;source=10.0.10.200;client_port=6970-6971;server_port=6970-6971
[2017-03-31 15:17:49 +0800] Session: 2A4A2DAF;timeout=65
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Sending PLAY to rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:49 +0800] PLAY rtsp://10.0.10.200:8557/H264/ RTSP/1.0
[2017-03-31 15:17:49 +0800] CSeq: 4
[2017-03-31 15:17:49 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:49 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:49 +0800] Range: npt=0.000-
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Received response:
[2017-03-31 15:17:49 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:49 +0800] CSeq: 4
[2017-03-31 15:17:49 +0800] Date: Fri, Mar 31 2017 07:18:17 GMT
[2017-03-31 15:17:49 +0800] Range: npt=0.000-
[2017-03-31 15:17:49 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:49 +0800] RTP-Info: url=rtsp://10.0.10.200:8557/H264/track1;seq=5877;rtptime=3937889106,url=rtsp://10.0.10.200:8557/H264/track2;seq=0;rtptime=0
[2017-03-31 15:17:49 +0800]
[2017-03-31 15:17:49 +0800] Capturing RTP data on port 6970
[2017-03-31 15:17:54 +0800] Sending PAUSE to rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:54 +0800] PAUSE rtsp://10.0.10.200:8557/H264/ RTSP/1.0
[2017-03-31 15:17:54 +0800] CSeq: 5
[2017-03-31 15:17:54 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:54 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:54 +0800]
[2017-03-31 15:17:54 +0800] Received response:
[2017-03-31 15:17:54 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:54 +0800] CSeq: 5
[2017-03-31 15:17:54 +0800] Date: Fri, Mar 31 2017 07:18:22 GMT
[2017-03-31 15:17:54 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:54 +0800]
[2017-03-31 15:17:56 +0800] Sending TEARDOWN to rtsp://10.0.10.200:8557/H264/
[2017-03-31 15:17:56 +0800] TEARDOWN rtsp://10.0.10.200:8557/H264/ RTSP/1.0
[2017-03-31 15:17:56 +0800] CSeq: 6
[2017-03-31 15:17:56 +0800] User-Agent: RubyRTSP/0.4.5 (Ruby 2.0.0-p648)
[2017-03-31 15:17:56 +0800] Session: 2A4A2DAF
[2017-03-31 15:17:56 +0800]
[2017-03-31 15:17:57 +0800] Received response:
[2017-03-31 15:17:57 +0800] RTSP/1.0 200 OK
[2017-03-31 15:17:57 +0800] CSeq: 6
[2017-03-31 15:17:57 +0800] Date: Fri, Mar 31 2017 07:18:25 GMT
参考文档:https://github.com/turboladen/rtsp
RUBY 模拟rtsp消息的更多相关文章
- 转:简单的RTSP消息交互过程
简单的RTSP消息交互过程 C表示RTSP客户端,S表示RTSP服务端 1. 第一步:查询服务器端可用方法 1.C->S:OPTION request //询问S有哪些方法可用 ...
- Ruby Web实时消息后台服务器推送技术---GoEasy
越来越多的项目需要用到实时消息的推送与接收,怎样用Ruby实现最方便呢?我这里推荐大家使用GoEasy, 它是一款第三方推送服务平台,使用它的API可以轻松搞定实时推送! 浏览器兼容性:GoEasy推 ...
- keybd_event跟SendMessage,PostMessage模拟键盘消息的区别 z
首先你会发现keybd_event函数中是没有窗口句柄作为参数的,好奇的你一定会觉得很奇怪,那是因为,keybd_event是全局模拟按键的,只对前台窗口(即当前的活动窗口)才可以,但是如果模拟的按键 ...
- RTSP 消息拼装实例代码
整理了下之前文章提到的RTSP实例的代码,主要是拼装各类消息字段. 首先,抽取一个公共函数,用来根据消息类型,生成不同的format,供sprintf试用. char * GetRTSPCmd( co ...
- C++模拟键盘消息
实现功能:在现有DLL程序中向特定的EXE窗口中发送模拟键盘的消息 使用API根据窗口标题递归查找特定的窗口句柄,之后模拟调用. 注意:keybd_event函数不能在VS下使用,所以用SendInp ...
- java模拟异步消息的发送与回调
http://kt8668.iteye.com/blog/205739 本文的目的并不是介绍使用的什么技术,而是重点阐述其实现原理. 一. 异步和同步 讲通俗点,异步就是不需要等当前执行的动作完成 ...
- android 模拟微信消息 OnItemClickListener()方法 [3]
在 http://www.cnblogs.com/Seven-cjy/p/6101555.html 是基础上修改 MainActivity.java /winxinmff/src/com/exampl ...
- android 模拟微信消息框 BaseAdapter()方法 [2]
在昨天的微信布局的基础上加内容 http://www.cnblogs.com/Seven-cjy/p/6098024.html 项目下/res/layout下创建一个 listview_layout. ...
- 简单的RTSP消息交互过程
C表示RTSP客户端,S表示RTSP服务端 第一步:查询服务器端可用方法 1. C->S:OPTION request //询问S有哪些方法可用 2. S->C:OPTION ...
随机推荐
- Python常见编程规范总结
Pythonic定义 Python最常用的编码风格还是PEP8,详见:http://jython.cn/dev/peps/pep-0008/ Pythonic确实很难定义,先简单引用下<Pyth ...
- POJ 1065 Wooden Sticks(LIS,最少链划分)
题意:求二维偏序的最少链划分. 用到Dilworth定理:最少链划分=最长反链.(对偶也成立,个人认为区别只是一个维度上的两个方向,写了个简单的证明 相关概念:偏序集,链,反链等等概念可以参考这里:h ...
- Ubuntu 上配置静态的ip
先关掉或卸掉 network-manager.然后,改动/etc/network/interfaces 如下:(由于是静态ip,你当然知道把例子中那些东西改成你自己的)auto lo eth0ifac ...
- Struts2 In Action笔记_页面到动作的数据流入和流出
因为回答百度知道的一个问题,仔细查看了<Struts2 In Action>,深入细致的看了 “数据转移OGNL 和 构建视图-标签”,很多东西才恍然大悟. 一直觉得国外写的书很浮,不具有 ...
- 解决ndk编译lua时遇到 undefined reference to '__srget'的问题
今天用ndk r10d版本编译lua时,遇到几个错误,提示没有找到__srget 没有定义,于是看了国外的大神的解决方法, 是因为ndk在r10c之后的版本已经将getc函数屏蔽了,所以导致编译器找不 ...
- Node第二天
一.http模块: 步骤一:创建http服务器 const https = require('https'); 步骤二:const fs = require('fs'); 步骤三:创建请求=> ...
- SummerVocation_Learning--java的String类方法总结
壹: public char charAt(int index),返回字符串中第index个字符. public int length(), 返回字符串长度. public int indexOf(S ...
- ABAP读取长文本的方法
SAP中所有的项目文本都存在以下两张数据表中: 1. STXH 抬头项目文本 透明表 2. STXL 明细项目文本 透明表 长文本读取方法 首先在STXH和STXL中根据OBJECT NAME ...
- MySql学习笔记05
复习 GROUP BY 语句 HAVING 子句 -- 查询每个分类商品所对应的库存总量中,高于1000的总量 select category_id,sum(num) s from t_item gr ...
- 三十五、MySQL 运算符
MySQL 运算符 本章节我们主要介绍 MySQL 的运算符及运算符的优先级. MySQL 主要有以下几种运算符: 算术运算符 比较运算符 逻辑运算符 位运算符 算术运算符 MySQL 支持的算术运算 ...