os/mm/devsound/sounddevbt/src/A2dpBlueTooth/headsetaudioif/AudioBufferArray.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/sounddevbt/src/A2dpBlueTooth/headsetaudioif/AudioBufferArray.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,199 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __AUDIOBUFFERARRAY_H__
    1.20 +#define __AUDIOBUFFERARRAY_H__
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include <rtp.h>
    1.24 +
    1.25 +const TUint KMaxNumberOfSBCFramesPerRTPPacket = 15;
    1.26 +
    1.27 +class TSBCFrameParameters;
    1.28 +class CA2dpAudioCodecConfiguration;
    1.29 +/**
    1.30 +This class contains an array of RRtpSendPackets that contain
    1.31 +the audio to be sent to the headset over RTP
    1.32 +Note that the RRtpSendPackets are only created once upfront
    1.33 +it is assumed that these packets can be recycled
    1.34 +Each audio buffer consists of one CRtpSendPackets class instance,
    1.35 +however due to the underlying restrictions imposed by A2DP and 
    1.36 +the BT L2CAP bearer MTU size limit- each CRtpSendPackets may
    1.37 +consist of one or more RRtpSendPacket
    1.38 +
    1.39 +@internalComponent
    1.40 +*/
    1.41 +NONSHARABLE_CLASS(CRtpSendPackets) : public CBase
    1.42 +	{
    1.43 +public:
    1.44 +	static CRtpSendPackets* NewL(RRtpSendSource& aRtpSendSource, TUint aNumberOfPackets);
    1.45 +	~CRtpSendPackets();
    1.46 +	void ConstructL(RRtpSendSource& aRtpSendSource, TUint aNumberOfPackets);
    1.47 +	inline RRtpSendPacket& Packet(TUint aPacketNumber);
    1.48 +private:
    1.49 +	void CloseAndResetSendPackets();
    1.50 +private:
    1.51 +	RArray<RRtpSendPacket> iRtpSendPackets;
    1.52 +	};
    1.53 +
    1.54 +
    1.55 +/**
    1.56 +This function obtains the next free RTPsendPacket
    1.57 +that is available to be filled with audio data
    1.58 +
    1.59 +@return RRtpSendPacket that is free and hence can be filled with audio
    1.60 +*/	
    1.61 +inline RRtpSendPacket& CRtpSendPackets::Packet(TUint aPacketNumber)
    1.62 +	{
    1.63 +	return iRtpSendPackets[aPacketNumber];
    1.64 +	}
    1.65 +
    1.66 +
    1.67 +
    1.68 +/**
    1.69 +This class is used by CActiveRTPStreamer
    1.70 +It is a FIFO used to provide a buffer array of audio buffers.
    1.71 +Each audio buffer is contained in one CRtpSendPackets which 
    1.72 +may itself be broken up into multiple RTP packets.
    1.73 +The size and number of packets each audio buffer is broken down is
    1.74 +calculated from the various input parameters provided to the NewL.
    1.75 +This class makes the assumption than provided the audio parameters
    1.76 +are unchanged, then the buffer length stays the same for each buffer sent,
    1.77 +(except the last buffer)
    1.78 +This assumption has been made, as by not assuming this, then the frame duration
    1.79 +and number of frames calculations would need to be recalculated for every audio buffer
    1.80 +and the RTPSendPackets would need to be created for every buffer.
    1.81 +
    1.82 +@internalComponent
    1.83 +*/	
    1.84 +NONSHARABLE_CLASS(CAudioBufferArray) : public CBase
    1.85 +	{
    1.86 +public:
    1.87 +	static CAudioBufferArray* NewL(RRtpSendSource& aRtpSendSource,
    1.88 +							TUint aNumberOfAudioBuffers,
    1.89 +							TUint aAudioBufferSize,
    1.90 +							TUint aMTULength,
    1.91 +							TUint aTotalRTPHeaderLength,
    1.92 +							TUint aFrameLength);
    1.93 +	~CAudioBufferArray();
    1.94 +	void CurrentAudioBufferReadyToSend();
    1.95 +	void CancelMostRecentAudioBuffer(TBool aSendInProgress);
    1.96 +	void FlushPendingPackets();
    1.97 +	RRtpSendPacket& CurrentSendPacket();
    1.98 +	void CurrentSendPacketSent(TBool& aEntireAudioBufferSent);
    1.99 +	inline CRtpSendPackets* CurrentAudioBufferRtpSendPackets() const;
   1.100 +	inline TUint NumberOfAudioBuffersReadyToSend() const;
   1.101 +	inline TUint MaxNumberOfAudioBuffers() const;
   1.102 +	inline TUint InputBytesPerRTPPacket() const;
   1.103 +	inline TUint NumberOfRtpPacketsPerAudioBuffer() const;
   1.104 +	inline TUint NumberOfFramesPerRtpPacket() const;
   1.105 +private:
   1.106 +	void ConstructL(RRtpSendSource& aRtpSendSource, 
   1.107 +				TUint aNumberOfAudioBuffers,
   1.108 +				TUint aAudioBufferSize,
   1.109 +				TUint aMTULength,
   1.110 +				TUint aTotalRTPHeaderLength,
   1.111 +				TUint aFrameLength);
   1.112 +private:
   1.113 +	RPointerArray<CRtpSendPackets> iAudioBufferArray;
   1.114 +	TUint	iAudioBufferBeingSent;
   1.115 +	TUint	iNextRtpPacketToSend;
   1.116 +	TUint	iNextAudioBufferToFill;
   1.117 +	TUint	iNumberOfReadyAudioBuffers; 
   1.118 +	TUint	iNumberOfRtpPacketsPerAudioBuffer;
   1.119 +	TUint	iInputBytesPerRtpPacket;
   1.120 +	TUint	iFrameLength;
   1.121 +	TUint	iNumberOfFramesPerRtpPacket;
   1.122 +	};
   1.123 +
   1.124 +
   1.125 +/**
   1.126 +This function obtains the current free audio buffer
   1.127 +in the form of a CRTPsendPackets
   1.128 +The  CRTPsendPackets returned are available to be filled with audio data
   1.129 +
   1.130 +@return CRtpSendPackets array that is free and hence can be filled with audio
   1.131 +*/	
   1.132 +inline CRtpSendPackets* CAudioBufferArray::CurrentAudioBufferRtpSendPackets() const
   1.133 +	{
   1.134 +	return iAudioBufferArray[iNextAudioBufferToFill];
   1.135 +	}
   1.136 +	
   1.137 +	
   1.138 +/**
   1.139 +This function returns the total number of audio buffers in the
   1.140 +audio buffer array that have been filled with audio and hence are
   1.141 +ready to be sent to the headset.
   1.142 +
   1.143 +@return number of audio buffers ready to send
   1.144 +*/	
   1.145 +inline TUint CAudioBufferArray::NumberOfAudioBuffersReadyToSend() const
   1.146 +	{
   1.147 +	return iNumberOfReadyAudioBuffers;
   1.148 +	}
   1.149 +	
   1.150 +
   1.151 +/**
   1.152 +This function returns the maximum number of audio buffers that 
   1.153 +can be stored in the audio buffer array.
   1.154 +It is set by the aNumberOfAudioBuffers parameter in the constructor
   1.155 +
   1.156 +@return max number of audio buffers that can be stored in the audio 
   1.157 +buffer array
   1.158 +*/	
   1.159 +inline TUint CAudioBufferArray::MaxNumberOfAudioBuffers() const
   1.160 +	{
   1.161 +	return iAudioBufferArray.Count();
   1.162 +	}
   1.163 +	
   1.164 +
   1.165 +/**
   1.166 +This function returns the number of input bytes 
   1.167 +ie bytes prior to any codec processing that will
   1.168 +(after possible codec processing) constitute an RTP packet
   1.169 +
   1.170 +@return input bytes per RTP packet
   1.171 +*/
   1.172 +inline TUint CAudioBufferArray::InputBytesPerRTPPacket() const
   1.173 +	{
   1.174 +	return iInputBytesPerRtpPacket;
   1.175 +	}
   1.176 +	
   1.177 +
   1.178 +/**
   1.179 +This function returns the number of RTP packets that make up an audio buffer
   1.180 +
   1.181 +@return number of RTP packets
   1.182 +*/	
   1.183 +inline TUint CAudioBufferArray::NumberOfRtpPacketsPerAudioBuffer() const
   1.184 +	{
   1.185 +	return iNumberOfRtpPacketsPerAudioBuffer;
   1.186 +	}
   1.187 +
   1.188 +
   1.189 +/**
   1.190 +This function returns the number of audio frames in a single RTP packet
   1.191 +ie the total number of audio frames in a single audio buffer is given by:
   1.192 +NumberOfFramesPerRtpPacket()*NumberOfRtpPacketsPerAudioBuffer()
   1.193 +
   1.194 +@return number of audio frames in a single RTP packet
   1.195 +*/	
   1.196 +inline TUint CAudioBufferArray::NumberOfFramesPerRtpPacket() const 
   1.197 +	{
   1.198 +	return iNumberOfFramesPerRtpPacket;
   1.199 +	};
   1.200 +	
   1.201 +#endif
   1.202 +