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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef IRMP3PLAYER_H |
|
20 #define IRMP3PLAYER_H |
|
21 |
|
22 #include <audio.h> |
|
23 #include <mdaaudiooutputstream.h> |
|
24 |
|
25 #include "ircontrolparams.h" |
|
26 #include "irmediaenginedef.h" |
|
27 #include "irmediaengineinterface.h" |
|
28 |
|
29 class CIRBufferContainer; |
|
30 #ifdef __WINS__ |
|
31 class CIRTestingAudioPlayer; |
|
32 #endif //__WINS__ |
|
33 |
|
34 //========================================class declaration CIRMP3Player============================================ |
|
35 |
|
36 /** |
|
37 * This class is the implementation of MP3 format.This forms a part of |
|
38 * media engine which is implemented as an ECom plugin. The interface class |
|
39 * is irmediaengineinterface.h . The mime type of mp3 is used to load this |
|
40 * plugin mimetype : audio/mpeg This is to be passed as the default data |
|
41 * while creation of player |
|
42 * |
|
43 * @code |
|
44 * |
|
45 * //mimetype is buffer with audio/mpeg as data |
|
46 * iPlayer = CIRMediaEngineInterface::NewL(mimetype); |
|
47 * |
|
48 * TConfig config; |
|
49 * config.iVolume = xxxxxx; //some integer value between 0 and Maximum Volume |
|
50 * TUint8* buffer; //is a buffer of size [KINPUT_BUFFER_SIZE] as defined in IRMediaEngineBuffer.h |
|
51 * //this is should have filled buffer when you call Intialize |
|
52 * CIRCtrlCmdObserver* aChannel; //command channel dll's instant |
|
53 * TInt volume; |
|
54 * iPlayer->Intialize(config,buffer,channel); |
|
55 * iPlayer->Play();//to play |
|
56 * iPlayer->Stop();//to stop |
|
57 * iPlayer->SetVolume(volume);//set the volume |
|
58 * iPlayer->Volume;// returns current volume |
|
59 * iPlayer->MaxVolume();//return maximum volume |
|
60 * iPlayer->StopPlayerBuffering();//stop buffering if required |
|
61 * iPlayer->StartPlayerBuffering();//start buffering (incase if stop you can restart with this method) |
|
62 * iPlayer->BufferFilled(); //should be called when the buffer given by player is return |
|
63 * //this will mark the buffer as filled |
|
64 * |
|
65 * @endcode |
|
66 */ |
|
67 |
|
68 NONSHARABLE_CLASS(CIRMP3Player) : public CIRMediaEngineInterface, |
|
69 public MMdaAudioOutputStreamCallback |
|
70 { |
|
71 public: |
|
72 //Member Functions |
|
73 /** |
|
74 * Function : NewL |
|
75 * function returns an instance of CIRMP3Player |
|
76 * Two phase constructor |
|
77 * @return instance of CIRMP3Player |
|
78 */ |
|
79 static CIRMP3Player* NewL(); |
|
80 |
|
81 /** |
|
82 * Function : NewLC |
|
83 * function creates an instance of CIRMP3Player |
|
84 * Two phase constructor |
|
85 * @return instance of CIRMP3Player |
|
86 */ |
|
87 static CIRMP3Player* NewLC(); |
|
88 |
|
89 /** |
|
90 * Function : ~CIRMP3Player |
|
91 * Default Destructor |
|
92 */ |
|
93 ~CIRMP3Player(); |
|
94 |
|
95 //Function which control the play |
|
96 |
|
97 /** |
|
98 * Function : Play |
|
99 * function to which intiate the player |
|
100 */ |
|
101 void Play(); |
|
102 |
|
103 /** |
|
104 * Function : Stop |
|
105 * function to which stop the player |
|
106 */ |
|
107 void Stop(); |
|
108 |
|
109 //Function to control the volume |
|
110 |
|
111 /** |
|
112 * Function : SetVolume |
|
113 * function to set the volume, integer level of volume is the input |
|
114 * @param integer level of volume is the input |
|
115 */ |
|
116 void SetVolume(TInt aVolume); |
|
117 |
|
118 /** |
|
119 * Function : MaxVolume |
|
120 * function to returns the maximum volume , integer value is the Output |
|
121 * @return integer value is the Output |
|
122 */ |
|
123 TInt MaxVolume() const; |
|
124 |
|
125 /** |
|
126 * Function : Volume |
|
127 * function to returns the volume, integer level of voume is the Output |
|
128 * @return integer value is the Output |
|
129 */ |
|
130 TInt Volume() const; |
|
131 |
|
132 /** |
|
133 * Function: Intialize |
|
134 * Set the codec type and sampling rate channel of stream |
|
135 * This is set to initial settings which is required to start the player |
|
136 * @param configuration infomation |
|
137 * @param instance of data buffer, whose size is defined in IRMediaEngineBuffer.h |
|
138 * @param instance of the channel through with information is sent to UI |
|
139 */ |
|
140 void Intialize(TConfig& aConfig,TUint8* aInitParams,CIRCtrlCmdObserver* aChannel); |
|
141 |
|
142 /** |
|
143 * Function: StopPlayerBuffering |
|
144 * Function is used to stop bufferring |
|
145 */ |
|
146 void StopPlayerBuffering(); |
|
147 |
|
148 /** |
|
149 * Function: BufferFilled |
|
150 * Function which is called when the buffer filled with data |
|
151 */ |
|
152 void BufferFilled(); |
|
153 |
|
154 /** |
|
155 * Function: GetAudioPlayer |
|
156 * Function which is called when the Player Instance has Changed |
|
157 */ |
|
158 CMdaAudioOutputStream* GetAudioPlayer(); |
|
159 |
|
160 private: |
|
161 /** |
|
162 * Function: CIRMP3Player |
|
163 * This function is the default constructor |
|
164 */ |
|
165 CIRMP3Player(); |
|
166 |
|
167 /** |
|
168 * Function: ConstructL |
|
169 * Two phase constructor is used to intialize data members |
|
170 */ |
|
171 void ConstructL(); |
|
172 |
|
173 /** |
|
174 * Function: CreateBufferL |
|
175 * Create the buffers and allocates address for each buffers |
|
176 * keeps them in buffer queue |
|
177 */ |
|
178 void CreateBufferL(); |
|
179 |
|
180 /** |
|
181 * Function: ReCreateBufferL |
|
182 * Function is used to recreate the buffer |
|
183 */ |
|
184 void ReCreateBufferL(); |
|
185 |
|
186 /** |
|
187 * Function: GetMP3AudioProperties |
|
188 * extract all the information to start the play from the stream by calling DoFindnDecodeMP3Header |
|
189 */ |
|
190 void GetMP3AudioProperties(); |
|
191 |
|
192 /** |
|
193 * Function: DoFindnDecodeMP3Header |
|
194 * Function is used to find the mp3 header and decode the mp3 header |
|
195 */ |
|
196 void DoFindnDecodeMP3Header(); |
|
197 |
|
198 /** |
|
199 * Function: CrossCheckHeader |
|
200 * Function is cross checks sampling rate |
|
201 * @param a pointer to input buffer |
|
202 * @return ETrue if the sampling rate matches with sampling rate of next MP3 frame |
|
203 */ |
|
204 TBool CrossCheckHeader(TUint8* aInput); |
|
205 |
|
206 //Call back functions |
|
207 public: |
|
208 /** |
|
209 * Function: MaoscBufferCopied |
|
210 * call back to be implement for using CMdaAudioOutputStream |
|
211 * Call as callback from the CMdaAudioOutputStream::WriteL |
|
212 * after frame work copies the stream to buffer |
|
213 * @param Error code |
|
214 * @param reference to buffer |
|
215 */ |
|
216 void MaoscBufferCopied(TInt aError, const TDesC8 &aBuffer); |
|
217 |
|
218 /** |
|
219 * Function: MaoscPlayComplete |
|
220 * call back to beimplement for using CMdaAudioOutputStream |
|
221 * after play is completed |
|
222 * @param error code |
|
223 */ |
|
224 void MaoscPlayComplete(TInt aError); |
|
225 |
|
226 /** |
|
227 * Function: MaoscOpenComplete |
|
228 * call back to implement for using CMdaAudioOutputStream |
|
229 * Call as callback from the CMdaAudioOutputStream::Open |
|
230 * @param error code |
|
231 */ |
|
232 void MaoscOpenComplete(TInt aError); |
|
233 |
|
234 //data members |
|
235 |
|
236 private: |
|
237 //Enum for Play State |
|
238 enum TState |
|
239 { |
|
240 ENotReady, //Not ready to play |
|
241 EReadyToPlay, //Ready to play |
|
242 EPlaying //Playing |
|
243 }; |
|
244 |
|
245 // Player state |
|
246 TState iState; |
|
247 |
|
248 |
|
249 //For implement Player functionalities |
|
250 |
|
251 //player utility |
|
252 CMdaAudioOutputStream* iAudioPlayer; |
|
253 #ifdef __WINS__ |
|
254 //Instance for TestingAudioPlayer |
|
255 CIRTestingAudioPlayer* iTestingAudioPlayer; |
|
256 #endif //__WINS__ |
|
257 |
|
258 //Holds the address of data buffer which is to be played |
|
259 TUint8* iTempbuffer; |
|
260 |
|
261 //This represents a large input buffer which takes the input |
|
262 TUint8* iInputBufferPtr; |
|
263 |
|
264 //Temporary holder for buffer container |
|
265 CIRBufferContainer* iTempBufferHolder; |
|
266 |
|
267 //Instance of channel through with data is sent UI |
|
268 CIRCtrlCmdObserver* iChannel; |
|
269 |
|
270 //Setting for sampling rate, channel |
|
271 TMdaAudioDataSettings iSettings; |
|
272 |
|
273 //FourCC representation of the codec |
|
274 TFourCC iDataType; |
|
275 |
|
276 //hold the configuration information |
|
277 TConfig iConfig; |
|
278 |
|
279 //Hold the pointer to the buffer to be filled |
|
280 TPtr8 iInputBuffer; |
|
281 |
|
282 //Contains Data to be played |
|
283 TPtr8 iInput; |
|
284 |
|
285 //Queue of buffer which is filled |
|
286 TSglQue<CIRBufferContainer> iSourceBufferQ; |
|
287 |
|
288 //Queue of buffer which is empty |
|
289 TSglQue<CIRBufferContainer> iSinkBufferQ; |
|
290 |
|
291 //Holds the audio format data |
|
292 TAudioFormatData iAudioInfo; |
|
293 |
|
294 //Holds the percentage of data in the buffer |
|
295 TInt iBufferPercentage; |
|
296 |
|
297 // For First time play |
|
298 TBool iFirstTime; |
|
299 |
|
300 //this bool indicates buffering is taking place initially or rebuffering |
|
301 //mainly to intial parameter like volume during rebuffering |
|
302 TBool iNeedReBuffering; |
|
303 |
|
304 //Indicates that it is a new player |
|
305 TBool iNewPlayer; |
|
306 |
|
307 //This is used to StopPlayerBuffering while playing |
|
308 TBool iStopPlayerBuffering; |
|
309 |
|
310 //This is used to stop buffering if its rebuffering, set if stop function is called |
|
311 //and reset when play function is called |
|
312 TBool iStopState; |
|
313 |
|
314 //Indicates that player is rebuffering |
|
315 TBool iReBuffering; |
|
316 |
|
317 //skips sending the error code during stop if stop internally |
|
318 //is during play called |
|
319 TBool iSkipPlayCompleted; |
|
320 }; |
|
321 |
|
322 #endif//IRMP3PLAYER_H |
|
323 |
|
324 |
|