os/security/contentmgmt/cafstreamingsupport/source/streamagentresolver.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 "streamagentresolver.h"
sl@0
    17
#include "streamagentinfo.h"
sl@0
    18
#include <caf/streaming/streamagentfactory.h>
sl@0
    19
#include <caf/patchdata.h>
sl@0
    20
#include "scaflog.h"
sl@0
    21
sl@0
    22
#include <caf/caferr.h>
sl@0
    23
sl@0
    24
using namespace StreamAccess;
sl@0
    25
sl@0
    26
CStreamAgentResolver* CStreamAgentResolver::NewLC()
sl@0
    27
	{
sl@0
    28
	CStreamAgentResolver* self = new(ELeave) CStreamAgentResolver();
sl@0
    29
	CleanupStack::PushL(self);
sl@0
    30
	self->ConstructL();
sl@0
    31
	return self;
sl@0
    32
	}
sl@0
    33
sl@0
    34
CStreamAgentResolver::CStreamAgentResolver()
sl@0
    35
	{
sl@0
    36
	}
sl@0
    37
sl@0
    38
CStreamAgentResolver::~CStreamAgentResolver()
sl@0
    39
	{
sl@0
    40
	// Reset and Destroy the stream agent information array 
sl@0
    41
	iStreamAgentInfoArray.ResetAndDestroy();
sl@0
    42
	}
sl@0
    43
sl@0
    44
void CStreamAgentResolver::ConstructL()
sl@0
    45
	{
sl@0
    46
	// Construct a list of the available stream agent interface implementations
sl@0
    47
	BuildStreamAgentListL();
sl@0
    48
	}
sl@0
    49
sl@0
    50
void CStreamAgentResolver::BuildStreamAgentListL()
sl@0
    51
	{
sl@0
    52
	/* Construct a new implementation information array that is used in conjunction with the ECOM
sl@0
    53
	 * framework in order to retrieve resource data about the available stream agent plug-ins
sl@0
    54
	 */
sl@0
    55
	RImplInfoPtrArray agentImplArray;
sl@0
    56
	CleanupStack::PushL(TCleanupItem(CleanAgentImplArray, &agentImplArray));
sl@0
    57
	REComSession::ListImplementationsL(KUidStreamAgentFactoryInterface, agentImplArray);
sl@0
    58
	
sl@0
    59
	TInt streamAgentCount = agentImplArray.Count();
sl@0
    60
	
sl@0
    61
	DEBUG_PRINTF2(_L("Number of streaming agents found on the device: %d"),streamAgentCount);
sl@0
    62
	
sl@0
    63
	for (TInt i = 0; i < streamAgentCount; ++i)
sl@0
    64
		{
sl@0
    65
		/* In order to load stream agents from sources other than ROM, the patch 
sl@0
    66
		 * data KCafLoadPostProductionAgents must be set to True (non-zero).
sl@0
    67
		 * Default SymbianOS behavior is to only load file and streaming agents from ROM
sl@0
    68
		 */
sl@0
    69
		if ((KCafLoadPostProductionAgents == 0) &&
sl@0
    70
            !agentImplArray[i]->RomBased())
sl@0
    71
			{
sl@0
    72
			/* If the stream agent is not in ROM, don't load it because it might
sl@0
    73
			 * be a security risk.
sl@0
    74
			 */
sl@0
    75
			continue;
sl@0
    76
			}
sl@0
    77
		
sl@0
    78
		/* Construct a seperate element in the CStreamAgentInfo array for each of the 
sl@0
    79
		 * identified stream agent implementations 
sl@0
    80
		 */
sl@0
    81
		AddStreamAgentL(*agentImplArray[i]);
sl@0
    82
		}
sl@0
    83
	
sl@0
    84
	CleanupStack::PopAndDestroy(&agentImplArray);
sl@0
    85
	}
sl@0
    86
sl@0
    87
void CStreamAgentResolver::CleanAgentImplArray(TAny* aArray)
sl@0
    88
	{
sl@0
    89
	// Performs the cleanup on the implementation information array
sl@0
    90
	static_cast<RImplInfoPtrArray*>(aArray)->ResetAndDestroy();
sl@0
    91
	}
sl@0
    92
sl@0
    93
void CStreamAgentResolver::AddStreamAgentL(const CImplementationInformation& aAgentInfo)
sl@0
    94
	{
sl@0
    95
	// Create a new CStreamAgentInfo instance to add to the stream agent list
sl@0
    96
	CStreamAgentInfo* agentInformation = CStreamAgentInfo::NewLC(aAgentInfo);
sl@0
    97
	
sl@0
    98
	TUid agentUid(agentInformation->ImplementationUid());
sl@0
    99
	TPtrC agentName(agentInformation->Name());
sl@0
   100
	
sl@0
   101
	DEBUG_PRINTF3(_L("Stream Agent Identified: 0x%08x (%S)"),agentUid,&agentName);
sl@0
   102
	
sl@0
   103
	// Append the CStreamAgentInfo object to the stream agent information array
sl@0
   104
	User::LeaveIfError(iStreamAgentInfoArray.Append(agentInformation));
sl@0
   105
	CleanupStack::Pop(agentInformation);
sl@0
   106
	}
sl@0
   107
sl@0
   108
CStreamAgentInfo& CStreamAgentResolver::ResolveSdpKeyStreamL(const CSdpMediaField& aSdpKeyStream) const
sl@0
   109
	{
sl@0
   110
	TInt streamAgentInfoCount = iStreamAgentInfoArray.Count();
sl@0
   111
	
sl@0
   112
	/* Loop through each of the identified stream agents to determine which (if any) supports 
sl@0
   113
	 * the SDP key management description
sl@0
   114
	 */
sl@0
   115
	for(TInt i=0; i < streamAgentInfoCount; ++i)
sl@0
   116
		{
sl@0
   117
		if(iStreamAgentInfoArray[i]->IsKeyStreamSupportedL(aSdpKeyStream))
sl@0
   118
			{
sl@0
   119
			TUid agentUid(iStreamAgentInfoArray[i]->ImplementationUid());
sl@0
   120
			TPtrC agentName (iStreamAgentInfoArray[i]->Name());
sl@0
   121
			DEBUG_PRINTF3(_L("Key stream is supported by the agent: 0x%08x (%S)"),agentUid,&agentName);
sl@0
   122
			return *iStreamAgentInfoArray[i];
sl@0
   123
			}
sl@0
   124
		}
sl@0
   125
	
sl@0
   126
	// If a stream agent capable of decoding the key stream can not be found, leave with KErrCANoAgent
sl@0
   127
	DEBUG_PRINTF(_L("A stream agent capable of decoding the key stream can not be found!"));
sl@0
   128
	User::Leave(KErrCANoAgent);
sl@0
   129
	
sl@0
   130
	// Return NULL reference to avoid warnings (should never get here)
sl@0
   131
	CStreamAgentInfo* retVal=NULL;
sl@0
   132
	return *retVal;
sl@0
   133
	}