Beispiel #1
0
    public void cutScreen()
    {
        //yield return new WaitForEndOfFrame();
        //videoBytes = Marshal.AllocHGlobal(Screen.width * Screen.height * 4);
        mTexture.ReadPixels(mRect, 0, 0);
        mTexture.Apply();
        byte[]     bytes = mTexture.GetRawTextureData();
        int        size  = Marshal.SizeOf(bytes[0]) * bytes.Length;
        IRtcEngine rtc   = IRtcEngine.QueryEngine();

        if (rtc != null)
        {
            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            externalVideoFrame.type       = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            externalVideoFrame.format     = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
            externalVideoFrame.buffer     = bytes;
            externalVideoFrame.stride     = (int)mRect.width;
            externalVideoFrame.height     = (int)mRect.height;
            externalVideoFrame.cropLeft   = 10;
            externalVideoFrame.cropTop    = 10;
            externalVideoFrame.cropRight  = 10;
            externalVideoFrame.cropBottom = 10;
            externalVideoFrame.rotation   = 10;
            externalVideoFrame.timestamp  = 100;
            int a = rtc.PushVideoFrame(externalVideoFrame);
            Debug.Log(" pushVideoFrame =       " + a);
        }
    }
        public void Start(ulong senderId, int frameWidth, int frameHeight)
        {
            Stop();

            _senderId = (uint)senderId;

            IRtcEngine engine = IRtcEngine.QueryEngine();

            if (engine != null)
            {
                _videoRender = (VideoRender)engine.GetVideoRender();
                _videoRender.SetVideoRenderMode(VIDEO_RENDER_MODE.RENDER_RAWDATA);
                _videoRender.AddUserVideoInfo(_senderId, 0);
            }

            _nativeTexture = new Texture2D(frameWidth, frameHeight, TextureFormat.RGBA32, false);
            OnUpdateTexture?.Invoke(_nativeTexture);

            _customTextureRenderer =
                new PluginTextureRenderer(
                    UpdateRawTextureDataFunction,
                    targetTexture: _nativeTexture,
                    autoDispose: false
                    );

            CustomTextureRenderSystem.Instance.AddRenderer(_customTextureRenderer);
        }
Beispiel #3
0
    IEnumerator shareScreen()
    {
        yield return(new WaitForEndOfFrame());

        IRtcEngine rtc = IRtcEngine.QueryEngine();

        if (rtc != null)
        {
            mTexture.ReadPixels(mRect, 0, 0);
            mTexture.Apply();
            byte[]             bytes = mTexture.GetRawTextureData();
            int                size  = Marshal.SizeOf(bytes[0]) * bytes.Length;
            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            externalVideoFrame.type       = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            externalVideoFrame.format     = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_RGBA;
            externalVideoFrame.buffer     = bytes;
            externalVideoFrame.stride     = (int)mRect.width;
            externalVideoFrame.height     = (int)mRect.height;
            externalVideoFrame.cropLeft   = 10;
            externalVideoFrame.cropTop    = 10;
            externalVideoFrame.cropRight  = 10;
            externalVideoFrame.cropBottom = 10;
            externalVideoFrame.rotation   = 180;
            externalVideoFrame.timestamp  = i++;
            int a = rtc.PushVideoFrame(externalVideoFrame);
            Debug.Log("PushVideoFrame ret = " + a);
        }
    }
Beispiel #4
0
    void Start()
    {
        rtcEngine = IRtcEngine.QueryEngine();
        if (rtcEngine != null)
        {
            rtcEngine.OnStreamMessage += HandleStreamMessage;
        }

        CamStart();
    }
        public void Initialize()
        {
            _rtcEngine = IRtcEngine.QueryEngine();

            if (_rtcEngine != null)
            {
                _audioRawDataManager = AudioRawDataManager.GetInstance(_rtcEngine);
                _initialized         = true;
            }
            else
            {
                _initialized = false;
            }
        }
        private void Initialize()
        {
            IRtcEngine engine = IRtcEngine.QueryEngine();

            if (engine != null)
            {
                var videoRawDataManager = VideoRawDataManager.GetInstance(engine);
                videoRawDataManager.SetOnRenderVideoFrameCallback(OnRenderVideoFrameHandler);
                _IsInitialized = true;
            }
            else
            {
                _IsInitialized = false;
            }
        }
Beispiel #7
0
 void OnApplicationPause(bool paused)
 {
     if (paused)
     {
         if (IRtcEngine.QueryEngine() != null)
         {
             IRtcEngine.QueryEngine().DisableVideo();
         }
     }
     else
     {
         if (IRtcEngine.QueryEngine() != null)
         {
             IRtcEngine.QueryEngine().EnableVideo();
         }
     }
 }
Beispiel #8
0
    void ShareCam(Texture2D tex)
    {
        if (tex == null)
        {
            return;
        }

        byte[] bytes = tex.GetRawTextureData();
//                    Debug.Log(tex.width+"|"+tex.height+"|"+bytes.Length);
        int size = Marshal.SizeOf(bytes[0]) * bytes.Length;
        // 查询是否存在 IRtcEngine 实例。
        IRtcEngine rtc = IRtcEngine.QueryEngine();

        if (rtc != null)
        {
            //   921600
            // 创建外部视频帧。

            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            // 设置视频帧 buffer 类型。
            externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            // 设置像素格式。
            //     if(useCam)
            //    externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_NV12;
            //   else
            externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
            // 应用原始数据。
            externalVideoFrame.buffer = bytes;
            // 设置视频帧宽度(pixel)。
            externalVideoFrame.stride = tex.width;
            // 设置视频帧高度(pixel)。
            externalVideoFrame.height = tex.height;
            // 设置从哪侧移除视频帧的像素。
            externalVideoFrame.cropLeft   = 0;
            externalVideoFrame.cropTop    = 0;
            externalVideoFrame.cropRight  = 0;
            externalVideoFrame.cropBottom = 0;
            // 设置视频帧旋转角度: 0、90、180 或 270。
            externalVideoFrame.rotation = 180;

            // 使用视频时间戳增加 i。
            externalVideoFrame.timestamp = i++;
            // 推送外部视频帧。
            int a = rtc.PushVideoFrame(externalVideoFrame);
        }
    }
 public void PushVideo()
 {
     while (!stop)
     {
         if (outImageBuffer.Count > 0)
         {
             byte[] bytes = outImageBuffer.Dequeue();
             //    toast.text = "x: " + x + "y:" + y + "b:" + bytes.Length;
             // 为字节数组提供足够的空间。
             int size = Marshal.SizeOf(bytes[0]) * bytes.Length;
             // 查询是否存在 IRtcEngine 实例。
             IRtcEngine rtc = IRtcEngine.QueryEngine();
             if (rtc != null)
             {
                 //   921600
                 // 创建外部视频帧。
                 ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
                 // 设置视频帧 buffer 类型。
                 externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
                 // 设置像素格式。
                 externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
                 // 应用原始数据。
                 externalVideoFrame.buffer = bytes;
                 // 设置视频帧宽度(pixel)。
                 externalVideoFrame.stride = (int)mRect.width / 3;
                 // 设置视频帧高度(pixel)。
                 externalVideoFrame.height = (int)mRect.height / 3;
                 // 设置从哪侧移除视频帧的像素。
                 externalVideoFrame.cropLeft   = 10;
                 externalVideoFrame.cropTop    = 10;
                 externalVideoFrame.cropRight  = 10;
                 externalVideoFrame.cropBottom = 10;
                 // 设置视频帧旋转角度: 0、90、180 或 270。
                 externalVideoFrame.rotation = 180;
                 // 使用视频时间戳增加 i。
                 externalVideoFrame.timestamp = i++;
                 // 推送外部视频帧。
                 int a = rtc.PushVideoFrame(externalVideoFrame);
             }
         }
         else
         {
             Thread.Sleep(10);
         }
     }
 }
Beispiel #10
0
    public override void OnSceneLoaded()
    {
        base.OnSceneLoaded();
        GameObject gameObject = GameObject.Find(SelfVideoName);

        if (gameObject != null)
        {
            gameObject.AddComponent <VideoSurface>();
        }

        gameObject = GameObject.Find("ColorController");
        if (gameObject != null)
        {
            colorButtonController = gameObject.GetComponent <ColorButtonController>();
            monoProxy             = colorButtonController.GetComponent <MonoBehaviour>();
        }

        gameObject = GameObject.Find("TouchWatcher");
        if (gameObject != null)
        {
            touchWatcher                      = gameObject.GetComponent <AudienceTouchWatcher>();
            touchWatcher.DrawColor            = colorButtonController.SelectedColor;
            touchWatcher.ProcessDrawing      += ProcessDrawing;
            touchWatcher.NotifyClearDrawings += delegate()
            {
                monoProxy.StartCoroutine(CoClearDrawing());
            };

            colorButtonController.OnColorChange += delegate(Color color)
            {
                touchWatcher.DrawColor = color;
            };
        }

        if (ViewOnly)
        {
            colorButtonController?.gameObject.SetActive(false);
            touchWatcher?.gameObject.SetActive(false);
            GameObject.Find(SelfVideoName)?.SetActive(false);
            GameObject.Find("ToggleButton")?.SetActive(false);
            GameObject.Find("ButtonClear")?.SetActive(false);
        }

        rtcEngine    = IRtcEngine.QueryEngine();
        dataStreamId = rtcEngine.CreateDataStream(reliable: true, ordered: true);
    }
 void OnApplicationQuit()
 {
     Debug.Log("OnApplicationQuit, clean up...");
     if (_previewing)
     {
         var engine = IRtcEngine.QueryEngine();
         if (engine != null)
         {
             engine.StopPreview();
             _previewing = false;
         }
     }
     if (!ReferenceEquals(app, null))
     {
         app.UnloadEngine();
     }
     IRtcEngine.Destroy();
 }
Beispiel #12
0
    IEnumerator shareScreen()
    {
        yield return(new WaitForEndOfFrame());

        // ��ȡ��Ļ���ء�
        mTexture.ReadPixels(mRect, 0, 0);
        // Ӧ�����ء�
        mTexture.Apply();
        // ��ȡ Raw Texture ������Ӧ�õ��ֽ������С�
        byte[] bytes = mTexture.GetRawTextureData();

        int size = Marshal.SizeOf(bytes[0]) * bytes.Length;
        // ��ѯ�Ƿ���� IRtcEngine ʵ����
        IRtcEngine rtc = IRtcEngine.QueryEngine();

        if (rtc != null)
        {
            //   921600
            // �����ⲿ��Ƶ֡��
            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            // ������Ƶ֡ buffer ���͡�
            externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            // �������ظ�ʽ��
            externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
            // Ӧ��ԭʼ���ݡ�
            externalVideoFrame.buffer = bytes;
            // ������Ƶ֡���ȣ�pixel����
            externalVideoFrame.stride = (int)mRect.width;
            // ������Ƶ֡�߶ȣ�pixel����
            externalVideoFrame.height = (int)mRect.height;
            // ���ô��IJ��Ƴ���Ƶ֡�����ء�
            externalVideoFrame.cropLeft   = 10;
            externalVideoFrame.cropTop    = 10;
            externalVideoFrame.cropRight  = 10;
            externalVideoFrame.cropBottom = 10;
            // ������Ƶ֡��ת�Ƕȣ� 0��90��180 �� 270��
            externalVideoFrame.rotation = 180;
            // ʹ����Ƶʱ������� i��
            externalVideoFrame.timestamp = i++;
            // �����ⲿ��Ƶ֡��
            int a = rtc.PushVideoFrame(externalVideoFrame);
        }
    }
    // Push frame to the remote client
    IEnumerator PushFrame(byte[] bytes, int width, int height, System.Action onFinish)
    {
        if (bytes == null || bytes.Length == 0)
        {
            Debug.LogError("Zero bytes found!!!!");
            yield break;
        }

        IRtcEngine rtc = IRtcEngine.QueryEngine();

        //if the engine is present
        if (rtc != null)
        {
            //Create a new external video frame
            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            //Set the buffer type of the video frame
            externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            // Set the video pixel format
            //externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
            externalVideoFrame.format = PixelFormat;
            //apply raw data you are pulling from the rectangle you created earlier to the video frame
            externalVideoFrame.buffer = bytes;
            //Set the width of the video frame (in pixels)
            externalVideoFrame.stride = width;
            //Set the height of the video frame
            externalVideoFrame.height = height;
            //Remove pixels from the sides of the frame
            externalVideoFrame.cropLeft   = 10;
            externalVideoFrame.cropTop    = 10;
            externalVideoFrame.cropRight  = 10;
            externalVideoFrame.cropBottom = 10;
            //Rotate the video frame (0, 90, 180, or 270)
            externalVideoFrame.rotation = 90;
            // increment i with the video timestamp
            externalVideoFrame.timestamp = i++;
            //Push the external video frame with the frame we just created
            int a = rtc.PushVideoFrame(externalVideoFrame);
            Debug.Log(" pushVideoFrame(" + i + ") size:" + bytes.Length + " => " + a);
        }
        yield return(null);

        onFinish();
    }
    public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
    {
        // Stop preview
        if (_previewing)
        {
            var engine = IRtcEngine.QueryEngine();
            if (engine != null)
            {
                engine.StopPreview();
                _previewing = false;
            }
        }

        if (!ReferenceEquals(app, null))
        {
            app.OnSceneLoaded(); // call this after scene is loaded
        }
        SceneManager.sceneLoaded -= OnLevelFinishedLoading;
    }
Beispiel #15
0
    IEnumerator shareScreen()
    {
        yield return(new WaitForEndOfFrame());

        // Reads the Pixels of the rectangle you create.
        mTexture.ReadPixels(mRect, 0, 0);
        // Applies the Pixels read from the rectangle to the texture.
        mTexture.Apply();
        // Gets the Raw Texture data from the texture and apply it to an array of bytes.
        byte[] bytes = mTexture.GetRawTextureData();
        // Gives enough space for the bytes array.
        int size = Marshal.SizeOf(bytes[0]) * bytes.Length;
        // Checks whether the IRtcEngine instance is existed.
        IRtcEngine rtc = IRtcEngine.QueryEngine();

        if (rtc != null)
        {
            // Creates a new external video frame.
            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            // Sets the buffer type of the video frame.
            externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            // Sets the format of the video pixel.
            externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
            // Applies raw data.
            externalVideoFrame.buffer = bytes;
            // Sets the width (pixel) of the video frame.
            externalVideoFrame.stride = (int)mRect.width;
            // Sets the height (pixel) of the video frame.
            externalVideoFrame.height = (int)mRect.height;
            // Removes pixels from the sides of the frame
            //    externalVideoFrame.cropLeft = 10;
            //    externalVideoFrame.cropTop = 10;
            //    externalVideoFrame.cropRight = 10;
            //    externalVideoFrame.cropBottom = 10;
            // Rotates the video frame (0, 90, 180, or 270)
            externalVideoFrame.rotation = 180;
            // Increments i with the video timestamp.
            externalVideoFrame.timestamp = i++;
            // Pushes the external video frame with the frame you create.
            int a = rtc.PushVideoFrame(externalVideoFrame);
        }
    }
Beispiel #16
0
    // 开始屏幕共享。
    IEnumerator shareScreen()
    {
        yield return(new WaitForEndOfFrame());

        // 读取屏幕像素。
        mTexture.ReadPixels(mRect, 0, 0);
        // 应用像素。
        mTexture.Apply();
        // 获取 Raw Texture 并将其应用到字节数组中。
        byte[] bytes = mTexture.GetRawTextureData();
        // 为字节数组提供足够的空间。
        int size = Marshal.SizeOf(bytes[0]) * bytes.Length;
        // 查询是否存在 IRtcEngine 实例。
        IRtcEngine rtc = IRtcEngine.QueryEngine();

        if (rtc != null)
        {
            // 创建外部视频帧。
            ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
            // 设置视频帧 buffer 类型。
            externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
            // 设置像素格式。
            externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA;
            // 应用原始数据。
            externalVideoFrame.buffer = bytes;
            // 设置视频帧宽度(pixel)。
            externalVideoFrame.stride = (int)mRect.width;
            // 设置视频帧高度(pixel)。
            externalVideoFrame.height = (int)mRect.height;
            // 设置从哪侧移除视频帧的像素。
            externalVideoFrame.cropLeft   = 10;
            externalVideoFrame.cropTop    = 10;
            externalVideoFrame.cropRight  = 10;
            externalVideoFrame.cropBottom = 10;
            // 设置视频帧旋转角度: 0、90、180 或 270。
            externalVideoFrame.rotation = 180;
            // 使用视频时间戳增加 i。
            externalVideoFrame.timestamp = i++;
            // 推送外部视频帧。
            int a = rtc.PushVideoFrame(externalVideoFrame);
        }
    }
Beispiel #17
0
    // Start is called before the first frame update
    void Start()
    {
        AssignButtonHandler("ToggleMute", (toggle) =>
        {
            IRtcEngine rtc = IRtcEngine.QueryEngine();
            if (rtc != null)
            {
                rtc.MuteLocalAudioStream(toggle.isOn);
            }
        });

        AssignButtonHandler("ToggleCamera", (toggle) =>
        {
            IRtcEngine rtc = IRtcEngine.QueryEngine();
            if (rtc != null)
            {
                rtc.SwitchCamera();
            }
        });
    }
        public void Stop()
        {
            _disposable?.Dispose();
            _disposable = null;

            _customTextureRenderer?.Dispose();
            _customTextureRenderer = null;

            if (_nativeTexture != null)
            {
                UnityEngine.Object.Destroy(_nativeTexture);
                _nativeTexture = null;
            }

            if (_videoRender != null && IRtcEngine.QueryEngine() != null)
            {
                _videoRender.RemoveUserVideoInfo(_senderId);
                _senderId = 0;
            }
        }
Beispiel #19
0
        private async void SendVideoFrame()
        {
            await UniTask.WaitForEndOfFrame();

            var request = AsyncGPUReadback.Request(_SourceTexture, 0);
            await UniTask.WaitUntil(() => request.done);

            var rawByteArray = request.GetData <byte>().ToArray();

            // Checks whether the IRtcEngine instance is existed.
            IRtcEngine engine = IRtcEngine.QueryEngine();

            if (engine != null)
            {
                // Creates a new external video frame.
                ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame();
                // Sets the buffer type of the video frame.
                externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA;
                // Sets the format of the video pixel.
                externalVideoFrame.format = _VideoPixelFormat;
                // Applies raw data.
                externalVideoFrame.buffer = rawByteArray;
                // Sets the width (pixel) of the video frame.
                externalVideoFrame.stride = _SourceTexture.width;
                // Sets the height (pixel) of the video frame.
                externalVideoFrame.height = _SourceTexture.height;
                // Removes pixels from the sides of the frame
                externalVideoFrame.cropLeft   = 0;
                externalVideoFrame.cropTop    = 0;
                externalVideoFrame.cropRight  = 0;
                externalVideoFrame.cropBottom = 0;
                // Rotates the video frame (0, 90, 180, or 270)
                externalVideoFrame.rotation = 0;
                // Increments with the video timestamp.
                externalVideoFrame.timestamp = _Frame++;
                // Pushes the external video frame with the frame you create.
                engine.PushVideoFrame(externalVideoFrame);
            }
        }
 void SetupEchoTest()
 {
     EchoButton = GameObject.Find("EchoButton").GetComponent <Button>();
     EchoButton.onClick.AddListener(() => {
         var engine = IRtcEngine.QueryEngine();
         if (engine != null)
         {
             if (_echoTesting)
             {
                 engine.StopEchoTest();
                 EchoButton.GetComponentInChildren <Text>().text = "Test Echo";
                 SetAppIdText();
                 _echoTesting = false;
             }
             else
             {
                 _echoTesting = true;
                 EchoButton.GetComponentInChildren <Text>().text = "Stop Echo";
                 engine.StartEchoTest(EchoRecordSecs);
                 StartCoroutine(EchoTestHint());
             }
         }
     });
 }