High performance VoIP SDK for .Net developers

VoIP SIP SDK

Addressing video quality (resolutions, codecs)

Overview

Prerequisities

Download: 27_VideoSoftphone.zip

Ozeki VoIP SIP SDK gives you the opportunity to use various audio and video codecs in order to provide outstanding voice and video quality. This article will be a great help in identifying video quality issues and in finding the best solution to avoid them. You will also learn how to handle camera change or how to set the selected codecs when you use Ozeki VoIP SIP SDK.

Introduction

VoIP video communication is based on some background implementation of coder and decoder definitions called codecs. These standard tools are used for defining the digitization and digital to analog conversion methods for video data streams. The codecs also hold information about the compression of video data with saving the quality.


Figure 1 - Video codec support

The video quality is improving day by day and the video communication also requires more clear and smooth video and sound quality. This all depends on the codecs you use when implementing a VoIP solution.

Ozeki VoIP SIP SDK provides reliable support for several video codecs that can be used in video communication and also for capturing and replaying video phoning sessions.

The following program code uses the background support of Ozeki VoIP SIP SDK. You can download and install the SDK on your computer before starting to use the program code. You will also need to have Visual Studio 2010 or compatible IDE and .NET Framework installed on your system, as the program code below is written in C# language.

Graphical User Interface

The GUI of this videophone example is somewhat different from the one that is introduced in the previous articles: How to make a video call and Video devices. This GUI has a greater space for the incoming video stream and contains some extra functionality for video resolution and codec changing (Figure 2).


Figure 2 - The full GUI layout of the video softphone

This videophone makes it possible to change between the available video devices (web cameras), the video resolution (according to the selected cam's abilities) and the transmission codecs. Figure 3 shows how you can change the video resolution of the camera. The list contains all the possible resolutions the web cam is capable of.


Figure 3 - GUI support for video resolution change

In case of both voice and video communication, Ozeki VoIP SIP SDK provides you the opportunity to change the transmission codec to be used. You can, of course, use the codecs automatically, but you can choose among all the supported codecs if you wish (Figure 4).


Figure 4 - GUI support codec change

Now you are familiar with the basic GUI elements for the camera, resolution and codec changing support, it is time to take a look at the source code to get familiar with the implementation of these functions.

The following sections will show you how to implement video device, video resolution and transmission codec changing using Ozeki VoIP SIP SDK. You can check the function controls on the GUI above.

When the program starts and the GUI is initialized, you can set the available video devices on the GUI and the possible resolution values for the selected camera device that will be the default camera (Code 1).

public VideoSoftphone()
{
    InitializeComponent();
    setCameras();
    UpdateCameraResolution(comboBox1.SelectedItem as VideoDeviceInfo);
}

Code 1 - Initializing the cameras and the resolution settings

Code 2 shows the method for setting all the available cameras on the GUI. This method runs only once when the application is started. If you connect new video devices to your computer, you will need to restart the program in order to detect these new devices.

The available cameras can be got by calling the WebCamera.GetDevices() method. This will initialize the cameras List and the GUI list will be filled from that. If there is at least one camera connected to your computer, the first one will be chosen from the list. You can, of course change the camera during the application runtime.

private void setCameras()
{
    foreach (Ozeki.Media.Video.VideoDeviceInfo cam in cameras)
        this.comboBox1.Items.Add(cam);
    if (cameras.Count > 0)
        this.comboBox1.SelectedIndex = 0;
    camera = WebCamera.GetDevice(comboBox1.SelectedItem as VideoDeviceInfo);
}

Code 2 - Setting the cameras on the GUI and choosing the default for the start

When a camera is chosen, the application gets the available video resolution information about the chosen device and sets the list on the GUI according to that info (Code 3). The resolution is a VideoCapabilities object in Ozeki VoIP SIP SDK. All cameras store all the possible resolution values they can use.

When the resolution list is filled up, the program chooses the maximum resolution value that is the first one as the resolutions follow each other in a descending order. You can, of course, change the video resolution during the application runtime.

private void UpdateCameraResolution(VideoDeviceInfo device)
{
    if (device == null)
        return;
    comboBox2.Items.Clear();
    if (device.Capabilities != null)
    {
        foreach (VideoCapabilities resolution in device.Capabilities)
        {
            comboBox2.Items.Add(resolution);
        }
        if (comboBox2.Items.Count > 0)
            comboBox2.SelectedItem = device.Capabilities[0];

        comboBox2.Update();
    }
}

Code 3 - Setting the available resolutions of the chosen camera

When you want to change the camera, you can choose from the list on the GUI. When a new camera is chosen, the event handler in Code 4 runs. This method sets the actual camera object and updates the resolution list according to the chosen camera.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    camera = WebCamera.GetDevice(comboBox1.SelectedItem as VideoDeviceInfo);
    UpdateCameraResolution(comboBox1.SelectedItem as VideoDeviceInfo);
}

Code 4 - Handling the camera change

You can also change the resolution of the video during runtime. In this case, you use the resolution list on the GUI that invokes the event handler method shown in Code 5. This method simply changes the camera resolution to the chosen one.

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
    VideoCapabilities vid = comboBox2.SelectedItem as VideoCapabilities;
    if (vid != null)
        camera.Resolution = vid.Resolution;
}

Code 5 - Handling the video resolution change

The transmission codecs are not in direct connection with the video devices. You can choose from all the Ozeki VoIP SIP SDK supported codecs during runtime, the only important thing is that all the communicating parties need to use the same codecs for the communication.

The codecs can be get by calling a method of the softphone object, therefore initializing the codecs list needs to be put after the softphone initialization (Code 6).

private void InitializeSoftPhone()
{
    try
    {

        softPhone = SoftPhoneFactory.CreateSoftPhone(SoftPhoneFactory.GetLocalIP(), 5700, 5750, 5700);
        softPhone.IncomingCall += new EventHandler<VoIPEventArgs<IPhoneCall>>(softPhone_IncomingCall);
        setCodecs();
        ...

Code 6 - Setting the supported codecs

The setCodecs() method shown in Code 7 gets all the available codecs from the already initialized softphone and fills the codec list on the GUI according to those. The method will set the first codec on the list as the chosen one but you can change the transmission codec during runtime. The setCodecs() method only runs once at the beginning of the application runtime.

private void setCodecs()
{
    if (softPhone == null)
        return;
    codecs = softPhone.Codecs;
    foreach (CodecInfo ci in codecs)
        comboBox3.Items.Add(ci);
    if (comboBox3.Items.Count > 0)
        comboBox3.SelectedIndex = 0;
}

Code 7 - Listing the supported codecs on the GUI

When you want to change the transmission codec, you can choose one from the codec list on the GUI. In this case the event handler method introduced in Code 8 will run, and it will change the enabled codec for the softphone object. The codecs are identified by their payload information that can be added as parameter to the EnableCodec method of the softphone.

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
    if (softPhone == null)
        return;
    CodecInfo ci = comboBox3.SelectedItem as CodecInfo;
    softPhone.EnableCodec(ci.Payload);
}

Code 8 - Handling the transmission codec change

The other parts of the example program are exactly the same as in case of an ordinary videophone application. The device, resolution and codec changing support only needs the above listed code sections to work properly.

At this point you have all the information that is needed to implement a video softphone with camera, video resolution and codec changing using Ozeki VoIP SIP SDK. You can decide if you need some or all of them and create your own solution according to your needs.

If you have any questions or need assistance, please contact us at info@voip-sip-sdk.com

You can select a suitable Ozeki VoIP SIP SDK license for your project on Licensing page

Related Pages

Operating system: Windows 8, Windows 7, Vista, 200x, XP
Development environment: Visual Studio 2010 (Recommended), Visual Studio 2008, Visual Studio 2005
Programming language: C#.NET
Supported .NET framework: .NET Framework 4.5, .NET Framework 4.0, .NET Framework 3.5 SP1
Software development kit: OZEKI VoIP SIP SDK (Download)
VoIP connection: 1 SIP account
System memory: 512 MB+
Free disk space: 100 MB+