Professional Documents
Culture Documents
Submitted by:
ACKNOWLEDGEMENT
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 3
CERTIFICATE
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)
TABLE OF CONTENTS
1. Objective……………………………………. 5
2. Abstract…………………………………….. 6
3. List of Figures……………………………….. 7
4. List of Abbreviations……………………….. 7
5. Requirements……………………………….. 8
6. Code………………….……………………. 13
6.1. Protocols Implemented..........……… 14
6.2. Classes……………………………… 19
6.3. Client……………………………….. 21
6.4. Server………………………………. 23
7. Database Requirements……………………. 25
8. Data Flow Diagrams..……………………… 26
9. State Diagram………………………………. 30
10. Designing Modules………………………. 31
11. FCAPS……………………………… . . . . 58
12. How we implemented FCAPS……….……… 61
13. Screenshots……………………………… 62
14. Future Scope………….…………………...64
15. Conclusions………………………………..65
16. References………………………………….66
Streaming Video Using RTP and RTSP 5
1. OBJECTIVE
2. ABSTRACT
In this project, 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). We are going to implement the RTSP protocol in the client and
implement the RTP packetization in the server, using Java. 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 bit stream 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 7
3. List of Figures
4. List of Abbreviations
5. REQUIREMENTS
5.1. Hardware:
INTEL PENTIUM-IV Processor
At least 128 MB RAM
Microprocessor-486 or above
5.2. Software:
JAVA (jdk 1.6)
MS Windows Platform
JAVA SWING
• Socket Programming
In computing, network programming, essentially identical to socket programming
or client-server programming, involves
Streaming Video Using RTP and RTSP 10
TCP/IP/UDP Networking
The TCP/IP model, or Internet Protocol Suite, describes a set
of general design guidelines and implementations of specific
networking protocols to enable computers to communicate
over a network. TCP/IP provides end-to-end connectivity
specifying how data should be formatted, addressed,
transmitted, routed and received at the destination. Protocols
exist for a variety of different types of communication
services between computers.
Streaming Video Using RTP and RTSP 12
6. CODE
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), using Java.
Streaming Video Using RTP and RTSP 14
RTP is usually used in conjunction with the RTP Control Protocol (RTCP). While RTP
carries the media streams (e.g., audio and video) or out-of-band events signaling (DTMF
in separate payload type), RTCP is used to monitor transmission statistics and quality
Streaming Video Using RTP and RTSP 15
Protocol components
The data transfer protocol, which deals with the transfer of real-
time multimedia data. Information provided by this protocol
include timestamps (for synchronization), sequence numbers
(for packet loss detection) and the payload format which
indicates the encoded format of the data.
Sessions
Presented here are the basic RTSP requests. Some typical HTTP
requests, like the OPTIONS request, are also available. The
default transport layer port number is 554.
OPTIONS
SETUP
A SETUP request specifies how a single media stream must be transported. This must
be done before a PLAY request is sent. The request contains the media stream URL
and a transport specifier. This specifier typically includes a local port for receiving
RTP data (audio or video), and another for RTCP data (meta information). The server
reply usually confirms the chosen parameters, and fills in the missing parts, such as
the
Streaming Video Using RTP and RTSP 18
PAUSE
RECORD
A TEARDOWN request is used to terminate the session. It stops all media streams
and frees all session related data on the server.
Streaming Video Using RTP and RTSP 19
6.2. 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 20
1. Client
2. Server
3. RTPpacket
4. VideoStream
6.2.1. 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. Below is what the interface look like. Here, we implement
the actions that are taken when the buttons (Setup, Play, Pause, and
Teardown) are pressed.
6.2.2. Server
This class implements the server which responds to the RTSP
requests and streams back the video. Here, we implement the
RTSP interaction and the server calls routines in the RTPpacket
class to packetize the video data.
6.2.3. RTPpacket
This class is used to handle the RTP packets. It has separate
routines for handling the received packets at the client side. The
first constructor of this class implements RTP-packetization of the
video data. The second constructor is used by the client to de-
packetize the data.
6.2.4. VideoStream
Streaming Video Using RTP and RTSP 21
This class is used to read video data from the file on disk.
6.3. CLIENT
Our first task is to implement the RTSP on the client side. To do
this, we will be defining the functions that are called when the user
clicks on the buttons in the user interface. For each button in the
interface there is a handler function in the code. We will
implement the following actions in each handler function.
When the client starts, it also opens the RTSP socket to the server.
This socket is used for sending all RTSP requests.
SETUP
Create a socket for receiving RTP data and set the timeout on
the socket to 5 milliseconds.
Send SETUP request to server. We need to insert the
Transport header in which we specify the port for the RTP data
socket we have created.
Read reply from server and parse the Session header in the
response to get the session ID.
PLAY
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.
Streaming Video Using RTP and RTSP 22
TEARDOWN
Fig. 1
6.4. SERVER
On the server we will implement the packetization of the video data into RTP packets.
For this we will creat the packet, set the fields in the packet header, and copy the payload
(i.e., one video frame) into the packet.
Streaming Video Using RTP and RTSP 24
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 25
Fig.2
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 26
8.1. Level 0
Fig. 3
Streaming Video Using RTP and RTSP 27
8.2. Level 1
Fig. 4
Streaming Video Using RTP and RTSP 28
8.3. Level 3
8.3.1. Setup
Fig. 5.1
Streaming Video Using RTP and RTSP 29
8.3.2. Play
Fig. 5.2
8.3.3. Pause
Fig. 5.3
Streaming Video Using RTP and RTSP 30
8.3.4. Teardown
Fig. 5.4
9. STATE DIAGRAM
Fig. 6
Streaming Video Using RTP and RTSP 31
Module 1: Client
Module 2: Server
Module 3: RTPpacket
Module 4: VideoStream
Fig. 7
Streaming Video Using RTP and RTSP 32
Description of Modules:
Module 1: Client
Streaming Video Using RTP and RTSP 33
Fig. 8.1
Module 2: Server
Fig. 8.2
Module 3: RTPpacket
Fig. 8.3
Streaming Video Using RTP and RTSP 34
Module 4: VideoStream
Fig. 8.4
CODE:-
Server.java
import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
//Layout JLabel
label;
Streaming Video Using RTP and RTSP 35
int imagenb = 0;
VideoStream video;
static int MJPEG_TYPE = 26;
static int FRAME_PERIOD = 100;
static int VIDEO_LENGTH = 500;
Timer timer;
byte[] buf;
final static int INIT = 0;
final static int READY = 1;
final static int PLAYING = 2;
public Server(){
super("Server");
timer = new Timer(FRAME_PERIOD, this);
timer.setInitialDelay(0);
timer.setCoalesce(true);
buf = new byte[15000];
System.exit(0);
}
};
int request_type;
boolean done =
false; while(!done)
{
request_type = theServer.parse_RTSP_request(); //blocking
if (request_type == SETUP)
{
done = true;
Streaming Video Using RTP and RTSP 37
state = READY;
System.out.println("New RTSP state:
READY"); theServer.send_RTSP_response();
theServer.video = new VideoStream(VideoFileName);
theServer.RTPsocket = new DatagramSocket();
}
}
while(true)
{
request_type = theServer.parse_RTSP_request(); //blocking
theServer.send_RTSP_response();
theServer.timer.start();
state = PLAYING;
System.out.println("New RTSP state: PLAYING");
}
else if
((request_type == PAUSE) && (state == PLAYING))
{
theServer.send_RTSP_response();
theServer.timer.stop();
state = READY;
System.out.println("New RTSP state: READY");
}
else if (request_type == TEARDOWN)
{
theServer.send_RTSP_response();
theServer.timer.stop();
theServer.RTSPsocket.close();
theServer.RTPsocket.close(); System.exit(0);
Streaming Video Using RTP and RTSP 38
}
}
}
{
int request_type = -1;
try
{
String RequestLine = RTSPBufferedReader.readLine();
System.out.println(RequestLine);
StringTokenizer tokens = new
StringTokenizer(RequestLine);
String request_type_string = tokens.nextToken();
if ((new String(request_type_string)).compareTo("SETUP")
== 0)
request_type = SETUP;
else if ((new String(request_type_string)).compareTo("PLAY")
== 0)
request_type = PLAY;
else if ((new
String(request_type_string)).compareTo("PAUSE") == 0)
request_type = PAUSE;
else if ((new
String(request_type_string)).compareTo("TEARDOWN") == 0)
request_type = TEARDOWN;
if (request_type == SETUP)
{
VideoFileName = tokens.nextToken();
}
System.out.println(LastLine);
if (request_type == SETUP)
{
tokens = new StringTokenizer(LastLine);
for (int i=0; i<3; i++)
tokens.nextToken(); //skip unused stuff
RTP_dest_port = Integer.parseInt(tokens.nextToken());
}
}
catch(Exception ex)
{
System.out.println("Exception caught:
"+ex); System.exit(0);
}
return(request_type);}
Client.java import
java.io.*; import
java.net.*; import
java.util.*; import
java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
DatagramPacket rcvdp;
DatagramSocket RTPsocket;
static int RTP_RCV_PORT =
25000; Timer timer;
byte[] buf;
public Client() {
f.addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
pauseButton.addActionListener(new pauseButtonListener());
tearButton.addActionListener(new tearButtonListener());
iconLabel.setIcon(null);
mainPanel.setLayout(null);
mainPanel.add(iconLabel);
mainPanel.add(buttonPanel);
iconLabel.setBounds(0,0,380,280);
buttonPanel.setBounds(0,280,380,50);
f.getContentPane().add(mainPanel, BorderLayout.CENTER);
f.setSize(new Dimension(390,370));
f.setVisible(true);
if (state == INIT)
{
try{
RTPsocket = new DatagramSocket(RTP_RCV_PORT);
RTPsocket.setSoTimeout(5);
}
catch (SocketException se)
{
System.out.println("Socket exception: "+se);
System.exit(0);
}
RTSPSeqNb = 1;
send_RTSP_request("SETUP");
if (parse_server_response() != 200)
System.out.println("Invalid Server Response");
else
{
state = READY;
System.out.println("New RTSP state: READY");
}
}
}
}
if (state == READY)
{
RTSPSeqNb++;
send_RTSP_request("PLAY");
if (parse_server_response() != 200)
System.out.println("Invalid Server Response");
else
{
state = PLAYING;
System.out.println("New RTSP state:
PLAYING"); timer.start();
}
}
}
}
try{ RTPsocket.receive(rcvd
p);
RTPpacket rtp_packet = new RTPpacket(rcvdp.getData(),
rcvdp.getLength());
rtp_packet.printheader();
int payload_length = rtp_packet.getpayload_length(); byte [] payload
= new byte[payload_length]; rtp_packet.getpayload(payload);
Streaming Video Using RTP and RTSP 47
try{
String StatusLine = RTSPBufferedReader.readLine();
System.out.println("RTSP Client - Received from Server:");
System.out.println(StatusLine);
return(reply_code);
}
if ((new String(request_type)).compareTo("SETUP") == 0)
RTSPBufferedWriter.write("Transport: RTP/UDP;
client_port=
"+RTP_RCV_PORT+CRLF); else
RTSPBufferedWriter.write("Session: "+RTSPid+"\n");
RTSPBufferedWriter.flush();
}
catch(Exception ex)
{
System.out.println("Exception caught :
"+ex); System.exit(0);
}
}
}
Streaming Video Using RTP and RTSP 49
RTPpacket.java:-
Padding = 0;
Extension = 0;
CC = 0;
Marker = 0;
Ssrc = 0;
if (packet_size >= HEADER_SIZE)
{
header = new byte[HEADER_SIZE];
for (int i=0; i < HEADER_SIZE; i++)
header[i] = packet[i];
payload_size = packet_size - HEADER_SIZE;
payload = new byte[payload_size];
for (int i=HEADER_SIZE; i < packet_size; i++)
payload[i-HEADER_SIZE] = packet[i];
PayloadType = header[1] & 127;
SequenceNumber = unsigned_int(header[3]) +
256*unsigned_int(header[2]);
TimeStamp = unsigned_int(header[7]) +
256*unsigned_int(header[6]) + 65536*unsigned_int(header[5]) +
16777216*unsigned_int(header[4]);
}
}
return(payload_size);
}
else
System.out.print("0");
System.out.print(" ");
}
System.out.println();
*/
}
static int unsigned_int(int nb) {
if (nb >= 0)
return(nb);
else
return(256+nb);
}
}
VideoStream.java:-
import java.io.*;
return(fis.read(frame,0,length));
}
}
GUI.java:-
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.net.*;
public GUI() {
valid = false ;
JPanel panel = new JPanel(); panel.setOpaque( false );
panel.setPreferredSize( new Dimension() );
Streaming Video Using RTP and RTSP 55
frame1.setSize(550,600);
Streaming Video Using RTP and RTSP 56
frame1.setVisible(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if(firstname.equals("") ||passwrd.equals(""))
{
JOptionPane.showMessageDialog(null,"One or more fields were
left empty","Error message",JOptionPane.ERROR_MESSAGE);
frame1.dispose();
}
Statement stmt1;
Class.forName("com.mysql.jdbc.Driver");
Connection con = null;
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/
AVStreaming","root","root");
stmt1=con.createStatement();
String query1,query2,name,pass1;
ResultSet rs = stmt1.executeQuery("select DesiredLoginName,
passwd FROM userinfo");
while ( rs.next()) {
Streaming Video Using RTP and RTSP 57
if(valid){
JOptionPane.showMessageDialog(null,"you are
authenticated","Error
message",JOptionPane.ERROR_MESSAGE);
new Client();
frame1.dispose();
}
else{
JOptionPane.showMessageDialog(null,”authentication
failure","Error message",JOptionPane.ERROR_MESSAGE);
}
}catch(Exception m){}
}
public static void main(String args[]){
11. FCAPS
FCAPS is the ISO Telecommunications Management Network
model and framework for network management. FCAPS is an
acronym for Fault, Configuration, Accounting, Performance,
Security, the management categories into which the ISO model
defines network management tasks. In non-billing organizations
Accounting is sometimes replaced with Administration.
Fault management
Fault logs are one input used to compile statistics to determine the provided service
level of individual network elements, as well as sub-networks or the whole network.
They are also used to
Streaming Video Using RTP and RTSP 59
Fault Isolation tools like Delphi are also available, which are
basically used to isolate the fault in any telecom network.
Configuration management
Accounting management
Using the statistics the users can be billed and usage quota can
be enforced.
Examples:
Disk usage
Link utilization
CPU time
Streaming Video Using RTP and RTSP 60
Security management
Security management is the process of controlling access to assets in the network. Data
security can be achieved mainly with authentication and encryption. Authorization to it
configured with OS and DBMS access control settings. This level of management will
help reduce the possibility of sabotage or unauthorized access into the network by illegal
users. 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.
Streaming Video Using RTP and RTSP 61
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.
Streaming Video Using RTP and RTSP 62
15. CONCLUSION
Our project will make video and audio data sharing convenient and
faster due to facility of streaming instead of (actually)
downloading the video.
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. This spares the end user
the necessity of choosing between various formats.
Streaming Video Using RTP and RTSP 66
16. REFERENCES
Books-
Computer Networks, Andrew S Tanenbaum, Fourth
Edition PHI.
Websites-
http://java.sun.com/docs/books/tutorial/networking/ov
erview/networking.html
http://tools.ietf.org/html/rfc2326 , Real Time
Streaming Protocol (RTSP), IETF, 1998
http://all-streaming-media.com/faq/streaming-
media/faqstreaming-media-protocols.htm
http://java.sun.com/developer/Books/jdbc/ch07.pdf
PDF to Word