コード例 #1
0
        public async Task DecryptPacket_WhenPacketIsValid_DecryptsSuccessfully(string drmName)
        {
            Logger.Info(drmName);

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

            using (var cdmInstance = new CdmInstance(EmeUtils.GetKeySystemName(drmInitData.SystemId)))
                using (var session = await cdmInstance.GetDrmSession(drmInitData, new List <byte[]>(), new List <DrmDescription> {
                    drmDescription
                }))
                {
                    using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(90)))
                        await session.WaitForInitialization().WithCancellation(cts.Token);
                    using (var decrypted = await cdmInstance.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));
                    }
                }
        }
コード例 #2
0
        public async Task GetDrmSession_WhenInitDataIsInvalid_ReturnsNullSession(string drmName)
        {
            Logger.Info(drmName);

            var drmInitData = CreateDrmInitData(drmName);

            drmInitData.InitData = null;
            var drmDescription = CreateDrmDescription(drmName);

            using (var cdmInstance = new CdmInstance(EmeUtils.GetKeySystemName(drmInitData.SystemId)))
                using (var session = await cdmInstance.GetDrmSession(drmInitData, new List <byte[]>(),
                                                                     new List <DrmDescription> {
                    drmDescription
                }))
                {
                    Assert.That(session, Is.Null);
                }

            drmInitData.InitData = initPlayReadyData.Take(initPlayReadyData.Length / 2).ToArray();

            using (var cdmInstance = new CdmInstance(EmeUtils.GetKeySystemName(drmInitData.SystemId)))
                using (var session = await cdmInstance.GetDrmSession(drmInitData, new List <byte[]>(),
                                                                     new List <DrmDescription> {
                    drmDescription
                }))
                {
                    Assert.That(session, Is.Null);
                }
        }
コード例 #3
0
        public void Dispose_WhenInitializationInProgress_DoesNotThrow(string drmName)
        {
            Logger.Info(drmName);

            var drmInitData    = CreateDrmInitData(drmName);
            var drmDescription = CreateDrmDescription(drmName);

            using (var cdmInstance = new CdmInstance(EmeUtils.GetKeySystemName(drmInitData.SystemId)))
                Assert.DoesNotThrow(() =>
                {
                    using (var session = cdmInstance.GetDrmSession(drmInitData, new List <byte[]>(), new List <DrmDescription> {
                        drmDescription
                    }).GetAwaiter().GetResult())
                        using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(90)))
                            session.WaitForInitialization().WithCancellation(cts.Token).GetAwaiter().GetResult();
                });
        }
コード例 #4
0
        public void Concurrent_CreateDispose_DoesNotThrow(string drmName)
        {
            Logger.Info(drmName);

            Assert.DoesNotThrowAsync(async() =>
            {
                var drmInitData    = CreateDrmInitData(drmName);
                var drmDescription = CreateDrmDescription(drmName);
                using (var cdmInstance = new CdmInstance(EmeUtils.GetKeySystemName(drmInitData.SystemId)))
                    using (var goDispose = new Barrier(0))
                    {
                        var id = 0;

                        async Task DoWork(string drm)
                        {
                            var myId     = Interlocked.Increment(ref id);
                            var signaled = false;

                            try
                            {
                                Logger.Info($"Creating {drm} Session {myId}.");

                                using (var session = await cdmInstance.GetDrmSession(drmInitData, new List <byte[]>(), new List <DrmDescription> {
                                    drmDescription
                                }))
                                {
                                    // 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
                                        {
                                            Logger.Info($"Initializing {drm} Session {myId}.");
                                            await session.WaitForInitialization().WithCancellation(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");
                    }
            });
        }