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