Skip to main content
Skip table of contents

Initialising the DRM

This document describes direct mode initialisation only.

To enable encrypted playback, you must first initialise the DRM by creating and starting the PakCore instance. This operation can occur after the whole application has started up and must descramble content or after the PAK disposal due to an error state.

Creating the PAK

The following code sample shows how to create the PAK.

CODE
+(void)initialize
{
  (…)
  PakCore::gCreateUnstartedInstance();
  PakCore* pCore = PakCore::pgGetInstance();
  assert(pCore!=0);
  (…)
  ret = pCore->start();
  assert(ret);
}

Setting platform parameters

The client application must read the operator vault file and provide it as a byte buffer to the PakCore. The client application must also provide the user store file and file path. This file path must be valid, and the specified file must be accessible. If the file is not present, it is the responsibility of the application to create it. The platform parameters must be set before the PakCore instance is started. Failing to do so will prevent the PakCore from starting.

Example code

The following code sample shows how to set platform parameters.

CODE
+(void)initialize
{
  (…)
  IPakCorePlatformParameters* pCorePlatformParameters = pCore->pGetPlatformParametersInterface();
  assert(pCorePlatformParameters!=0);
  NMPPakCoreBuffer opvaultBuffer;
  NSMutableData* opvaulData = [[NSMutableData alloc] initWithContentsOfFile:opVaultPath];
  opvaultBuffer.setData(opvaulData);
  bool ret = pCorePlatformParameters->setOperatorVaultBuffer(opvaultBuffer);
  assert(ret);
  ret = pCorePlatformParameters->setUserStoreFilePath([stroragePath UTF8String]);
  assert(ret);
  (…)
  ret = pCore->start();
  assert(ret);
}

Configuring debug settings (optional)

By default, the debug level is NONE. If debug is available, the debug settings can be enabled or changed at any time.

Example code

The following code example shows how to configure the log provider and logging level.

CODE
+(void)initialize
{
  (…)
#if defined(TRACE) || defined(DEBUG)
  IPakCoreDebugSettings* pCoreDebugSettings = pCore->pGetDebugSettingsInterface();
  if(pCoreDebugSettings)
  {
    pCoreDebugSettings->setDebugLevel(IPakCoreDebugSettings::DBG_LEVEL_WARNING);
 
    static NMPPakCoreDebugProvider* debugProvider = NULL;
    debugProvider = new NMPPakCoreDebugProvider;
    pCoreDebugSettings->setLogProvider(debugProvider);
  }
#endif
  (…)
  ret = pCore->start();
  assert(ret);
}

Initialising the PAK

You must initialise the PAK for it to become usable.

The PAK connects directly to the license server to retrieve initialisation payloads. The client application and the remote server portal do not need to be involved in exchanges but should exchange data through application data sent along initialisation exchanges, typically to manage the authentication of initialisation requests.

If an error occurs preventing the initialisation from happening, the client application controls the retries and whether to display an error to the user. The PAK must be initialised each time it is created, immediately after it has been started.

Example code

Silent initialisation is a single command, three-step process.

Set up notifications and observers

CODE
@interface DrmHandler ()
{
  //NMPPakCoreNotifListener instance for PAK stateChanged event
  NMPPakCoreNotifListener* _stateLis;
...
}
- (void)initializeListenersAndObservers
{
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pakStateChanged)  name:@"PAKStateChanged" object:nil];
...
  PakCore *pPakCore = PakCore :: pgGetInstance();
  IPakCoreDrmAgent *pDrmAgent = pPakCore->pGetDrmAgent();
  _stateLis    = new NMPPakCoreNotifListener(@"PAKStateChanged");

  if (!pDrmAgent->addPakStateChangedListener(*_stateLis)){
    NMPCLog(@"addPakStateChanged listener failed");
  }
...
}

Perform the actual silent initialise

CODE
- (void)directInitialize: (NSDictionary*)server
{
  PakCore *pPakCore = PakCore :: pgGetInstance();
  IPakCoreDrmAgent *pDrmAgent = pPakCore->pGetDrmAgent();
  If (pDrmAgent->getState() !=
    IPakCoreDrmAgent::PAK_ERROR_CONNECTION_REQUIRED) {
      return;
  }

  pDrmAgent->silentInitialize([server[@"url"] UTF8String],
                              [server[@"protectedPrivateData"] UTF8String],
                              [server[@"clearPrivateData"] UTF8String],
                              true);
}

Wait for PAK notification and check DRM values

CODE
// simple example to check the state of the server

- (void) pakStateChanged
{
  PakCore *pPakCore = PakCore :: pgGetInstance();
  IPakCoreDrmAgent *pDrmAgent = pPakCore->pGetDrmAgent();
  if ((pDrmAgent->getState() == IPakCoreDrmAgent::PAK_READY)
    && (pDrmAgent->getLastCommunicationStatus() ==
    NMP::COMMUNICATION_STATUS_OK))
  {
    NMPCLog(@"Sever is ready");
  }
}

Next step: You can now obtain the licence.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.