diff options
Diffstat (limited to 'video/out/hwdec/hwdec_aimagereader.c')
-rw-r--r-- | video/out/hwdec/hwdec_aimagereader.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/video/out/hwdec/hwdec_aimagereader.c b/video/out/hwdec/hwdec_aimagereader.c index 10f1c85687..1aa92eea4a 100644 --- a/video/out/hwdec/hwdec_aimagereader.c +++ b/video/out/hwdec/hwdec_aimagereader.c @@ -18,7 +18,6 @@ */ #include <assert.h> -#include <pthread.h> #include <dlfcn.h> #include <EGL/egl.h> #include <media/NdkImageReader.h> @@ -28,6 +27,7 @@ #include <libavutil/hwcontext_mediacodec.h> #include "misc/jni.h" +#include "osdep/threads.h" #include "osdep/timer.h" #include "video/out/gpu/hwdec.h" #include "video/out/opengl/ra_gl.h" @@ -63,8 +63,8 @@ struct priv { AImage *image; EGLImageKHR egl_image; - pthread_mutex_t lock; - pthread_cond_t cond; + mp_mutex lock; + mp_cond cond; bool image_available; EGLImageKHR (EGLAPIENTRY *CreateImageKHR)( @@ -75,7 +75,7 @@ struct priv { void (EGLAPIENTRY *EGLImageTargetTexture2DOES)(GLenum, GLeglImageOES); }; -const static struct { const char *symbol; int offset; } lib_functions[] = { +static const struct { const char *symbol; int offset; } lib_functions[] = { { "AImageReader_newWithUsage", offsetof(struct priv_owner, AImageReader_newWithUsage) }, { "AImageReader_getWindow", offsetof(struct priv_owner, AImageReader_getWindow) }, { "AImageReader_setImageListener", offsetof(struct priv_owner, AImageReader_setImageListener) }, @@ -129,7 +129,7 @@ static int init(struct ra_hwdec *hw) { struct priv_owner *p = hw->priv; - if (!ra_is_gl(hw->ra)) + if (!ra_is_gl(hw->ra_ctx->ra)) return -1; if (!eglGetCurrentContext()) return -1; @@ -138,12 +138,16 @@ static int init(struct ra_hwdec *hw) if (!gl_check_extension(exts, "EGL_ANDROID_image_native_buffer")) return -1; + JNIEnv *env = MP_JNI_GET_ENV(hw); + if (!env) + return -1; + if (!load_lib_functions(p, hw->log)) return -1; static const char *es2_exts[] = {"GL_OES_EGL_image_external", 0}; static const char *es3_exts[] = {"GL_OES_EGL_image_external_essl3", 0}; - GL *gl = ra_gl_get(hw->ra); + GL *gl = ra_gl_get(hw->ra_ctx->ra); if (gl_check_extension(gl->extensions, es3_exts[0])) hw->glsl_extensions = es3_exts; else @@ -167,8 +171,6 @@ static int init(struct ra_hwdec *hw) } assert(window); - JNIEnv *env = MP_JNI_GET_ENV(hw); - assert(env); jobject surface = p->ANativeWindow_toSurface(env, window); p->surface = (*env)->NewGlobalRef(env, surface); (*env)->DeleteLocalRef(env, surface); @@ -178,6 +180,12 @@ static int init(struct ra_hwdec *hw) .av_device_ref = create_mediacodec_device_ref(p->surface), .hw_imgfmt = IMGFMT_MEDIACODEC, }; + + if (!p->hwctx.av_device_ref) { + MP_VERBOSE(hw, "Failed to create hwdevice_ctx\n"); + return -1; + } + hwdec_devices_add(hw->devs, &p->hwctx); return 0; @@ -186,10 +194,10 @@ static int init(struct ra_hwdec *hw) static void uninit(struct ra_hwdec *hw) { struct priv_owner *p = hw->priv; - JNIEnv *env = MP_JNI_GET_ENV(hw); - assert(env); if (p->surface) { + JNIEnv *env = MP_JNI_GET_ENV(hw); + assert(env); (*env)->DeleteGlobalRef(env, p->surface); p->surface = NULL; } @@ -212,10 +220,10 @@ static void image_callback(void *context, AImageReader *reader) { struct priv *p = context; - pthread_mutex_lock(&p->lock); + mp_mutex_lock(&p->lock); p->image_available = true; - pthread_cond_signal(&p->cond); - pthread_mutex_unlock(&p->lock); + mp_cond_signal(&p->cond); + mp_mutex_unlock(&p->lock); } static int mapper_init(struct ra_hwdec_mapper *mapper) @@ -225,8 +233,8 @@ static int mapper_init(struct ra_hwdec_mapper *mapper) GL *gl = ra_gl_get(mapper->ra); p->log = mapper->log; - pthread_mutex_init(&p->lock, NULL); - pthread_cond_init(&p->cond, NULL); + mp_mutex_init(&p->lock); + mp_cond_init(&p->cond); p->CreateImageKHR = (void *)eglGetProcAddress("eglCreateImageKHR"); p->DestroyImageKHR = (void *)eglGetProcAddress("eglDestroyImageKHR"); @@ -292,8 +300,8 @@ static void mapper_uninit(struct ra_hwdec_mapper *mapper) ra_tex_free(mapper->ra, &mapper->tex[0]); - pthread_mutex_destroy(&p->lock); - pthread_cond_destroy(&p->cond); + mp_mutex_destroy(&p->lock); + mp_cond_destroy(&p->cond); } static void mapper_unmap(struct ra_hwdec_mapper *mapper) @@ -326,16 +334,15 @@ static int mapper_map(struct ra_hwdec_mapper *mapper) } bool image_available = false; - pthread_mutex_lock(&p->lock); + mp_mutex_lock(&p->lock); if (!p->image_available) { - struct timespec ts = mp_rel_time_to_timespec(0.1); - pthread_cond_timedwait(&p->cond, &p->lock, &ts); + mp_cond_timedwait(&p->cond, &p->lock, MP_TIME_MS_TO_NS(100)); if (!p->image_available) MP_WARN(mapper, "Waiting for frame timed out!\n"); } image_available = p->image_available; p->image_available = false; - pthread_mutex_unlock(&p->lock); + mp_mutex_unlock(&p->lock); media_status_t ret = o->AImageReader_acquireLatestImage(o->reader, &p->image); if (ret != AMEDIA_OK) { |