1 /*****************************************************************************
2 * video-jni.cc: JNI native video functions for VLC Java Bindings
3 *****************************************************************************
4 * Copyright (C) 1998-2006 the VideoLAN team
6 * Authors: Filippo Carone <filippo@carone.org>
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.
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.
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 *****************************************************************************/
30 #include <vlc/libvlc.h>
33 /* JVLC internal imports, generated by gcjh */
34 #include "../includes/Video.h"
39 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1toggleFullscreen (JNIEnv *env, jobject _this)
45 libvlc_toggle_fullscreen( input, &exception );
47 libvlc_media_instance_release(input);
52 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setFullscreen (JNIEnv *env, jobject _this, jboolean value)
58 libvlc_set_fullscreen( input, value, &exception );
60 libvlc_media_instance_release(input);
64 JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Video__1getFullscreen (JNIEnv *env, jobject _this)
71 res = libvlc_get_fullscreen( input, &exception );
73 libvlc_media_instance_release(input);
79 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getHeight (JNIEnv *env, jobject _this)
86 res = libvlc_video_get_height( input, &exception );
88 libvlc_media_instance_release(input);
94 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getWidth (JNIEnv *env, jobject _this)
101 res = libvlc_video_get_width( input, &exception );
103 libvlc_media_instance_release(input);
109 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1getSnapshot (JNIEnv *env, jobject _this, jstring filepath, jint width, jint height)
113 const char* psz_filepath = env->GetStringUTFChars( filepath, 0 );
117 libvlc_video_take_snapshot( input, (char *) psz_filepath,(unsigned int) width,(unsigned int) height, &exception );
119 libvlc_media_instance_release(input);
122 if (psz_filepath != NULL) {
123 env->ReleaseStringUTFChars( filepath, psz_filepath );
128 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1destroyVideo (JNIEnv *env, jobject _this)
134 libvlc_video_destroy( input, &exception );
136 libvlc_media_instance_release(input);
140 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, jobject _this, jobject canvas)
146 libvlc_drawable_t drawable;
149 JAWT_DrawingSurface* ds;
150 JAWT_DrawingSurfaceInfo* dsi;
152 JAWT_Win32DrawingSurfaceInfo* dsi_win;
154 JAWT_X11DrawingSurfaceInfo* dsi_x11;
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);
167 /* Get the drawing surface */
168 ds = awt.GetDrawingSurface(env, canvas);
170 printf("NULL drawing surface\n");
171 libvlc_media_instance_release(input);
175 /* Lock the drawing surface */
177 if((lock & JAWT_LOCK_ERROR) != 0) {
178 printf("Error locking surface\n");
179 awt.FreeDrawingSurface(ds);
180 libvlc_media_instance_release(input);
184 /* Get the drawing surface info */
185 dsi = ds->GetDrawingSurfaceInfo(ds);
187 printf("Error getting surface info\n");
189 awt.FreeDrawingSurface(ds);
190 libvlc_media_instance_release(input);
196 /* Get the platform-specific drawing info */
197 dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
198 drawable = reinterpret_cast<int>(dsi_win->hwnd);
200 libvlc_video_set_parent((libvlc_instance_t *) instance, drawable, &exception );
201 libvlc_media_instance_release(input);
206 /* Get the platform-specific drawing info */
208 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
211 gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
212 XSetBackground(dsi_x11->display, gc, 0);
215 drawable = dsi_x11->drawable;
216 libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
220 XFreeGC(dsi_x11->display, gc);
223 /* Free the drawing surface info */
224 ds->FreeDrawingSurfaceInfo(dsi);
226 /* Unlock the drawing surface */
229 /* Free the drawing surface */
230 awt.FreeDrawingSurface(ds);
233 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1paint (JNIEnv *env, jobject _this, jobject canvas, jobject graphics)
237 libvlc_drawable_t drawable;
240 JAWT_DrawingSurface* ds;
241 JAWT_DrawingSurfaceInfo* dsi;
243 JAWT_Win32DrawingSurfaceInfo* dsi_win;
245 JAWT_X11DrawingSurfaceInfo* dsi_x11;
251 awt.version = JAWT_VERSION_1_3;
252 if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
253 printf("AWT Not found\n");
257 /* Get the drawing surface */
258 ds = awt.GetDrawingSurface(env, canvas);
260 printf("NULL drawing surface\n");
264 /* Lock the drawing surface */
266 if((lock & JAWT_LOCK_ERROR) != 0) {
267 printf("Error locking surface\n");
268 awt.FreeDrawingSurface(ds);
272 /* Get the drawing surface info */
273 dsi = ds->GetDrawingSurfaceInfo(ds);
275 printf("Error getting surface info\n");
277 awt.FreeDrawingSurface(ds);
283 /* Get the platform-specific drawing info */
284 dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
285 drawable = reinterpret_cast<int>(dsi_win->hwnd);
287 libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
292 /* Get the platform-specific drawing info */
294 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
297 gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
298 XSetBackground(dsi_x11->display, gc, 0);
301 drawable = dsi_x11->drawable;
302 libvlc_video_set_parent( (libvlc_instance_t *) instance, drawable, &exception );
306 XFreeGC(dsi_x11->display, gc);
309 /* Free the drawing surface info */
310 ds->FreeDrawingSurfaceInfo(dsi);
312 /* Unlock the drawing surface */
315 /* Free the drawing surface */
316 awt.FreeDrawingSurface(ds);
321 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setSize (JNIEnv *env, jobject _this, jint width, jint height)
327 libvlc_video_resize( input, width, height, &exception );
329 libvlc_media_instance_release(input);