private async Task SendMessageUsingMessageWebSocketAsync(Gabriel.FromClient fromClient) { using (var dataWriter = new DataWriter(this._messageWebSocket.OutputStream)) { dataWriter.WriteBytes(fromClient.ToByteArray()); await dataWriter.StoreAsync(); dataWriter.DetachStream(); } }
private void StartVideoStreamingThread() { IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunAsync( async(workItem) => { while (true) { if (!_frameReadyFlag) { await System.Threading.Tasks.Task.Delay(30); continue; } { byte[] imageData = null; // after compression if (!Const.LOAD_IMAGES) { imageData = _imageDataRaw; // Compress to JPEG bytes //imageData = await Bitmap2JPEG(_imageDataRaw); } // Stream image to the server if (_numTokens > 0) { lock (_tokenLock) { _numTokens--; } Matricies matricies = new Matricies(_cameraToWorldMatrix, _projectionMatrix); _frameIdMatriciesMap.TryAdd(_frameID, matricies); Gabriel.FromClient fromClient = new Gabriel.FromClient { PayloadType = Gabriel.PayloadType.Image, EngineName = Const.ENGINE_NAME, Payload = ByteString.CopyFrom(imageData), EngineFields = Any.Pack(_engineFields), FrameId = _frameID }; await SendMessageUsingMessageWebSocketAsync(fromClient); _frameID++; } _frameReadyFlag = false; _isDoingTimerTask = false; } } }); }