How to make a video call?

download Download:video-call.zip

This article is a detailed guide about making video calls in relation with Ozeki VoIP SIP SDK. To use this example, you need to have Ozeki VoIP SIP SDK installed, and a reference to ozeki.dll should be added to your visual studio project. It's also recommended to visit the How to make a Voice Call article before you begin to study how to perform Video calls.

making video calls
Figure 1 - Making video calls

What is video call, how does it work?

VoIP communication has extended functions that are not usually part of the ordinary telephoning system. One of these is the video phoning function that can be implemented in a VoIP application (Figure 1).

Video phoning uses the basis of the voice communication and extends it with some extra codec support and display methods. In case of a video communication not only audio but video data is also sent in a digitized and segmented form through the established phone line between the two VoIP clients. If both clients support video phoning, the users can talk to each other like they were in the same room.

How to make video call using C#?

The MediaHandler classes contain new media handlers for supporting video handling. As for the audio, the video support also has receiver and sender objects (PhoneCallVideoSender and PhoneCallVideoReceiver). For the sake of simplicity, this example is on the sending process only.

The basic peripheral device for the video is, of course, the web camera that also has its own model class in Ozeki VoIP SIP SDK (WebCamera).

After defining the basic tools, you need to know how you can use them for making video calls. It is really similar to the voice calls.

The call accept and start are done similar to the original softphones. In this case you can use the CallType class to identify if the call is actually a video or an audio call. It is possible to change the CallType during the call too.

Afterwards, if there is a camera connected to your computer, you should start that camera and connect to phoneCallVideoSender using the Connect method of the MediaConnector. In the end, you can connect the video of the camera with the help of the AttachToCall method of the phoneCallVideoSender.

Video call example in C#

using System;
using Ozeki.Media;
using Ozeki.VoIP;

namespace Video_call
{
    internal class Program
    {
        private static ISoftPhone softphone; // softphone object
        private static IPhoneLine phoneLine; // phoneline object
        private static IPhoneCall call;
        private static string numberToDial;
        private static MediaConnector mediaConnector;

        private static void Main(string[] args)
        {
            // Create a softphone object with RTP port range 5000-10000
            softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);

            // SIP account registration data, (supplied by your VoIP service provider)
            var registrationRequired = true;
            var userName = "sipusername";
            var displayName = "sipdisplayname";
            var authenticationId = "authenticationid";
            var registerPassword = "Password";
            var domainHost = "pbxip.voipprovider.com";
            var domainPort = 5060;

            var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);

            // Send SIP regitration request
            RegisterAccount(account);

            // Prevents the termination of the application
            Console.ReadLine();
        }

        static void RegisterAccount(SIPAccount account)
        {
            try
            {
                phoneLine = softphone.CreatePhoneLine(account);
                phoneLine.RegistrationStateChanged += sipAccount_RegStateChanged;
                softphone.RegisterPhoneLine(phoneLine);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during SIP registration: " + ex);
            }
        }

        private static void sipAccount_RegStateChanged(object sender, RegistrationStateChangedArgs e)
        {
            Console.WriteLine(e.State);
            if (e.State == RegState.RegistrationSucceeded)
                CreateCall();
        }

        static void CreateCall()
        {
            numberToDial = "1001";
            call = softphone.CreateCallObject(phoneLine, numberToDial);

            mediaConnector = new MediaConnector();
            var phoneCallVideoSender = new PhoneCallVideoSender();
            var cam = WebCamera.GetDefaultDevice();

            if (cam != null)
            {
                cam.Start();
                mediaConnector.Connect(cam, phoneCallVideoSender);
            }

            phoneCallVideoSender.AttachToCall(call);

            call.CallStateChanged += call_CallStateChanged;
            call.Start();
        }

        static void call_CallStateChanged(object sender, CallStateChangedArgs e)
        {
            Console.WriteLine("\nCall state: {0}.", e.State);
        }
    }  
}

Communication through the network

Making a video call is similar to voice calls. Codec information is being set at the INVITE SIP request.

Step 1: INVITE request with codec information is being sent via PBX (UDP message, Softphone -> PBX)

INVITE sip:1000@192.168.112.215 SIP/2.0
Via: SIP/2.0/UDP 192.168.112.215:20362;branch=z9hG4bK3306562f-ce06-4618-bdf3-
db62b7c25a89;rport
To: <sip:1000@192.168.112.215>
From: "1001"<sip:1001@192.168.112.215>;tag=pbijubat
CSeq: 2 INVITE
Call-ID: ouatpkwydurbfawquftcsnugbcnmembrcjsyeqjmjirvtqbdjn
Max-Forwards: 70
Contact: <sip:1001@192.168.112.215:20362>
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE
Content-Type: application/sdp
Proxy-Authorization:Digest username="1001",realm="OzekiPBX",
nonce="2f54d99f7bb3469394f3107760c3418a",response="33ca9363317e970cb864ff49ba531df1",
uri="sip:1000@192.168.112.215",algorithm=MD5
Content-Length: 591

v=0
o=- 1759144828 1759144828 IN IP4 192.168.112.215
s=Ozeki VoIP SIP SDK v10.1.8
c=IN IP4 192.168.112.215
t=0 0
m=audio 20253 RTP/AVP 8 0 3 101 9 104 98
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=rtpmap:9 G722/8000
a=fmtp:9 bitrate=64000
a=rtpmap:104 G726-16/8000
a=rtpmap:98 iLBC/8000
a=fmtp:98 mode=20
a=sendrecv
m=video 20067 RTP/AVP 34 102 99
a=rtpmap:34 H263/90000
a=fmtp:34 QCIF=1;CIF=1
a=rtpmap:102 H263-1998/90000
a=fmtp:102 QCIF=1;CIF=1
a=rtpmap:99 H264/90000
a=fmtp:99 packetization-mode=1
a=sendrecv

Step 2: A 100 Trying SIP message arrives through the PBX (UDP message, PBX -> Softphone)

SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.112.215:5060;branch=z9hG4bKc10803d2-33d9-49ab-9e45-
797114027b67;rport=5060;received=192.168.112.215
From: "1001"<sip:1001@192.168.112.215:5060>;tag=cafajhtj
Call-ID: vebcuubfbyarpmhrfqehipfxwfasqyqrincrklymfvmwtagepf
CSeq: 1 INVITE
To: "1000"<sip:1000@192.168.112.215:5060>
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Content-Length: 0

Step 3: With the 180 Ringing SIP message the called softphone's ringing is being indicated (UDP message, PBX -> Softphone)

SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 192.168.112.215:5060;branch=z9hG4bKc10803d2-33d9-49ab-9e45-
797114027b67;rport=5060;received=192.168.112.215
From: "1001"<sip:1001@192.168.112.215:5060>;tag=cafajhtj
Call-ID: vebcuubfbyarpmhrfqehipfxwfasqyqrincrklymfvmwtagepf
CSeq: 1 INVITE
To: "1000"<sip:1000@192.168.112.215:5060>;tag=hjkjrxnu
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Content-Length: 0
Contact: <sip:1000@192.168.112.215:20037>

Step 4: When the call is being accepted, the 200 OK sip message is being sent back with codec information (UDP message, PBX -> Softphone)

SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.112.215:20362;branch=z9hG4bK3306562f-ce06-4618-bdf3-
db62b7c25a89;rport=20362;received=192.168.112.215
From: "1001"<sip:1001@192.168.112.215>;tag=pbijubat
Call-ID: ouatpkwydurbfawquftcsnugbcnmembrcjsyeqjmjirvtqbdjn
CSeq: 2 INVITE
To: <sip:1000@192.168.112.215>;tag=setxvdef
User-Agent: Ozeki Phone System XE v5.3.1
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REGISTER, SUBSCRIBE, NOTIFY, REFER, 
INFO, MESSAGE
Content-Type: application/sdp
Content-Length: 496
Contact: <sip:1000@192.168.112.215:5060>

v=0
o=- 1796422525 763565987 IN IP4 192.168.112.215
s=Ozeki Call
c=IN IP4 192.168.112.215
t=0 0
m=audio 9662 RTP/AVP 8 0 3 101 9
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=rtpmap:9 G722/8000
a=fmtp:9 bitrate=64000
a=sendrecv
m=video 9249 RTP/AVP 34 102 99
a=rtpmap:34 H263/90000
a=fmtp:34 QCIF=1;CIF=1
a=rtpmap:102 H263-1998/90000
a=fmtp:102 QCIF=1;CIF=1
a=rtpmap:99 H264/90000
a=fmtp:99 packetization-mode=1
a=sendrecv

Step 5: The acknowledgement about the answered call is being sent back (UDP message, Softphone -> PBX)

ACK sip:1000@192.168.112.215:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.112.215:20362;branch=z9hG4bKe4f3737b-b452-4c5c-aed8-
fefa739708d8;rport
To: <sip:1000@192.168.112.215>;tag=setxvdef
From: "1001"<sip:1001@192.168.112.215>;tag=pbijubat
CSeq: 2 ACK
Call-ID: ouatpkwydurbfawquftcsnugbcnmembrcjsyeqjmjirvtqbdjn
Max-Forwards: 70
Contact: <sip:1001@192.168.112.215:20362>
User-Agent: Ozeki VoIP SIP SDK v10.1.8
Content-Length: 0

Step 6: The communication is done by sending and receiving RTP packages (a sample package)

[Stream setup by SDP (frame 28)]
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: ITU-T G.711 PCMU (0)
Sequence number: 7133
[Extended sequence number: 72669]
Timestamp: 85000
Synchronization Source identifier: 0x712f7356 (1898935126)
Payload: d55555545657545756565455575051575650515557515050...

Related Pages

More information