Exemplo n.º 1
0
        public async Task DecryptPacket_WhenPacketIsValid_DecryptsSuccessfully(string drmName)
        {
            Logger.Info(drmName);

            var drmInitData     = CreateDrmInitData(drmName);
            var configuration   = CreateDrmDescription(drmName);
            var encryptedPacket = CreateEncryptedPacket(drmName);

            using (var drmSession = CencSession.Create(drmInitData, configuration))
            {
                await drmSession.Initialize();

                using (var decrypted = await drmSession.DecryptPacket(encryptedPacket, CancellationToken.None))
                {
                    Assert.That(decrypted, Is.Not.Null);
                    Assert.That(decrypted, Is.InstanceOf <DecryptedEMEPacket>());

                    var decryptedEme = decrypted as DecryptedEMEPacket;

                    Assert.That(decryptedEme.Dts, Is.EqualTo(encryptedPacket.Dts));
                    Assert.That(decryptedEme.Pts, Is.EqualTo(encryptedPacket.Pts));
                    Assert.That(decryptedEme.IsKeyFrame, Is.EqualTo(encryptedPacket.IsKeyFrame));
                    Assert.That(decryptedEme.StreamType, Is.EqualTo(encryptedPacket.StreamType));
                    Assert.That(decryptedEme.HandleSize, Is.Not.Null);
                    Assert.That(decryptedEme.HandleSize.handle, Is.GreaterThan(0));
                    Assert.That(decryptedEme.HandleSize.size, Is.EqualTo(encryptedPacket.Storage.Length));
                }
            }
        }
Exemplo n.º 2
0
        public void Constructor_WhenLicenceUrlIsNull_ThrowsNullReferenceException()
        {
            var drmInitData   = CreateDrmInitData();
            var configuration = CreateDrmDescription();

            configuration.LicenceUrl = null;

            Assert.Throws <NullReferenceException>(() => CencSession.Create(drmInitData, configuration));
        }
Exemplo n.º 3
0
        public void Dispose_WhenInitializationInProgress_DoesNotThrow()
        {
            var drmInitData   = CreateDrmInitData();
            var configuration = CreateDrmDescription();

            Assert.DoesNotThrow(() =>
            {
                var drmSession = CencSession.Create(drmInitData, configuration);
                drmSession.Initialize();
                drmSession.Dispose();
            });
        }
Exemplo n.º 4
0
        public void Initialize_WhenInitDataIsInvalid_ThrowsDRMException()
        {
            var drmInitData   = CreateDrmInitData();
            var configuration = CreateDrmDescription();

            drmInitData.InitData = null;
            Assert.ThrowsAsync <DrmException>(async() =>
            {
                using (var drmSession = CencSession.Create(drmInitData, configuration))
                    await drmSession.Initialize();
            });

            drmInitData.InitData = initData.Take(initData.Length / 2).ToArray();
            Assert.ThrowsAsync <DrmException>(async() =>
            {
                using (var drmSession = CencSession.Create(drmInitData, configuration))
                    await drmSession.Initialize();
            });
        }
Exemplo n.º 5
0
        public void Concurrent_CreateDispose_DoesNotThrow(string drmName)
        {
            Assert.DoesNotThrowAsync(async() =>
            {
                using (var goDispose = new Barrier(0))
                {
                    var id = 0;

                    async Task DoWork(string drm)
                    {
                        var drmInitData   = CreateDrmInitData(drm);
                        var configuration = CreateDrmDescription(drm);

                        var myId     = Interlocked.Increment(ref id);
                        var signaled = false;

                        try
                        {
                            Logger.Info($"Creating {drm} Session {myId}");
                            using (var ses = CencSession.Create(drmInitData, configuration))
                            {
                                Logger.Info($"Initializing {drm} Session {myId}");
                                ses.Initialize();

                                // Widevine cases - 15 concurrent sessions - individual session may take 60s+
                                // to initialize when run @15 sessions.
                                using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(90)))
                                {
                                    try
                                    {
                                        await ses.WaitForInitialization(cts.Token);
                                    }
                                    catch (OperationCanceledException)
                                    {
                                        Logger.Info($"TIMEOUT {drm} Session {myId}");
                                        throw;
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.Error(e);
                                        throw;
                                    }
                                }

                                Logger.Info($"{drm} Session {myId} Initialized. Waiting for Dispose");
                                goDispose.SignalAndWait();
                                signaled = true;
                            }

                            Logger.Info($"{drm} Session {myId} completed");
                        }
                        finally
                        {
                            if (!signaled)
                            {
                                goDispose.RemoveParticipant();
                            }
                        }
                    }

                    var workPool = new List <Task>();

                    for (var i = 0; i < ConcurrentDrmSessionsLimit; i++)
                    {
                        workPool.Add(DoWork(drmName));
                        goDispose.AddParticipant();
                    }

                    await Task.WhenAll(workPool.ToArray());
                    Logger.Info($"{drmName} Test completed");
                }
            });
        }