public async Task StartAsync() { if (m_mediaCapture != null) { throw new InvalidOperationException("Cannot start while recording"); } m_mediaCapture = new MediaCapture(); await m_mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings() { MediaCategory = MediaCategory.Speech, AudioProcessing = AudioProcessing.Default, MemoryPreference = MediaCaptureMemoryPreference.Auto, SharingMode = MediaCaptureSharingMode.SharedReadOnly, StreamingCaptureMode = StreamingCaptureMode.Audio, }); m_opusSink = await OpusCodec.CreateMediaSinkAsync(m_file); var wawEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High); wawEncodingProfile.Audio.BitsPerSample = 16; wawEncodingProfile.Audio.SampleRate = 48000; wawEncodingProfile.Audio.ChannelCount = 1; await m_mediaCapture.StartRecordToCustomSinkAsync(wawEncodingProfile, m_opusSink); }
public async Task StartAsync() { m_isRecording = true; if (m_isVideo) { var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto); var rotationAngle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper.GetCameraCaptureOrientation()); profile.Video.Properties.Add(new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1"), PropertyValue.CreateInt32(rotationAngle)); m_lowLag = await m_mediaCapture.PrepareLowLagRecordToStorageFileAsync(profile, m_file); await m_lowLag.StartAsync(); } else { var wavEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High); wavEncodingProfile.Audio.BitsPerSample = 16; wavEncodingProfile.Audio.SampleRate = 48000; wavEncodingProfile.Audio.ChannelCount = 1; m_opusSink = await OpusCodec.CreateMediaSinkAsync(m_file); await m_mediaCapture.StartRecordToCustomSinkAsync(wavEncodingProfile, m_opusSink); } }
internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state) { Discord = client; Guild = guild; Channel = channel; SSRCMap = new ConcurrentDictionary <uint, ulong>(); _userSpeaking = new AsyncEvent <UserSpeakingEventArgs>(Discord.EventErrorHandler, "USER_SPEAKING"); _userLeft = new AsyncEvent <VoiceUserLeaveEventArgs>(Discord.EventErrorHandler, "USER_LEFT"); #if !NETSTANDARD1_1 _voiceReceived = new AsyncEvent <VoiceReceiveEventArgs>(Discord.EventErrorHandler, "VOICE_RECEIVED"); #endif _voiceSocketError = new AsyncEvent <SocketErrorEventArgs>(Discord.EventErrorHandler, "VOICE_WS_ERROR"); TokenSource = new CancellationTokenSource(); Configuration = config; Opus = new OpusCodec(48000, 2, Configuration.VoiceApplication); Sodium = new SodiumCodec(); Rtp = new RtpCodec(); ServerData = server; StateData = state; var eps = ServerData.Endpoint; var epi = eps.LastIndexOf(':'); var eph = string.Empty; var epp = 80; if (epi != -1) { eph = eps.Substring(0, epi); epp = int.Parse(eps.Substring(epi + 1)); } else { eph = eps; } ConnectionEndpoint = new ConnectionEndpoint { Hostname = eph, Port = epp }; ReadyWait = new TaskCompletionSource <bool>(); IsInitialized = false; IsDisposed = false; PlayingWait = null; PlaybackSemaphore = new SemaphoreSlim(1, 1); UdpClient = Discord.Configuration.UdpClientFactory(); VoiceWs = Discord.Configuration.WebSocketClientFactory(Discord.Configuration.Proxy); VoiceWs.OnDisconnect += VoiceWS_SocketClosed; VoiceWs.OnMessage += VoiceWS_SocketMessage; VoiceWs.OnConnect += VoiceWS_SocketOpened; VoiceWs.OnError += VoiceWs_SocketErrored; }
public AudioEngine(WsVoiceClient voiceClient, WebSocket socket) { _voiceClient = voiceClient; _socket = socket; _rtpCodec = new RtpCodec(); _opusCodec = new OpusCodec(); Packets = new ConcurrentQueue <AudioPacket>(); _stream = new AudioStream(this); _sources = Singleton.Of <SourceHandler>(); _cache = Singleton.Of <CacheHandler>(); IsReady = true; }
public async Task StartAsync() { m_isRecording = true; if (m_isVideo) { var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga); m_lowLag = await m_mediaCapture.PrepareLowLagRecordToStorageFileAsync(profile, m_file); await m_lowLag.StartAsync(); } else { var wavEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High); wavEncodingProfile.Audio.BitsPerSample = 16; wavEncodingProfile.Audio.SampleRate = 48000; wavEncodingProfile.Audio.ChannelCount = 1; m_opusSink = await OpusCodec.CreateMediaSinkAsync(m_file); await m_mediaCapture.StartRecordToCustomSinkAsync(wavEncodingProfile, m_opusSink); } }
static void Main(string[] args) { const ushort controlPortStarting = 5061; var settingsManager = new CommandLineClientSettingsReader(); if (!settingsManager.ParseArgs(args)) { return; } var settings = settingsManager.ClientSettings; var webClient = new RopuWebClient("https://192.168.1.9:5001/", settingsManager); var keysClient = new KeysClient(webClient, false, encryptionKey => new CachedEncryptionKey(encryptionKey, key => new AesGcmWrapper(key))); var packetEncryption = new PacketEncryption(keysClient); var protocolSwitch = new ProtocolSwitch(controlPortStarting, new PortFinder(), packetEncryption, keysClient, settings); var servingNodeClient = new ServingNodeClient(protocolSwitch); IAudioSource audioSource = settings.FileMediaSource != null ? (IAudioSource) new FileAudioSource(settings.FileMediaSource) : (IAudioSource) new PulseAudioSimple(StreamDirection.Record, "RopuInput"); var audioPlayer = new PulseAudioSimple(StreamDirection.Playback, "RopuOutput"); var audioCodec = new OpusCodec(); var jitterBuffer = new AdaptiveJitterBuffer(2, 50); var mediaClient = new MediaClient(protocolSwitch, audioSource, audioPlayer, audioCodec, jitterBuffer, settings); var callManagementProtocol = new LoadBalancerProtocol(new PortFinder(), 5079, packetEncryption, keysClient); var beepPlayer = new BeepPlayer(new PulseAudioSimple(StreamDirection.Playback, "RopuBeeps")); var ropuClient = new RopuClient(protocolSwitch, servingNodeClient, mediaClient, callManagementProtocol, settings, beepPlayer, webClient, keysClient); var application = new RopuApplication(ropuClient); var imageService = new ImageService(); //TODO: get web address from config var imageClient = new ImageClient(webClient); var groupsClient = new GroupsClient(webClient, imageClient); var usersClient = new UsersClient(webClient); //settings.UserId = usersClient.GetCurrentUser().Result.Id; var pttPage = new PttPage(imageService); var navigator = new Navigator(); var colorService = new ColorService(); navigator.Register <LoginViewModel, LoginView>(() => new LoginView(new LoginViewModel(navigator, webClient, settingsManager), imageService)); navigator.Register <SignupViewModel, SignupPage>(() => new SignupPage(new SignupViewModel(navigator, usersClient), imageService)); Action <Func <Task> > invoke = toDo => Application.Instance.Invoke(toDo); var permissionServices = new PermissionServices(); var pttView = new PttView(new PttViewModel <Color>(ropuClient, settingsManager, groupsClient, usersClient, imageClient, colorService, invoke, permissionServices, webClient, navigator), pttPage); navigator.Register <PttViewModel <Color>, PttView>(() => pttView); navigator.RegisterView("HomeRightPanel", "PttView", () => pttView); var homeView = new HomeView(new HomeViewModel(navigator), navigator, colorService); navigator.Register <HomeViewModel, HomeView>(() => homeView); var browseGroupsView = new BrowseGroupsView(new BrowseGroupsViewModel(groupsClient, navigator)); navigator.Register <BrowseGroupsViewModel, BrowseGroupsView>(() => browseGroupsView); Func <Group, BrowseGroupView> browseGroupViewBuilder = group => new BrowseGroupView(new BrowseGroupViewModel(group, groupsClient, settings, navigator), imageService, navigator, colorService); navigator.Register <BrowseGroupViewModel, BrowseGroupView, Group>(group => browseGroupViewBuilder(group)); var selectIdleGroupView = new SelectIdleGroupView(new SelectGroupViewModel(groupsClient, navigator, ropuClient)); navigator.RegisterView("HomeRightPanel", "SelectIdleGroupView", () => selectIdleGroupView); var mainForm = new MainView(navigator, new MainViewModel(settings, navigator)); mainForm.Icon = imageService.Ropu; var ignore = navigator.ShowModal <HomeViewModel>(); ignore = navigator.ShowPttView(); application.Run(mainForm); }