Esempio n. 1
0
    bool OnApplicationGoingToQuit()
    {
        Debug.Log("OnApplicationGoingQuit");


        IAliRtcEngine.Destroy();

        Debug.Log("OnApplicationGoingQuit End");
        return(true);
    }
Esempio n. 2
0
    void Start()
    {
#if (UNITY_2018_3_OR_NEWER && UNITY_ANDROID)
        permissionList.Add(Permission.Microphone);
        permissionList.Add(Permission.Camera);
        permissionList.Add(Permission.ExternalStorageRead);
        permissionList.Add(Permission.ExternalStorageWrite);
#endif

#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
        Screen.fullScreen        = false;
        Application.wantsToQuit += OnApplicationGoingToQuit;
#endif
        mControlButton = GameObject.Find("ControlButton").GetComponent <Button>();
        //mControlButton.onClick.AddListener(OnControlButtonClicked);

        GameObject          go      = GameObject.Find("LocalVideoCube");
        VideoDisplaySurface surface = go.AddComponent <VideoDisplaySurface>();

        go      = GameObject.Find("RemoteVideoCube");
        surface = go.AddComponent <VideoDisplaySurface>();

        //create alirtc engine
        string extra = "";
        mRtcEngine = IAliRtcEngine.GetEngine(extra);

        //set callback
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
        IAliRtcEngine.OnJoinChannelNotify          = onJoinChannelNotify;
        IAliRtcEngine.OnPublishNotify              = onPublishNotify;
        IAliRtcEngine.OnSubscribeNotify            = onSubscribeNotify;
        IAliRtcEngine.OnRemoteUserOnLineNotify     = onRemoteUserOnLineNotify;
        IAliRtcEngine.OnRemoteUserOffLineNotify    = onRemoteUserOffLineNotify;
        IAliRtcEngine.OnRemoteTrackAvailableNotify = onRemoteTrackAvailableNotify;
        IAliRtcEngine.OnSubscribeChangedNotify     = onSubscribeChangedNotify;
        IAliRtcEngine.OnLeaveChannelResultNotify   = onLeaveChannelResultNotify;
#else
        mRtcEngine.OnJoinChannelNotify          = onJoinChannelNotify;
        mRtcEngine.OnPublishNotify              = onPublishNotify;
        mRtcEngine.OnSubscribeNotify            = onSubscribeNotify;
        mRtcEngine.OnRemoteUserOnLineNotify     = onRemoteUserOnLineNotify;
        mRtcEngine.OnRemoteUserOffLineNotify    = onRemoteUserOffLineNotify;
        mRtcEngine.OnRemoteTrackAvailableNotify = onRemoteTrackAvailableNotify;
        mRtcEngine.OnSubscribeChangedNotify     = onSubscribeChangedNotify;
        mRtcEngine.OnLeaveChannelResultNotify   = onLeaveChannelResultNotify;
#endif
        //set auto publish and subscribe
        mRtcEngine.SetAutoPublish(true, true);
    }
Esempio n. 3
0
    void Update()
    {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
        if (Time.realtimeSinceStartup - mLastUpdateTime <= mFrameInterval)
        {
            return;
        }
        mLastUpdateTime = Time.realtimeSinceStartup;

        if (!mEnable)
        {
            return;
        }

        IAliRtcEngine engine = IAliRtcEngine.QueryEngine();
        if (ReferenceEquals(engine, null))
        {
            return;
        }

        if (engine.GetVideoRenderData(mUserId, (int)mTrackId, mNativeTextureData, ref mTextureWidth, ref mTextureHeight) == true)
        {
            if (ReferenceEquals(mNativeTexture, null) && mTextureHeight > 0 && mTextureWidth > 0)
            {
                mNativeTexture = new Texture2D(mTextureWidth, mTextureHeight, TextureFormat.RGBA32, false);
                Renderer rend = GetComponent <Renderer>();
                rend.material.mainTexture = mNativeTexture;
            }

            if (!ReferenceEquals(mNativeTexture, null) && (mTextureWidth != mNativeTexture.width || mTextureHeight != mNativeTexture.height))
            {
                mNativeTexture = null;
                mNativeTexture = new Texture2D(mTextureWidth, mTextureHeight, TextureFormat.RGBA32, false);
                Renderer rend = GetComponent <Renderer>();
                rend.material.mainTexture = mNativeTexture;
            }

            if (!ReferenceEquals(mNativeTexture, null))
            {
                mNativeTexture.LoadRawTextureData(mNativeTextureData, mTextureWidth * mTextureHeight * 4);
                mNativeTexture.Apply();
            }
        }
#elif UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE
        Renderer rend = GetComponent <Renderer>();
        if (mEnable)
        {
            if (rend.material.mainTexture == null)
            {
                IAliRtcEngine engine = IAliRtcEngine.QueryEngine();
                if (engine == null)
                {
                    return;
                }
                IntPtr tex = (IntPtr)engine.GenerateTexture();
                nativeTexture            = Texture2D.CreateExternalTexture(720, 1280, TextureFormat.ARGB32, false, false, tex);
                nativeTexture.filterMode = FilterMode.Bilinear;
                nativeTexture.wrapMode   = TextureWrapMode.Clamp;
                nativeTexture.Apply();
                rend.material.mainTexture = nativeTexture;

                if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D)
                {
                    Texture2D         tex2D     = rend.material.mainTexture as Texture2D;
                    int               texId     = (int)tex2D.GetNativeTexturePtr();
                    int               texWidth  = 720;
                    int               texHeight = 1280;
                    AliRTCTextureInfo textureInfo;
                    textureInfo.textureId = texId;
                    textureInfo.flip      = (int)AliRTCRenderMirror.RENDER_MIRROR_FRONT_PREVIEW_ENABLED;
                    engine.SetTexture(textureInfo, mTrackId, mUserId);
                }
            }
        }
#endif
    }
Esempio n. 4
0
    public void SetEnable(bool enable)
    {
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
        mEnable = enable;

        if (!mEnable)
        {
            Renderer rend = GetComponent <Renderer>();
            rend.material.mainTexture = null;
            mNativeTexture            = null;
        }
#elif UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE
        IAliRtcEngine engine = IAliRtcEngine.QueryEngine();
        if (engine == null)
        {
            return;
        }

        Renderer rend = GetComponent <Renderer>();

        if (enable)
        {
            if (mUserId == "")
            {
                if (rend.material.mainTexture == null)
                {
                    IntPtr tex = (IntPtr)engine.GenerateTexture();
                    nativeTexture            = Texture2D.CreateExternalTexture(720, 1280, TextureFormat.ARGB32, false, false, tex);
                    nativeTexture.filterMode = FilterMode.Bilinear;
                    nativeTexture.wrapMode   = TextureWrapMode.Clamp;
                    nativeTexture.Apply();
                    rend.material.mainTexture = nativeTexture;

                    if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D)
                    {
                        Texture2D         tex2D     = rend.material.mainTexture as Texture2D;
                        int               texId     = (int)tex2D.GetNativeTexturePtr();
                        int               texWidth  = 720;
                        int               texHeight = 1280;
                        AliRTCTextureInfo textureInfo;
                        textureInfo.textureId = texId;
                        textureInfo.flip      = (int)AliRTCRenderMirror.RENDER_MIRROR_FRONT_PREVIEW_ENABLED;
                        Debug.Log("AliRTCUnityDemo VideoDisplaySurface SetEnable SetTexture : texId " + texId + " uid : " + mUserId + " mTrackId : " + mTrackId);
                        engine.SetTexture(textureInfo, mTrackId, mUserId);
                    }
                }
            }
            else
            {
                rend.material.mainTexture = null;
            }
        }
        else
        {
            if (rend.material.mainTexture != null && rend.material.mainTexture is Texture2D)
            {
                Texture2D tex   = rend.material.mainTexture as Texture2D;
                int       texId = (int)tex.GetNativeTexturePtr();
                Debug.Log("AliRTCUnityDemo VideoDisplaySurface engine.RemoveTexture texId : " + texId);
                engine.RemoveTexture(texId);
                rend.material.mainTexture = null;
            }
        }

        mEnable = enable;
#endif
    }