bluetoothmgmt/bluetoothclientlib/avlib/avdtpMediaCodecCapability.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2003-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 "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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedPartner
       
    19 */
       
    20 
       
    21 #include <bluetooth/logger.h>
       
    22 #include <bluetoothav.h>
       
    23 #include "gavdpinterface.h"
       
    24 
       
    25 #ifdef __FLOG_ACTIVE
       
    26 _LIT8(KLogComponent, LOG_COMPONENT_AVLIB);
       
    27 #endif
       
    28 
       
    29 #ifdef _DEBUG
       
    30 PANICCATEGORY("medcodec");
       
    31 #endif
       
    32 
       
    33 TAvdtpMediaCodecCapabilities::TAvdtpMediaCodecCapabilities(
       
    34 					SymbianBluetoothAV::TBluetoothMediaType aMediaType,
       
    35 					TBluetoothMediaCodecType aCodecType,
       
    36 					TInt aLOSC)
       
    37 : TAvdtpServiceCapability(EServiceCategoryMediaCodec, aLOSC),
       
    38 iMediaType(aMediaType),
       
    39 iMediaCodecType(aCodecType)
       
    40 	{
       
    41 	}
       
    42 
       
    43 /**
       
    44 Parse AVDTP protocol-domain buffer representing media codec capabilities into this
       
    45 @param aPtr the buffer
       
    46 @internalTechnology
       
    47 */	
       
    48 EXPORT_C /*virtual*/ void TAvdtpMediaCodecCapabilities::Parse(const TDesC8& aPtr)
       
    49 	{
       
    50 	ASSERT_DEBUG(aPtr.Length()>=2);	// the parse broke if this is not true
       
    51 	iMediaType = static_cast<SymbianBluetoothAV::TBluetoothMediaType>(aPtr[0]>>4);
       
    52 	iMediaCodecType = static_cast<TBluetoothMediaCodecType>(aPtr[1]);
       
    53 	}
       
    54 
       
    55 /**
       
    56 Allocate a concrete codec capability from an AVDTP-protocol domain buffer
       
    57 */
       
    58 /*static*/ TAvdtpMediaCodecCapabilities* TAvdtpMediaCodecCapabilities::AllocCodecFromPDUL(const TDesC8& aBuf)
       
    59 	{
       
    60 	const TInt KMinMediaCodecLOSC = 2;
       
    61 	
       
    62 	if (aBuf.Length() < KMinMediaCodecLOSC)
       
    63 		{
       
    64 		User::Leave(KErrCorrupt);
       
    65 		}
       
    66 		
       
    67 	using namespace SymbianBluetoothAV;
       
    68 
       
    69 	TAvdtpMediaCodecCapabilities* res = NULL;
       
    70 	
       
    71 	static const TInt KMediaTypeOffset = 0;	
       
    72 	TBluetoothMediaType type = static_cast
       
    73 		<TBluetoothMediaType>(aBuf[KMediaTypeOffset]);
       
    74 		
       
    75 	static const TInt KMediaCodecTypeOffset = 1;	
       
    76 	TBluetoothMediaCodecType codec = static_cast
       
    77 		<TBluetoothMediaCodecType>(aBuf[KMediaCodecTypeOffset]);
       
    78 	
       
    79 	switch (codec)
       
    80 		{
       
    81 		// at present only support SBC
       
    82 		// more useful for SymbianOS as nearly always want to mix anyway
       
    83 		// which means decoding to PCM
       
    84 		// must then re-encode to something, and that might as well be SBC as mandatory
       
    85 		case EAudioCodecSBC:
       
    86 			{
       
    87 			res = new (ELeave) TSBCCodecCapabilities;
       
    88 			}
       
    89 			break;
       
    90 
       
    91 		// to allow other codecs just arrange for a descriptor - clients don't
       
    92 		// get the parsing done for free			
       
    93 		// later could use ECOM plugins to support other codecs
       
    94 		// other codecs can be added compile time in the style of the SBC codec
       
    95 		default:
       
    96 			{
       
    97 			res = new (ELeave) TNonSBCCodecCapabilities(type, codec);
       
    98 			}
       
    99 		}
       
   100 		
       
   101 	return res;
       
   102 	}
       
   103 
       
   104 /**
       
   105 Returns the media type
       
   106 @return media type
       
   107 @see SymbianBluetoothAV::TBluetoothMediaType
       
   108 */
       
   109 EXPORT_C SymbianBluetoothAV::TBluetoothMediaType TAvdtpMediaCodecCapabilities::MediaType() const
       
   110 	{
       
   111 	return iMediaType;	
       
   112 	}
       
   113 
       
   114 /**
       
   115 Returns the media codec type
       
   116 @return media codec type
       
   117 @see SymbianBluetoothAV::TBluetoothMediaType
       
   118 */
       
   119 EXPORT_C TBluetoothMediaCodecType TAvdtpMediaCodecCapabilities::MediaCodecType() const
       
   120 	{
       
   121 	return iMediaCodecType;
       
   122 	}
       
   123