SCRtcPeer.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class SCRtcPeer
  9. {
  10. [DllImport("NativeCameraPlugin")]
  11. public static extern void SetTextureFromUnity(System.IntPtr texture);
  12. [DllImport("NativeCameraPlugin")]
  13. private static extern IntPtr GetRenderEventFunc();
  14. public string name;
  15. public string peerId;
  16. public string cIdV="";
  17. public string cIdA="";
  18. public Texture2D tex;
  19. public int FPS = 0;
  20. private int TextureID;
  21. public virtual void setTexture(JsonData data)
  22. {
  23. this.tex = new Texture2D(int.Parse(data["data"]["data"]["w"].ToString()), int.Parse(data["data"]["data"]["h"].ToString()), TextureFormat.RGB24, false);
  24. TextureID = this.tex.GetNativeTexturePtr().ToInt32();
  25. SetTextureFromUnity(this.tex.GetNativeTexturePtr());
  26. SCRtcFactory.Instance.mSCRtcHandle.addTextureID(this.cIdV, TextureID);
  27. }
  28. public virtual void setName(string n)
  29. {
  30. name = n;
  31. }
  32. public virtual void changeTexture(JsonData data)
  33. {
  34. setTexture(data);
  35. }
  36. public virtual void updateTexture()
  37. {
  38. if (TextureID != 0)
  39. {
  40. GL.IssuePluginEvent(GetRenderEventFunc(), TextureID);
  41. }
  42. }
  43. public virtual void setInfo(string type, string id)
  44. {
  45. if (type == "video")
  46. {
  47. this.cIdV = id;
  48. }
  49. else
  50. {
  51. this.cIdA = id;
  52. }
  53. }
  54. }