]> git.sesse.net Git - vlc/blob - bindings/java/src/vlm-jni.cc
fix dependancies
[vlc] / bindings / java / src / vlm-jni.cc
1 /*****************************************************************************
2  * vlm-jni.cc: JNI native VLM functions for VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2006 the VideoLAN team
5  *
6  * Authors: Philippe Morin <phmorin@free.fr>
7  *
8  *
9  * $Id $
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 #include <jni.h>
27
28 #include <vlc/libvlc.h>
29
30 /* JVLC internal imports, generated by gcjh */
31 #include "../includes/VLM.h"
32 #include "utils.h"
33
34 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1addBroadcast (JNIEnv *env, jobject _this, jstring name, jstring inputmrl, jstring outputmrl, jobjectArray options, jboolean enable, jboolean loop) 
35 {
36     INIT_FUNCTION;
37     const char* psz_name = env->GetStringUTFChars( name, 0 );   
38     const char* psz_inputmrl = env->GetStringUTFChars( inputmrl, 0 );    
39     const char* psz_outputmrl = env->GetStringUTFChars( outputmrl, 0 );        
40     int i_options = 0;
41     const char** ppsz_options = NULL;
42     
43     if ( options != NULL ) {
44         i_options = ( int ) env->GetArrayLength( ( jarray ) options );
45         ppsz_options = ( const char ** ) malloc( i_options * sizeof( char* ) );
46         
47         for ( int i = 0; i < i_options - 1; i++ ) {
48             ppsz_options[ i ] = 
49                 env->GetStringUTFChars( ( jstring ) env->GetObjectArrayElement( options, i ), 0 );
50         }
51     }
52
53     libvlc_vlm_add_broadcast( (libvlc_instance_t *) instance, (char*)psz_name, (char*)psz_inputmrl, (char*)psz_outputmrl ,
54                               i_options, (char**)ppsz_options, enable, loop, &exception );
55
56     CHECK_EXCEPTION ;
57
58     
59     if (psz_name != NULL) {
60         env->ReleaseStringUTFChars( name, psz_name );
61     }    
62     if (psz_inputmrl != NULL) {
63         env->ReleaseStringUTFChars( inputmrl, psz_inputmrl );
64     }    
65     if (psz_outputmrl != NULL) {
66         env->ReleaseStringUTFChars( outputmrl, psz_outputmrl );
67     }
68 }
69
70 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1deleteMedia (JNIEnv *env, jobject _this, jstring name) 
71 {
72     INIT_FUNCTION ;
73     const char* psz_name = env->GetStringUTFChars( name, 0 );
74
75     libvlc_vlm_del_media( (libvlc_instance_t *) instance, (char*)psz_name, &exception);    
76     CHECK_EXCEPTION ;
77
78     if (psz_name != NULL) {
79         env->ReleaseStringUTFChars( name, psz_name );
80     }    
81 }
82
83 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1setEnabled (JNIEnv *env, jobject _this, jstring name, jboolean newStatus) 
84 {
85     INIT_FUNCTION ;
86     const char* psz_name = env->GetStringUTFChars( name, 0 );
87
88     libvlc_vlm_set_enabled( (libvlc_instance_t *) instance, (char*)psz_name, newStatus, &exception);
89     CHECK_EXCEPTION ;
90
91     if (psz_name != NULL) {
92         env->ReleaseStringUTFChars( name, psz_name );
93     }        
94 }
95
96 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1setOutput (JNIEnv *env, jobject _this, jstring name, jstring mrl) 
97 {
98     INIT_FUNCTION;
99     const char* psz_name = env->GetStringUTFChars( name, 0 );
100     const char* psz_mrl = env->GetStringUTFChars( mrl, 0 );    
101
102     libvlc_vlm_set_output((libvlc_instance_t *) instance, (char*)psz_name, (char*)psz_mrl, &exception);
103     CHECK_EXCEPTION ;
104
105     if (psz_name != NULL) {
106         env->ReleaseStringUTFChars( name, psz_name );
107     }    
108
109     if (psz_mrl != NULL) {
110         env->ReleaseStringUTFChars( mrl, psz_mrl );
111     }    
112 }
113
114 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1setInput (JNIEnv *env, jobject _this, jstring name, jstring mrl) 
115 {
116     INIT_FUNCTION;
117     const char* psz_name = env->GetStringUTFChars( name, 0 );
118     const char* psz_mrl = env->GetStringUTFChars( mrl, 0 );    
119
120     libvlc_vlm_set_input((libvlc_instance_t *) instance, (char*)psz_name, (char*)psz_mrl, &exception);
121     CHECK_EXCEPTION ;
122
123     if (psz_name != NULL) {
124         env->ReleaseStringUTFChars( name, psz_name );
125     }    
126     if (psz_mrl != NULL) {
127         env->ReleaseStringUTFChars( mrl, psz_mrl );
128     }    
129 }
130
131 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1setLoop (JNIEnv *env, jobject _this, jstring name, jboolean newStatus) 
132 {
133     INIT_FUNCTION;
134     const char* psz_name = env->GetStringUTFChars( name, 0 );
135
136     libvlc_vlm_set_loop((libvlc_instance_t *) instance, (char*)psz_name, newStatus, &exception);
137     CHECK_EXCEPTION ;
138
139     if (psz_name != NULL) {
140         env->ReleaseStringUTFChars( name, psz_name );
141     }    
142 }
143
144 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1changeMedia (JNIEnv *env, jobject _this, jstring name, jstring inputmrl, jstring outputmrl, jobjectArray options, jboolean enablenewbroadcast, jboolean broadcast) 
145 {
146     INIT_FUNCTION;
147     int i_options = 0;
148     const char** ppsz_options = NULL;
149     const char* psz_name      = env->GetStringUTFChars( name, 0 );
150     const char* psz_inputmrl  = env->GetStringUTFChars( inputmrl, 0 );    
151     const char* psz_outputmrl = env->GetStringUTFChars( outputmrl, 0 );        
152
153     if ( options != NULL ) {
154         i_options = ( int ) env->GetArrayLength( ( jarray ) options );
155         ppsz_options = ( const char ** ) malloc( i_options * sizeof( char* ) );
156         
157         for ( int i = 0; i < i_options - 1; i++ ) {
158             ppsz_options[ i ] = 
159                 env->GetStringUTFChars( ( jstring ) env->GetObjectArrayElement( options, i ), 0 );
160         }
161     }
162
163     libvlc_vlm_change_media( (libvlc_instance_t *) instance, (char*)psz_name, (char*)psz_inputmrl, (char*)psz_outputmrl ,
164                               i_options, (char**)ppsz_options, enablenewbroadcast, broadcast, &exception );
165     CHECK_EXCEPTION ;
166     
167     if (psz_name != NULL) {
168         env->ReleaseStringUTFChars( name, psz_name );
169     }    
170     
171     if (psz_inputmrl != NULL) {
172        env->ReleaseStringUTFChars( name, psz_inputmrl );
173     }    
174    
175     if (psz_outputmrl != NULL) {
176         env->ReleaseStringUTFChars( name, psz_outputmrl );
177     }
178 }
179
180 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1playMedia (JNIEnv *env, jobject _this, jstring name) 
181 {
182     INIT_FUNCTION;
183     const char* psz_name = env->GetStringUTFChars( name, 0 );
184
185     libvlc_vlm_play_media( (libvlc_instance_t *) instance, (char*)psz_name, &exception );
186     CHECK_EXCEPTION ;
187
188     if (psz_name != NULL) {
189         env->ReleaseStringUTFChars( name, psz_name );
190     }
191 }
192
193 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1stopMedia (JNIEnv *env, jobject _this, jstring name) 
194 {
195     INIT_FUNCTION;
196     const char* psz_name = env->GetStringUTFChars( name, 0 );
197
198
199     libvlc_vlm_stop_media( (libvlc_instance_t *) instance, (char*)psz_name, &exception );
200     CHECK_EXCEPTION ;
201
202     if (psz_name != NULL) {
203         env->ReleaseStringUTFChars( name, psz_name );
204     }
205 }
206
207 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1pauseMedia (JNIEnv *env, jobject _this, jstring name) 
208 {
209     INIT_FUNCTION;
210     const char* psz_name = env->GetStringUTFChars( name, 0 );
211    
212     libvlc_vlm_pause_media( (libvlc_instance_t *) instance, (char*)psz_name, &exception );
213     CHECK_EXCEPTION ;
214
215     if (psz_name != NULL) {
216         env->ReleaseStringUTFChars( name, psz_name );
217     }    
218 }
219
220 JNIEXPORT void JNICALL Java_org_videolan_jvlc_VLM__1seekMedia (JNIEnv *env, jobject _this, jstring name, jfloat percentage) 
221 {
222     INIT_FUNCTION;
223     const char* psz_name = env->GetStringUTFChars( name, 0 );
224
225     libvlc_vlm_seek_media( (libvlc_instance_t *) instance, (char*)psz_name, (float)percentage, &exception );
226     CHECK_EXCEPTION ;
227
228     if (psz_name != NULL) {
229         env->ReleaseStringUTFChars( name, psz_name );
230     }
231 }
232
233 JNIEXPORT jstring JNICALL Java_org_videolan_jvlc_VLM__1showMedia (JNIEnv *env, jobject _this, jstring name) 
234 {
235     INIT_FUNCTION;
236     const char* psz_name = env->GetStringUTFChars( name, 0 );
237     char *psz_response;
238     jstring js_response;
239    
240     psz_response = libvlc_vlm_show_media( (libvlc_instance_t *) instance, (char*)psz_name, &exception );
241     CHECK_EXCEPTION ;
242
243     if (psz_name != NULL) {
244         env->ReleaseStringUTFChars( name, psz_name );
245     }
246     js_response = env->NewStringUTF(psz_response);
247     if (psz_response != NULL) {
248         free(psz_response);
249     }
250     return js_response;
251 }
252
253 #define LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( attr, returnType, dummyGetType, dummyDefault)\
254 JNIEXPORT j ## returnType JNICALL Java_org_videolan_jvlc_VLM__1getMedia ## attr(JNIEnv *env, jobject _this, jstring name, jint index) \
255 { \
256     INIT_FUNCTION; \
257     const char* psz_name = env->GetStringUTFChars( name, 0 ); \
258     returnType response; \
259     \
260     response = libvlc_vlm_get_media_ ## attr( (libvlc_instance_t *) instance, (char*)psz_name, (int)index, &exception ); \
261     CHECK_EXCEPTION ; \
262     \
263     if (psz_name != NULL) { \
264         env->ReleaseStringUTFChars( name, psz_name ); \
265     } \
266     return response; \
267 }
268
269 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( position, float, Float, -1);
270 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( time, int, Integer, -1);
271 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( length, int, Integer, -1);
272 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( rate, int, Integer, -1);
273 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( title, int, Integer, 0);
274 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( chapter, int, Integer, 0);
275 LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( seekable, int, Bool, 0);
276
277 #undef LIBVLC_VLM_GET_MEDIA_ATTRIBUTE