Exemple #1
0
        private async void OnMediaProtectionManagerServiceRequested(MediaProtectionManager sender, ServiceRequestedEventArgs e)
        {
            Debug.WriteLine("ProtectionManager ServiceRequested");

            _serviceCompletionNotifier = e.Completion;
            IPlayReadyServiceRequest serviceRequest = (IPlayReadyServiceRequest)e.Request;

            Debug.WriteLine("Servie request type = " + serviceRequest.GetType());

            var result = false;

            if (serviceRequest.Type == PlayReadyStatics.IndividualizationServiceRequestType)
            {
                result = await PlayReadyLicenseHandler.RequestIndividualizationToken(serviceRequest as PlayReadyIndividualizationServiceRequest);
            }
            else if (serviceRequest.Type == PlayReadyStatics.LicenseAcquirerServiceRequestType)
            {
                // NOTE: You might need to set the request.ChallengeCustomData, depending on your Rights Manager.
                if (RequestConfigData != null)
                {
                    _requestChain = new RequestChain(serviceRequest);
                    _requestChain.RequestConfigData = this.RequestConfigData;
                    _requestChain.FinishAndReportResult(HandleServiceRequest_Finished);

                    return;
                }
                else
                {
                    result = await PlayReadyLicenseHandler.RequestLicense(serviceRequest as PlayReadyLicenseAcquisitionServiceRequest);
                }
            }

            _serviceCompletionNotifier.Complete(result);
        }
Exemple #2
0
        void ServiceRequested(MediaProtectionManager sender, ServiceRequestedEventArgs srEvent)
        {
            serviceCompletionNotifier = srEvent.Completion;
            IPlayReadyServiceRequest serviceRequest = (IPlayReadyServiceRequest)srEvent.Request;

            ViewModelBase.Log(serviceRequest.GetType().Name);
            ProcessServiceRequest(serviceRequest);
        }
Exemple #3
0
        void ProtectionManager_ServiceRequested(MediaProtectionManager sender, ServiceRequestedEventArgs srEvent)
        {
            _serviceCompletionNotifier = srEvent.Completion;
            IPlayReadyServiceRequest serviceRequest = (IPlayReadyServiceRequest)srEvent.Request;

            _requestChain = new RequestChain(serviceRequest);
            _requestChain.LicenseRequestUri = new Uri(LAURL);
            _requestChain.RequestConfigData = this.RequestConfigData;
            _requestChain.FinishAndReportResult(new ReportResultDelegate(HandleServiceRequest_Finished));
        }
Exemple #4
0
        void ProtectionManager_ServiceRequested(MediaProtectionManager sender, ServiceRequestedEventArgs srEvent)
        {
            TestLogger.LogMessage("Enter Playback.ProtectionManager_ServiceRequested()");

            _serviceCompletionNotifier = srEvent.Completion;
            IPlayReadyServiceRequest serviceRequest = ( IPlayReadyServiceRequest )srEvent.Request;

            TestLogger.LogMessage("Servie request type = " + serviceRequest.GetType());

            _requestChain = new RequestChain(serviceRequest);
            _requestChain.RequestConfigData = this.RequestConfigData;
            _requestChain.FinishAndReportResult(new ReportResultDelegate(HandleServiceRequest_Finished));

            TestLogger.LogMessage("Leave Playback.ProtectionManager_ServiceRequested()");
        }
Exemple #5
0
        /// <summary>
        /// Reactive license acquisition is triggered by PlayReady when the DRM does not have a license for the
        /// content(KeyID) as part of an active playback attempt.
        /// Service requests can be queued which is useful in scenarios such as root/leaf license and PlayReady Domains
        /// where one license depends on another. The serviceCompletionNotifier is utilized to notify the ProtectionManager
        /// that the next service request can begin.
        /// </summary>
        static async public void ReactiveLicenseAcquisition(IPlayReadyLicenseAcquisitionServiceRequest licenseRequest,
                                                            MediaProtectionServiceCompletion serviceCompletionNotifier,
                                                            Action callback = null)
        {
            Exception exception = null;
            bool      success   = false;

            try
            {
                await licenseRequest.BeginServiceRequest();

                success = true;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (serviceCompletionNotifier != null)
                {
                    // The Complete call will notify listeners that the service call is complete
                    // and queued service requests can begin.
                    serviceCompletionNotifier.Complete(success);
                    serviceCompletionNotifier = null;
                }
                ViewModelBase.Log("ReactiveLicenseAcquisition::Complete");
            }

            // optional call back to update UI.
            if (callback != null)
            {
                var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    callback.Invoke();
                });
            }
        }
Exemple #6
0
        /// <summary>
        /// Reactive individualization is triggered by PlayReady when the DRM is first utilized in a new app.
        /// If individualization was triggered as part a license request then that request will be queued until
        /// the indiv process completes. The serviceCompletionNotifier is utilized to notify the ProtectionManager
        /// that the next service request can begin.
        /// </summary>
        static public async void ReactiveIndividualization(PlayReadyIndividualizationServiceRequest indivRequest,
                                                           MediaProtectionServiceCompletion serviceCompletionNotifier,
                                                           Action callback = null)
        {
            Exception exception = null;

            try
            {
                // The actual service call.
                // The Indiv ServiceRequest call cannot be customized like most other ServiceRequests.
                await indivRequest.BeginServiceRequest();
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (serviceCompletionNotifier != null)
                {
                    // The Complete call will notify listeners that the service call is complete
                    // and queued service requests can begin.
                    serviceCompletionNotifier.Complete(exception == null);
                }
                ViewModelBase.Log("ReactiveIndividualization::Complete");
            }

            // The callback is only used in the sample to show PlayReadyStatics within the UI on the
            // completion of the ServiceRequest.
            if (callback != null)
            {
                var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    callback.Invoke();
                });
            }
        }
Exemple #7
0
        // Method not used in this sample.
        // This shows the minimal configuration for basic reactive playback.
        public void MinConfig(MediaElement mediaElement)
        {
            var manager = new MediaProtectionManager();
            var props   = new Windows.Foundation.Collections.PropertySet();

            props.Add("{F4637010-03C3-42CD-B932-B48ADF3A6A54}", "Windows.Media.Protection.PlayReady.PlayReadyWinRTTrustedInput");
            manager.Properties.Add("Windows.Media.Protection.MediaProtectionSystemIdMapping", props);
            manager.Properties.Add("Windows.Media.Protection.MediaProtectionSystemId", "{F4637010-03C3-42CD-B932-B48ADF3A6A54}");
            manager.Properties.Add("Windows.Media.Protection.MediaProtectionContainerGuid", "{9A04F079-9840-4286-AB92-E65BE0885F95}");

            MediaProtectionServiceCompletion completionNotifer = null;

            manager.ServiceRequested += async(sender, srEvent) =>
            {
                completionNotifer = srEvent.Completion;
                var serviceRequest = (IPlayReadyServiceRequest)srEvent.Request;

                ProcessServiceRequest(serviceRequest);
                if (serviceRequest is PlayReadyIndividualizationServiceRequest)
                {
                    var indivRequest = serviceRequest as PlayReadyIndividualizationServiceRequest;
                    await indivRequest.BeginServiceRequest();

                    serviceCompletionNotifier.Complete(true);
                }
                else if (serviceRequest is PlayReadyLicenseAcquisitionServiceRequest)
                {
                    var licenseRequest = serviceRequest as PlayReadyLicenseAcquisitionServiceRequest;
                    //licenseRequest.
                    await licenseRequest.BeginServiceRequest();

                    serviceCompletionNotifier.Complete(true);
                    serviceCompletionNotifier = null;
                }
            };
            mediaElement.ProtectionManager = manager;
        }
Exemple #8
0
        /// <summary>
        /// Invoked to send the Individualization Request
        /// </summary>
        async Task <bool> ReactiveIndividualizationRequestAsync(PlayReadyIndividualizationServiceRequest individualizationRequest, MediaProtectionServiceCompletion completionNotifier)
        {
            bool bResult = false;

            Log("ProtectionManager PlayReady Individualization Service Request in progress...");
            try
            {
                await individualizationRequest.BeginServiceRequest();

                bResult = true;
            }
            catch (COMException comException) when(comException.HResult == MSPR_E_CONTENT_ENABLING_ACTION_REQUIRED)
            {
                individualizationRequest.NextServiceRequest();
            }
            catch (Exception)
            {
            }

            if (bResult == true)
            {
                Log("ProtectionManager PlayReady Individualization Service Request successful");
            }
            else
            {
                Log("ProtectionManager PlayReady Individualization Service Request failed");
            }
            if (completionNotifier != null)
            {
                completionNotifier.Complete(bResult);
            }
            return(bResult);
        }
Exemple #9
0
        /// <summary>
        /// Invoked to acquire the PlayReady License
        /// </summary>
        async void LicenseAcquisitionRequest(PlayReadyLicenseAcquisitionServiceRequest licenseRequest, MediaProtectionServiceCompletion completionNotifier, string url, string challengeCustomData)
        {
            bool   bResult          = false;
            string ExceptionMessage = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(url))
                {
                    Log("ProtectionManager PlayReady Manual License Acquisition Service Request in progress - URL: " + url);

                    if (!string.IsNullOrEmpty(challengeCustomData))
                    {
                        var    encoding = new UTF8Encoding();
                        byte[] b        = encoding.GetBytes(challengeCustomData);
                        licenseRequest.ChallengeCustomData = Convert.ToBase64String(b, 0, b.Length);
                    }

                    PlayReadySoapMessage soapMessage = licenseRequest.GenerateManualEnablingChallenge();

                    byte[]      messageBytes = soapMessage.GetMessageBody();
                    HttpContent httpContent  = new ByteArrayContent(messageBytes);

                    IPropertySet propertySetHeaders = soapMessage.MessageHeaders;
                    foreach (string strHeaderName in propertySetHeaders.Keys)
                    {
                        string strHeaderValue = propertySetHeaders[strHeaderName].ToString();

                        // The Add method throws an ArgumentException try to set protected headers like "Content-Type"
                        // so set it via "ContentType" property
                        if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase))
                        {
                            httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue);
                        }
                        else
                        {
                            httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue);
                        }
                    }
                    var         licenseAcquision    = new CommonLicenseRequest();
                    HttpContent responseHttpContent = await licenseAcquision.AcquireLicenseAsync(new Uri(url), httpContent);

                    if (responseHttpContent != null)
                    {
                        Exception exResult = licenseRequest.ProcessManualEnablingResponse(await responseHttpContent.ReadAsByteArrayAsync());
                        if (exResult != null)
                        {
                            throw exResult;
                        }
                        bResult = true;
                    }
                    else
                    {
                        ExceptionMessage = licenseAcquision.GetLastErrorMessage();
                    }
                }
                else
                {
                    Log("ProtectionManager PlayReady License Acquisition Service Request in progress - URL: " + licenseRequest.Uri.ToString());
                    await licenseRequest.BeginServiceRequest();

                    bResult = true;
                }
            }
            catch (Exception e)
            {
                ExceptionMessage = e.Message;
            }

            if (bResult == true)
            {
                Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request successful" :
                    "ProtectionManager PlayReady License Acquisition Service Request successful");
            }
            else
            {
                Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request failed: " + ExceptionMessage :
                    "ProtectionManager PlayReady License Acquisition Service Request failed: " + ExceptionMessage);
            }
            completionNotifier.Complete(bResult);
        }
        /// <summary>
        /// Invoked to send the Individualization Request
        /// </summary>
        async Task <bool> ReactiveIndivRequest(PlayReadyIndividualizationServiceRequest IndivRequest, MediaProtectionServiceCompletion CompletionNotifier)
        {
            bool      bResult   = false;
            Exception exception = null;

            log("ProtectionManager PlayReady Individualization Service Request in progress...");
            try
            {
                await IndivRequest.BeginServiceRequest();
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                if (exception == null)
                {
                    bResult = true;
                }
                else
                {
                    COMException comException = exception as COMException;
                    if (comException != null && comException.HResult == MSPR_E_CONTENT_ENABLING_ACTION_REQUIRED)
                    {
                        IndivRequest.NextServiceRequest();
                    }
                }
            }
            if (bResult == true)
            {
                log("ProtectionManager PlayReady Individualization Service Request successful");
            }
            else
            {
                log("ProtectionManager PlayReady Individualization Service Request failed");
            }
            if (CompletionNotifier != null)
            {
                CompletionNotifier.Complete(bResult);
            }
            return(bResult);
        }