public static AgoraWindowInfo[] GetWindowInfos(this IAgoraRtcEngine agoraRtcEngine)
        {
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
            var windowCollectionPtr = AgoraRtcNative.EnumerateWindows();
            var windowCollection    =
                (IrisWindowCollection)(Marshal.PtrToStructure(windowCollectionPtr, typeof(IrisWindowCollection)));
            var windowInfos = new AgoraWindowInfo[windowCollection.length];
            for (var i = 0; i < windowCollection.length; i++)
            {
#if NET_2_0_SUBSET
                var window =
                    (IrisWindow)(Marshal.PtrToStructure(
                                     (IntPtr)((long)windowCollection.windows + Marshal.SizeOf(typeof(IrisWindow)) * i),
                                     typeof(IrisWindow)) ?? new IrisWindow());
                windowInfos[i] = new AgoraWindowInfo(window.id, window.name, window.owner_name, window.bounds,
                                                     window.work_area);
#else
                var window =
                    (IrisWindow)(Marshal.PtrToStructure(
                                     windowCollection.windows + Marshal.SizeOf(typeof(IrisWindow)) * i,
                                     typeof(IrisWindow)) ??
                                 new IrisWindow());
                windowInfos[i] = new AgoraWindowInfo(window.id, window.name, window.owner_name, window.bounds,
                                                     window.work_area);
#endif
            }

            AgoraRtcNative.FreeIrisWindowCollection(windowCollectionPtr);

            return(windowInfos);
#else
            throw new PlatformNotSupportedException();
#endif
        }
        public static AgoraDisplayInfo[] GetDisplayInfos(this IAgoraRtcEngine agoraRtcEngine)
        {
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || NET40_OR_GREATER || NETCOREAPP2_0_OR_GREATER
            var displayCollectionPtr = AgoraRtcNative.EnumerateDisplays();
            var displayCollection    =
                (IrisDisplayCollection)(Marshal.PtrToStructure(displayCollectionPtr, typeof(IrisDisplayCollection)) ??
                                        new IrisDisplayCollection());
            var displayInfos = new AgoraDisplayInfo[displayCollection.length];
            for (var i = 0; i < displayCollection.length; i++)
            {
#if NET_2_0_SUBSET
                var display =
                    (IrisDisplay)(Marshal.PtrToStructure(
                                      (IntPtr)((long)displayCollection.displays + Marshal.SizeOf(typeof(IrisDisplay)) * i),
                                      typeof(IrisDisplay)) ?? new IrisDisplay());
                displayInfos[i] = new AgoraDisplayInfo(display.id, display.bounds, display.work_area);
#else
                var display =
                    (IrisDisplay)(Marshal.PtrToStructure(
                                      displayCollection.displays + Marshal.SizeOf(typeof(IrisDisplay)) * i,
                                      typeof(IrisDisplay)) ?? new IrisDisplay());
                displayInfos[i] = new AgoraDisplayInfo(display.id, display.bounds, display.work_area);
#endif
            }

            AgoraRtcNative.FreeIrisDisplayCollection(displayCollectionPtr);

            return(displayInfos);
#else
            throw new PlatformNotSupportedException();
#endif
        }
        internal override int EnableVideoFrameCache(int width, int height, uint uid, string channel_id = "")
        {
            if (_agoraRtcEngine == null)
            {
                AgoraLog.LogError(string.Format("EnableVideoFrameCache ret: ${0}", ERROR_CODE_TYPE.ERR_NOT_INITIALIZED));
                return((int)ERROR_CODE_TYPE.ERR_NOT_INITIALIZED);
            }

            IntPtr irisEngine = (_agoraRtcEngine as AgoraRtcEngine).GetNativeHandler();

            if (irisEngine != IntPtr.Zero)
            {
                var rawDataPtr = AgoraRtcNative.GetIrisRtcRawData(irisEngine);
                var renderPtr  = AgoraRtcNative.GetIrisRtcRenderer(rawDataPtr);
                _renderCacheConfig = new IrisRtcCRendererCacheConfigNative {
                    type = (int)VIDEO_FRAME_TYPE.FRAME_TYPE_RGBA,
                    OnVideoFrameReceived = IntPtr.Zero,
                    resize_width         = width,
                    resize_height        = height
                };
                _irisRtcRendererCacheConfigHandle = AgoraRtcNative.EnableVideoFrameCache(renderPtr, ref _renderCacheConfig, uid, channel_id);
                return((int)ERROR_CODE_TYPE.ERR_OK);
            }
            return((int)ERROR_CODE_TYPE.ERR_NOT_INITIALIZED);
        }
Ejemplo n.º 4
0
        public override bool GetRecordingDeviceMute()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMGetRecordingDeviceMute,
                                                                   JsonMapper.ToJson(param), out _result) == 1);
        }
Ejemplo n.º 5
0
        public override int StopAudioDeviceLoopbackTest()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMStopAudioDeviceLoopbackTest,
                                                                   JsonMapper.ToJson(param), out _result));
        }
Ejemplo n.º 6
0
        public override int GetPlaybackDeviceVolume()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMGetPlaybackDeviceVolume,
                                                                   JsonMapper.ToJson(param), out _result));
        }
Ejemplo n.º 7
0
        public override int StopDeviceTest()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcVideoDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeVideoDeviceManager.kVDMStopDeviceTest, JsonMapper.ToJson(param),
                                                                   out _result));
        }
Ejemplo n.º 8
0
        internal int CallIrisRtcVideoDeviceManagerApi(ApiTypeVideoDeviceManager apiType, string paramJson,
                                                      out string result)
        {
            var ret = AgoraRtcNative.CallIrisRtcVideoDeviceManagerApi(_irisRtcDeviceManager, apiType,
                                                                      paramJson, out _result);

            result = _result.Result;
            return(ret);
        }
Ejemplo n.º 9
0
        public override string GetDevice()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcVideoDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeVideoDeviceManager.kVDMGetDevice, JsonMapper.ToJson(param),
                                                                   out _result) != 0
                            ? null
                            : ((_result.Result.Length == 0) ? null : _result.Result));
        }
Ejemplo n.º 10
0
        public override DeviceInfo[] EnumerateVideoDevices()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcVideoDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeVideoDeviceManager.kVDMEnumerateVideoDevices, JsonMapper.ToJson(param),
                                                                   out _result) != 0
                ? new DeviceInfo[0]
                : AgoraJson.JsonToStructArray <DeviceInfo>(_result.Result));
        }
Ejemplo n.º 11
0
        public override DeviceInfo GetRecordingDeviceInfo()
        {
            var param = new { };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMGetRecordingDeviceInfo,
                                                                   JsonMapper.ToJson(param), out _result) != 0
                ? new DeviceInfo()
                : AgoraJson.JsonToStruct <DeviceInfo>(_result.Result));
        }
Ejemplo n.º 12
0
        public override int SetDevice(string deviceId)
        {
            var param = new
            {
                deviceId
            };

            return(AgoraRtcNative.CallIrisRtcVideoDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeVideoDeviceManager.kVDMSetDevice, JsonMapper.ToJson(param),
                                                                   out _result));
        }
Ejemplo n.º 13
0
        public override int StartDeviceTest(view_t hwnd)
        {
            var param = new
            {
                hwnd = (ulong)hwnd
            };

            return(AgoraRtcNative.CallIrisRtcVideoDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeVideoDeviceManager.kVDMStartDeviceTest, JsonMapper.ToJson(param),
                                                                   out _result));
        }
Ejemplo n.º 14
0
        public override int SetPlaybackDeviceMute(bool mute)
        {
            var param = new
            {
                mute
            };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMSetPlaybackDeviceMute,
                                                                   JsonMapper.ToJson(param), out _result));
        }
Ejemplo n.º 15
0
        public override int SetRecordingDeviceVolume(int volume)
        {
            var param = new
            {
                volume
            };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMSetRecordingDeviceVolume,
                                                                   JsonMapper.ToJson(param), out _result));
        }
Ejemplo n.º 16
0
        public override int StartRecordingDeviceTest(int indicationInterval)
        {
            var param = new
            {
                indicationInterval
            };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMStartRecordingDeviceTest,
                                                                   JsonMapper.ToJson(param), out _result));
        }
Ejemplo n.º 17
0
        public override int StartPlaybackDeviceTest(string testAudioFilePath)
        {
            var param = new
            {
                testAudioFilePath
            };

            return(AgoraRtcNative.CallIrisRtcAudioDeviceManagerApi(_irisRtcDeviceManager,
                                                                   ApiTypeAudioDeviceManager.kADMStartPlaybackDeviceTest,
                                                                   JsonMapper.ToJson(param), out _result));
        }
        internal override void DisableVideoFrameCache(uint uid = 0, string channel_id = "")
        {
            if (_agoraRtcEngine == null)
            {
                AgoraLog.LogError(string.Format("EnableVideoFrameCache ret: ${0}", ERROR_CODE_TYPE.ERR_NOT_INITIALIZED));
                return;
            }

            IntPtr irisEngine = (_agoraRtcEngine as AgoraRtcEngine).GetNativeHandler();

            if (irisEngine != IntPtr.Zero)
            {
                var rawDataPtr = AgoraRtcNative.GetIrisRtcRawData(irisEngine);
                var renderPtr  = AgoraRtcNative.GetIrisRtcRenderer(rawDataPtr);

                AgoraRtcNative.DisableVideoFrameCacheByUid(renderPtr, uid, channel_id);
            }
        }
        internal override bool GetVideoFrame(ref IrisRtcVideoFrame video_frame,
                                             ref bool is_new_frame, uint uid, string channel_id = "")
        {
            if (_agoraRtcEngine == null)
            {
                AgoraLog.LogError(string.Format("EnableVideoFrameCache ret: ${0}", ERROR_CODE_TYPE.ERR_NOT_INITIALIZED));
                return(false);
            }

            IntPtr irisEngine = (_agoraRtcEngine as AgoraRtcEngine).GetNativeHandler();

            if (irisEngine != IntPtr.Zero)
            {
                var rawDataPtr = AgoraRtcNative.GetIrisRtcRawData(irisEngine);
                var renderPtr  = AgoraRtcNative.GetIrisRtcRenderer(rawDataPtr);

                return(AgoraRtcNative.GetVideoFrame(renderPtr, ref video_frame, out is_new_frame, uid, channel_id));
            }
            return(false);
        }
        private static VideoFrame ProcessVideoFrameReceived(IntPtr videoFramePtr, string channelId, uint uid)
        {
            var videoFrame = (IrisRtcVideoFrame)(Marshal.PtrToStructure(videoFramePtr, typeof(IrisRtcVideoFrame)) ??
                                                 new IrisRtcVideoFrame());
            var localVideoFrame = new VideoFrame();

            var ifConverted         = VideoFrameObserver.GetVideoFormatPreference() != VIDEO_FRAME_TYPE.FRAME_TYPE_YUV420;
            var videoFrameConverted = ifConverted
                ? AgoraRtcNative.ConvertVideoFrame(ref videoFrame, VideoFrameObserver.GetVideoFormatPreference())
                : videoFrame;

            if (channelId == "")
            {
                switch (uid)
                {
                case 0:
                    localVideoFrame = LocalVideoFrames.CaptureVideoFrame;
                    break;

                case 1:
                    localVideoFrame = LocalVideoFrames.PreEncodeVideoFrame;
                    break;
                }
            }
            else
            {
                if (!LocalVideoFrames.RenderVideoFrameEx.ContainsKey(channelId))
                {
                    LocalVideoFrames.RenderVideoFrameEx[channelId]      = new Dictionary <uint, VideoFrame>();
                    LocalVideoFrames.RenderVideoFrameEx[channelId][uid] = new VideoFrame();
                }
                else if (!LocalVideoFrames.RenderVideoFrameEx[channelId].ContainsKey(uid))
                {
                    LocalVideoFrames.RenderVideoFrameEx[channelId][uid] = new VideoFrame();
                }

                localVideoFrame = LocalVideoFrames.RenderVideoFrameEx[channelId][uid];
            }

            if (localVideoFrame.height != videoFrameConverted.height ||
                localVideoFrame.yStride != videoFrameConverted.y_stride ||
                localVideoFrame.uStride != videoFrameConverted.u_stride ||
                localVideoFrame.vStride != videoFrameConverted.v_stride)
            {
                localVideoFrame.yBuffer = new byte[videoFrameConverted.y_buffer_length];
                localVideoFrame.uBuffer = new byte[videoFrameConverted.u_buffer_length];
                localVideoFrame.vBuffer = new byte[videoFrameConverted.v_buffer_length];
            }

            if (videoFrameConverted.y_buffer != IntPtr.Zero)
            {
                Marshal.Copy(videoFrameConverted.y_buffer, localVideoFrame.yBuffer, 0,
                             (int)videoFrameConverted.y_buffer_length);
            }
            if (videoFrameConverted.u_buffer != IntPtr.Zero)
            {
                Marshal.Copy(videoFrameConverted.u_buffer, localVideoFrame.uBuffer, 0,
                             (int)videoFrameConverted.u_buffer_length);
            }
            if (videoFrameConverted.v_buffer != IntPtr.Zero)
            {
                Marshal.Copy(videoFrameConverted.v_buffer, localVideoFrame.vBuffer, 0,
                             (int)videoFrameConverted.v_buffer_length);
            }
            localVideoFrame.width        = videoFrameConverted.width;
            localVideoFrame.height       = videoFrameConverted.height;
            localVideoFrame.yBufferPtr   = videoFrameConverted.y_buffer;
            localVideoFrame.yStride      = videoFrameConverted.y_stride;
            localVideoFrame.uBufferPtr   = videoFrameConverted.u_buffer;
            localVideoFrame.uStride      = videoFrameConverted.u_stride;
            localVideoFrame.vBufferPtr   = videoFrameConverted.v_buffer;
            localVideoFrame.vStride      = videoFrameConverted.v_stride;
            localVideoFrame.rotation     = videoFrameConverted.rotation;
            localVideoFrame.renderTimeMs = videoFrameConverted.render_time_ms;
            localVideoFrame.avsync_type  = videoFrameConverted.av_sync_type;

            if (ifConverted)
            {
                AgoraRtcNative.ClearVideoFrame(ref videoFrameConverted);
            }

            return(localVideoFrame);
        }