sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __AUDIOBUFFERARRAY_H__ sl@0: #define __AUDIOBUFFERARRAY_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: const TUint KMaxNumberOfSBCFramesPerRTPPacket = 15; sl@0: sl@0: class TSBCFrameParameters; sl@0: class CA2dpAudioCodecConfiguration; sl@0: /** sl@0: This class contains an array of RRtpSendPackets that contain sl@0: the audio to be sent to the headset over RTP sl@0: Note that the RRtpSendPackets are only created once upfront sl@0: it is assumed that these packets can be recycled sl@0: Each audio buffer consists of one CRtpSendPackets class instance, sl@0: however due to the underlying restrictions imposed by A2DP and sl@0: the BT L2CAP bearer MTU size limit- each CRtpSendPackets may sl@0: consist of one or more RRtpSendPacket sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(CRtpSendPackets) : public CBase sl@0: { sl@0: public: sl@0: static CRtpSendPackets* NewL(RRtpSendSource& aRtpSendSource, TUint aNumberOfPackets); sl@0: ~CRtpSendPackets(); sl@0: void ConstructL(RRtpSendSource& aRtpSendSource, TUint aNumberOfPackets); sl@0: inline RRtpSendPacket& Packet(TUint aPacketNumber); sl@0: private: sl@0: void CloseAndResetSendPackets(); sl@0: private: sl@0: RArray iRtpSendPackets; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This function obtains the next free RTPsendPacket sl@0: that is available to be filled with audio data sl@0: sl@0: @return RRtpSendPacket that is free and hence can be filled with audio sl@0: */ sl@0: inline RRtpSendPacket& CRtpSendPackets::Packet(TUint aPacketNumber) sl@0: { sl@0: return iRtpSendPackets[aPacketNumber]; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: This class is used by CActiveRTPStreamer sl@0: It is a FIFO used to provide a buffer array of audio buffers. sl@0: Each audio buffer is contained in one CRtpSendPackets which sl@0: may itself be broken up into multiple RTP packets. sl@0: The size and number of packets each audio buffer is broken down is sl@0: calculated from the various input parameters provided to the NewL. sl@0: This class makes the assumption than provided the audio parameters sl@0: are unchanged, then the buffer length stays the same for each buffer sent, sl@0: (except the last buffer) sl@0: This assumption has been made, as by not assuming this, then the frame duration sl@0: and number of frames calculations would need to be recalculated for every audio buffer sl@0: and the RTPSendPackets would need to be created for every buffer. sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(CAudioBufferArray) : public CBase sl@0: { sl@0: public: sl@0: static CAudioBufferArray* NewL(RRtpSendSource& aRtpSendSource, sl@0: TUint aNumberOfAudioBuffers, sl@0: TUint aAudioBufferSize, sl@0: TUint aMTULength, sl@0: TUint aTotalRTPHeaderLength, sl@0: TUint aFrameLength); sl@0: ~CAudioBufferArray(); sl@0: void CurrentAudioBufferReadyToSend(); sl@0: void CancelMostRecentAudioBuffer(TBool aSendInProgress); sl@0: void FlushPendingPackets(); sl@0: RRtpSendPacket& CurrentSendPacket(); sl@0: void CurrentSendPacketSent(TBool& aEntireAudioBufferSent); sl@0: inline CRtpSendPackets* CurrentAudioBufferRtpSendPackets() const; sl@0: inline TUint NumberOfAudioBuffersReadyToSend() const; sl@0: inline TUint MaxNumberOfAudioBuffers() const; sl@0: inline TUint InputBytesPerRTPPacket() const; sl@0: inline TUint NumberOfRtpPacketsPerAudioBuffer() const; sl@0: inline TUint NumberOfFramesPerRtpPacket() const; sl@0: private: sl@0: void ConstructL(RRtpSendSource& aRtpSendSource, sl@0: TUint aNumberOfAudioBuffers, sl@0: TUint aAudioBufferSize, sl@0: TUint aMTULength, sl@0: TUint aTotalRTPHeaderLength, sl@0: TUint aFrameLength); sl@0: private: sl@0: RPointerArray iAudioBufferArray; sl@0: TUint iAudioBufferBeingSent; sl@0: TUint iNextRtpPacketToSend; sl@0: TUint iNextAudioBufferToFill; sl@0: TUint iNumberOfReadyAudioBuffers; sl@0: TUint iNumberOfRtpPacketsPerAudioBuffer; sl@0: TUint iInputBytesPerRtpPacket; sl@0: TUint iFrameLength; sl@0: TUint iNumberOfFramesPerRtpPacket; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This function obtains the current free audio buffer sl@0: in the form of a CRTPsendPackets sl@0: The CRTPsendPackets returned are available to be filled with audio data sl@0: sl@0: @return CRtpSendPackets array that is free and hence can be filled with audio sl@0: */ sl@0: inline CRtpSendPackets* CAudioBufferArray::CurrentAudioBufferRtpSendPackets() const sl@0: { sl@0: return iAudioBufferArray[iNextAudioBufferToFill]; sl@0: } sl@0: sl@0: sl@0: /** sl@0: This function returns the total number of audio buffers in the sl@0: audio buffer array that have been filled with audio and hence are sl@0: ready to be sent to the headset. sl@0: sl@0: @return number of audio buffers ready to send sl@0: */ sl@0: inline TUint CAudioBufferArray::NumberOfAudioBuffersReadyToSend() const sl@0: { sl@0: return iNumberOfReadyAudioBuffers; sl@0: } sl@0: sl@0: sl@0: /** sl@0: This function returns the maximum number of audio buffers that sl@0: can be stored in the audio buffer array. sl@0: It is set by the aNumberOfAudioBuffers parameter in the constructor sl@0: sl@0: @return max number of audio buffers that can be stored in the audio sl@0: buffer array sl@0: */ sl@0: inline TUint CAudioBufferArray::MaxNumberOfAudioBuffers() const sl@0: { sl@0: return iAudioBufferArray.Count(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: This function returns the number of input bytes sl@0: ie bytes prior to any codec processing that will sl@0: (after possible codec processing) constitute an RTP packet sl@0: sl@0: @return input bytes per RTP packet sl@0: */ sl@0: inline TUint CAudioBufferArray::InputBytesPerRTPPacket() const sl@0: { sl@0: return iInputBytesPerRtpPacket; sl@0: } sl@0: sl@0: sl@0: /** sl@0: This function returns the number of RTP packets that make up an audio buffer sl@0: sl@0: @return number of RTP packets sl@0: */ sl@0: inline TUint CAudioBufferArray::NumberOfRtpPacketsPerAudioBuffer() const sl@0: { sl@0: return iNumberOfRtpPacketsPerAudioBuffer; sl@0: } sl@0: sl@0: sl@0: /** sl@0: This function returns the number of audio frames in a single RTP packet sl@0: ie the total number of audio frames in a single audio buffer is given by: sl@0: NumberOfFramesPerRtpPacket()*NumberOfRtpPacketsPerAudioBuffer() sl@0: sl@0: @return number of audio frames in a single RTP packet sl@0: */ sl@0: inline TUint CAudioBufferArray::NumberOfFramesPerRtpPacket() const sl@0: { sl@0: return iNumberOfFramesPerRtpPacket; sl@0: }; sl@0: sl@0: #endif sl@0: