/// <summary> /// Configures PlayReady license template. /// </summary> /// <returns></returns> private static ContentKeyPolicyPlayReadyConfiguration ConfigurePlayReadyLicenseTemplate() { ContentKeyPolicyPlayReadyLicense objContentKeyPolicyPlayReadyLicense; objContentKeyPolicyPlayReadyLicense = new ContentKeyPolicyPlayReadyLicense { AllowTestDevices = true, ContentKeyLocation = new ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(), ContentType = ContentKeyPolicyPlayReadyContentType.UltraVioletStreaming, LicenseType = ContentKeyPolicyPlayReadyLicenseType.NonPersistent, PlayRight = new ContentKeyPolicyPlayReadyPlayRight { ImageConstraintForAnalogComponentVideoRestriction = true, ExplicitAnalogTelevisionOutputRestriction = new ContentKeyPolicyPlayReadyExplicitAnalogTelevisionRestriction(true, 2), AllowPassingVideoContentToUnknownOutput = ContentKeyPolicyPlayReadyUnknownOutputPassingOption.Allowed } }; ContentKeyPolicyPlayReadyConfiguration objContentKeyPolicyPlayReadyConfiguration = new() { Licenses = new List <ContentKeyPolicyPlayReadyLicense> { objContentKeyPolicyPlayReadyLicense } }; return(objContentKeyPolicyPlayReadyConfiguration); }
public void CreateContentKeyPolicyDRM(ContentProtection contentProtection) { ContentKeyPolicyPlayReadyLicenseType licenseType = ContentKeyPolicyPlayReadyLicenseType.NonPersistent; if (contentProtection != null && contentProtection.PersistentLicense) { licenseType = ContentKeyPolicyPlayReadyLicenseType.Persistent; } ContentKeyPolicyPlayReadyLicense playReadyLicense = new ContentKeyPolicyPlayReadyLicense() { LicenseType = licenseType, ContentType = ContentKeyPolicyPlayReadyContentType.Unspecified, ContentKeyLocation = new ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader() }; ContentKeyPolicyPlayReadyConfiguration playReadyConfiguration = new ContentKeyPolicyPlayReadyConfiguration() { Licenses = new ContentKeyPolicyPlayReadyLicense[] { playReadyLicense } }; WidevineTemplate widevineTemplate = new WidevineTemplate(); if (contentProtection != null && contentProtection.PersistentLicense) { widevineTemplate.PolicyOverrides = new PolicyOverrides() { CanPersist = true }; } ContentKeyPolicyWidevineConfiguration widevineConfiguration = new ContentKeyPolicyWidevineConfiguration() { WidevineTemplate = JsonConvert.SerializeObject(widevineTemplate) }; string policyName = Constant.Media.ContentKey.PolicyDRM; ContentKeyPolicyConfiguration[] policyConfigurations = new ContentKeyPolicyConfiguration[] { playReadyConfiguration, widevineConfiguration }; CreateContentKeyPolicy(policyName, policyConfigurations); }
/// <summary> /// Configures PlayReady license template for non persistent licenses. /// </summary> /// <returns>The PlayReady template for non persistent licenses.</returns> private static ContentKeyPolicyPlayReadyConfiguration ConfigurePlayReadyLicenseTemplatePersistentNone() { ContentKeyPolicyPlayReadyLicense objContentKeyPolicyPlayReadyLicense; objContentKeyPolicyPlayReadyLicense = new ContentKeyPolicyPlayReadyLicense { AllowTestDevices = false, ContentKeyLocation = new ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(), ContentType = ContentKeyPolicyPlayReadyContentType.Unspecified, LicenseType = ContentKeyPolicyPlayReadyLicenseType.NonPersistent, PlayRight = new ContentKeyPolicyPlayReadyPlayRight { AllowPassingVideoContentToUnknownOutput = ContentKeyPolicyPlayReadyUnknownOutputPassingOption.Allowed } }; return(new ContentKeyPolicyPlayReadyConfiguration { Licenses = new List <ContentKeyPolicyPlayReadyLicense> { objContentKeyPolicyPlayReadyLicense } }); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("AMS v3 Function - CreatePlayReadyLicenseTemplate was triggered!"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); List <ContentKeyPolicyPlayReadyLicense> licenseTemplates = new List <ContentKeyPolicyPlayReadyLicense>(); JToken jToken = null; JsonConverter[] jsonReaders = { new MediaServicesHelperJsonReader(), new MediaServicesHelperTimeSpanJsonConverter() }; JsonConverter[] jsonWriter = { new MediaServicesHelperJsonWriter(), new MediaServicesHelperTimeSpanJsonConverter() }; try { if (data.playReadyLicenses != null) { licenseTemplates = JsonConvert.DeserializeObject <List <ContentKeyPolicyPlayReadyLicense> >(data.playReadyLicenses.ToString(), jsonReaders); } ContentKeyPolicyPlayReadyLicense licenseTemplate = new ContentKeyPolicyPlayReadyLicense(); licenseTemplate.PlayRight = new ContentKeyPolicyPlayReadyPlayRight(); // default value settings licenseTemplate.ContentKeyLocation = new ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(); licenseTemplate.ContentType = ContentKeyPolicyPlayReadyContentType.Unspecified; licenseTemplate.LicenseType = ContentKeyPolicyPlayReadyLicenseType.NonPersistent; licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = ContentKeyPolicyPlayReadyUnknownOutputPassingOption.NotAllowed; if (data.allowTestDevices != null) { licenseTemplate.AllowTestDevices = data.allowTestDevices; } if (data.licenseType != null) { switch (data.licenseType) { case "NonPersistent": licenseTemplate.LicenseType = ContentKeyPolicyPlayReadyLicenseType.NonPersistent; break; case "Persistent": licenseTemplate.LicenseType = ContentKeyPolicyPlayReadyLicenseType.Persistent; break; default: return(new BadRequestObjectResult("Please pass valid licenseType in the input object")); } } if (data.contentKeyLocation != null) { switch (data.contentKeyLocation) { case "ContentEncryptionKeyFromHeader": licenseTemplate.ContentKeyLocation = new ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(); break; case "ContentEncryptionKeyFromKeyIdentifier": licenseTemplate.ContentKeyLocation = new ContentKeyPolicyPlayReadyContentEncryptionKeyFromKeyIdentifier(); break; default: return(new BadRequestObjectResult("Please pass valid contentKeyLocation in the input object")); } } if (data.contentType != null) { switch (data.contentType) { case "Unspecified": licenseTemplate.ContentType = ContentKeyPolicyPlayReadyContentType.Unspecified; break; case "UltraVioletDownload": licenseTemplate.ContentType = ContentKeyPolicyPlayReadyContentType.UltraVioletDownload; break; case "UltraVioletStreaming": licenseTemplate.ContentType = ContentKeyPolicyPlayReadyContentType.UltraVioletStreaming; break; default: return(new BadRequestObjectResult("Please pass valid contentType in the input object")); } } if (data.beginDate != null) { licenseTemplate.BeginDate = data.beginDate; } if (data.expirationDate != null) { licenseTemplate.ExpirationDate = data.expirationDate; } if (data.relativeBeginDate != null) { licenseTemplate.RelativeBeginDate = System.Xml.XmlConvert.ToTimeSpan(data.relativeBeginDate); } if (data.relativeExpirationDate != null) { licenseTemplate.RelativeExpirationDate = System.Xml.XmlConvert.ToTimeSpan(data.relativeExpirationDate); } if (data.gracePeriod != null) { licenseTemplate.GracePeriod = System.Xml.XmlConvert.ToTimeSpan(data.gracePeriod); } if (data.digitalVideoOnlyContentRestriction != null) { licenseTemplate.PlayRight.DigitalVideoOnlyContentRestriction = data.digitalVideoOnlyContentRestriction; } if (data.imageConstraintForAnalogComponentVideoRestriction != null) { licenseTemplate.PlayRight.ImageConstraintForAnalogComponentVideoRestriction = data.imageConstraintForAnalogComponentVideoRestriction; } if (data.imageConstraintForAnalogComputerMonitorRestriction != null) { licenseTemplate.PlayRight.ImageConstraintForAnalogComputerMonitorRestriction = data.imageConstraintForAnalogComputerMonitorRestriction; } if (data.allowPassingVideoContentToUnknownOutput != null) { switch (data.allowPassingVideoContentToUnknownOutput) { case "NotAllowed": licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = ContentKeyPolicyPlayReadyUnknownOutputPassingOption.NotAllowed; break; case "Allowed": licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = ContentKeyPolicyPlayReadyUnknownOutputPassingOption.Allowed; break; case "AllowedWithVideoConstriction": licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = ContentKeyPolicyPlayReadyUnknownOutputPassingOption.AllowedWithVideoConstriction; break; default: return(new BadRequestObjectResult("Please pass valid allowPassingVideoContentToUnknownOutput in the input object")); } } if (data.firstPlayExpiration != null) { licenseTemplate.PlayRight.FirstPlayExpiration = System.Xml.XmlConvert.ToTimeSpan(data.firstPlayExpiration); } if (data.scmsRestriction != null) { licenseTemplate.PlayRight.ScmsRestriction = data.scmsRestriction; } if (data.agcAndColorStripeRestriction != null) { licenseTemplate.PlayRight.AgcAndColorStripeRestriction = data.agcAndColorStripeRestriction; } if (data.explicitAnalogTelevisionOutputRestriction != null || data.explicitAnalogTelevisionOutputRestrictionBestEffort != null) { licenseTemplate.PlayRight.ExplicitAnalogTelevisionOutputRestriction = new ContentKeyPolicyPlayReadyExplicitAnalogTelevisionRestriction(); if (data.explicitAnalogTelevisionOutputRestriction != null) { licenseTemplate.PlayRight.ExplicitAnalogTelevisionOutputRestriction.ConfigurationData = data.explicitAnalogTelevisionOutputRestriction; } if (data.explicitAnalogTelevisionOutputRestrictionBestEffort != null) { licenseTemplate.PlayRight.ExplicitAnalogTelevisionOutputRestriction.BestEffort = data.explicitAnalogTelevisionOutputRestrictionBestEffort; } } if (data.uncompressedDigitalVideoOpl != null) { licenseTemplate.PlayRight.UncompressedDigitalVideoOpl = data.uncompressedDigitalVideoOpl; } if (data.compressedDigitalVideoOpl != null) { licenseTemplate.PlayRight.CompressedDigitalVideoOpl = data.compressedDigitalVideoOpl; } if (data.analogVideoOpl != null) { licenseTemplate.PlayRight.AnalogVideoOpl = data.analogVideoOpl; } if (data.uncompressedDigitalAudioOpl != null) { licenseTemplate.PlayRight.UncompressedDigitalAudioOpl = data.uncompressedDigitalAudioOpl; } if (data.compressedDigitalAudioOpl != null) { licenseTemplate.PlayRight.CompressedDigitalAudioOpl = data.compressedDigitalAudioOpl; } licenseTemplate.Validate(); licenseTemplates.Add(licenseTemplate); string jsonString = JsonConvert.SerializeObject(licenseTemplates, jsonWriter); jToken = JToken.Parse(jsonString); } catch (ApiErrorException e) { log.LogError($"ERROR: AMS API call failed with error code: {e.Body.Error.Code} and message: {e.Body.Error.Message}"); return(new BadRequestObjectResult("AMS API call error: " + e.Message + "\nError Code: " + e.Body.Error.Code + "\nMessage: " + e.Body.Error.Message)); } catch (Exception e) { log.LogError($"ERROR: Exception with message: {e.Message}"); return(new BadRequestObjectResult("Error: " + e.Message)); } return((ActionResult) new OkObjectResult(new { playReadyLicenses = jToken })); }