Exemple #1
0
        // 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
        }
Exemple #2
0
        // 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
        }