|
1 /* |
|
2 * Copyright (c) 2006-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 "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: Reads data from opened ICY session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /* --------------------------------------------------------------------------- |
|
20 * Version history: |
|
21 * Template version: |
|
22 * <ccm_history> |
|
23 * |
|
24 * Version: 2, Tue Feb 28 18:00:00 2008 by Rohit/Kranthi |
|
25 * Ref: |
|
26 * Added NetworkController instance for Byte Counter Impl |
|
27 * |
|
28 * </ccm_history> |
|
29 * ============================================================================ |
|
30 */ |
|
31 |
|
32 #ifndef IR_IRICYFLOWREADER |
|
33 #define IR_IRICYFLOWREADER |
|
34 |
|
35 |
|
36 #include <e32base.h> |
|
37 #include <es_sock.h> |
|
38 |
|
39 class CIRMetaData; |
|
40 class CIRNetworkBuffer; |
|
41 class CIRStationConnection; |
|
42 class MIRStationDataObserver; |
|
43 class RSocket; |
|
44 class TChannelInfo; |
|
45 class CIRNetworkController; |
|
46 |
|
47 /** |
|
48 * This class handles reading audio and metadata from a connected |
|
49 * ICY session. It assumes that the socket is connected, the |
|
50 * ICY session has been requested and initial ICY headers have been |
|
51 * processed. |
|
52 * |
|
53 */ |
|
54 NONSHARABLE_CLASS( CIRIcyFlowReader ) : public CActive |
|
55 { |
|
56 public: // Constructors and destructors |
|
57 |
|
58 /** |
|
59 * Standard Symbian two-phase construction |
|
60 * |
|
61 * @param aSocket Socket to be read. |
|
62 * @param aOwner The owner of this CIRIcyFlowReader |
|
63 * @param aDataObserver The observer wishing to receive audio/metadata. |
|
64 * @param aChannelInfo Information describing the ICY session |
|
65 * @return Instance of CIRIcyFlowReader |
|
66 */ |
|
67 static CIRIcyFlowReader* NewL( RSocket& aSocket, CIRStationConnection& aOwner, |
|
68 MIRStationDataObserver& aDataObserver, |
|
69 TChannelInfo& aChannelInfo ); |
|
70 |
|
71 /** |
|
72 * Destructor |
|
73 */ |
|
74 ~CIRIcyFlowReader(); |
|
75 |
|
76 public: |
|
77 |
|
78 /** |
|
79 * Starts the reading from the socket |
|
80 */ |
|
81 void Start(); |
|
82 |
|
83 /** |
|
84 * Fills the buffer with the streamed data |
|
85 * |
|
86 * @param aInputBuffer Buffer into which audio data is to be copied |
|
87 */ |
|
88 void FillBuffer(TDes8& aInputBuffer); |
|
89 |
|
90 private: // Functions from base classes |
|
91 |
|
92 /** |
|
93 * From CActive |
|
94 */ |
|
95 void RunL(); |
|
96 |
|
97 /** |
|
98 * From CActive |
|
99 */ |
|
100 void DoCancel(); |
|
101 |
|
102 private: |
|
103 /** |
|
104 * Copies the buffer to the mediaengine sink queue |
|
105 * |
|
106 * @param aData Data to copy. |
|
107 */ |
|
108 void AddToSinkQueue( const TDesC8& aData ); |
|
109 |
|
110 /** |
|
111 * Fills the media engine buffer with audio data upon request |
|
112 * by the media engine |
|
113 * |
|
114 * @param aInputBuffer Buffer into which audio data is to be copied |
|
115 */ |
|
116 void FillMediaEngineBuffer(const TDes8& aInputBuffer); |
|
117 |
|
118 /** |
|
119 * Fills the unfilled media engine buffers with the remaining audio data |
|
120 */ |
|
121 void FillRemainingBuffers(); |
|
122 |
|
123 /** |
|
124 * C++ default constructor |
|
125 */ |
|
126 CIRIcyFlowReader( RSocket& aSocket, CIRStationConnection& aOwner, |
|
127 MIRStationDataObserver& aDataObserver, TChannelInfo& aChannelInfo ); |
|
128 |
|
129 /** |
|
130 * Second phase construction |
|
131 */ |
|
132 void ConstructL(); |
|
133 |
|
134 private: |
|
135 |
|
136 /** |
|
137 * The parsing states |
|
138 */ |
|
139 enum TIRParsingState |
|
140 { |
|
141 EIRReadingAudioData, /**< Reading raw audio data. */ |
|
142 EIRReadingMetaDataLength, /**< Reading the length of the meta data. */ |
|
143 EIRReadingMetaData /**< Reading meta data. */ |
|
144 }; |
|
145 |
|
146 /** |
|
147 * Initiates a read from socket. |
|
148 */ |
|
149 void IssueRead(); |
|
150 |
|
151 /** |
|
152 * Initializes the buffers that will be used for streaming |
|
153 */ |
|
154 void InitializeBuffersL(); |
|
155 |
|
156 /** |
|
157 * Extracts the meta data from the stream |
|
158 */ |
|
159 void ExtractMetadataL(); |
|
160 |
|
161 /** |
|
162 * Handles received data. |
|
163 * |
|
164 * Can contain any amount of audio and/or meta data mixed in with it. |
|
165 * |
|
166 * @param aData Data received. |
|
167 */ |
|
168 void HandleReceivedDataL( const TDesC8& aData ); |
|
169 |
|
170 /** |
|
171 * Handles received audio data. |
|
172 * |
|
173 * Can only contain raw audio data. |
|
174 * |
|
175 * @param aData Data received. |
|
176 */ |
|
177 void HandleReceivedAudioData( const TDesC8& aData ); |
|
178 |
|
179 /** |
|
180 * Handles received meta data. |
|
181 * |
|
182 * Can only contain meta data. |
|
183 * |
|
184 * @param aData Data received. |
|
185 */ |
|
186 void HandleReceivedMetaData( const TDesC8& aData ); |
|
187 /** |
|
188 * Recognizes if the string is UTF-8 encoded and decodes it, |
|
189 * if required. |
|
190 * |
|
191 * @param aString The string to be decoded. |
|
192 * @return The string in Unicode/ISO-8859-1 format. |
|
193 */ |
|
194 HBufC* DecodeMetadataStringLC( const TDesC8& aString ) const; |
|
195 |
|
196 /** |
|
197 * Tests whether the string is UTF-8 encoded. |
|
198 * |
|
199 * @param aString The string to be examined |
|
200 * @return ETrue, if the string is UTF-8 encoded, EFalse otherwise. |
|
201 */ |
|
202 TBool IsUtf8Encoded( const TDesC8& aString ) const; |
|
203 |
|
204 private: |
|
205 |
|
206 /** |
|
207 * The pointer to buffer which holds the audio data. |
|
208 * Owned. |
|
209 */ |
|
210 TUint8* iSongBuffer; |
|
211 |
|
212 /** |
|
213 * Buffer that holds the data received over the network. |
|
214 * Owned. |
|
215 */ |
|
216 HBufC8* iSocketBuffer; |
|
217 |
|
218 /** |
|
219 * Buffer to contain unfinished song data. |
|
220 * Owned. |
|
221 */ |
|
222 HBufC8* iTempSongBuffer; |
|
223 |
|
224 /** |
|
225 * Buffer to contain unfinished meta data. |
|
226 * Owned. |
|
227 */ |
|
228 HBufC8* iTempMetaBuffer; |
|
229 |
|
230 /** |
|
231 * Current meta data information. |
|
232 * Owned. |
|
233 */ |
|
234 CIRMetaData* iMetaData; |
|
235 |
|
236 /** |
|
237 * The socket that read. |
|
238 */ |
|
239 RSocket& iSocket; |
|
240 |
|
241 /** |
|
242 * The owner of this object in the whole-part relation. |
|
243 */ |
|
244 CIRStationConnection& iOwner; |
|
245 |
|
246 /** |
|
247 * The observer wishing to receive audio/metadata |
|
248 */ |
|
249 MIRStationDataObserver& iDataObserver; |
|
250 |
|
251 /** |
|
252 * Queue of buffer which is filled |
|
253 */ |
|
254 TSglQue<CIRNetworkBuffer> iSourceQ; |
|
255 |
|
256 /** |
|
257 * Queue of buffer which is empty |
|
258 */ |
|
259 TSglQue<CIRNetworkBuffer> iSinkQ; |
|
260 |
|
261 /** |
|
262 * Temporary holder for network buffer. |
|
263 * Not owned. |
|
264 */ |
|
265 CIRNetworkBuffer* iTempBufferHolder; |
|
266 |
|
267 /** |
|
268 * Pointer descriptor to the network data buffer. |
|
269 */ |
|
270 TPtr8 iSocketBufferPtr; |
|
271 |
|
272 /** |
|
273 * Indicates the no. of bytes read from the socket |
|
274 */ |
|
275 TSockXfrLength iSocketBytesRead; |
|
276 |
|
277 /** |
|
278 * Indicates that stream source ( network side ) buffering is happening. |
|
279 */ |
|
280 TBool iInitialBuffering; |
|
281 |
|
282 /** |
|
283 * Indicates rebuffering is occurring |
|
284 */ |
|
285 TBool iReBuffering; |
|
286 |
|
287 /** |
|
288 * Indicates no of chunks of buffers to be copied |
|
289 */ |
|
290 TInt iNoOfChunks; |
|
291 |
|
292 /** |
|
293 * Indicates the number of chunks are remaining |
|
294 */ |
|
295 TInt iChunksRemaining; |
|
296 |
|
297 /** |
|
298 * Length of the current meta data block in bytes. |
|
299 */ |
|
300 TInt iMetaDataLength; |
|
301 |
|
302 /** |
|
303 * Pointer to buffer to be filled. |
|
304 * Not owned. |
|
305 */ |
|
306 TUint8* iBufferFillPointer; |
|
307 |
|
308 /** |
|
309 * Used to give buffer fill value to progress bar |
|
310 */ |
|
311 TInt iBufferCounter; |
|
312 |
|
313 /** |
|
314 * Used to determine the metadata position |
|
315 */ |
|
316 TInt iAudioDataOffset; |
|
317 |
|
318 /** |
|
319 * Indicates the data parsing state. |
|
320 */ |
|
321 TIRParsingState iParsingState; |
|
322 |
|
323 /** |
|
324 * Holds the channel information |
|
325 */ |
|
326 TChannelInfo& iChannelInfo; |
|
327 |
|
328 /** |
|
329 * Indicates if the channel info should be published or not |
|
330 */ |
|
331 TBool iPublishStationInfo; |
|
332 |
|
333 /** |
|
334 * NetworkController singleton instance |
|
335 */ |
|
336 CIRNetworkController* iNetworkControllerHandle; |
|
337 }; |
|
338 |
|
339 #endif // IR_IRICYFLOWREADER |
|
340 |
|
341 |
|
342 |