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 has JNI wrappers for CMMAPlayer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //#include <jutils.h> |
|
20 #include "com_nokia_microedition_media_PlayerImpl.h" |
|
21 |
|
22 #include "mmafunctionserver.h" |
|
23 #include "cmmaplayer.h" |
|
24 #include "s60commonutils.h" |
|
25 #include <logger.h> |
|
26 |
|
27 using namespace java::util; |
|
28 |
|
29 // If eventsource is already disposed, then do nothing |
|
30 #define CHECK_HANDLE(x, j) { if ( !( x ) || ( ( x )->Players().Count() == 0 ) ) { return ( j ); } } |
|
31 /* |
|
32 * Wrappers for calling non static methods |
|
33 */ |
|
34 |
|
35 TInt VoidFunc(TInt aPlayer, MMAFunctionServer* aEventSource, |
|
36 TInt(CMMAPlayer::*aFunc)()) |
|
37 { |
|
38 CMMAPlayer* p = aEventSource->FindPlayer(aPlayer); |
|
39 if (p) |
|
40 { |
|
41 return (p->*aFunc)(); |
|
42 } |
|
43 else |
|
44 { |
|
45 return KErrBadHandle; |
|
46 } |
|
47 } |
|
48 |
|
49 void BoolFuncL(TInt aPlayer, MMAFunctionServer* aEventSource, |
|
50 void(CMMAPlayer::*aFunc)(TBool), |
|
51 TBool aValue) |
|
52 { |
|
53 CMMAPlayer* p = aEventSource->FindPlayer(aPlayer); |
|
54 if (p) |
|
55 { |
|
56 (p->*aFunc)(aValue); |
|
57 } |
|
58 // ignore call if player is not found |
|
59 } |
|
60 |
|
61 void VVoidFuncL(TInt aPlayer, MMAFunctionServer* aEventSource, void(CMMAPlayer::*aFunc)()) |
|
62 { |
|
63 CMMAPlayer* p = aEventSource->FindPlayer(aPlayer); |
|
64 if (p) |
|
65 { |
|
66 (p->*aFunc)(); |
|
67 } |
|
68 // ignore call if player is not found |
|
69 } |
|
70 |
|
71 void IntFunc(TInt aPlayer, |
|
72 MMAFunctionServer* aEventSource, |
|
73 void(CMMAPlayer::*aFunc)(TInt), |
|
74 TInt aData) |
|
75 { |
|
76 CMMAPlayer* p = aEventSource->FindPlayer(aPlayer); |
|
77 if (p) |
|
78 { |
|
79 (p->*aFunc)(aData); |
|
80 } |
|
81 // ignore call if player is not found |
|
82 } |
|
83 |
|
84 void TInt64Func(TInt aPlayer, MMAFunctionServer* aEventSource, |
|
85 void(CMMAPlayer::*aFunc)(TInt64* aData), |
|
86 TInt64* aData) |
|
87 { |
|
88 CMMAPlayer* p = aEventSource->FindPlayer(aPlayer); |
|
89 if (p) |
|
90 { |
|
91 (p->*aFunc)(aData); |
|
92 } |
|
93 else |
|
94 { |
|
95 *aData = KErrBadHandle; |
|
96 } |
|
97 } |
|
98 |
|
99 |
|
100 |
|
101 /* |
|
102 * Class: com_nokia_microedition_media_PlayerImpl |
|
103 * Method: _createPlayer |
|
104 * Signature: (III)I |
|
105 */ |
|
106 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1initPlayer |
|
107 (JNIEnv* aJni, |
|
108 jobject aObject, |
|
109 jobject aListenerObject, |
|
110 jint aEventSourceHandle, |
|
111 jint aPlayerHandle) |
|
112 { |
|
113 LOG(EJavaMMAPI,EInfo,"jni_PlayerImpl__1initPlayer Enter... 1"); |
|
114 MMAFunctionServer* eventSource = |
|
115 reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle); |
|
116 |
|
117 CHECK_HANDLE(eventSource, KErrNone); |
|
118 |
|
119 CMMAPlayer* player = reinterpret_cast< CMMAPlayer* >(aPlayerHandle); |
|
120 |
|
121 // init player |
|
122 jobject playerObject = aJni->NewWeakGlobalRef(aObject); |
|
123 LOG(EJavaMMAPI,EInfo,"jni_PlayerImpl__1initPlayer Enter... 5"); |
|
124 TInt err = eventSource->ExecuteTrap(&CMMAPlayer::StaticInitPlayerL, |
|
125 player, |
|
126 eventSource, |
|
127 playerObject, |
|
128 eventSource->getValidJniEnv()); |
|
129 if (err != KErrNone) |
|
130 { |
|
131 aJni->DeleteWeakGlobalRef((jweak)playerObject); |
|
132 return err; |
|
133 } |
|
134 |
|
135 // set player listener |
|
136 jobject playerListener = aJni->NewWeakGlobalRef(aListenerObject); |
|
137 err = eventSource->ExecuteTrap(&CMMAPlayer::StaticSetPlayerListenerObjectL, |
|
138 player, |
|
139 eventSource, |
|
140 playerListener, |
|
141 eventSource->getValidJniEnv(), |
|
142 (MMMAEventPoster*)eventSource); |
|
143 if (err != KErrNone) |
|
144 { |
|
145 aJni->DeleteWeakGlobalRef((jweak)playerListener); |
|
146 } |
|
147 return err; |
|
148 } |
|
149 |
|
150 /* |
|
151 * Class: com_nokia_microedition_media_PlayerImpl |
|
152 * Method: _start |
|
153 * Signature: (II)I |
|
154 */ |
|
155 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1start |
|
156 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
157 { |
|
158 LOG( EJavaMMAPI, EInfo, "jni_PlayerImpl__1start..."); |
|
159 MMAFunctionServer* eventSource = |
|
160 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
161 CHECK_HANDLE(eventSource, KErrNone); |
|
162 TInt err = eventSource->ExecuteTrap(&VVoidFuncL, |
|
163 aPlayer, |
|
164 eventSource, |
|
165 &CMMAPlayer::StartL); |
|
166 LOG1(EJavaMMAPI,EInfo,"jni_PlayerImpl__1start Enter... 3, err = %d",err); |
|
167 // complete java side request in case of leave. |
|
168 if (err != KErrNone) |
|
169 { |
|
170 CMMAPlayer* p = eventSource->FindPlayer(aPlayer); |
|
171 p->PostActionCompleted(err); // java start return |
|
172 } |
|
173 |
|
174 return err; |
|
175 } |
|
176 |
|
177 /* |
|
178 * Class: com_nokia_microedition_media_PlayerImpl |
|
179 * Method: _stop |
|
180 * Signature: (II)I |
|
181 */ |
|
182 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1stop |
|
183 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
184 { |
|
185 MMAFunctionServer* eventSource = |
|
186 reinterpret_cast< MMAFunctionServer *>(aEventSource); |
|
187 |
|
188 CHECK_HANDLE(eventSource, KErrNone); |
|
189 |
|
190 TInt err = eventSource->ExecuteTrap(&BoolFuncL, |
|
191 aPlayer, |
|
192 eventSource, |
|
193 &CMMAPlayer::StopL, |
|
194 (TBool)ETrue); |
|
195 return err; |
|
196 } |
|
197 |
|
198 /* |
|
199 * Class: com_nokia_microedition_media_PlayerImpl |
|
200 * Method: _close |
|
201 * Signature: (II)I |
|
202 */ |
|
203 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1close |
|
204 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
205 { |
|
206 // if eventsource is already disposed, then do nothing |
|
207 |
|
208 MMAFunctionServer* eventSource = |
|
209 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
210 |
|
211 CHECK_HANDLE(eventSource, KErrNone); |
|
212 |
|
213 LOG( EJavaMMAPI, EInfo, "jni_Player.cpp__1close before &CMMAPlayer::CloseL"); |
|
214 TInt err = eventSource->ExecuteTrap(&VVoidFuncL, |
|
215 aPlayer, |
|
216 eventSource, |
|
217 &CMMAPlayer::CloseL); |
|
218 ELOG1( EJavaMMAPI, "jni_Player.cpp__1close %d", err); |
|
219 return err; |
|
220 } |
|
221 |
|
222 /* |
|
223 * Class: com_nokia_microedition_media_PlayerImpl |
|
224 * Method: _prefetch |
|
225 */ |
|
226 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1prefetch |
|
227 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
228 { |
|
229 ELOG( EJavaMMAPI, "jni_Player.cpp__1prefetch "); |
|
230 MMAFunctionServer* eventSource = |
|
231 //JavaUnhand< MMAFunctionServer >(aEventSource); |
|
232 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
233 |
|
234 CHECK_HANDLE(eventSource, KErrNone); |
|
235 |
|
236 TInt err = eventSource->ExecuteTrap(&VVoidFuncL, aPlayer, |
|
237 eventSource, |
|
238 &CMMAPlayer::PrefetchL); |
|
239 |
|
240 ELOG1( EJavaMMAPI, "jni_Player.cpp__1prefetch %d", err); |
|
241 |
|
242 return err; |
|
243 } |
|
244 |
|
245 |
|
246 /* |
|
247 * Class: com_nokia_microedition_media_PlayerImpl |
|
248 * Method: _realize |
|
249 * Signature: (II)I |
|
250 */ |
|
251 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1realize |
|
252 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
253 { |
|
254 MMAFunctionServer* eventSource = |
|
255 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
256 |
|
257 CHECK_HANDLE(eventSource, KErrNone); |
|
258 |
|
259 TInt err = eventSource->ExecuteTrap(&VVoidFuncL, |
|
260 aPlayer, eventSource, |
|
261 &CMMAPlayer::RealizeL); |
|
262 return err; |
|
263 } |
|
264 |
|
265 |
|
266 /* |
|
267 * Class: com_nokia_microedition_media_PlayerImpl |
|
268 * Method: _setLoopCount |
|
269 * Signature: (III)I |
|
270 */ |
|
271 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1setLoopCount |
|
272 (JNIEnv *, jclass, jint aEventSource, jint aPlayer, jint aLoopCount) |
|
273 { |
|
274 MMAFunctionServer* eventSource = |
|
275 reinterpret_cast< MMAFunctionServer *>(aEventSource); |
|
276 |
|
277 CHECK_HANDLE(eventSource, KErrNone); |
|
278 |
|
279 eventSource->ExecuteV(&IntFunc, |
|
280 aPlayer, eventSource, |
|
281 &CMMAPlayer::SetLoopCount, |
|
282 aLoopCount); |
|
283 return KErrNone; |
|
284 } |
|
285 |
|
286 /* |
|
287 * Class: com_nokia_microedition_media_PlayerImpl |
|
288 * Method: _duration |
|
289 * Signature: (II)J |
|
290 */ |
|
291 JNIEXPORT jlong JNICALL Java_com_nokia_microedition_media_PlayerImpl__1duration |
|
292 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
293 { |
|
294 MMAFunctionServer* eventSource = |
|
295 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
296 |
|
297 CHECK_HANDLE(eventSource, KErrNone); |
|
298 |
|
299 TInt64 duration(0); |
|
300 |
|
301 TInt err = eventSource->ExecuteTrap(&TInt64Func, |
|
302 aPlayer, eventSource, |
|
303 &CMMAPlayer::GetDuration, |
|
304 &duration); |
|
305 if (err != KErrNone) |
|
306 { |
|
307 return err; |
|
308 } |
|
309 return *reinterpret_cast< jlong* >(&duration); |
|
310 } |
|
311 |
|
312 /* |
|
313 * Class: com_nokia_microedition_media_PlayerImpl |
|
314 * Method: _setMediaTime |
|
315 * Signature: (IIJ)J |
|
316 */ |
|
317 JNIEXPORT jlong JNICALL Java_com_nokia_microedition_media_PlayerImpl__1setMediaTime |
|
318 (JNIEnv *, jclass, jint aEventSource, jint aPlayer, jlong aNow) |
|
319 { |
|
320 MMAFunctionServer* eventSource = |
|
321 reinterpret_cast< MMAFunctionServer *>(aEventSource); |
|
322 |
|
323 CHECK_HANDLE(eventSource, KErrNone); |
|
324 |
|
325 |
|
326 TInt64 time = *reinterpret_cast< TInt64* >(&aNow); |
|
327 |
|
328 TInt err = eventSource->ExecuteTrap(&TInt64Func, |
|
329 aPlayer, eventSource, |
|
330 &CMMAPlayer::SetMediaTimeL, |
|
331 &time); |
|
332 |
|
333 if (err != KErrNone) |
|
334 { |
|
335 ELOG1( EJavaMMAPI, "MMA::Java_com_nokia_microedition_media_PlayerImpl__1setMediaTime error %d ", |
|
336 err); |
|
337 return err; |
|
338 } |
|
339 return *reinterpret_cast< jlong* >(&time); |
|
340 } |
|
341 |
|
342 /* |
|
343 * Class: com_nokia_microedition_media_PlayerImpl |
|
344 * Method: _deallocate |
|
345 * Signature: (II)I |
|
346 */ |
|
347 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1deallocate |
|
348 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
349 { |
|
350 MMAFunctionServer* eventSource = |
|
351 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
352 |
|
353 CHECK_HANDLE(eventSource, KErrNone); |
|
354 |
|
355 TInt err = eventSource->ExecuteTrap(&VVoidFuncL, |
|
356 aPlayer, eventSource, |
|
357 &CMMAPlayer::DeallocateL); |
|
358 return err; |
|
359 } |
|
360 |
|
361 /* |
|
362 * Class: com_nokia_microedition_media_PlayerImpl |
|
363 * Method: _getMediaTime |
|
364 * Signature: (II)J |
|
365 */ |
|
366 JNIEXPORT jlong JNICALL Java_com_nokia_microedition_media_PlayerImpl__1getMediaTime |
|
367 (JNIEnv*, jclass, jint aEventSource, jint aPlayer) |
|
368 { |
|
369 MMAFunctionServer* eventSource = |
|
370 reinterpret_cast< MMAFunctionServer *>(aEventSource); |
|
371 |
|
372 CHECK_HANDLE(eventSource, KErrNone); |
|
373 |
|
374 TInt64 mediaTime(0); |
|
375 |
|
376 TInt err = eventSource->ExecuteTrap(&TInt64Func, aPlayer, |
|
377 eventSource, |
|
378 &CMMAPlayer::GetMediaTime, |
|
379 &mediaTime); |
|
380 if (err != KErrNone) |
|
381 { |
|
382 return err; |
|
383 } |
|
384 return *reinterpret_cast< jlong* >(&mediaTime); |
|
385 } |
|
386 |
|
387 /* |
|
388 * Class: com_nokia_microedition_media_PlayerImpl |
|
389 * Method: _getState |
|
390 * Signature: (II)I |
|
391 */ |
|
392 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1getState |
|
393 (JNIEnv *, jclass, jint aEventSource, jint aPlayer) |
|
394 { |
|
395 MMAFunctionServer* eventSource = |
|
396 reinterpret_cast< MMAFunctionServer* >(aEventSource); |
|
397 |
|
398 CHECK_HANDLE(eventSource, KErrNone); |
|
399 |
|
400 LOG(EJavaMMAPI,EInfo,"MMA::Java_com_nokia_microedition_media_PlayerImpl__1getState before finding player "); |
|
401 CMMAPlayer* player = eventSource->FindPlayer(aPlayer); |
|
402 LOG(EJavaMMAPI,EInfo,"MMA::Java_com_nokia_microedition_media_PlayerImpl__1getState after finding player "); |
|
403 TInt state = CMMAPlayer::EClosed; |
|
404 if (player != NULL) |
|
405 { |
|
406 state = player->State(); |
|
407 } |
|
408 |
|
409 LOG1(EJavaMMAPI,EInfo,"MMA::Java_com_nokia_microedition_media_PlayerImpl__1getState state %d ", |
|
410 state); |
|
411 return state; |
|
412 } |
|
413 |
|
414 /* |
|
415 * |
|
416 */ |
|
417 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1addSourceStream |
|
418 (JNIEnv* aJni, jclass, jint aEventSource, jint aPlayer, jobject aReader) |
|
419 { |
|
420 MMAFunctionServer* eventSource = |
|
421 reinterpret_cast< MMAFunctionServer *>(aEventSource); |
|
422 |
|
423 CHECK_HANDLE(eventSource, KErrNone); |
|
424 |
|
425 CMMAPlayer* player = eventSource->FindPlayer(aPlayer); |
|
426 CMMASourceStream* sourceStream; |
|
427 |
|
428 jobject readerRef = aJni->NewWeakGlobalRef(aReader); |
|
429 |
|
430 TInt err = KErrNotFound; |
|
431 if (player != NULL) |
|
432 { |
|
433 err = eventSource->ExecuteTrap(&CMMAPlayer::StaticAddSourceStreamL, |
|
434 eventSource->getValidJniEnv(), |
|
435 player, |
|
436 eventSource, |
|
437 readerRef, |
|
438 &sourceStream); |
|
439 } |
|
440 if (err != KErrNone) |
|
441 { |
|
442 aJni->DeleteWeakGlobalRef((jweak)readerRef); |
|
443 return err; |
|
444 } |
|
445 return reinterpret_cast<TInt>(sourceStream); |
|
446 } |
|
447 |
|
448 |
|
449 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1getControlsCount |
|
450 (JNIEnv*, jclass, jint aEventSourceHandle, jint aPlayer) |
|
451 { |
|
452 MMAFunctionServer* eventSource = |
|
453 reinterpret_cast< MMAFunctionServer* >(aEventSourceHandle); |
|
454 |
|
455 CHECK_HANDLE(eventSource, KErrNone); |
|
456 |
|
457 |
|
458 TInt count = eventSource->Execute(&VoidFunc, |
|
459 aPlayer, eventSource, |
|
460 &CMMAPlayer::ControlCount); |
|
461 return count; |
|
462 } |
|
463 |
|
464 |
|
465 JNIEXPORT jstring JNICALL Java_com_nokia_microedition_media_PlayerImpl__1getControlClassName |
|
466 (JNIEnv* aJniEnv, jclass, jint aEventSourceHandle, jint aControlHandle) |
|
467 { |
|
468 MMAFunctionServer* eventSource = |
|
469 reinterpret_cast< MMAFunctionServer* >(aEventSourceHandle); |
|
470 |
|
471 CMMAControl* control = reinterpret_cast< CMMAControl* >(aControlHandle); |
|
472 |
|
473 const TDesC* name = eventSource->Execute(CMMAControl::ClassNameJni, |
|
474 control); |
|
475 return S60CommonUtils::NativeToJavaString(*aJniEnv, *name); |
|
476 } |
|
477 |
|
478 |
|
479 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_PlayerImpl__1getControlHandle |
|
480 (JNIEnv*, jclass, jint aEventSourceHandle, jint aPlayer, jint aIndex) |
|
481 { |
|
482 MMAFunctionServer* eventSource = |
|
483 reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle); |
|
484 |
|
485 CHECK_HANDLE(eventSource, KErrNone); |
|
486 |
|
487 CMMAPlayer* player = eventSource->FindPlayer(aPlayer); |
|
488 CMMAControl* control = NULL; |
|
489 if (player) |
|
490 { |
|
491 control = eventSource->Execute(CMMAPlayer::StaticControl, |
|
492 player, |
|
493 aIndex); |
|
494 } |
|
495 else |
|
496 { |
|
497 return KErrBadHandle; |
|
498 } |
|
499 |
|
500 return reinterpret_cast<TInt>(control); |
|
501 } |
|
502 |
|
503 LOCAL_C void DisposePlayer(MMAFunctionServer* aEventSource, |
|
504 TInt aPlayer) |
|
505 { |
|
506 CMMAPlayer* player = aEventSource->FindPlayer(aPlayer); |
|
507 if (player) |
|
508 { |
|
509 aEventSource->DisposePlayer(player); |
|
510 } |
|
511 // else already disposed |
|
512 } |
|
513 |
|
514 JNIEXPORT void JNICALL Java_com_nokia_microedition_media_PlayerImpl__1dispose |
|
515 (JNIEnv*, jclass, jint aEventSourceHandle, jint aPlayer) |
|
516 { |
|
517 MMAFunctionServer* eventSource = |
|
518 reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle); |
|
519 |
|
520 // if eventsource is already disposed, then do nothing |
|
521 if (!eventSource || eventSource->IsDisposed()) |
|
522 { |
|
523 return; |
|
524 } |
|
525 |
|
526 eventSource->ExecuteV(&DisposePlayer, |
|
527 eventSource, |
|
528 aPlayer); |
|
529 } |
|
530 |
|
531 JNIEXPORT jstring JNICALL Java_com_nokia_microedition_media_PlayerImpl__1getContentType |
|
532 (JNIEnv* aJni, jclass, |
|
533 jint aPlayerHandle) |
|
534 { |
|
535 CMMAPlayer* player = reinterpret_cast< CMMAPlayer* >(aPlayerHandle); |
|
536 jstring contentType = NULL; |
|
537 |
|
538 // if content type is null, we just return NULL to Java |
|
539 if (player->ContentType()) |
|
540 { |
|
541 // need to create Java String object |
|
542 contentType = S60CommonUtils::NativeToJavaString(*aJni, *player->ContentType()); |
|
543 } |
|
544 return contentType; |
|
545 } |
|
546 |
|
547 // END OF FILE |
|