os/mm/devsound/sounddevbt/src/A2dpBlueTooth/headsetaudioif/A2dpCodecUtilities.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-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 "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
#ifndef __A2DPCODECUTILITIES_H__
sl@0
    17
#define __A2DPCODECUTILITIES_H__
sl@0
    18
sl@0
    19
sl@0
    20
#include <bluetoothav.h> //TAvdtpSEPInfo, TSEID
sl@0
    21
#include <mmf/server/sounddevice.h> //TMMFStereoSupport
sl@0
    22
#include "BtSBCFrameParameters.h"
sl@0
    23
sl@0
    24
//[TODO] change this to 44100 when we have hardware that supports higher data rates
sl@0
    25
const TUint KDefaultSampleRate = 32000;
sl@0
    26
const TUint KDefaultBitPoolValue = 20;
sl@0
    27
//[TODO] change this to EMMFStereo & EMMFInterleavedOnly when we have hardware that supports higher data rates
sl@0
    28
const TUint KDefaultChannels = EMMFMono;
sl@0
    29
const TMMFStereoSupport KDefaultStereoSupport = EMMFNone;
sl@0
    30
sl@0
    31
const TUint KMinBitPoolValue = 2;
sl@0
    32
const TUint KMaxBitPoolValue = 250;
sl@0
    33
sl@0
    34
//A2DP codec specific data masks
sl@0
    35
const TUint8 KA2dpMPEG12AudioChannelModeMask = 0x0F; //A2DP 4.4.2.3
sl@0
    36
const TUint8 KA2dpMPEG12LayerMask = 0xE0; //A2DP 4.4.2.1
sl@0
    37
const TUint8 KA2dpMPEG12LayerMP3Supported = 0x20; //A2DP 4.4.2.1
sl@0
    38
const TUint8 KA2dpMPEG12SamplingFrequencyMask = 0x3F; //A2DP 4.4.2.5
sl@0
    39
const TUint8 KA2dpMPEG12SupportedBitRateIndex = 0xFE; //A2DP 4.4.2.7 octet 3 all bit rates <=96kbs-1 except free
sl@0
    40
sl@0
    41
//RTP Codec profile specific constants
sl@0
    42
const TUint KMPEG12RTPTimeStampClock = 90000; //RFC2250 3.3
sl@0
    43
const TUint KSbcRTPPayloadType = 0; //A2DP 4.3.3.2 isn't too clear on this but 0 seems ok
sl@0
    44
const TUint KMPEG12RTPAudioPayloadType = 14; //MPA MPEG12 PT RFC3551 6
sl@0
    45
const TUint KSbcRTPMediaPayloadHeaderLength = 1;//A2DP 4.3.4
sl@0
    46
const TUint KMPEG12RTPMediaPayloadHeaderLength = 4;//MPF-1 RFC2250 3.5 
sl@0
    47
sl@0
    48
//Frame header masks
sl@0
    49
const TUint8 KSbcFrameHeaderSyncWord = 0x9C;
sl@0
    50
const TUint8 KSbcFrameHeaderSamplingFrequencyMask = 0xC0;
sl@0
    51
const TUint8 KSbcFrameHeaderBlocksMask = 0x30;
sl@0
    52
const TUint8 KSbcFrameHeaderChannelModeMask = 0x0C;
sl@0
    53
const TUint8 KSbcFrameHeaderSubbandsMask = 0x01;
sl@0
    54
const TUint8 KMPEGAudioFrameHeaderSyncWord = 0xFF;
sl@0
    55
const TUint8 KMp3AudioFrameHeaderIdMask = 0xFE;//mask out CRC
sl@0
    56
const TUint8 KMp3AudioFrameHeaderId = 0xFA;
sl@0
    57
const TUint8 KMp3FrameHeaderSamplingFrequencyMask = 0x0C;
sl@0
    58
const TUint8 KMp3FrameHeaderBitRateIndexMask = 0xF0;
sl@0
    59
sl@0
    60
using namespace SymbianSBC;
sl@0
    61
using namespace SymbianBluetoothAV;	
sl@0
    62
sl@0
    63
sl@0
    64
typedef TUint8	TMPEG12SamplingFrequencyBitmask;
sl@0
    65
	
sl@0
    66
/**
sl@0
    67
Mask for configuring mp3 sampling frequencies
sl@0
    68
*/
sl@0
    69
enum TMPEG12SamplingFrequency
sl@0
    70
	{
sl@0
    71
	EMPEG12_16kHz		= 0x20,
sl@0
    72
	EMPEG12_22050Hz		= 0x10,
sl@0
    73
	EMPEG12_24kHz		= 0x8,
sl@0
    74
	EMPEG12_32kHz		= 0x4,
sl@0
    75
	EMPEG12_44100Hz		= 0x2,
sl@0
    76
	EMPEG12_48kHz		= 0x1
sl@0
    77
	};
sl@0
    78
sl@0
    79
sl@0
    80
/**
sl@0
    81
mp3 bit rate index table
sl@0
    82
*/	
sl@0
    83
enum TMp3BitRateIndex
sl@0
    84
	{
sl@0
    85
	EMp3BitRateIndex32000	= 0x01,
sl@0
    86
	EMp3BitRateIndex40000	= 0x02,
sl@0
    87
	EMp3BitRateIndex48000	= 0x03,
sl@0
    88
	EMp3BitRateIndex56000	= 0x04,
sl@0
    89
	EMp3BitRateIndex64000	= 0x05,
sl@0
    90
	EMp3BitRateIndex80000	= 0x06,
sl@0
    91
	EMp3BitRateIndex96000	= 0x07,
sl@0
    92
	EMp3BitRateIndex112000	= 0x08,
sl@0
    93
	EMp3BitRateIndex128000	= 0x09,
sl@0
    94
	EMp3BitRateIndex160000	= 0x0A,
sl@0
    95
	EMp3BitRateIndex192000	= 0x0B,
sl@0
    96
	EMp3BitRateIndex224000	= 0x0C,
sl@0
    97
	EMp3BitRateIndex256000	= 0x0D,
sl@0
    98
	EMp3BitRateIndex320000	= 0x0E
sl@0
    99
	};
sl@0
   100
sl@0
   101
/**
sl@0
   102
Utility that parses the codec capabilities to get the supported sample rates and channels
sl@0
   103
sl@0
   104
@internalComponent
sl@0
   105
*/
sl@0
   106
class TA2dpCodecCapabilityParser
sl@0
   107
	{
sl@0
   108
public:
sl@0
   109
	static TInt GetSupportedSampleRates(const TAvdtpMediaCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedDiscreteRates);
sl@0
   110
	static TInt GetSupportedChannels(const TAvdtpMediaCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
sl@0
   111
private:
sl@0
   112
	static TInt GetSupportedSBCSampleRates(const TSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedDiscreteRates);
sl@0
   113
	static TInt GetSupportedMPEG12SampleRates(const TNonSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedDiscreteRates);
sl@0
   114
	static TInt GetSupportedSBCChannels(const TSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
sl@0
   115
	static TInt GetSupportedMPEG12Channels(const TNonSBCCodecCapabilities& aCodecCaps, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
sl@0
   116
	static TInt GetSupportedChannelsCommonCode(TSBCChannelModeBitmask aChannelModesBitMask, RArray<TUint>& aSupportedChannels, TMMFStereoSupport& aStereoSupport);
sl@0
   117
	};
sl@0
   118
sl@0
   119
sl@0
   120
/**
sl@0
   121
Utility to get codec specific RTP header parameters
sl@0
   122
sl@0
   123
@internalComponent
sl@0
   124
*/
sl@0
   125
class TRTPa2dpCodecSpecificUtils
sl@0
   126
	{
sl@0
   127
public:
sl@0
   128
	static TUint8 PayloadType(const TFourCC& aCodecDataType);
sl@0
   129
	static TUint MediaPayloadHeaderLength(const TFourCC& aCodecDataType);
sl@0
   130
	};
sl@0
   131
sl@0
   132
sl@0
   133
/**
sl@0
   134
Utility to calculate frame duration and time stamp increments
sl@0
   135
sl@0
   136
@internalComponent
sl@0
   137
*/	
sl@0
   138
class TFrameTimingUtils
sl@0
   139
	{
sl@0
   140
public:
sl@0
   141
	static TTimeIntervalMicroSeconds32 FrameDuration(TUint aFrameLength, TUint aBitRate);
sl@0
   142
	static TUint TimeStampIncrementPerFrame(const TFourCC& aCodecDataType, TUint aFrameLength, TUint aBitRate, TUint aSampleRate);
sl@0
   143
private:
sl@0
   144
	static TUint CalculateSBCTimeStampIncrementPerFrame(TUint aFrameLength, TUint aBitRate, TUint aSampleRate);
sl@0
   145
	static TUint CalculateMPEG12TimeStampIncrementPerFrame(TUint aFrameLength, TUint aBitRate);
sl@0
   146
	};
sl@0
   147
sl@0
   148
sl@0
   149
/**
sl@0
   150
Utility class to store the local SEP codec capabilities
sl@0
   151
sl@0
   152
@internalComponent
sl@0
   153
*/
sl@0
   154
NONSHARABLE_CLASS(CA2dpLocalCodecCapabilities) : public CBase
sl@0
   155
	{
sl@0
   156
public:
sl@0
   157
	static CA2dpLocalCodecCapabilities* NewL();
sl@0
   158
	~CA2dpLocalCodecCapabilities();
sl@0
   159
	TAvdtpMediaCodecCapabilities* LocalCodecCapabilities(const TFourCC& aCodecDataType);
sl@0
   160
private:
sl@0
   161
	CA2dpLocalCodecCapabilities();
sl@0
   162
	TSBCCodecCapabilities* LocalSBCCodecCapabilities();
sl@0
   163
	TNonSBCCodecCapabilities* LocalMPEG12CodecCapabilities();
sl@0
   164
private:
sl@0
   165
	TAvdtpMediaCodecCapabilities* iLocalCodecCapabilities; //this is owned
sl@0
   166
	};
sl@0
   167
sl@0
   168
	
sl@0
   169
/** 
sl@0
   170
Utiltiy class to store remote (ie headset) codec configuration 
sl@0
   171
and the local (ie symbian OS device) SBC codec configuration.
sl@0
   172
An instance of this class is owned by CA2dpBTHeadsetAudioInterface 
sl@0
   173
which sets the settings - the configuration is passed to the GAVDP state machine
sl@0
   174
which needs the configuration to configure the SEPs and RTPStreeamer uses
sl@0
   175
the configuration to calculate frame sizes and timings.
sl@0
   176
sl@0
   177
@internalComponent
sl@0
   178
*/
sl@0
   179
NONSHARABLE_CLASS(CA2dpAudioCodecConfiguration) : public CBase 
sl@0
   180
	{
sl@0
   181
public:
sl@0
   182
	static CA2dpAudioCodecConfiguration* NewL();
sl@0
   183
	~CA2dpAudioCodecConfiguration();
sl@0
   184
	void Reset();
sl@0
   185
	inline void SetHeadsetCodecDataType(const TFourCC& aHeadsetCodecDataType);
sl@0
   186
	inline void SetSampleRate(TUint aSampleRate);
sl@0
   187
	inline void SetChannels(TUint aChannels);
sl@0
   188
	inline void SetStereoSupport(TMMFStereoSupport aStereoSupport);
sl@0
   189
	inline const TFourCC& HeadsetCodecDataType() const;
sl@0
   190
	inline TUint SampleRate() const;
sl@0
   191
	inline TUint Channels() const;
sl@0
   192
	inline TMMFStereoSupport StereoSupport() const;
sl@0
   193
	TAvdtpMediaCodecCapabilities* UpdateRemoteCodecConfiguration(const TAvdtpMediaCodecCapabilities& aRemoteCodecCapabilities);
sl@0
   194
	TSBCFrameParameters& UpdateLocalSBCCodecConfiguration();
sl@0
   195
	inline TAvdtpMediaCodecCapabilities* RemoteCodecConfiguration() const;
sl@0
   196
	inline const TSBCFrameParameters& LocalSBCCodecConfiguration() const;
sl@0
   197
	TTimeIntervalMicroSeconds32 FrameDuration(TUint aFrameLength) const;
sl@0
   198
	TUint TimeStampIncrementPerFrame(TUint aFrameLength) const;
sl@0
   199
	TUint CalculateSBCBufferLength(TUint aPCM16BufferLength) const;
sl@0
   200
	void TEST_ForceRemoteSBCCodecConfiguration(const TSBCCodecCapabilities& aRemoteCodecConfiguration);
sl@0
   201
private:
sl@0
   202
	CA2dpAudioCodecConfiguration();
sl@0
   203
	TSBCCodecCapabilities* GetRemoteSBCCodecConfiguration(const TSBCCodecCapabilities& aCodecCaps);
sl@0
   204
	TNonSBCCodecCapabilities* GetRemoteMPEG12CodecConfiguration(const TNonSBCCodecCapabilities& aCodecCaps);
sl@0
   205
	TTimeIntervalMicroSeconds32 CalculateSBCFrameDuration() const;
sl@0
   206
	TTimeIntervalMicroSeconds32 CalculateMPEG12FrameDuration() const;
sl@0
   207
	TUint CalculateSBCTimeStampIncrementPerFrame() const;
sl@0
   208
	TUint CalculateMPEG12TimeStampIncrementPerFrame() const;
sl@0
   209
private:
sl@0
   210
	TFourCC iHeadsetCodecDataType;
sl@0
   211
	TUint	iSampleRate;
sl@0
   212
	TUint	iChannels;
sl@0
   213
	TMMFStereoSupport	iStereoSupport;
sl@0
   214
	TUint	iBitRate;
sl@0
   215
	TAvdtpMediaCodecCapabilities* iRemoteCodecConfiguration;
sl@0
   216
	TSBCFrameParameters iLocalSBCCodecConfiguration;
sl@0
   217
	TSBCCodecCapabilities* iForcedRemoteSBCCodecConfiguration;//just used for unit test purposes	
sl@0
   218
	};
sl@0
   219
sl@0
   220
sl@0
   221
/**
sl@0
   222
Utiltiy class to parse the header of non pcm16 data in order to obtain
sl@0
   223
the frame length and bit rate
sl@0
   224
sl@0
   225
@internalComponent
sl@0
   226
*/
sl@0
   227
NONSHARABLE_CLASS(CA2dpCodecFrameHeaderParser)
sl@0
   228
	{
sl@0
   229
public:
sl@0
   230
	static CA2dpCodecFrameHeaderParser* NewL(const TFourCC& aCodecDataType, const TDesC8& aHeader);
sl@0
   231
	~CA2dpCodecFrameHeaderParser();
sl@0
   232
	inline TUint FrameLength() const;
sl@0
   233
	inline TUint BitRate() const;
sl@0
   234
private:
sl@0
   235
	CA2dpCodecFrameHeaderParser();
sl@0
   236
	void ConstructL(const TFourCC& aCodecDataType, const TDesC8& aHeader);
sl@0
   237
	void ParseSBCHeaderL(const TDesC8& aHeader);
sl@0
   238
	void ParseMPEG12HeaderL(const TDesC8& aHeader);
sl@0
   239
private:
sl@0
   240
	TUint iFrameLength;
sl@0
   241
	TUint iSampleRate;
sl@0
   242
	TUint iBitRate;
sl@0
   243
	};
sl@0
   244
sl@0
   245
#include "A2dpCodecUtilities.inl"
sl@0
   246
		
sl@0
   247
#endif
sl@0
   248