Ejemplo n.º 1
0
        public void Start_PacketsDemuxed_PublishesPackets(StartType startType)
        {
            AsyncContext.Run(async() =>
            {
                var demuxerStub = Substitute.For <IDemuxer>();
                var packet      = new Packet {
                    StreamType = StreamType.Video, IsEOS = false, IsKeyFrame = true
                };
                demuxerStub.NextPacket().Returns(Task.FromResult(packet));
                demuxerStub.IsInitialized().Returns(true);
                demuxerStub.Completion.Returns(Task.Delay(500));

                using (var controller = new DemuxerController(demuxerStub))
                {
                    var packetReadyTask = controller.PacketReady()
                                          .Take(2)
                                          .Count()
                                          .FirstAsync()
                                          .ToTask();

                    StartController(controller, startType);

                    var receivedCount = await packetReadyTask;
                    Assert.That(receivedCount, Is.EqualTo(2));
                }
            });
        }
Ejemplo n.º 2
0
        public void Seek_Called_ListensForEos()
        {
            AsyncContext.Run(async() =>
            {
                var demuxerStub = Substitute.For <IDemuxer>();
                demuxerStub.NextPacket().Returns(Utils.TaskExtensions.Never <Packet>());
                demuxerStub.Completion.Returns(Task.CompletedTask);

                using (var controller = new DemuxerController(demuxerStub))
                {
                    var packetReady = controller.PacketReady().FirstAsync().ToTask();

                    await controller.Seek(TimeSpan.FromSeconds(5), CancellationToken.None);

                    var packet = await packetReady;
                    Assert.That(packet, Is.Null);
                }
            });
        }
Ejemplo n.º 3
0
        public void SetDataSource_DataSourceCompletes_SignalsEos()
        {
            AsyncContext.Run(async() =>
            {
                var demuxerStub = Substitute.For <IDemuxer>();
                var dataSource  = new Subject <byte[]>();
                using (var controller = new DemuxerController(demuxerStub))
                {
                    controller.SetDataSource(dataSource);
                    var packetReadyTask = controller.PacketReady()
                                          .FirstAsync()
                                          .ToTask();

                    dataSource.OnNext(null);

                    var isEmpty = await packetReadyTask;
                    Assert.That(isEmpty, Is.Null);
                }
            });
        }