Revision: 68614
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 26, 2015 21:50 by sacha-manji
Initial Code
using System; using Ozeki.Media.MediaHandlers; using Ozeki.Media.MediaHandlers.Video; using Ozeki.VoIP; using Ozeki.VoIP.SDK; 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 = "444"; var displayName = "444"; var authenticationId = "444"; var registerPassword = "444"; var domainHost = "192.168.115.25"; 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 = "333"; //call = softphone.CreateCallObject(phoneLine, numberToDial); var dialParams = new DialParameters("333"); dialParams.CallType = CallType.AudioVideo; call = softphone.CreateCallObject(phoneLine, dialParams); 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); } } }
Initial URL
http://www.voip-sip-sdk.com
Initial Description
While searching on the Internet on how to make SIP video calls using C#, I recognised that there aren’t any brief and straightforward tutorial in this topic. I found multi-page articles (sorry, but some of them are full of bullsh*t) and neverending forum threads, but none of them provided me complete solution. Therefore, I undertook to create a short and concise guide on how to make video calls in C# using the VoIP technology. Look at the prerequisites: - PBX: To be able to make and receive video calls you, a phone system (e.g. Asterisk) is essentially needed. You need to add a new SIP account in your PBX for this application. - Visual Studio: This solution is based on a console softphone, so a new Visual C# Console Application is just enough. - VoIPSDK.dll: I used prewritten VoIP components to implement the SIP video calling feature. The necessary .dll file can be found on this website: http://www.voip-sip-sdk.com/. It should be added to your references. - Test phone: To test your application you can use any VoIP phone stat supports video calling (e.g. Bria softphone). Now take a look at the code. As you can see below, just a few lines of C# code are enough to connect the application to a PBX and to initiate a video call. Firstly, you need to perform the SIP registration tasks. You need to create a softphone and a phone line object, then you need to specify the SIP account to be used for the phone line. These configurations are needed to be able to register to your PBX. After calling the RegisterPhoneLine method the regsitration procedure starts, and the application will indicates its status due to the mySoftphone_PhoneLineStateChanged method. The PhoneCallVideoSender and PhoneCallVideoReceiver objects are responsible for video handling. To handle the USB webcamera, the WebCamera object can be used. The CallType class is used to identify whether the call is a video or an audio call. To make a test call, provide valid SIP account details for this console application to be able to register to your PBX, then specify a telephone number to be dialled (it can be an other SIP account that has been previously registered to the PBX). After running the application, it dials the provided phone number automatically meanwhile sending the image of the webcamera.
Initial Title
How to make SIP video calls in C#
Initial Tags
video, code, free, Net, Development, c#
Initial Language
C#