Windows UWP with linphone-sdk

Installing the Nuget package

A NuGet package (.nupkg) embedding and wrapping the Linphone SDK for UWP development on Windows is provided for your convenience.

It supports 3 frameworks:

  • - netcore (WindowsStore-32bits)
  • - netcore45 (Win32-32bits)
  • - uap10.0 (UWP-64bits)

Some other frameworks are provided for convenience but aren't fully tested:

  • - net5.0 : .NET 5
  • - netstandard2.1:.NET Standard
  • - netcoreapp3.1 : .NET Core
  • - net48 : .NET Framework

If you would like to use another framework, you can build a nuget package from source. In the project, you have to add a target framework in 'cmake/NuGet/windows/LinphoneSDK.nuspec.in' by adding your item in 'dependencies' section:
<group targetFramework="<your target framework>" />

From our Package Registry (>= v5.2.0)

Since version 5.2.0, the nupkg is availble for download from our self-hosted NuGet package registry.

  1. Add the Linphone package source to your development environment (You only need to do that once)
    nuget source Add -Name "Linphone" -Source "https://gitlab.linphone.org/api/v4/projects/411/packages/nuget/index.json"
    Or in Visual Studio, go to Tools->Nuget Package Manager->Package Manager Settings, go to Package sources, add a new package source with the URL above. (See below for screenshots of a similar process)
  2. Install the LinphoneSDK.Windows package from that new source
    nuget install LinphoneSDK.Windows -Source "Linphone"

You will then be able to update the package as you do other NuGet packages.

From a local package source (< v5.2.0)

For versions below 5.2.0, you will have to manually download or build the nupkg and setup a local source from which to install it.

For versions 5.0.x or 5.1.x, you can get pre-built Nuget packages from :
- https://www.linphone.org/releases/windows/sdk/

For anything older, you will have to build it from source:
- https://gitlab.linphone.org/BC/public/linphone-sdk

Download the nuget package and place it in the folder of your choice

In Visual Studio with your project, go to Tools->Nuget Package Manager->Package Manager Settings, go to Package sources, add a new package source to the folder.

packagesources.png

After this go to Tools->Nuget Package Manager->Manage Nuget Packages for solution. Select the local source.

selectSource.png

Select the project which the sdk will be install.

installnuget.png

On updating, be careful to the version : If the version is the same as an old version (for example, it can happen when building your own package), you have to manually delete the folder in .nuget:
C:\Users\<UserName>\.nuget\packages\linphonesdk
Visual Studio try to use the cache before using the version inside the custom folder where you put your package.

Get Liblinphone Log in Visual Studio Output

To set the log in Liblinphone your need to call this:

Linphone.LoggingService.Instance.LogLevel = Linphone.LogLevel.Debug;

After this, go to the properties of your UWP project:

1506944770356-563.png

Select the "Mixed (Managed and Native)" option for the Debugger type.

1506944730498-818.png

Application capabilities

Don't forget to set permission for your applications.

Open Package.appxmanifest:

1506947395922-745.png

Set the capabilities needed for your application:

1506947413617-757.png

More Help

Demo application : https://gitlab.linphone.org/BC/public/linphone-windows10/

Documentation : https://linphone.org/releases/docs/liblinphone/4.5/cs/api/Linphone.html

Tutorials : https://gitlab.linphone.org/BC/public/tutorials/-/tree/dev/c%23/cs

Windows UWP with Old Win32 linphone-sdk

This is working only with linphone SDK >= 4.0 and without the current nuget version (5.0)

The ability to create a Windows app package for your desktop application (otherwise known as the Desktop Bridge) was introduced in Windows 10, version 1607, and it can only be used in projects that target Windows 10 Anniversary Update (10.0; Build 14393) or a later release in Visual Studio.

https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-root

Create the desktop project for UWP

Just follow steps here: https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-packaging-dot-net

Resources to be embedded in application

liblinphone does requires 2 resources files from the nuget paquet to be embedded in the application.

<Content Include="Assets\belr\grammars\cpim_grammar">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Assets\belr\grammars\vcard_grammar">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

Display video

You need to clone the repository "mswinrtvid" add to your project visual studio the project ./mswinrtvid/MSWinRTVideo.vcxproj
Reference MSWinRTVideo in your project. This project will add a new UI form "SwapChainPanel"
Add in your "Package.appxmanifest":

<Package>
...
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>MSWinRTVideo.dll</Path>
<ActivatableClass ActivatableClassId="MSWinRTVideo.SchemeHandler" ThreadingModel="both" ></ActivatableClass>
</InProcessServer>
</Extension>
</Extensions>
</Package>

Example:
View.xaml

<SwapChainPanel x:Name="VideoSwapChainPanel" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Grid.RowSpan="3"></SwapChainPanel>
<SwapChainPanel x:Name="PreviewSwapChainPanel" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2" Grid.Row="2" RenderTransformOrigin="0.5,0.5">
<SwapChainPanel.RenderTransform>
<CompositeTransform x:Name="PreviewRender" ScaleX="-1"></CompositeTransform>
</SwapChainPanel.RenderTransform>
</SwapChainPanel>

View.xaml.cs

 private void StartVideoStream() {
           try {
               _videoSource = new MSWinRTVideo.SwapChainPanelSource();
               _videoSource.Start(VideoSwapChainPanel);
               _previewSource = new MSWinRTVideo.SwapChainPanelSource();
               _previewSource.Start(PreviewSwapChainPanel);

               LinphoneManager.Instance.Core.NativeVideoWindowIdString = VideoSwapChainPanel.Name;
               LinphoneManager.Instance.Core.NativePreviewWindowIdString = PreviewSwapChainPanel.Name;
            } catch (Exception e) {
               Debug.WriteLine(String.Format("StartVideoStream: Exception {0}", e.Message));
            }
        }

       private void StopVideoStream() {
           try {
               if (_videoSource != null) {
                   _videoSource.Stop();
                   _videoSource = null;
                }
               if (_previewSource != null) {
                   _previewSource.Stop();
                   _previewSource = null;
                }
            } catch (Exception e) {
               Debug.WriteLine(String.Format("StopVideoStream: Exception {0}", e.Message));
            }

        }
Tags: