[Android] libvlcjni: throw exception from VLCJniObject_new*
Thomas Guillem
git at videolan.org
Wed May 27 17:00:12 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed May 27 14:56:17 2015 +0200| [91ed357ef9dfe57c125e81a0fb88cd94f11deb76] | committer: Thomas Guillem
libvlcjni: throw exception from VLCJniObject_new*
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=91ed357ef9dfe57c125e81a0fb88cd94f11deb76
---
libvlc/jni/libvlcjni-media.c | 11 ++--------
libvlc/jni/libvlcjni-mediadiscoverer.c | 5 +----
libvlc/jni/libvlcjni-medialist.c | 21 +++---------------
libvlc/jni/libvlcjni-mediaplayer.c | 8 +------
libvlc/jni/libvlcjni-vlcobject.c | 37 +++++++++++++++-----------------
libvlc/jni/libvlcjni-vlcobject.h | 6 ++----
6 files changed, 26 insertions(+), 62 deletions(-)
diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index fc42ff5..163935e 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -163,7 +163,6 @@ Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
{
vlcjni_object *p_obj;
const char* p_mrl;
- const char *p_error;
if (!jmrl || !(p_mrl = (*env)->GetStringUTFChars(env, jmrl, 0)))
{
@@ -171,12 +170,10 @@ Java_org_videolan_libvlc_Media_nativeNewFromMrl(JNIEnv *env, jobject thiz,
return;
}
- p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc, &p_error);
-
+ p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
if (!p_obj)
{
(*env)->ReleaseStringUTFChars(env, jmrl, p_mrl);
- throw_IllegalStateException(env, p_error);
return;
}
@@ -195,16 +192,12 @@ Java_org_videolan_libvlc_Media_nativeNewFromMediaList(JNIEnv *env, jobject thiz,
jobject ml, jint index)
{
vlcjni_object *p_obj;
- const char *p_error;
GET_INSTANCE(p_ml_obj)
- p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_ml_obj->p_libvlc, &p_error);
+ p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_ml_obj->p_libvlc);
if (!p_obj)
- {
- throw_IllegalStateException(env, p_error);
return;
- }
p_obj->u.p_m = MediaList_get_media(p_ml_obj, index);
diff --git a/libvlc/jni/libvlcjni-mediadiscoverer.c b/libvlc/jni/libvlcjni-mediadiscoverer.c
index a8c7625..da8fb2e 100644
--- a/libvlc/jni/libvlcjni-mediadiscoverer.c
+++ b/libvlc/jni/libvlcjni-mediadiscoverer.c
@@ -27,7 +27,6 @@ Java_org_videolan_libvlc_MediaDiscoverer_nativeNew(JNIEnv *env,
{
vlcjni_object *p_obj;
const char* p_name;
- const char *p_error;
if (!jname || !(p_name = (*env)->GetStringUTFChars(env, jname, 0)))
{
@@ -35,12 +34,10 @@ Java_org_videolan_libvlc_MediaDiscoverer_nativeNew(JNIEnv *env,
return;
}
- p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc, &p_error);
-
+ p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
if (!p_obj)
{
(*env)->ReleaseStringUTFChars(env, jname, p_name);
- throw_IllegalStateException(env, p_error);
return;
}
diff --git a/libvlc/jni/libvlcjni-medialist.c b/libvlc/jni/libvlcjni-medialist.c
index af7e81b..21d3874 100644
--- a/libvlc/jni/libvlcjni-medialist.c
+++ b/libvlc/jni/libvlcjni-medialist.c
@@ -163,16 +163,9 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromLibVlc(JNIEnv *env,
jobject thiz,
jobject libVlc)
{
- const char *p_error;
-
- vlcjni_object *p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc,
- &p_error);
-
+ vlcjni_object *p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libVlc);
if (!p_obj)
- {
- throw_IllegalStateException(env, p_error);
return;
- }
p_obj->u.p_ml = libvlc_media_list_new(p_obj->p_libvlc);
@@ -185,16 +178,12 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromMediaDiscoverer(JNIEnv *env,
jobject md)
{
vlcjni_object *p_obj;
- const char *p_error;
GET_INSTANCE(p_md_obj)
- p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_md_obj->p_libvlc, &p_error);
+ p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_md_obj->p_libvlc);
if (!p_obj)
- {
- throw_IllegalStateException(env, p_error);
return;
- }
p_obj->u.p_ml = libvlc_media_discoverer_media_list(p_md_obj->u.p_md);
@@ -207,16 +196,12 @@ Java_org_videolan_libvlc_MediaList_nativeNewFromMedia(JNIEnv *env,
jobject m)
{
vlcjni_object *p_obj;
- const char *p_error;
GET_INSTANCE(p_m_obj)
- p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_m_obj->p_libvlc, &p_error);
+ p_obj = VLCJniObject_newFromLibVlc(env, thiz, p_m_obj->p_libvlc);
if (!p_obj)
- {
- throw_IllegalStateException(env, p_error);
return;
- }
p_obj->u.p_ml = libvlc_media_subitems(p_m_obj->u.p_m);
diff --git a/libvlc/jni/libvlcjni-mediaplayer.c b/libvlc/jni/libvlcjni-mediaplayer.c
index d5fa9ae..c9ed0d9 100644
--- a/libvlc/jni/libvlcjni-mediaplayer.c
+++ b/libvlc/jni/libvlcjni-mediaplayer.c
@@ -123,15 +123,9 @@ Java_org_videolan_libvlc_MediaPlayer_nativeNewFromLibVlc(JNIEnv *env,
jobject thiz,
jobject libvlc)
{
- const char *p_error;
- vlcjni_object *p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libvlc,
- &p_error);
-
+ vlcjni_object *p_obj = VLCJniObject_newFromJavaLibVlc(env, thiz, libvlc);
if (!p_obj)
- {
- throw_IllegalStateException(env, p_error);
return;
- }
/* Create a media player playing environment */
p_obj->u.p_mp = libvlc_media_player_new(p_obj->p_libvlc);
diff --git a/libvlc/jni/libvlcjni-vlcobject.c b/libvlc/jni/libvlcjni-vlcobject.c
index e576d8a..d96d562 100644
--- a/libvlc/jni/libvlcjni-vlcobject.c
+++ b/libvlc/jni/libvlcjni-vlcobject.c
@@ -55,30 +55,29 @@ VLCJniObject_setInstance(JNIEnv *env, jobject thiz, vlcjni_object *p_obj)
vlcjni_object *
VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
- libvlc_instance_t *p_libvlc,
- const char **pp_error)
+ libvlc_instance_t *p_libvlc)
{
- vlcjni_object *p_obj;
+ vlcjni_object *p_obj = NULL;
libvlc_event_manager_t *ev;
+ const char *p_error;
- p_obj = VLCJniObject_getInstance(env, thiz);
- if (p_obj)
+ if (VLCJniObject_getInstance(env, thiz))
{
- *pp_error = "VLCObject.mInstanceID already exists";
- return NULL;
+ p_error = "VLCObject.mInstanceID already exists";
+ goto error;
}
p_obj = calloc(1, sizeof(vlcjni_object));
if (!p_obj)
{
- *pp_error = "vlcjni_object calloc failed";
+ p_error = "vlcjni_object calloc failed";
goto error;
}
p_obj->p_owner = calloc(1, sizeof(vlcjni_object_owner));
if (!p_obj->p_owner)
{
- *pp_error = "vlcjni_object_owner calloc failed";
+ p_error = "vlcjni_object_owner calloc failed";
goto error;
}
@@ -98,34 +97,32 @@ VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
p_obj->p_owner->weak = (*env)->NewWeakGlobalRef(env, thiz);
if (!p_obj->p_owner->weak && !p_obj->p_owner->weakCompat)
{
- *pp_error = "No VLCObject weak reference";
+ p_error = "No VLCObject weak reference";
goto error;
}
VLCJniObject_setInstance(env, thiz, p_obj);
-
- *pp_error = NULL;
return p_obj;
error:
- VLCJniObject_release(env, thiz, p_obj);
+ if (p_obj)
+ VLCJniObject_release(env, thiz, p_obj);
+ throw_IllegalStateException(env, p_error);
return NULL;
}
vlcjni_object *
-VLCJniObject_newFromJavaLibVlc(JNIEnv *env, jobject thiz,
- jobject libVlc, const char **pp_error)
+VLCJniObject_newFromJavaLibVlc(JNIEnv *env, jobject thiz, jobject libVlc)
{
libvlc_instance_t *p_libvlc = getLibVlcInstance(env, libVlc);
if (!p_libvlc)
{
- if (libVlc)
- *pp_error = "Can't get mLibVlcInstance from libVlc";
- else
- *pp_error = "libVlc is NULL";
+ const char *p_error = libVlc ? "Can't get mLibVlcInstance from libVlc"
+ : "libVlc is NULL";
+ throw_IllegalStateException(env, p_error);
return NULL;
}
- return VLCJniObject_newFromLibVlc(env, thiz, p_libvlc, pp_error);
+ return VLCJniObject_newFromLibVlc(env, thiz, p_libvlc);
}
void
diff --git a/libvlc/jni/libvlcjni-vlcobject.h b/libvlc/jni/libvlcjni-vlcobject.h
index c4ca517..57e63d1 100644
--- a/libvlc/jni/libvlcjni-vlcobject.h
+++ b/libvlc/jni/libvlcjni-vlcobject.h
@@ -76,12 +76,10 @@ typedef bool (*event_cb)(vlcjni_object *p_obj, const libvlc_event_t *p_ev,
vlcjni_object *VLCJniObject_getInstance(JNIEnv *env, jobject thiz);
vlcjni_object *VLCJniObject_newFromJavaLibVlc(JNIEnv *env, jobject thiz,
- jobject libVlc,
- const char **pp_error);
+ jobject libVlc);
vlcjni_object *VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
- libvlc_instance_t *p_libvlc,
- const char **pp_error);
+ libvlc_instance_t *p_libvlc);
void VLCJniObject_release(JNIEnv *env, jobject thiz, vlcjni_object *p_obj);
More information about the Android
mailing list