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