summaryrefslogtreecommitdiff
path: root/libavcodec/mediacodec_surface.c
diff options
context:
space:
mode:
authorMatthieu Bouron <matthieu.bouron@stupeflix.com>2016-07-01 09:59:13 +0200
committerMatthieu Bouron <matthieu.bouron@stupeflix.com>2016-07-27 15:43:39 +0200
commit376d8fb2c5742e6718323d6a69479c6ee68dd75b (patch)
treebcf8a1bc9c40fd3b46359cc481632fad95855082 /libavcodec/mediacodec_surface.c
parent293676c476733e81d7b596736add6cd510eb6960 (diff)
lavc/ffjni: replace ff_jni_{attach,detach} with ff_jni_get_env
If a JNI environment is not already attached to the thread where the MediaCodec calls are made the current implementation will attach / detach an environment for each MediaCodec call wasting some CPU time. ff_jni_get_env replaces ff_jni_{attach,detach} by permanently attaching an environment (if it is not already the case) to the current thread. The environment will be automatically detached at the thread destruction using a pthread_key callback. Saves around 5% of CPU time (out of 20%) while decoding a stream with MediaCodec.
Diffstat (limited to 'libavcodec/mediacodec_surface.c')
-rw-r--r--libavcodec/mediacodec_surface.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/libavcodec/mediacodec_surface.c b/libavcodec/mediacodec_surface.c
index 903ebe4d8b..aada1ecebe 100644
--- a/libavcodec/mediacodec_surface.c
+++ b/libavcodec/mediacodec_surface.c
@@ -27,40 +27,30 @@
void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
{
- int attached = 0;
JNIEnv *env = NULL;
void *reference = NULL;
- env = ff_jni_attach_env(&attached, log_ctx);
+ env = ff_jni_get_env(log_ctx);
if (!env) {
return NULL;
}
reference = (*env)->NewGlobalRef(env, surface);
- if (attached) {
- ff_jni_detach_env(log_ctx);
- }
-
return reference;
}
int ff_mediacodec_surface_unref(void *surface, void *log_ctx)
{
- int attached = 0;
JNIEnv *env = NULL;
- env = ff_jni_attach_env(&attached, log_ctx);
+ env = ff_jni_get_env(log_ctx);
if (!env) {
return AVERROR_EXTERNAL;
}
(*env)->DeleteGlobalRef(env, surface);
- if (attached) {
- ff_jni_detach_env(log_ctx);
- }
-
return 0;
}