public UtxoSet GetMyUtxo(string hash, int index) { var item = transactionMsgs.FirstOrDefault(x => x.Transaction.Hash.Equals(hash)); if (item == null) { return(null); } if (index >= item.Transaction.OutputCount) { return(null); } var transaction = item.Transaction; var output = item.Transaction.Outputs[index]; return(new UtxoSet { BlockHeight = 0, IsCoinbase = false, IsSpent = false, Locktime = transaction.Locktime, TransactionHash = transaction.Hash, Index = output.Index, Amount = output.Amount, BlockHash = null, BlockTime = 0, TransactionTime = transaction.Timestamp, LockScript = output.LockScript, Account = DtoExtensions.GetAccountByLockScript == null ? null : DtoExtensions.GetAccountByLockScript(output.LockScript) }); }
public async Task <DtoCaptureCapabilities> GetVideoCaptureCapabilitiesAsync(DtoMediaDevice device) { MediaDevice checkDevice = DtoExtensions.FromDto(device); var capabilities = await checkDevice.GetVideoCaptureCapabilities(); return(DtoExtensions.ToDto(capabilities.ToArray())); }
public void SetAudioPlayoutDevice(DtoMediaDevice device) { _audioPlayoutDevice = device; _localSettings.Values[MediaSettingsIds.AudioPlayoutDeviceSettings] = device?.Id; if ((null != device) && (null != Media)) { Media.SelectAudioPlayoutDevice(DtoExtensions.FromDto(device)); } }
public IEnumerable <string> Insert(IEnumerable <TransactionPoolItem> msgs) { var hashes = transactionMsgs.Select(x => x.Transaction.Hash); var addMsgs = msgs.Where(x => !hashes.Contains(x.Transaction.Hash)).ToArray(); if (!addMsgs.Any()) { return(null ?? new List <string>()); } var result = addMsgs.Select(x => x.Transaction.Hash); foreach (var msg in addMsgs) { foreach (var item in msg.Transaction.Inputs) { var key = $"{item.OutputTransactionHash}_{item.OutputIndex}"; if (spentUtxoSets.ContainsKey(key)) { spentUtxoSets[key].Add(msg.Transaction.Hash); } else { spentUtxoSets.Add(key, new List <string>() { msg.Transaction.Hash }); } } transactionMsgs.Add(msg); } long useAmount = 0; long addAmount = 0; var inputs = addMsgs.SelectMany(x => x.Transaction.Inputs); var outputs = addMsgs.SelectMany(x => x.Transaction.Outputs); var accounts = AccountDac.Default.GetAccountBook(); var spentUtxos = inputs.Select(item => $"{item.OutputTransactionHash}_{item.OutputIndex}"); var spentSets = UtxoSetDac.Default.Get(spentUtxos); if (spentSets != null) { useAmount = spentSets.Where(x => accounts.Contains(x.Account)).Sum(x => x.Amount); } var addUtxos = outputs.Where(x => accounts.Contains(DtoExtensions.GetAccountByLockScript(x.LockScript))); addAmount = addUtxos.Sum(x => x.Amount); UseBalanceInPool += useAmount; AddBalanceInPool += addAmount; return(result); }
public void Del(IEnumerable <string> hashes) { var items = transactionMsgs.Where(x => hashes.Contains(x.Transaction.Hash)).ToList(); if (!items.Any()) { return; } items.ForEach(x => { transactionMsgs.Remove(x); Storage.Instance.Delete(DbDomains.TxContainer, x.Transaction.Hash); }); foreach (var item in items) { var hashIndexs = item.Transaction.Inputs.Select(x => $"{x.OutputTransactionHash}_{x.OutputIndex}"); foreach (var spentUtxo in hashIndexs) { if (spentUtxoSets.ContainsKey(spentUtxo)) { spentUtxoSets[spentUtxo].Remove(item.Transaction.Hash); } } } long useAmount = 0; long addAmount = 0; var inputs = items.SelectMany(x => x.Transaction.Inputs); var outputs = items.SelectMany(x => x.Transaction.Outputs); var accounts = AccountDac.Default.GetAccountBook(); var spentUtxos = inputs.Select(item => $"{item.OutputTransactionHash}_{item.OutputIndex}"); var spentSets = UtxoSetDac.Default.Get(spentUtxos); if (spentSets != null) { useAmount = spentSets.Where(x => accounts.Contains(x.Account)).Sum(x => x.Amount); } var addUtxos = outputs.Where(x => accounts.Contains(DtoExtensions.GetAccountByLockScript(x.LockScript))); addAmount = addUtxos.Sum(x => x.Amount); UseBalanceInPool -= useAmount; AddBalanceInPool -= addAmount; var delKeys = PaymentDac.Default.Payment_Mem.Where(x => hashes.Contains(x.txId)).Select(x => x.ToString()); PaymentDac.Default.Del(delKeys); }
public bool Insert(TransactionPoolItem msg) { if (transactionMsgs.Any(x => x.Transaction.Hash.Equals(msg.Transaction.Hash))) { return(false); } var accounts = AccountDac.Default.GetAccountBook(); long useAmount = 0; long addAmount = 0; foreach (var item in msg.Transaction.Inputs) { var key = $"{item.OutputTransactionHash}_{item.OutputIndex}"; if (spentUtxoSets.ContainsKey(key)) { spentUtxoSets[key].Add(msg.Transaction.Hash); } else { spentUtxoSets.Add(key, new List <string>() { msg.Transaction.Hash }); } } var spentUtxos = msg.Transaction.Inputs.Select(item => $"{item.OutputTransactionHash}_{item.OutputIndex}"); var spentSets = UtxoSetDac.Default.Get(spentUtxos); if (spentSets != null && spentSets.Any()) { useAmount = spentSets.Where(x => accounts.Contains(x.Account)).Sum(x => x.Amount); } var addUtxos = msg.Transaction.Outputs.Where(x => accounts.Contains(DtoExtensions.GetAccountByLockScript(x.LockScript))); if (addUtxos.Any()) { addAmount = addUtxos.Sum(x => x.Amount); } UseBalanceInPool += useAmount; AddBalanceInPool += addAmount; transactionMsgs.Add(msg); return(true); }
public void Del(string hash) { var item = transactionMsgs.FirstOrDefault(x => x.Transaction.Hash.Equals(hash)); if (item == null) { return; } transactionMsgs.Remove(item); Storage.Instance.Delete(DbDomains.TxContainer, item.Transaction.Hash); var spentUtxos = item.Transaction.Inputs.Select(x => $"{x.OutputTransactionHash}_{x.OutputIndex}"); foreach (var spentUtxo in spentUtxos) { if (spentUtxoSets.ContainsKey(spentUtxo)) { spentUtxoSets[spentUtxo].Remove(hash); } } long useAmount = 0; long addAmount = 0; var outputs = item.Transaction.Outputs; var accounts = AccountDac.Default.GetAccountBook(); var spentSets = UtxoSetDac.Default.Get(spentUtxos); if (spentSets != null) { useAmount = spentSets.Where(x => accounts.Contains(x.Account)).Sum(x => x.Amount); } var addUtxos = outputs.Where(x => accounts.Contains(DtoExtensions.GetAccountByLockScript(x.LockScript))); addAmount = addUtxos.Sum(x => x.Amount); UseBalanceInPool -= useAmount; AddBalanceInPool -= addAmount; var delKeys = PaymentDac.Default.Payment_Mem.Where(x => hash.Equals(x.txId)).Select(x => x.ToString()); PaymentDac.Default.Del(delKeys); }
public override async Task OnEnteringState() { Debug.Assert(Context.PeerConnection == null); Context.VoipCoordinator.StartOutgoingCall(_callRequest); var config = new RTCConfiguration { IceServers = WebRtcSettingsUtils.ToRTCIceServer(IceServerSettings.IceServers) }; Context.PeerConnection = new RTCPeerConnection(config); Context.LocalStream = await Context.Media.GetUserMedia(new RTCMediaStreamConstraints { videoEnabled = _callRequest.VideoEnabled, audioEnabled = true }); Context.PeerConnection.AddStream(Context.LocalStream); var sdpOffer = await Context.PeerConnection.CreateOffer(); var sdpString = sdpOffer.Sdp; SdpUtils.SelectCodecs(ref sdpString, DtoExtensions.FromDto(Context.GetAudioCodec()), DtoExtensions.FromDto(Context.GetVideoCodec())); sdpOffer.Sdp = sdpString; await Context.PeerConnection.SetLocalDescription(sdpOffer); var tracks = Context.LocalStream.GetVideoTracks(); if (tracks.Count > 0) { #if WIN10 var source = Context.Media.CreateMediaSource(tracks[0], VoipContext.LocalMediaStreamId); #else var source = Context.Media.CreateMediaStreamSource(tracks[0], 30, VoipContext.LocalMediaStreamId); #endif Context.LocalVideoRenderer.SetupRenderer(Context.ForegroundProcessId, source, Context.LocalVideoControlSize); } Context.SendToPeer(RelayMessageTags.SdpOffer, sdpOffer.Sdp); }
public DtoCodecInfos GetVideoCodecs() { return(DtoExtensions.ToDto(WebRTC.GetVideoCodecs().ToArray())); }
public DtoMediaDevices GetAudioPlayoutDevices() { return(DtoExtensions.ToDto(Media.GetAudioPlayoutDevices().ToArray())); }
/// <summary> /// On Win10 in a background task, WebRTC initialization has to be done /// when we have access to the resources. That's inside an active /// voip call. /// This function must be called after VoipCoordinator.StartVoipTask() /// </summary> /// <returns></returns> public void InitializeRTC() { if (Media == null) { WebRTC.Initialize(_dispatcher); Media = WebRTCMedia.CreateMedia(); WebRTCMedia.SetDisplayOrientation(_displayOrientation); // Uncomment the following line to enable WebRTC logging. // Logs are: // - Saved to local storage. Log folder location can be obtained using WebRTC.LogFolder() // - Sent over network if client is connected to TCP port 47003 //WebRTC.EnableLogging(LogLevel.LOGLVL_INFO); } if (DisplayOrientations.None != _displayOrientation) { WebRTCMedia.SetDisplayOrientation(_displayOrientation); } string videoDeviceId = string.Empty; if (_localSettings.Values.ContainsKey(MediaSettingsIds.VideoDeviceSettings)) { videoDeviceId = (string)_localSettings.Values[MediaSettingsIds.VideoDeviceSettings]; } var videoDevices = Media.GetVideoCaptureDevices(); var selectedVideoDevice = videoDevices.FirstOrDefault(d => d.Id.Equals(videoDeviceId)); selectedVideoDevice = selectedVideoDevice ?? videoDevices.FirstOrDefault(); if (selectedVideoDevice != null) { Media.SelectVideoDevice(selectedVideoDevice); } string audioDeviceId = string.Empty; if (_localSettings.Values.ContainsKey(MediaSettingsIds.AudioDeviceSettings)) { audioDeviceId = (string)_localSettings.Values[MediaSettingsIds.AudioDeviceSettings]; } var audioDevices = Media.GetAudioCaptureDevices(); var selectedAudioDevice = audioDevices.FirstOrDefault(d => d.Id.Equals(audioDeviceId)); selectedAudioDevice = selectedAudioDevice ?? audioDevices.FirstOrDefault(); if (selectedAudioDevice != null) { Media.SelectAudioDevice(selectedAudioDevice); } string audioPlayoutDeviceId = string.Empty; if (_localSettings.Values.ContainsKey(MediaSettingsIds.AudioPlayoutDeviceSettings)) { audioPlayoutDeviceId = (string)_localSettings.Values[MediaSettingsIds.AudioPlayoutDeviceSettings]; } var audioPlayoutDevices = Media.GetAudioPlayoutDevices(); var selectedAudioPlayoutDevice = audioPlayoutDevices.FirstOrDefault(d => d.Id.Equals(audioPlayoutDeviceId)); selectedAudioPlayoutDevice = selectedAudioPlayoutDevice ?? audioPlayoutDevices.FirstOrDefault(); if (selectedAudioPlayoutDevice != null) { Media.SelectAudioPlayoutDevice(selectedAudioPlayoutDevice); } int videoCodecId = int.MinValue; if (_localSettings.Values.ContainsKey(MediaSettingsIds.VideoCodecSettings)) { videoCodecId = (int)_localSettings.Values[MediaSettingsIds.VideoCodecSettings]; } var videoCodecs = WebRTC.GetVideoCodecs(); var selectedVideoCodec = videoCodecs.FirstOrDefault(c => c.Id.Equals(videoCodecId)); SetVideoCodec(DtoExtensions.ToDto(selectedVideoCodec ?? videoCodecs.FirstOrDefault())); int audioCodecId = int.MinValue; if (_localSettings.Values.ContainsKey(MediaSettingsIds.AudioCodecSettings)) { audioCodecId = (int)_localSettings.Values[MediaSettingsIds.AudioCodecSettings]; } var audioCodecs = WebRTC.GetAudioCodecs(); var selectedAudioCodec = audioCodecs.FirstOrDefault(c => c.Id.Equals(audioCodecId)); SetAudioCodec(DtoExtensions.ToDto(selectedAudioCodec ?? audioCodecs.FirstOrDefault())); if (_localSettings.Values.ContainsKey(MediaSettingsIds.PreferredVideoCaptureWidth) && _localSettings.Values.ContainsKey(MediaSettingsIds.PreferredVideoCaptureHeight) && _localSettings.Values.ContainsKey(MediaSettingsIds.PreferredVideoCaptureFrameRate)) { WebRTC.SetPreferredVideoCaptureFormat((int)_localSettings.Values[MediaSettingsIds.PreferredVideoCaptureWidth], (int)_localSettings.Values[MediaSettingsIds.PreferredVideoCaptureHeight], (int)_localSettings.Values[MediaSettingsIds.PreferredVideoCaptureFrameRate]); } ResolutionHelper.ResolutionChanged += (id, width, height) => { if (id == LocalMediaStreamId) { LocalVideoRenderer.ResolutionChanged(width, height); } else if (id == PeerMediaStreamId) { RemoteVideoRenderer.ResolutionChanged(width, height); } }; FrameCounterHelper.FramesPerSecondChanged += (id, frameRate) => { if (id == LocalMediaStreamId) { LocalVideo_FrameRateUpdate(frameRate); } else if (id == PeerMediaStreamId) { RemoteVideo_FrameRateUpdate(frameRate); } }; }
private static string Entity2StoreOwnerFullName(this vw_USER_EventsLog entity) { return(entity.StoreOwnerUserID == null ? string.Empty : DtoExtensions.CombineFullName(entity.StoreOwnerFirstName, entity.StoreOwnerLastName, entity.StoreOwnerNickname)); }
private static string Entity2VideoAuthorFullName(this vw_USER_EventsLog entity) { return(entity.VideoAuthorId == null ? string.Empty : DtoExtensions.CombineFullName(entity.VideoAuthorFirstName, entity.VideoAuthorLastName, entity.VideoAuthorNickname)); }
private static string GetUserName(this vw_USER_EventsLog entity) { return(entity.UserID == null ? string.Empty : DtoExtensions.CombineFullName(entity.FirstName, entity.LastName, entity.Nickname)); }
public void Setup() { _mocker = new AutoMocker(); DtoExtensions.Reset(); }