os/mm/devsound/sounddevbt/src/A2dpBlueTooth/headsetaudioif/AudioBufferArray.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __AUDIOBUFFERARRAY_H__
    17 #define __AUDIOBUFFERARRAY_H__
    18 
    19 #include <e32base.h>
    20 #include <rtp.h>
    21 
    22 const TUint KMaxNumberOfSBCFramesPerRTPPacket = 15;
    23 
    24 class TSBCFrameParameters;
    25 class CA2dpAudioCodecConfiguration;
    26 /**
    27 This class contains an array of RRtpSendPackets that contain
    28 the audio to be sent to the headset over RTP
    29 Note that the RRtpSendPackets are only created once upfront
    30 it is assumed that these packets can be recycled
    31 Each audio buffer consists of one CRtpSendPackets class instance,
    32 however due to the underlying restrictions imposed by A2DP and 
    33 the BT L2CAP bearer MTU size limit- each CRtpSendPackets may
    34 consist of one or more RRtpSendPacket
    35 
    36 @internalComponent
    37 */
    38 NONSHARABLE_CLASS(CRtpSendPackets) : public CBase
    39 	{
    40 public:
    41 	static CRtpSendPackets* NewL(RRtpSendSource& aRtpSendSource, TUint aNumberOfPackets);
    42 	~CRtpSendPackets();
    43 	void ConstructL(RRtpSendSource& aRtpSendSource, TUint aNumberOfPackets);
    44 	inline RRtpSendPacket& Packet(TUint aPacketNumber);
    45 private:
    46 	void CloseAndResetSendPackets();
    47 private:
    48 	RArray<RRtpSendPacket> iRtpSendPackets;
    49 	};
    50 
    51 
    52 /**
    53 This function obtains the next free RTPsendPacket
    54 that is available to be filled with audio data
    55 
    56 @return RRtpSendPacket that is free and hence can be filled with audio
    57 */	
    58 inline RRtpSendPacket& CRtpSendPackets::Packet(TUint aPacketNumber)
    59 	{
    60 	return iRtpSendPackets[aPacketNumber];
    61 	}
    62 
    63 
    64 
    65 /**
    66 This class is used by CActiveRTPStreamer
    67 It is a FIFO used to provide a buffer array of audio buffers.
    68 Each audio buffer is contained in one CRtpSendPackets which 
    69 may itself be broken up into multiple RTP packets.
    70 The size and number of packets each audio buffer is broken down is
    71 calculated from the various input parameters provided to the NewL.
    72 This class makes the assumption than provided the audio parameters
    73 are unchanged, then the buffer length stays the same for each buffer sent,
    74 (except the last buffer)
    75 This assumption has been made, as by not assuming this, then the frame duration
    76 and number of frames calculations would need to be recalculated for every audio buffer
    77 and the RTPSendPackets would need to be created for every buffer.
    78 
    79 @internalComponent
    80 */	
    81 NONSHARABLE_CLASS(CAudioBufferArray) : public CBase
    82 	{
    83 public:
    84 	static CAudioBufferArray* NewL(RRtpSendSource& aRtpSendSource,
    85 							TUint aNumberOfAudioBuffers,
    86 							TUint aAudioBufferSize,
    87 							TUint aMTULength,
    88 							TUint aTotalRTPHeaderLength,
    89 							TUint aFrameLength);
    90 	~CAudioBufferArray();
    91 	void CurrentAudioBufferReadyToSend();
    92 	void CancelMostRecentAudioBuffer(TBool aSendInProgress);
    93 	void FlushPendingPackets();
    94 	RRtpSendPacket& CurrentSendPacket();
    95 	void CurrentSendPacketSent(TBool& aEntireAudioBufferSent);
    96 	inline CRtpSendPackets* CurrentAudioBufferRtpSendPackets() const;
    97 	inline TUint NumberOfAudioBuffersReadyToSend() const;
    98 	inline TUint MaxNumberOfAudioBuffers() const;
    99 	inline TUint InputBytesPerRTPPacket() const;
   100 	inline TUint NumberOfRtpPacketsPerAudioBuffer() const;
   101 	inline TUint NumberOfFramesPerRtpPacket() const;
   102 private:
   103 	void ConstructL(RRtpSendSource& aRtpSendSource, 
   104 				TUint aNumberOfAudioBuffers,
   105 				TUint aAudioBufferSize,
   106 				TUint aMTULength,
   107 				TUint aTotalRTPHeaderLength,
   108 				TUint aFrameLength);
   109 private:
   110 	RPointerArray<CRtpSendPackets> iAudioBufferArray;
   111 	TUint	iAudioBufferBeingSent;
   112 	TUint	iNextRtpPacketToSend;
   113 	TUint	iNextAudioBufferToFill;
   114 	TUint	iNumberOfReadyAudioBuffers; 
   115 	TUint	iNumberOfRtpPacketsPerAudioBuffer;
   116 	TUint	iInputBytesPerRtpPacket;
   117 	TUint	iFrameLength;
   118 	TUint	iNumberOfFramesPerRtpPacket;
   119 	};
   120 
   121 
   122 /**
   123 This function obtains the current free audio buffer
   124 in the form of a CRTPsendPackets
   125 The  CRTPsendPackets returned are available to be filled with audio data
   126 
   127 @return CRtpSendPackets array that is free and hence can be filled with audio
   128 */	
   129 inline CRtpSendPackets* CAudioBufferArray::CurrentAudioBufferRtpSendPackets() const
   130 	{
   131 	return iAudioBufferArray[iNextAudioBufferToFill];
   132 	}
   133 	
   134 	
   135 /**
   136 This function returns the total number of audio buffers in the
   137 audio buffer array that have been filled with audio and hence are
   138 ready to be sent to the headset.
   139 
   140 @return number of audio buffers ready to send
   141 */	
   142 inline TUint CAudioBufferArray::NumberOfAudioBuffersReadyToSend() const
   143 	{
   144 	return iNumberOfReadyAudioBuffers;
   145 	}
   146 	
   147 
   148 /**
   149 This function returns the maximum number of audio buffers that 
   150 can be stored in the audio buffer array.
   151 It is set by the aNumberOfAudioBuffers parameter in the constructor
   152 
   153 @return max number of audio buffers that can be stored in the audio 
   154 buffer array
   155 */	
   156 inline TUint CAudioBufferArray::MaxNumberOfAudioBuffers() const
   157 	{
   158 	return iAudioBufferArray.Count();
   159 	}
   160 	
   161 
   162 /**
   163 This function returns the number of input bytes 
   164 ie bytes prior to any codec processing that will
   165 (after possible codec processing) constitute an RTP packet
   166 
   167 @return input bytes per RTP packet
   168 */
   169 inline TUint CAudioBufferArray::InputBytesPerRTPPacket() const
   170 	{
   171 	return iInputBytesPerRtpPacket;
   172 	}
   173 	
   174 
   175 /**
   176 This function returns the number of RTP packets that make up an audio buffer
   177 
   178 @return number of RTP packets
   179 */	
   180 inline TUint CAudioBufferArray::NumberOfRtpPacketsPerAudioBuffer() const
   181 	{
   182 	return iNumberOfRtpPacketsPerAudioBuffer;
   183 	}
   184 
   185 
   186 /**
   187 This function returns the number of audio frames in a single RTP packet
   188 ie the total number of audio frames in a single audio buffer is given by:
   189 NumberOfFramesPerRtpPacket()*NumberOfRtpPacketsPerAudioBuffer()
   190 
   191 @return number of audio frames in a single RTP packet
   192 */	
   193 inline TUint CAudioBufferArray::NumberOfFramesPerRtpPacket() const 
   194 	{
   195 	return iNumberOfFramesPerRtpPacket;
   196 	};
   197 	
   198 #endif
   199