os/security/contentmgmt/cafstreamingsupport/source/keystreamdecoder.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <caf/streaming/keystreamdecoder.h>
sl@0
    17
#include <caf/streaming/streamagentfactory.h>
sl@0
    18
#include "streamagentresolver.h"
sl@0
    19
#include <caf/streaming/protectedstreamdesc.h>
sl@0
    20
#include "scaflog.h"
sl@0
    21
#include <caf/supplier.h>
sl@0
    22
#include <caf/metadataarray.h>
sl@0
    23
sl@0
    24
using namespace StreamAccess;
sl@0
    25
 
sl@0
    26
EXPORT_C CKeyStreamDecoder* CKeyStreamDecoder::NewL(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc)
sl@0
    27
	{
sl@0
    28
	CKeyStreamDecoder* self = CKeyStreamDecoder::NewLC(aProtectedStreamDesc,aSdpKeyStream,aSdpDoc);
sl@0
    29
	CleanupStack::Pop(self);
sl@0
    30
	return self;
sl@0
    31
	}
sl@0
    32
sl@0
    33
EXPORT_C CKeyStreamDecoder* CKeyStreamDecoder::NewLC(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc)
sl@0
    34
	{
sl@0
    35
	CKeyStreamDecoder* self = new(ELeave) CKeyStreamDecoder();
sl@0
    36
	CleanupStack::PushL(self);
sl@0
    37
	self->ConstructL(aProtectedStreamDesc,aSdpKeyStream,aSdpDoc);
sl@0
    38
	return self;
sl@0
    39
	}
sl@0
    40
sl@0
    41
CKeyStreamDecoder::CKeyStreamDecoder()
sl@0
    42
	{
sl@0
    43
	}
sl@0
    44
sl@0
    45
CKeyStreamDecoder::~CKeyStreamDecoder()
sl@0
    46
	{
sl@0
    47
	delete iAgentKeyStreamDecoder;
sl@0
    48
	delete iStreamAgentFactory;
sl@0
    49
	
sl@0
    50
	REComSession::DestroyedImplementation(iEcomKey);
sl@0
    51
	REComSession::FinalClose();	
sl@0
    52
	}
sl@0
    53
sl@0
    54
void CKeyStreamDecoder::ConstructL(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc)
sl@0
    55
	{
sl@0
    56
	DEBUG_PRINTF(_L("Creating a key stream decoder object."));
sl@0
    57
	
sl@0
    58
	// Create an instance of the Stream Agent Resolver
sl@0
    59
	CStreamAgentResolver* resolver = CStreamAgentResolver::NewLC();
sl@0
    60
	
sl@0
    61
	/* Retrieve a reference to the CStreamAgentInfo object, associated to the resolved stream agent plugin 
sl@0
    62
	 * capable of supporting the supplied SDP media description 
sl@0
    63
	 */
sl@0
    64
	CStreamAgentInfo& agentInfo = resolver->ResolveSdpKeyStreamL(aSdpKeyStream);
sl@0
    65
	
sl@0
    66
	/* Create a handle to the factory object (CStreamAgentFactory) associated to the
sl@0
    67
	 * resolved stream agent, so that it can be successfully destroyed and freed having been used 
sl@0
    68
	 */
sl@0
    69
	iStreamAgentFactory = static_cast<CStreamAgentFactory *>(REComSession::CreateImplementationL(agentInfo.ImplementationUid(), iEcomKey));
sl@0
    70
	
sl@0
    71
	// Instantiate the necessary implementation of key stream sink
sl@0
    72
	CKeyStreamSink* keyStreamSink = aProtectedStreamDesc.CreateKeyStreamSinkLC();
sl@0
    73
	
sl@0
    74
	// Retrieve a reference to the stream agents factory
sl@0
    75
	CStreamAgentFactory& agentFactory = agentInfo.StreamAgentFactory();
sl@0
    76
	
sl@0
    77
	/* The factory is then used to generate an instance of the CAgentKeyStreamDecoder, using the instantiated key
sl@0
    78
	 * stream sink and the SDP media description
sl@0
    79
	 */
sl@0
    80
	iAgentKeyStreamDecoder = agentFactory.GetKeyStreamDecoderL(*keyStreamSink,aSdpKeyStream,aSdpDoc);
sl@0
    81
	
sl@0
    82
	CleanupStack::PopAndDestroy(2,resolver); //< keyStreamSink, resolver
sl@0
    83
	
sl@0
    84
	DEBUG_PRINTF(_L("The key stream decoder object has been created successfully."));
sl@0
    85
	}
sl@0
    86
	
sl@0
    87
EXPORT_C void CKeyStreamDecoder::GetAttributeL(const TAttribute& aAttribute, TBool& aValue) const
sl@0
    88
	{
sl@0
    89
	iAgentKeyStreamDecoder->GetAttributeL(aAttribute, aValue);
sl@0
    90
	}
sl@0
    91
sl@0
    92
EXPORT_C HBufC* CKeyStreamDecoder::GetStringAttributeLC(const TStringAttribute& aAttribute) const
sl@0
    93
	{
sl@0
    94
	return iAgentKeyStreamDecoder->GetStringAttributeLC(aAttribute);
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
EXPORT_C ContentAccess::CImportFile* CKeyStreamDecoder::CreateImportSessionLC(const TDesC8& aContentMimeType, const TDesC& aSuggestedName, const TDesC& aOutputDirectory) const
sl@0
    99
	{
sl@0
   100
	return DoCreateImportSessionLC(aContentMimeType, aSuggestedName, aOutputDirectory);
sl@0
   101
	}
sl@0
   102
sl@0
   103
EXPORT_C ContentAccess::CImportFile* CKeyStreamDecoder::CreateImportSessionLC(const TDesC8& aContentMimeType) const
sl@0
   104
	{
sl@0
   105
	return DoCreateImportSessionLC(aContentMimeType, KNullDesC(), KNullDesC());
sl@0
   106
	}
sl@0
   107
sl@0
   108
ContentAccess::CImportFile* CKeyStreamDecoder::DoCreateImportSessionLC(const TDesC8& aContentMimeType, const TDesC& aSuggestedName, const TDesC& aOutputDirectory) const
sl@0
   109
	{
sl@0
   110
	DEBUG_PRINTF(_L("Creating an import session for post-acquisition content."));
sl@0
   111
	
sl@0
   112
	// Handle to the post-acquisition rights object file owned by the agent
sl@0
   113
	RFile   fPostAcq;
sl@0
   114
	// The content Id of the pos-acquisition rights object.
sl@0
   115
	RBuf8 contentId;
sl@0
   116
	contentId.CreateL(KMimeTypesMaxLength);
sl@0
   117
	contentId.CleanupClosePushL();
sl@0
   118
	// The mime type which will be used to import the rights object
sl@0
   119
	RBuf8 mimeTypeRights; 
sl@0
   120
	mimeTypeRights.CreateL(KMimeTypesMaxLength);
sl@0
   121
	mimeTypeRights.CleanupClosePushL();
sl@0
   122
	// The mime type which will be used to import the content file.
sl@0
   123
	RBuf8 mimeTypeContent;
sl@0
   124
	mimeTypeContent.CreateL(KMimeTypesMaxLength);
sl@0
   125
	mimeTypeContent.CleanupClosePushL();
sl@0
   126
	
sl@0
   127
	iAgentKeyStreamDecoder->GetPostDeliveryRightsL(fPostAcq, contentId, mimeTypeRights, mimeTypeContent);
sl@0
   128
	CleanupClosePushL(fPostAcq);
sl@0
   129
	
sl@0
   130
	DEBUG_PRINTF2(_L8("Post-acquisition RO's Mime Type: (%S)"), &mimeTypeRights);
sl@0
   131
	DEBUG_PRINTF2(_L8("Post-acquisition Content's Mime Type: (%S)"), &mimeTypeContent);
sl@0
   132
	
sl@0
   133
	// Create a supplier
sl@0
   134
	ContentAccess::CSupplier* supplier = ContentAccess::CSupplier::NewLC();
sl@0
   135
	// Check if there is any CAF agent supporting postacquisition rights object import
sl@0
   136
	if(!supplier->IsImportSupported(mimeTypeRights))
sl@0
   137
		{
sl@0
   138
		DEBUG_PRINTF2(_L8("A CAF agent capable of importing (%S) mime type can not be found!"), &mimeTypeRights);
sl@0
   139
		User::Leave(KErrNotSupported);
sl@0
   140
		}
sl@0
   141
	// if everything went successfully, create a file import object and import the rights object
sl@0
   142
	// Create meta-data array
sl@0
   143
	ContentAccess::CMetaDataArray* metaDataArray = ContentAccess::CMetaDataArray::NewLC();
sl@0
   144
sl@0
   145
	// The content Id is provided as suggested name to allow the agent to generate the output file
sl@0
   146
	HBufC* roName = HBufC::NewLC(contentId.Length());
sl@0
   147
	TPtr roPtr (roName->Des());
sl@0
   148
	roPtr.Copy(contentId);
sl@0
   149
	// Create the import object for the rights object file
sl@0
   150
	ContentAccess::CImportFile* importRo =  supplier->ImportFileL(mimeTypeRights, *metaDataArray, *roName);
sl@0
   151
	CleanupStack::PopAndDestroy(roName);
sl@0
   152
	CleanupStack::PushL(importRo);
sl@0
   153
	
sl@0
   154
	TBuf8<128> buf;
sl@0
   155
	TInt dataLen = 0;
sl@0
   156
	// Start importing the content of the post-acquisition RO file
sl@0
   157
	do
sl@0
   158
		{
sl@0
   159
		User::LeaveIfError(fPostAcq.Read(buf));
sl@0
   160
		dataLen = buf.Length();
sl@0
   161
		User::LeaveIfError(importRo->WriteData(buf));
sl@0
   162
		} while(dataLen > 0);
sl@0
   163
	// Post-acquisition rigths object import is being completed
sl@0
   164
	User::LeaveIfError(importRo->WriteDataComplete());
sl@0
   165
	CleanupStack::PopAndDestroy(importRo);
sl@0
   166
	
sl@0
   167
	//The meta data field of the content Id. A content Id is passed to an agent through this meta-data field.
sl@0
   168
	_LIT8(KMetaDataFieldCid, "cid");
sl@0
   169
	// Add the (postacq) RO's content id used to match the content with the RO
sl@0
   170
	metaDataArray->AddL(KMetaDataFieldCid(), contentId);
sl@0
   171
	
sl@0
   172
	//The meta data field of the mime type. A mime type is passed to an agent through this meta-data field.
sl@0
   173
	_LIT8(KMetaDataFieldMimeType, "mimetype");
sl@0
   174
	// Add the mime type of the protected streamed data (e.g. video/3gpp)
sl@0
   175
	metaDataArray->AddL(KMetaDataFieldMimeType(), aContentMimeType);
sl@0
   176
	
sl@0
   177
	// Create the import object for the protected streamed content
sl@0
   178
	ContentAccess::CImportFile* importContent(0);
sl@0
   179
	if((aSuggestedName.Length() > 0) && (aOutputDirectory.Length() > 0))
sl@0
   180
		{
sl@0
   181
		// A file name is suggested. The client wants the agent to generate the output files.
sl@0
   182
		DEBUG_PRINTF2(_L("Output filename (%S) is suggested."), &aSuggestedName);
sl@0
   183
		supplier->SetOutputDirectoryL(aOutputDirectory);
sl@0
   184
		importContent =  supplier->ImportFileL(mimeTypeContent, *metaDataArray, aSuggestedName);
sl@0
   185
		}
sl@0
   186
	else
sl@0
   187
		{
sl@0
   188
		// No suggested file name is passed to the agent, the client will provide output files for the agent to use
sl@0
   189
		DEBUG_PRINTF(_L("Output filename is not suggested."));
sl@0
   190
		importContent =  supplier->ImportFileL(mimeTypeContent, *metaDataArray);
sl@0
   191
		}
sl@0
   192
	
sl@0
   193
	CleanupStack::PopAndDestroy(6, &contentId);
sl@0
   194
	CleanupStack::PushL(importContent);
sl@0
   195
	
sl@0
   196
	DEBUG_PRINTF(_L("Import session has been created successfully."));
sl@0
   197
	
sl@0
   198
	return importContent;
sl@0
   199
	}