1 /*****************************************************************************
2 * JVLC.java: JNI interface for vlc Java Bindings
3 *****************************************************************************
4 * Copyright (C) 1998-2005 the VideoLAN team
6 * Authors: Filippo Carone <filippo@carone.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
27 #include <stdio.h> // for printf
28 #include <stdlib.h> // for calloc
29 #include <string.h> // for strcmp
32 /* JVLC internal imports, generated by gcjh */
33 #include "org_videolan_jvlc_JVLC.h"
34 #include "org_videolan_jvlc_JVLCVariable.h"
35 #include "org_videolan_jvlc_JVLCIntVariable.h"
36 #include "org_videolan_jvlc_JVLCBoolVariable.h"
37 #include "org_videolan_jvlc_JVLCFloatVariable.h"
38 #include "org_videolan_jvlc_JVLCStringVariable.h"
39 #include "org_videolan_jvlc_JVLCTimeVariable.h"
40 #include "org_videolan_jvlc_JVLCVarVariable.h"
41 #include "org_videolan_jvlc_JVLCVarValue.h"
43 int getClassID (JNIEnv *env, jobject obj);
45 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_create (JNIEnv *env, jobject obj) {
49 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_init (JNIEnv *env, jobject obj, jobjectArray args) {
51 /* build the argv vector */
54 /* count the arguments */
55 // int argc = (int) (*env)->GetArrayLength(env, args)
56 int argc = (int) env->GetArrayLength((jarray) args);
58 /* convert java strings to c strings
59 how many pointers do we need? */
60 argv = (const char **) malloc(argc * sizeof(char*));
62 /* now fill the argv* */
63 for (int i = 0; i < argc; i++) {
64 argv[i] = env->GetStringUTFChars((jstring) env->GetObjectArrayElement(args, i),
69 /* execute the library call */
70 int res = VLC_Init(getClassID(env,obj), argc, (char **) argv);
77 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_addInterface (JNIEnv *env, jobject obj, jstring moduleName, jboolean blocking, jboolean startPlay) {
78 const char *psz_module = NULL;
79 int i_blocking, i_startPlay;
81 if (moduleName != NULL) {
82 psz_module = env->GetStringUTFChars(moduleName, 0);
85 if (blocking == true) i_blocking = 1;
88 if (startPlay == true) i_startPlay = 1;
91 int addIntf_res = VLC_AddIntf(getClassID(env,obj), psz_module, i_blocking, i_startPlay);
93 if (psz_module != NULL) {
94 env->ReleaseStringUTFChars(moduleName, psz_module);
99 JNIEXPORT jstring JNICALL Java_org_videolan_jvlc_JVLC_getVersion (JNIEnv *env, jobject obj) {
100 return env->NewStringUTF(VLC_Version());
103 JNIEXPORT jstring JNICALL Java_org_videolan_jvlc_JVLC_getError (JNIEnv *env, jobject obj, jint errorCode) {
104 return env->NewStringUTF(VLC_Error(errorCode));
107 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_die (JNIEnv *env, jobject obj) {
108 return VLC_Die(getClassID(env, obj));
111 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_cleanUp (JNIEnv *env, jobject obj) {
112 return VLC_CleanUp(getClassID(env, obj));
115 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_setVariable (JNIEnv *env, jobject obj, jobject jvlcVariable) {
117 char* psz_var = NULL;
119 jstring stringValue = NULL;
121 if (jvlcVariable != NULL) {
122 /* get the name of jvlcVariable class */
123 jclass variableClass = env->GetObjectClass(jvlcVariable);
124 jclass varSuperClass = env->GetSuperclass (variableClass);
125 jmethodID getNameMethod = env->GetMethodID (varSuperClass, "getName", "()Ljava/lang/String;");
126 jstring varName = (jstring) env->CallObjectMethod (jvlcVariable, getNameMethod);
129 jclass tmpClass = env->FindClass("org/videolan/jvlc/JVLCIntVariable");
130 if (env->IsInstanceOf(jvlcVariable, tmpClass)) {
131 jmethodID mid = env->GetMethodID(variableClass, "getIntValue", "()I");
132 value.i_int = env->CallIntMethod(jvlcVariable, mid);
137 tmpClass = env->FindClass("org/videolan/jvlc/JVLCBoolVariable");
138 if (env->IsInstanceOf(jvlcVariable, tmpClass )) {
139 jmethodID mid = env->GetMethodID(variableClass, "getBoolValue", "()Z");
140 value.b_bool = env->CallBooleanMethod(jvlcVariable, mid);
145 tmpClass = env->FindClass("org/videolan/jvlc/JVLCFloatVariable");
146 if (env->IsInstanceOf(jvlcVariable, tmpClass )) {
147 jmethodID mid = env->GetMethodID(variableClass, "getFloatValue", "()F");
148 value.f_float = env->CallBooleanMethod(jvlcVariable, mid);
153 tmpClass = env->FindClass("org/videolan/jvlc/JVLCStringVariable");
154 if (env->IsInstanceOf(jvlcVariable, tmpClass )) {
155 jmethodID mid = env->GetMethodID(variableClass, "getStringValue", "()Ljava/lang/String");
156 jstring stringValue = (jstring) env->CallObjectMethod(jvlcVariable, mid);
157 value.psz_string = (char *)env->GetStringUTFChars(stringValue, 0);
162 tmpClass = env->FindClass("org/videolan/jvlc/JVLCTimeVariable");
163 if (env->IsInstanceOf(jvlcVariable, tmpClass )) {
164 jmethodID mid = env->GetMethodID(variableClass, "getTimeValue", "()L");
165 value.i_time = env->CallLongMethod(jvlcVariable, mid);
170 tmpClass = env->FindClass("org/videolan/jvlc/JVLCVarVariable");
171 if (env->IsInstanceOf(jvlcVariable, tmpClass )) {
173 * This is the longer one. We have to get the VarValue object
174 * from the JVLCVarVariable and retrieve the OID from it.
176 jmethodID getVarValueMID = env->GetMethodID(variableClass, "getVarValue", "()Lorg/videolan/jvlc/JVLCVarValue;");
177 jobject varVariableObj = env->CallObjectMethod(jvlcVariable, getVarValueMID);
180 * Now from the varVariableObj we need to retrieve its name and OID
184 * Get the VarValue name
187 jclass varVariableCls = env->GetObjectClass(varVariableObj);
188 jmethodID getVarName = env->GetMethodID(varVariableCls, "getName","()Ljava/lang/String;");
189 jstring varName = (jstring) env->CallObjectMethod(varVariableObj, getVarName);
190 value.var.psz_name = (char *)env->GetStringUTFChars(varName, 0);
193 * Get the VarValue OID
196 jmethodID getOID = env->GetMethodID(varVariableCls, "getOID", "()I");
197 value.var.i_object_id = env->CallIntMethod(varVariableObj, getOID);
203 psz_var = (char *) env->GetStringUTFChars(varName, 0);
206 if (psz_var != NULL) {
207 int res = VLC_VariableSet(getClassID(env, obj), (char* const) psz_var, value);
208 env->ReleaseStringUTFChars(varName, psz_var);
209 if (stringValue != NULL) env->ReleaseStringUTFChars(stringValue, value.psz_string);
216 JNIEXPORT jobject JNICALL Java_org_videolan_jvlc_JVLC_getVariable (JNIEnv *env, jobject obj, jstring varName) {
218 const char* psz_var = env->GetStringUTFChars(varName, 0);
220 if (VLC_VariableGet(getClassID(env, obj), psz_var, &value) != VLC_SUCCESS) {
231 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_addTarget (JNIEnv *env, jobject obj, jstring URI, jobjectArray options, jint insertMode, jint position) {
233 char* psz_target = NULL;
234 char** ppsz_options = NULL;
235 int options_number = 0;
238 psz_target = (char *) env->GetStringUTFChars(URI, 0);
241 if (options != NULL) {
242 options_number = env->GetArrayLength(options);
243 ppsz_options = (char **) malloc (options_number * sizeof(char*));
245 for (int i = 0; i < options_number; i++) {
246 ppsz_options[i] = (char *) env->GetStringUTFChars((jstring) env->GetObjectArrayElement(options, i), 0);
250 int res = VLC_AddTarget(getClassID(env, obj), (char const *)psz_target, (const char **) ppsz_options, options_number, insertMode, position);
252 if (ppsz_options != NULL) {
253 for (int i = 0; i < options_number; i++) {
254 free(ppsz_options[i]);
258 if (psz_target != NULL) {
264 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_play (JNIEnv *env, jobject obj) {
265 return VLC_Play(getClassID(env, obj));
268 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_pause (JNIEnv *env, jobject obj) {
269 return VLC_Pause(getClassID(env, obj));
272 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_stop (JNIEnv *env, jobject obj) {
273 return VLC_Stop(getClassID(env, obj));
276 JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_JVLC_isPlaying (JNIEnv *env, jobject obj) {
277 return VLC_IsPlaying(getClassID(env, obj));
280 JNIEXPORT jfloat JNICALL Java_org_videolan_jvlc_JVLC_getPosition (JNIEnv *env, jobject obj) {
281 return VLC_PositionGet(getClassID(env, obj));
284 JNIEXPORT jfloat JNICALL Java_org_videolan_jvlc_JVLC_setPosition (JNIEnv *env, jobject obj, jfloat position) {
285 return VLC_PositionSet(getClassID(env, obj), position);
288 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_getTime (JNIEnv *env, jobject obj) {
289 return VLC_TimeGet(getClassID(env, obj));
292 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_setTime (JNIEnv *env, jobject obj, jint seconds, jboolean relative) {
293 return VLC_TimeSet(getClassID(env, obj), seconds, relative);
296 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_getLength (JNIEnv *env, jobject obj) {
297 return VLC_LengthGet(getClassID(env, obj));
300 JNIEXPORT jfloat JNICALL Java_org_videolan_jvlc_JVLC_speedFaster (JNIEnv *env, jobject obj) {
301 return VLC_SpeedFaster(getClassID(env, obj));
304 JNIEXPORT jfloat JNICALL Java_org_videolan_jvlc_JVLC_speedSlower (JNIEnv *env, jobject obj) {
305 return VLC_SpeedSlower(getClassID(env, obj));
308 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_getPlaylistIndex (JNIEnv *env, jobject obj) {
309 return VLC_PlaylistIndex(getClassID(env, obj));
312 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_getPlaylistItems (JNIEnv *env, jobject obj) {
313 return VLC_PlaylistNumberOfItems(getClassID(env, obj));
316 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_playlistNext (JNIEnv *env, jobject obj) {
317 return VLC_PlaylistNext(getClassID(env, obj));
320 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_playlistPrev (JNIEnv *env, jobject obj) {
321 return VLC_PlaylistPrev(getClassID(env, obj));
324 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_playlistClear (JNIEnv *env, jobject obj) {
325 return VLC_PlaylistClear(getClassID(env, obj));
328 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_getVolume (JNIEnv *env, jobject obj) {
329 return VLC_VolumeGet(getClassID(env, obj));
332 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_setVolume (JNIEnv *env, jobject obj, jint volume) {
333 return VLC_VolumeSet(getClassID(env, obj), volume);
336 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_muteVolume (JNIEnv *env, jobject obj) {
337 return VLC_VolumeMute(getClassID(env, obj));
340 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_JVLC_fullScreen (JNIEnv *env, jobject obj) {
341 return VLC_FullScreen(getClassID(env, obj));
345 * This method is an helper method
346 * only valid if obj == JVLC
349 int getClassID (JNIEnv *env, jobject obj) {
350 /* get the id field of object */
351 jclass cls = env->GetObjectClass(obj);
352 jmethodID mid = env->GetMethodID(cls, "getID", "()I");
353 int field = env->CallIntMethod(obj, mid);