Processing Key Stream

The CKeyStreamDecoder class provides an interface for initializing key stream decoders and process a key stream.

Follow the steps below to process a Key stream:

  1. Initialize a key stream decoder using CKeyStreamDecoder::NewLC() to launch a streaming agent.

    When a key stream decoder is initialized, a streaming agent that can handle the requested stream data is identified and launched. Get the required parameters as input for integrating with the with Session Description Protocol (SDP) definition.

  2. Query attributes from the server using CKeyStreamDecoder::GetStringAttributeL() and CKeyStreamDecoder::GetAttributeL().

    These methods provides information about a broadcaster or content provider and recording right indicating whether a stream can be recorded.

  3. Record the stream data using CKeyStreamDecoder::CreateImportSessionLC() to check for post-acquisition rights.

    If the rights object does not match with the recording rights, the request fails and returns an error.

Initializing key stream decoder

The following code segment shows initializing a key stream decoder and querying attributes from the server.

Note: The key stream decoder needs to remain active, to process a key stream.


/* In this code sample, a key stream decoder is created to decode a key stream which 
   is protected by IPSec. Create a protected stream descriptor for IPSec.
   serverAddr => source connection address (content distributor in real case). 
   This address can be extracted from the SDP (Session Description Protocol).
   It is assumed that the client has already received this object.
   clientAddr => target connection address (device in real case).
 
*/

CProtectedStreamDesc *protectedStreamDesc = CIpSecProtectedStreamDesc::NewLC(serverAddr, clientAddr);

/* The relevant media field for the key stream (CSdpMediaField* keyStreamSDPDesc) is 
  extracted from the SDP (CSdpDocument* sdpDocument).
   ......
   Now create the key stream decoder by using the protected stream descriptor, the key stream media 
   field, and the whole SDP object. 
*/

CKeyStreamDecoder *keyStreamDecoder = CKeyStreamDecoder::NewLC(protectedStreamDesc, keyStreamSDPDesc, 
 sdpDocument);
Cleanupstack::PopAndDestroy(protectedStreamDesc);

/*If this section of code is reached, the key stream decoder is initialized correctly. If the user has rights to view the stream, the content 
            will be decrypted.
*/

The following sequence of events occur in the back-end:

  • In case of an authenticated user of the service, the streaming agent loads the key stream. This creates a key stream decoder object.

  • The streaming agent starts a new processing task to decrypt the protected stream data. For example, the key processing task for IPSec is to decrypt Short Term Key Message (STKM) received as the key stream, and extract the corresponding cryptographic context.

Note: s
  • The key stream object must be kept alive while receiving the key stream and decrypting the protected streamed data.

  • If the user is not authenticated, (for example, no rights for a specific pay-per-view program), cryptographic context will not be set.

Querying for protected stream content

Query the streaming agent to get information about the protected stream content, using the created key stream decoder object.

The following code snippet shows an example for querying the playability of the content:

TBool playable = EFalse;
keyStreamDecoder->GetAttributeL(ECanPlay, playable);

// When the protected key stream receiving has finished or stopped, the key decoder object is destroyed.
Cleanupstack::PopAndDestroy(keyStreamDecoder);

Recording protected stream content

The following code snippet shows an example of recording protected streamed content with post-acquisition rights.

// Generate a protected key stream description for IPSec
CProtectedStreamDesc *protectedStreamDesc = CIpSecProtectedStreamDesc::NewLC(serverAddr, clientAddr);

// Create a key stream decoder 
CKeyStreamDecoder *keyStreamDecoder = CKeyStreamDecoder::NewLC(protectedStreamDesc, keyStreamSDPDesc,
 sdpDocument);

//Check whether the content is recordable
TBool value = EFalse;
keyStreamDecoder->GetAttributeL(ECanExport, value);
if(!value)
    {
    User::Leave(KErrCANotSupported);
    }

/* Get an import handle to record the protected streamed data in 3GPP video format
   By using the import handle, the streamed content will be recorded as protected together
   with its post-acquisition Rights Object. After importing, the recorded content is reached
   according to the restrictions defined in the post-acquisition Rights Object.
*/
CImportFile* import = keyStreamDecoder->CreateImportSessionLC(_L8("video/3gpp")); 

TPtr8 decryptedContent;
 do
    {
    
    // Decrypt the protected streamed content and assign to decryptedContent pointer.
    
    import->WriteData(decryptedContent);
    } while (decryptedContent);

// Import has been completed.
TFileName fileName;
TInt err = import->WriteDataComplete();
while (err == KErrCANewFileHandleRequired)              
     {
     err = ProvideNewOutputFileL(*import, fileName);
     if(err == KErrNone)
         {
         err = import->WriteDataComplete();
         }
     }
User::LeaveIfError(err);
Related concepts
Using Streaming CAF