First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <caf/streaming/keystreamdecoder.h>
17 #include <caf/streaming/streamagentfactory.h>
18 #include "streamagentresolver.h"
19 #include <caf/streaming/protectedstreamdesc.h>
21 #include <caf/supplier.h>
22 #include <caf/metadataarray.h>
24 using namespace StreamAccess;
26 EXPORT_C CKeyStreamDecoder* CKeyStreamDecoder::NewL(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc)
28 CKeyStreamDecoder* self = CKeyStreamDecoder::NewLC(aProtectedStreamDesc,aSdpKeyStream,aSdpDoc);
29 CleanupStack::Pop(self);
33 EXPORT_C CKeyStreamDecoder* CKeyStreamDecoder::NewLC(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc)
35 CKeyStreamDecoder* self = new(ELeave) CKeyStreamDecoder();
36 CleanupStack::PushL(self);
37 self->ConstructL(aProtectedStreamDesc,aSdpKeyStream,aSdpDoc);
41 CKeyStreamDecoder::CKeyStreamDecoder()
45 CKeyStreamDecoder::~CKeyStreamDecoder()
47 delete iAgentKeyStreamDecoder;
48 delete iStreamAgentFactory;
50 REComSession::DestroyedImplementation(iEcomKey);
51 REComSession::FinalClose();
54 void CKeyStreamDecoder::ConstructL(const CProtectedStreamDesc& aProtectedStreamDesc, const CSdpMediaField& aSdpKeyStream, const CSdpDocument& aSdpDoc)
56 DEBUG_PRINTF(_L("Creating a key stream decoder object."));
58 // Create an instance of the Stream Agent Resolver
59 CStreamAgentResolver* resolver = CStreamAgentResolver::NewLC();
61 /* Retrieve a reference to the CStreamAgentInfo object, associated to the resolved stream agent plugin
62 * capable of supporting the supplied SDP media description
64 CStreamAgentInfo& agentInfo = resolver->ResolveSdpKeyStreamL(aSdpKeyStream);
66 /* Create a handle to the factory object (CStreamAgentFactory) associated to the
67 * resolved stream agent, so that it can be successfully destroyed and freed having been used
69 iStreamAgentFactory = static_cast<CStreamAgentFactory *>(REComSession::CreateImplementationL(agentInfo.ImplementationUid(), iEcomKey));
71 // Instantiate the necessary implementation of key stream sink
72 CKeyStreamSink* keyStreamSink = aProtectedStreamDesc.CreateKeyStreamSinkLC();
74 // Retrieve a reference to the stream agents factory
75 CStreamAgentFactory& agentFactory = agentInfo.StreamAgentFactory();
77 /* The factory is then used to generate an instance of the CAgentKeyStreamDecoder, using the instantiated key
78 * stream sink and the SDP media description
80 iAgentKeyStreamDecoder = agentFactory.GetKeyStreamDecoderL(*keyStreamSink,aSdpKeyStream,aSdpDoc);
82 CleanupStack::PopAndDestroy(2,resolver); //< keyStreamSink, resolver
84 DEBUG_PRINTF(_L("The key stream decoder object has been created successfully."));
87 EXPORT_C void CKeyStreamDecoder::GetAttributeL(const TAttribute& aAttribute, TBool& aValue) const
89 iAgentKeyStreamDecoder->GetAttributeL(aAttribute, aValue);
92 EXPORT_C HBufC* CKeyStreamDecoder::GetStringAttributeLC(const TStringAttribute& aAttribute) const
94 return iAgentKeyStreamDecoder->GetStringAttributeLC(aAttribute);
98 EXPORT_C ContentAccess::CImportFile* CKeyStreamDecoder::CreateImportSessionLC(const TDesC8& aContentMimeType, const TDesC& aSuggestedName, const TDesC& aOutputDirectory) const
100 return DoCreateImportSessionLC(aContentMimeType, aSuggestedName, aOutputDirectory);
103 EXPORT_C ContentAccess::CImportFile* CKeyStreamDecoder::CreateImportSessionLC(const TDesC8& aContentMimeType) const
105 return DoCreateImportSessionLC(aContentMimeType, KNullDesC(), KNullDesC());
108 ContentAccess::CImportFile* CKeyStreamDecoder::DoCreateImportSessionLC(const TDesC8& aContentMimeType, const TDesC& aSuggestedName, const TDesC& aOutputDirectory) const
110 DEBUG_PRINTF(_L("Creating an import session for post-acquisition content."));
112 // Handle to the post-acquisition rights object file owned by the agent
114 // The content Id of the pos-acquisition rights object.
116 contentId.CreateL(KMimeTypesMaxLength);
117 contentId.CleanupClosePushL();
118 // The mime type which will be used to import the rights object
119 RBuf8 mimeTypeRights;
120 mimeTypeRights.CreateL(KMimeTypesMaxLength);
121 mimeTypeRights.CleanupClosePushL();
122 // The mime type which will be used to import the content file.
123 RBuf8 mimeTypeContent;
124 mimeTypeContent.CreateL(KMimeTypesMaxLength);
125 mimeTypeContent.CleanupClosePushL();
127 iAgentKeyStreamDecoder->GetPostDeliveryRightsL(fPostAcq, contentId, mimeTypeRights, mimeTypeContent);
128 CleanupClosePushL(fPostAcq);
130 DEBUG_PRINTF2(_L8("Post-acquisition RO's Mime Type: (%S)"), &mimeTypeRights);
131 DEBUG_PRINTF2(_L8("Post-acquisition Content's Mime Type: (%S)"), &mimeTypeContent);
134 ContentAccess::CSupplier* supplier = ContentAccess::CSupplier::NewLC();
135 // Check if there is any CAF agent supporting postacquisition rights object import
136 if(!supplier->IsImportSupported(mimeTypeRights))
138 DEBUG_PRINTF2(_L8("A CAF agent capable of importing (%S) mime type can not be found!"), &mimeTypeRights);
139 User::Leave(KErrNotSupported);
141 // if everything went successfully, create a file import object and import the rights object
142 // Create meta-data array
143 ContentAccess::CMetaDataArray* metaDataArray = ContentAccess::CMetaDataArray::NewLC();
145 // The content Id is provided as suggested name to allow the agent to generate the output file
146 HBufC* roName = HBufC::NewLC(contentId.Length());
147 TPtr roPtr (roName->Des());
148 roPtr.Copy(contentId);
149 // Create the import object for the rights object file
150 ContentAccess::CImportFile* importRo = supplier->ImportFileL(mimeTypeRights, *metaDataArray, *roName);
151 CleanupStack::PopAndDestroy(roName);
152 CleanupStack::PushL(importRo);
156 // Start importing the content of the post-acquisition RO file
159 User::LeaveIfError(fPostAcq.Read(buf));
160 dataLen = buf.Length();
161 User::LeaveIfError(importRo->WriteData(buf));
162 } while(dataLen > 0);
163 // Post-acquisition rigths object import is being completed
164 User::LeaveIfError(importRo->WriteDataComplete());
165 CleanupStack::PopAndDestroy(importRo);
167 //The meta data field of the content Id. A content Id is passed to an agent through this meta-data field.
168 _LIT8(KMetaDataFieldCid, "cid");
169 // Add the (postacq) RO's content id used to match the content with the RO
170 metaDataArray->AddL(KMetaDataFieldCid(), contentId);
172 //The meta data field of the mime type. A mime type is passed to an agent through this meta-data field.
173 _LIT8(KMetaDataFieldMimeType, "mimetype");
174 // Add the mime type of the protected streamed data (e.g. video/3gpp)
175 metaDataArray->AddL(KMetaDataFieldMimeType(), aContentMimeType);
177 // Create the import object for the protected streamed content
178 ContentAccess::CImportFile* importContent(0);
179 if((aSuggestedName.Length() > 0) && (aOutputDirectory.Length() > 0))
181 // A file name is suggested. The client wants the agent to generate the output files.
182 DEBUG_PRINTF2(_L("Output filename (%S) is suggested."), &aSuggestedName);
183 supplier->SetOutputDirectoryL(aOutputDirectory);
184 importContent = supplier->ImportFileL(mimeTypeContent, *metaDataArray, aSuggestedName);
188 // No suggested file name is passed to the agent, the client will provide output files for the agent to use
189 DEBUG_PRINTF(_L("Output filename is not suggested."));
190 importContent = supplier->ImportFileL(mimeTypeContent, *metaDataArray);
193 CleanupStack::PopAndDestroy(6, &contentId);
194 CleanupStack::PushL(importContent);
196 DEBUG_PRINTF(_L("Import session has been created successfully."));
198 return importContent;