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 ...
随机推荐
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer
这其实就是 获得应用的根url,比如说你的应用的根路径是 http://localhost:8080,那么你列出的代码就是为basePath赋值为 http://localhost:8080.具体点: ...
- 【BZOJ4300】绝世好题(位运算水题)
点此看题面 大致题意: 给你一个序列\(a\),让你求出最长的一个子序列\(b\)满足\(b_i\&b_{i-1}!=0\). 位运算+\(DP\) 考虑设\(f_i\)表示以第\(i\)个数 ...
- 使用RichTextBox控件保存文件
实习效果: 知识运用: RichTextBox控件的SaveFile方法 SaveFileDialog对象的ShowDialog方法 实现代码: private void 打开RTF文件ToolStr ...
- Andrew NG 自动化所演讲(20140707):DeepLearning Overview and Trends
出处 以下内容转载于 网友 Fiona Duan,感谢作者分享 (原作的图片显示有问题,所以我从别处找了一些附上,小伙伴们可以看看).最近越来越觉得人工智能,深度学习是一个很好的发展方向,应该也是未来 ...
- FILE对象线程安全
根据apue讲述: 标准的IO例程可能从它们各自的内部数据结构的角度出发,是以线程安全的方式实现的!但在线程中,如果标准 IO例程都获取它们各自的锁,那么在做一次一个字符的IO时就会出现严重的性能下降 ...
- CentOS7 ngnix 的安装和配置
刚开始我也在纠结到底是该用Apache呢还是Nginx?然后网上各种查看了它俩的对比,总结了它俩最大区别在于apache是同步多进程模型,在处理动态有优势:nginx是异步的,并发性能比较好,cpu内 ...
- Jane Austen【简·奥斯汀】
Jane Austen Jane Austen, a famous English writer, was born at Steventon, Hampshire, on December 16, ...
- 常州大学新生寒假训练会试 I 合成反应
题目描述 有机合成是指从较简单的化合物或单质经化学反应合成有机物的过程. 有时也包括从复杂原料降解为较简单化合物的过程. 由于有机化合物的各种特点,尤其是碳与碳之间以共价键相连,有机合成比较困难,常常 ...
- time模块和datetime模块详解
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
- 第八届蓝桥杯C/C++ B组省赛----分巧克力
分巧克力 问题描述 儿童节那天有K位小朋友到小明家做客.小明拿出了珍藏的巧克力招待小朋友们. 小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形. 为了公平起见,小明需要从这 N 块巧 ...