P. 1


|Views: 102|Likes:
Published by Shivangi Harit

More info:

Published by: Shivangi Harit on Apr 18, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Streaming Video Using RTP and RTSP



Submitted by:
Shivangi Harit (1238) M.Sc.(Informatics) 4th Sem Institute of Informatics & Communication UNIVERSITY OF DELHI ,SOUTH CAMPUS ( 2009- 11)

Streaming Video Using RTP and RTSP


This project has been a learning ground for all of us, not only in terms of learning new aspects of things we were already acknowledged with, not only in terms of learning new techniques of getting things done, but also in the terms of working as a team and working towards a common objective, and seeing it perform. We would like to take this opportunity to extend our heartfelt acknowledgements and regards, to our guide and coordinator, in this regard and others, Mr. Rajat Budhiraja, under whose guidance and mentoring, we were able to accomplish the task and the objectives, we initially began with. The project would not have been possible without the support provided to us, in terms of infrastructure, and other amenities, by the campus and its members. We would also like to thank them for the support and the faith, they invested in us. We also wish to express our delight, in working with our fine batch of classmates, with whom you can always find some light moments during the project.
We also wish to thank each other, for being so supportive a team member and seeing the project completed, in whatever objectives, that were envisioned in the very beginning.

Streaming Video Using RTP and RTSP



This is to certify that the project titled "Streaming Video Using RTP & RTSP" submitted by: Santanu Pal(1237) Shivangi Harit(1238) Shoikat Das(1239) Sumit Kr. Baberwal(1240) in partial fulfillment of the requirement of the degree of M. Sc. Informatics is a record of bona-fide work carried out by them under my supervision and guidance.

Dated April 8, 2011 Mr. Rajat Budhiraja Institute of Informatics & Communication
University of Delhi South Campus

7 5... Objective……………………………………... Database Requirements…………………….1.Streaming Video Using RTP and RTSP 4 TABLE OF CONTENTS 1.. Classes……………………………… 19 6. 21 6. 23 7. Abstract…………………………………….……… 14 6.. References………………………………….……………………. . Code…………………. 31 11.……… 61 13. List of Figures………………………………. State Diagram………………………………..2.……………………… 26 9. 7 4..65 16. 6 3. 5 2.. Designing Modules………………………... Future Scope…………. Protocols Implemented..64 15. .. Client……………………………….. Requirements………………………………. Screenshots……………………………… 62 14. FCAPS……………………………… . Conclusions……………………………….. 13 6. List of Abbreviations……………………….. Server……………………………….66 . How we implemented FCAPS………. 25 8.…………………..3. . 58 12. Data Flow Diagrams.4. 30 10.. 8 6.

using java . we will implement a streaming video server and client that communicate using the Real-Time Streaming Protocol (RTSP) and send data using the Real-time Transfer Protocol (RTP). OBJECTIVE In this project. The client can view the database videos actually transferring the data to his end. We are going to implement the RTSP protocol in the client and implement the RTP packetization in the server.Streaming Video Using RTP and RTSP 5 1. . we are developing a STREAMING VIDEO SERVER AND CLIENT which would help user to view videos without actually downloading it to user-end.

The server streams a video which has been encoded into a proprietary MJPEG file format.Streaming Video Using RTP and RTSP 6 2. The client then displays the individual JPEG images as they arrive from the server. ABSTRACT In this project. We are going to implement the RTSP protocol in the client and implement the RTP packetization in the server. . we will implement a streaming video server and client that communicate using the Real-Time Streaming Protocol (RTSP) and send data using the Real-time Transfer Protocol (RTP). The server parses the bit stream of the MJPEG file to extract the JPEG images on the fly. with each image being preceded by a 5Byte header which indicates the bit size of the image. using Java. This format stores the video as concatenated JPEG-encoded images. The server sends the images to the client at periodic intervals.

.U..: Graphical User Interface TCP: Transmission Control Protocol IP: Internet Protocol UDP: User Datagram Protocol SQL: Structure Query Language PT: Payload Type field SSRC: Synchronization Source (telephony..………………… Figure 5: Level 2 DFDs……….I..Time Streaming Protocol JPEG: Joint Photographic Experts Group MJPEG: Motion JPEG G. realtime control protocol) CSRC: Contributing Source .………………… Figure 6: State Diagram…………………………. Figure 2: Length of Packet Header……………… Figure 3: Level 0 DFD………. Figure 8: Description of Modules……………….... List of Figures Figure 1: Our Interface…………………………..………………… Figure 4: Level 1 DFD……….Streaming Video Using RTP and RTSP 7 3. 4. List of Abbreviations RTP: Real-time Transfer Protocol RTSP: Real. Figure 7: Modules and their relations…………….

In particular. unlike AWT. Hardware:  INTEL PENTIUM-IV Processor  At least 128 MB RAM  Microprocessor-486 or above 5. REQUIREMENTS 5. using AWT’s lightweight component support.2. (Graphical User Interface). Swing provides a native look and feel that emulates the look and feel of several platforms. Tools and Technology Used:  Swing (Java) Swing is a widget toolkit for Java. Swing is built on top of AWT and is entirely written in Java. 5. Software:  JAVA (jdk 1. Components from AWT and Swing can be mixed. Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit. The user has to just perform clicking events on the functionalities which he has to use. and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform. allowing you to add .U.1.3. It is part of Sun Microsystems' Java Foundation Classes (JFC) — an API for providing a graphical user interface (GUI) for Java programs.6)  MS Windows Platform  JAVA SWING 5.4. t he architecture of Swing components makes it easy to customize both their appearance and behavior.Streaming Video Using RTP and RTSP 8 5.I. User Interface: The user could interact with the software easily as it has very good G.

involves .Streaming Video Using RTP and RTSP 9 Swing support to existing AWT-based programs. network programming. You could subclass the existing Swing UI. textfields and scrollbars. For example. JButton and JCheckbox could be used in the same program with standard AWT labels. swing components such as JSlider. essentially identical to socket programming or client-server programming. Swing also has the ability to replace these objects on-the-fly. or change listener classes without having to reinvent the entire implementation. Anatomy of an Application GUI GUI Internal Structure • Socket Programming In computing. model.

The program or process initiating the communication is called a client process. first introduced in 1983. The client and server processes together form a distributed system. Most implementations are based on Berkeley sockets. or connectionless (based on UDP datagrams). Sockets are usually implemented by an API library such as Berkeley sockets. The communication between the client and server process may either be connection-oriented (such as an established TCP virtual circuit or session). These are examples of functions or methods typically provided by the API library: . such as the STREAMS-based Transport Layer Interface (TLI).Streaming Video Using RTP and RTSP 10 writing computer programs that communicate with other programs across a computer network. and the program waiting for the communication to be initiated is the server process. Other socket API implementations exist. for example Winsock introduced 1991.

or recvfrom() and sendto(). or write() and read().  accept() is used on the server side. describes a set of general design guidelines and implementations of specific networking protocols to enable computers to communicate over a network. and creates a new socket associated with the socket address pair of this connection. and allocates system resources to it. are used for sending and receiving data to/from a remote socket. routed and received at the destination. and causes a bound TCP socket to enter listening state. or Internet Protocol Suite.  connect() is used on the client side. and assigns a free local port number to a socket.  bind() is typically used on the server side. identified by an integer number. the connection is terminated. addressed. Protocols exist for a variety of different types of communication services between computers. it causes an attempt to establish a new TCP connection.  listen() is used on the server side. In case of TCP. i. transmitted.  send() and recv(). a specified local port number and IP address. TCP/IP provides end-to-end connectivity specifying how data should be formatted.  TCP/IP/UDP Networking The TCP/IP model. .e.Streaming Video Using RTP and RTSP 11  socket() creates a new socket of a certain socket type. It accepts a received incoming attempt to create a new TCP connection from the remote client. In case of a TCP socket. and associates a socket with a socket address structure.  close() causes the system to release resources allocated to a socket.

Other applications. it is a best effort. UDP is typically used for applications such as streaming media (audio. The appropriate transport protocol is chosen based on the higher-layer protocol application. or for simple query/response applications like DNS lookups. Reliability is addressed through error detection using a weak checksum algorithm. will guarantee reliable transfer. "unreliable" protocol. Like IP. can tolerate some loss of packets. For example. following are the four layers: Link Layer Internet Layer Transport Layer Application Layer User Datagram Protocol is a connectionless datagram protocol. the File Transfer Protocol expects a reliable connection. not transport. Voice over IP etc) where on-time arrival is more important than reliability. TCP and UDP are used to carry an assortment of higher-level applications. Real-time Transport Protocol (RTP) is a datagram protocol that is designed for real-time data such as streaming audio and video. The applications at any given network address are distinguished by their TCP or UDP port. video. where the overhead of setting up a reliable connection is disproportionately large. . but not the reordering or delay that could be caused by retransmission. Starting from the lowest level. but the Network File System (NFS) assumes that the subordinate Remote Procedure Call protocol.Streaming Video Using RTP and RTSP 12 TCP/IP is generally described as having four abstraction layers. By convention certain well known ports are associated with specific applications. such as VoIP.

CODE We will implement a streaming video server and client that communicate using the RealTime Streaming Protocol (RTSP) and send data using the Real-time Transfer Protocol (RTP). Back End: SQL 6. using Java.5.Streaming Video Using RTP and RTSP 13 Transport Service Requirements of Common Apps 5.6. Front End: Java (Programming Language) 5. .

or Session Initiation Protocol (SIP) signaling protocols. RTP (Real-Time Transport Protocol) Tool Used: Swing The Real-time Transport Protocol (RTP) defines a standardized packet format for delivering audio and video over the Internet. making it one of the technical foundations of the Voice over IP industry.323..Streaming Video Using RTP and RTSP 14 We will implement the RTSP protocol and RTSP de-packetization in the client and implement the RTSP protocol and RTP packetization in the server. RTP is usually used in conjunction with the RTP Control Protocol (RTCP). While RTP carries the media streams (e. Megaco. audio and video) or out-of-band events signaling (DTMF in separate payload type). RTP is used extensively in communication and entertainment systems that involve streaming media. PROTOCOLS IMPLEMENTED 6. video teleconference applications and web-based push to talk features.1. For these it carries media streams controlled by H. MGCP.1. 6. such as telephony.1. RTCP is used to monitor transmission statistics and quality . SCCP.g.

but may use other transport protocols (most notably. an RTP port should be even and the RTCP port is the next higher odd port number. which deals with the transfer of realtime multimedia data. The Real Time Control Protocol (RTCP) is used to specify Quality of Service (QOS) feedback and synchronization between the media streams. whereas RTCP uses the next higher odd port number. as the protocol design is transport independent. SCTP and DCCP) as well. For example. The bandwidth of RTCP traffic compared to RTP is small.1. sequence numbers (for packet loss detection) and the payload format which indicates the encoded format of the data.[9] The ports which form a session are negotiated using other protocols such as RTSP (using SDP in the setup method) and SIP. RTSP (Real Time Streaming Protocol) . typically around 5%. Information provided by this protocol include timestamps (for synchronization).  Protocol components The RTP specification describes two sub-protocols: The data transfer protocol. According to the specification. 6. enabling a receiver to deselect a particular stream. RTP is usually originated and received on even port numbers.Streaming Video Using RTP and RTSP 15 of service (QoS) information. audio and video streams will have separate RTP sessions. When both protocols are used in conjunction. A session consists of an IP address with a pair of ports for RTP and RTCP.  Sessions An RTP Session is established for each multimedia stream.1. RTP and RTCP typically use unprivileged UDP ports (1024 to 65535).

The transmission of streaming data itself is not a task of the RTSP protocol. to facilitate real-time control of playback of media files from the server. Most RTSP servers use the Real-time Transport Protocol (RTP) for media stream delivery. however some vendors implement proprietary transport protocols. such as play and pause. also features RealNetworks' proprietary RDT stream transport.Streaming Video Using RTP and RTSP 16 The Real Time Streaming Protocol (RTSP) is a network control protocol designed for use in entertainment and communications systems to control streaming media servers. for example.  Protocol directives . Clients of media servers issue VCR-like commands. The RTSP server from RealNetworks. The protocol is used to establish and control media sessions between end points.

The default port for the RTSP protocol is 554 for both UDP and TCP transports. In the typical case. This specifier typically includes a local port for receiving RTP data (audio or video). Some typical HTTP requests. although some exceptions exist where the server will send to the client. like the OPTIONS request. RTSP messages are sent from client to server. the presentation description lists the media streams controlled with the aggregate URL. no permanent TCP connection is required.. typically in Session Description Protocol (SDP) format. SETUP A SETUP request specifies how a single media stream must be transported. OPTIONS An OPTIONS request returns the request types the server will accept. A session identifier is used to keep track of sessions when needed. Presented here are the basic RTSP requests. and another for RTCP data (meta information). The server reply usually confirms the chosen parameters. and fills in the missing parts. While HTTP is stateless. This must be done before a PLAY request is sent. are also available. there is one media stream each for audio and video. RTSP is a stateful protocol. This reply includes the presentation description.).. such as the . but RTSP adds new requests. Among other things. The default transport layer port number is 554. The request contains the media stream URL and a transport specifier. DESCRIBE A DESCRIBE request includes an RTSP URL (rtsp://.Streaming Video Using RTP and RTSP 17 The RTSP protocol has similarities to HTTP. thus. and the type of reply data that can be handled.

PAUSE A PAUSE request temporarily halts one or all media streams. If no range is specified. The URL may be the aggregate URL (to play all media streams). A range can be specified. it is resumed at the point it was paused. The range parameter can be left out to pause immediately. Each media stream must be configured using SETUP before an aggregate play request may be sent. PLAY A PLAY request will cause one or all media streams to be played. Play requests can be stacked by sending multiple PLAY requests. if the stream is paused. When to pause can be specified with a range parameter. . RECORD The RECORD request can be used to send a stream to the server for storage. TEARDOWN A TEARDOWN request is used to terminate the session. The request contains an aggregate or media stream URL. It stops all media streams and frees all session related data on the server. or a single media stream URL (to play only that stream). the stream is played from the beginning and plays to the end. so it can later be resumed with a PLAY request. or.Streaming Video Using RTP and RTSP 18 server's chosen ports.

CLASSES Our code implements the RTSP protocol in the client as well as server and implements the RTP packetization in the server and .Streaming Video Using RTP and RTSP 19 Protocol stack for multimedia services 6.2.

1. The first constructor of this class implements RTP-packetization of the video data. RTPpacket 4. we implement the RTSP interaction and the server calls routines in the RTPpacket class to packetize the video data.Streaming Video Using RTP and RTSP 20 RTP de-packetization in the client. and Teardown) are pressed.4. The second constructor is used by the client to depacketize the data. There are 4 classes in our code.2. 6.2. 6. Server 3. we implement the actions that are taken when the buttons (Setup.2. Server This class implements the server which responds to the RTSP requests and streams back the video. VideoStream .2. Below is what the interface look like. Pause. Client 2.3. It has separate routines for handling the received packets at the client side.1. Play. 6. Client This class implements the client and the user interface which we use to send RTSP commands and which is used to display the video. Here. RTPpacket This class is used to handle the RTP packets. VideoStream 6. Here. using Java (Programming Language).2.

For each button in the interface there is a handler function in the code. SETUP  Create a socket for receiving RTP data and set the timeout on the socket to 5 milliseconds. PLAY  Send PLAY request. PAUSE  Send PAUSE request. We insert the Session header and use the session ID returned in the SETUP response. We do not put the Transport header in this request. CLIENT Our first task is to implement the RTSP on the client side. We need to insert the Transport header in which we specify the port for the RTP data socket we have created. We will implement the following actions in each handler function. We need to insert the Session header and use the session ID returned in the SETUP response. 6. .Streaming Video Using RTP and RTSP 21 This class is used to read video data from the file on disk. We do not put the Transport header in this request.3. This socket is used for sending all RTSP requests. When the client starts.  Read server's response. we will be defining the functions that are called when the user clicks on the buttons in the user interface. it also opens the RTSP socket to the server.  Read reply from server and parse the Session header in the response to get the session ID.  Send SETUP request to server. To do this.

any RTSP session identifier associated with the session is no longer valid.Streaming Video Using RTP and RTSP 22 • Read server's response. a SETUP request has to be issued before the session can be played again. It is appropriate to send TEARDOWN when user clicks on the stop-button.  Read server's response. freeing the resources associated with it. If the URI is the presentation URI for this presentation. Unless all transport parameters are defined by the session description. We insert the Session header and use the session ID returned in the SETUP response. TEARDOWN  Send TEARDOWN request. because The TEARDOWN request stops the stream delivery for the given URI. . We do not put the Transport header in this request.

SERVER On the server we will implement the packetization of the video data into RTP packets. . and copy the payload (i..e. For this we will creat the packet.Streaming Video Using RTP and RTSP 23 As per our designed code. one video frame) into the packet. 1 6. the interface will resemble the following. set the fields in the packet header.4. taking in account the general Windows display: Fig.

Streaming Video Using RTP and RTSP


When the server receives the PLAY-request from the client, it starts a timer which is triggered every 100 ms. At these times the server will read one video frame from the file and send it to the client. The server creates an RTPpacket-object which is the RTPencapsulation of the video frame. The server calls the first constructor of the class RTPpacket to perform the encapsulation. Following are the tasks at server’s end: (the letters in parenthesis refer to the fields in the RTP packet format below) 1. Set the RTP-version field (V). This will be set to 2. 2. Set padding (P), extension (X), number of contributing sources (CC), and marker (M) fields. These are all set to zero in our project. 3. Set payload type field (PT). In this project we use MJPEG and the type for that is 26. 4. Set the sequence number. The server gives this the sequence number as the Framenb argument to the constructor. 5. Set the timestamp. The server gives this number as the Time argument to the constructor. 6. Set the source identifier (SSRC). This field identifies the server. Any integer value can be taken.
Because we have no other contributing sources (field CC == 0), the CSRC-field does not exist. The length of the packet header is therefore 12 bytes, or the first three lines from the diagram below.

Streaming Video Using RTP and RTSP


Fig.2 The diagram is in the network byte order (also known as bigendian). The Java Virtual Machine uses the same byte order.

MJPEG (Motion JPEG) format files.

The server streams a video which has been encoded into a proprietary MJPEG file 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 file to extract the JPEG images on the fly. 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.

Streaming Video Using RTP and RTSP


8. DATA FLOW DIAGRAMS 8.1. Level 0

Fig. 3

2.Streaming Video Using RTP and RTSP 27 8. Level 1 Fig. 4 .

Streaming Video Using RTP and RTSP 28 8. Setup Fig.3. 5. Level 3 .

5. Play Fig.2 8. Pause Fig. 5.Streaming Video Using RTP and RTSP 29 .3.3.

4. Teardown Fig. 5.Streaming Video Using RTP and RTSP 30 8.4 9. STATE DIAGRAM Fig.3. 6 .

DESIGNING MODULES  Module 1: Client  Module 2: Server  Module 3: RTPpacket  Module 4: VideoStream 10.Streaming Video Using RTP and RTSP 31 10. 7 .1: Modules and their relations: Fig.

Streaming Video Using RTP and RTSP 32 Description of Modules: Module 1: Client .

3 .Streaming Video Using RTP and RTSP 33 Fig. 8. 8.1 Module 2: Server Fig.2 Module 3: RTPpacket Fig. 8.

awt.*.*. import java.*.Timer. import javax. .swing. 8. import java.io. public class Server extends JFrame implements ActionListener { DatagramSocket RTPsocket. DatagramPacket senddp.java import java.*. import java.swing. import java. int RTP_dest_port = 0.*.net. import javax.*. //Layout JLabel label.Streaming Video Using RTP and RTSP 34 Module 4: VideoStream Fig.event. InetAddress ClientIPAddr.awt.util.4 CODE:Server.

static int VIDEO_LENGTH = 500. timer. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { timer. static int MJPEG_TYPE = 26. final static String CRLF = "\r\n". timer = new Timer(FRAME_PERIOD. this). . Timer timer. static BufferedWriter RTSPBufferedWriter. static int RTSP_ID = 123456. final static int PAUSE = 5.setInitialDelay(0). static int FRAME_PERIOD = 100. final static int TEARDOWN = 6.setCoalesce(true). VideoStream video. public Server(){ super("Server"). final static int SETUP = 3. static String VideoFileName. byte[] buf. final static int PLAY = 4. timer. static int state. int RTSPSeqNb = 0. final static int INIT = 0. final static int READY = 1. static BufferedReader RTSPBufferedReader. Socket RTSPsocket. buf = new byte[15000].Streaming Video Using RTP and RTSP 35 int imagenb = 0.stop(). final static int PLAYING = 2.

pack().RTSPsocket. BorderLayout.add(label.CENTER). theServer. RTSPBufferedWriter = new BufferedWriter(new OutputStreamWriter(theServer. theServer. label = new JLabel("Send frame # ". boolean done = false.exit(0). } }. JLabel. ServerSocket listenSocket = new ServerSocket(RTSPport).setVisible(true).getOutputStream()) ). .RTSPsocket.parse_RTSP_request().RTSPsocket.ClientIPAddr = theServer. theServer. state = INIT. int RTSPport = 25000.getInputStream()) ). int request_type.CENTER). listenSocket. theServer.accept(). while(!done) { request_type = theServer. getContentPane(). } public static void main(String args[]) throws Exception { Server theServer = new Server().RTSPsocket = listenSocket.getInetAddress().close(). //blocking if (request_type == SETUP) { done = true. RTSPBufferedReader = new BufferedReader(new InputStreamReader(theServer.Streaming Video Using RTP and RTSP 36 System.

//blocking if ((request_type == PLAY) && (state == READY)) { theServer. . System.parse_RTSP_request().println("New RTSP state: READY"). state = READY. } else if ((request_type == PAUSE) && (state == PLAYING)) { theServer.send_RTSP_response().close(). theServer.out.stop(). theServer. theServer. state = PLAYING. System.RTPsocket = new DatagramSocket().stop().timer. theServer.send_RTSP_response(). theServer. theServer.Streaming Video Using RTP and RTSP 37 } } state = READY. System. while(true) { request_type = theServer. System.close().println("New RTSP state: PLAYING"). } else if (request_type == TEARDOWN) { theServer.println("New RTSP state: READY").send_RTSP_response().start().exit(0).RTPsocket.send_RTSP_response().timer.timer. theServer.RTSPsocket.out.video = new VideoStream(VideoFileName). theServer.out.

} catch(Exception ex) { System.getlength(). } } else { timer. image_length).stop(). buf.send(senddp). label. ClientIPAddr. RTP_dest_port). RTPsocket. rtp_packet. rtp_packet.exit(0).setText("Send frame #" + imagenb). imagenb*FRAME_PERIOD.out. RTPpacket rtp_packet = new RTPpacket(MJPEG_TYPE. System. byte[] packet_bits = new byte[packet_length].println("Exception caught: "+ex). imagenb. int packet_length = rtp_packet. senddp = new DatagramPacket(packet_bits. } } private int parse_RTSP_request() .printheader(). try { int image_length = video.getpacket(packet_bits). packet_length.getnextframe(buf).Streaming Video Using RTP and RTSP 38 } } } public void actionPerformed(ActionEvent e) { if (imagenb < VIDEO_LENGTH) { imagenb++.

else if ((new String(request_type_string)).nextToken()). System.nextToken().readLine().nextToken(). else if ((new String(request_type_string)).compareTo("SETUP") == 0) request_type = SETUP.compareTo("TEARDOWN") == 0) request_type = TEARDOWN. . String LastLine = RTSPBufferedReader. } String SeqNumLine = RTSPBufferedReader.readLine().Streaming Video Using RTP and RTSP 39 { int request_type = -1. System.println(SeqNumLine).out.compareTo("PLAY") == 0) request_type = PLAY.parseInt(tokens.readLine(). tokens.println(RequestLine). RTSPSeqNb = Integer. tokens = new StringTokenizer(SeqNumLine). else if ((new String(request_type_string)). try { String RequestLine = RTSPBufferedReader. if ((new String(request_type_string)). StringTokenizer tokens = new StringTokenizer(RequestLine).nextToken().compareTo("PAUSE") == 0) request_type = PAUSE.out. if (request_type == SETUP) { VideoFileName = tokens. String request_type_string = tokens.

//skip unused stuff RTP_dest_port = Integer.nextToken().nextToken()).println("Exception caught: "+ex).out.out. i<3.println("Exception caught: "+ex).} private void send_RTSP_response() { try{ RTSPBufferedWriter.println(LastLine). RTSPBufferedWriter. } } } .0 200 OK"+CRLF). RTSPBufferedWriter. if (request_type == SETUP) { tokens = new StringTokenizer(LastLine).out.flush().Streaming Video Using RTP and RTSP 40 System.exit(0). } return(request_type).write("Session: "+RTSP_ID+CRLF). RTSPBufferedWriter. } catch(Exception ex) { System. } } catch(Exception ex) { System. System. for (int i=0. System.exit(0).write("CSeq: "+RTSPSeqNb+CRLF).parseInt(tokens.write("RTSP/1. i++) tokens.

awt. import java. JLabel iconLabel = new JLabel(). import java.event. JPanel buttonPanel = new JPanel().*.*. JButton setupButton = new JButton("Setup"). JButton playButton = new JButton("Play").swing. import javax.java import java. . ImageIcon icon.awt. JButton tearButton = new JButton("Teardown").Timer.swing. JPanel mainPanel = new JPanel(). JButton pauseButton = new JButton("Pause"). public class Client{ JFrame f = new JFrame("Client").*.io.*. import java.*.Streaming Video Using RTP and RTSP 41 Client. import java. import javax.util.net.*.

Streaming Video Using RTP and RTSP 42 DatagramPacket rcvdp.setLayout(new GridLayout(1. byte[] buf.addActionListener(new setupButtonListener()).addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System. int RTSPSeqNb = 0. DatagramSocket RTPsocket. } }.addActionListener(new playButtonListener()). . int RTSPid = 0. static BufferedReader RTSPBufferedReader.add(playButton). final static int INIT = 0. final static int PLAYING = 2. Socket RTSPsocket. buttonPanel. buttonPanel. playButton. public Client() { f. Timer timer. final static String CRLF = "\r\n". static int RTP_RCV_PORT = 25000. static int MJPEG_TYPE = 26.add(tearButton). final static int READY = 1. static BufferedWriter RTSPBufferedWriter. static int state.add(pauseButton). static String VideoFileName.add(setupButton). buttonPanel.exit(0). buttonPanel. setupButton.0)). buttonPanel.

setBounds(0.50).getByName(ServerHost). . tearButton. iconLabel. buttonPanel. iconLabel. mainPanel. timer = new Timer(20.addActionListener(new pauseButtonListener()).setBounds(0.RTSPsocket. RTSP_server_port).add(mainPanel. timer.setInitialDelay(0). } public static void main(String argv[]) throws Exception { Client theClient = new Client().setVisible(true). buf = new byte[15000]. f. theClient.setLayout(null).380.370)).setCoalesce(true).280). String ServerHost = "127. mainPanel.setIcon(null). f.Mjpeg".getInputStream()) ).addActionListener(new tearButtonListener()). mainPanel.add(iconLabel).CENTER). int RTSP_server_port = 25000.add(buttonPanel). InetAddress ServerIPAddr = InetAddress. RTSPBufferedReader = new BufferedReader(new InputStreamReader(theClient.0.380.0.1". VideoFileName = "movie.setSize(new Dimension(390. BorderLayout.0.280.getContentPane(). f. timer. new timerListener()).RTSPsocket = new Socket(ServerIPAddr.Streaming Video Using RTP and RTSP 43 pauseButton.

System. if (parse_server_response() != 200) System. } class setupButtonListener implements ActionListener{ public void actionPerformed(ActionEvent e){ if (state == INIT) { try{ RTPsocket = new DatagramSocket(RTP_RCV_PORT). send_RTSP_request("SETUP").out.getOutputStream()) ). RTPsocket.setSoTimeout(5).println("New RTSP state: READY"). System.exit(0). } } } } class playButtonListener implements ActionListener { public void actionPerformed(ActionEvent e){ .out. } catch (SocketException se) { System.out.RTSPsocket.println("Socket exception: "+se).Streaming Video Using RTP and RTSP 44 RTSPBufferedWriter = new BufferedWriter(new OutputStreamWriter(theClient.println("Invalid Server Response"). else { state = READY. state = INIT. } RTSPSeqNb = 1.

if (state == PLAYING) { RTSPSeqNb++. else { state = PLAYING. timer. } } } } .println("New RTSP state: PLAYING"). timer. send_RTSP_request("PLAY").out.Streaming Video Using RTP and RTSP 45 if (state == READY) { RTSPSeqNb++.out.println("New RTSP state: READY"). send_RTSP_request("PAUSE"). if (parse_server_response() != 200) System. } } } } class pauseButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { System. else { state = READY.out.println("Pause Button pressed !"). System.stop(). if (parse_server_response() != 200) System.out.println("Invalid Server Response").start().out.println("Invalid Server Response"). System.

packet with SeqNum # TimeStamp of type ms.gettimestamp()+" "+rtp_packet.out. buf.getpayload_length(). send_RTSP_request("TEARDOWN"). if (parse_server_response() != 200) System. try{ RTPsocket.length). int payload_length = rtp_packet.println("New RTSP state: INIT").getpayload(payload). } } } class timerListener implements ActionListener { public void actionPerformed(ActionEvent e) { rcvdp = new DatagramPacket(buf.getLength()).out.stop(). rtp_packet.receive(rcvd p). RTPpacket rtp_packet = new RTPpacket(rcvdp.getData(). else { state = INIT.getpayloadtype()).println("Invalid Server Response"). rcvdp. . System. byte [] payload = new byte[payload_length].exit(0).println("Got RTP "+rtp_packet.out. timer.Streaming Video Using RTP and RTSP 46 class tearButtonListener implements ActionListener { public void actionPerformed(ActionEvent e){ RTSPSeqNb++.getsequencenumber()+" "+rtp_packet. System. System. rtp_packet.printheader().

readLine(). icon = new ImageIcon(image).nextToken()).getDefaultToolkit(). tokens = new StringTokenizer(SessionLine).Streaming Video Using RTP and RTSP 47 Toolkit toolkit = Toolkit. System.println("RTSP Client . System.println(SessionLine).out.out. String SessionLine = RTSPBufferedReader. System.readLine().out. iconLabel.createImage(payload.println(StatusLine). System. tokens.out. } catch (InterruptedIOException iioe){ } catch (IOException ioe) { System.Received from Server:").out.parseInt(tokens. .readLine().nextToken().println(SeqNumLine). Image image = toolkit. payload_length). if (reply_code == 200) { String SeqNumLine = RTSPBufferedReader. StringTokenizer tokens = new StringTokenizer(StatusLine). 0.setIcon(icon).println("Exception caught: "+ioe). try{ String StatusLine = RTSPBufferedReader. } } } private int parse_server_response() { int reply_code = 0. reply_code = Integer.

write("Session: "+RTSPid+"\n").0"+CRLF).exit(0). if ((new String(request_type)). } catch(Exception ex) { System.parseInt(tokens. } private void send_RTSP_request(String request_type) { try{ RTSPBufferedWriter.println("Exception caught : "+ex).flush(). RTSPBufferedWriter. System. } return(reply_code).write("CSeq: "+RTSPSeqNb+CRLF). } } } .compareTo("SETUP") == 0) RTSPBufferedWriter.out. //skip over the Session: RTSPid = Integer.nextToken().write("Transport: RTP/UDP.out.println("Exception caught : "+ex). } catch(Exception ex) { System. client_port= "+RTP_RCV_PORT+CRLF).exit(0). System.nextToken()). RTSPBufferedWriter. else RTSPBufferedWriter.write(request_type +" "+VideoFileName+" RTSP/1.Streaming Video Using RTP and RTSP 48 } tokens.

public int Version. public int PayloadType. public int Ssrc.Streaming Video Using RTP and RTSP 49 RTPpacket. public byte[] payload. public int Extension. public int Marker.java:public class RTPpacket{ static int HEADER_SIZE = 12. public int CC. public byte[] header. public int Padding. . public int TimeStamp. public int SequenceNumber. public int payload_size.

CC = 0. i < 4. int data_length){ Version = 2. byte[] data. header[0] = new Integer((Version<<6)|(Padding<<5)| (Extension<<4)|CC).Streaming Video Using RTP and RTSP 50 public RTPpacket(int PType. payload = new byte[data_length]. PayloadType = PType. Padding = 0. i++) header[11-i] = new Integer(Ssrc>>(8*i)). header[1] = new Integer((Marker<<7)| PayloadType). header[3] = new Integer(SequenceNumber).byteValue().byteValue(). for (int i=0. int Time. Marker = 0. .byteValue(). SequenceNumber = Framenb. int Framenb. TimeStamp = Time. i < 4. header = new byte[HEADER_SIZE]. i++) header[7-i] = new Integer(TimeStamp>>(8*i)). int packet_size) { Version = 2.byteValue(). Ssrc = 0. i++) payload[i] = data[i]. Extension = 0. payload_size = data_length.byteValu e().byteValue(). } public RTPpacket(byte[] packet. i < data_length. header[2] = new Integer(SequenceNumber>>8). for (int i=0. for (int i=0.

Streaming Video Using RTP and RTSP 51 Padding = 0. return(payload_size). i < payload_size. PayloadType = header[1] & 127. payload = new byte[payload_size]. i++) payload[i-HEADER_SIZE] = packet[i]. if (packet_size >= HEADER_SIZE) { header = new byte[HEADER_SIZE]. for (int i=HEADER_SIZE. } public int getpayload_length() { return(payload_size). i < packet_size. Marker = 0.HEADER_SIZE. i+ +) data[i] = payload[i]. Ssrc = 0. TimeStamp = unsigned_int(header[7]) + 256*unsigned_int(header[6]) + 65536*unsigned_int(header[5]) + 16777216*unsigned_int(header[4]). payload_size = packet_size . Extension = 0. } . CC = 0. for (int i=0. } } public int getpayload(byte[] data) { for (int i=0. i < HEADER_SIZE. SequenceNumber = unsigned_int(header[3]) + 256*unsigned_int(header[2]). i++) header[i] = packet[i].

} public int getpacket(byte[] packet) { for (int i=0. i+ +) packet[i] = header[i]. i < (HEADER_SIZE-4). } public int getpayloadtype() { return(PayloadType). .out. for (int i=0. j>=0 .Streaming Video Using RTP and RTSP 52 public int getlength() { return(payload_size + HEADER_SIZE). } public void printheader() { //TO DO : uncomment /* for (int i=0. j--) if (((1<<j) & header[i] ) != 0) System. i < HEADER_SIZE. i++) packet[i+HEADER_SIZE] = payload[i].print("1"). i++) { for (int j = 7. i < payload_size. return(payload_size + HEADER_SIZE). } public int getsequencenumber() { return(SequenceNumber). } public int gettimestamp() { return(TimeStamp).

length_string = new String(frame_length).print(" "). public class VideoStream { FileInputStream fis.out. int frame_nb.out. String length_string.print("0"). } } VideoStream.*. } public int getnextframe(byte[] frame) throws Exception { int length = 0.parseInt(length_string). byte[] frame_length = new byte[5]. System. */ } static int unsigned_int(int nb) { if (nb >= 0) return(nb). length = Integer. } System. public VideoStream(String filename) throws Exception{ fis = new FileInputStream(filename).0. . frame_nb = 0. else return(256+nb).println().5).out.java:import java.Streaming Video Using RTP and RTSP 53 else System.read(frame_length. fis.io.

*. . import java.read(frame. public GUI() { valid = false . JButton sign_in. panel. } } GUI.awt.awt.*. import java.length)). JTextField text.*.0. import java. import java.sql. JPasswordField passwd2.*.swing.setOpaque( false ).net.util. panel.*.io. import java.java:import javax.*.setPreferredSize( new Dimension() ).Streaming Video Using RTP and RTSP 54 return(fis. import java. JPanel panel = new JPanel(). static boolean valid . public class GUI implements ActionListener{ JFrame frame1.*.event.

addActionListener(this). label2.getContentPane().25)). sign_in. passwd2. label1. text = new JTextField().19)). Container cp = frame1. label1.500.BLUE). passwd2 = new JPasswordField(). label1. Font.350. cp.add(label2).PLAIN. //text1.setForeground(Color.setSize(550.setFont(new Font("Algerian".30).setLayout(null). label2.setFont(new Font("Algerian".setForeground(Color. // change color panel. text. sign_in = new JButton("sign_in").190.add(text).200. //button1.setBounds(290.setForeground(Color.add(label1).setBounds(140.310.600). .375.22)).PLAIN. frame1. panel.setBounds(140.BLUE).Streaming Video Using RTP and RTSP 55 frame1 = new JFrame("Welcome To Create a New Account"). panel. sign_in.175.add(sign_in).200.setForeground(Color.35).add(panel).30). Font.BLUE). label2.setFont(new Font("Algerian". panel.175. Font.200. JLabel label2 = new JLabel("password") .PLAIN. passwd2. frame1.setForeground(Color. //text1.80).BLUE).BLUE). JLabel label1 = new JLabel("user name") .add(passwd2).setBounds(280.30). panel.setResizable(false). panel.setBounds(280.

next()) { . frame1.jdbc.mysql. Class.setVisible(true).dispose().println(firstname). System.equals("")) { JOptionPane.out."Error message".passwrd="".query2.showMessageDialog(null.pass1.JOptionPane. frame1. String status = "".out.println(passwrd)."root".Streaming Video Using RTP and RTSP 56 frame1.equals("") ||passwrd.getConnection("jdbc:mysql://localhost:3306/ AVStreaming".EXIT_ON_CLOSE). con=DriverManager. while ( rs.Driver"). } Statement stmt1."root"). stmt1=con. String query1. Connection con = null. passwrd=passwd2.getText(). System. ResultSet rs = stmt1.getText().ERROR_MESSAGE).executeQuery("select DesiredLoginName.forName("com.name. firstname=text. if(firstname.createStatement().setDefaultCloseOperation(JFrame. } public void actionPerformed(ActionEvent e) { try{ String firstname=””. passwd FROM userinfo")."One or more fields were left empty".

showMessageDialog(null.ERROR_MESSAGE).dispose(). } }catch(Exception m){} } public static void main(String args[]){ GUI obj = new GUI(). } else{ JOptionPane. frame1.JOptionPane.equals(firstname) && pass1.out. pass1=rs. } } if(valid){ ":" + JOptionPane. name=rs. } } are .getString("DesiredLoginName"). if(name.println( rs.getString("passwd")."you authenticated".showMessageDialog(null.ERROR_MESSAGE).”authentication failure".getString("passwrd")).println("invalid user name name or passwd").getString("loginame") + rs. break.out."Error message". new Client()."Error message".equals(passwrd)){ valid = true .Streaming Video Using RTP and RTSP 57 //System. System.JOptionPane.

The goal of fault management is to recognize. and problems can be quickly identified and resolved. In non-billing organizations Accounting is sometimes replaced with Administration. as well as sub-networks or the whole network. the management categories into which the ISO model defines network management tasks. FCAPS FCAPS is the ISO Telecommunications Management Network model and framework for network management. They are also used to . or at least write a message to its console for a console server to catch and log/page.Streaming Video Using RTP and RTSP 58 11. The comprehensive management of an organization's information technology (IT) infrastructure is a fundamental requirement. Mean time to repair (MTTR) must be as short as possible to avoid system downtimes where a loss of revenue or lives is possible. FCAPS is an acronym for Fault. When a fault or event occurs. This can be established by monitoring different things for abnormal behavior. Employees and customers rely on IT services where availability and performance are mandated. Fault logs are one input used to compile statistics to determine the provided service level of individual network elements. Configuration. Fault management A fault is an event that has a negative significance. This notification is supposed to trigger manual or automatic activities. it uses trend analysis to predict errors so that the network is always available. For example. Security. Accounting. Furthermore. correct and log faults that occur in the network. Performance. isolate. a network component will often send a notification to the network operator using a proprietary or open protocol such as SNMP. the gathering of more data to identify the nature and severity of the problem or to bring backup equipment on-line.

 to simplify the configuration of the device  to track changes that are made to the configuration  to configure ('provision') circuits or paths through nonswitched networks Accounting management Accounting is often referred to as billing management. Configuration management The goals of configuration management include:  To gather and store configurations from network devices (this can be done locally or remotely). The goal is to gather usage statistics for users. Examples:    Disk usage Link utilization CPU time .Streaming Video Using RTP and RTSP 59 determine apparently fragile network components that require further attention. Using the statistics the users can be billed and usage quota can be enforced. which are basically used to isolate the fault in any telecom network. Fault Isolation tools like Delphi are also available.

The alarm would be handled by the normal fault management process . Performance management Performance management enables the manager to prepare the network for the future. Security management Security management is the process of controlling access to assets in the network.Streaming Video Using RTP and RTSP 60 For non-billed networks. The goals of administration are to administer the set of authorized users by establishing users. Trends can indicate capacity or reliability issues before they become service affecting. as well as to determine the efficiency of the current network. Authorization to it configured with OS and DBMS access control settings. the network health can be monitored. By collecting and analyzing performance data. passwords.Alarms vary depending upon the severity. The network performance addresses the throughput. "administration" replaces "accounting". percentage utilization. and permissions. This level of management will help reduce the possibility of sabotage or unauthorized access into the network by illegal users. and to administer the operations of the equipment such as by performing software backup and synchronization. for example. error rates and response time areas. This part involves the authentication and authorization of users as well as the encryption of data to protect the confidentiality of user information and rights. Performance thresholds can be set in order to trigger an alarm. in relation to the investments done to set it up. Data security can be achieved mainly with authentication and encryption. .

. a video can only be streamed by the user when he logins. Accounting We can determine which all person are using our server to stream the video from the list of names from database which we are maintaining. How we implemented FCAPS Security management in our project. then that persons login fails and that person is not authorized to see the video. Configuration Management In our project we can define the port at which the socket is to be formed.Streaming Video Using RTP and RTSP 61 12. Also we can define the server address at which the streaming is going on. If the user is not a eligible person. We can also define the videos which are to be made available for streaming.

SCREEN SHOTS .Streaming Video Using RTP and RTSP 62 13.

Streaming Video Using RTP and RTSP 63 .

and STOP (roughly corresponding to TEARDOWN). Implementation of a method DESCRIBE can be used to pass information about the media stream. When the server receives a DESCRIBE-request.Streaming Video Using RTP and RTSP 64 14. we can implement that in a media player in future. . There is no SETUP-button available to the user. it sends back a session description file which tells the client what kinds of streams are in the session and what encodings are used. PLAY. namely. Given that SETUP is mandatory in an RTSP interaction. allows only three actions.  Currently the client and server only implement the minimum necessary RTSP interactions and PAUSE. FUTURE SCOPE  The standard media player. PAUSE. such as RealPlayer or Windows Media Player.

providing there is an Internet connection nearby. this is similar to typical security cameras.Streaming Video Using RTP and RTSP 65 15. At first glance. The advantages of using a streaming server include detecting the client's connection speed so that video files of an appropriate bit rate are delivered. The video can be monitored from virtually anywhere in the world. This spares the end user the necessity of choosing between various formats. except that streaming technology does not need closed circuits. CONCLUSION Our project will make video and audio data sharing convenient and faster due to facility of streaming instead of (actually) downloading the video. . Live video streaming can also help monitor remote locations.

ietf.Streaming Video Using RTP and RTSP 66 16.htm  http://java.pdf PDF to Word . Fourth Edition PHI. IETF. Andrew S Tanenbaum. 1998  http://all-streaming-media. Real Time Streaming Protocol (RTSP).html http://tools.org/html/rfc2326 . Websiteshttp://java.sun.sun.com/developer/Books/jdbc/ch07.com/faq/streamingmedia/faqstreaming-media-protocols.com/docs/books/tutorial/networking/ov erview/networking. REFERENCES Books Computer Networks.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->