Browse Source

修复部分bug

胡佳骏 1 year ago
parent
commit
b77e0ab295

+ 92 - 25
Assets/AgoraVideoAudioManager.cs

@@ -173,19 +173,18 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
 
         // RtcEngine.DisableAudio();
         //  RtcEngine.DisableVideo();
-     //   VideoEncoderConfiguration config = new VideoEncoderConfiguration();
-        //config.dimensions = new VideoDimensions(1280, 720);
+        VideoEncoderConfiguration config = new VideoEncoderConfiguration();
+        //config.dimensions = new VideoDimensions(CustomInfo.mWidth, CustomInfo.mHight);
         //config.frameRate = 15;
         //config.bitrate = 0;
         //    config.orientationMode = ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
-      //  RtcEngine.SetVideoEncoderConfiguration(config);
+        //RtcEngine.SetVideoEncoderConfiguration(config);
         RtcEngine.SetChannelProfile(CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_COMMUNICATION);
         RtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER);
         // _channelName = roomid;
         SenderOptions s = new SenderOptions();
-        s.targetBitrate = 1000;
         RtcEngine.SetExternalVideoSource(true, true, EXTERNAL_VIDEO_SOURCE_TYPE.VIDEO_FRAME,s);
-        RtcEngine.SetRemoteDefaultVideoStreamType(VIDEO_STREAM_TYPE.VIDEO_STREAM_LOW);
+        //RtcEngine.SetRemoteDefaultVideoStreamType(VIDEO_STREAM_TYPE.VIDEO_STREAM_LOW);
         if (DeviceType.type == "DreamGlass")
             RtcEngine.SetAudioProfile(0, AUDIO_SCENARIO_TYPE.AUDIO_SCENARIO_GAME_STREAMING);
         //  RtcEngine.SetLocalVideoMirrorMode(VIDEO_MIRROR_MODE_TYPE.VIDEO_MIRROR_MODE_ENABLED);
@@ -199,7 +198,6 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
         EnableLoacalAudio(CustomInfo.isSendAudio);
         EnableLocalVideo(CustomInfo.isSendVideo);
         isSendVideo = CustomInfo.isSendVideo;
-          StartCoroutine(RenderTexturesScreenCapture());
     }
 
     public void OpenAgoraAudio()
@@ -224,7 +222,7 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
             screenShot = new Texture2D(CustomInfo.mWidth, CustomInfo.mHight, TextureFormat.RGBA32, false);
             StartCoroutine(GetRenederFPS());
         }
-        while (true)
+        while (screenShot!=null)
         {
            // if (isSendVideo)
            //     continue;
@@ -258,26 +256,30 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
     byte[] bts;
     IEnumerator GetRenederFPS()
     {
-        while (true)
+        while (screenShot != null)
         {
-            var req = AsyncGPUReadback.Request(RemoteRtc.Instance.cam2.activeTexture);
+            var req = AsyncGPUReadback.Request(RemoteRtc.Instance.cam2.targetTexture);
             yield return new WaitUntil(() => req.done);
-            if (!req.hasError)
+            if(screenShot!=null)
             {
 
-                if (bts == null)
+                if (!req.hasError)
                 {
-                    bts = new byte[req.layerDataSize];
+
+                    if (bts == null)
+                    {
+                        bts = new byte[req.layerDataSize];
+                    }
+                    req.GetData<byte>().CopyTo(bts);
+                    //   screenShot.LoadRawTextureData(bts);
+                    //  screenShot.Apply();
+                    //  tex.SetPixels32(req.GetData<Color32>().ToArray());
+                    //  img.texture = screenShot;
+                }
+                else
+                {
+                    Debug.LogError("Error AsyncGPUReadbackRequest.hasError");
                 }
-                req.GetData<byte>().CopyTo(bts);
-             //   screenShot.LoadRawTextureData(bts);
-              //  screenShot.Apply();
-                //  tex.SetPixels32(req.GetData<Color32>().ToArray());
-              //  img.texture = screenShot;
-            }
-            else
-            {
-                Debug.LogError("Error AsyncGPUReadbackRequest.hasError");
             }
         }
     }
@@ -292,6 +294,7 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
 
     public void LeaveChannel()
     {
+        cameraStop();
         Debug.Log("LeaveChannel ");
         int msg = RtcEngine.LeaveChannel();
         switch (msg)
@@ -342,7 +345,12 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
         Debug.Log(" AddPeeridUid " + peerid + "   " + uid);
 
         if (dicPeeridAndUid.ContainsKey(peerid))
+        {
+            dicPeeridAndUid[peerid] = uid;
+
             return;
+
+        }
         dicPeeridAndUid.Add(peerid, uid);
     }
 
@@ -352,7 +360,11 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
         Debug.Log(" AddPeeridUid " + peerid + "   " + uid);
 
         if (dicPeeridAndUid.ContainsKey(peerid))
+        {
+
+            dicPeeridAndUid[peerid] = uid;
             return;
+        }
         dicPeeridAndUid.Add(peerid, uid);
     }
 
@@ -368,7 +380,10 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
         for (int i = 0; i < listCustomPeer.Count; i++)
         {
             if (listCustomPeer[i].peerId == peerid)
+            {
                 listCustomPeer.RemoveAt(i);
+                break;
+            }
         }
     }
 
@@ -461,9 +476,39 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
                 break;
         }
     }
+    public void  cameraStart()
+    {
+        if (rc == null)
+        {
+            if (RemoteRtc.Instance.cam2.targetTexture != null)
+                RemoteRtc.Instance.cam2.targetTexture.Release();
+            RemoteRtc.Instance.cam2.targetTexture = new RenderTexture(CustomInfo.mWidth, CustomInfo.mHight, 1);
+            StartCoroutine(RenderTexturesScreenCapture());
+            XRRGBCamera.Instance.playCamera(CustomInfo.mWidth, CustomInfo.mHight);
 
+        }
+    }
+    public void cameraStop()
+    {
+        XRRGBCamera.Instance.stopCamera();
+        if (screenShot != null)
+            Destroy(screenShot);
+        screenShot = null;
+        rc = null;
+        bts = null;
+    }
+    Coroutine rc;
     public void EnableLocalVideo(bool isVideo)
     {
+        if(isVideo)
+        {
+            cameraStart();
+        }
+        else
+        {
+            cameraStop();
+        }
+
         int msg = RtcEngine.MuteLocalVideoStream(!isVideo);
         //RtcEngine.EnableVideo();
         //int msg = RtcEngine.EnableLocalVideo(isVideo);
@@ -479,10 +524,13 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
                 break;
         }
     }
-    public void MuteRemoteAudioStream(string uid, bool isAudio)
+    public void MuteRemoteAudioStream(string peerid, bool isAudio)
     {
-     
-        int msg = RtcEngine.MuteRemoteAudioStream(StringToUint(uid) , !isAudio);
+
+        Debug.Log(peerid);
+        if (!dicPeeridAndUid.ContainsKey(peerid))
+            return;
+        int msg = RtcEngine.MuteRemoteAudioStream(dicPeeridAndUid[peerid], !isAudio);
 
         switch (msg)
         {
@@ -615,7 +663,26 @@ public class AgoraVideoAudioManager : SingletonMono<AgoraVideoAudioManager>
             Debug.Log(listCustomPeer[i].peerId);
             if (dicPeeridAndUid[listCustomPeer[i].peerId] == uid)
             {
-                Debug.Log("RemoteAudioStateChanged   " + 2);
+                switch (state)
+                {
+                    case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STOPPED:
+                        // listCustomPeer[i].isVideo = false;
+                        break;
+                    case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_STARTING:
+                        listCustomPeer[i].isAudio = true;
+                        break;
+                    case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_DECODING:
+                        listCustomPeer[i].isCloseAudio = false;
+                        break;
+                    case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FROZEN:
+                        break;
+                    case REMOTE_AUDIO_STATE.REMOTE_AUDIO_STATE_FAILED:
+                        //  listCustomPeer[i].isVideo = false;
+                        break;
+                    default:
+                        break;
+                }
+                Debug.Log("RemoteAudioStateChanged   " + reason);
                 switch (reason)
                 {
                     case REMOTE_AUDIO_STATE_REASON.REMOTE_AUDIO_REASON_INTERNAL:

+ 1 - 2
Assets/MediaSoup/RemoteRtc.cs

@@ -33,12 +33,11 @@ public class RemoteRtc : SCRtcManager
             CustomInfo.mWidth = 640;
             CustomInfo.mHight = 360;
         }
-        cam2.targetTexture = new RenderTexture(CustomInfo.mWidth, CustomInfo.mHight,1);
         WSHandler.Rtc.onRtcState += onRtcState;
         DontDestroyOnLoad(this.gameObject);
         Instance = this;
 
-        InitCamera();
+      //  InitCamera();
     }
 
     public void InitCamera()

+ 23 - 2
Assets/Remote/Scenes/Remote3.0.unity

@@ -502,6 +502,27 @@ MonoBehaviour:
   - {fileID: 177754137775656777, guid: 8424bf138cfb87e4ba067ca1cf86b920, type: 3}
   window: []
   loginType: 1
+--- !u!1 &440967584 stripped
+GameObject:
+  m_CorrespondingSourceObject: {fileID: 604547950963967445, guid: 1f19c6a2eb9f83340a868c4c9fd2d104,
+    type: 3}
+  m_PrefabInstance: {fileID: 258612956}
+  m_PrefabAsset: {fileID: 0}
+--- !u!114 &440967588
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 440967584}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: d4c33e92d8dc2934e919ffa2ff71afd6, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  isAutoOpen: 0
+  CaptureImage: {fileID: 0}
+  RGBCamTexture: {fileID: 0}
 --- !u!1 &570473685
 GameObject:
   m_ObjectHideFlags: 0
@@ -796,7 +817,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 0, y: 1.6}
+  m_AnchoredPosition: {x: 0, y: 0}
   m_SizeDelta: {x: 100, y: 100}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &760973018
@@ -1907,7 +1928,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 0, y: 0}
-  m_AnchoredPosition: {x: 0, y: 1.6}
+  m_AnchoredPosition: {x: 0, y: 0}
   m_SizeDelta: {x: 100, y: 100}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!114 &973110132107938480

+ 18 - 0
Assets/Remote/ShowLogin/TestMVC/LoginDlg.cs

@@ -339,6 +339,24 @@ namespace ShadowStudio.UI
                 CustomInfo.isSendAudio = bool.Parse(sData["data"]["settings"]["mic"].ToString());
                 CustomInfo.isSendVideo = bool.Parse(sData["data"]["settings"]["camera"].ToString());
                 CustomInfo.camIndex = int.Parse(sData["data"]["settings"]["resolution"].ToString());
+
+                switch (CustomInfo.camIndex-1)
+                {
+                    case 0:
+                        CustomInfo.mWidth = 1920;
+                        CustomInfo.mHight = 1080;
+                        break;
+                    case 1:
+
+                        CustomInfo.mWidth = 1280;
+                        CustomInfo.mHight = 720;
+                        break;
+                    case 2:
+
+                        CustomInfo.mWidth = 640;
+                        CustomInfo.mHight = 360;
+                        break;
+                }
                 NetWorkHeaders.GetUserAvater((JsonData aData) =>
                 {
                     NetWorkHeaders.Instance.getNetTexture(aData["data"]["user"][0].ToString(), null, (Texture tex) => {

+ 10 - 0
Assets/Remote/ShowRoom/PeerSamllView.cs

@@ -121,6 +121,7 @@ public class PeerSamllView : BaseView, IPointerEnterHandler, IPointerExitHandler
         mViewTexture.material.mainTexture = texture;
         if (c is PeerConfig)
         {
+            Debug.Log("initinitinitinitinitinit");
             if (this.inviteUserConfig != null)
             {
                 this.inviteUserConfig = null;
@@ -177,6 +178,15 @@ public class PeerSamllView : BaseView, IPointerEnterHandler, IPointerExitHandler
 
             alltime = 30f;
             istime = false;
+            bool isAdd =false;
+            for (int j = 0; j < AgoraVideoAudioManager.Instance.listCustomPeer.Count; j++)
+            {
+                if(AgoraVideoAudioManager.Instance.listCustomPeer[i].peerId == cPeer.peerId)
+                {
+                    isAdd = true;
+                }
+            }
+            if(!isAdd)
             AgoraVideoAudioManager.Instance.listCustomPeer.Add(cPeer);
         }
         else if (c is InviteUserConfig)

+ 1 - 1
Assets/Remote/ShowRoom/RoomFile.cs

@@ -274,7 +274,7 @@ public class RoomFile : RemoteSingleton<RoomFile>
                 {
                     float Valuex = float.Parse(data["data"]["params"]["x"].ToString());
                     float Valuey = float.Parse(data["data"]["params"]["y"].ToString());
-                    RemoteRtc.Instance.webTex.autoFocusPoint = new Vector2(Valuex, 1 - Valuey);
+                    //RemoteRtc.Instance.webTex.autoFocusPoint = new Vector2(Valuex, 1 - Valuey);
                     //TextMesh textMesh = obj.transform.Find("Text").GetComponent<TextMesh>();
                     //textMesh.text = "**" + RemoteRtc.Instance.webTex.autoFocusPoint;
                 }

+ 9 - 25
Assets/Remote/ShowRoom/RoomMain.cs

@@ -143,27 +143,11 @@ public class RoomMain : RemoteSingleton<RoomMain>
         isSendVideo = CustomInfo.isSendVideo;
         isCloseView = CustomInfo.isCloseView;
         
-        if (isSendAudio)
-        {
-            TimerMgr.Instance.CreateTimer(() => {
-                RemoteRtc.Instance.sendMic(true);
-            }, 1f);
-        }
-        if (isSendVideo)
-        {
-            TimerMgr.Instance.CreateTimer(() => {
-                RemoteRtc.Instance.startCamera();
-                RemoteRtc.Instance.sendVideo(true);
-            }, 1f);
-        }
-        else
-        {
-            RemoteRtc.Instance.startCamera();
-            // RemoteRtc.Instance.meshRender.gameObject.SetActive(false);
-        }
+        sendAudio(isSendAudio);
+        sendVideo(isSendAudio);
         //if(isCloseView)
         //{
-            RemoteRtc.Instance.changeViewOpen();
+        RemoteRtc.Instance.changeViewOpen();
          //   isCloseView = false;
         //}
         //else
@@ -266,15 +250,15 @@ public class RoomMain : RemoteSingleton<RoomMain>
     {
         if (PopPeerView.Instance)
         {
-            PopPeerView.Instance.list.position = new Vector3(0, 0, 0);
-            PopPeerView.Instance.list.eulerAngles = new Vector3(0, 0, 0);
             PopPeerView.Instance.list.SetParent(PopPublic.Instance.transform);
+            PopPeerView.Instance.list.localPosition = new Vector3(0, 0, 0);
+            PopPeerView.Instance.list.localEulerAngles = new Vector3(0, 0, 0);
         }
         if (PopUpInfo.Instance)
         {
-            PopUpInfo.Instance.transform.position = new Vector3(0, 0, 0);
-            PopUpInfo.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
             PopUpInfo.Instance.transform.SetParent(PopPublic.Instance.transform);
+            PopUpInfo.Instance.transform.localPosition = new Vector3(0, 0, 0);
+            PopUpInfo.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
         }
         //sendAudio(false);
         //sendVideo(false);
@@ -308,8 +292,8 @@ public class RoomMain : RemoteSingleton<RoomMain>
         if (ShowRoom.Instance)
         {
             ShowRoom.Instance.ShowMainScreen();
-            ShowRoom.Instance.transform.position = new Vector3(0, 0, 0);
-            ShowRoom.Instance.transform.eulerAngles = new Vector3(0, 0, 0);
+            ShowRoom.Instance.transform.localPosition = new Vector3(0, 0, 0);
+            ShowRoom.Instance.transform.localEulerAngles = new Vector3(0, 0, 0);
         }
         if (GameStart.Instance && GameStart.Instance.systemMenu)
         {

+ 2 - 1
Assets/Remote/ShowRoom/RoomMain.prefab

@@ -2597,6 +2597,7 @@ MonoBehaviour:
   canTwoHandScale: 0
   minScaleRatio: 0.8
   maxScaleRatio: 3
+  isParentDrag: 0
 --- !u!1 &6936254396664479206
 GameObject:
   m_ObjectHideFlags: 0
@@ -2756,7 +2757,7 @@ MonoBehaviour:
   m_FallbackScreenDPI: 96
   m_DefaultSpriteDPI: 96
   m_DynamicPixelsPerUnit: 1
-  m_PresetInfoIsWorld: 0
+  m_PresetInfoIsWorld: 1
 --- !u!114 &5666940668507655411
 MonoBehaviour:
   m_ObjectHideFlags: 0

+ 17 - 0
Assets/Remote/ShowRoom/SysSizeView.cs

@@ -20,6 +20,23 @@ public class SysSizeView : BaseView
 
     public void chooseView()
     {
+        switch(viewIndex)
+        {
+            case 0:
+                CustomInfo.mWidth = 1920;
+                CustomInfo.mHight = 1080;
+                break;
+            case 1:
+
+                CustomInfo.mWidth = 1280;
+                CustomInfo.mHight = 720;
+                break;
+            case 2:
+
+                CustomInfo.mWidth = 640;
+                CustomInfo.mHight = 360;
+                break;
+        }
         CustomInfo.camIndex = viewIndex + 1;
         baselist.updateConfig(CustomInfo.sscList);
     }

+ 0 - 14
Assets/VersionSdk.cs

@@ -1,14 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEngine.UI;
-
-public class VersionSdk : MonoBehaviour
-{
-    // Start is called before the first frame update
-    void Start()
-    {
-        this.GetComponent<Text>().text ="V "+ Application.version;
-    }
-
-}

+ 0 - 11
Assets/VersionSdk.cs.meta

@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 07ae1475383877c49a1289fbc3983403
-MonoImporter:
-  externalObjects: {}
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: