diff options
Diffstat (limited to 'video/out/android_common.c')
-rw-r--r-- | video/out/android_common.c | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/video/out/android_common.c b/video/out/android_common.c index f333d56325..27e7b5bb5b 100644 --- a/video/out/android_common.c +++ b/video/out/android_common.c @@ -20,29 +20,16 @@ #include "android_common.h" #include "common/msg.h" +#include "misc/jni.h" #include "options/m_config.h" #include "vo.h" -struct android_opts { - struct m_geometry surface_size; -}; - -#define OPT_BASE_STRUCT struct android_opts -const struct m_sub_options android_conf = { - .opts = (const struct m_option[]) { - OPT_SIZE_BOX("android-surface-size", surface_size, UPDATE_VO_RESIZE), - {0} - }, - .size = sizeof(struct android_opts), -}; - - struct vo_android_state { struct mp_log *log; ANativeWindow *native_window; }; -int vo_android_init(struct vo *vo) +bool vo_android_init(struct vo *vo) { vo->android = talloc_zero(vo, struct vo_android_state); struct vo_android_state *ctx = vo->android; @@ -51,24 +38,25 @@ int vo_android_init(struct vo *vo) .log = mp_log_new(ctx, vo->log, "android"), }; - jobject surface = (jobject)(intptr_t)vo->opts->WinID; - JavaVM *vm = (JavaVM *)av_jni_get_java_vm(NULL); - JNIEnv *env; - int ret = (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6); - if (ret == JNI_EDETACHED) { - if ((*vm)->AttachCurrentThread(vm, &env, NULL) != 0) { - MP_FATAL(ctx, "Could not attach Java VM.\n"); - goto fail; - } + JNIEnv *env = MP_JNI_GET_ENV(ctx); + if (!env) { + MP_FATAL(ctx, "Could not attach java VM.\n"); + goto fail; } + + assert(vo->opts->WinID != 0 && vo->opts->WinID != -1); + jobject surface = (jobject)(intptr_t)vo->opts->WinID; ctx->native_window = ANativeWindow_fromSurface(env, surface); - (*vm)->DetachCurrentThread(vm); + if (!ctx->native_window) { + MP_FATAL(ctx, "Failed to create ANativeWindow\n"); + goto fail; + } - return 1; + return true; fail: talloc_free(ctx); vo->android = NULL; - return 0; + return false; } void vo_android_uninit(struct vo *vo) @@ -93,16 +81,14 @@ ANativeWindow *vo_android_native_window(struct vo *vo) bool vo_android_surface_size(struct vo *vo, int *out_w, int *out_h) { struct vo_android_state *ctx = vo->android; - void *tmp = talloc_new(NULL); - struct android_opts *opts = mp_get_config_group(tmp, vo->global, &android_conf); - int w = opts->surface_size.w, h = opts->surface_size.h; + int w = vo->opts->android_surface_size.w, + h = vo->opts->android_surface_size.h; if (!w) w = ANativeWindow_getWidth(ctx->native_window); if (!h) h = ANativeWindow_getHeight(ctx->native_window); - talloc_free(tmp); if (w <= 0 || h <= 0) { MP_ERR(ctx, "Failed to get height and width.\n"); return false; |