summaryrefslogtreecommitdiffstats
path: root/gst/rtsp/README
blob: 024589157684d4c4bb4facdc2c97a535cffae7d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
RTSP source 
-----------

The RTSP source establishes a connection to an RTSP server and sets up
the UDP sources and RTP session handlers.

An RTSP session is created as follows:

- Parse RTSP URL:

   ex:
     rtsp://thread:5454/south-rtsp.mp3

- Open a connection to the server with the url. All further conversation with
  the server should be done with this connection. Each request/reply has
  a CSeq number added to the header.

- Send a DESCRIBE request for the url. We currently support a response in
  SDP.

  ex:

    >> DESCRIBE rtsp://thread:5454/south-rtsp.mp3 RTSP/1.0
    >> Accept: application/sdp
    >> CSeq: 0
    >>
    << RTSP/1.0 200 OK
    << Content-Length: 84
    << Content-Type: application/sdp
    << CSeq: 0
    << Date: Wed May 11 13:09:37 2005 GMT
    <<
    << v=0
    << o=- 0 0 IN IP4 192.168.1.1
    << s=No Title
    << m=audio 0 RTP/AVP 14
    << a=control:streamid=0

- Parse the SDP message, for each stream (m=) we create an GstRTPStream. We need
  to allocate two local UDP ports for receiving the RTP and RTCP data because we
  need to send the port numbers to the server in the next request.

  In RTSPSrc we first create an element that can handle the udp://0.0.0.0:0 uri. This
  will create an udp source element with a random port number. We get the port
  number by getting the "port" property of the element after setting the element to 
  PAUSED. This element is used for the RTP packets and has to be an even number. If
  the random port number is not an even number we retry to allocate a new udp source.

  We then create another UDP source element with the next (uneven) port number to 
  receive the RTCP packet on. After this step we have two udp ports we can use to
  accept RTP packets.

    +-----------------+
    | +------------+  |
    | | udpsrc0    |  |
    | |  port=5000 |  |
    | +------------+  |
    | +------------+  |
    | | udpsrc1    |  |
    | |  port=5001 |  |
    | +------------+  |
    +-----------------+

- Send a SETUP message to the server with the RTP ports. We get the setup URI from
  the a= attribute in the SDP message. This can be an absolute URL or a relative
  url.

  ex:

    >> SETUP rtsp://thread:5454/south-rtsp.mp3/streamid=0 RTSP/1.0
    >> CSeq: 1
    >> Transport: RTP/AVP/UDP;unicast;client_port=5000-5001,RTP/AVP/UDP;multicast,RTP/AVP/TCP
    >>
    << RTSP/1.0 200 OK
    << Transport: RTP/AVP/UDP;unicast;client_port=5000-5001;server_port=6000-6001
    << CSeq: 1
    << Date: Wed May 11 13:21:43 2005 GMT
    << Session: 5d5cb94413288ccd
    <<

  The client needs to send the local ports to the server along with the supported 
  transport types. The server selects the final transport which it returns in the
  Transport header field. The server also includes its ports where RTP and RTCP
  messages can be sent to.

  In the above example UDP was choosen as a transport. At this point the RTSPSrc element
  will furter configure its elements to process this stream.

  The RTSPSrc will create and connect an RTP session manager element and will
  connect it to the src pads of the udp element. The data pad from the RTP session 
  manager is ghostpadded to RTPSrc.
  The RTCP pad of the rtpdec is routed to a new udpsink that sends data to the RTCP
  port of the server as returned in the Transport: header field.

    +---------------------------------------------+
    | +------------+                              |
    | | udpsrc0    |   +--------+                 |
    | |  port=5000 ----- rtpdec --------------------
    | +------------+   |        |                 |
    | +------------+   |        |  +------------+ |
    | | udpsrc1    ----- RTCP   ---- udpsink    | |
    | |  port=5001 |   +--------+  |  port=6001 | |
    | +------------+               +------------+ |
    +---------------------------------------------+

  The output type of rtpdec is configured as the media type specified in the SDP
  message. 

- All the elements are set to PAUSED/PLAYING and the PLAY RTSP message is
  sent.

    >> PLAY rtsp://thread:5454/south-rtsp.mp3 RTSP/1.0
    >> CSeq: 2
    >> Session: 5d5cb94413288ccd
    >>
    << RTSP/1.0 200 OK
    << CSeq: 2
    << Date: Wed May 11 13:21:43 2005 GMT
    << Session: 5d5cb94413288ccd
    <<

- The udp source elements receive data from that point and the RTP/RTCP messages
  are processed by the elements.

- In the case of interleaved mode, the SETUP method yields:

    >> SETUP rtsp://thread:5454/south-rtsp.mp3/streamid=0 RTSP/1.0
    >> CSeq: 1
    >> Transport: RTP/AVP/UDP;unicast;client_port=5000-5001,RTP/AVP/UDP;multicast,RTP/AVP/TCP
    >>
    << RTSP/1.0 200 OK
    << Transport: RTP/AVP/TCP;interleaved=0-1
    << CSeq: 1
    << Date: Wed May 11 13:21:43 2005 GMT
    << Session: 5d5cb94413288ccd
    <<

  This means that RTP/RTCP messages will be sent on channel 0/1 respectively and that
  the data will be received on the same connection as the RTSP connection.

  At this point, we remove the UDP source elements as we don't need them anymore. We
  set up the rtpsess session manager element though as follows:

    +---------------------------------------------+
    | +------------+                              |
    | | _loop()    |   +--------+                 |
    | |            ----- rtpses --------------------
    | |            |   |        |                 |
    | |            |   |        |  +------------+ |
    | |            ----- RTCP   ---- udpsink    | |
    | |            |   +--------+  |  port=6001 | |
    | +------------+               +------------+ |
    +---------------------------------------------+

  We start an interal task to start reading from the RTSP connection waiting
  for data. The received data is then pushed to the rtpdec element.

  When reading from the RTSP connection we receive data packets in the
  following layout (see also RFC2326)

    $<1 byte channel><2 bytes length, big endian><length bytes of data>


RTSP server
-----------

An RTSP server listen on a port (default 554) for client connections. The client
typically keeps this channel open during the RTSP session to instruct the server
to pause/play/stop the stream.

The server exposes a stream consisting of one or more media streams using an
URL. The media streams are typically audio and video.

  ex:
     rtsp://thread:5454/alien-rtsp.mpeg

     exposes an audio/video stream. The video is mpeg packetized in RTP and
     the audio is mp3 in RTP.

The streaming server typically uses a different channel to send the media
data to clients, typically using RTP over UDP. It is also possible to stream
the data to the client using the initial RTSP TCP session (the interleaved
mode). This last mode is usufull when the client is behind a firewall but
does not take advantage of the RTP/UDP features.

In both cases, media data is send to the clients in an unmultiplexed format
packetized as RTP packets.

The streaming server has to negotiate a connection protocol for each of the
media streams with the client.

Minimal server requirements:

- The server should copy the CSeq header field in a client request to the
  response so that the client can match the response to the request.

- The server should keep a session for each client after the client issued
  a SETUP command. The client should use the same session id for all future
  request to this server.

- the server must support an OPTIONS request send over the RTSP connection.

    >> OPTIONS * RTSP/1.0
    >> CSeq: 1
    >>
    << RTSP/1.0 200 OK
    << CSeq: 1
    << Date: Wed May 11 13:21:43 2005 GMT
    << Session: 5d5cb94413288ccd
    << Public: DESCRIBE, SETUP, TEARDOWN, PLAY
    <<

   The OPTIONS request should list all supported methods on the server.
 
 - The server should support the DESCRIBE method.

    >> DESCRIBE rtsp://thread:5454/south-rtsp.mp3 RTSP/1.0
    >> Accept: application/sdp
    >> CSeq: 2
    >>
    << RTSP/1.0 200 OK
    << Content-Length: 84
    << Content-Type: application/sdp
    << CSeq: 2
    << Date: Wed May 11 13:09:37 2005 GMT
    <<
    << v=0
    << o=- 0 0 IN IP4 192.168.1.1
    << s=No Title
    << m=audio 0 RTP/AVP 14
    << a=control:streamid=0

    The client issues a DESCRIBE command for a specific URL that corresponds
    to an available stream. The client will also send an Accept header to
    list its supported formats. 

    The server answers this request with a reply in one of the client supported
    formats (application/sdp is the most common). The server typically sends a
    fixed reply to all clients for each configured stream.

 - The server must support the SETUP command to configure the media streams 
   that were listed in the DESCRIBE command.

    >> SETUP rtsp://thread:5454/south-rtsp.mp3/streamid=0 RTSP/1.0
    >> CSeq: 3
    >> Transport: RTP/AVP/UDP;unicast;client_port=5000-5001,RTP/AVP/UDP;multicast,RTP/AVP/TCP
    >>
    << RTSP/1.0 200 OK
    << Transport: RTP/AVP/UDP;unicast;client_port=5000-5001;server_port=6000-6001
    << CSeq: 3
    << Date: Wed May 11 13:21:43 2005 GMT
    << Session: 5d5cb94413288ccd

    The client will send a SETUP command for each of the streams listed in the 
    DESCRIBE reply. For sdp will use a URL as listed in the a=control: property.

    The client will list the supported transports in the Transport: header field.
    Each transport is separated with a comma (,) and listed in order of preference.
    The server has to select the first supported transport.
 
    In the above example 3 transport are listed:

       RTP/AVP/UDP;unicast;client_port=5000-5001

         The client will accept RTP over UDP on the port pair 5000-5001. Port
	 5000 will accept the RTP packets, 5001 the RTSP packets send by the
	 server.
       
       RTP/AVP/UDP;multicast

         The client can join a multicast group for the specific media stream.
	 The port numbers of the multicast group it will connect to have to
	 be specified by the server in the reply.
       
       RTP/AVP/TCP

         the client can accept RTP packets interleaved on the RTSP connection.

    The server selects a supported transport an allocates an RTP port pair to
    receive RTP and RTSP data from the client. This last step is optional when
    the server does not accept RTP data.

    The server should allocate a session for the client and should send the
    sessionId to the client. The client should use this session id for all
    future requests.

    The server may refuse a client that does not use the same transport method
    for all media streams.

    The server stores all client port pairs in the server client session along
    with the transport method.

    ex:

      For an on-demand stream the server could construct a (minimal) RTP GStreamer 
      pipeline for the client as follows (for an mp3 stream):
    
      +---------+    +-----------+    +------------+    +-------------+
      | filesrc |    | rtpmp3enc |    | rtpsession |    | udpsink     |
      |         |    |           |    |            |    |   host=XXX  |
      |         |    |           |    |            |    |   port=5000 |
      |        src--sink        src--rtpsink   rtpsrc--sink           |
      +---------+    +-----------+    |            |    +-------------+
                                      |            |    +-------------+
                                      |            |    | udpsink     |
                                      |            |    |   host=XXX  |
                                      |            |    |   port=5001 |
                                      |       rtspsrc--sink           |
                                      +------------+    +-------------+

      The server would set the above pipeline to PAUSE to make sure no data
      is sent to the client yet.

      optionally udpsrc elements can be configured to receive client RTP and
      RTSP messages.

    ex:

      For a live stream the server could construct a (minimal) RTP GStreamer 
      pipeline for the clients as follows (for an mp3 stream):
    
      +---------+    +--------+    +-----------+    +------------+    +--------------+
      | source  |    | mp3enc |    | rtpmp3enc |    | rtpsession |    | multiudpsink |
      |         |    |        |    |           |    |            |    |   host=...   |
      |         |    |        |    |           |    |            |    |   port=...   |
      |        src--sink     src--sink        src--rtpsink   rtpsrc--sink            |
      +---------+    +--------+    +-----------+    |            |    +--------------+
                                                    |            |    +--------------+
                                                    |            |    | multiudpsink |
                                                    |            |    |   host=...   |
                                                    |            |    |   port=...   |
                                                    |       rtspsrc--sink            |
                                                    +------------+    +--------------+

      Media data is streamed to clients by adding the client host and port numbers
      to the multiudpsinks.

      optionally udpsrc elements can be configured to receive client RTP and
      RTSP messages.
     
 - The server must support the PLAY command to start playback of the configured
   media streams.

    >> PLAY rtsp://thread:5454/south-rtsp.mp3 RTSP/1.0
    >> CSeq: 2
    >> Session: 5d5cb94413288ccd
    >>
    << RTSP/1.0 200 OK
    << CSeq: 2
    << Date: Wed May 11 13:21:43 2005 GMT
    << Session: 5d5cb94413288ccd
    <<

    Using the Session: header field, the server finds the pipeline of the session
    to PLAY and sets the pipeline to PLAYING at which point the client receives
    the media stream data.

    In case of a live stream, the server adds the port numbers to a multiudpsink
    element.

 - The server must support the TEARDOWN command to stop playback and free the
   session of a client.

    >> TEARDOWN rtsp://thread:5454/south-rtsp.mp3 RTSP/1.0
    >> CSeq: 4
    >> Session: 5d5cb94413288ccd
    >>
    << RTSP/1.0 200 OK
    << CSeq: 4
    << Date: Wed May 11 13:21:43 2005 GMT
    <<

    The server destroys the client pipeline in case of an on-demand stream or
    removes the client ports from the multiudpsinks. This effectively stops
    streaming to the client.