//Start getting the video stream public async Task StartStream() { try { StartStreaming request = new StartStreaming { Decorate = true }; using (var call = _client.StartStream(request)) { var responseStream = call.ResponseStream; while (await responseStream.MoveNext()) { var imageBytes = responseStream.Current.Image.ToByteArray(); var carAction = responseStream.Current.Action; //Call update UI _mainWindow.HandleStream(imageBytes, carAction); } } } catch (RpcException e) { Console.Write("RPC failed " + e); throw; } }
protected override void HandleStartStreaming(IMessageHeader header, StartStreaming startStreaming) { base.HandleStartStreaming(header, startStreaming); var channelMetadata = Simulator.GetChannelMetadata(header) .Cast <ChannelMetadataRecord>() .ToList(); ChannelMetadata(header, channelMetadata); StartSendingChannelData(header); }
///// <summary> ///// Handles the channel describe. ///// </summary> ///// <param name="args">The <see cref="ProtocolEventArgs{T}"/> instance containing the event data.</param> //protected override void HandleChannelDescribe(ProtocolEventArgs<ChannelDescribe, IList<ChannelMetadataRecord>> args) //{ // var uris = args.Message.Uris.Contains(EtpUri.RootUri) // ? new[] { EtpUris.Witsml131, EtpUris.Witsml141, EtpUris.Witsml200 } // : args.Message.Uris.Select(x => new EtpUri(x)); // // foreach (var family in uris.ToLookup(x => x.Version)) // { // var providers = _providers[family.Key]; // foreach (var provider in providers) // { // var metadata = provider.GetChannelMetadata(Session.Adapter, family.ToArray()); // // metadata.ForEach(m => // { // // Check by uri if we have the metadata in our dictionary. // var channelMetadataRecord = Channels.Values // .Select(c => c.Item2) // .FirstOrDefault(c => c.ChannelUri.EqualsIgnoreCase(m.ChannelUri)); // // // if not add it and set its channelId // if (channelMetadataRecord == null) // { // var channelUri = new EtpUri(m.ChannelUri); // var parentUri = channelUri.Parent; // // // e.g. Trajectory channels // if (string.IsNullOrWhiteSpace(parentUri.ObjectId)) // parentUri = channelUri; // // m.ChannelId = Channels.Keys.Count; // Channels.Add(m.ChannelId, new Tuple<EtpUri, IChannelMetadataRecord>(parentUri, m)); // channelMetadataRecord = m; // } // // args.Context.Add(channelMetadataRecord); // }); // } // } //} /// <summary> /// Handles the start streaming. /// </summary> /// <param name="header">The header.</param> /// <param name="startStreaming">The start streaming.</param> protected override void HandleStartStreaming(IMessageHeader header, StartStreaming startStreaming) { // No action needed if streaming already started if (_tokenSource != null) { return; } base.HandleStartStreaming(header, startStreaming); Request = null; if (_tokenSource == null) { _tokenSource = new CancellationTokenSource(); } var token = _tokenSource.Token; Logger.Debug("Channel Streaming starting."); var channelIds = Channels.Keys.ToList(); Task.Run(() => StartChannelStreaming(header.MessageId, channelIds, token), token); }