]> git.sesse.net Git - vlc/blob - bindings/java/src/core-jni.cc
Initial callback support in libvlc + example on how to use in the java bindings
[vlc] / bindings / java / src / core-jni.cc
1 /*****************************************************************************
2  * vlc-libvlc-jni.cc: JNI interface for vlc Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2006 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *          Philippe Morin <phmorin@free.fr>
8  *
9  * $Id: core-jni.cc 156 2006-08-01 09:23:01Z littlejohn $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /* These are a must*/
27 #include <jni.h>
28 #include <vlc/libvlc.h>
29
30 #include <stdio.h>  // for printf
31 #include <stdlib.h> // for calloc
32 #include <string.h> // for strcmp
33 #ifdef WIN32
34 #undef usleep
35 #define usleep(var) Sleep(var/1000)
36 #else
37 #include <unistd.h> // for usleep
38 #endif
39
40 /* JVLC internal imports, generated by gcjh */
41 #include "../includes/JVLC.h"
42
43 #include <jawt.h>
44 #include <jawt_md.h>
45
46 #include "utils.h"
47
48
49 jlong getClassInstance (JNIEnv *env, jobject _this);
50
51 JNIEXPORT jlong JNICALL Java_org_videolan_jvlc_JVLC_createInstance (JNIEnv *env, jobject _this, jobjectArray args) {
52
53     long res;
54     int argc;
55     const char **argv;
56
57     libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ) );
58
59     libvlc_exception_init( exception );
60   
61     argc = (int) env->GetArrayLength((jarray) args);
62     argv = (const char **) malloc(argc * sizeof(char*));
63
64     for (int i = 0; i < argc; i++) {
65         argv[i] = env->GetStringUTFChars((jstring) env->GetObjectArrayElement(args, i),
66                                          0
67         );
68     }
69
70     res = (long) libvlc_new(argc, (char**) argv, exception );
71
72     free( exception );
73
74     return res;
75
76 }
77
78 JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1destroy (JNIEnv *env, jobject _this) 
79 {
80     long instance;
81     
82     instance = getClassInstance( env, _this );
83
84     libvlc_destroy( (libvlc_instance_t *) instance, NULL);
85
86     return;
87 }
88
89
90 //JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1paint (JNIEnv *env, jobject _this, jobject canvas, jobject graphics)
91
92
93 /*
94  * Utility functions
95  */
96 jlong getClassInstance (JNIEnv *env, jobject _this) {
97     /* get the id field of object */
98     jclass    cls   = env->GetObjectClass(_this);
99     jmethodID mid   = env->GetMethodID(cls, "getInstance", "()J");
100     jlong     field = env->CallLongMethod(_this, mid);
101     return field;
102 }