Commit 35848de4 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Android app working again except for video

parent 9af1c112
......@@ -258,4 +258,6 @@ ModelManifest.xml
# FAKE - F# Make
.fake/
# Generate files, do not commit
Xamarin/Xamarin/Xamarin/LinphoneWrapper.cs
Xamarin/Xamarin/Liblinphone/liblinphone-sdk.aar
using System;
using Android.App;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
using Linphone;
using Android.Content.Res;
using System.IO;
using Linphone;
namespace Xamarin.Droid
{
[Activity(Label = "Xamarin", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
//GL2JNIView captureCamera;
protected override void OnCreate(Bundle bundle)
{
Java.Lang.JavaSystem.LoadLibrary("c++_shared");
......@@ -47,8 +47,16 @@ namespace Xamarin.Droid
}
global::Xamarin.Forms.Forms.Init(this, bundle);
App app = new App();
App app = new App(); // Do not add an arg to App constructor
app.ConfigFilePath = rc_path;
/*captureCamera = new GL2JNIView(this);
captureCamera.Holder.SetFixedSize(1920, 1080);
AndroidVideoWindowImpl androidView = new AndroidVideoWindowImpl(captureCamera, null, null);
app.Core.NativeVideoWindowId = androidView.Handle;
app.Core.VideoDisplayEnabled = true;
app.getLayoutView().Children.Add(captureCamera);*/
LoadApplication(app);
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="org.linphone.xamarin" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<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.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application android:label="Xamarin.Android"></application>
</manifest>
\ No newline at end of file
......@@ -18,14 +18,25 @@ namespace Xamarin
InitializeComponent();
LinphoneWrapper.setNativeLogHandler();
Factory.Instance.EnableLogCollection(LogCollectionState.Enabled);
CoreListener listener = Factory.Instance.CreateCoreListener();
listener.OnGlobalStateChanged = OnGlobal;
#if ANDROID
// Giving app context in CreateCore is mandatory for Android to be able to load grammars (and other assets) from AAR
Core = Factory.Instance.CreateCore(listener, ConfigFilePath, null, IntPtr.Zero, LinphoneAndroid.AndroidContext);
#else
Core = Factory.Instance.CreateCore(listener, ConfigFilePath, null);
#endif
Core.NetworkReachable = true;
MainPage = new MainPage();
}
}
public StackLayout getLayoutView()
{
return MainPage.FindByName<StackLayout>("stack_layout");
}
private void OnGlobal(Core lc, GlobalState gstate, string message)
{
......
This diff is collapsed.
......@@ -4,11 +4,23 @@
xmlns:local="clr-namespace:Xamarin"
x:Class="Xamarin.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<StackLayout x:Name="stack_layout" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Orientation="Vertical" Spacing="15">
<Label x:Name="welcome" Text="Welcome to Linphone Xamarin!" HorizontalOptions="Center" />
<StackLayout x:Name="stack_registrar">
<Entry x:Name="username" Placeholder="Username" />
<Entry x:Name="password" Placeholder="Password" IsPassword="true"/>
<Entry x:Name="domain" Placeholder="Domain" Text="sip.linphone.org"/>
<Button x:Name="register" Text="Register" Clicked="OnRegisterClicked" HorizontalOptions="Center" />
<Label x:Name="registration_status" HorizontalOptions="Center" />
</StackLayout>
<Entry x:Name="address" Placeholder="Address" />
<Button x:Name="call" Text="Start Call" Clicked="OnCallClicked" HorizontalOptions="Center" />
<Label x:Name="call_status" HorizontalOptions="Center" />
<Label x:Name="call_stats" HorizontalOptions="Center" />
<Button x:Name="video" Text="Start Video" Clicked="OnVideoClicked" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
......@@ -22,27 +22,124 @@ namespace Xamarin
private void OnRegistration(Core lc, ProxyConfig config, RegistrationState state, string message)
{
Console.WriteLine("Registration state changed: " + state);
registration_status.Text = "Registration state changed: " + state;
if (state == RegistrationState.Ok)
{
register.IsEnabled = false;
this.FindByName<StackLayout>("stack_registrar").IsVisible = false;
}
}
private void OnCall(Core lc, Call lcall, CallState state, string message)
{
Console.WriteLine("Call state changed: " + state);
call_status.Text = "Call state changed: " + state;
if (lc.CallsNb > 0)
{
if (state == CallState.IncomingReceived)
{
call.Text = "Answer Call (" + lcall.RemoteAddressAsString + ")";
}
else
{
call.Text = "Terminate Call";
}
if (lcall.CurrentParams.VideoEnabled)
{
video.Text = "Stop Video";
}
else
{
video.Text = "Start Video";
}
}
else
{
call.Text = "Start Call";
call_stats.Text = "";
}
}
private void OnStats(Core lc, Call call, CallStats stats)
{
Console.WriteLine("Call stats: " + stats.DownloadBandwidth + " kbits/s / " + stats.UploadBandwidth + " kbits/s");
call_stats.Text = "Call stats: " + stats.DownloadBandwidth + " kbits/s / " + stats.UploadBandwidth + " kbits/s";
}
public MainPage()
{
InitializeComponent();
welcome.Text = "Linphone Xamarin version: " + Core.Version;
Listener = Factory.Instance.CreateCoreListener();
Listener.OnRegistrationStateChanged = OnRegistration;
Listener.OnCallStateChanged = OnCall;
Listener.OnCallStatsUpdated = OnStats;
Core.AddListener(Listener);
}
}
private void OnRegisterClicked(object sender, EventArgs e)
{
var authInfo = Factory.Instance.CreateAuthInfo(username.Text, null, password.Text, null, null, domain.Text);
Core.AddAuthInfo(authInfo);
var proxyConfig = Core.CreateProxyConfig();
var identity = Factory.Instance.CreateAddress("sip:sample@domain.tld");
identity.Username = username.Text;
identity.Domain = domain.Text;
proxyConfig.Edit();
proxyConfig.IdentityAddress = identity;
proxyConfig.ServerAddr = domain.Text;
proxyConfig.Route = domain.Text;
proxyConfig.RegisterEnabled = true;
proxyConfig.Done();
Core.AddProxyConfig(proxyConfig);
Core.DefaultProxyConfig = proxyConfig;
Core.RefreshRegisters();
}
private void OnCallClicked(object sender, EventArgs e)
{
if (Core.CallsNb == 0)
{
var addr = Core.InterpretUrl(address.Text);
Core.InviteAddress(addr);
}
else
{
Call call = Core.CurrentCall;
if (call.State == CallState.IncomingReceived)
{
Core.AcceptCall(call);
}
else
{
Core.TerminateAllCalls();
}
}
}
private void OnVideoClicked(object sender, EventArgs e)
{
if (Core.CallsNb > 0)
{
Call call = Core.CurrentCall;
if (call.State == CallState.StreamsRunning)
{
Core.VideoAdaptiveJittcompEnabled = true;
CallParams param = Core.CreateCallParams(call);
param.VideoEnabled = !call.CurrentParams.VideoEnabled;
param.VideoDirection = MediaDirection.SendRecv;
Core.UpdateCall(call, param);
}
}
}
}
}
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