Commit 8b2e4865 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Updated xamarin sample with android video call with remote and local video windows

parent 6ebcf676
LinphoneXamarin/LinphoneXamarin.Droid/Libs
LibLinphoneJavaBindings/Jars
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
......
Additions allow you to add arbitrary C# to the generated classes
before they are compiled. This can be helpful for providing convenience
methods or adding pure C# classes.
== Adding Methods to Generated Classes ==
Let's say the library being bound has a Rectangle class with a constructor
that takes an x and y position, and a width and length size. It will look like
this:
public partial class Rectangle
{
public Rectangle (int x, int y, int width, int height)
{
// JNI bindings
}
}
Imagine we want to add a constructor to this class that takes a Point and
Size structure instead of 4 ints. We can add a new file called Rectangle.cs
with a partial class containing our new method:
public partial class Rectangle
{
public Rectangle (Point location, Size size) :
this (location.X, location.Y, size.Width, size.Height)
{
}
}
At compile time, the additions class will be added to the generated class
and the final assembly will a Rectangle class with both constructors.
== Adding C# Classes ==
Another thing that can be done is adding fully C# managed classes to the
generated library. In the above example, let's assume that there isn't a
Point class available in Java or our library. The one we create doesn't need
to interact with Java, so we'll create it like a normal class in C#.
By adding a Point.cs file with this class, it will end up in the binding library:
public class Point
{
public int X { get; set; }
public int Y { get; set; }
}
\ No newline at end of file
This directory is for Android .jars.
There are 2 types of jars that are supported:
== Input Jar ==
This is the jar that bindings should be generated for.
For example, if you were binding the Google Maps library, this would
be Google's "maps.jar".
Set the build action for these jars in the properties page to "InputJar".
== Reference Jars ==
These are jars that are referenced by the input jar. C# bindings will
not be created for these jars. These jars will be used to resolve
types used by the input jar.
NOTE: Do not add "android.jar" as a reference jar. It will be added automatically
based on the Target Framework selected.
Set the build action for these jars in the properties page to "ReferenceJar".
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}</ProjectGuid>
<ProjectTypeGuids>{10368E6C-D01B-4462-8E8B-01FC667A7035};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LibLinphoneJavaBindings</RootNamespace>
<AssemblyName>LibLinphoneJavaBindings</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Jars\AboutJars.txt" />
<None Include="Additions\AboutAdditions.txt" />
</ItemGroup>
<ItemGroup>
<TransformFile Include="Transforms\Metadata.xml" />
<TransformFile Include="Transforms\EnumFields.xml" />
<TransformFile Include="Transforms\EnumMethods.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedJar Include="Jars\liblinphone.jar" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.Bindings.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LibLinphoneJavaBindings")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LibLinphoneJavaBindings")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<enum-field-mappings>
<!--
This example converts the constants Fragment_id, Fragment_name,
and Fragment_tag from android.support.v4.app.FragmentActivity.FragmentTag
to an enum called Android.Support.V4.App.FragmentTagType with values
Id, Name, and Tag.
<mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType">
<field jni-name="Fragment_name" clr-name="Name" value="0" />
<field jni-name="Fragment_id" clr-name="Id" value="1" />
<field jni-name="Fragment_tag" clr-name="Tag" value="2" />
</mapping>
-->
</enum-field-mappings>
\ No newline at end of file
<enum-method-mappings>
<!--
This example changes the Java method:
android.support.v4.app.Fragment.SavedState.writeToParcel (int flags)
to be:
android.support.v4.app.Fragment.SavedState.writeToParcel (Android.OS.ParcelableWriteFlags flags)
when bound in C#.
<mapping jni-class="android/support/v4/app/Fragment.SavedState">
<method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" />
</mapping>
-->
</enum-method-mappings>
\ No newline at end of file
<metadata>
<!--
This sample removes the class: android.support.v4.content.AsyncTaskLoader.LoadTask:
<remove-node path="/api/package[@name='android.support.v4.content']/class[@name='AsyncTaskLoader.LoadTask']" />
This sample removes the method: android.support.v4.content.CursorLoader.loadInBackground:
<remove-node path="/api/package[@name='android.support.v4.content']/class[@name='CursorLoader']/method[@name='loadInBackground']" />
-->
<remove-node path="/api/package[@name='org.linphone.core']" />
</metadata>
......@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinphoneXamarin.UWP", "Linp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinphoneXamarin.Windows", "LinphoneXamarin\LinphoneXamarin.Windows\LinphoneXamarin.Windows.csproj", "{02E3E4B4-0B22-4D92-A79E-6C4FCDB5BC2B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibLinphoneJavaBindings", "LibLinphoneJavaBindings\LibLinphoneJavaBindings.csproj", "{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
LinphoneXamarin\LinphoneXamarin\LinphoneXamarin.projitems*{02e3e4b4-0b22-4d92-a79e-6c4fcdb5bc2b}*SharedItemsImports = 4
......@@ -359,6 +361,54 @@ Global
{02E3E4B4-0B22-4D92-A79E-6C4FCDB5BC2B}.Release|x86.ActiveCfg = Release|x86
{02E3E4B4-0B22-4D92-A79E-6C4FCDB5BC2B}.Release|x86.Build.0 = Release|x86
{02E3E4B4-0B22-4D92-A79E-6C4FCDB5BC2B}.Release|x86.Deploy.0 = Release|x86
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|ARM.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|x64.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|Any CPU.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|ARM.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|ARM.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|iPhone.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|iPhone.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|x64.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|x64.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|x86.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.AppStore|x86.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|ARM.Build.0 = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|iPhone.Build.0 = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|x64.ActiveCfg = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|x64.Build.0 = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|x86.ActiveCfg = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Debug|x86.Build.0 = Debug|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|Any CPU.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|ARM.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|ARM.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|iPhone.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|iPhone.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|x64.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|x64.Build.0 = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|x86.ActiveCfg = Release|Any CPU
{D4ED3A97-C1C9-4111-A0C2-3D2D98490D72}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -135,6 +135,12 @@
<ItemGroup>
<AndroidJavaLibrary Include="Libs\liblinphone.jar" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\LibLinphoneJavaBindings\LibLinphoneJavaBindings.csproj">
<Project>{d4ed3a97-c1c9-4111-a0c2-3d2d98490d72}</Project>
<Name>LibLinphoneJavaBindings</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\LinphoneXamarin\LinphoneXamarin.projitems" Label="Shared" Condition="Exists('..\LinphoneXamarin\LinphoneXamarin.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.2.2.0.45\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.2.0.45\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
......
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Android.App;
using Android.Content.PM;
......@@ -8,14 +9,63 @@ using Android.Views;
using Android.Widget;
using Android.OS;
using Org.Linphone.Mediastream.Video;
using Org.Linphone.Mediastream.Video.Display;
namespace LinphoneXamarin.Droid
{
[Activity (Label = "LinphoneXamarin", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
[Activity(Label = "LinphoneXamarin", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity, AndroidVideoWindowImpl.IVideoWindowListener
{
[DllImport("liblinphone-armeabi-v7a")]
private const string LIBNAME = "liblinphone-armeabi-v7a";
private LinphoneXamarin.App app;
private System.Threading.Thread coreIterate;
private GL2JNIView view1;
private SurfaceView view2;
private AndroidVideoWindowImpl androidVideo;
[DllImport(LIBNAME)]
static extern void ms_set_jvm_from_env(IntPtr jnienv);
[DllImport(LIBNAME)]
static extern void setAndroidLogHandler();
[DllImport(LIBNAME)]
static extern void setMediastreamerAndroidContext(IntPtr jnienv, IntPtr context);
[DllImport(LIBNAME)]
static extern void linphone_core_iterate(IntPtr lc);
[DllImport(LIBNAME)]
static extern void linphone_core_set_native_video_window_id(IntPtr lc, IntPtr id);
[DllImport(LIBNAME)]
static extern void linphone_core_set_native_preview_window_id(IntPtr lc, IntPtr id);
[DllImport(LIBNAME)]
static extern void linphone_core_enable_video(IntPtr lc, int enable_c, int enable_d);
[DllImport(LIBNAME)]
static extern IntPtr linphone_core_create_call_params(IntPtr lc, IntPtr call);
[DllImport(LIBNAME)]
static extern void linphone_call_params_enable_video(IntPtr callp, int enabled);
[DllImport(LIBNAME)]
static extern IntPtr linphone_address_new(string to);
[DllImport(LIBNAME)]
static extern IntPtr linphone_core_invite_address_with_params(IntPtr lc, IntPtr to, IntPtr callp);
void LinphoneCoreIterate()
{
while (true)
{
RunOnUiThread(() => linphone_core_iterate(app.corePtr));
System.Threading.Thread.Sleep(50);
}
}
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
......@@ -29,9 +79,63 @@ namespace LinphoneXamarin.Droid
Java.Lang.JavaSystem.LoadLibrary("linphone-armeabi-v7a");
ms_set_jvm_from_env(Android.Runtime.JNIEnv.Handle);
setAndroidLogHandler();
setMediastreamerAndroidContext(Android.Runtime.JNIEnv.Handle, this.Handle);
app = new LinphoneXamarin.App();
LoadApplication(app);
coreIterate = new Thread(LinphoneCoreIterate);
coreIterate.IsBackground = false;
coreIterate.Start();
view1 = new GL2JNIView(this);
view1.LayoutParameters = new LinearLayout.LayoutParams(500, 500);
view2 = new SurfaceView(this);
view2.LayoutParameters = new LinearLayout.LayoutParams(500, 500);
LinearLayout ll = new LinearLayout(this);
ll.Orientation = Orientation.Vertical;
ll.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
ll.AddView(view1);
ll.AddView(view2);
SetContentView(ll);
view1.SetZOrderOnTop(false);
view2.SetZOrderOnTop(true);
androidVideo = new AndroidVideoWindowImpl(view1, view2, this);
}
protected override void OnResume()
{
base.OnResume();
linphone_core_enable_video(app.corePtr, 1, 1);
IntPtr callp = linphone_core_create_call_params(app.corePtr, IntPtr.Zero);
linphone_call_params_enable_video(callp, 1);
IntPtr to = linphone_address_new("sip:sylvain@sip.linphone.org");
linphone_core_invite_address_with_params(app.corePtr, to, callp);
linphone_core_set_native_video_window_id(app.corePtr, androidVideo.Handle);
}
public void OnVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl p0)
{
}
public void OnVideoPreviewSurfaceReady(AndroidVideoWindowImpl p0, SurfaceView p1)
{
linphone_core_set_native_preview_window_id(app.corePtr, p1.Handle);
}
public void OnVideoRenderingSurfaceDestroyed(AndroidVideoWindowImpl p0)
{
}
LoadApplication (new LinphoneXamarin.App ());
public void OnVideoRenderingSurfaceReady(AndroidVideoWindowImpl p0, SurfaceView p1)
{
linphone_core_set_native_video_window_id(app.corePtr, p0.Handle);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.linphonex" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application android:label="LinphoneXamarin.Droid"></application>
</manifest>
\ No newline at end of file
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Xamarin.Forms;
......@@ -9,6 +10,8 @@ namespace LinphoneXamarin
{
public partial class App : Application
{
public IntPtr corePtr;
public App()
{
InitializeComponent();
......@@ -16,9 +19,83 @@ namespace LinphoneXamarin
MainPage = new LinphoneXamarin.MainPage();
}
const string LIBNAME = "liblinphone-armeabi-v7a";
struct LinphoneCoreVTable
{
public IntPtr global_state_changed;
public IntPtr registration_state_changed;
public IntPtr call_state_changed;
public IntPtr notify_presence_received;
public IntPtr notify_presence_received_for_uri_or_tel;
public IntPtr new_subscription_requested;
public IntPtr auth_info_requested;
public IntPtr authentication_requested;
public IntPtr call_log_updated;
public IntPtr message_received;
public IntPtr is_composing_received;
public IntPtr dtmf_received;
public IntPtr refer_received;
public IntPtr call_encryption_changed;
public IntPtr transfer_state_changed;
public IntPtr buddy_info_updated;
public IntPtr call_stats_updated;
public IntPtr info_received;
public IntPtr subscription_state_changed;
public IntPtr notify_received;
public IntPtr publish_state_changed;
public IntPtr configuring_status;
public IntPtr display_status;
public IntPtr display_message;
public IntPtr display_warning;
public IntPtr display_url;
public IntPtr show;
public IntPtr text_received;
public IntPtr file_transfer_recv;
public IntPtr file_transfer_send;
public IntPtr file_transfer_progress_indication;
public IntPtr network_reachable;
public IntPtr log_collection_upload_state_changed;
public IntPtr log_collection_upload_progress_indication;
public IntPtr friend_list_created;
public IntPtr friend_list_removed;
};
public enum LinphoneGlobalState
{
LinphoneGlobalOff,
LinphoneGlobalStartup,
LinphoneGlobalOn,
LinphoneGlobalShutdown,
LinphoneGlobalConfiguring
};
[DllImport(LIBNAME)]
static extern IntPtr linphone_core_v_table_new();
[DllImport(LIBNAME)]
static extern IntPtr linphone_core_new(IntPtr vtable, string config_path, string factory_config_path, IntPtr userdata);
[DllImport(LIBNAME)]
static extern void linphone_core_enable_logs_with_cb(IntPtr cb);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void LinphoneCoreGlobalStateChangedCb(IntPtr lc, LinphoneGlobalState state, string message);
void OnGlobalStateChanged(IntPtr lc, LinphoneGlobalState state, string message)
{
Console.WriteLine("[GLOBAL STATE CHANGED] " + message);
}
protected override void OnStart()
{
// Handle when your app starts
IntPtr vtablePtr = linphone_core_v_table_new();
LinphoneCoreVTable vtable = Marshal.PtrToStructure<LinphoneCoreVTable>(vtablePtr);
LinphoneCoreGlobalStateChangedCb global_cb = new LinphoneCoreGlobalStateChangedCb(OnGlobalStateChanged);
vtable.global_state_changed = Marshal.GetFunctionPointerForDelegate(global_cb);
Marshal.StructureToPtr(vtable, vtablePtr, false);
corePtr = linphone_core_new(vtablePtr, null, null, IntPtr.Zero);
}
protected override void OnSleep ()
......
......@@ -9,12 +9,6 @@
x:Name="globalStateLabel"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Button Text="Start Linphone"
x:Name="startLinphoneButton"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
Clicked="OnButtonClicked" />
</StackLayout>
</ContentPage>
\ No newline at end of file
......@@ -3,95 +3,15 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Xamarin.Forms;
namespace LinphoneXamarin
{
public partial class MainPage : ContentPage
{
const string LIBNAME = "liblinphone-armeabi-v7a";
struct LinphoneCoreVTable
{
public IntPtr global_state_changed;
public IntPtr registration_state_changed;
public IntPtr call_state_changed;
public IntPtr notify_presence_received;
public IntPtr notify_presence_received_for_uri_or_tel;
public IntPtr new_subscription_requested;
public IntPtr auth_info_requested;
public IntPtr authentication_requested;
public IntPtr call_log_updated;
public IntPtr message_received;
public IntPtr is_composing_received;
public IntPtr dtmf_received;
public IntPtr refer_received;
public IntPtr call_encryption_changed;
public IntPtr transfer_state_changed;
public IntPtr buddy_info_updated;
public IntPtr call_stats_updated;
public IntPtr info_received;
public IntPtr subscription_state_changed;
public IntPtr notify_received;
public IntPtr publish_state_changed;
public IntPtr configuring_status;
public IntPtr display_status;
public IntPtr display_message;
public IntPtr display_warning;
public IntPtr display_url;
public IntPtr show;
public IntPtr text_received;
public IntPtr file_transfer_recv;
public IntPtr file_transfer_send;
public IntPtr file_transfer_progress_indication;
public IntPtr network_reachable;
public IntPtr log_collection_upload_state_changed;
public IntPtr log_collection_upload_progress_indication;
public IntPtr friend_list_created;
public IntPtr friend_list_removed;
};
public enum LinphoneGlobalState
{
LinphoneGlobalOff,
LinphoneGlobalStartup,
LinphoneGlobalOn,
LinphoneGlobalShutdown,
LinphoneGlobalConfiguring
};
[DllImport(LIBNAME)]
static extern IntPtr linphone_core_v_table_new();
[DllImport(LIBNAME)]
static extern IntPtr linphone_core_new(IntPtr vtable, string config_path, string factory_config_path, IntPtr userdata);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void LinphoneCoreGlobalStateChangedCb(IntPtr lc, LinphoneGlobalState state, string message);
void OnGlobalStateChanged(IntPtr lc, LinphoneGlobalState state, string message)
{
globalStateLabel.Text += "[LINPHONE GLOBAL STATE CHANGED] " + message + "\r\n";
}
public MainPage()
{
InitializeComponent();
}
void OnButtonClicked(object sender, EventArgs args)
{
globalStateLabel.Text = "";
startLinphoneButton.IsEnabled = false;
IntPtr vtablePtr = linphone_core_v_table_new();
LinphoneCoreVTable vtable = Marshal.PtrToStructure<LinphoneCoreVTable>(vtablePtr);
LinphoneCoreGlobalStateChangedCb global_cb = new LinphoneCoreGlobalStateChangedCb(OnGlobalStateChanged);
vtable.global_state_changed = Marshal.GetFunctionPointerForDelegate(global_cb);
Marshal.StructureToPtr(vtable, vtablePtr, false);
IntPtr corePtr = linphone_core_new(vtablePtr, null, null, IntPtr.Zero);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment