How to handle VoIP PBX MediaGateway Connection?

This article is a brief introduction about the VoIP PBX MediaGateway connection in relation with Ozeki VoIP SIP SDK. After reading through this page you will be fully familiar with all the essential terms concerning VoIP PBX and Ozeki MediaGateway connection and what you will need for creating your own solution using Ozeki VoIP SIP SDK.

What is MediaGateway?

This article explains how to connect an Ozeki VoIP PBX system with the Ozeki MediaGateway technology, this allows you to connect to your PBX with a webphone application too. As both parts of the Ozeki VoIP SIP SDK provides great support and basic background implementations, you only need to define some objects and call some methods for having a great cooperation between these two.

A media gateway is a translation device or service that converts digital media streams between disparate telecommunications networks such as PSTN, Next Generation Networks (2G, 2.5G and 3G radio access networks) or PBX. Media gateways enable multimedia communications across Next Generation Networks over multiple transport protocols such as Asynchronous Transfer Mode (ATM) and Internet Protocol (IP).
Basically, media gateway connects different types of networks.

Voice over Internet Protocol (VoIP) media gateways perform the conversion between TDM voice to a media streaming protocol (usually Real-time Transport Protocol, RTP), as well as a signaling protocol used in the VoIP system.

How to handle MediaGateway using C#?

The PBX's OnStart() method needs to be extended with the MediaGateway support. For example, the program can handle Flash client connections through the MediaGateway server.

The MediaGateway server that is used in the PBX is implemented in a class that is derived from the Ozeki.MediaGateway.MediaGateway class provided by the Ozeki VoIP SIP SDK. This derivation is necessary to get all the provided functionalities for webphone support (for example) in the PBX.

The MediaGateway also needs to handle the PBX extensions as the MediaGateway client class is defined to be a PBX extension as this is the easiest way for handling it.

MediaGateway clients get a SIP account from the PBX automatically during the login process. This SIP account is provided by a class called AccountPool. The SetAvailableAccounts(); instruction in the constructor code fills this pool with available SIP accounts.

The MediaGateway handles the client connections with the OnClientConnect() method. This is a method provided by the Ozeki SDK MediaGateway class and that needs to be overridden in this class.

When a webphone client tries to connect to the PBX, it gets a SIP account form the account pool if there is at least one available. If there are no available SIP accounts, the registration will be rejected by the PBX with the message to the client that the number of connections exceeded the limit.

The MediaGateway server stores the connected clients in a Dictionary object called myClients. When a client connected to the PBX, it will be put into this Dictionary and will be deleted from it after its disconnection.

The PBX MediaGateway server handles the webphone clients through a PBX extension class called MediaGatewayClient. The MediaGatewayClient class is derived from the IExtension interface that ensures the easiest handling process in the PBX.

In the case of a ringing call (incoming call), the PBX runs the OnCallRequest() method that will invoke the client-side method of the same name in the client application.
The call state handling is the most important part of the code.

In the case of an established call the same processes need to be done as in the case of a simple softphone. You need to attach the audio sender and receiver objects to the call and then you need to set the MediaGateway audio receiver parameterized with the media stream of the client.

You need to connect the phoneCallAudioReceiver with the mediaGatewayAudioReceiver. This connection makes possible the communication between the webphone solutions and any other SIP end points.

MediaGateway example in C#

This guide introduced the basic steps of the handling of MediaGateway, but if you would like to study sample example and step-by-step guide about MediaGateway management is C# using Ozeki VoIP SIP SDK, you can find it at the Training chapter's MediaGateway connection article.

Related Pages

More information