Subject: RTSP Examples (fwd)

From: Rob Lanphier <[email-masked]>
Date: Wed, 4 Dec 1996 00:41:52 -0800 (PST)

I worked out a couple of examples of how the current draft of RTSP works
at the byte level.  I hope this helps people understand how the protocol
works, or at least stir up questions that will inevitably come up as
development of RTSP progresses.

To be consistant with the examples already provided by Henning in RTSP
prime, I'm using a similar format and similar examples (though not the
same ones, since I want to highlight what we view as the common scenario,
and I want to highlight some of the more interesting aspects of RTSP),
this time using RTSP instead of RTSP'.

Enjoy,
Rob

---
Rob Lanphier               Voice: (206)674-2322         Fax: (206)674-2699
Program Manager-Protocols                         Email: [email-masked]
Progressive Networks-Home of RealAudio       Web: http://www.realaudio.com

The following is a typical on-demand fetch of video content, using
RTSP-style compressed RTP headers.  Note that some things may be done
asynchronously, and so in some cases, the order is not important.
Furthermore, the following example is designed for clarity rather than
efficiency.

C: RTSP Client
R: RTSP Server
W: Web Server

C->W: GET coolmovie HTTP/1.0
      Accept: application/sdf; application/sdp

W->C: 200 OK
      Content-type: application/sdf

      [A yet-to be described file format which conveys the following
      information:

           A 16kbps English audio clip using algorithm X can be found
           at the following URL:
             rtsp://server.content.com/coolmovie?stream=1
           A 32kbps English audio clip using algorithm X can be found 
	   at the following URL:
             rtsp://server.content.com/coolmovie?stream=2
           An 64kbps video clip using algorithm Y can found at the
	   following URL:
	     rtsp://server.content.com/coolmovie?stream=3
      ]

At this point, the client decides that it has copious bandwidth and
can take the high-bandwidth audio and the video clip.  The client
connects to the server, and the following then occurs:

[Note: I'm using SCP as it is defined in Appendix A of the initial
RTSP draft.  This is not consistant with the SCP specification, but
will be in later drafts.]

C->R: SCP Global Control Channel (0)
        Flags: SYN and PUSH (0x9)
        ID: 0
        Length: 30 (0x1E)
      RTSP Hello Message
        Tag (4 bytes): 1000 HELLO (0x3E8) 
        Major/Minor Version (2 bytes): 1.0 (0x0100)
        Subprotocol (1 byte) (0x1)
        Reserved (1 byte) (0x0)
        User Agent (null terminated): RTSP 1.0 Client/Win95\0

R->C  SCP Global Control Channel (0)
        Flags: PUSH (0x8)
        ID: 0
        Length: 30 (0x1E)
      RTSP Hello Message
        Tag (4 bytes): 1000 HELLO (0x3E8)
        Major/Minor Version (2 bytes): 1.0 (0x0100)
        Subprotocol (1 byte) (0x1)
        Reserved (1 byte) (0x0)
        User Agent (null terminated): RTSP 1.0 Server/Linux\0
        
Now the client opens up a control channel to control the audio stream,
and sets that stream up:

C->R  SCP Stream Control Channel (1024)
        Flags: SYN and PUSH (0x9)	
        ID: 0
        Length: 57 (0x39)
      RTSP Fetch Message
        Tag (4 bytes): 2000 FETCH (0x7D0)
        Bandwidth (bits per sec) (4 bytes): 32768 bps (0x8000)
        Max number of hops (2 bytes): unlimited (0xFFFF)
        Request flags (2 bytes): none set (0x0)
        URL: rtsp://server.content.com/coolmovie?stream=2\0
    
R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 32 (0x20)
      RTSP Stream Header Message:
        Tag (4 bytes): 2001 STREAM_HEADER (0x7D1)
        Generic Type (4 bytes): Audio (0x1)
        Bandwidth (bits per sec) (4 bytes): 32768 bps (0x8000)
        Last Modification Time (4 bytes): Feb 16 1996 13:38:45 (0x312488E5) 
        Reserved (4 bytes): 0x0
        Length (4 bytes): 22 minutes (1320000 ms) (0x142440)
        Max Packet Size (4 bytes): 120 bytes (0x78)
        Flags (4 bytes): (0x4E)
           Unicast available: True
           Live: False
           Copy: False
           Cache: True
           Client-Cache: True
           UDP-okay: True
           Multicast: False

C->R  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 16 (0x10)
      RTSP Set Transport Message:
        Tag (4 bytes): 2002 SET_TRANSPORT (0x7D2)
	Flags (2 bytes): (0x8000)
	   C Flag: Compressed Headers On
        Channel ID (2 bytes): Unicast UDP (0x0)
        SSRC identifier (4 bytes): (0x0)
        Port (4 bytes): 7820 (0x1E8C)

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 48 (0x30)
      RTSP Param Reply Message:
        Tag (4 bytes): 4001 PARAM_REPLY (0xFA1)
	Request ID (4 bytes): Not specifically requested (0x0)
        Family ID (4 bytes): Audio (0x1)
        Parameter ID (4 bytes): Format Descriptor (0x1)
	Data Type (4 bytes): Opaque (0x2)
      Audio Format Descriptor:
        CODEC ID (4 bytes):  Fictional CODEC X (0xffffffff)
        NumChannels (2 bytes):  1 (0x1)
        Bits/Sample (2 bytes): 16 (0x10)
        Samples per second (4 bytes): 44100 hz (0xACFF)
        Average Frame Size (2 bytes): 64 bytes (0x40)
        Maximum Frame Size (2 bytes): 64 bytes (0x40)
        Samples per frame (4 bytes): 689 (0x2B1)
        P (1 bit): Packetized audio (0x1)
        Frames per packet (15 bits): 1 (0x1)
	Extra bytes (2 bytes): none (0x0)
	Number of Frames (4 bytes): 21120 frames (0x5280)

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 92 (0x5C)
      RTSP Param Reply Message:
        Tag (4 bytes): 4001 PARAM_REPLY (0xFA1)
	Request ID (4 bytes): Not specifically requested (0x0)
        Family ID (4 bytes): Audio (0x1)
        Parameter ID (4 bytes): Annotations (0x2)
	Data Type (4 bytes): Opaque (0x2)
      Audio Format Descriptor:
	Number of chunks (4 bytes): 3 (0x3)
        Chunk identifier (4 bytes): Name 'INAM' (0x494E414D)
	Number of bytes (4 bytes): 12 (0xC)
	Chunk data (12 bytes): "Cool Movie\0\0"
        Chunk identifier (4 bytes): Author 'IAUT' (0x49415554)
	Number of bytes (4 bytes): 18 (0x12)
	Chunk data (18 bytes): "Jean Spleenburger\0"
        Chunk identifier (4 bytes): Copyright 'ICOP' (0x49434F50)
	Number of bytes (4 bytes): 34 (0x22)
	Chunk data (34 bytes): "Copyright 1996 Cool Movie Company\0"

It needs to do the same thing for the video stream:

C->R  SCP Stream Control Channel (1026)
        Flags: SYN and PUSH (0x9)	
        ID: 0
        Length: 57 (0x39)
      RTSP Fetch Message
        Tag (4 bytes): 2000 FETCH (0x7D0)
        Bandwidth (bits per sec) (4 bytes): 65536 bps (0x10000)
        Max number of hops (2 bytes): unlimited (0xFFFF)
        Request flags (2 bytes): none set (0x0)
        URL: rtsp://server.content.com/coolmovie?stream=3\0
    
R->C  SCP Stream Control Channel (1026)
        Flags: PUSH (0x8)
        ID: 0
        Length: 32 (0x20)
      RTSP Stream Header Message:
        Tag (4 bytes): 2001 STREAM_HEADER (0x7D1)
        Generic Type (4 bytes): Audio (0x1)
        Bandwidth (bits per sec) (4 bytes): 65536 bps (0x10000)
        Last Modification Time (4 bytes): Feb 16 1996 13:38:45 (0x312488E5) 
        Reserved (4 bytes): 0x0
        Length (4 bytes): 22 minutes (1320000 ms) (0x142440)
        Max Packet Size (4 bytes): 120 bytes (0x78)
        Flags (4 bytes): (0x4E)
           Unicast available: True
           Live: False
           Copy: False
           Cache: True
           Client-Cache: True
           UDP-okay: True
           Multicast: False

C->R  SCP Stream Control Channel (1026)
        Flags: PUSH (0x8)
        ID: 0
        Length: 16 (0x10)
      RTSP Set Transport Message:
        Tag (4 bytes): 2002 SET_TRANSPORT (0x7D2)
	Flags (2 bytes): (0x8000)
	   C Flag: Compressed Headers On
        Channel ID (2 bytes): Unicast UDP (0x0)
        SSRC identifier (4 bytes): (0x0)
        Port (4 bytes): 7820 (0x1E8C)

R->C  SCP Stream Control Channel (1026)
        Flags: PUSH (0x8)
        ID: 0
        Length: 20 (0x14)
      RTSP Param Reply Message:
        Tag (4 bytes): 4001 PARAM_REPLY (0xFA1)
	Request ID (4 bytes): Not specifically requested (0x0)
        Family ID (4 bytes): Video (0x2)
        Parameter ID (4 bytes): Format Descriptor (0x1)
	Data Type (4 bytes): Opaque (0x2)
      Video Format Descriptor:
        (unspecified in current specificiation)

Setup is finished, so the client starts the stream:

C->R  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 12 (0xC)
      RTSP Play Range Message:
        Tag (4 bytes): 2004 PLAY_RANGE (0x7D4)
        From (4 bytes): Beginning (0x0)
        To (4 bytes) : End (0x0)

C->R  SCP Stream Control Channel (1026)
        Flags: PUSH (0x8)
        ID: 0
        Length: 12 (0xC)
      RTSP Play Range Message:
        Tag (4 bytes): 2004 PLAY_RANGE (0x7D4)
        From (4 bytes): Beginning (0x0)
        To (4 bytes) : End (0x0)

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 12 (0xC)
      RTSP Stream Sync Message:
        Tag (4 bytes): 2005 STREAM_SYNC (0x7D5)
        Sequence Number (2 bytes): Random value (0x34A2)
        Reserved (2 bytes): 0x0
        Start Time (4 bytes): Beginning (0x0)

R->C  SCP Stream Control Channel (1026)
        Flags: PUSH (0x8)
        ID: 0
        Length: 12 (0xC)
      RTSP Stream Sync Message:
        Tag (4 bytes): 2005 STREAM_SYNC (0x7D5)
        Sequence Number (2 bytes): Random value (0xC655)
        Reserved (2 bytes): 0x0
        Start Time (4 bytes): Beginning (0x0)

In this example, the timestamps are not included.  The timestamps may
be derived from knowing the samples per second and the start time.

R->C  UDP Packet
        Version (1 bit): Compressed (0x0)
        Marker (1 bit): On (0x1)
        timestamp lower bits compression bit (1 bit): don't include (0x0)
        sequence number inclusion bit (1 bit): include (0x1)
        SSRC: (0x0)
        sequence number (2 bytes): (0x34A2)

R->C  UDP Packet
        Version (1 bit): Compressed (0x0)
        Marker (1 bit): On (0x1)
        timestamp lower bits compression bit (1 bit): don't include (0x0)
        sequence number inclusion bit (1 bit): include (0x1)
        SSRC: (0x1)
        sequence number (2 bytes): (0xC655)

R->C  UDP Packet
        Version (1 bit): Compressed (0x0)
        Marker (1 bit): On (0x1)
        timestamp lower bits compression bit (1 bit): don't include (0x0)
        sequence number inclusion bit (1 bit): include (0x1)
        SSRC: (0x0)
        sequence number (2 bytes): (0x34A3)

R->C  UDP Packet
        Version (1 bit): Compressed (0x0)
        Marker (1 bit): On (0x1)
        timestamp lower bits compression bit (1 bit): don't include (0x0)
        sequence number inclusion bit (1 bit): include (0x1)
        SSRC: (0x1)
        sequence number (2 bytes): (0xC656)
...

=========================================
This second example is of a client joining an already existing
multicast.

C->W: GET coolbroadcast HTTP/1.0
      Accept: application/sdf; application/sdp

W->C: 200 OK
      Content-type: application/sdf

      [A yet-to be described file format which conveys the following
      information:

           A 16kbps English audio clip using algorithm X can be found
           at the following URL:
             rtsp://server.content.com/coolbroadcast?stream=1
      ]

Hmm...this time there is only one stream.  We'll take it.

[Note: I'm using SCP as it is defined in Appendix A of the initial
RTSP draft.  This is not consistant with the SCP specification, but
will be in later drafts.]

C->R: SCP Global Control Channel (0)
        Flags: SYN and PUSH (0x9)
        ID: 0
        Length: 30 (0x1E)
      RTSP Hello Message
        Tag (4 bytes): 1000 HELLO (0x3E8) 
        Major/Minor Version (2 bytes): 1.0 (0x0100)
        Subprotocol (1 byte) (0x1)
        Reserved (1 byte) (0x0)
        User Agent (null terminated): RTSP 1.0 Client/Win95\0

R->C  SCP Global Control Channel (0)
        Flags: PUSH (0x8)
        ID: 0
        Length: 30 (0x1E)
      RTSP Hello Message
        Tag (4 bytes): 1000 HELLO (0x3E8)
        Major/Minor Version (2 bytes): 1.0 (0x0100)
        Subprotocol (1 byte) (0x1)
        Reserved (1 byte) (0x0)
        User Agent (null terminated): RTSP 1.0 Server/Linux\0

This time, the user is forced to undergo server authentication.  (Note
that this authentication is currently undocumented.  This scheme is
only a strawman.):

R->C  SCP Global Control Channel (0)
        Flags: PUSH (0x8)
        ID: 0
        Length: 30 (0x1E)
      RTSP ID Message
        Tag (4 bytes): 1001 ID (0x3E9)
	Key type (2 bytes): Basic (0x0)
	Reserved (2 bytes): (0x0)
        Authentication key (0 bytes): None

C->R  SCP Global Control Channel (0)
        Flags: PUSH (0x8)
        ID: 0
        Length: 30 (0x1E)
      RTSP ID Response Message
        Tag (4 bytes): 1002 ID_RESP (0x3E9)
	Key type (2 bytes): Basic (0x0)
	Reserved (2 bytes): (0x0)
        Response data (16 bytes): foouser\0barpass\0

Now the client opens up a control channel to control the audio stream,
and sets that stream up:

C->R  SCP Stream Control Channel (1024)
        Flags: SYN and PUSH (0x9)	
        ID: 0
        Length: 57 (0x39)
      RTSP Fetch Message
        Tag (4 bytes): 2000 FETCH (0x7D0)
        Bandwidth (bits per sec) (4 bytes): 16384 bps (0x4000)
        Max number of hops (2 bytes): unlimited (0xFFFF)
        Request flags (2 bytes): none set (0x0)
        URL: rtsp://server.content.com/coolbroadcast?stream=1\0

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 32 (0x20)
      RTSP Stream Header Message:
        Tag (4 bytes): 2001 STREAM_HEADER (0x7D1)
        Generic Type (4 bytes): Audio (0x1)
        Bandwidth (bits per sec) (4 bytes): 16384 bps (0x4000)
        Last Modification Time (4 bytes): Feb 16 1996 13:38:45 (0x312488E5) 
        Reserved (4 bytes): 0x0
        Length (4 bytes): 22 minutes (1320000 ms) (0x142440)
        Max Packet Size (4 bytes): 120 bytes (0x78)
        Flags (4 bytes): (0x4E)
           Unicast available: True
           Live: False
           Copy: False
           Cache: True
           Client-Cache: True
           UDP-okay: True
           Multicast: False

Note that now the server sends the "Set Transport" message:

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 20 (0x10)
      RTSP Set Transport Message:
        Tag (4 bytes): 2002 SET_TRANSPORT (0x7D2)
	Flags (2 bytes): (0x8000)
	   C Flag: Compressed Headers On
        Channel ID (2 bytes): Multicast UDP (0x0)
        SSRC identifier (4 bytes): (0x9C9AE15E)
        Port (4 bytes): 6000 (0x1770)
        Address (4 bytes): 230.215.15.35 (0xE6D70F23)

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 48 (0x30)
      RTSP Param Reply Message:
        Tag (4 bytes): 4001 PARAM_REPLY (0xFA1)
	Request ID (4 bytes): Not specifically requested (0x0)
        Family ID (4 bytes): Audio (0x1)
        Parameter ID (4 bytes): Format Descriptor (0x1)
	Data Type (4 bytes): Opaque (0x2)
      Audio Format Descriptor:
        CODEC ID (4 bytes):  Fictional CODEC X (0xffffffff)
        NumChannels (2 bytes):  1 (0x1)
        Bits/Sample (2 bytes): 16 (0x10)
        Samples per second (4 bytes): 22050 hz (0xACFF)
        Average Frame Size (2 bytes): 64 bytes (0x40)
        Maximum Frame Size (2 bytes): 64 bytes (0x40)
        Samples per frame (4 bytes): 1378 (0x562)
        P (1 bit): Packetized audio (0x1)
        Frames per packet (15 bits): 1 (0x1)
	Extra bytes (2 bytes): none (0x0)
	Number of Frames (4 bytes): Indefinite (0x0)

R->C  SCP Stream Control Channel (1024)
        Flags: PUSH (0x8)
        ID: 0
        Length: 92 (0x5C)
      RTSP Param Reply Message:
        Tag (4 bytes): 4001 PARAM_REPLY (0xFA1)
	Request ID (4 bytes): Not specifically requested (0x0)
        Family ID (4 bytes): Audio (0x1)
        Parameter ID (4 bytes): Annotations (0x2)
	Data Type (4 bytes): Opaque (0x2)
      Audio Format Descriptor:
	Number of chunks (4 bytes): 3 (0x3)
        Chunk identifier (4 bytes): Name 'INAM' (0x494E414D)
	Number of bytes (4 bytes): 12 (0xC)
	Chunk data (12 bytes): "Cool Broadcast\0\0"
        Chunk identifier (4 bytes): Author 'IAUT' (0x49415554)
	Number of bytes (4 bytes): 18 (0x12)
	Chunk data (18 bytes): "Guy Frownee\0"
        Chunk identifier (4 bytes): Copyright 'ICOP' (0x49434F50)
	Number of bytes (4 bytes): 34 (0x22)
	Chunk data (34 bytes): "Copyright 1996 Cool Broadcast Company\0"

R))C  UDP Packet
        Version (2 bits): Standard v2 RTP (0x10)
        Padding (1 bit): False (0x0)
        Extension (1 bit): None (0x0)
	CSRC Count (CC) (4 bits): None (0x0)
	Marker (1 bit): True (0x1)
	Payload type (7 bits): Type "X" (0x60)
        Sequence Number (2 bytes): (0x5F68)
	Timestamp (4 bytes): (0x7C224486)
	Data (64 bytes)

R))C  UDP Packet
        Version (2 bits): Standard v2 RTP (0x10)
        Padding (1 bit): False (0x0)
        Extension (1 bit): None (0x0)
	CSRC Count (CC) (4 bits): None (0x0)
	Marker (1 bit): True (0x1)
	Payload type (7 bits): Type "X" (0x60)
        Sequence Number (2 bytes): (0x5F69)
	Timestamp (4 bytes): (0x7C224487)
	Data (64 bytes)

R))C  UDP Packet
        Version (2 bits): Standard v2 RTP (0x10)
        Padding (1 bit): False (0x0)
        Extension (1 bit): None (0x0)
	CSRC Count (CC) (4 bits): None (0x0)
	Marker (1 bit): True (0x1)
	Payload type (7 bits): Type "X" (0x60)
        Sequence Number (2 bytes): (0x5F6A)
	Timestamp (4 bytes): (0x7C224488)
	Data (64 bytes)

R))C  UDP Packet
        Version (2 bits): Standard v2 RTP (0x10)
        Padding (1 bit): False (0x0)
        Extension (1 bit): None (0x0)
	CSRC Count (CC) (4 bits): None (0x0)
	Marker (1 bit): True (0x1)
	Payload type (7 bits): Type "X" (0x60)
        Sequence Number (2 bytes): (0x5F6B)
	Timestamp (4 bytes): (0x7C224489)
	Data (64 bytes)