[Android] libvlc: Media: add constructor from fd
Thomas Guillem
git at videolan.org
Wed May 27 17:00:13 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed May 27 16:47:22 2015 +0200| [f7c8cd5f596fc0af6620dc9ea94d62d231f824a7] | committer: Thomas Guillem
libvlc: Media: add constructor from fd
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=f7c8cd5f596fc0af6620dc9ea94d62d231f824a7
---
libvlc/jni/libvlcjni-media.c | 27 +++++++++++++++++++++++++++
libvlc/jni/libvlcjni.c | 6 ++++++
libvlc/jni/utils.h | 4 ++++
libvlc/src/org/videolan/libvlc/Media.java | 15 +++++++++++++++
4 files changed, 52 insertions(+)
diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index ea2ac07..807ff20 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -201,6 +201,33 @@ Java_org_videolan_libvlc_Media_nativeNewFromLocation(JNIEnv *env, jobject thiz,
}
void
+Java_org_videolan_libvlc_Media_nativeNewFromFd(JNIEnv *env, jobject thiz,
+ jobject libVlc, jobject jfd)
+{
+ vlcjni_object *p_obj;
+ int fd = (*env)->GetIntField(env, jfd, fields.FileDescriptor.descriptorID);
+
+ if ((*env)->ExceptionOccurred(env))
+ {
+ (*env)->ExceptionClear(env);
+ fd = -1;
+ }
+ if (fd == -1)
+ {
+ throw_IllegalArgumentException(env, "fd invalid");
+ return;
+ }
+
+ p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
+ if (!p_obj)
+ return;
+
+ p_obj->u.p_m = libvlc_media_new_fd(p_obj->p_libvlc, fd);
+
+ Media_nativeNewCommon(env, thiz, p_obj);
+}
+
+void
Java_org_videolan_libvlc_Media_nativeNewFromMediaList(JNIEnv *env, jobject thiz,
jobject ml, jint index)
{
diff --git a/libvlc/jni/libvlcjni.c b/libvlc/jni/libvlcjni.c
index ba2cbf1..b26bec6 100644
--- a/libvlc/jni/libvlcjni.c
+++ b/libvlc/jni/libvlcjni.c
@@ -176,6 +176,12 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
"java/lang/IllegalArgumentException", true);
GET_CLASS(fields.String.clazz,
"java/lang/String", true);
+ GET_CLASS(fields.FileDescriptor.clazz,
+ "java/io/FileDescriptor", true);
+ GET_ID(GetFieldID,
+ fields.FileDescriptor.descriptorID,
+ fields.FileDescriptor.clazz,
+ "descriptor", "I");
GET_CLASS(fields.LibVLC.clazz,
"org/videolan/libvlc/LibVLC", true);
GET_CLASS(fields.VLCObject.clazz,
diff --git a/libvlc/jni/utils.h b/libvlc/jni/utils.h
index 3df0a7b..585279c 100644
--- a/libvlc/jni/utils.h
+++ b/libvlc/jni/utils.h
@@ -38,6 +38,10 @@ struct fields {
} String;
struct {
jclass clazz;
+ jfieldID descriptorID;
+ } FileDescriptor;
+ struct {
+ jclass clazz;
jmethodID onNativeCrashID;
} LibVLC;
struct {
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index 63a15f0..9903580 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -22,6 +22,8 @@ package org.videolan.libvlc;
import android.net.Uri;
+import java.io.FileDescriptor;
+
public final class Media extends VLCObject {
private final static String TAG = "LibVLC/Media";
@@ -248,6 +250,18 @@ public final class Media extends VLCObject {
}
/**
+ * Create a Media from libVLC and a FileDescriptor
+ *
+ * @param libVLC
+ * @param fd
+ */
+ public Media(LibVLC libVLC, FileDescriptor fd) {
+ nativeNewFromFD(libVLC, fd);
+ mMrl = nativeGetMrl();
+ mType = nativeGetType();
+ }
+
+ /**
*
* @param ml Should not be released
* @param index
@@ -444,6 +458,7 @@ public final class Media extends VLCObject {
/* JNI */
private native void nativeNewFromPath(LibVLC libVLC, String path);
private native void nativeNewFromLocation(LibVLC libVLC, String location);
+ private native void nativeNewFromFD(LibVLC libVLC, FileDescriptor fd);
private native void nativeNewFromMediaList(MediaList ml, int index);
private native void nativeRelease();
private native boolean nativeParseAsync(int flags);
More information about the Android
mailing list