Commit ced8f79a authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added video capture + preview

parent 2b1fd6f1
......@@ -10,6 +10,9 @@ using Xamarin.Forms.Platform.Android;
using Android;
using Android.Util;
using System.Collections.Generic;
using Xamarin.Forms;
using Android.Views;
using Android.Widget;
namespace Xamarin.Droid
{
......@@ -17,7 +20,8 @@ namespace Xamarin.Droid
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
int PERMISSIONS_REQUEST = 101;
Org.Linphone.Mediastream.Video.Display.GL2JNIView captureCamera;
Org.Linphone.Mediastream.Video.Display.GL2JNIView displayCamera;
SurfaceView captureCamera;
protected override void OnCreate(Bundle bundle)
{
......@@ -39,7 +43,7 @@ namespace Xamarin.Droid
AssetManager assets = Assets;
string path = FilesDir.AbsolutePath;
string rc_path = path + "/default_rc";
using (var br = new BinaryReader(Application.Context.Assets.Open("linphonerc_default")))
using (var br = new BinaryReader(Assets.Open("linphonerc_default")))
{
using (var bw = new BinaryWriter(new FileStream(rc_path, FileMode.Create)))
{
......@@ -56,12 +60,30 @@ namespace Xamarin.Droid
App app = new App(); // Do not add an arg to App constructor
app.ConfigFilePath = rc_path;
captureCamera = new Org.Linphone.Mediastream.Video.Display.GL2JNIView(this);
captureCamera.Holder.SetFixedSize(1920, 1080);
AndroidVideoWindowImpl androidView = new AndroidVideoWindowImpl(captureCamera, null, null);
LinearLayout fl = new LinearLayout(this);
ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
fl.LayoutParameters = lparams;
displayCamera = new Org.Linphone.Mediastream.Video.Display.GL2JNIView(this);
ViewGroup.LayoutParams dparams = new ViewGroup.LayoutParams(640, 480);
displayCamera.LayoutParameters = dparams;
displayCamera.Holder.SetFixedSize(640, 480);
captureCamera = new SurfaceView(this);
ViewGroup.LayoutParams cparams = new ViewGroup.LayoutParams(320, 240);
captureCamera.LayoutParameters = cparams;
captureCamera.Holder.SetFixedSize(320, 240);
fl.AddView(displayCamera);
fl.AddView(captureCamera);
AndroidVideoWindowImpl androidView = new AndroidVideoWindowImpl(displayCamera, captureCamera, null);
app.Core.NativeVideoWindowId = androidView.Handle;
app.Core.NativePreviewWindowId = captureCamera.Handle;
app.getLayoutView().Children.Add(fl);
app.Core.VideoDisplayEnabled = true;
app.getLayoutView().Children.Add(captureCamera.ToView());
app.Core.VideoCaptureEnabled = true;
LoadApplication(app);
}
......
......@@ -17,6 +17,7 @@
<Entry x:Name="address" Placeholder="Address" />
<Button x:Name="call" Text="Start Call" Clicked="OnCallClicked" HorizontalOptions="Center" />
<Button x:Name="video_call" Text="Start Video Call" Clicked="OnVideoCallClicked" HorizontalOptions="Center" />
<Label x:Name="call_status" HorizontalOptions="Center" />
<Label x:Name="call_stats" HorizontalOptions="Center" />
......
......@@ -54,10 +54,12 @@ namespace Xamarin
if (state == CallState.IncomingReceived)
{
call.Text = "Answer Call (" + lcall.RemoteAddressAsString + ")";
video_call.Text = "Answer Call with Video";
}
else
{
call.Text = "Terminate Call";
video_call.Text = "Terminate Call";
}
if (lcall.CurrentParams.VideoEnabled)
{
......@@ -73,6 +75,7 @@ namespace Xamarin
video.IsEnabled = false;
call.Text = "Start Call";
call_stats.Text = "";
video_call.Text = "Start Video Call";
}
}
......@@ -158,6 +161,31 @@ namespace Xamarin
}
}
private void OnVideoCallClicked(object sender, EventArgs e)
{
if (Core.CallsNb == 0)
{
var addr = Core.InterpretUrl(address.Text);
CallParams CallParams = Core.CreateCallParams(null);
CallParams.VideoEnabled = true;
Core.InviteAddressWithParams(addr, CallParams);
}
else
{
Call call = Core.CurrentCall;
if (call.State == CallState.IncomingReceived)
{
CallParams CallParams = Core.CreateCallParams(call);
CallParams.VideoEnabled = true;
Core.AcceptCallWithParams(call, CallParams);
}
else
{
Core.TerminateAllCalls();
}
}
}
private void OnVideoClicked(object sender, EventArgs e)
{
if (Core.CallsNb > 0)
......
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