Example #1
0
        private void PushEncryptedPacket(EncryptedPacket dataPacket, CancellationToken token)
        {
            using (var decryptedPacket = dataPacket.Decrypt(token) as DecryptedEMEPacket)
            {
                if (decryptedPacket == null)
                {
                    logger.Error($"{dataPacket.StreamType}: Non an EME Packet!");
                    return;
                }

                var esPacket = decryptedPacket.ESDecryptedPacket();

                // Continue pushing packet till success or terminal failure
                bool doRetry;
                do
                {
                    var res = player.SubmitPacket(esPacket);

                    // reset unmanaged handle on successful submit
                    if (res == ESPlayer.SubmitStatus.Success)
                    {
                        decryptedPacket.CleanHandle();
                    }

                    doRetry = ShouldRetry(res, token);

                    logger.Debug(
                        $"{esPacket.type}: ({!doRetry}/{res}) PTS: {esPacket.pts.FromNano()} Duration: {esPacket.duration.FromNano()} Handle: {esPacket.handle} HandleSize: {esPacket.handleSize}");
                } while (doRetry && !token.IsCancellationRequested);
            }
        }
Example #2
0
        /// <summary>
        /// Pushes encrypted data packet to ESPlayer.
        /// Decryption is performed prior to packet push.
        /// </summary>
        /// <param name="dataPacket">Packet</param>
        /// <param name="token">CancellationToken</param>
        /// <exception cref="PacketSubmitException">
        /// Exception thrown on submit error
        /// </exception>
        /// <exception cref="OperationCanceledException">
        /// Exception thrown on submit cancellation
        /// </exception>
        private async Task PushEncryptedPacket(EncryptedPacket dataPacket, CancellationToken token)
        {
            using (var decryptedPacket = await dataPacket.Decrypt(token) as DecryptedEMEPacket)
            {
                // Continue pushing packet till success or terminal failure
                for (; ;)
                {
                    var submitStatus = player.Submit(decryptedPacket);

                    logger.Debug(
                        $"{decryptedPacket.StreamType}: ({submitStatus}) PTS: {decryptedPacket.Pts} Duration:" +
                        $"{decryptedPacket.Duration} Handle: {decryptedPacket.HandleSize.handle} " +
                        $"HandleSize: {decryptedPacket.HandleSize.size}");

                    if (submitStatus == ESPlayer.SubmitStatus.Success)
                    {
                        decryptedPacket.CleanHandle();
                        return;
                    }

                    if (!ShouldRetry(submitStatus))
                    {
                        throw new PacketSubmitException("Packet Submit Error", submitStatus);
                    }

                    var delay = CalculateDelay(submitStatus);
                    Wait(delay, token);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Pushes encrypted data packet to ESPlayer.
        /// Decryption is performed prior to packet push.
        /// </summary>
        /// <param name="dataPacket">Packet</param>
        /// <param name="token">CancellationToken</param>
        /// <exception cref="PacketSubmitException">
        /// Exception thrown on submit error
        /// </exception>
        /// <exception cref="OperationCanceledException">
        /// Exception thrown on submit cancellation
        /// </exception>
        private async ValueTask PushEncryptedPacket(EncryptedPacket dataPacket, CancellationToken token)
        {
            if (!dataPacket.DrmSession.CanDecrypt())
            {
#pragma warning disable 4014    // No await intentional. Do not care much when buffering will be displayed
                _suspendResumeLogic.RequestBuffering(true);
                await dataPacket.DrmSession.WaitForInitialization(token);

                _suspendResumeLogic.RequestBuffering(false);
#pragma warning restore 4014    // of hidden for that matter.
                logger.Info($"{streamType}: DRM Initialization complete");
            }

            using (var decryptedPacket = await dataPacket.Decrypt(token) as DecryptedEMEPacket)
            {
                // Continue pushing packet till success or terminal failure
                for (; ;)
                {
                    var submitStatus = player.Submit(decryptedPacket);

                    logger.Debug(
                        $"{decryptedPacket.StreamType}: ({submitStatus}) PTS: {decryptedPacket.Pts} Duration:" +
                        $"{decryptedPacket.Duration} Handle: {decryptedPacket.HandleSize.handle} " +
                        $"HandleSize: {decryptedPacket.HandleSize.size}");

                    if (submitStatus == ESPlayer.SubmitStatus.Success)
                    {
                        decryptedPacket.CleanHandle();
                        return;
                    }

                    if (!ShouldRetry(submitStatus))
                    {
                        throw new PacketSubmitException("Packet Submit Error", submitStatus);
                    }

                    await Task.Delay(CalculateDelay(submitStatus), token);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Pushes encrypted data packet to ESPlayer.
        /// Decryption is performed prior to packet push.
        /// </summary>
        /// <param name="dataPacket">Packet</param>
        /// <param name="token">CancellationToken</param>
        /// <exception cref="PacketSubmitException">
        /// Exception thrown on submit error
        /// </exception>
        /// <exception cref="OperationCanceledException">
        /// Exception thrown on submit cancellation
        /// </exception>
        private async ValueTask PushEncryptedPacket(EncryptedPacket dataPacket, CancellationToken token)
        {
            if (!dataPacket.DrmSession.CanDecrypt())
            {
                _bufferingSubject.OnNext(true);
                await dataPacket.DrmSession.WaitForInitialization(token);

                // If exception occurs, Transfer task will restore correct buffering state
                _bufferingSubject.OnNext(false);

                logger.Info($"{streamType}: DRM Initialization complete");
            }

            using (var decryptedPacket = await dataPacket.Decrypt(token) as DecryptedEMEPacket)
            {
                // Continue pushing packet till success or terminal failure
                for (; ;)
                {
                    var submitStatus = player.Submit(decryptedPacket);

                    logger.Debug(
                        $"{decryptedPacket.StreamType}: ({submitStatus}) PTS: {decryptedPacket.Pts} Duration:" +
                        $"{decryptedPacket.Duration} Handle: {decryptedPacket.HandleSize.handle} " +
                        $"HandleSize: {decryptedPacket.HandleSize.size}");

                    if (submitStatus == ESPlayer.SubmitStatus.Success)
                    {
                        decryptedPacket.CleanHandle();
                        return;
                    }

                    if (!ShouldRetry(submitStatus))
                    {
                        throw new PacketSubmitException("Packet Submit Error", submitStatus);
                    }

                    await Task.Delay(CalculateDelay(submitStatus), token);
                }
            }
        }