예제 #1
0
        public static StreamProtection[] GetStreamProtections(string authToken, string protectionTypes)
        {
            List <StreamProtection> streamProtections = new List <StreamProtection>();

            if (!string.IsNullOrEmpty(protectionTypes))
            {
                authToken = string.Concat("Bearer=", authToken);
                string[] streamProtectionTypes = protectionTypes.Split(Constant.TextDelimiter.Application);
                foreach (string streamProtectionType in streamProtectionTypes)
                {
                    StreamProtection streamProtection = new StreamProtection()
                    {
                        Type = (MediaProtection)Enum.Parse(typeof(MediaProtection), streamProtectionType),
                        AuthenticationToken = authToken
                    };
                    streamProtections.Add(streamProtection);
                }
            }
            return(streamProtections.ToArray());
        }
        public StreamProtection[] GetProtectionInfo(string authToken, MediaClient mediaClient, StreamingLocator locator)
        {
            authToken = string.Concat("Bearer=", authToken);
            List <StreamProtection> protectionInfo = new List <StreamProtection>();

            if (locator.StreamingPolicyName == PredefinedStreamingPolicy.ClearKey)
            {
                StreamProtection streamProtection = new StreamProtection()
                {
                    Type = MediaProtection.AES,
                    AuthenticationToken = authToken
                };
                protectionInfo.Add(streamProtection);
            }
            else if (locator.StreamingPolicyName == PredefinedStreamingPolicy.SecureStreaming)
            {
                ContentKeyPolicy contentKeyPolicy = mediaClient.GetEntity <ContentKeyPolicy>(MediaEntity.ContentKeyPolicy, locator.DefaultContentKeyPolicyName);
                foreach (ContentKeyPolicyOption contentKeyPolicyOption in contentKeyPolicy.Options)
                {
                    if (contentKeyPolicyOption.Configuration is ContentKeyPolicyPlayReadyConfiguration)
                    {
                        StreamProtection streamProtection = new StreamProtection()
                        {
                            Type = MediaProtection.PlayReady,
                            AuthenticationToken = authToken
                        };
                        protectionInfo.Add(streamProtection);
                    }
                    else if (contentKeyPolicyOption.Configuration is ContentKeyPolicyWidevineConfiguration)
                    {
                        StreamProtection streamProtection = new StreamProtection()
                        {
                            Type = MediaProtection.Widevine,
                            AuthenticationToken = authToken
                        };
                        protectionInfo.Add(streamProtection);
                    }
                }
            }
            return(protectionInfo.Count == 0 ? null : protectionInfo.ToArray());
        }
예제 #3
0
        public StreamProtection[] GetStreamProtections(string authToken, IAsset asset)
        {
            List <StreamProtection> streamProtections = new List <StreamProtection>();

            authToken = string.Concat("Bearer=", authToken);

            IAssetDeliveryPolicy[] deliveryPolicies = asset.DeliveryPolicies.Where(dp => dp.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicEnvelopeEncryption).ToArray();
            if (deliveryPolicies.Length > 0)
            {
                StreamProtection streamProtection = new StreamProtection()
                {
                    Type = MediaProtection.AES,
                    AuthenticationToken = authToken
                };
                streamProtections.Add(streamProtection);
            }

            deliveryPolicies = asset.DeliveryPolicies.Where(dp => dp.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicCommonEncryption).ToArray();
            if (deliveryPolicies.Length > 0)
            {
                IContentKey[] contentKeys = asset.ContentKeys.Where(ck => ck.ContentKeyType == ContentKeyType.CommonEncryption).ToArray();
                foreach (IContentKey contentKey in contentKeys)
                {
                    IContentKeyAuthorizationPolicy authPolicy = GetEntityById(MediaEntity.ContentKeyAuthPolicy, contentKey.AuthorizationPolicyId) as IContentKeyAuthorizationPolicy;
                    if (authPolicy != null)
                    {
                        IContentKeyAuthorizationPolicyOption[] policyOptions = authPolicy.Options.Where(po => po.KeyDeliveryType == ContentKeyDeliveryType.PlayReadyLicense).ToArray();
                        if (policyOptions.Length > 0)
                        {
                            StreamProtection streamProtection = new StreamProtection()
                            {
                                Type = MediaProtection.PlayReady,
                                AuthenticationToken = authToken
                            };
                            streamProtections.Add(streamProtection);
                        }
                        policyOptions = authPolicy.Options.Where(po => po.KeyDeliveryType == ContentKeyDeliveryType.Widevine).ToArray();
                        if (policyOptions.Length > 0)
                        {
                            StreamProtection streamProtection = new StreamProtection()
                            {
                                Type = MediaProtection.Widevine,
                                AuthenticationToken = authToken
                            };
                            streamProtections.Add(streamProtection);
                        }
                    }
                }
            }

            deliveryPolicies = asset.DeliveryPolicies.Where(p => p.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicCommonEncryptionCbcs).ToArray();
            if (deliveryPolicies.Length > 0)
            {
                StreamProtection streamProtection = new StreamProtection()
                {
                    Type = MediaProtection.FairPlay,
                    AuthenticationToken = authToken
                };
                streamProtections.Add(streamProtection);
            }

            return(streamProtections.ToArray());
        }