1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Ring buffer for storing packets from source.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 #ifndef _CCRPACKETBUFFER_H |
|
21 #define _CCRPACKETBUFFER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "MCRPacketSource.h" |
|
25 #include "CCRPacketSinkBase.h" |
|
26 #include <e32base.h> |
|
27 #include <e32cmn.h> |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KStreamTypeBytePoint( 0 ); |
|
31 const TInt KStreamTypeBytesLength( 1 ); |
|
32 |
|
33 // MACROS |
|
34 // None |
|
35 |
|
36 // DATA TYPES |
|
37 // None |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class CCRPacketSinkBase; |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 /** |
|
45 * Ring buffer where to store RTP packets. |
|
46 * |
|
47 * @lib CommonRecordingEngine.lib |
|
48 * @since Series 60 3.0 |
|
49 */ |
|
50 class CCRPacketBuffer : public CBase |
|
51 { |
|
52 |
|
53 public: // Constructors and destructors |
|
54 |
|
55 /** |
|
56 * Allocation method for buffer. |
|
57 * @param aMaxPackets a maximum packets count in buffer. |
|
58 * @return buffer id. |
|
59 */ |
|
60 static CCRPacketBuffer* NewL( const TInt aMaxPackets ); |
|
61 |
|
62 /** |
|
63 * De-allocation method. |
|
64 */ |
|
65 ~CCRPacketBuffer(); |
|
66 |
|
67 public: // New methods |
|
68 |
|
69 /** |
|
70 * Method for setting sink for buffer |
|
71 * @since Series 60 3.0 |
|
72 * @param aSink is the sink to set |
|
73 * @return KErrNone if ok, otherwise system-wide error codes. |
|
74 */ |
|
75 TInt AddSink( CCRPacketSinkBase* aSink ); |
|
76 |
|
77 /** |
|
78 * Method for adding a packet to buf. Succeeds always. |
|
79 * If memory allocation fails this silently fails. |
|
80 * @since Series 60 3.0 |
|
81 * @param aStream a type of packet. |
|
82 * @param aHeader a pointer to packet header. |
|
83 * @param aPacket a pointer to packet payload. |
|
84 * @return none |
|
85 */ |
|
86 void AddPacket( const MCRPacketSource::TCRPacketStreamId& aStream, |
|
87 const TDesC8& aHeader, |
|
88 const TDesC8& aPacket ); |
|
89 |
|
90 /** |
|
91 * Method for adding a packet to buf. |
|
92 * If memory allocation fails this silently fails. |
|
93 * @since Series 60 3.0 |
|
94 * @param aStream a type of packet. |
|
95 * @param aPacket is pointer to data that will be stored to buf. |
|
96 * @return none |
|
97 */ |
|
98 void AddPacket( const MCRPacketSource::TCRPacketStreamId& aStream, |
|
99 const TDesC8& aPacket ); |
|
100 |
|
101 /** |
|
102 * Setter for buffer's flow control mode. |
|
103 * @since Series 60 3.0 |
|
104 * @param aState a state to set. |
|
105 * @return none |
|
106 */ |
|
107 void ContinousStream( const TBool aState ); |
|
108 |
|
109 /** |
|
110 * Getter for buffer's flow control mode. |
|
111 * @since Series 60 3.0 |
|
112 * @return true if continous stream, |
|
113 false if needs flow control. |
|
114 */ |
|
115 TBool ContinousStream(); |
|
116 |
|
117 /** |
|
118 * Setter for buffer's flow control state. |
|
119 * @since Series 60 3.0 |
|
120 * @param aState a state to set. |
|
121 * @return none |
|
122 */ |
|
123 void MoreComing( const TBool aState ); |
|
124 |
|
125 /** |
|
126 * Getter for buffer's flow control state. |
|
127 * @since Series 60 3.0 |
|
128 * @return more coming state. |
|
129 */ |
|
130 TBool MoreComing(); |
|
131 |
|
132 /** |
|
133 * Getter for stream of next packet. |
|
134 * @since Series 60 3.0 |
|
135 * @param aId a id of requester. |
|
136 * @param a stream of the packet. |
|
137 * @return a book keeping index of sink. |
|
138 */ |
|
139 TInt GetStream( const CCRStreamingSession::TCRSinkId& aId, |
|
140 MCRPacketSource::TCRPacketStreamId& aStreamId ); |
|
141 |
|
142 /** |
|
143 * Getter for stream of packet in given offset. |
|
144 * @since Series 60 3.0 |
|
145 * @param aId a id of requester. |
|
146 * @param a stream of the packet. |
|
147 * @return a book keeping index of sink. |
|
148 */ |
|
149 TInt GetStream( const CCRStreamingSession::TCRSinkId& aId, |
|
150 const TInt aOffset, |
|
151 MCRPacketSource::TCRPacketStreamId& aStreamId ); |
|
152 |
|
153 /** |
|
154 * Method for taking packet from a buffer. |
|
155 * @since Series 60 3.0 |
|
156 * @param aId a id of requester. |
|
157 * @param aReturnedData is pointer where the data is read. |
|
158 * NULL if nothing found. |
|
159 * @return none. |
|
160 */ |
|
161 void GetPacket( const CCRStreamingSession::TCRSinkId& aId, |
|
162 TPtr8& aReturnedData ); |
|
163 |
|
164 /** |
|
165 * Method for taking packet from a buffer. |
|
166 * @since Series 60 3.0 |
|
167 * @param aBookKeeping a book keeping index. |
|
168 * @param aReturnedData is pointer where the data is read. |
|
169 * NULL if nothing found. |
|
170 * @return none. |
|
171 */ |
|
172 void GetPacket( const TInt aBookKeeping, |
|
173 TPtr8& aReturnedData ); |
|
174 |
|
175 /** |
|
176 * Method for peeking at a packet in particular offset. This does not |
|
177 * set the packet to be removed from the buffer. |
|
178 * |
|
179 * @since S60 v3.0 |
|
180 * @param aId a id of requester. |
|
181 * @param aReturnedData is pointer where the data is read. |
|
182 * NULL if nothing found. |
|
183 * @param aOffset offset of the packet to be peeked. If zero, the next |
|
184 * packet in the buffer is peeked. |
|
185 */ |
|
186 void PeekPacket( const CCRStreamingSession::TCRSinkId& aId, |
|
187 TPtr8& aReturnedData, |
|
188 const TInt aOffset ); |
|
189 |
|
190 /** |
|
191 * Method for peeking at a packet in particular offset. This does not |
|
192 * set the packet to be removed from the buffer. |
|
193 * |
|
194 * @since S60 v3.0 |
|
195 * @param aBookKeeping a book keeping index. |
|
196 * @param aReturnedData is pointer where the data is read. |
|
197 * NULL if nothing found. |
|
198 * @param aOffset offset of the packet to be peeked. If zero, the next |
|
199 * packet in the buffer is peeked. |
|
200 */ |
|
201 void PeekPacket( const TInt aBookKeeping, |
|
202 TPtr8& aReturnedData, |
|
203 const TInt aOffset ); |
|
204 |
|
205 /** |
|
206 * Method for asking how much packets there are in buf for certain sink. |
|
207 * @since Series 60 3.0 |
|
208 * @param aId a id of requester. |
|
209 * @return number of packets in buffer. |
|
210 */ |
|
211 TInt PacketsCount( const CCRStreamingSession::TCRSinkId& aId ); |
|
212 |
|
213 /** |
|
214 * Method for asking how much packets there are in buf in any sink. |
|
215 * @since Series 60 3.0 |
|
216 * @param none. |
|
217 * @return minimum number of packets in buffer. |
|
218 */ |
|
219 TInt PacketsMinCount(); |
|
220 |
|
221 /** |
|
222 * Method for removing a sink. |
|
223 * @since Series 60 3.0 |
|
224 * @param aSink is the sink to delete |
|
225 * @return number of sinks remaining |
|
226 */ |
|
227 TInt RemoveSink( CCRPacketSinkBase* aSink ); |
|
228 |
|
229 /** |
|
230 * Method for handle buffer wrapping. |
|
231 * @since Series 60 3.0 |
|
232 * @return None. |
|
233 */ |
|
234 void HandleBufferSize(); |
|
235 |
|
236 /** |
|
237 * Method for handle buffer size adjust. |
|
238 * @since Series 60 3.0 |
|
239 * @return None. |
|
240 */ |
|
241 void AdjustBuffer(); |
|
242 |
|
243 /** |
|
244 * Method for handle buffer resetting. |
|
245 * @since Series 60 3.0 |
|
246 * @return None. |
|
247 */ |
|
248 void ResetBuffer(); |
|
249 |
|
250 private: // Constructors and destructor |
|
251 |
|
252 /** |
|
253 * Second pat of construction |
|
254 */ |
|
255 void ConstructL(); |
|
256 |
|
257 /** |
|
258 * Default constructor is private. |
|
259 * @param aMaxPackets a maximum packets count in buffer. |
|
260 */ |
|
261 CCRPacketBuffer( const TInt aMaxPackets ); |
|
262 |
|
263 private: // New methods |
|
264 |
|
265 /** |
|
266 * Method for handling maximum packets in buffer. |
|
267 * @since Series 60 3.0 |
|
268 * @param none. |
|
269 * @return none. |
|
270 */ |
|
271 void VerifyRoom(); |
|
272 |
|
273 /** |
|
274 * Method for taking book keeping index from sink id. |
|
275 * @since Series 60 3.0 |
|
276 * @param aId a id of requester. |
|
277 * @return a book keeping index of sink. |
|
278 */ |
|
279 TInt GetBookKeeping( const CCRStreamingSession::TCRSinkId& aId ); |
|
280 |
|
281 /** |
|
282 * Method for taking book keeping index from sink id. |
|
283 * @since Series 60 3.0 |
|
284 * @param aBookKeeping a book keeping index. |
|
285 * @return an buffer index base on sink. |
|
286 */ |
|
287 TInt GetBufferIndex( const TInt aBookKeeping ); |
|
288 |
|
289 /** |
|
290 * Method for update book keeping of the packets. |
|
291 * @since Series 60 3.0 |
|
292 * @param aDataLength a data length of packet. |
|
293 * @return None. |
|
294 */ |
|
295 void PacketToBookKeeping(); |
|
296 |
|
297 private: // Data types |
|
298 |
|
299 // Book keeping array |
|
300 class SBookKeeping |
|
301 { |
|
302 |
|
303 public: // Data |
|
304 |
|
305 /** |
|
306 * Sink id. |
|
307 */ |
|
308 CCRStreamingSession::TCRSinkId iId; |
|
309 |
|
310 /** |
|
311 * Buffer index. |
|
312 */ |
|
313 TInt iIndex; |
|
314 |
|
315 }; |
|
316 |
|
317 private: // Data |
|
318 |
|
319 /** |
|
320 * Maximum memory usage. |
|
321 */ |
|
322 const TInt iMaxPackets; |
|
323 |
|
324 /** |
|
325 * Flow control mode. |
|
326 */ |
|
327 TBool iContinousStream; |
|
328 |
|
329 /** |
|
330 * Flow control state. |
|
331 */ |
|
332 TBool iMoreComing; |
|
333 |
|
334 /** |
|
335 * Buffer to keep packets. |
|
336 */ |
|
337 RPointerArray<HBufC8> iBuffer; |
|
338 |
|
339 /** |
|
340 * Keeps track of point of each user. |
|
341 */ |
|
342 RArray<SBookKeeping> iBookKeeping; |
|
343 |
|
344 /** |
|
345 * Zero or more packet sinks that are fed via this buffer. |
|
346 */ |
|
347 RPointerArray<CCRPacketSinkBase> iSinkArray; |
|
348 |
|
349 }; |
|
350 |
|
351 #endif // _CCRPACKETBUFFER_H |
|