diff -r 000000000000 -r 307788aac0a8 realtimenetprots/sipfw/ClientResolver/Resolver/src/CSdpRtpmapStrategy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/realtimenetprots/sipfw/ClientResolver/Resolver/src/CSdpRtpmapStrategy.cpp Tue Feb 02 01:03:15 2010 +0200 @@ -0,0 +1,240 @@ +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// Name : CSdpRtpmapStrategy.cpp +// Part of : SIP Client Resolver +// Version : 1.0 +// + + + +#include "CSdpRtpmapStrategy.h" +#include "sdpdocument.h" +#include "sdpmediafield.h" +#include "sdpcodecstringconstants.h" +#include "sdpcodecstringpool.h" + +const TUint KMinDynPayloadType = 96; + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::NewLC +// ---------------------------------------------------------------------------- +// +CSdpRtpmapStrategy* CSdpRtpmapStrategy::NewLC( + const MSipClients& aSipClients) + { + CSdpRtpmapStrategy* self = + new(ELeave)CSdpRtpmapStrategy(aSipClients); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::CSdpRtpmapStrategy +// ---------------------------------------------------------------------------- +// +CSdpRtpmapStrategy::CSdpRtpmapStrategy(const MSipClients& aSipClients) + : CSdpMLineStrategyBase(aSipClients) + { + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::ConstructL +// ---------------------------------------------------------------------------- +// +void CSdpRtpmapStrategy::ConstructL() + { + iApplicationStringF = + SdpCodecStringPool::StringPoolL().StringF( + SdpCodecStringConstants::EMediaApplication, + SdpCodecStringPool::StringTableL()); + + iRtpAvpStringF = + SdpCodecStringPool::StringPoolL().StringF( + SdpCodecStringConstants::EProtocolRtpAvp, + SdpCodecStringPool::StringTableL()); + + iRtpmapStringF = + SdpCodecStringPool::StringPoolL().StringF( + SdpCodecStringConstants::EAttributeRtpmap, + SdpCodecStringPool::StringTableL()); + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::~CSdpRtpmapStrategy +// ---------------------------------------------------------------------------- +// +CSdpRtpmapStrategy::~CSdpRtpmapStrategy () + { + iRtpmapStringF.Close(); + iRtpAvpStringF.Close(); + iApplicationStringF.Close(); + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::IsApplicable +// ---------------------------------------------------------------------------- +// +TBool CSdpRtpmapStrategy::IsApplicable(CSdpMediaField& aMediaField) + { + if (aMediaField.Media() != iApplicationStringF && + aMediaField.Protocol() == iRtpAvpStringF && + aMediaField.FormatAttributeFields().Count() > 0) + { + return ETrue; + } + return EFalse; + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::FieldsMatchL +// ---------------------------------------------------------------------------- +// +TBool CSdpRtpmapStrategy::FieldsMatchL( + const CSdpMediaField& aReceivedMedia, + const CSdpMediaField& aClientMedia) + { + if (aReceivedMedia.Media() == aClientMedia.Media() && + aReceivedMedia.Protocol() == iRtpAvpStringF && + aClientMedia.Protocol() == iRtpAvpStringF) + { + const RPointerArray& clientAttributes = + const_cast(aClientMedia).FormatAttributeFields(); + if (clientAttributes.Count() == 0) + { + // A client that does not announce any RTPMAPs + // is assumed to accept all possible mappings. + return ETrue; + } + + if (HasMatchingFormatsL(aReceivedMedia,aClientMedia)) + { + return ETrue; + } + + const RPointerArray& attributes = + const_cast(aReceivedMedia).FormatAttributeFields(); + for (TInt i=0; i < attributes.Count(); i++) + { + if (HasMatchingRtpmapAttritbute(aClientMedia,*attributes[i])) + { + return ETrue; + } + } + } + return EFalse; + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::HasMatchingRtpmapAttritbute +// ---------------------------------------------------------------------------- +// +TBool CSdpRtpmapStrategy::HasMatchingRtpmapAttritbute( + const CSdpMediaField& aMediaField, + const CSdpFmtAttributeField& aAttribute) + { + if (aAttribute.Attribute() != iRtpmapStringF) + { + return EFalse; + } + + const RPointerArray& attributes = + const_cast(aMediaField).FormatAttributeFields(); + + for (TInt i=0; i < attributes.Count(); i++) + { + CSdpFmtAttributeField& attribute = *attributes[i]; + if (attribute.Attribute() == iRtpmapStringF && + aAttribute.Value().CompareF(attribute.Value()) == 0) + { + return ETrue; + } + } + + return EFalse; + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::HasMatchingFormatsL +// ---------------------------------------------------------------------------- +// +TBool CSdpRtpmapStrategy::HasMatchingFormatsL( + const CSdpMediaField& aReceivedMedia, + const CSdpMediaField& aClientMedia) const + { + if (aReceivedMedia.Protocol() != iRtpAvpStringF || + aClientMedia.Protocol() != iRtpAvpStringF) + { + return EFalse; + } + + RArray formats(ExtractFormatsL(aReceivedMedia.FormatList())); + CleanupClosePushL(formats); + + const RPointerArray& clientAttributes = + const_cast(aClientMedia).FormatAttributeFields(); + + for (TInt i=0; i < clientAttributes.Count(); i++) + { + const CSdpFmtAttributeField& clientAttribute = *clientAttributes[i]; + if (clientAttribute.Attribute() == iRtpmapStringF) + { + TLex8 formatLex(clientAttribute.Format()); + TUint value = 0; + if (formatLex.Val(value) == KErrNone && + value < KMinDynPayloadType) + { + TInt index = 0; + TInt err = formats.FindInOrder(value,index); + if (err == KErrNone && index >= 0) + { + CleanupStack::PopAndDestroy(1); // formats + return ETrue; + } + } + } + } + + CleanupStack::PopAndDestroy(1); // formats + return EFalse; + } + +// ---------------------------------------------------------------------------- +// CSdpRtpmapStrategy::ExtractFormatsL +// ---------------------------------------------------------------------------- +// +RArray CSdpRtpmapStrategy::ExtractFormatsL( + const TDesC8& aFormats) const + { + RArray formats; + CleanupClosePushL(formats); + TLex8 formatLex(aFormats); + formatLex.SkipSpace(); + TUint value = 0; + while (!formatLex.Eos()) + { + if (formatLex.Val(value) == KErrNone) + { + formats.InsertInOrderAllowRepeatsL(value); + } + else + { + // Skip the invalid token + formatLex.NextToken(); + } + formatLex.SkipSpace(); + } + CleanupStack::Pop(&formats); + return formats; + }