summaryrefslogtreecommitdiff
path: root/libavcodec/mediacodec.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.c
parent293676c476733e81d7b596736add6cd510eb6960 (diff)
downloadffmpeg-376d8fb2c5742e6718323d6a69479c6ee68dd75b.tar.gz
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.c')
-rw-r--r--libavcodec/mediacodec.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/libavcodec/mediacodec.c b/libavcodec/mediacodec.c
index 5b79798a87..cd8766f3b1 100644
--- a/libavcodec/mediacodec.c
+++ b/libavcodec/mediacodec.c
@@ -43,9 +43,8 @@ int av_mediacodec_default_init(AVCodecContext *avctx, AVMediaCodecContext *ctx,
{
int ret = 0;
JNIEnv *env = NULL;
- int attached = 0;
- env = ff_jni_attach_env(&attached, avctx);
+ env = ff_jni_get_env(avctx);
if (!env) {
return AVERROR_EXTERNAL;
}
@@ -58,17 +57,12 @@ int av_mediacodec_default_init(AVCodecContext *avctx, AVMediaCodecContext *ctx,
ret = AVERROR_EXTERNAL;
}
- if (attached) {
- ff_jni_detach_env(avctx);
- }
-
return ret;
}
void av_mediacodec_default_free(AVCodecContext *avctx)
{
JNIEnv *env = NULL;
- int attached = 0;
AVMediaCodecContext *ctx = avctx->hwaccel_context;
@@ -76,7 +70,7 @@ void av_mediacodec_default_free(AVCodecContext *avctx)
return;
}
- env = ff_jni_attach_env(&attached, avctx);
+ env = ff_jni_get_env(avctx);
if (!env) {
return;
}
@@ -86,10 +80,6 @@ void av_mediacodec_default_free(AVCodecContext *avctx)
ctx->surface = NULL;
}
- if (attached) {
- ff_jni_detach_env(avctx);
- }
-
av_freep(&avctx->hwaccel_context);
}