// Update is called once per frame void Update() { // process engine messages (TODO: put in some other place) agora_gaming_rtc.IRtcEngine engine = agora_gaming_rtc.IRtcEngine.QueryEngine(); if (engine == null) { return; } }
/** Sets the local or remote video of users in multiple channels. * * @since v3.0.1 * * @note * - This method only applies to the multi-channel feature. * - Do not call this method and {@link VideoSurface.SetForUser SetForUser} together. * - Ensure that you call this method in the main thread. * - Ensure that you call this method before binding VideoSurface.cs. * * @param channelId The channel name. * @param uid The ID of the remote user, which is retrieved from {@link agora_gaming_rtc.OnUserJoinedHandler OnUserJoinedHandler}. The default value is 0, which means you can see the local video. */ public void SetForMultiChannelUser(string channelId, uint uid) { if (IRtcEngine.QueryEngine() != null) { isMultiChannelWant = true; mUid = uid; mChannelId = channelId; IRtcEngine.QueryEngine().GetVideoRender().AddUserVideoInfo(mChannelId, mUid, 0); } else { Debug.LogError("Plear init agora engine first"); } }
public static AudioRawDataManager GetInstance(IRtcEngine irtcEngine) { if (irtcEngine == null) { return(null); } if (_audioRawDataManagerInstance == null) { _audioRawDataManagerInstance = new AudioRawDataManager(irtcEngine); } return(_audioRawDataManagerInstance); }
public static IRtcEngine GetEngine(string appId) { if (instance == null) { instance = new IRtcEngine(appId); } if (initEngine) { return(instance); } else { Debug.Log("ERROR: ---------------Init Agora Real Time Engine fail------------------------"); return(null); } }
void OnDestroy() { Debug.Log("VideoSurface OnDestroy"); if (videoRender != null && IRtcEngine.QueryEngine() != null) { if (isMultiChannelWant) { if (mUid == 0) { videoRender.RemoveUserVideoInfo(mUid); } else { videoRender.RemoveUserVideoInfo(mChannelId, mUid); } } else { videoRender.RemoveUserVideoInfo(mUid); } } if (data != IntPtr.Zero) { Marshal.FreeHGlobal(data); data = IntPtr.Zero; } if (nativeTexture != null) { Destroy(nativeTexture); nativeTexture = null; } mRenderer = null; }
private AudioPlaybackDeviceManager(IRtcEngine rtcEngine) { mEngine = rtcEngine; }
private AudioEffectManagerImpl(IRtcEngine rtcEngine) { _mEngine = rtcEngine; }
public void SetEngine(IRtcEngine irtcEngine) { _irtcEngine = irtcEngine; }
public static void releaseInstance() { _irtcEngine = null; }
private MetadataObserver(IRtcEngine irtcEngine) { _irtcEngine = irtcEngine; }
private AudioRawDataManager(IRtcEngine irtcEngine) { _irtcEngine = irtcEngine; }
private PacketObserver(IRtcEngine irtcEngine) { _irtcEngine = irtcEngine; }
// Update is called once per frame void Update() { // process engine messages (TODO: put in some other place) agora_gaming_rtc.IRtcEngine engine = agora_gaming_rtc.IRtcEngine.QueryEngine(); if (engine == null) { return; } while (engine.GetMessageCount() > 0) { engine.Poll(); } // render video Renderer rend = GetComponent <Renderer> (); Debug.Log(" VideoSurface render = " + rend); #if UNITY_IOS || UNITY_ANDROID uint uid = mUid; if (mEnable) { // create texture if not existent if (rend.material.mainTexture == null) { //Debug.Log("rend.material.mainTexture"); System.IntPtr texPtr = (System.IntPtr)engine.GenerateNativeTexture(); Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 360, TextureFormat.ARGB32, false, false, texPtr); // FIXME! texture size is subject to change rend.material.mainTexture = nativeTexture; } // update texture if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { //Debug.Log("rend.material.mainTexture is Texture2D"); //Debug.Log("rend.material.mainTexture is Texture2D ThreadID : -->"+System.Threading.Thread.CurrentThread.ManagedThreadId); Texture2D tex = rend.material.mainTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); // update texture (possible size changing) uint texWidth = 0; uint texHeight = 0; if (engine.UpdateTexture(texId, uid, ref texWidth, ref texHeight) == 0) { // TODO: process texture then render } } } else { if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { Texture2D tex = rend.material.mainTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); engine.DeleteTexture(texId); rend.material.mainTexture = null; } } #endif // add your extra effects if (mAdjustTransfrom != null) { Transform trans = rend.transform; mAdjustTransfrom(mUid, gameObject.name, ref trans); } }
// Update is called once per frame void Update() { // process engine messages (TODO: put in some other place) agora_gaming_rtc.IRtcEngine engine = agora_gaming_rtc.IRtcEngine.QueryEngine(); if (engine == null) { return; } // render video RawImage rend = GetComponent <RawImage>(); uint uid = mUid; #if UNITY_STANDALONE_WIN || UNITY_EDITOR || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE if (mEnable) { // create texture if not existent if (rend.material.mainTexture == null && rend.texture == null) { int tmpi = engine.UpdateTexture(0, uid, data, ref defWidth, ref defHeight); if (tmpi == -1) { return; } if (defWidth > 0 && defHeight > 0) { try { // create Texture in the first time update data nativeTexture = new Texture2D((int)defWidth, (int)defHeight, TextureFormat.RGBA32, false); rend.material.mainTexture = nativeTexture; rend.texture = nativeTexture; nativeTexture.LoadRawTextureData(data, (int)defWidth * (int)defHeight * 4); nativeTexture.Apply(); } catch (System.Exception e) { Debug.Log("Exception e = " + e); } } } else if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { int width = 0; int height = 0; int tmpi = engine.UpdateTexture(0, uid, data, ref width, ref height); if (tmpi == -1) { return; } if (width == defWidth && height == defHeight) { try { /* * if width and height don't change ,we only need to update data for texture, do not need to create Texture. */ nativeTexture.LoadRawTextureData(data, (int)width * (int)height * 4); nativeTexture.Apply(); } catch (System.Exception e) { Debug.Log("Exception e = " + e); } } else { try { /* * if width or height changed ,we need to create new texture. */ defWidth = width; defHeight = height; nativeTexture = null; nativeTexture = new Texture2D((int)defWidth, (int)defHeight, TextureFormat.RGBA32, false); rend.material.mainTexture = nativeTexture; rend.texture = nativeTexture; } catch (System.Exception e) { Debug.Log("Exception e = " + e); } } } } else { if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { rend.material.mainTexture = null; } } #else if (mEnable) { // create texture if not existent if (rend.material.mainTexture == null) { System.IntPtr texPtr = (IntPtr)engine.GenerateNativeTexture(); Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 360, TextureFormat.ARGB32, false, false, texPtr); // FIXME! texture size is subject to change rend.material.mainTexture = nativeTexture; } if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { Texture2D tex = rend.material.mainTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); int texWidth = 0; int texHeight = 0; if (engine.UpdateTexture(texId, uid, data, ref texWidth, ref texHeight) == 0) { // TODO: process texture then render } } } else { if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D) { Texture2D tex = rend.material.mainTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); engine.DeleteTexture(texId); rend.material.mainTexture = null; } } #endif }
public AudioEffectManagerImpl(IRtcEngine rtcEngine) { mEngine = rtcEngine; }
private AudioRecordingDeviceManager(IRtcEngine rtcEngine) { mEngine = rtcEngine; }
private VideoRawDataManager(IRtcEngine irtcEngine) { _irtcEngine = irtcEngine; }
// Update is called once per frame void Update() { // process engine messages (TODO: put in some other place) agora_gaming_rtc.IRtcEngine engine = agora_gaming_rtc.IRtcEngine.QueryEngine(); if (engine == null) { return; } while (engine.GetMessageCount() > 0) { engine.Poll(); } // render video Image image = GetComponent <Image>(); #if UNITY_IOS || UNITY_ANDROID uint uid = mUid; if (mEnable) { // create texture if not existent if (testTexture == null) { System.IntPtr texPtr = (System.IntPtr)engine.GenerateNativeTexture(); Texture2D nativeTexture = Texture2D.CreateExternalTexture(640, 360, TextureFormat.ARGB32, false, false, texPtr); // FIXME! texture size is subject to change testTexture = nativeTexture; Sprite m_sprite = Sprite.Create(testTexture, new Rect(0, 0, testTexture.width, testTexture.height), new Vector2(0, 0)); image.sprite = m_sprite; } // update texture if (image.sprite != null && testTexture is Texture2D) { Texture2D tex = testTexture; int texId = (int)tex.GetNativeTexturePtr(); // update texture (possible size changing) uint texWidth = 0; uint texHeight = 0; if (engine.UpdateTexture(texId, uid, ref texWidth, ref texHeight) == 0) { // TODO: process texture then render } } } else { if (image.sprite != null && testTexture is Texture2D) { Texture2D tex = testTexture as Texture2D; int texId = (int)tex.GetNativeTexturePtr(); engine.DeleteTexture(texId); testTexture = null; } } #endif // add your extra effects //if (mAdjustTransfrom != null) //{ // Transform trans = image.transform; // mAdjustTransfrom(mUid, gameObject.name, ref trans); //} }
private VideoDeviceManager(IRtcEngine rtcEngine) { _mEngine = rtcEngine; }
private VideoRender(IRtcEngine rtcEngine) { _rtcEngine = rtcEngine; }
// used internally public void SetEngine(IRtcEngine engine) { _mEngine = engine; }
public void SetEngine(IRtcEngine rtcEngine) { _rtcEngine = rtcEngine; }
// Update is called once per frame void Update() { #if UNITY_STANDALONE_WIN || UNITY_EDITOR || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE if (updateVideoFrameCount >= gameFps) { updateVideoFrameCount = 0; } else { ++updateVideoFrameCount; return; } // process engine messages (TODO: put in some other place) IRtcEngine engine = GetEngine(); if (engine == null || !_initialized) { return; } // render video uint uid = mUid; if (mEnable) { // create texture if not existent if (IsBlankTexture()) { int tmpi = videoRender.UpdateVideoRawData(uid, data, ref defWidth, ref defHeight); if (tmpi == -1) { return; } if (defWidth > 0 && defHeight > 0) { try { // create Texture in the first time update data nativeTexture = new Texture2D((int)defWidth, (int)defHeight, TextureFormat.RGBA32, false); nativeTexture.LoadRawTextureData(data, (int)defWidth * (int)defHeight * 4); FlipTextureHorizontal(nativeTexture); FlipTextureVertically(nativeTexture); ApplyTexture(nativeTexture); nativeTexture.Apply(); } catch (System.Exception e) { Debug.LogError("Exception e = " + e); } } } else { int width = 0; int height = 0; int tmpi = videoRender.UpdateVideoRawData(uid, data, ref width, ref height); // Debug.LogError("Width:"+width+"Height:"+height); if (tmpi == -1) { return; } try { if (width == defWidth && height == defHeight) { /* * if width and height don't change ,we only need to update data for texture, do not need to create Texture. */ nativeTexture.LoadRawTextureData(data, (int)width * (int)height * 4); FlipTextureHorizontal(nativeTexture); FlipTextureVertically(nativeTexture); nativeTexture.Apply(); } else { /* * if width or height changed ,we need to resize texture. */ defWidth = width; defHeight = height; nativeTexture.Resize(defWidth, defHeight); nativeTexture.LoadRawTextureData(data, (int)width * (int)height * 4); FlipTextureHorizontal(nativeTexture); FlipTextureVertically(nativeTexture); nativeTexture.Apply(); } if (resize) { // Debug.LogError(nativeTexture.width + "||" + nativeTexture.height); float rH = Screen.height; float rW = nativeTexture.width * Screen.height * 1f / nativeTexture.height; if (!expert) { mRectTrans.sizeDelta = new Vector2(rW, rH); mRectTrans.localScale = new Vector3(1, -1, 1); } else { mRectTrans.sizeDelta = new Vector2(rW, rH); mRectTrans.localScale = Vector3.one; } } } catch (System.Exception e) { Debug.LogError("Exception e = " + e); } } } else { if (!IsBlankTexture()) { ApplyTexture(null); } } #endif }
// Update is called once per frame void Update() { #if UNITY_STANDALONE_WIN || UNITY_EDITOR || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE if (updateVideoFrameCount >= videoFps / videoFilter) { updateVideoFrameCount = 0; } else { ++updateVideoFrameCount; return; } // process engine messages (TODO: put in some other place) IRtcEngine engine = GetEngine(); if (engine == null || !_initialized || videoRender == null) { return; } // render video uint uid = mUid; if (mEnable) { // create texture if not existent if (IsBlankTexture()) { int tmpi = -1; if (isMultiChannelWant) { if (uid == 0) { tmpi = videoRender.UpdateVideoRawData(uid, data, ref defWidth, ref defHeight); } else { tmpi = videoRender.UpdateVideoRawData(mChannelId, uid, data, ref defWidth, ref defHeight); } } else { tmpi = videoRender.UpdateVideoRawData(uid, data, ref defWidth, ref defHeight); } if (tmpi == -1) { return; } if (defWidth > 0 && defHeight > 0) { try { // create Texture in the first time update data nativeTexture = new Texture2D((int)defWidth, (int)defHeight, TextureFormat.RGBA32, false); nativeTexture.LoadRawTextureData(data, (int)defWidth * (int)defHeight * 4); ApplyTexture(nativeTexture); nativeTexture.Apply(); } catch (System.Exception e) { Debug.LogError("Exception e = " + e); } } } else { if (nativeTexture == null) { Debug.LogError("You didn't initialize native texture, please remove native texture and initialize it by agora."); return; } int width = 0; int height = 0; int tmpi = -1; if (isMultiChannelWant) { if (uid == 0) { tmpi = videoRender.UpdateVideoRawData(uid, data, ref width, ref height); } else { tmpi = videoRender.UpdateVideoRawData(mChannelId, mUid, data, ref width, ref height); } } else { tmpi = videoRender.UpdateVideoRawData(uid, data, ref width, ref height); } if (tmpi == -1) { return; } try { if (width == defWidth && height == defHeight) { /* * if width and height don't change ,we only need to update data for texture, do not need to create Texture. */ nativeTexture.LoadRawTextureData(data, (int)width * (int)height * 4); nativeTexture.Apply(); } else { /* * if width or height changed ,we need to resize texture. */ defWidth = width; defHeight = height; nativeTexture.Resize(defWidth, defHeight); nativeTexture.LoadRawTextureData(data, (int)width * (int)height * 4); nativeTexture.Apply(); } } catch (System.Exception e) { Debug.LogError("Exception e = " + e); } } } else { if (!IsBlankTexture()) { ApplyTexture(null); } } #endif }