The goal of this project is to implement a streaming video server and client that communicate using theReal Time Streaming Protocol(RTSP) and send data using the Real-time Transfer Protocol(RTP). Your task is to implement the RTSP protocol in the client and implement the RTP packetization in the server. We will provide you code that implements the RTSP protocol in the server, the RTP de-packetization in the client, and takes care of displaying the transmitted video.
Task1 Code Client,ClientLauncher The ClientLauncher starts the Client and the user interface which you use to send RTSP commands and which is used to display the video. In the Client class, you will need to implement the actions that are taken when the buttons are pressed. You do not need to modify the ClientLauncher module. ServerWorker, Server These two modules implement the server which responds to the RTSP requests and streams back the video. The RTSP interaction is already implemented and the ServerWorker calls methods from the RtpPacket class to packetize the video data. You do not need to modify these modules. RtpPacket This class is used to handle the RTP packets. It has separate methods for handling the received packets at the client side and you do not need to modify them. The Client also depacketizes (decodes) the data and you do not need to modify this method. You will need to complete the implementation of video data RTP-packetization (which is used by the server). Video Stream This class is used to read video data from the le on disk.
Task2 Running the code After completing the code, you can run it as follows: First, start the server with the command python Server.py server_port where server_port is the port your server listens to for incoming RTSP connections. The standard RTSP port is 554, but you will need to choose a port number greater than 1024. Then, start the client with the command 1 python ClientLauncher.py server_host server_port RTP_port video_file where server_host is the name of the machine where the server is running, server_port is the port where the server is listening on, RTP_port is the port where the RTP packets are received, and video_file is the name of the video le you want to request (we have provided one example le movie.Mjpeg). The le format is described in Appendix section. The client opens a connection to the server and pops up a window like this: You can send RTSP commands to the server by pressing the buttons. Anormal RTSP interaction goes as follows: 1. The client sends SETUP. This command is used to set up the session and transport parameters. 2. The client sends PLAY. This command starts the playback. 3. The client may send PAUSE if it wants to pause during playback. 4. The client sends TEARDOWN. This command terminates the session and closes the connection. The server always replies to all the messages that the client sends. The code200 means that the request was successful while the codes 404 and 500 represent FILE_NOT_FOUND error and connection error respectively. In this assignment, you do not need to implement any other reply codes. For more information about RTSP, please see RFC 2326. Task3 TheClient Your rst task is to implement the RTSP protocol on the client side. To do this, you need to complete the functions that are called when the user clicks on the buttons on the user interface. You will need to implement the actions for the following request types. When the client starts, it also opens the RTSP socket to the server. Use this socket for sending all RTSP requests. SETUP Send SETUP request to the server. You will need to insert the Transport header in which you specify the port for the RTP data socket you just created. Read the servers response and parse the Session header (from the response) to get the RTSP session ID. Create a datagram socket for receiving RTP data and set the timeout on the socket to 0.5 seconds. PLAY Send PLAY request. You must insert the Session header and use the session ID returned in the SETUP response. You must not put the Transport header in this request. Read the servers response. PAUSE SendPAUSErequest. You must insert the Session header and use the session ID returned in the SETUP response. You must not put the Transport header in this request. Read the servers response. TEARDOWN Send TEAR DOWN request. You must insert the Session header and use the session ID returned in the SETUP response. You must not put the Transport header in this request. Read the servers response. Note: You must insert the CSeq header in every request you send. The value of the CSeq header is a number which starts at 1 and is incremented by one for each request you send. Example Here is a sample interaction between the client and server. The clients requests are marked with C: and servers replies with S:. In this assignment both the client and the server do not use sophisticated parsing methods, and they expect the header elds to be in the order you see below.
1 C: SETUP movie.Mjpeg RTSP/1.0 2 C: CSeq:1 3 C: Transport: RTP/UDP; client_port=25000 4 5 S: RTSP/1.0200 OK 6 S: CSeq:1 7 S: Session:123456 8 9 C: PLAY movie.Mjpeg RTSP/1.0 10 C: CSeq:2 11 C: Session:123456 12 13 S: RTSP/1.0200 OK 14 S: CSeq:2 15 S: Session:123456 16 17 C: PAUSE movie.Mjpeg RTSP/1.0 18 C: CSeq:3 19 C: Session:123456 20 21 S: RTSP/1.0200 OK 22 S: CSeq:3 23 S: Session:123456 24 25 C: PLAY movie.Mjpeg RTSP/1.0 26 C: CSeq:4 27 C: Session:123456 28 29 S: RTSP/1.0200 OK 30 S: CSeq:4 31 S: Session:123456 32 33 C: TEARDOWN movie.Mjpeg RTSP/1.0 34 C: CSeq:5 35 C: Session:123456 36 37 S: RTSP/1.0200 OK 38 S: CSeq:5 39 S: Session:123456 Clientstate. One of the key differences between HTTP and RTSP is that in RTSP each session has a state. In this assignment you will need to keep the clients state up-to-date. Client changes state when it receives a reply from the server according to the following state diagram. Theserver. On the server side, you will need to implement the packetization of the video data into RTP packets. You will need to create the packet, set the elds in the packet header and copy the payload (i.e., one video frame) into the packet. WhentheserverreceivesthePLAY-request from the client,the server reads one video frame from the le and creates an RtpPacket-object which is the RTP-encapsulation of the videof rame. It then sends the frame to the client over UDP every 50 milliseconds. For the encapsulation, the server calls the encode function of the RtpPacket class. Your task is to write this function. You will need to do the following: (the letters in parenthesis refer to the elds in the RTP packet format below). Set the RTP-version eld (V). You must set this to 2. Set padding (P), extension (X), number of contributing sources (CC), and marker (M) elds. These are all set to zero in this assignment. Set payload type eld (PT). In this assignment we use MJPEG and the type for that is 26. Set the sequence number. The server gives this the sequence number as the frame Nbr argument to the encode function. Set the time stamp using the Pythons time module. Set the sourceidentier(SSRC).This eld identies the server. You can pick any integer value you like. Because we have no other contributing sources (eld CC == 0), the CSRC-eld does not exist. The length of the packet header is therefore 12 bytes, or the rst three lines from the diagram below. You must ll in the header elds in the header by the array of the RtpPacket class. You will also need to copy the payload (given as argument data) to the RtpPackets payload data eld. The above diagram is in the network byte order (also known as big-endian). Python uses the same byte order, so you do not need to transform your packet header into the network byte order. For more details on RTP, please see RFC 1889. Twiddling the Bits. Here are some examples on how to set and check individual bits or groups of bits. Note that in the RTP packet header format smaller bit-numbers refer to higher order bits, that is, bit number 0 of a byte is 27 and bit number 7 is 1 (or 20). In the examples below, the bit numbers refer to the numbers in the above diagram. Because the header-eld of the RtpPacket class is of type bytearray, you will need to set the header onebyteatatime,thatis,in groups of 8bits. The rst byte has bits 0-7,the second byte has bits 8-15, and so on. To set bit number n in variable my byte of type byte: 1 mybyte = mybyte | 1 << (7 n) To set bits n and n + 1 to the value of foo in variable mybyte: 1 mybyte = mybyte | foo << (7 n) Note that foo must have a value that can be expressed with 2 bits, that is, 0, 1, 2, or 3. To copy a 16-bit integer foo into 2 bytes, b1 and b2: 1 b1 = (foo 8) & 0xFF 2 b2 = foo & 0xFF After this, b1 will have the 8 high-order bits of foo and b2 will have the 8 low-order bits of foo. You can copy a 32-bit integer into 4 bytes in a similar way. Bit Example. Suppose we want to ll in the rst byte of the RTP packet header with the following values: V = 2 P = 0 X = 0 CC = 3 In binary this would be represented as 1 1 0 | 0 | 0 | 0 0 1 1 2 V=2 P X CC = 3 3 2^7 . . . . . . . . 2^0 Task4 AdditionalExercise 1. Calculate the statistics about the session. You will need to calculate RTP packet loss rate,video data rate (in bits or bytes per second), and any other interesting statistics that you can think of. 2. The user interface on the RTPClient has 4 buttons for the 4 actions. If you compare this to a standard media player, such as RealPlayer or Windows Media Player, you can see that they have only 3 buttons for the same actions: PLAY, PAUSE, and STOP (roughly corresponding to TEARDOWN). There is no SETUP button available to the user. Given that SETUP is mandatory in an RTSP-interaction, how would you implement that in a media player? When does the client send the SETUP? Come up with a solution and implement it. Also, is it appropriate to send TEARDOWN when the user clicks on the STOP button? 3. Currently, the client and server only implement the minimum necessary RTSP interactions and PAUSE. Implement the method DESCRIBE which is used to pass information about the media stream.
When the server receives a DESCRIBE-request, it sends back asession description le which tells the client what kinds of streams are in the session and what encodings are used. ProprietaryMJPEG(MotionJPEG)format. In this assignment,the server streams a video which has been encoded into aproprietary MJPEGle format. This format stores the video as concatenated JPEG-encoded images, with each image being preceded by a 5-Byte header which indicates the bit size of the image. The server parses the bitstream of the MJPEG le to extract the JPEG images on the y. The server sends the images to the client at periodic intervals. The client then displays the individual JPEG images as they arrive from the server.
Reviews
There are no reviews yet.