public MeetingResult Subscribe(int accountId, int resourceId, MediaType mediaType)
        {
            MeetingResult result = new MeetingResult();

            Participant participant = null;

            switch (mediaType)
            {
            case MediaType.Camera:

                var cameraParam = StreamParameterProviders.GetParameter <SubscribeCameraStreamParameter>(string.Empty);
                if (_participants.TryGetValue(accountId, out participant))
                {
                    StreamResource <IStreamParameter> streamResource =
                        participant.Resources.SingleOrDefault(res => res.ResourceId == resourceId);

                    if (streamResource == null)
                    {
                        throw new NullReferenceException("流缓存不存在。");
                    }

                    SubscribeVideoModel subscribeCameraModel = cameraParam.GetSubscribeVideoModel();
                    //subscribeCameraModel.AvSyncGroupId = (uint)streamResource.SyncId;
                    subscribeCameraModel.ResourceId = resourceId;
                    subscribeCameraModel.UserId     = accountId.ToString();

                    VideoBox videoBox;
                    if (VideoBoxManager.TryGet(participant.Account, VideoBoxType.None, mediaType, out videoBox))
                    {
                        subscribeCameraModel.VideoRecvModel.DisplayWindow = videoBox.Handle;
                        videoBox.AccountResource.ResourceId = resourceId;
                        videoBox.AccountResource.MediaType  = mediaType;
                    }

                    MeetingResult subscribeCameraResult = _meetingSdkWrapper.SubscribeVideo(subscribeCameraModel);

                    if (subscribeCameraResult.StatusCode == 0)
                    {
                        _eventAggregator.GetEvent <VideoBoxAddedEvent>().Publish(videoBox);

                        streamResource.IsUsed = true;
                        if (videoBox != null)
                        {
                            //await _meetingSdkWrapper.StartRemoteVideoRender(accountId, resourceId, videoBox.Handle,
                            //    (int)videoBox.Host.ActualWidth,
                            //    (int)videoBox.Host.ActualHeight);
                        }
                    }

                    result = subscribeCameraResult;
                }

                break;

            case MediaType.Microphone:

                var micParam = StreamParameterProviders.GetParameter <SubscribeMicStreamParameter>(string.Empty);
                if (_participants.TryGetValue(accountId, out participant))
                {
                    var streamResource =
                        participant.Resources.SingleOrDefault(res => res.ResourceId == resourceId);

                    if (streamResource == null)
                    {
                        throw new NullReferenceException("流缓存不存在。");
                    }

                    SubscribeAudioModel subscribeMicModel = micParam.GetSubscribeAudioModel();

                    subscribeMicModel.UserId = accountId.ToString();
                    //subscribeMicModel.AvSyncGroupId = (uint)streamResource.SyncId;
                    subscribeMicModel.ResourceId = resourceId;
                    string audioOutputDeviceName;
                    if (!_deviceNameAccessor.TryGetSingleName(DeviceName.Speaker, out audioOutputDeviceName))
                    {
                        throw new Exception("扬声器未设置!");
                    }
                    subscribeMicModel.AudioRecvModel.SourceName = audioOutputDeviceName;

                    var subscribeMicResult = _meetingSdkWrapper.SubscribeAudio(subscribeMicModel);
                    if (subscribeMicResult.StatusCode == 0)
                    {
                        streamResource.IsUsed = true;
                    }

                    result = subscribeMicResult;
                }


                break;

            case MediaType.VideoDoc:

                var winCapParam = StreamParameterProviders.GetParameter <SubscribeDataCardStreamParameter>(string.Empty);
                if (_participants.TryGetValue(accountId, out participant))
                {
                    var streamResource =
                        participant.Resources.SingleOrDefault(res => res.ResourceId == resourceId);

                    if (streamResource == null)
                    {
                        throw new NullReferenceException("流缓存不存在。");
                    }

                    SubscribeVideoModel subscribeWinCapModel = winCapParam.GetSubscribeVideoModel();
                    //subscribeWinCapModel.AvSyncGroupId = (uint)streamResource.SyncId;
                    subscribeWinCapModel.ResourceId = resourceId;
                    subscribeWinCapModel.UserId     = accountId.ToString();

                    VideoBox videoBox;
                    var      user = Participants.FirstOrDefault(p => p.Account.AccountId == accountId);

                    if (VideoBoxManager.TryGet(user.Account, VideoBoxType.DataCard, mediaType, out videoBox))
                    {
                        subscribeWinCapModel.VideoRecvModel.DisplayWindow = videoBox.Handle;
                        videoBox.AccountResource.ResourceId = resourceId;
                        videoBox.AccountResource.MediaType  = mediaType;
                    }

                    MeetingResult subscribeWinCapResult = _meetingSdkWrapper.SubscribeVideo(subscribeWinCapModel);

                    if (subscribeWinCapResult.StatusCode == 0)
                    {
                        _eventAggregator.GetEvent <VideoBoxAddedEvent>().Publish(videoBox);

                        streamResource.IsUsed = true;
                        if (videoBox != null)
                        {
                            //await _meetingSdkWrapper.StartRemoteVideoRender(accountId, resourceId, videoBox.Handle,
                            //    (int)videoBox.Host.ActualWidth,
                            //    (int)videoBox.Host.ActualHeight);
                        }
                    }

                    result = subscribeWinCapResult;
                }


                break;

            case MediaType.AudioDoc:
            case MediaType.AudioCaptureCard:

                var docMicParam = StreamParameterProviders.GetParameter <SubscribeMicStreamParameter>(string.Empty);
                if (_participants.TryGetValue(accountId, out participant))
                {
                    var streamResource =
                        participant.Resources.SingleOrDefault(res => res.ResourceId == resourceId);

                    if (streamResource == null)
                    {
                        throw new NullReferenceException("流缓存不存在。");
                    }

                    SubscribeAudioModel subscribeMicModel = docMicParam.GetSubscribeAudioModel();

                    subscribeMicModel.UserId = accountId.ToString();
                    //subscribeMicModel.AvSyncGroupId = (uint)streamResource.SyncId;
                    subscribeMicModel.ResourceId = resourceId;
                    string audioOutputDeviceName;
                    if (!_deviceNameAccessor.TryGetSingleName(DeviceName.Speaker, out audioOutputDeviceName))
                    {
                        throw new Exception("扬声器未设置!");
                    }
                    subscribeMicModel.AudioRecvModel.SourceName = audioOutputDeviceName;

                    var subscribeMicResult = _meetingSdkWrapper.SubscribeAudio(subscribeMicModel);
                    if (subscribeMicResult.StatusCode == 0)
                    {
                        streamResource.IsUsed = true;
                    }

                    result = subscribeMicResult;
                }

                break;

            case MediaType.VideoCaptureCard:

                var dataCardParam = StreamParameterProviders.GetParameter <SubscribeWinCaptureStreamParameter>(string.Empty);
                if (_participants.TryGetValue(accountId, out participant))
                {
                    var streamResource =
                        participant.Resources.SingleOrDefault(res => res.ResourceId == resourceId);

                    if (streamResource == null)
                    {
                        throw new NullReferenceException("流缓存不存在。");
                    }

                    SubscribeVideoModel subscribeDataCardModel = dataCardParam.GetSubscribeVideoModel();
                    //subscribeDataCardModel.AvSyncGroupId = (uint)streamResource.SyncId;
                    subscribeDataCardModel.ResourceId = resourceId;
                    subscribeDataCardModel.UserId     = accountId.ToString();

                    VideoBox    videoBox;
                    Participant user = Participants.FirstOrDefault(p => p.Account.AccountId == accountId);

                    if (VideoBoxManager.TryGet(user.Account, VideoBoxType.WinCapture, mediaType, out videoBox))
                    {
                        subscribeDataCardModel.VideoRecvModel.DisplayWindow = videoBox.Handle;
                        videoBox.AccountResource.ResourceId = resourceId;
                        videoBox.AccountResource.MediaType  = mediaType;
                    }

                    MeetingResult subscribeCameraResult =
                        _meetingSdkWrapper.SubscribeVideo(subscribeDataCardModel);

                    if (subscribeCameraResult.StatusCode == 0)
                    {
                        _eventAggregator.GetEvent <VideoBoxAddedEvent>().Publish(videoBox);

                        streamResource.IsUsed = true;
                        if (videoBox != null)
                        {
                            //await _meetingSdkWrapper.StartRemoteVideoRender(accountId, resourceId, videoBox.Handle,
                            //    (int)videoBox.Host.ActualWidth,
                            //    (int)videoBox.Host.ActualHeight);
                        }
                    }

                    result = subscribeCameraResult;
                }

                break;

            case MediaType.StreamMedia:
                break;

            case MediaType.File:
                break;

            case MediaType.WhiteBoard:
                break;

            case MediaType.RemoteControl:
                break;

            case MediaType.MediaTypeMax:
                break;
            }
            LayoutChanged(mediaType);
            return(result);
        }
Beispiel #2
0
        public bool IsVideoAudioSettingsValid(Window sourceWindow)
        {
            string errorMsg = string.Empty;

            MeetingResult <IList <VideoDeviceModel> > videoDeviceResult = _meetingSdkAgent.GetVideoDevices();

            MeetingResult <IList <string> > micResult = _meetingSdkAgent.GetMicrophones();

            MeetingResult <IList <string> > speakerResult = _meetingSdkAgent.GetLoudSpeakers();

            ConfigManager configManager = _localDataManager.GetSettingConfigData();

            if (configManager == null)
            {
                errorMsg = "参数配置有误!";
                MessageQueueManager.Instance.AddInfo(errorMsg);

                SettingNavView settingNavView = new SettingNavView();
                settingNavView.Show();

                sourceWindow?.Close();
                return(false);
            }

            IDeviceNameAccessor deviceNameAccessor = DependencyResolver.Current.GetService <IDeviceNameAccessor>();

            IEnumerable <string> cameraDeviceName;

            if (videoDeviceResult.Result.Count == 0 || string.IsNullOrEmpty(configManager.MainVideoInfo?.VideoDevice) || !deviceNameAccessor.TryGetName(DeviceName.Camera, new Func <DeviceName, bool>(d => { return(d.Option == "first"); }), out cameraDeviceName) || !videoDeviceResult.Result.Any(vdm => vdm.DeviceName == cameraDeviceName.FirstOrDefault()))
            {
                errorMsg = "人像采集未设置!";
                MessageQueueManager.Instance.AddInfo(errorMsg);

                VideoSettingView videoSettingView = new VideoSettingView();
                videoSettingView.Show();

                sourceWindow?.Close();
                return(false);
            }

            if (configManager.MainVideoInfo?.DisplayWidth == 0 || configManager.MainVideoInfo?.DisplayHeight == 0 || configManager.MainVideoInfo?.VideoBitRate == 0)
            {
                errorMsg = "人像采集参数未设置!";
                MessageQueueManager.Instance.AddInfo(errorMsg);

                VideoSettingView videoSettingView = new VideoSettingView();
                videoSettingView.Show();

                sourceWindow?.Close();

                return(false);
            }

            IEnumerable <string> micDeviceName;

            if (micResult.Result.Count == 0 || string.IsNullOrEmpty(configManager.AudioInfo?.AudioSammpleDevice) || !deviceNameAccessor.TryGetName(DeviceName.Microphone, new Func <DeviceName, bool>(d => { return(d.Option == "first"); }), out micDeviceName) || !micResult.Result.Any(mic => mic == micDeviceName.FirstOrDefault()))
            {
                errorMsg = "人声音源未设置!";
                MessageQueueManager.Instance.AddInfo(errorMsg);

                AudioSettingView audioSettingView = new AudioSettingView();
                audioSettingView.Show();

                sourceWindow?.Close();

                return(false);
            }

            if (configManager.AudioInfo?.SampleRate == 0 || configManager.AudioInfo?.AAC == 0)
            {
                errorMsg = "人声音源参数未设置!";
                MessageQueueManager.Instance.AddInfo(errorMsg);

                AudioSettingView audioSettingView = new AudioSettingView();
                audioSettingView.Show();

                sourceWindow?.Close();

                return(false);
            }

            string audioOutputDeviceName;

            if (speakerResult.Result.Count == 0 || string.IsNullOrEmpty(configManager.AudioInfo?.AudioOutPutDevice) || !deviceNameAccessor.TryGetSingleName(DeviceName.Speaker, out audioOutputDeviceName) || !speakerResult.Result.Any(speaker => speaker == audioOutputDeviceName))
            {
                errorMsg = "放音设备未设置!";
                MessageQueueManager.Instance.AddInfo(errorMsg);

                AudioSettingView audioSettingView = new AudioSettingView();
                audioSettingView.Show();

                sourceWindow?.Close();

                return(false);
            }


            return(true);
        }
Beispiel #3
0
        public string IsVideoAudioSettingsValid()
        {
            MeetingResult <IList <VideoDeviceModel> > videoDeviceResult = _meetingSdkAgent.GetVideoDevices();

            MeetingResult <IList <string> > micResult = _meetingSdkAgent.GetMicrophones();

            MeetingResult <IList <string> > speakerResult = _meetingSdkAgent.GetLoudSpeakers();

            IDeviceNameAccessor deviceNameAccessor = IoC.Get <IDeviceNameAccessor>();

            IEnumerable <string> cameraDeviceName;

            if (videoDeviceResult.Result.Count == 0 || string.IsNullOrEmpty(_configManager.MainVideoInfo?.VideoDevice) || !deviceNameAccessor.TryGetName(DeviceName.Camera, new Func <DeviceName, bool>(d => { return(d.Option == "first"); }), out cameraDeviceName) || !videoDeviceResult.Result.Any(vdm => vdm.DeviceName == cameraDeviceName.FirstOrDefault()))
            {
                return(Messages.WarningNoCamera);
            }

            if (_configManager.MainVideoInfo?.DisplayWidth == 0 || _configManager.MainVideoInfo?.DisplayHeight == 0 || _configManager.MainVideoInfo?.VideoBitRate == 0)
            {
                return(Messages.WarningWrongVideoParams);
            }

            IEnumerable <string> micDeviceName;

            if (micResult.Result.Count == 0 || string.IsNullOrEmpty(_configManager.AudioInfo?.AudioSammpleDevice) || !deviceNameAccessor.TryGetName(DeviceName.Microphone, new Func <DeviceName, bool>(d => { return(d.Option == "first"); }), out micDeviceName) || !micResult.Result.Any(mic => mic == micDeviceName.FirstOrDefault()))
            {
                return(Messages.WarningNoMicrophone);
            }

            if (_configManager.AudioInfo?.SampleRate == 0 || _configManager.AudioInfo?.AAC == 0)
            {
                return(Messages.WarningWrongMicParams);
            }

            string audioOutputDeviceName;

            if (speakerResult.Result.Count == 0 || string.IsNullOrEmpty(_configManager.AudioInfo?.AudioOutPutDevice) || !deviceNameAccessor.TryGetSingleName(DeviceName.Speaker, out audioOutputDeviceName) || !speakerResult.Result.Any(speaker => speaker == audioOutputDeviceName))
            {
                return(Messages.WarningNoSpeaker);
            }

            if (string.IsNullOrEmpty(_configManager.RecordInfo.RecordDirectory))
            {
                return(Messages.WarningRecordDirectoryNotSet);
            }

            if (!Directory.Exists(_configManager.RecordInfo.RecordDirectory))
            {
                return(Messages.WarningRecordDirectoryNotExist);
            }

            return("");
        }