|
1 /* |
|
2 * Copyright (c) 2002-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: This class is used for playing sounds |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 //#include <mmf/server/mmfdes.h> |
|
21 #include <AudioPreference.h> |
|
22 #include <logger.h> |
|
23 #include "cmmaemcplayerbase.h" |
|
24 #include "cmmaemcresolver.h" |
|
25 |
|
26 using namespace multimedia; |
|
27 |
|
28 using multimedia::MSourceControlObserver; |
|
29 using multimedia::MStreamControlObserver; |
|
30 |
|
31 CMMAEMCPlayerBase::~CMMAEMCPlayerBase() |
|
32 { |
|
33 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::~CMMAEMCPlayerBase +"); |
|
34 |
|
35 if (iMStreamControl) |
|
36 { |
|
37 iMStreamControl->RemoveObserver(*this); |
|
38 if (iMStreamControl->GetState() > 0) |
|
39 { |
|
40 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::~CMMAEMCPlayerBase: iMStreamControl's state = %d",iMStreamControl->GetState()); |
|
41 TInt err = iMStreamControl->Close(); |
|
42 ELOG1(EJavaMMAPI, "MMA::CMMAEMCPlayerBase::~CMMAEMCPlayerBase: Close() err = %d",err); |
|
43 } |
|
44 } |
|
45 |
|
46 if (iFactory) |
|
47 { |
|
48 CleanupSource(); |
|
49 |
|
50 MSinkControl* objPtr1 = iMAudioSink; |
|
51 iMStreamControl->RemoveSink(*objPtr1); |
|
52 |
|
53 iFactory->DeleteSinkControl(objPtr1); |
|
54 iMAudioSink = NULL; |
|
55 |
|
56 //before deleting Stream Control all the controls need to be deleted |
|
57 if (iControls.Count() > 0) |
|
58 iControls.ResetAndDestroy(); |
|
59 |
|
60 iFactory->DeleteStreamControl(iMStreamControl); |
|
61 delete iFactory; |
|
62 } |
|
63 |
|
64 delete iFileName; |
|
65 |
|
66 delete iActiveSchedulerWait; |
|
67 |
|
68 delete iMimeType; |
|
69 |
|
70 delete iDescData; |
|
71 |
|
72 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::~CMMAEMCPlayerBase -"); |
|
73 } |
|
74 |
|
75 |
|
76 CMMAEMCPlayerBase::CMMAEMCPlayerBase( |
|
77 CMMAEMCResolver* aResolver) : |
|
78 iMediaTime(KTimeUnknown), iStartedEventTime(0) |
|
79 { |
|
80 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase +"); |
|
81 // content type ownership is transferred |
|
82 iDescData = NULL; |
|
83 iContentType = aResolver->ContentTypeOwnership(); |
|
84 iMimeType = aResolver->MimeTypeOwnership(); // 8-bit version of iContentType |
|
85 |
|
86 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::ContentType-- %S" ,iContentType->Des().PtrZ()); |
|
87 |
|
88 // file name ownership is transferred |
|
89 iFileName = aResolver->FileNameOwnership(); |
|
90 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::FileName-- %S" ,iFileName->Des().PtrZ()); |
|
91 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase -"); |
|
92 } |
|
93 |
|
94 void CMMAEMCPlayerBase::ConstructL() |
|
95 { |
|
96 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::ConstructL +"); |
|
97 CMMAPlayer::ConstructL(); |
|
98 iSourceType = EDATABUFFERSOURCE; //Currently it only support Http |
|
99 |
|
100 TInt status=CMultimediaFactory::CreateFactory(iFactory); |
|
101 CreateStreamL(); |
|
102 AddDataSourceToStreamL(); |
|
103 |
|
104 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::ConstructL -"); |
|
105 } |
|
106 |
|
107 void CMMAEMCPlayerBase::CreateStreamL() |
|
108 { |
|
109 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::CreateStreamL +"); |
|
110 if (iMStreamControl) |
|
111 User::Leave(KErrAlreadyExists); |
|
112 TInt err = iFactory->CreateStreamControl(KStreamControl,iMStreamControl); |
|
113 User::LeaveIfError(err); |
|
114 //If the state of iMStreamControl changes,iPrevStreamControlState will keep its previous state |
|
115 iPrevStreamControlState = MStreamControl::CLOSED; |
|
116 iMStreamControl->AddObserver(*this); |
|
117 |
|
118 MSinkControl* tempSinkCtrl(NULL); |
|
119 err = iFactory->CreateSinkControl(KMMFAudioOutputSinkControl,tempSinkCtrl); |
|
120 User::LeaveIfError(err); |
|
121 iMAudioSink = tempSinkCtrl; |
|
122 iMStreamControl->AddSink(*iMAudioSink); |
|
123 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::CreateStreamL -"); |
|
124 } |
|
125 |
|
126 void CMMAEMCPlayerBase::AddDataSourceToStreamL() |
|
127 { |
|
128 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::AddDataSourceToStreamL +"); |
|
129 if (iMStreamControl == NULL) |
|
130 { |
|
131 User::Leave(KErrNotReady); |
|
132 } |
|
133 |
|
134 TInt err(KErrNone); |
|
135 MSourceControl* tempCtrl(NULL); |
|
136 |
|
137 switch (iSourceType) |
|
138 { |
|
139 case EFILESOURCE: |
|
140 { |
|
141 err = iFactory->CreateSourceControl(KFileSourceControl, tempCtrl); |
|
142 User::LeaveIfError(err); |
|
143 iMFileSource = static_cast<MFileSource*>(tempCtrl); |
|
144 iMimeType->Des().FillZ(); |
|
145 User::LeaveIfError(iMFileSource->Open(*iFileName, *iMimeType)); |
|
146 iMFileSource->AddObserver(*this); |
|
147 break; |
|
148 } |
|
149 case EDATABUFFERSOURCE: |
|
150 { |
|
151 err = iFactory->CreateSourceControl(KDataBufferSourceControl, tempCtrl); |
|
152 User::LeaveIfError(err); |
|
153 |
|
154 iMDataBufferSource = static_cast<MDataBufferSource*>(tempCtrl); |
|
155 MDataBuffer* headerData = NULL; |
|
156 User::LeaveIfError(iMDataBufferSource->Open(*iMimeType, *headerData)); |
|
157 iMDataBufferSource->AddObserver(*this); |
|
158 break; |
|
159 } |
|
160 case EDESCRIPTORSOURCE: |
|
161 { |
|
162 err = iFactory->CreateSourceControl(KDescriptorSourceControl, tempCtrl); |
|
163 User::LeaveIfError(err); |
|
164 iMDescriptorSource = static_cast<MDescriptorSource*>(tempCtrl); |
|
165 TInt size = 0; |
|
166 // iFile.Size(size); will be used when Descriptor support will be implemented |
|
167 |
|
168 if (iDescData) |
|
169 { |
|
170 delete iDescData; |
|
171 iDescData = NULL; |
|
172 } |
|
173 iDescData = HBufC8::NewL(size); |
|
174 TPtr8 des = iDescData->Des(); |
|
175 //iFile.Read(des); |
|
176 User::LeaveIfError(iMDescriptorSource->Open(*iMimeType,*iDescData)); |
|
177 iMDescriptorSource->AddObserver(*this); |
|
178 break; |
|
179 } |
|
180 default: |
|
181 break; |
|
182 } |
|
183 |
|
184 iMStreamControl->AddSource(*tempCtrl); |
|
185 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::AddDataSourceToStreamL -"); |
|
186 } |
|
187 |
|
188 void CMMAEMCPlayerBase::CleanupSource() |
|
189 { |
|
190 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::CleanupSource +"); |
|
191 if (iMDataBufferSource) |
|
192 { |
|
193 iMDataBufferSource->RemoveObserver(*this); |
|
194 MSourceControl* objPtr = iMDataBufferSource; |
|
195 iMStreamControl->RemoveSource(*objPtr); //added |
|
196 objPtr->Close(); |
|
197 iFactory->DeleteSourceControl(objPtr); |
|
198 iMDataBufferSource = NULL; |
|
199 } |
|
200 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::CleanupSource -"); |
|
201 } |
|
202 |
|
203 EXPORT_C MStreamControl* CMMAEMCPlayerBase::StreamControl() |
|
204 { |
|
205 return iMStreamControl; |
|
206 } |
|
207 |
|
208 EXPORT_C CMultimediaFactory* CMMAEMCPlayerBase::MMFactory() |
|
209 { |
|
210 return iFactory; |
|
211 } |
|
212 |
|
213 TBool CMMAEMCPlayerBase::IsFilePlayer() |
|
214 { |
|
215 return EFalse; |
|
216 } |
|
217 |
|
218 void CMMAEMCPlayerBase::StartL() |
|
219 { |
|
220 // empty implementation |
|
221 // should be overwritten in derived class |
|
222 } |
|
223 |
|
224 void CMMAEMCPlayerBase::StopL(TBool /*aPostEvent*/) |
|
225 { |
|
226 // empty implementation |
|
227 // should be overwritten in derived class |
|
228 } |
|
229 |
|
230 void CMMAEMCPlayerBase::DeallocateL() |
|
231 { |
|
232 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::DeallocateL +"); |
|
233 if (iState == EPrefetched) |
|
234 { |
|
235 // Change state first to enable AMMS to delete Effect API classes |
|
236 ChangeState(ERealized); |
|
237 |
|
238 TInt err = iMStreamControl->Stop(); |
|
239 ELOG1(EJavaMMAPI, "CMMAEMCPlayerBase::DeallocateL iMStreamControl->Stop = %d", err); |
|
240 ResetSourceStreams(); |
|
241 } |
|
242 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::DeallocateL -"); |
|
243 } |
|
244 |
|
245 |
|
246 void CMMAEMCPlayerBase::GetDuration(TInt64* aDuration) |
|
247 { |
|
248 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::GetDuration +"); |
|
249 if (iDuration == KTimeUnknown) |
|
250 { |
|
251 TInt64 duration(0); |
|
252 TInt err = iMStreamControl->GetDuration(duration); |
|
253 if (!err) |
|
254 { |
|
255 iDuration = duration; |
|
256 } |
|
257 } |
|
258 *aDuration = iDuration; |
|
259 LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCPlayerBase::GetDuration -"); |
|
260 } |
|
261 |
|
262 void CMMAEMCPlayerBase::SetMediaTimeL(TInt64* aTime) |
|
263 { |
|
264 LOG(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::SetMediaTimeL +"); |
|
265 |
|
266 // Negative values are not checked here |
|
267 // because it's done already in Java side. |
|
268 |
|
269 // Get clip duration |
|
270 TInt64 duration; |
|
271 User::LeaveIfError(iMStreamControl->GetDuration(duration)); |
|
272 LOG1(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::SetMediaTimeL iMStreamControl->GetDuration=%d", duration); |
|
273 |
|
274 TInt64 position; |
|
275 |
|
276 // If the desired media time is beyond the duration, |
|
277 // the time is set to the end of the media. |
|
278 if (*aTime > duration) |
|
279 { |
|
280 position = duration; |
|
281 } |
|
282 else |
|
283 { |
|
284 position = *aTime; |
|
285 } |
|
286 |
|
287 // The controller must be in the PRIMED or PLAYING state |
|
288 User::LeaveIfError(iMStreamControl->SetPosition(position)); |
|
289 |
|
290 // Reset cached media time, because actual set position may be |
|
291 // something else than aTime. |
|
292 iMediaTime = KTimeUnknown; |
|
293 |
|
294 // Inform about the position change to the StateListeners |
|
295 ChangeState(iState); |
|
296 |
|
297 // Get the actual media time |
|
298 GetMediaTime(aTime); |
|
299 |
|
300 iStartedEventTime = iMediaTime; |
|
301 LOG(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::SetMediaTimeL -"); |
|
302 } |
|
303 |
|
304 void CMMAEMCPlayerBase::GetMediaTime(TInt64* aMediaTime) |
|
305 { |
|
306 LOG(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::GetMediaTimeL +"); |
|
307 TInt64 position(0); |
|
308 |
|
309 if (iMediaTime == KTimeUnknown || iState == EStarted) |
|
310 { |
|
311 |
|
312 TInt error(iMStreamControl->GetPosition(position)); |
|
313 |
|
314 if (error == KErrNone) |
|
315 { |
|
316 TInt64 newTime = position; |
|
317 |
|
318 // Sanity check for media time going backwards or beyond the |
|
319 // duration. |
|
320 // Some native controls may return zero media time for |
|
321 // a few moments just before playback will complete. |
|
322 if (newTime < iMediaTime || |
|
323 (iDuration > 0 && newTime > iDuration)) |
|
324 { |
|
325 GetDuration(&iMediaTime); |
|
326 } |
|
327 else |
|
328 { |
|
329 // set return value |
|
330 iMediaTime = newTime; |
|
331 } |
|
332 } |
|
333 else |
|
334 { |
|
335 ELOG1(EJavaMMAPI, "CMMAEMCPlayerBase::GetMediaTimeL: error=%d, returning TIME_UNKNOWN", error); |
|
336 // cannot get media time |
|
337 iMediaTime = KTimeUnknown; |
|
338 } |
|
339 } |
|
340 *aMediaTime = iMediaTime; |
|
341 LOG(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::GetMediaTimeL -"); |
|
342 } |
|
343 |
|
344 void CMMAEMCPlayerBase::CloseL() |
|
345 { |
|
346 LOG(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::CloseL +"); |
|
347 CMMAPlayer::CloseL(); |
|
348 |
|
349 iMStreamControl->Close(); |
|
350 LOG(EJavaMMAPI, EInfo, "CMMAEMCPlayerBase::CloseL -"); |
|
351 } |
|
352 |
|
353 void CMMAEMCPlayerBase::Event(MControl* /*aControl*/, TUint /*aEventType*/, TAny* /*aEventObject*/) |
|
354 { |
|
355 //Not Called |
|
356 } |
|
357 |
|
358 // END OF FILE |