public MediaPipeline CreatePipeline(ISource src, bool isLive) { return(MediaPipeline.CreateBuilder() .Source(src) .Transform(new FacialDiscoveryTransform()) .Sink(_sink) .Build()); }
public RtspSession(ISource source, byte payloadType, IPEndPoint target) { _pipeline = MediaPipeline.CreateBuilder() .Source(source) .Transform(new RtpPacketizer(new DefaultRtpClock(90000), SSRC, payloadType)) .Sink(new UdpSink(target)) .Build(); }
public async Task StartStream() { await Task.Run(() => { _pipeline = MediaPipeline.CreateBuilder() .Source(new OpenCVRtspSource(SelectDataInterface(_dataSource), TimeSpan.FromMilliseconds(250))) .Transform(_transform) .Sink(this) .Build(); _pipeline.Start(); }); }
private static MediaPipeline MapMediaServicesSet(MediaServicesSetConfig configMediaServiceSet) { var mediaPipeline = new MediaPipeline(); mediaPipeline.Name = configMediaServiceSet.Name; mediaPipeline.Deployments = configMediaServiceSet.MediaServicesAccounts .Denull() .Select(MapMediaServicesAccounts) .Where(ad => null != ad) .ToList(); return(mediaPipeline); }
public void TestInterleaved() { var transport = TransportHeader.CreateBuilder() .Type(TransportType.RtspInterleaved) .InterleavedChannels(0, 1) .Build(); var response = _fixture.Client.Request().Transport(transport).SetUp(); Assert.True(response.ResponseStatus.Is(RtspResponse.Status.Ok)); transport = response.Transport; Assert.NotNull(transport); Assert.Equal(TransportType.RtspInterleaved, transport.Type); Assert.Equal(0, transport.InterleavedChannels.RtpPort); Assert.Equal(1, transport.InterleavedChannels.RtcpPort); var session = response.Session; Assert.NotNull(session); Assert.NotEmpty(session.ID); Assert.Equal(60u, session.Timeout); var sink = new Sink(); var pipeline = MediaPipeline.CreateBuilder() .Source(_fixture.Client.GetChannelSource(transport.InterleavedChannels.RtpPort)) .Transform(new DefaultRtpDepacketizer()) .Sink(sink) .Build(); pipeline.Start(); _fixture.Client.Request().Session(session.ID).PlayAsync((res) => { Assert.True(res.ResponseStatus.Is(RtspResponse.Status.Ok)); }); sink.WaitForCompletion(TimeSpan.FromSeconds(20)); _fixture.Client.Request().Session(session.ID).TeardownAsync((res) => { }); pipeline.Stop(); var sessData = _spy.GetData(session.ID); Assert.Equal(sessData.Buffers.Count, sink.ReceivedBuffers.Count); Assert.True(Enumerable.SequenceEqual(sessData.Buffers, sink.ReceivedBuffers)); }
public FacialDetectionSource(Uri rtspUri, Configuration config) { var transform = new FacialRecognitionTransform(); transform.ScaleFactor = config.ScaleFactor; transform.MinimumNeighbors = config.MinimumNeighbors; _teeSink = new TeeSink(); _src = new OpenCVRtspSource(rtspUri, TimeSpan.FromMilliseconds(250)); _pipeline = MediaPipeline.CreateBuilder() .Source(_src) .Transform(transform) .Sink(_teeSink) .Build(); }
public override void Start() { lock (this) { if (_pipeline == null) { _pipeline = MediaPipeline.CreateBuilder() .Source(_src) .Transform(new RecordingTransform(_spy, Id)) .Transform(new RtpPacketizer(new DefaultRtpClock(90000), SSRC, _payloadType)) .Sink(new TcpInterleavedSink(_context, (byte)_ports.RtpPort)) .Build(); _pipeline.Start(); } } }
public void JumpToLive() { lock (PlayerLock) { if (!_isLive) { _isLive = true; _pipeline.SetFlushing(true); _pipeline.Stop(); _pipeline = _config.PipelineFactory.CreatePipeline(_transformSource, _isLive); _pipeline.SetFlushing(false); _pipeline.Start(); _source.JumpToLive(); } } }
public void Start(DateTime?playAt = null) { lock (PlayerLock) { if (_pipeline != null) { // Already started. return; } _transformSource = new RtpPayloadTransform(); _isLive = !playAt.HasValue; _source.Play(_transformSource, playAt); _pipeline = _config.PipelineFactory.CreatePipeline(_transformSource, _isLive); _pipeline.Start(); } }
public void Seek(DateTime seekTo) { lock (PlayerLock) { if (_transformSource == null) { throw new ArgumentException("Unable to seek before starting player"); } if (_isLive) { _isLive = false; _pipeline.SetFlushing(true); _pipeline.Stop(); _pipeline = _config.PipelineFactory.CreatePipeline(_transformSource, _isLive); _pipeline.Start(); } _source.Seek(seekTo); } }
private void RunTest(int frameSize) { var src = new Source(); var sink = new Sink(); var pipeline = MediaPipeline.CreateBuilder() .Source(src) .Transform(new RtpPacketizer(new DefaultRtpClock(90000), 5678, 96)) .Transform(new DefaultRtpDepacketizer()) .Sink(sink) .Build(); pipeline.Start(); while (sink.ReceivedBuffer == ByteBuffer.EMPTY) { Thread.Sleep(500); } pipeline.Stop(); Assert.True(sink.ReceivedBuffer.Equals(src.SentBuffer)); }
private RtpSession Setup(MediaTrack track, RtpChannelSink sink, bool interleaved) { lock (SourceLock) { IRtpSource rtpSource = null; try { TransportHeader transport = null; if (interleaved) { transport = TransportHeader.CreateBuilder() .Type(Media.RTSP.TransportType.RtspInterleaved) .InterleavedChannels(0, 1) .Build(); } else { // TODO(frank.lamar): Add multicast support. rtpSource = new RtpUdpSource(track.Address); transport = TransportHeader.CreateBuilder() .Type(Media.RTSP.TransportType.UdpUnicast) .ClientPorts(rtpSource.RtpPort, rtpSource.RtcpPort) .Build(); } var response = CheckResponse(_client.Send(RtspRequest.CreateBuilder() .Method(RtspRequest.RtspMethod.SETUP) .Uri(track.ControlUri) .AddHeader(RtspHeaders.Names.TRANSPORT, transport.ToString()) .Build()), RtspRequest.RtspMethod.SETUP); if (!response.Headers.ContainsKey(RtspHeaders.Names.SESSION)) { throw new RtspClientException("Rtsp SETUP response does not contain a session id"); } var rtspSession = Session.Parse(response.Headers[RtspHeaders.Names.SESSION]); transport = response.Transport; if (interleaved) { if (transport.Type != Media.RTSP.TransportType.RtspInterleaved) { throw new RtspClientException($"Server does not support interleaved. Response Transport='{transport}'"); } var channels = transport.InterleavedChannels != null ? transport.InterleavedChannels : new PortPair(0, 1); sink.Channel = channels.RtpPort; // Ensure that the sink contains the correct Interleaved channel id. rtpSource = new RtpInterleavedSource(_client.GetChannelSource(channels.RtpPort), _client.GetChannelSource(channels.RtcpPort)); } var pipeline = MediaPipeline.CreateBuilder() .Source(rtpSource.RtpSource) .TransformIf(transport.SSRC != null, new SsrcFilter(transport.SSRC)) .Sink(sink) .Build(); var session = new RtpSession(track, rtspSession, rtpSource); session.Pipelines.Add(pipeline); session.Start(); CheckAndStartRefreshTimer(session.Session.Timeout); return(session); } catch (Exception e) { if (rtpSource != null) { rtpSource?.Stop(); } if (e is RtspClientException) { throw e; } throw new RtspClientException($"Unable to set up media track {track.ID}", e); } } }