]> git.sesse.net Git - vlc/blob - bindings/java/src/video-jni.cc
Start splitting the various meta module types
[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
29 #include <vlc/libvlc.h>
30
31 /* JVLC internal imports, generated by gcjh */
32 #include "../includes/Video.h"
33
34 #include "utils.h"
35 #include <stdio.h>
36
37 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1toggleFullscreen (JNIEnv *env, jobject _this)
38 {
39     INIT_FUNCTION ;
40
41     GET_INPUT_THREAD ;
42     
43     libvlc_toggle_fullscreen( input, exception );
44
45     CHECK_EXCEPTION_FREE ;
46 }
47
48 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setFullscreen (JNIEnv *env, jobject _this, jboolean value) 
49 {
50     INIT_FUNCTION ;
51
52     GET_INPUT_THREAD ;
53
54     libvlc_set_fullscreen( input, value, exception );
55
56     CHECK_EXCEPTION_FREE ;
57 }
58
59 JNIEXPORT jboolean JNICALL Java_org_videolan_jvlc_Video__1getFullscreen (JNIEnv *env, jobject _this) 
60 {
61     INIT_FUNCTION;
62     int res = 0;
63
64     GET_INPUT_THREAD ;
65
66     res = libvlc_get_fullscreen( input, exception );
67
68     CHECK_EXCEPTION_FREE ;
69     
70     return res;
71 }
72
73 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getHeight (JNIEnv *env, jobject _this) 
74 {
75     INIT_FUNCTION;
76     int res = 0;
77
78     GET_INPUT_THREAD ;
79
80     res = libvlc_video_get_height( input, exception );
81
82     CHECK_EXCEPTION_FREE ;
83
84     return res;
85 }
86
87 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Video__1getWidth (JNIEnv *env, jobject _this) 
88 {
89     INIT_FUNCTION;
90     int res = 0;
91
92     GET_INPUT_THREAD ;
93
94     res = libvlc_video_get_width( input, exception );
95
96     CHECK_EXCEPTION_FREE ;
97
98     return res;
99 }
100
101 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1getSnapshot (JNIEnv *env, jobject _this, jstring filepath) 
102 {
103     INIT_FUNCTION;
104     
105     const char* psz_filepath  = env->GetStringUTFChars( filepath, 0 );
106
107     GET_INPUT_THREAD ;
108
109     libvlc_video_take_snapshot( input, (char *) psz_filepath, exception );
110
111     CHECK_EXCEPTION_FREE ;
112     
113     if (psz_filepath != NULL) {
114         env->ReleaseStringUTFChars( filepath, psz_filepath );
115     }
116     
117 }
118
119 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1destroyVideo (JNIEnv *env, jobject _this) 
120 {
121     INIT_FUNCTION ;
122      
123     GET_INPUT_THREAD ;
124
125     libvlc_video_destroy( input, exception );
126
127     CHECK_EXCEPTION_FREE;
128 }
129
130 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1reparent (JNIEnv *env, jobject _this, jobject canvas) 
131 {
132     INIT_FUNCTION ;
133     
134     GET_INPUT_THREAD ;
135
136     JAWT awt;
137     JAWT_DrawingSurface* ds;
138     JAWT_DrawingSurfaceInfo* dsi;
139 #ifdef WIN32
140     JAWT_Win32DrawingSurfaceInfo* dsi_win;
141 #else
142     JAWT_X11DrawingSurfaceInfo* dsi_x11;
143     GC gc;  
144 #endif    
145     jint lock;
146     
147     vlc_value_t value;
148
149     /* Get the AWT */
150     awt.version = JAWT_VERSION_1_3;
151     if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
152         printf("AWT Not found\n");
153         return;
154     }
155
156     /* Get the drawing surface */
157     ds = awt.GetDrawingSurface(env, canvas);
158     if (ds == NULL) {
159         printf("NULL drawing surface\n");
160         return;
161     }
162
163     /* Lock the drawing surface */
164     lock = ds->Lock(ds);
165     if((lock & JAWT_LOCK_ERROR) != 0) {
166         printf("Error locking surface\n");
167         awt.FreeDrawingSurface(ds);
168         return;
169     }
170
171     /* Get the drawing surface info */
172     dsi = ds->GetDrawingSurfaceInfo(ds);
173     if (dsi == NULL) {
174         printf("Error getting surface info\n");
175         ds->Unlock(ds);
176         awt.FreeDrawingSurface(ds);
177         return;
178     }
179
180     
181 #ifdef WIN32
182     /* Get the platform-specific drawing info */
183     dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
184
185     libvlc_video_reparent( input, dsi_win->hwnd, exception );
186
187     CHECK_EXCEPTION_FREE ;
188     
189     /* Now paint */
190     value.i_int = reinterpret_cast<int>(dsi_win->hwnd); 
191     VLC_VariableSet( 1, "drawable", value );
192
193 #else // UNIX
194     /* Get the platform-specific drawing info */
195
196     dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
197
198     /* Now paint */
199     gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
200     XSetBackground(dsi_x11->display, gc, 0);
201
202     /* and reparent */
203     libvlc_video_reparent( input, dsi_x11->drawable, exception );
204
205     CHECK_EXCEPTION_FREE ;
206
207     /* also update the drawable variable value */
208     value.i_int = dsi_x11->drawable;
209     VLC_VariableSet( 0, "drawable", value );
210     
211     XFreeGC(dsi_x11->display, gc);
212
213 #endif
214   /* Free the drawing surface info */
215   ds->FreeDrawingSurfaceInfo(dsi);
216
217   /* Unlock the drawing surface */
218   ds->Unlock(ds);
219
220   /* Free the drawing surface */
221   awt.FreeDrawingSurface(ds);
222 }
223
224 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Video__1setSize__II (JNIEnv *env, jobject _this, jint width, jint height) 
225 {
226     INIT_FUNCTION ;
227
228     GET_INPUT_THREAD ;
229     
230     libvlc_video_resize( input, width, height, exception );
231
232     CHECK_EXCEPTION_FREE ;
233 }