Esempio n. 1
0
        /// <summary>
        /// Seek Task. Performs seek to specified seekId, followed by seek to specified
        /// seek position
        /// </summary>
        /// <param name="seekId">Seek ID to seek to</param>
        /// <param name="seekPosition">seek position to seek to</param>
        /// <param name="token">cancel token</param>
        /// <returns></returns>
        private SeekResult SeekTask(uint seekId, TimeSpan seekPosition, CancellationToken token)
        {
            logger.Info($"{streamType}: {seekId}");

            while (true)
            {
                try
                {
                    var packet = packetStorage.GetPacket(streamType, token);

                    switch (packet)
                    {
                    case BufferConfigurationPacket bufferConfigPacket:
                        var isCompatible = CurrentConfig.Compatible(bufferConfigPacket);
                        CurrentConfig = bufferConfigPacket;
                        if (CurrentConfig.StreamType == StreamType.Audio && !isCompatible)
                        {
                            return(SeekResult.RestartRequired);
                        }
                        break;

                    case SeekPacket seekPacket:
                        if (seekPacket.SeekId != seekId)
                        {
                            break;
                        }

                        logger.Info($"{streamType}: Seek Id {seekId} found. Looking for time {seekPosition}");
                        return(SeekResult.Ok);

                    default:
                        packet.Dispose();
                        break;
                    }
                }
                catch (InvalidOperationException)
                {
                    logger.Warn($"{streamType}: Stream completed");
                    return(SeekResult.Ok);
                }
                catch (OperationCanceledException)
                {
                    logger.Warn($"{streamType}: Seek cancelled");
                    return(SeekResult.Ok);
                }
                catch (Exception e)
                {
                    logger.Error(e, $"{streamType}");
                    throw;
                }
            }
        }
Esempio n. 2
0
        private async ValueTask <bool> ProcessNextPacket(CancellationToken token)
        {
            if (currentPacket == null)
            {
                var displayBuffering = packetStorage.Count(streamType) == 0 &&
                                       (_playerClock.LastClock - currentPts).Duration() <= EsStreamConfig.BufferingEventThreshold;

                _bufferingSubject.OnNext(displayBuffering);

                currentPacket = packetStorage.GetPacket(streamType, token);

                currentPts = currentPacket.Pts;
            }

            var shouldContinue = await ProcessPacket(currentPacket, token);

            _dataSynchronizer.DataOut(currentPacket);
            var packetType = currentPacket.GetType();

            currentPacket.Dispose();
            currentPacket = null;

            _packetProcessed.OnNext(packetType);
            return(shouldContinue);
        }
Esempio n. 3
0
        private async ValueTask <bool> ProcessNextPacket(CancellationToken token)
        {
            if (currentPacket == null)
            {
                if (packetStorage.Count(streamType) == 0 &&
                    (PlayerClockProvider.LastClock - currentPts).Duration() <= EsStreamConfig.BufferingEventThreshold)
                {
                    await _suspendResumeLogic.RequestBuffering(true);

                    currentPacket = packetStorage.GetPacket(streamType, token);
#pragma warning disable 4014 // No need to wait for dissapear. Will happen.. eventually.
                    _suspendResumeLogic.RequestBuffering(false);
#pragma warning restore 4014
                }
                else
                {
                    currentPacket = packetStorage.GetPacket(streamType, token);
                }

                currentPts = currentPacket.Pts;
            }

            var shouldContinue = await ProcessPacket(currentPacket, token);

            _dataSynchronizer.DataOut(currentPacket);

            if (_firstDataPacketTcs?.Task.IsCompleted == false)
            {
                ConfirmFirstDataPacket();
            }

            currentPacket.Dispose();
            currentPacket = null;

            return(shouldContinue);
        }
Esempio n. 4
0
        private async Task <bool> ProcessNextPacket(CancellationToken token)
        {
            if (currentPacket == null)
            {
                currentPacket = packetStorage.GetPacket(streamType, token);
            }

            var shouldContinue = await ProcessPacket(currentPacket, token);

            streamBufferController.DataOut(currentPacket);
            barrier.PacketPushed(currentPacket);

            currentPacket.Dispose();
            currentPacket = null;

            return(shouldContinue);
        }