public void DibujarSimulacion() { //cargo los labels lblserverpower.Text = "Serve Power: " + GetServerPower(ServerPower); lblservereffect.Text = "Effect: " + GetServerEffect(ServerEffect); lblserverdirection.Text = "Direction: " + GetServerDirection(ServerDirection); lblserverhilt.Text = "Serve Hilt: " + GetServerHilt(ServerHilt); lblserverhilttype.Text = "Serve Hilt Type: " + GetServerHiltType(ServerHilt); lblservershottype.Text = "Serve Shot Type:" + GetServerShotType(ServerShotType); //Posiciono los jugadores y la bola ResetBallRight(); ResetServerPosition(); ResetReceptorPosition(); VideoSample video = new VideoSample(); String tipoSaque = VideoSample.SaquePlano; if (ServerEffect == 1) { tipoSaque = VideoSample.SaqueConEfecto; } video.PlayVideo(tipoSaque); video.Show(); Show(); graficar = new Thread(new ThreadStart(this.MoveBall)); graficar.Start(); }
private void SendSamples() { while (_sampleQueue.Count() > 0 && _outstandingGetVideoSampleCount > 0) { if (!(shutdownEvent.WaitOne(0))) { VideoSample vs = _sampleQueue.Dequeue(); Stream s = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.AsStream(vs.buffer); // Send out the next sample MediaStreamSample msSamp = new MediaStreamSample( _videoDesc, s, 0, s.Length, (long)vs.hnsPresentationTime, (long)vs.hnsSampleDuration, _emptySampleDict); ReportGetSampleCompleted(msSamp); _outstandingGetVideoSampleCount--; } else { // If video rendering is shutting down we should no longer deliver frames return; } } }
public RtspHandler(Uri uri) { _rtspClient = new RtspClient(uri, RtspClient.ClientProtocolType.Udp) { AutomaticallyReconnect = true, /*ConfigureSocket = (s) => { * s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); * }*/ }; _videoStreamInfo = new StreamInfo(OnVideoPacket); _audioStreamInfo = new StreamInfo(OnAudioPacket); _playStarted = new BehaviorSubject <bool>(false); _lastVideoSample = null; #if DEBUG _rtspClient.Logger = new DebuggingLogger(); _rtspClient.OnConnect += (s, o) => Trace.WriteLine("RtspClient::OnConnect()"); _rtspClient.OnDisconnect += (s, o) => Trace.WriteLine("RtspClient::OnDisconnect()"); _rtspClient.OnPause += (s, o) => Trace.WriteLine("RtspClient::OnPause()"); _rtspClient.OnPlay += (s, o) => Trace.WriteLine("RtspClient::OnPlay()"); _rtspClient.OnRequest += (s, req) => Trace.WriteLine("RtspClient::OnRequest(): " + req.HeaderEncoding.GetString(req.PrepareStatusLine(false).ToArray())); _rtspClient.OnResponse += (s, req, res) => Trace.WriteLine($"RtspClient::OnResponse(): {req.MethodString} => {res?.StatusCode} {res?.HttpStatusCode}\n{res?.Body}"); _rtspClient.OnStop += (s, a) => Trace.WriteLine("RtspClient::OnStop()"); #endif }
private void AddVideoParamaterSet(VideoSample sample) { var configpart = VideoParameter.Split(','); // Add SPS sample.BeginUnit(); sample.AddUnitData(Convert.FromBase64String(configpart[0])); sample.EndUnit(); // Add PPS sample.BeginUnit(); sample.AddUnitData(Convert.FromBase64String(configpart[1])); sample.EndUnit(); }
private IRtspSample OnVideoPacket(long sampleTime, RtpPacket packet, bool discontinuity) { if (discontinuity) { // clear fragmented NAL unit _lastVideoSample = null; } var data = packet.PayloadData.ToArray(); if (data.Length < 1) { return(null); } // Interleaved mode is not supported. var nalUnitFlags = data[0] & 0xe0; var nalUnitType = data[0] & 0x1f; if (nalUnitType <= 23) { // NAL unit (one packet, one NAL) //Trace.WriteLine($"RtspHandler::OnVideoPacket(): NALType({nalUnitType}) Timestamp={packet.Timestamp} Length={data.Length}"); var sample = new VideoSample(sampleTime, discontinuity, (nalUnitType == 5)); if (sampleTime == 0) { AddVideoParamaterSet(sample); } sample.BeginUnit(); sample.AddUnitData(data); sample.EndUnit(); sample.Commit(); return(sample); } if (nalUnitType == 24) { // STAP-A (Single-time aggregation packet: one packet, multiple NALs) // TBD Debug.WriteLine("RtspHandler::OnVideoPacket(): STAP-A"); return(null); } if (nalUnitType == 28) { // FU-A (Fragmentation Units: multiple packets, one NAL) //var fuIndicator = data[0]; var fuHeader = data[1]; if ((fuHeader & 0x80) != 0) // check start bit // start of a fragmented NAL unit { var fuNalUnitType = fuHeader & 0x1f; //Trace.WriteLine($"RtspHandler::OnVideoPacket(): FU-A Start NALType({fuNalUnitType}) Timestamp={packet.Timestamp} Length={data.Length - 2}"); if (_lastVideoSample != null) { Debug.WriteLine("RtspHandler::OnVideoPacket(): Invalid fragmented NAL start."); } _lastVideoSample = new VideoSample(sampleTime, discontinuity, (fuNalUnitType == 5)); if (sampleTime == 0) { AddVideoParamaterSet(_lastVideoSample); } _lastVideoSample.BeginUnit(); _lastVideoSample.AddUnitData((byte)(nalUnitFlags | fuNalUnitType)); _lastVideoSample.AddUnitData(data.Skip(2)); return(null); } if (discontinuity) { Debug.WriteLine("RtspHandler::OnVideoPacket(): Ignore middle-started fragmented NAL."); return(null); } if ((fuHeader & 0x40) != 0) // check end bit // end of a fragmented NAL unit //Trace.WriteLine($"RtspHandler::OnVideoPacket(): FU-A End Timestamp={packet.Timestamp} Length={data.Length - 2}"); { if (_lastVideoSample != null) { _lastVideoSample.AddUnitData(data.Skip(2)); _lastVideoSample.EndUnit(); _lastVideoSample.Commit(); var sample = _lastVideoSample; _lastVideoSample = null; return(sample); } else { Debug.WriteLine("RtspHandler::OnVideoPacket(): Invalid fragmented NAL end."); return(null); } } // following FU payload //Trace.WriteLine($"RtspHandler::OnVideoPacket(): FU-A Continue Timestamp={packet.Timestamp} Length={data.Length - 2}"); if (_lastVideoSample != null) { _lastVideoSample.AddUnitData(data.Skip(2)); } else { Debug.WriteLine("RtspHandler::OnVideoPacket(): Invalid fragmented NAL."); } return(null); } Debug.WriteLine($"RtspHandler::OnVideoPacket(): Unknown NALType({nalUnitType})"); return(null); }
private void SubmitVideoSample(VideoSample videoSample) { Stream sampleStream = WindowsRuntimeBufferExtensions.AsStream(videoSample.buffer); // Send out the next NAL MediaStreamSample mediaStreamSamp = new MediaStreamSample( videoDesc, sampleStream, 0, sampleStream.Length, (long)videoSample.frameNumber, emptySampleDict); Debug.WriteLine("Submitting video samples"); ReportGetSampleCompleted(mediaStreamSamp); }
private void EnqueueNal(byte[] buf, int nalStart, int nalEnd, ulong frameNumber) { int nalLength = nalEnd - nalStart; byte[] nal = new byte[nalLength]; Array.ConstrainedCopy(buf, nalStart, nal, 0, nalLength); VideoSample videoSample = new VideoSample(nal.AsBuffer(), frameNumber); bool canDirectSubmit; lock (nalQueueLock) { if (nalQueue.Count == 0 && outstandingGetVideoSampleCount > 0) { outstandingGetVideoSampleCount--; canDirectSubmit = true; } else { canDirectSubmit = false; nalQueue.Enqueue(videoSample); } } if (canDirectSubmit) { Debug.WriteLine("Direct submitting NALU"); SubmitVideoSample(videoSample); } else { Debug.WriteLine("Queued NALU"); } }