sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "streamagentresolver.h" sl@0: #include sl@0: #include "scaflog.h" sl@0: #include sl@0: #include sl@0: sl@0: using namespace StreamAccess; sl@0: sl@0: EXPORT_C CKeyStreamDecoder* CKeyStreamDecoder::NewL(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc) sl@0: { sl@0: CKeyStreamDecoder* self = CKeyStreamDecoder::NewLC(aProtectedStreamDesc,aSdpKeyStream,aSdpDoc); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CKeyStreamDecoder* CKeyStreamDecoder::NewLC(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc) sl@0: { sl@0: CKeyStreamDecoder* self = new(ELeave) CKeyStreamDecoder(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aProtectedStreamDesc,aSdpKeyStream,aSdpDoc); sl@0: return self; sl@0: } sl@0: sl@0: CKeyStreamDecoder::CKeyStreamDecoder() sl@0: { sl@0: } sl@0: sl@0: CKeyStreamDecoder::~CKeyStreamDecoder() sl@0: { sl@0: delete iAgentKeyStreamDecoder; sl@0: delete iStreamAgentFactory; sl@0: sl@0: REComSession::DestroyedImplementation(iEcomKey); sl@0: REComSession::FinalClose(); sl@0: } sl@0: sl@0: void CKeyStreamDecoder::ConstructL(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc) sl@0: { sl@0: DEBUG_PRINTF(_L("Creating a key stream decoder object.")); sl@0: sl@0: // Create an instance of the Stream Agent Resolver sl@0: CStreamAgentResolver* resolver = CStreamAgentResolver::NewLC(); sl@0: sl@0: /* Retrieve a reference to the CStreamAgentInfo object, associated to the resolved stream agent plugin sl@0: * capable of supporting the supplied SDP media description sl@0: */ sl@0: CStreamAgentInfo& agentInfo = resolver->ResolveSdpKeyStreamL(aSdpKeyStream); sl@0: sl@0: /* Create a handle to the factory object (CStreamAgentFactory) associated to the sl@0: * resolved stream agent, so that it can be successfully destroyed and freed having been used sl@0: */ sl@0: iStreamAgentFactory = static_cast(REComSession::CreateImplementationL(agentInfo.ImplementationUid(), iEcomKey)); sl@0: sl@0: // Instantiate the necessary implementation of key stream sink sl@0: CKeyStreamSink* keyStreamSink = aProtectedStreamDesc.CreateKeyStreamSinkLC(); sl@0: sl@0: // Retrieve a reference to the stream agents factory sl@0: CStreamAgentFactory& agentFactory = agentInfo.StreamAgentFactory(); sl@0: sl@0: /* The factory is then used to generate an instance of the CAgentKeyStreamDecoder, using the instantiated key sl@0: * stream sink and the SDP media description sl@0: */ sl@0: iAgentKeyStreamDecoder = agentFactory.GetKeyStreamDecoderL(*keyStreamSink,aSdpKeyStream,aSdpDoc); sl@0: sl@0: CleanupStack::PopAndDestroy(2,resolver); //< keyStreamSink, resolver sl@0: sl@0: DEBUG_PRINTF(_L("The key stream decoder object has been created successfully.")); sl@0: } sl@0: sl@0: EXPORT_C void CKeyStreamDecoder::GetAttributeL(const TAttribute& aAttribute, TBool& aValue) const sl@0: { sl@0: iAgentKeyStreamDecoder->GetAttributeL(aAttribute, aValue); sl@0: } sl@0: sl@0: EXPORT_C HBufC* CKeyStreamDecoder::GetStringAttributeLC(const TStringAttribute& aAttribute) const sl@0: { sl@0: return iAgentKeyStreamDecoder->GetStringAttributeLC(aAttribute); sl@0: } sl@0: sl@0: sl@0: EXPORT_C ContentAccess::CImportFile* CKeyStreamDecoder::CreateImportSessionLC(const TDesC8& aContentMimeType, const TDesC& aSuggestedName, const TDesC& aOutputDirectory) const sl@0: { sl@0: return DoCreateImportSessionLC(aContentMimeType, aSuggestedName, aOutputDirectory); sl@0: } sl@0: sl@0: EXPORT_C ContentAccess::CImportFile* CKeyStreamDecoder::CreateImportSessionLC(const TDesC8& aContentMimeType) const sl@0: { sl@0: return DoCreateImportSessionLC(aContentMimeType, KNullDesC(), KNullDesC()); sl@0: } sl@0: sl@0: ContentAccess::CImportFile* CKeyStreamDecoder::DoCreateImportSessionLC(const TDesC8& aContentMimeType, const TDesC& aSuggestedName, const TDesC& aOutputDirectory) const sl@0: { sl@0: DEBUG_PRINTF(_L("Creating an import session for post-acquisition content.")); sl@0: sl@0: // Handle to the post-acquisition rights object file owned by the agent sl@0: RFile fPostAcq; sl@0: // The content Id of the pos-acquisition rights object. sl@0: RBuf8 contentId; sl@0: contentId.CreateL(KMimeTypesMaxLength); sl@0: contentId.CleanupClosePushL(); sl@0: // The mime type which will be used to import the rights object sl@0: RBuf8 mimeTypeRights; sl@0: mimeTypeRights.CreateL(KMimeTypesMaxLength); sl@0: mimeTypeRights.CleanupClosePushL(); sl@0: // The mime type which will be used to import the content file. sl@0: RBuf8 mimeTypeContent; sl@0: mimeTypeContent.CreateL(KMimeTypesMaxLength); sl@0: mimeTypeContent.CleanupClosePushL(); sl@0: sl@0: iAgentKeyStreamDecoder->GetPostDeliveryRightsL(fPostAcq, contentId, mimeTypeRights, mimeTypeContent); sl@0: CleanupClosePushL(fPostAcq); sl@0: sl@0: DEBUG_PRINTF2(_L8("Post-acquisition RO's Mime Type: (%S)"), &mimeTypeRights); sl@0: DEBUG_PRINTF2(_L8("Post-acquisition Content's Mime Type: (%S)"), &mimeTypeContent); sl@0: sl@0: // Create a supplier sl@0: ContentAccess::CSupplier* supplier = ContentAccess::CSupplier::NewLC(); sl@0: // Check if there is any CAF agent supporting postacquisition rights object import sl@0: if(!supplier->IsImportSupported(mimeTypeRights)) sl@0: { sl@0: DEBUG_PRINTF2(_L8("A CAF agent capable of importing (%S) mime type can not be found!"), &mimeTypeRights); sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: // if everything went successfully, create a file import object and import the rights object sl@0: // Create meta-data array sl@0: ContentAccess::CMetaDataArray* metaDataArray = ContentAccess::CMetaDataArray::NewLC(); sl@0: sl@0: // The content Id is provided as suggested name to allow the agent to generate the output file sl@0: HBufC* roName = HBufC::NewLC(contentId.Length()); sl@0: TPtr roPtr (roName->Des()); sl@0: roPtr.Copy(contentId); sl@0: // Create the import object for the rights object file sl@0: ContentAccess::CImportFile* importRo = supplier->ImportFileL(mimeTypeRights, *metaDataArray, *roName); sl@0: CleanupStack::PopAndDestroy(roName); sl@0: CleanupStack::PushL(importRo); sl@0: sl@0: TBuf8<128> buf; sl@0: TInt dataLen = 0; sl@0: // Start importing the content of the post-acquisition RO file sl@0: do sl@0: { sl@0: User::LeaveIfError(fPostAcq.Read(buf)); sl@0: dataLen = buf.Length(); sl@0: User::LeaveIfError(importRo->WriteData(buf)); sl@0: } while(dataLen > 0); sl@0: // Post-acquisition rigths object import is being completed sl@0: User::LeaveIfError(importRo->WriteDataComplete()); sl@0: CleanupStack::PopAndDestroy(importRo); sl@0: sl@0: //The meta data field of the content Id. A content Id is passed to an agent through this meta-data field. sl@0: _LIT8(KMetaDataFieldCid, "cid"); sl@0: // Add the (postacq) RO's content id used to match the content with the RO sl@0: metaDataArray->AddL(KMetaDataFieldCid(), contentId); sl@0: sl@0: //The meta data field of the mime type. A mime type is passed to an agent through this meta-data field. sl@0: _LIT8(KMetaDataFieldMimeType, "mimetype"); sl@0: // Add the mime type of the protected streamed data (e.g. video/3gpp) sl@0: metaDataArray->AddL(KMetaDataFieldMimeType(), aContentMimeType); sl@0: sl@0: // Create the import object for the protected streamed content sl@0: ContentAccess::CImportFile* importContent(0); sl@0: if((aSuggestedName.Length() > 0) && (aOutputDirectory.Length() > 0)) sl@0: { sl@0: // A file name is suggested. The client wants the agent to generate the output files. sl@0: DEBUG_PRINTF2(_L("Output filename (%S) is suggested."), &aSuggestedName); sl@0: supplier->SetOutputDirectoryL(aOutputDirectory); sl@0: importContent = supplier->ImportFileL(mimeTypeContent, *metaDataArray, aSuggestedName); sl@0: } sl@0: else sl@0: { sl@0: // No suggested file name is passed to the agent, the client will provide output files for the agent to use sl@0: DEBUG_PRINTF(_L("Output filename is not suggested.")); sl@0: importContent = supplier->ImportFileL(mimeTypeContent, *metaDataArray); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(6, &contentId); sl@0: CleanupStack::PushL(importContent); sl@0: sl@0: DEBUG_PRINTF(_L("Import session has been created successfully.")); sl@0: sl@0: return importContent; sl@0: }