]> git.sesse.net Git - vlc/blob - bindings/java/src/video-jni.cc
fix dependancies
[vlc] / bindings / java / src / video-jni.cc
1 /*****************************************************************************
2  * video-jni.cc: JNI native video functions for VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2006 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
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 /* These are a must*/
27 #include <jni.h>
28 #include <jawt.h>
29
30 #include <vlc/libvlc.h>
31 #include <stdio.h>
32
33 /* JVLC internal imports, generated by gcjh */
34 #include "../includes/Video.h"
35
36 #include "utils.h"
37
38
39 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1toggleFullscreen (JNIEnv *env, jobject _this)
40 {
41     INIT_FUNCTION ;
42
43     GET_INPUT_THREAD ;
44     
45     libvlc_toggle_fullscreen( input, &exception );
46
47     libvlc_media_instance_release(input);
48
49     CHECK_EXCEPTION ;
50 }
51
52 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setFullscreen (JNIEnv *env, jobject _this, jboolean value) 
53 {
54     INIT_FUNCTION ;
55
56     GET_INPUT_THREAD ;
57
58     libvlc_set_fullscreen( input, value, &exception );
59
60     libvlc_media_instance_release(input);
61     CHECK_EXCEPTION ;
62 }
63
64 JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Video__1getFullscreen (JNIEnv *env, jobject _this) 
65 {
66     INIT_FUNCTION;
67     int res = 0;
68
69     GET_INPUT_THREAD ;
70
71     res = libvlc_get_fullscreen( input, &exception );
72
73     libvlc_media_instance_release(input);
74     CHECK_EXCEPTION ;
75     
76     return res;
77 }
78
79 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getHeight (JNIEnv *env, jobject _this) 
80 {
81     INIT_FUNCTION;
82     int res = 0;
83
84     GET_INPUT_THREAD ;
85
86     res = libvlc_video_get_height( input, &exception );
87
88     libvlc_media_instance_release(input);
89     CHECK_EXCEPTION ;
90
91     return res;
92 }
93
94 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getWidth (JNIEnv *env, jobject _this) 
95 {
96     INIT_FUNCTION;
97     int res = 0;
98
99     GET_INPUT_THREAD ;
100
101     res = libvlc_video_get_width( input, &exception );
102
103     libvlc_media_instance_release(input);
104     CHECK_EXCEPTION ;
105
106     return res;
107 }
108
109 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1getSnapshot (JNIEnv *env, jobject _this, jstring filepath, jint width, jint height) 
110 {
111     INIT_FUNCTION;
112     
113     const char* psz_filepath  = env->GetStringUTFChars( filepath, 0 );
114
115     GET_INPUT_THREAD ;
116
117     libvlc_video_take_snapshot( input, (char *) psz_filepath,(unsigned int) width,(unsigned int) height, &exception );
118
119     libvlc_media_instance_release(input);
120     CHECK_EXCEPTION ;
121     
122     if (psz_filepath != NULL) {
123         env->ReleaseStringUTFChars( filepath, psz_filepath );
124     }
125     
126 }
127
128 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1destroyVideo (JNIEnv *env, jobject _this) 
129 {
130     INIT_FUNCTION ;
131      
132     GET_INPUT_THREAD ;
133
134     libvlc_video_destroy( input, &exception );
135
136     libvlc_media_instance_release(input);
137     CHECK_EXCEPTION;
138 }
139
140 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, jobject _this, jobject canvas) 
141 {
142     INIT_FUNCTION ;
143     
144     GET_INPUT_THREAD ;
145
146     libvlc_drawable_t drawable;
147
148     JAWT awt;
149     JAWT_DrawingSurface* ds;
150     JAWT_DrawingSurfaceInfo* dsi;
151 #ifdef WIN32
152     JAWT_Win32DrawingSurfaceInfo* dsi_win;
153 #else
154     JAWT_X11DrawingSurfaceInfo* dsi_x11;
155     GC gc;  
156 #endif    
157     jint lock;
158     
159     /* Get the AWT */
160     awt.version = JAWT_VERSION_1_3;
161     if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
162         printf("AWT Not found\n");
163         libvlc_media_instance_release(input);
164         return;
165     }
166
167     /* Get the drawing surface */
168     ds = awt.GetDrawingSurface(env, canvas);
169     if (ds == NULL) {
170         printf("NULL drawing surface\n");
171         libvlc_media_instance_release(input);
172         return;
173     }
174
175     /* Lock the drawing surface */
176     lock = ds->Lock(ds);
177     if((lock & JAWT_LOCK_ERROR) != 0) {
178         printf("Error locking surface\n");
179         awt.FreeDrawingSurface(ds);
180         libvlc_media_instance_release(input);
181         return;
182     }
183
184     /* Get the drawing surface info */
185     dsi = ds->GetDrawingSurfaceInfo(ds);
186     if (dsi == NULL) {
187         printf("Error getting surface info\n");
188         ds->Unlock(ds);
189         awt.FreeDrawingSurface(ds);
190         libvlc_media_instance_release(input);
191         return;
192     }
193
194     
195 #ifdef WIN32
196     /* Get the platform-specific drawing info */
197     dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
198     drawable = reinterpret_cast<int>(dsi_win->hwnd);
199
200     libvlc_video_set_parent((libvlc_instance_t *) instance, drawable, &exception );
201     libvlc_media_instance_release(input);
202
203     CHECK_EXCEPTION ;
204     
205 #else // UNIX
206     /* Get the platform-specific drawing info */
207
208     dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
209
210     /* Now paint */
211     gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
212     XSetBackground(dsi_x11->display, gc, 0);
213
214     /* and reparent */
215     drawable = dsi_x11->drawable;
216     libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
217
218     CHECK_EXCEPTION ;
219
220     XFreeGC(dsi_x11->display, gc);
221
222 #endif
223   /* Free the drawing surface info */
224   ds->FreeDrawingSurfaceInfo(dsi);
225
226   /* Unlock the drawing surface */
227   ds->Unlock(ds);
228
229   /* Free the drawing surface */
230   awt.FreeDrawingSurface(ds);
231 }
232
233 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1paint (JNIEnv *env, jobject _this, jobject canvas, jobject graphics)
234 {
235     INIT_FUNCTION ;
236     
237     libvlc_drawable_t drawable;
238
239     JAWT awt;
240     JAWT_DrawingSurface* ds;
241     JAWT_DrawingSurfaceInfo* dsi;
242 #ifdef WIN32
243     JAWT_Win32DrawingSurfaceInfo* dsi_win;
244 #else
245     JAWT_X11DrawingSurfaceInfo* dsi_x11;
246     GC gc;  
247 #endif    
248     jint lock;
249     
250     /* Get the AWT */
251     awt.version = JAWT_VERSION_1_3;
252     if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
253         printf("AWT Not found\n");
254         return;
255     }
256
257     /* Get the drawing surface */
258     ds = awt.GetDrawingSurface(env, canvas);
259     if (ds == NULL) {
260         printf("NULL drawing surface\n");
261         return;
262     }
263
264     /* Lock the drawing surface */
265     lock = ds->Lock(ds);
266     if((lock & JAWT_LOCK_ERROR) != 0) {
267         printf("Error locking surface\n");
268         awt.FreeDrawingSurface(ds);
269         return;
270     }
271
272     /* Get the drawing surface info */
273     dsi = ds->GetDrawingSurfaceInfo(ds);
274     if (dsi == NULL) {
275         printf("Error getting surface info\n");
276         ds->Unlock(ds);
277         awt.FreeDrawingSurface(ds);
278         return;
279     }
280
281     
282 #ifdef WIN32
283     /* Get the platform-specific drawing info */
284     dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
285     drawable = reinterpret_cast<int>(dsi_win->hwnd);
286
287     libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
288
289     CHECK_EXCEPTION ;
290     
291 #else // UNIX
292     /* Get the platform-specific drawing info */
293
294     dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
295
296     /* Now paint */
297     gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
298     XSetBackground(dsi_x11->display, gc, 0);
299
300     /* and reparent */
301     drawable = dsi_x11->drawable;
302     libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
303
304     CHECK_EXCEPTION ;
305
306     XFreeGC(dsi_x11->display, gc);
307
308 #endif
309   /* Free the drawing surface info */
310   ds->FreeDrawingSurfaceInfo(dsi);
311
312   /* Unlock the drawing surface */
313   ds->Unlock(ds);
314
315   /* Free the drawing surface */
316   awt.FreeDrawingSurface(ds);
317 }
318
319
320
321 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setSize (JNIEnv *env, jobject _this, jint width, jint height) 
322 {
323     INIT_FUNCTION ;
324
325     GET_INPUT_THREAD ;
326     
327     libvlc_video_resize( input, width, height, &exception );
328
329     libvlc_media_instance_release(input);
330     CHECK_EXCEPTION ;
331 }