DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Trending

  • Finding Needles in Digital Haystacks: The Distributed Tracing Revolution
  • Toward Indigenous AI: A Critical Analysis of BharatGen’s Role in Data Sovereignty and Language Equity
  • The Bare Metal Bet That Made Our Multiplayer Platform Hum
  • Integrating Cursor and LLM for BDD Testing With Playwright MCP (Model Context Protocol)

How to make SIP video calls in C#

By 
Sacha Manji user avatar
Sacha Manji
·
Jan. 26, 15 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
8.3K Views

Join the DZone community and get the full member experience.

Join For Free

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: c# voip stack . 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.

test the program:

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.


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);
        }
    }  
}
Session Initiation Protocol

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: