`

Specifications for a simple RTSP client

    博客分类:
  • RTSP
 
阅读更多

Abstract

This document describes a simple implementation of the client side of an RTSP session, including the minimal requirements to complete a successful dialogue with the IFI extension of the Darwin Streaming Server RTSP implementation. Here, emphasis is made on making parsing and error control as simple as possible, not necessarily following all the aspects of the RTSP standard (RFC 2326) requirements.

Connecting

The client is initially supplied with an RTSP URL, on the form:

rtsp://server.address:port/object.sdp
The URL is either supplied within a simple text file, the file name being supplied as a command line parameter when the client is started, or hopefully, the client is able to accept user input in a text box in the client's graphical user interface.

There are a number of things the client should check while parsing the URL:

  • Whether the URL starts with "rtsp://" (no case sensitivity)
  • Whether the server address is invalid or not (either DNS name or IP address should be accepted)
  • If port number is included (simply check for a colon, ':'), it should check if this port number is valid (an unsigned integer, less than 65536)

What comes after the last slash ('/'), we can leave to the server parser (in our case, however, it would be nice to check whether the object ends with ".sdp", since this is required to activate our reflector capabilities in the RTSP server).

After parsing the URL, the client should have a valid server address (at least lexically), and possibly a port number. If no port number is supplied, the default "well known port" for RTSP is assumed, which is 554.

As soon as the URL is parsed, a TCP connection should be made to the obtained server address/port. The client should then transmit the DESCRIBE request as follows:

Client: Here, of course, '/r/n' is not to be taken literally, but as return and newline characters (as in printf in the C programming language). The describe request should include the RTSP URL exactly as supplied by the user/caller. The "CSeq" header field is used in sequence numbering, and not really necessary to operate the RTSP server (it is mandatory according to the standard, however). It is mainly practical when not operating with an open TCP connection during the entire session, for the client to make sure no messages are lost. The server will blindly echo the sequence number, including a "CSeq" header in the response messages.

The TCP connection can remain open for the duration of the session, but there is no reason why the connection should be maintained after the first SETUP request. It is necessary, however, to keep the connection alive while doing the DESCRIBE and the following SETUP requests, because of the the way in which the server is implemented.

Receiving SDP information

The server may respond to the DESCRIBE request in any number of ways (or it might not respond at all), but it is safe to assume that any other response than "RTSP/1.0 200 OK" in the first line might indicate an error situation (and a good excuse to give up on this particular session). A successful response to the DESCRIBE might look as follows:

Server: It's not necessary to parse the SDP information entirely. It will suffice to extract the lines containing "a=control:trackID=x" and keep hold of these control strings. It will also be necessary to extract the associated "m=..." lines kbdceding the control attributes. These indicate the nature of the media stream, and hence which tool is required to render it ("video" and "audio" indicating vic and rat, respectively).

What to do if there are other media descriptors than "video" or "audio" is not decided, but the best thing to do might be to ignore them altogether, telling the user that "unknown media types were encountered". If no known media type is found, the client must terminate gracefully.

Setting up

To set up, the "SETUP" request must be issued. It might look like this:

Client:


SETUP rtsp://server.address:port/object.sdp/trackID=1 RTSP/1.0/r/n
CSeq: 2/r/n
Transport: RTP/AVP;unicast;client_port=9000-9001/r/n
/r/n

This request must be issued for each of the control strings obtained above (leaving out the ones rekbdsenting media types we can't handle, of course). Note that the original URL is used, augmented by a slash ('/') and the control string. For the first one of these requests, the server (if all goes well) will respond with:

Server:


RTSP/1.0 200 OK/n
Server: QTSS(IFI)/v88/n
Cseq: 2/n
Session: 1234567890;timeout=60
Transport: rtp/avp;source=129.240.65.208;server_port=9000-9001;client_port=9000-9001/n
/n

All consecutive SETUP requests must include the session header field. It looks like this:

Client:


SETUP rtsp://server.address:port/object.sdp/trackID=2 RTSP/1.0/r/n
CSeq: 3/r/n
Session: 1234567890/r/n
Transport: RTP/AVP;unicast;client_port=9000-9001/r/n
/r/n

Even though in this example, the session identifier contains only numbers, the standard allows alpha characters as well. So making the client able to accept 2Ak432zDQr just as well as 1234567890 would be a good idea (case-sensitive, of course). The standard requires the identifier to be at least 8 octets long.

Again, anything other than "RTSP/1.0 200 OK" might indicate error, and should result in termination. In the responses, the information worth making a note of is the source attribute in the transport header field, and the client_port attribute. These will be needed to start the media tools later on.

Setting up a reflector session is only required if the client host is not capable of multicast on the MBone. However, using the returned SDP information to start the Meccano tools will require a much more elaborate parsing. For the sake of simplicity, we might assume that the client is not MBone capable.

Otherwise we might issue the SETUP request with "multicast" instead of "unicast" in the transport header field. The server can then respond with the appropriate multicast address/port numbers instead of setting up the reflector. This, however, remains to be implemented in the server. Other problems might arise as well, since the multicast sessions visible to the reflector/listener system might not be visible to the client. A more complete client would parse the SDP information, determine whether the multicast session is reachable, and initiate rendering on its own.

Start playing

To start getting the media packets, all we have to do is to send a "PLAY" request to the server. It looks like this:

Client: Note that the control string is omitted, hence the request applies to all streams currently set up. Again, other responses than "RTSP/1.0 200 OK" is handled as a fatal error.

Now is the time for starting up the media tools, using the source address and port number obtained above. Note that the media tools only require one of the port numbers acquired, for an example, if the transport header from the server includes "client_port=9000-9001", the media tool only needs port number 9000 in its command line parameters.

 

Pausing

This is handled the same way as playing. These two actions might be implemented using a single button in the client's graphical user interface, toggling between play and pause.

Client:

Tearing down

The request "TEARDOWN" is only issued at the very end of the session. This makes the server release all its resources pertaining to the session, and new SETUP requests will have to be sent in order to restart the media streams. It looks like this:

Client: The server will reply:

Server: When the reply to this message is received, the client can safely disconnect. The sequence number is really not required. However, the Session: header field is mandatory.

Important: The TEARDOWN must be issued before the client application is allowed to terminate, otherwise the reflector is liable to swamp the client host with unwanted udp packets. Another thing which might pose a problem, is that of client bandwidth. If reflector output surpasses available bandwitdh between itself and the client, TCP traffic to the RTSP server might be blocked. This situation is extremely undisirable, because the client internet connection in effect becomes unusable. The solution to this problem (at the moment), has been to implement a refresh timeout in the server. The client is required to send "dummy" requests within certain intervals. The most suited request for this, is OPTIONS. The timeout period (in seconds) is indicated by the SETUP reply message, in the session header field. To keep the session alive, just send along an OPTIONS request every now and then. It's done like this:

Client: Failure to pass these refresh "requests" would in effect mean the same as a TEARDOWN request.

Summary

The client may operate in three distinct states, disconnected, playing and paused. When the application is started, the state is of course "disconnected". After starting up, the client issues the requests DESCRIBE, SETUP and PLAY, and enters the "playing" state. The play button changes into a pause button, and the media rendering tools are started. During this state, the client sends the OPTIONS request regularly.

When the user kbdsses the recently appeared pause button, the PAUSE request is sent, and state is transferred into "paused". The pause button changes into a play button. When the user kbdsses the exit button (or exits the client application), TEARDOWN is sent, the TCP channel is broken, and the media tools are terminated.

An example of how the client dialog might look like, is included below.

 

 

OPTIONS rtsp://server.address:port/object.sdp RTSP/1.0/r/n
CSeq: 6/r/n
Session: 1234567890/r/n
/r/n

 

RTSP/1.0 200 OK/n
Server: QTSS(IFI)/v88/n
Cseq: 6/n
Session: 537103309/n
Connection: Close/n
/n

 

TEARDOWN rtsp://server.address:port/object.sdp RTSP/1.0/r/n
CSeq: 6/r/n
Session: 1234567890/r/n
/r/n

 

PAUSE rtsp://server.address:port/object.sdp RTSP/1.0/r/n
CSeq: 5/r/n
Session: 1234567890/r/n
/r/n

 

PLAY rtsp://server.address:port/object.sdp RTSP/1.0/r/n
CSeq: 4/r/n
Session: 1234567890/r/n
/r/n

 

RTSP/1.0 200 OK/n
Server: QTSS(IFI)/v88/n
Cseq: 1/n
Content-Type: application/sdp/n
Content-Base: rtsp://bildeus.ifi.uio.no:8000/12.sdp//n
Content-length: 785/n
/n
n=2236805513 2236805513 932036356 224.2.127.254 9875 127 trusted/n
v=0/n
o=yozo 3138827440 3138828177 IN IP4 aohakobe.ipc.chiba-u.ac.jp/n
s=Places all over the world/n
i=Low bandwidth video (10kb/s) with views from all over the world. Audio is primarily for feedback for the senders of video. (looks like there's some problem for the session announcement from sweden distributes to the whole MBone, I'm repeating the announcement from japan. -- yozo.)/n
e=Yozo TODA at IPC, Chiba University, JAPAN <yozo@ipc.chiba-u.ac.jp.>/n
p=+81-43-290-3539/n
c=IN IP4 224.2.213.113/127/n
t=3138827400 3141246600/n
a=tool:sdr v2.6.1/n
a=type:test/n
m=audio 20154 RTP/AVP 0/n
c=IN IP4 224.2.213.113/127/n
a=ptime:40/n
a=control:trackID=1/n
m=video 51482 RTP/AVP 31/n
c=IN IP4 224.2.172.238/127/n
a=control:trackID=2/n

 

DESCRIBE rtsp://server.address:port/object.sdp RTSP/1.0/r/n
CSeq: 1/r/n
/r/n
分享到:
评论

相关推荐

    rtspclient_rtspclient_RTSPClient_rtsp_rtspclient

    "rtspclient"和"RTSPClient"可能是这个项目中的客户端实现,可能是一个C++或Java库,或者是一个命令行工具,用于测试和验证RTSP服务器的功能。 描述中的"RTSP流媒体,rtsp client 测试例程"表明这个压缩包包含了...

    rtsp.rar_C rtsp client_Simple RTSP_linux RTSP client_rtsp clien

    “linux_rtsp_client”和“rtsp_client_linux”标签表明这个客户端是为Linux平台设计的,这意味着它将依赖于Linux特有的库和API,例如libcurl或GStreamer等,这些库可能提供了方便的接口来处理网络通信和多媒体数据...

    rtspclient_rtsp客户端_RTSPClient_rtsp_linux_wasuog_

    在给定的标题"rtspclient_rtsp客户端_RTSPClient_rtsp_linux_wasuog_"中,我们可以推断这是一个关于在Linux环境下实现的RTSP客户端,可能被命名为"RTSPClient",并且可能与"wasuog"(可能是某个组织或项目的缩写)...

    java-rtsp-client.rar_RTSP JAVA_java rtsp client_rtsp_rtsp client

    文件"java rtsp client.doc"可能是关于如何在Java中构建RTSP客户端的详细指南,涵盖以下内容: 1. **设置环境**:安装必要的库,配置开发环境。 2. **RTSP协议理解**:解释RTSP的基本概念和命令。 3. **代码示例**:...

    rtspclient_rtspclient_RTSPClient_rtsp_rtspclient_源码.rar

    "rtspclient_rtspclient_RTSPClient_rtsp_rtspclient_源码.rar"这个压缩包文件很显然是一个关于RTSP客户端的源代码库,可能包含了实现RTSP协议的C++或Java等编程语言的代码。 1. RTSP协议基础: - RTSP协议是基于...

    rtsp client with c++.zip_c++使用rtsp协议_rtsp c++ client_rtsp_client

    RTSP(Real-Time Streaming Protocol)是一种应用层协议,主要用于控制实时流媒体的传输。它允许客户端与服务器之间协商媒体的播放、暂停、快进、快退等操作。本项目是用C++实现的一个RTSP客户端,非常适合初学者...

    rtspclient.zip

    本文将深入探讨标题为"rtspclient.zip"的压缩包文件,它包含了一个由作者自行改写的、在Linux环境下运行的纯C语言实现的RTSP客户端,能够接收并处理MP3流媒体。 首先,RTSP是一种应用层协议,主要负责建立、控制和...

    Simplified Java RTSP Client

    A simplified java rtsp client source code

    基于live555封装的RTSPClient

    基于live555封装的rtspClient, 解决了默认live555 rtspClient demo 掉线问题,支持网络断线重连,支持多摄像机接入。文件包括播放demo及封装的Lib,包括rtspClient的封装实现源码。

    Android代码-Rtsp-Android-Client

    RtspClient &gt; - [x] 实现基本框架 &gt; - [x] 支持以UDP方式接收RTP报文 [ ] 优化UDP报文解码 &gt; - [x] 支持以TCP方式接收RTP报文 [ ] 优化TCP报文重组 &gt; - [x] 实现RTP报文重组 [x] 支持FU-A报文重组 [x] 支持单包NAL...

    rtsp client(基于live555)

    在live555 srv运行h264,用此client可以接收到h264。在fwrite的地方加上自己的回调,就可以融入到自己的项目中去。 此代码我也应用于项目中了,代码中的ip或h264文件名之类的自己做微调即可。

    rtspclient_rtspclient_RTSPClient_rtsp_rtspclient.zip

    在你提供的文件"rtspclient_rtspclient_RTSPClient_rtsp_rtspclient.zip"中,我们可以期待找到一个关于RTSP客户端的源代码实现。这个客户端可能实现了与服务器进行交互的基本功能,如建立会话、发送播放、暂停和停止...

    RTSP_Client.rar

    在这个“RTSP_Client.rar”压缩包中,包含了一个在VS2013环境下编译执行的RTSP客户端代码,这个客户端已经成功地与海康大华等知名监控设备厂商进行了对接,实现了通过RTSP协议获取视频流的功能。 RTSP协议的核心...

    RTSPCLIENT.zip

    RTSPCLIENT.zip是一个包含C++源代码的压缩包,用于解析RTSP(Real Time Streaming Protocol)流,并将解析后的数据转换为IplImage格式,以便使用OpenGL进行显示。这个项目适用于Visual Studio 2012环境,且依赖于...

    test_rtspclient.zip_RTSP VC6_rtsp_rtsp client_rtsp_client_rtsp_c

    这个"test_rtspclient.zip"文件包含了一个用VC6.0(Visual C++ 6.0)编译环境构建的RTSP客户端示例项目。让我们深入探讨RTSP、VC6.0以及相关文件的功能和作用。 RTSP协议由IETF定义,主要用于远程控制实时数据流,...

    java RTSPClient

    根据网上的资料改写的RTSPClient的改进版本, 绝对可以用, 显示整个RTSP报文的交互过程

    rtsp.rar_rtsp_rtsp client_rtsp客户端

    RTSP(Real Time Streaming Protocol,实时流协议)是一种应用层协议,主要用于控制音频、视频等媒体的播放。在本文中,我们将深入探讨RTSP客户端的实现,基于C语言的简单代码,以及它如何与服务器进行交互。 首先...

    rtspclient demo

    这个"rtspclient demo"专为处理100路高清视频流设计,展示了如何有效地利用RTSP协议来实现实时多媒体数据的传输。 RTSP是一种应用层协议,主要用来控制实时媒体的播放,比如视频和音频。它允许用户进行播放、暂停、...

    RTSP_Client.c

    用C语言编写的RTSP的客户端,在海思平台经过数据验证。

    live555 rtspClient源代码

    【标题】"live555 rtspClient源代码"涉及的核心技术是实时流协议(RTSP)和live555库的应用。Live555是一个开源的C++库,广泛用于实现多媒体流传输,尤其是互联网上的实时音频和视频。RTSP(Real-Time Streaming ...

Global site tag (gtag.js) - Google Analytics