aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mediacodec_wrapper.c
diff options
context:
space:
mode:
authorZhao Zhili <zhilizhao@tencent.com>2022-10-20 14:35:32 +0000
committerZhao Zhili <zhilizhao@tencent.com>2022-11-21 23:55:57 +0800
commit3a5944696768e3b5680ae78d9d84ba9846050e61 (patch)
tree35e61b15349b1305fd0dc4071d3eaf85ca063b84 /libavcodec/mediacodec_wrapper.c
parent2697f23f4e866a81ddcfca0c99a56ed14f93dc07 (diff)
downloadffmpeg-3a5944696768e3b5680ae78d9d84ba9846050e61.tar.gz
avcodec/mediacodec: add ANativeWindow support
ANativeWindow can be used without JVM.
Diffstat (limited to 'libavcodec/mediacodec_wrapper.c')
-rw-r--r--libavcodec/mediacodec_wrapper.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index b12aced711..284d615980 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -1371,12 +1371,17 @@ fail:
return ret;
}
-static int mediacodec_jni_configure(FFAMediaCodec* ctx, const FFAMediaFormat* format_ctx, void* surface, void *crypto, uint32_t flags)
+static int mediacodec_jni_configure(FFAMediaCodec *ctx,
+ const FFAMediaFormat* format_ctx,
+ FFANativeWindow* window,
+ void *crypto,
+ uint32_t flags)
{
int ret = 0;
JNIEnv *env = NULL;
FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
const FFAMediaFormatJni *format = (FFAMediaFormatJni *)format_ctx;
+ jobject *surface = window ? window->surface : NULL;
JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
@@ -2151,16 +2156,27 @@ static int mediacodec_ndk_delete(FFAMediaCodec* ctx)
return ret;
}
-static int mediacodec_ndk_configure(FFAMediaCodec* ctx, const FFAMediaFormat* format_ctx, void* surface, void *crypto, uint32_t flags)
+static int mediacodec_ndk_configure(FFAMediaCodec* ctx,
+ const FFAMediaFormat* format_ctx,
+ FFANativeWindow* window,
+ void *crypto,
+ uint32_t flags)
{
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)format_ctx;
media_status_t status;
+ ANativeWindow *native_window = NULL;
- if (surface) {
- JNIEnv *env = NULL;
- JNI_GET_ENV_OR_RETURN(env, ctx, -1);
- codec->window = ANativeWindow_fromSurface(env, surface);
+ if (window) {
+ if (window->surface) {
+ JNIEnv *env = NULL;
+ JNI_GET_ENV_OR_RETURN(env, ctx, -1);
+ native_window = ANativeWindow_fromSurface(env, window->surface);
+ // Save for release
+ codec->window = native_window;
+ } else if (window->native_window) {
+ native_window = window->native_window;
+ }
}
if (format_ctx->class != &amediaformat_ndk_class) {
@@ -2168,7 +2184,7 @@ static int mediacodec_ndk_configure(FFAMediaCodec* ctx, const FFAMediaFormat* fo
return AVERROR(EINVAL);
}
- status = codec->configure(codec->impl, format->impl, codec->window, NULL, flags);
+ status = codec->configure(codec->impl, format->impl, native_window, NULL, flags);
if (status != AMEDIA_OK) {
av_log(codec, AV_LOG_ERROR, "configure failed, %d\n", status);
return AVERROR_EXTERNAL;