Course 1 / Lecture 6

How to develop a softphone in C#

How to enable and disable different codecs


Here you can learn how to enable/disable the (different) codecs in order to determine which codecs should be used during calls. This example requires the knowledge of SIP registering and the making of phone calles with the softphone. To learn these, you can visit the previous examples:

In this tutorial example we will learn the followings:

  • How to enable a codec
  • How to disable a codec

Please note that, only the softphone's new elements will be introduced here. You can find the registration's process and the needed elements for that at the first example, called "SIP Registration". You can find how to make and accept calls, how to begin to handle the call's states in the second example, called "Making and accepting calls".

Source code analysis

To understand the source code, the softphone's functions and their usage, we need to discuss the details.


This class is used to introduce how to declare, define and initialize a softphone, how to handle some of the Ozeki VoIP SIP SDK's events and how to use some of that's functions. In other words, we would like to create a "telephone software", which has the same functions (or much more), as an ordinary mobile (or any other) phone. In the Program.cs class we will use this class to create a new softphone, so we can use the functions, we can listen to the events placed here. Please note that, this softphone is not able to accept calls. That function is removed in purpose to reduce the code's size, and to be more understandable.

Access to the codecs

With the help of the softphone object, you can have access to the list of available codecs:


Enabling and disabling codecs

In order for you to be able to disable a given codec, you should use the DisableCodec() method. In this method, you should provide the payLoadType of the codec you wish to disable as a parameter. This is a number which identifies the given codec. Enabling a codec works in a similar manner. In this case, you should use the EnableCodec() method.



In this example, the softphone asks the user which codecs should be used. If the user does not wish to manually provide such codecs, by pressing Enter the default codec settings will be valid. This application guides you through the following steps:

  • Lists the available codecs so that the codecs you wish to use can be easily selected.
  • Afterwards, the numbers of these codecs will be requested or by pressing Enter, you can use the default codecs.
  • Shows which codecs will be used at that moment as a result of your settings.
  • Finally, by dialling a phone number, you can make calls using the previously selected codecs.

This code is handling everything with separate methods. These methods are communicating with each other, and making the source code more understandable and reusable.

Using Wireshark, you can check to see if the used codecs are the same as the codecs the user selected.

Figure 1 - In this case, just the 8 PCMA codec is used.

All you have to do is to filter the relevant data from the network traffic with the help of a SIP filter. This way you will be able to check which codecs were used during the call.


After reading this documentation and studying the source code, you are now familiar with how you can handle: enable and disable various codecs.

If you have any questions or need assistance, please contact us at

Related Pages

Copyright © 2000- - Ozeki Ltd |
Legal | Privacy | Terms of use | 7541 | | Login