CS422
Lab 3: Implementing an Internet Telephone
Slides
PSO Notes on Voice Capture
Here is the Grading form. This
grading form is very similar to the one that will be used during the
presentation. However, the one used during the presentation could be
slightly different.
Also, notice that 20/100 points are reserved for code inspection.
Goal:
In this lab you will implement an Internet Telephone. You will use
Windows
Microsoft Visual Studio .NET and Windows. You may work on any of the
ITAP
PC labs that already have Visual Studio.This project will be done in
teams
of up to four people. You may decide to work individually or in teams
of two members but the same grading criteria will be applied to
everybody.
Recommended Reading:
Getting
Started with Visual C++
Windows
Sockets : How to use sockets in windows.
Download
DirectX SDK. This contains
the libraries and documentation you need for capture and playing sound.
DirectX/DirectSound:
Capturing and playing sounds in Windows
msdn.microsoft.com:
Other documentation you will need.
Download Visual
Studio Free for Purdue Students
Architecture:
The Internet phone system will consist of two programs:
- The Telephone Program that will be running in the
computer of
each
user using the phone.
- A Directory Server that will have the name and IP address
of
each
of the users. When the telephone program starts running, it will tell
the
directory server its own IP address and user name.
The telephone program will have the following subsystems:
- A Directory Client that will communicate with the Directory
Server
to add the user and IP address and to get the list of user names.
- A Ringer Server that will be waiting for incoming
communications
and will tell the user if there is an incoming communication. The
server
will keep the connection open until the telephone hangs up.
- A Ringer Client, that will contact the Ringer-Server
in
the
other end when the dial button is pressed.
- Voice Capture Client, that will capture voice from the
microphone
and it will send the voice stream to the Voice Player Server in the
other
end.
- A Voice Player Server, that will receive the voice stream
sent
by
the Voice Capture Client.
The protocol used by the Directory Server/Client, Ringer Server/Client
will be TCP to make the lookup and call start/end reliable. The Voice
Capture
Client and the Voice Player Server will use UDP since the voice samples
should arrive on time to be played on time and using TCP/IP may add
cumulative
delays in the voice due to the retransmission.
Step 1: Download and unzip the example-code
Download and unzip the file Internet-Phone.zip.
This file contains three examples:
- UDPTimeServer is a UDP time server that shows you how to
use UDP
sokets in Windows.
- UDPTimeClient: is a UDP time client that shows you how to
use UDP
sokets in Windows.
- Capture-Play is a program that shows you how to capture and play
sounds
in Windows using DirectX/DirectSound
Unzip this file and run your Microsoft Visual Studio .NET. Open the
UDPTimeServer,
build it and run it. Also Run another instance of Microsoft Visual
Studio
.NET. and open UDPTimeClient, and build (do not run it). These are
console
applications, that means that you can only run them from a command
prompt
as they do not have a GUI. The executable files will be in the Debug
directory.
To run the client, first run a command prompt ( Start->Run and type
"cmd")
and then cd into the directory UDPTImeClient/Debug. Then type
"UDPTimeClient
localhost". You may try these programs in different PCs.
Step 2 Creating the Basic GUI
Using the wizard in Visual Studio implement the initial GUI for the
phone
program. Select New->Project->MFC-APplication. In the application
name
field type "Internet Phone" and in the Location select the directory
where
you unzipped the files in step 1. In the Application type select Dialog
Base then select Finish.. That will create a new application. Try
playing
around with Visual Studio to be familiar with it.
The initial GUI will be dialog based and it will have the following
components:
- A list of all the users that are currently in the directory
server,.
You
will fill this list with the information in the directory server.
- A button to dial, answer, and hang up. If there is no call in
progress,
the button will show the dial label. If there is a call in progress,
the
button will show: "Hang-up". If there is an incoming call, it will
display
"Answer", otherwise it will showe "Dial".
- Also, there is a button "Profile" that will open another dialog
box to
update the name of the user and the address of the Directory Server.
Step 3 Implementing the Directory Server and Client
Implement the Directory Server. Create a Dialog-Based
application
that will have the list of current users and the IP addresses, and a
button
to exit. The server will keep in memory the list of pairs <name,
IP-address>
that will be added by the Directory Clients. Use TCP sockets
for
this server. The server will be waiting for incoming connections and
when
a request of the following form arrives:
ADD<crlf>
<Name><crlf>
<crlf>
it will register this entry in the Directory Server. The server will
return:
OK<crlf>
<crlf>
or
ERROR<crlf>
<Error message><cr><lf>
<crlf>
The IP address will be taken from the socket information
returned
by accept.
When a request of the form:
DELETE<crlf>
<crlf>
is received, the entry that corresponds to that IP address will be
removed.
The server will return:
OK<crlf>
<crlf>
or
ERROR<crlf>
<Error message><cr><lf>
<crlf>
To get all the user entries the client will send:
GET<crlf>
<crlf>
and the server will answer with the list of user/ip pairs
User1<crlf>
ip address 1<crlf>
User2<crlf>
ip address 2<crlf>
...
<crlf>
The end of the list will be delimited by an empty line.
Alernatively,
the server will reply:
ERROR<crlf>
<Error message><cr><lf>
<crlf>
The telephone program will send an ADD message when the telephone
program
starts.
It will also send a DELETE message when the telephone program exits.
Also, add the Directory client to the GUI from Step 2.
Turnin step 1-3 before March 9th 11:59pm. Zip all
the files and then copy the files
to one of the lab machines (Use sftp for example). Then type the turnin
command:
turnin -c cs422 -p lab3-1 Internet-Phone.zip
Step 4 Implementing the Ringer Server
Note: Try to finish this step before the deadline to continue with step
5. Step 5 may take more time to get it right.
Implement the Ringer Server and Ringer Client. The Ringer Server
will
be started when the phone program starts.
When the other side sends the request:
RING<crlf>
<name><crlf>
<call-number><crlf>
<Sampling-speed><crlf>
<crlf>
The server will replay with the following when the user clicks the
incoming-call
button:
PICKUP<crlf>
<name><crlf>
<call-number><crlf>
<Sampling-speed><crlf>
<crlf>
The <name> is the name of the user. <call-number> is the
number
of calls the user has made/received since the program started. The
sampling
speed used for capturing voice.
or if there is a call in progress:
BUSY<crlf>
<crlf>
or if there is an error:
ERROR<crlf>
<Error message><cr><lf>
<crlf>
The connection will be kept open until one of the parties decides to
hang up. If one of the parties decides to hangup it will send the
message:
HANGUP<crlf>
<crlf>
and then both close the connection.
Integrate the Ringer Server and Client in the phone program. The
Ringer
Server can be started in a different thread that is started when the
program
starts.
Turnin step 4 before March 30th before 11:59pm. Zip all
the files
and then copy the files
to one of the lab machines (Use sftp for example). Then type the turnin
command:
turnin -c cs422 -p lab3-2 Internet-Phone.zip
Step 5 Implementing the Voice Capture Client and the Voice Player Server
To understand capture and playback, read first DirectX/DirectSound.
Then, take a look at program Capture-Play given to you that plays what
is captured in the microphone. I recommend you to buy a
earphone/microphone
headset. You can get a good quality one for less than 20 dls.
Build and run the Capture-Play program from Visual Studio. Then
select
the capture and playing speed. You will hear what you speak with a
small
delay.
The heart of this program is a thread that reads from the capture
buffer
and writes to the play buffer.You will need to separate this thread
into
three. For the Voice Capture Client, when the call is started create a
thread that will wake up every time there is new data captured and it
will
send it to the other peer in a UDP datagram. The Voice Player server
will
have two threads: one thread receiving the UDP packets and copying the
voice to an intermediate data buffer (called jitter buffer) and another
thread that will wait until the play buffer needs more data and it will
copy the data from the intermediate buffer. At the beginning fill
the jitter buffer with the contents of two packets before starting
playing.
The format of the UDP packet will be the following:
unsigned long callNumber; // Call number from when the call started.
unsigned long sampleOffset; // Position in the stream of the first sample in the packet
unsigned long numberOfSamples; // Number of samples in the packet
unsigned short samples[700] // 700 samples of voice max.
The callNumber will be the call number used when the call started. The
sampleOffset is the position of the first sample in the packet in the
whole
stream. sampleOffset is used to play the sample on time. The
numberOfSamples
will be 700 most of the time except maybe at the end.
Use 8000Hz Mono for the capturing frequency. This frequency will
generate
about 12 UDP packets per second. You may try experimenting with other
speeds.
Also add in the dialog of the phone program the number of seconds
the call has used and the number of packets lost/delayed.
Step 6 Implementing Conference Calling
You will also implement a conference calling feature. When a call is
already in progress where A called B, another caller C will be able to
join the call. C will dial B's number, and instead of C getting a
busy signal, a dialog will be opened on B asking if C can join the
conversation. C will get a "dialing signal" while all this happens.
If B allows C to join in, C will be able to talk/listen to both A
and B and vice versa, otherwise C will get a busy signal. The number
of participants in the conference will be unlimited.
All callers in a conference call will have to call the host's number.
If another host D calls a caller like A or C, D will get always a busy
signal. A conference call will end when the host A hangs up or when
there are no more callers in the call.
Step 7 Other files you need to submit
Along with your step 5 and step 6, you also need to turn in the
following:
Create a README file with
a) The name of your teamates.
b) What required features in your project did not work.
c) List of extra features.
Also create a file named "TEAMMATES" with the login and names for
each team member. The login and the name should be separated by a colon
and one team member per line.
Example:
jsmith: John Smith
psellers: Peter Sellers
dmessing:Debra Messing
gclooney: George Clooney
Final Turnin
Turnin step 5, 6 and 7 before April 5th before
11:59pm.
Zip all
the files and then copy the files
to one of the lab machines (Use sftp for example). Then type the turnin
command:
turnin -c cs422 -p lab3-3 Internet-Phone.zip
You will present your project during the PSOs on April 6th. We
will post a schedule with the possible slots before that date.
Other things to do -- extra credit
You may decide to add some of the following features.
- Compute a silence threshold and do not send data during that
iunterval.
This will save bandwidth,.
- Add a ringing tone for incoming calls.
- Add busy tone
- Add picture of the caller
- Make dialog more flashy,
- Make the phone program a Windows Service
- Compatibility with the programs of other students.
- Use compression (You may use public domain libraries like zlib or
MP3)
- Adjust automatically the jitter buffer to minimize delay.
- Dead client timeout handling in directory service for clients
that
exited
ungracefully.
- Use XML in the communication among Directory Client/Server and
Ringer
Client/Server
- Optimize conference calling throughput by not having a
centralized host but by having other callers be distribution points.
- Videoconferencing.