Commit cf95a708 authored by Thomas Guillem's avatar Thomas Guillem

jni: uniformize how to fetch libvlc_instance_t

parent 7ccc817d
......@@ -75,18 +75,18 @@ static int expand_media_internal(JNIEnv *env, libvlc_instance_t* p_instance, job
}
}
jint Java_org_videolan_libvlc_MediaList_expandMedia(JNIEnv *env, jobject thiz, jobject libvlcJava, jint position, jobject children) {
jint Java_org_videolan_libvlc_expandMedia(JNIEnv *env, jobject thiz, jint position, jobject children) {
return (jint)expand_media_internal(env,
(libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"),
getLibVlcInstance(env, thiz),
children,
(libvlc_media_t*)libvlc_media_player_get_media((libvlc_media_player_t*)(intptr_t)getLong(env, libvlcJava, "mInternalMediaPlayerInstance"))
);
(libvlc_media_t*)libvlc_media_player_get_media(getMediaPlayer(env, thiz)));
}
void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz, jobject libvlcJava, jstring mrl, jobject items) {
void Java_org_videolan_libvlc_loadPlaylist(JNIEnv *env, jobject thiz, jstring mrl, jobject items) {
const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL);
libvlc_instance_t *p_instance = getLibVlcInstance(env, thiz);
libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), p_mrl);
libvlc_media_t *p_md = libvlc_media_new_location(p_instance, p_mrl);
libvlc_media_add_option(p_md, ":demux=playlist,none");
libvlc_media_add_option(p_md, ":run-time=1");
......@@ -96,7 +96,7 @@ void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz,
monitor->stopped = false;
pthread_mutex_lock(&monitor->doneMutex);
libvlc_media_player_t* p_mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"));
libvlc_media_player_t* p_mp = libvlc_media_player_new(p_instance);
libvlc_media_player_set_video_title_display(p_mp, libvlc_position_disable, 0);
libvlc_event_manager_t* ev = libvlc_media_player_event_manager(p_mp);
libvlc_event_attach(ev, libvlc_MediaPlayerEndReached, stopped_callback, monitor);
......@@ -118,7 +118,7 @@ void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz,
libvlc_media_player_release(p_mp);
expand_media_internal(env, (libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), items, p_md);
expand_media_internal(env, p_instance, items, p_md);
(*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
}
......@@ -45,10 +45,10 @@ static void length_changed_callback(const libvlc_event_t *ev, void *data)
}
jboolean Java_org_videolan_libvlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz,
jlong i_instance, jstring fileLocation)
jstring fileLocation)
{
/* Create a new item and assign it to the media player. */
libvlc_media_t *p_m = new_media(i_instance, env, thiz, fileLocation, false, false);
libvlc_media_t *p_m = new_media(env, thiz, fileLocation, false, false);
if (p_m == NULL)
{
LOGE("Could not create the media!");
......@@ -183,10 +183,10 @@ jobjectArray read_track_info_internal(JNIEnv *env, jobject thiz, libvlc_media_t*
}
jobjectArray Java_org_videolan_libvlc_LibVLC_readTracksInfo(JNIEnv *env, jobject thiz,
jlong instance, jstring mrl)
jstring mrl)
{
/* Create a new item and assign it to the media player. */
libvlc_media_t *p_m = new_media(instance, env, thiz, mrl, false, false);
libvlc_media_t *p_m = new_media(env, thiz, mrl, false, false);
if (p_m == NULL)
{
LOGE("Could not create the media!");
......
......@@ -72,9 +72,9 @@ static void add_media_options(libvlc_media_t *p_md, JNIEnv *env, jobjectArray me
}
}
libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo)
libvlc_media_t *new_media(JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo)
{
libvlc_instance_t *libvlc = (libvlc_instance_t*)(intptr_t)instance;
libvlc_instance_t *libvlc = getLibVlcInstance(env, thiz);
jboolean isCopy;
const char *psz_location = (*env)->GetStringUTFChars(env, fileLocation, &isCopy);
libvlc_media_t *p_md = libvlc_media_new_location(libvlc, psz_location);
......@@ -96,11 +96,17 @@ libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fil
return p_md;
}
libvlc_instance_t *getLibVlcInstance(JNIEnv *env, jobject thiz)
{
return (libvlc_instance_t*)(intptr_t)getLong(env, thiz, "mLibVlcInstance");
}
libvlc_media_player_t *getMediaPlayer(JNIEnv *env, jobject thiz)
{
return (libvlc_media_player_t*)(intptr_t)getLong(env, thiz, "mInternalMediaPlayerInstance");
}
static void releaseMediaPlayer(JNIEnv *env, jobject thiz)
{
libvlc_media_player_t* p_mp = getMediaPlayer(env, thiz);
......@@ -399,14 +405,16 @@ void Java_org_videolan_libvlc_LibVLC_setEventHandler(JNIEnv *env, jobject thiz,
eventHandlerInstance = getEventHandlerReference(env, thiz, eventHandler);
}
void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong instance,
void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz,
jstring mrl, jobjectArray mediaOptions)
{
/* Release previous media player, if any */
releaseMediaPlayer(env, thiz);
libvlc_instance_t *p_instance = getLibVlcInstance(env, thiz);
/* Create a media player playing environment */
libvlc_media_player_t *mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)instance);
libvlc_media_player_t *mp = libvlc_media_player_new(p_instance);
libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0);
jobject myJavaLibVLC = (*env)->NewGlobalRef(env, thiz);
......@@ -444,7 +452,7 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong in
const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);
libvlc_media_t* p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)instance, p_mrl);
libvlc_media_t* p_md = libvlc_media_new_location(p_instance, p_mrl);
/* media options */
if (mediaOptions != NULL)
add_media_options(p_md, env, mediaOptions);
......
......@@ -139,10 +139,10 @@ static void thumbnailer_unlock(void *opaque, void *picture, void *const *pixels)
* return null if the thumbail generation failed.
**/
jbyteArray Java_org_videolan_libvlc_LibVLC_getThumbnail(JNIEnv *env, jobject thiz,
jlong instance, jstring filePath,
jstring filePath,
const jint frameWidth, const jint frameHeight)
{
libvlc_instance_t *libvlc = (libvlc_instance_t *)(intptr_t)instance;
libvlc_instance_t *libvlc = getLibVlcInstance(env, thiz);
jbyteArray byteArray = NULL;
/* Create the thumbnailer data structure */
......@@ -161,7 +161,7 @@ jbyteArray Java_org_videolan_libvlc_LibVLC_getThumbnail(JNIEnv *env, jobject thi
libvlc_media_player_t *mp = libvlc_media_player_new(libvlc);
libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0);
libvlc_media_t *m = new_media(instance, env, thiz, filePath, true, false);
libvlc_media_t *m = new_media(env, thiz, filePath, true, false);
if (m == NULL)
{
LOGE("Could not create the media to play!");
......
......@@ -21,7 +21,9 @@
#ifndef LIBVLCJNI_UTILS_H
#define LIBVLCJNI_UTILS_H
libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo);
libvlc_media_t *new_media(JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo);
libvlc_instance_t *getLibVlcInstance(JNIEnv *env, jobject thiz);
libvlc_media_player_t *getMediaPlayer(JNIEnv *env, jobject thiz);
......
......@@ -600,7 +600,7 @@ public class LibVLC {
return;
String[] options = mMediaList.getMediaOptions(position);
mInternalMediaPlayerIndex = position;
playMRL(mLibVlcInstance, mrl, options);
playMRL(mrl, options);
}
/**
......@@ -612,25 +612,7 @@ public class LibVLC {
// index=-1 will return options from libvlc instance without relying on MediaList
String[] options = mMediaList.getMediaOptions(-1);
mInternalMediaPlayerIndex = 0;
playMRL(mLibVlcInstance, mrl, options);
}
public TrackInfo[] readTracksInfo(String mrl) {
return readTracksInfo(mLibVlcInstance, mrl);
}
/**
* Get a media thumbnail.
*/
public byte[] getThumbnail(String mrl, int i_width, int i_height) {
return getThumbnail(mLibVlcInstance, mrl, i_width, i_height);
}
/**
* Return true if there is a video track in the file
*/
public boolean hasVideoTrack(String mrl) throws java.io.IOException {
return hasVideoTrack(mLibVlcInstance, mrl);
playMRL(mrl, options);
}
/**
......@@ -677,7 +659,7 @@ public class LibVLC {
/**
* Play an mrl
*/
private native void playMRL(long instance, String mrl, String[] mediaOptions);
private native void playMRL(String mrl, String[] mediaOptions);
/**
* Returns true if any media is playing
......@@ -773,14 +755,14 @@ public class LibVLC {
* Get a media thumbnail.
* @return a bytearray with the RGBA thumbnail data inside.
*/
private native byte[] getThumbnail(long instance, String mrl, int i_width, int i_height);
public native byte[] getThumbnail(String mrl, int i_width, int i_height);
/**
* Return true if there is a video track in the file
*/
private native boolean hasVideoTrack(long instance, String mrl);
public native boolean hasVideoTrack(String mrl) throws java.io.IOException;
private native TrackInfo[] readTracksInfo(long instance, String mrl);
public native TrackInfo[] readTracksInfo(String mrl);
public native TrackInfo[] readTracksInfoInternal();
......@@ -884,4 +866,8 @@ public class LibVLC {
public native String getMeta(int meta);
public native int setWindowSize(int width, int height);
/* MediaList */
protected native void loadPlaylist(String mrl, ArrayList<String> items);
protected native int expandMedia(int position, ArrayList<String> children);
}
......@@ -103,7 +103,7 @@ public class MediaList {
*/
public int expandMedia(int position) {
ArrayList<String> children = new ArrayList<String>();
int ret = expandMedia(mLibVLC, position, children);
int ret = mLibVLC.expandMedia(position, children);
if(ret == 0) {
mEventHandler.callback(EventHandler.CustomMediaListExpanding, new Bundle());
this.remove(position);
......@@ -114,17 +114,15 @@ public class MediaList {
}
return ret;
}
private native int expandMedia(LibVLC libvlc_instance, int position, ArrayList<String> children);
public void loadPlaylist(String mrl) {
ArrayList<String> items = new ArrayList<String>();
loadPlaylist(mLibVLC, mrl, items);
mLibVLC.loadPlaylist(mrl, items);
this.clear();
for(String item : items) {
this.add(item);
}
}
private native void loadPlaylist(LibVLC libvlc_instance, String mrl, ArrayList<String> items);
public void insert(int position, String mrl) {
insert(position, new Media(mLibVLC, mrl));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment