Exemplo n.º 1
0
        public async Task <IDrmSession> GetDrmSession(DrmInitData data)
        {
            var keyIds        = DrmInitDataTools.GetKeyIds(data);
            var useGenericKey = keyIds.Count == 0;

            if (useGenericKey)
            {
                Logger.Info("No keys found in initData - using entire DrmInitData with InitData as a generic key.");
                keyIds.Add(data.InitData);
            }
            Logger.Info("Keys found - getting DrmSession.");
            IDrmSession session;

            using (await clipDrmConfigurationsLock.LockAsync())
                session = await GetCdmInstance(data).GetDrmSession(data, keyIds, clipDrmConfigurations);
            return(session);
        }
Exemplo n.º 2
0
        public IDrmSession CreateDRMSession(DRMInitData data)
        {
            Logger.Info("Create DrmSession");

            // Before diving into locks, decode DRM InitData KeyIDs
            var keyIds        = DrmInitDataTools.GetKeyIds(data);
            var useGenericKey = keyIds.Count == 0;

            if (useGenericKey)
            {
                Logger.Info("No keys found. Using entire DRMInitData.InitData as generic key");
                keyIds.Add(data.InitData);
            }
            else
            {
                // Early exit scenario - already cached
                if (_sessionCache.TryGetSession(keyIds, out IDrmSession session))
                {
                    Logger.Info("Cached session found");
                    return(session);
                }
            }

            lock (drmHandlers)
            {
                var handler = drmHandlers.FirstOrDefault(o => o.SupportsSystemId(data.SystemId));
                if (handler == null)
                {
                    Logger.Warn("unknown drm init data");
                    return(null);
                }

                var scheme = handler.GetScheme(data.SystemId);

                lock (clipDrmConfiguration)
                {
                    var drmConfiguration = clipDrmConfiguration.FirstOrDefault(o => SchemeEquals(o.Scheme, scheme));
                    if (drmConfiguration == null)
                    {
                        Logger.Warn("drm not configured");
                        return(null);
                    }

                    // Recheck needs to be done for cached session.
                    // Early check may produce false negatives - session being created by other stream
                    // but not yet cached.
                    if (_sessionCache.TryGetSession(keyIds, out IDrmSession session))
                    {
                        Logger.Info("Cached session found");
                        return(session);
                    }

                    Logger.Info("No cached session found");

                    session = handler.CreateDRMSession(data, drmConfiguration);
                    session.Share();
                    if (_sessionCache.TryAddSession(keyIds, session))
                    {
                        return(session);
                    }

                    Logger.Info("Failed to cache session");
                    session.Release();

                    return(session);
                }
            }
        }
Exemplo n.º 3
0
 public override string ToString()
 {
     return(_cache.Keys.Aggregate("Cached Sessions: " + _cache.Keys.Count,
                                  (current, key) => current + "\n" + DrmInitDataTools.KeyToUuid(key)));
 }