Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __A2DPCODECUTILITIES_H__
17 #define __A2DPCODECUTILITIES_H__
20 #include <bluetoothav.h> //TAvdtpSEPInfo, TSEID
21 #include <mmf/server/sounddevice.h> //TMMFStereoSupport
22 #include "BtSBCFrameParameters.h"
24 //[TODO] change this to 44100 when we have hardware that supports higher data rates
25 const TUint KDefaultSampleRate = 32000;
26 const TUint KDefaultBitPoolValue = 20;
27 //[TODO] change this to EMMFStereo & EMMFInterleavedOnly when we have hardware that supports higher data rates
28 const TUint KDefaultChannels = EMMFMono;
29 const TMMFStereoSupport KDefaultStereoSupport = EMMFNone;
31 const TUint KMinBitPoolValue = 2;
32 const TUint KMaxBitPoolValue = 250;
34 //A2DP codec specific data masks
35 const TUint8 KA2dpMPEG12AudioChannelModeMask = 0x0F; //A2DP 4.4.2.3
36 const TUint8 KA2dpMPEG12LayerMask = 0xE0; //A2DP 4.4.2.1
37 const TUint8 KA2dpMPEG12LayerMP3Supported = 0x20; //A2DP 4.4.2.1
38 const TUint8 KA2dpMPEG12SamplingFrequencyMask = 0x3F; //A2DP 4.4.2.5
39 const TUint8 KA2dpMPEG12SupportedBitRateIndex = 0xFE; //A2DP 4.4.2.7 octet 3 all bit rates <=96kbs-1 except free
41 //RTP Codec profile specific constants
42 const TUint KMPEG12RTPTimeStampClock = 90000; //RFC2250 3.3
43 const TUint KSbcRTPPayloadType = 0; //A2DP 4.3.3.2 isn't too clear on this but 0 seems ok
44 const TUint KMPEG12RTPAudioPayloadType = 14; //MPA MPEG12 PT RFC3551 6
45 const TUint KSbcRTPMediaPayloadHeaderLength = 1;//A2DP 4.3.4
46 const TUint KMPEG12RTPMediaPayloadHeaderLength = 4;//MPF-1 RFC2250 3.5
49 const TUint8 KSbcFrameHeaderSyncWord = 0x9C;
50 const TUint8 KSbcFrameHeaderSamplingFrequencyMask = 0xC0;
51 const TUint8 KSbcFrameHeaderBlocksMask = 0x30;
52 const TUint8 KSbcFrameHeaderChannelModeMask = 0x0C;
53 const TUint8 KSbcFrameHeaderSubbandsMask = 0x01;
54 const TUint8 KMPEGAudioFrameHeaderSyncWord = 0xFF;
55 const TUint8 KMp3AudioFrameHeaderIdMask = 0xFE;//mask out CRC
56 const TUint8 KMp3AudioFrameHeaderId = 0xFA;
57 const TUint8 KMp3FrameHeaderSamplingFrequencyMask = 0x0C;
58 const TUint8 KMp3FrameHeaderBitRateIndexMask = 0xF0;
60 using namespace SymbianSBC;
61 using namespace SymbianBluetoothAV;
64 typedef TUint8 TMPEG12SamplingFrequencyBitmask;
67 Mask for configuring mp3 sampling frequencies
69 enum TMPEG12SamplingFrequency
72 EMPEG12_22050Hz = 0x10,
75 EMPEG12_44100Hz = 0x2,
81 mp3 bit rate index table
85 EMp3BitRateIndex32000 = 0x01,
86 EMp3BitRateIndex40000 = 0x02,
87 EMp3BitRateIndex48000 = 0x03,
88 EMp3BitRateIndex56000 = 0x04,
89 EMp3BitRateIndex64000 = 0x05,
90 EMp3BitRateIndex80000 = 0x06,
91 EMp3BitRateIndex96000 = 0x07,
92 EMp3BitRateIndex112000 = 0x08,
93 EMp3BitRateIndex128000 = 0x09,
94 EMp3BitRateIndex160000 = 0x0A,
95 EMp3BitRateIndex192000 = 0x0B,
96 EMp3BitRateIndex224000 = 0x0C,
97 EMp3BitRateIndex256000 = 0x0D,
98 EMp3BitRateIndex320000 = 0x0E
102 Utility that parses the codec capabilities to get the supported sample rates and channels
106 class TA2dpCodecCapabilityParser
109 static TInt GetSupportedSampleRates(const TAvdtpMediaCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedDiscreteRates);
110 static TInt GetSupportedChannels(const TAvdtpMediaCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
112 static TInt GetSupportedSBCSampleRates(const TSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedDiscreteRates);
113 static TInt GetSupportedMPEG12SampleRates(const TNonSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedDiscreteRates);
114 static TInt GetSupportedSBCChannels(const TSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
115 static TInt GetSupportedMPEG12Channels(const TNonSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
116 static TInt GetSupportedChannelsCommonCode(TSBCChannelModeBitmask aChannelModesBitMask, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
121 Utility to get codec specific RTP header parameters
125 class TRTPa2dpCodecSpecificUtils
128 static TUint8 PayloadType(const TFourCC& aCodecDataType);
129 static TUint MediaPayloadHeaderLength(const TFourCC& aCodecDataType);
134 Utility to calculate frame duration and time stamp increments
138 class TFrameTimingUtils
141 static TTimeIntervalMicroSeconds32 FrameDuration(TUint aFrameLength, TUint aBitRate);
142 static TUint TimeStampIncrementPerFrame(const TFourCC& aCodecDataType, TUint aFrameLength, TUint aBitRate, TUint aSampleRate);
144 static TUint CalculateSBCTimeStampIncrementPerFrame(TUint aFrameLength, TUint aBitRate, TUint aSampleRate);
145 static TUint CalculateMPEG12TimeStampIncrementPerFrame(TUint aFrameLength, TUint aBitRate);
150 Utility class to store the local SEP codec capabilities
154 NONSHARABLE_CLASS(CA2dpLocalCodecCapabilities) : public CBase
157 static CA2dpLocalCodecCapabilities* NewL();
158 ~CA2dpLocalCodecCapabilities();
159 TAvdtpMediaCodecCapabilities* LocalCodecCapabilities(const TFourCC& aCodecDataType);
161 CA2dpLocalCodecCapabilities();
162 TSBCCodecCapabilities* LocalSBCCodecCapabilities();
163 TNonSBCCodecCapabilities* LocalMPEG12CodecCapabilities();
165 TAvdtpMediaCodecCapabilities* iLocalCodecCapabilities; //this is owned
170 Utiltiy class to store remote (ie headset) codec configuration
171 and the local (ie symbian OS device) SBC codec configuration.
172 An instance of this class is owned by CA2dpBTHeadsetAudioInterface
173 which sets the settings - the configuration is passed to the GAVDP state machine
174 which needs the configuration to configure the SEPs and RTPStreeamer uses
175 the configuration to calculate frame sizes and timings.
179 NONSHARABLE_CLASS(CA2dpAudioCodecConfiguration) : public CBase
182 static CA2dpAudioCodecConfiguration* NewL();
183 ~CA2dpAudioCodecConfiguration();
185 inline void SetHeadsetCodecDataType(const TFourCC& aHeadsetCodecDataType);
186 inline void SetSampleRate(TUint aSampleRate);
187 inline void SetChannels(TUint aChannels);
188 inline void SetStereoSupport(TMMFStereoSupport aStereoSupport);
189 inline const TFourCC& HeadsetCodecDataType() const;
190 inline TUint SampleRate() const;
191 inline TUint Channels() const;
192 inline TMMFStereoSupport StereoSupport() const;
193 TAvdtpMediaCodecCapabilities* UpdateRemoteCodecConfiguration(const TAvdtpMediaCodecCapabilities& aRemoteCodecCapabilities);
194 TSBCFrameParameters& UpdateLocalSBCCodecConfiguration();
195 inline TAvdtpMediaCodecCapabilities* RemoteCodecConfiguration() const;
196 inline const TSBCFrameParameters& LocalSBCCodecConfiguration() const;
197 TTimeIntervalMicroSeconds32 FrameDuration(TUint aFrameLength) const;
198 TUint TimeStampIncrementPerFrame(TUint aFrameLength) const;
199 TUint CalculateSBCBufferLength(TUint aPCM16BufferLength) const;
200 void TEST_ForceRemoteSBCCodecConfiguration(const TSBCCodecCapabilities& aRemoteCodecConfiguration);
202 CA2dpAudioCodecConfiguration();
203 TSBCCodecCapabilities* GetRemoteSBCCodecConfiguration(const TSBCCodecCapabilities& aCodecCaps);
204 TNonSBCCodecCapabilities* GetRemoteMPEG12CodecConfiguration(const TNonSBCCodecCapabilities& aCodecCaps);
205 TTimeIntervalMicroSeconds32 CalculateSBCFrameDuration() const;
206 TTimeIntervalMicroSeconds32 CalculateMPEG12FrameDuration() const;
207 TUint CalculateSBCTimeStampIncrementPerFrame() const;
208 TUint CalculateMPEG12TimeStampIncrementPerFrame() const;
210 TFourCC iHeadsetCodecDataType;
213 TMMFStereoSupport iStereoSupport;
215 TAvdtpMediaCodecCapabilities* iRemoteCodecConfiguration;
216 TSBCFrameParameters iLocalSBCCodecConfiguration;
217 TSBCCodecCapabilities* iForcedRemoteSBCCodecConfiguration;//just used for unit test purposes
222 Utiltiy class to parse the header of non pcm16 data in order to obtain
223 the frame length and bit rate
227 NONSHARABLE_CLASS(CA2dpCodecFrameHeaderParser)
230 static CA2dpCodecFrameHeaderParser* NewL(const TFourCC& aCodecDataType, const TDesC8& aHeader);
231 ~CA2dpCodecFrameHeaderParser();
232 inline TUint FrameLength() const;
233 inline TUint BitRate() const;
235 CA2dpCodecFrameHeaderParser();
236 void ConstructL(const TFourCC& aCodecDataType, const TDesC8& aHeader);
237 void ParseSBCHeaderL(const TDesC8& aHeader);
238 void ParseMPEG12HeaderL(const TDesC8& aHeader);
245 #include "A2dpCodecUtilities.inl"