From 80faceb86399017851f9f72feaaef868a37ff23f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 26 三月 2021 10:50:35 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/lss' into temp-wxr

---
 HDL-ON_Android/VideoActivity.cs |  449 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 449 insertions(+), 0 deletions(-)

diff --git a/HDL-ON_Android/VideoActivity.cs b/HDL-ON_Android/VideoActivity.cs
new file mode 100644
index 0000000..1a9cf00
--- /dev/null
+++ b/HDL-ON_Android/VideoActivity.cs
@@ -0,0 +1,449 @@
+锘�
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using Android;
+using Android.App;
+using Android.Content;
+using Android.Content.PM;
+using Android.Graphics;
+using Android.OS;
+using Android.Runtime;
+using Android.Support.V4.App;
+using Android.Support.V4.Content;
+using Android.Util;
+using Android.Views;
+using Android.Widget;
+using Com.ETouchSky;
+using Com.Tool;
+using GateWay.Droid.FengLinVideo.widget;
+using HDL_ON.Common;
+using HDL_ON.DAL.Server;
+using HDL_ON_Android.FengLinVideo.Form;
+
+namespace HDL_ON_Android
+{
+    [Activity(Label = "VideoActivity", WindowSoftInputMode = SoftInput.AdjustResize, LaunchMode = LaunchMode.SingleInstance, ConfigurationChanges = (ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.LayoutDirection | ConfigChanges.Locale | ConfigChanges.Orientation | ConfigChanges.ScreenSize), Theme = "@style/MyTheme1", ScreenOrientation = ScreenOrientation.Portrait)]
+    public class VideoActivity : Activity, View.IOnClickListener, ISurfaceHolderCallback, VideoPhoneJni.ICallBack, TipDiaglog.OnConfirmClickListener
+    {
+        private static Activity activity;
+        private VideoPhone mPhone;
+        private ISurfaceHolder mRemoteSurfaceHolder;
+        private FrameLayout mRemoteFrameContainer;
+        private SurfaceView mSurfaceRemote;
+
+        private ImageView ivBack;
+        private TextView tvName;
+        private MonitorFragment monitorFragment = null;
+        private ReverseCallFragment reverseCallFragment = null;
+
+        public static string ESVideoUUID = "JJY000019VPLLF";//瀹ゅ鏈篣UID锛屼緥:JJY000007FSEYX  f5f6fa
+        public static string DeviceName;//瀹ゅ鏈虹殑鍚嶇О锛屼緥锛屽澶栨満
+        public static bool IsCollect;//鏄惁鏀惰棌
+        public static int Tpye = 0;//绫诲瀷锛�0 鐩戞帶锛�1鍙嶅懠
+
+        public static string UUId;
+        public static int CallId;//callId 鍛煎彨璁板綍id
+        public static string CmtID;//cmtID 涓版灄绀惧尯鍙�
+        public static string Roomno;//roomno 涓版灄鎴块棿鍙�
+        public static string Unitno;//unitno 涓版灄妤兼爧鍙� string
+        public static string HomeID;//HomeID 涓版灄浣忓畢id
+
+        protected override void OnCreate(Bundle savedInstanceState)
+        {
+            base.OnCreate(savedInstanceState);
+
+            try
+            {
+                activity = this;
+
+                ESVideoUUID = Intent.GetStringExtra("ESVideoUUID");//瀹ゅ鏈篣UID锛屼緥:JJY000007FSEYX
+                DeviceName = Intent.GetStringExtra("DeviceName");//瀹ゅ鏈虹殑鍚嶇О锛屼緥锛屽澶栨満
+                UUId = Intent.GetStringExtra("uuid");//
+                CallId = Intent.GetIntExtra("callId", 0);
+                CmtID = Intent.GetStringExtra("cmtID");
+                Roomno = Intent.GetStringExtra("roomno");
+                Unitno = Intent.GetStringExtra("unitno");
+                HomeID = Intent.GetStringExtra("HomeID");
+
+                IsCollect = Intent.GetBooleanExtra("IsCollect", false);//鏄惁鏀惰棌
+                Tpye = Intent.GetIntExtra("Type", 0);//绫诲瀷锛�0 鐩戞帶锛�1鍙嶅懠
+
+                SetContentView(Resource.Layout.activity_video_phone);
+
+                IniView();
+                IniData();
+
+                if (Tpye == 0)
+                {
+                    Monitor(ESVideoUUID); //鐩戞帶
+
+                    monitorFragment = new MonitorFragment(mPhone);
+                    FragmentManager.BeginTransaction().Replace(Resource.Id.content, monitorFragment).Commit();
+                }
+                else
+                {
+                    string param = "address=" + ESVideoUUID + ",tag=mobile://123,";
+                    reverseCallFragment = new ReverseCallFragment(mPhone, param);
+                    FragmentManager.BeginTransaction().Replace(Resource.Id.content, reverseCallFragment).Commit();
+                }
+            }
+            catch {}
+        }
+
+        /// <summary>
+        /// 蹇呰鐨勪竴浜涙潈闄�
+        /// </summary>
+        private void Permissions()
+        {
+            String[] mPermissionList = new String[]
+            {
+                Manifest.Permission.WriteExternalStorage,
+                Manifest.Permission.ReadExternalStorage,
+                Manifest.Permission.Camera,
+                Manifest.Permission.RecordAudio
+            };
+
+            foreach (String permissions in mPermissionList)
+            {
+                if (ContextCompat.CheckSelfPermission(this, permissions) != 0)
+                {
+                    ActivityCompat.RequestPermissions(this, new string[] { permissions }, 1);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 闅愯棌搴曢儴瀵艰埅鏍忊�斺�旇櫄鎷熸寜閿�
+        /// </summary>
+        private void HideVirtualButtons()
+        {
+            WindowManagerLayoutParams windowManager = Window.Attributes;
+            var uiOptions = (int)Window.DecorView.SystemUiVisibility;
+            var newUiOptions = (int)uiOptions;
+            newUiOptions = (int)SystemUiFlags.HideNavigation | (int)SystemUiFlags.Immersive | (int)SystemUiFlags.ImmersiveSticky;
+            windowManager.SystemUiVisibility = (StatusBarVisibility)newUiOptions;
+            Window.Attributes = windowManager;
+        }
+
+        /// <summary>
+        /// 鐩戞帶
+        /// </summary>
+        /// <param name="address"></param>
+        private void Monitor(string address)
+        {
+            //鐩戣鍔熻兘 浠庡钩鍙版媺鍙栫洃瑙嗗垪琛紝璋冪敤姝ゆ帴鍙e彲浠ヤ竴鍙颁竴鍙扮洃瑙�
+            if (mPhone != null)
+            {
+                //姝ゅ弬鏁� 鍙互鍚戦棬鍙f満璁惧浼犻�掓暟鎹紝
+                //娉ㄦ剰锛歊equestAudio 璇锋眰瀵规柟闊抽锛孯equestVideo璇锋眰瀵规柟瑙嗛 SendAudio鍙戦�佹湰鍦伴煶棰� SendVideo 鍙戦�佹湰鍦拌棰� 涓�鑸棬鍙d笉鎺ユ敹鍒拌棰戯紝鎵�浠ユ渶濂借缃�0锛屽噺灏戞祦閲忔秷鑰�
+                string UserData = "";
+                string param = "SendAudio=0\r\n" + "SendVideo=0\r\n" + "RequestAudio=0\r\n" + "RequestVideo=0\r\n" + "UserData=" + UserData + "\r\n";
+                mPhone.Monitor(address, param);
+            }
+        }
+
+        private void IniView()
+        {
+            mRemoteFrameContainer = (FrameLayout)FindViewById(Resource.Id.remoteFrame);
+
+            ivBack = (ImageView)FindViewById(Resource.Id.videoBackImg);
+            tvName = (TextView)FindViewById(Resource.Id.nameText);
+
+            tvName.SetText(DeviceName, null);
+
+            ivBack.SetOnClickListener(this);
+        }
+
+        private void IniData()
+        {
+            try
+            {
+                if (mPhone == null)
+                {
+                    string _params = "port=8554\r\n" + "packcode=1021df37c2abe546a4541ca2c4a9c910\r\n"; //鍒濆鍖栧璁茬鍙o紝榛樿灏卞ソ锛岃窡闂ㄥ彛鏈鸿缃鍖归厤,娉ㄦ剰鏂版帴鍙i渶瑕佸鍔爌ackcode鍙傛暟锛岄渶瑕佹妸浣犱滑鐨勫寘鍚嶅彂杩囨潵
+                    mPhone = new VideoPhone(this, this, _params);
+
+                    if (mRemoteSurfaceHolder != null)
+                    {
+                        mPhone.SetRemoteSurfaceHolder(mRemoteSurfaceHolder, "mRemoteSurfaceHolder!=null"); //璁剧疆鏉ョ數绐楀彛
+                    }
+
+                    ViewGroup v = (ViewGroup)FindViewById(Resource.Id.localVideo);
+                    mPhone.SetLocalVideoContainer(v);//璁剧疆鏈湴瑙嗛绐楀彛锛屼竴瀹氳璋冪敤锛屼笉鐒跺悗浼氬嚭鐜版病澹伴煶
+                }
+                else
+                {
+                    mPhone.StopStream();
+                    mPhone.Release();
+                    mPhone = null;
+                }
+            }
+            catch { }
+        }
+
+        protected override void OnResume()
+        {
+            base.OnResume();
+
+            HideVirtualButtons();
+
+            Permissions();
+
+            if (mPhone != null)
+            {
+                mPhone.OnActivityResume();
+            }
+        }
+
+        protected override void OnPause()
+        {
+            base.OnPause();
+            if (mPhone != null)
+            {
+                //mPhone.OnActivityPause();
+            }
+        }
+
+        protected override void OnDestroy()
+        {
+            base.OnDestroy();
+            if (mPhone != null)
+            {
+                mPhone.HangUp();
+                mPhone.Release();
+                mPhone = null;
+                //mPhone.OnActivityDestroy();
+            }
+        }
+
+        public override void OnBackPressed()
+        {
+            if (mPhone != null)
+                mPhone.HangUp();
+
+            Finish();
+        }
+
+        public void OnClick(View v)
+        {
+            if (v.Equals(ivBack))
+            {
+                if (mPhone != null)
+                    mPhone.HangUp();
+
+                Finish();
+            }
+        }
+
+        /// <summary>
+        /// show鍑鸿棰戠敾闈�
+        /// 涓嶈兘鐢╒iew.INVISIBLE鏉ュ畬鍏ㄩ殣钘�,鍚﹀垯MediaCodec.configure浼氭姤ava.lang.IllegalArgumentException: The surface has been released
+        /// </summary>
+        private void ShowRemoteVideo()
+        {
+            try
+            {
+                if (mSurfaceRemote != null)
+                {
+                    return;
+                }
+                mSurfaceRemote = new SurfaceView(this, null);
+                ISurfaceHolder holder = mSurfaceRemote.Holder;
+                holder.AddCallback(this);//ISurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS
+                holder.SetType(SurfaceType.PushBuffers);
+
+                //鍙戠幇绗竴娆how鏃朵細闂睆涓�涓嬶紝鍚庨潰hide鍐峴how鏃朵笉浼氶棯灞�
+                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
+                //v.setId(View.generateViewId());
+                mSurfaceRemote.LayoutParameters = lp;
+                mRemoteFrameContainer.AddView(mSurfaceRemote);
+            }
+            catch { }
+        }
+
+        /// <summary>
+        /// 鍏抽棴鐢婚潰
+        /// </summary>
+        private void HideRemoteVideo()
+        {
+            try
+            {
+                if (mSurfaceRemote != null)
+                {
+                    mRemoteFrameContainer.RemoveView(mSurfaceRemote);
+                    mSurfaceRemote = null;
+                }
+            }
+            catch { }
+        }
+
+        /// <summary>
+        /// 寮瑰嚭宸叉寕鏂彁绀�
+        /// </summary>
+        private void ShowTipDialog(string title, string text, string btnText, bool isClose)
+        {
+            try
+            {
+                TipDiaglog diaglog = new TipDiaglog(this);
+                diaglog.SetAutoClose(isClose);
+                diaglog.SetTitleText(title);//"鎻愮ず"
+                diaglog.SetContentText(text);//"宸叉寕鏂�"
+                diaglog.SetConfirmText(btnText);//"纭"
+                diaglog.SetCanceledOnTouchOutside(false);
+                diaglog.Show();
+                diaglog.Create();
+                diaglog.SetConfirmClickListener(this);
+            }
+            catch (Exception e)
+            {
+                string ss = e.Message;
+            }
+        }
+
+        public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
+        {
+            mRemoteSurfaceHolder = holder;
+            if (mPhone != null)
+            {
+                mPhone.SetRemoteSurfaceHolder(holder, "surfaceChanged");
+            }
+        }
+
+        public void SurfaceCreated(ISurfaceHolder holder)
+        {
+            mRemoteSurfaceHolder = holder;
+            if (mPhone != null)
+            {
+                mPhone.SetRemoteSurfaceHolder(holder, "surfaceCreated");
+            }
+        }
+
+        public void SurfaceDestroyed(ISurfaceHolder holder)
+        {
+            mRemoteSurfaceHolder = null;
+            if (mPhone != null)
+            {
+                mPhone.SetRemoteSurfaceHolder(null, "surfaceDestroyed");
+            }
+        }
+
+        /// <summary>
+        /// 寮�濮嬫媺娴�
+        /// 娉ㄦ剰锛氱敱浜巃ndroid妗嗘灦闄愬埗锛岃婊¤冻濡備笅鏉′欢鎵嶈兘寮�娴�:activity瑕佸湪鍓嶅彴锛屽苟涓攕urfaceview鍙敤
+        /// </summary>
+        /// <param name="reason"></param>
+        private void StartStream(String reason)
+        {
+            if (mPhone != null)
+            {
+                try
+                {
+                    //寮�娴佷箣鍓嶅彲閰嶇疆瑙嗛灏哄锛岀爜鐜囷紝甯х巼 閽堝鐨勬槸鏈湴
+                    //mPhone.SetVideoSize(640, 480);//1920x1080,1280x720,640x480
+                    //mPhone.SetBps(1.5 * 1024 * 1024);
+                    //mPhone.SetFps(30);
+                    mPhone.StartStream();
+                }
+                catch { }
+            }
+        }
+
+        /// <summary>
+        /// 閫氳瘽鐘舵�佸洖璋冩柟娉�
+        /// </summary>
+        /// <param name="msg"></param>
+        public void OnPhoneEvent(string msg)
+        {
+            try
+            {
+                if (monitorFragment != null)
+                {
+                    monitorFragment.OnPhoneEvent(msg);
+                }
+
+                if (reverseCallFragment != null)
+                {
+                    reverseCallFragment.OnPhoneEvent(msg);
+                }
+
+                TextProtocol tp = new TextProtocol();
+                tp.Parse(msg);
+                string event1 = tp.GetString("event");
+                Log.Info("FengLinVideo", "OnPhoneEvent event=" + event1);
+                switch (event1)
+                {
+                    case "EVT_Ringing":
+                        mPhone.RequestCallerSendVideo();
+                        ShowRemoteVideo();
+                        break;
+                    case "EVT_Connected":
+                        if (!mPhone.IsStreamRunning)
+                        {
+                            //鐢变簬android妗嗘灦闄愬埗锛岃婊¤冻濡備笅鏉′欢鎵嶈兘寮�娴�: activity瑕佸湪鍓嶅彴锛屽苟涓攕urfaceview鍙敤
+                            StartStream("EVT_Connected");
+                        }
+                        ShowRemoteVideo();
+                        break;
+                    case "EVT_StartStream":
+                        StartStream("EVT_StreamStream");
+                        break;
+                    case "EVT_StopStream":
+                        mPhone.StopStream();
+                        break;
+                    case "EVT_MonitorConnected":
+                        if (!mPhone.IsStreamRunning)
+                        {
+                            StartStream("EVT_MonitorConnected");
+                        }
+                        ShowRemoteVideo();
+                        break;
+                    case "EVT_HangUp":
+                        HideRemoteVideo();
+                        if (mPhone != null)
+                        {
+                            mPhone.StopStream();
+                        }
+                        //Toast.MakeText(this, GetString(Resource.String.end_call), ToastLength.Short).Show();
+                        this.Finish();
+                        //ShowTipDialog(tip, hang_up, confirm, true);
+                        break;
+                    case "EVT_RECV_CUSTOM_DATA":
+                        string data = tp.GetString("data");
+                        Toast.MakeText(this, GetString(Resource.String.video_success), ToastLength.Short).Show();
+                        break;
+                    case "EVT_SnapAck":
+                        int error = tp.GetInt("error");
+                        string filePath = tp.GetString("filePath");
+                        if (error == 0)
+                        {
+                            Toast.MakeText(this, GetString(Resource.String.video_success), ToastLength.Short).Show();
+                        }
+                        else
+                        {
+                            Toast.MakeText(this, GetString(Resource.String.video_fail), ToastLength.Short).Show();
+                        }
+                        break;
+                }
+            }
+            catch { }
+        }
+
+        public void OnRecvAudioFrame(byte[] p0)
+        {
+            //throw new NotImplementedException();
+        }
+
+        public void OnRecvVideoFrame(byte[] p0)
+        {
+            //throw new NotImplementedException();
+        }
+
+        public void onSureClick(TipDiaglog dialoog, View v, bool bol)
+        {
+            dialoog.Dismiss();
+            if (bol)
+                this.Finish();
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0