diff mbox series

[FFmpeg-devel,05/12] avcodec/mediacodec_wrapper: separate implementation from interface

Message ID tencent_0B1640CD14201B4D904FE555772724B8A507@qq.com
State New
Headers show
Series Add MediaCodec encoder and NDK MediaCodec support | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Zhao Zhili Oct. 24, 2022, 3:16 a.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

This is in preparation for NDK media codec wrapper.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
---
 libavcodec/mediacodec_wrapper.c | 244 +++++++++++++++++++++---------
 libavcodec/mediacodec_wrapper.h | 255 +++++++++++++++++++++++++++-----
 2 files changed, 394 insertions(+), 105 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index 8ffc58e1d8..e0c614680e 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -160,12 +160,14 @@  static const AVClass amediaformat_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-struct FFAMediaFormat {
+typedef struct FFAMediaFormatJni {
+    FFAMediaFormat api;
 
-    const AVClass *class;
     struct JNIAMediaFormatFields jfields;
     jobject object;
-};
+} FFAMediaFormatJni;
+
+static const FFAMediaFormat media_format_jni;
 
 struct JNIAMediaCodecFields {
 
@@ -272,9 +274,8 @@  static const AVClass amediacodec_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-struct FFAMediaCodec {
-
-    const AVClass *class;
+typedef struct FFAMediaCodecJni {
+    FFAMediaCodec api;
 
     struct JNIAMediaCodecFields jfields;
 
@@ -295,7 +296,9 @@  struct FFAMediaCodec {
     int CONFIGURE_FLAG_ENCODE;
 
     int has_get_i_o_buffer;
-};
+} FFAMediaCodecJni;
+
+static const FFAMediaCodec media_codec_jni;
 
 #define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret) do {              \
     (env) = ff_jni_get_env(log_ctx);                               \
@@ -622,17 +625,17 @@  done:
     return name;
 }
 
-FFAMediaFormat *ff_AMediaFormat_new(void)
+static FFAMediaFormat *mediaformat_jni_new(void)
 {
     JNIEnv *env = NULL;
-    FFAMediaFormat *format = NULL;
+    FFAMediaFormatJni *format = NULL;
     jobject object = NULL;
 
-    format = av_mallocz(sizeof(FFAMediaFormat));
+    format = av_mallocz(sizeof(*format));
     if (!format) {
         return NULL;
     }
-    format->class = &amediaformat_class;
+    format->api = media_format_jni;
 
     env = ff_jni_get_env(format);
     if (!env) {
@@ -664,19 +667,19 @@  fail:
         av_freep(&format);
     }
 
-    return format;
+    return (FFAMediaFormat *)format;
 }
 
-static FFAMediaFormat *ff_AMediaFormat_newFromObject(void *object)
+static FFAMediaFormat *mediaformat_jni_newFromObject(void *object)
 {
     JNIEnv *env = NULL;
-    FFAMediaFormat *format = NULL;
+    FFAMediaFormatJni *format = NULL;
 
-    format = av_mallocz(sizeof(FFAMediaFormat));
+    format = av_mallocz(sizeof(*format));
     if (!format) {
         return NULL;
     }
-    format->class = &amediaformat_class;
+    format->api = media_format_jni;
 
     env = ff_jni_get_env(format);
     if (!env) {
@@ -693,7 +696,7 @@  static FFAMediaFormat *ff_AMediaFormat_newFromObject(void *object)
         goto fail;
     }
 
-    return format;
+    return (FFAMediaFormat *)format;
 fail:
     ff_jni_reset_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format);
 
@@ -702,10 +705,10 @@  fail:
     return NULL;
 }
 
-int ff_AMediaFormat_delete(FFAMediaFormat* format)
+static int mediaformat_jni_delete(FFAMediaFormat* ctx)
 {
     int ret = 0;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
 
     if (!format) {
@@ -724,10 +727,10 @@  int ff_AMediaFormat_delete(FFAMediaFormat* format)
     return ret;
 }
 
-char* ff_AMediaFormat_toString(FFAMediaFormat* format)
+static char* mediaformat_jni_toString(FFAMediaFormat* ctx)
 {
     char *ret = NULL;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
     jstring description = NULL;
 
@@ -749,10 +752,10 @@  fail:
     return ret;
 }
 
-int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *out)
+static int mediaformat_jni_getInt32(FFAMediaFormat* ctx, const char *name, int32_t *out)
 {
     int ret = 1;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
     jstring key = NULL;
     jboolean contains_key;
@@ -788,10 +791,10 @@  fail:
     return ret;
 }
 
-int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out)
+static int mediaformat_jni_getInt64(FFAMediaFormat* ctx, const char *name, int64_t *out)
 {
     int ret = 1;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
     jstring key = NULL;
     jboolean contains_key;
@@ -827,10 +830,10 @@  fail:
     return ret;
 }
 
-int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out)
+static int mediaformat_jni_getFloat(FFAMediaFormat* ctx, const char *name, float *out)
 {
     int ret = 1;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
     jstring key = NULL;
     jboolean contains_key;
@@ -866,10 +869,10 @@  fail:
     return ret;
 }
 
-int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size)
+static int mediaformat_jni_getBuffer(FFAMediaFormat* ctx, const char *name, void** data, size_t *size)
 {
     int ret = 1;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
     jstring key = NULL;
     jboolean contains_key;
@@ -924,10 +927,10 @@  fail:
     return ret;
 }
 
-int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out)
+static int mediaformat_jni_getString(FFAMediaFormat* ctx, const char *name, const char **out)
 {
     int ret = 1;
-
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
     JNIEnv *env = NULL;
     jstring key = NULL;
     jboolean contains_key;
@@ -974,10 +977,11 @@  fail:
     return ret;
 }
 
-void ff_AMediaFormat_setInt32(FFAMediaFormat* format, const char* name, int32_t value)
+static void mediaformat_jni_setInt32(FFAMediaFormat* ctx, const char* name, int32_t value)
 {
     JNIEnv *env = NULL;
     jstring key = NULL;
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
 
     av_assert0(format != NULL);
 
@@ -999,10 +1003,11 @@  fail:
     }
 }
 
-void ff_AMediaFormat_setInt64(FFAMediaFormat* format, const char* name, int64_t value)
+static void mediaformat_jni_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
 {
     JNIEnv *env = NULL;
     jstring key = NULL;
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
 
     av_assert0(format != NULL);
 
@@ -1024,10 +1029,11 @@  fail:
     }
 }
 
-void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value)
+static void mediaformat_jni_setFloat(FFAMediaFormat* ctx, const char* name, float value)
 {
     JNIEnv *env = NULL;
     jstring key = NULL;
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
 
     av_assert0(format != NULL);
 
@@ -1049,11 +1055,12 @@  fail:
     }
 }
 
-void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value)
+static void mediaformat_jni_setString(FFAMediaFormat* ctx, const char* name, const char* value)
 {
     JNIEnv *env = NULL;
     jstring key = NULL;
     jstring string = NULL;
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
 
     av_assert0(format != NULL);
 
@@ -1084,12 +1091,13 @@  fail:
     }
 }
 
-void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size)
+static void mediaformat_jni_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
 {
     JNIEnv *env = NULL;
     jstring key = NULL;
     jobject buffer = NULL;
     void *buffer_data = NULL;
+    FFAMediaFormatJni *format = (FFAMediaFormatJni *)ctx;
 
     av_assert0(format != NULL);
 
@@ -1131,7 +1139,7 @@  fail:
     }
 }
 
-static int codec_init_static_fields(FFAMediaCodec *codec)
+static int codec_init_static_fields(FFAMediaCodecJni *codec)
 {
     int ret = 0;
     JNIEnv *env = NULL;
@@ -1193,17 +1201,17 @@  static inline FFAMediaCodec *codec_create(int method, const char *arg)
 {
     int ret = -1;
     JNIEnv *env = NULL;
-    FFAMediaCodec *codec = NULL;
+    FFAMediaCodecJni *codec = NULL;
     jstring jarg = NULL;
     jobject object = NULL;
     jobject buffer_info = NULL;
     jmethodID create_id = NULL;
 
-    codec = av_mallocz(sizeof(FFAMediaCodec));
+    codec = av_mallocz(sizeof(*codec));
     if (!codec) {
         return NULL;
     }
-    codec->class = &amediacodec_class;
+    codec->api = media_codec_jni;
 
     env = ff_jni_get_env(codec);
     if (!env) {
@@ -1286,11 +1294,11 @@  fail:
         av_freep(&codec);
     }
 
-    return codec;
+    return (FFAMediaCodec *)codec;
 }
 
 #define DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method) \
-FFAMediaCodec *ff_AMediaCodec_##name(const char *arg)    \
+static FFAMediaCodec *mediacodec_jni_##name(const char *arg)    \
 {                                                        \
     return codec_create(method, arg);                    \
 }                                                        \
@@ -1299,10 +1307,10 @@  DECLARE_FF_AMEDIACODEC_CREATE_FUNC(createCodecByName,   CREATE_CODEC_BY_NAME)
 DECLARE_FF_AMEDIACODEC_CREATE_FUNC(createDecoderByType, CREATE_DECODER_BY_TYPE)
 DECLARE_FF_AMEDIACODEC_CREATE_FUNC(createEncoderByType, CREATE_ENCODER_BY_TYPE)
 
-int ff_AMediaCodec_delete(FFAMediaCodec* codec)
+static int mediacodec_jni_delete(FFAMediaCodec* ctx)
 {
     int ret = 0;
-
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     JNIEnv *env = NULL;
 
     if (!codec) {
@@ -1335,11 +1343,12 @@  int ff_AMediaCodec_delete(FFAMediaCodec* codec)
     return ret;
 }
 
-char *ff_AMediaCodec_getName(FFAMediaCodec *codec)
+static char *mediacodec_jni_getName(FFAMediaCodec *ctx)
 {
     char *ret = NULL;
     JNIEnv *env = NULL;
     jobject *name = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, NULL);
 
@@ -1358,10 +1367,12 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_configure(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags)
+static int mediacodec_jni_configure(FFAMediaCodec* ctx, const FFAMediaFormat* format_ctx, void* surface, void *crypto, uint32_t flags)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
+    const FFAMediaFormatJni *format = (FFAMediaFormatJni *)format_ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1375,10 +1386,11 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_start(FFAMediaCodec* codec)
+static int mediacodec_jni_start(FFAMediaCodec* ctx)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1392,10 +1404,11 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_stop(FFAMediaCodec* codec)
+static int mediacodec_jni_stop(FFAMediaCodec* ctx)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1409,10 +1422,11 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_flush(FFAMediaCodec* codec)
+static int mediacodec_jni_flush(FFAMediaCodec* ctx)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1426,10 +1440,11 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render)
+static int mediacodec_jni_releaseOutputBuffer(FFAMediaCodec* ctx, size_t idx, int render)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1443,10 +1458,11 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
+static int mediacodec_jni_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1460,10 +1476,11 @@  fail:
     return ret;
 }
 
-ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs)
+static ssize_t mediacodec_jni_dequeueInputBuffer(FFAMediaCodec* ctx, int64_t timeoutUs)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1477,10 +1494,11 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
+static int mediacodec_jni_queueInputBuffer(FFAMediaCodec* ctx, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1494,10 +1512,11 @@  fail:
     return ret;
 }
 
-ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec* codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
+static ssize_t mediacodec_jni_dequeueOutputBuffer(FFAMediaCodec* ctx, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
 {
     int ret = 0;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
 
@@ -1529,11 +1548,11 @@  ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec* codec, FFAMediaCodecBu
     return ret;
 }
 
-uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
+static uint8_t* mediacodec_jni_getInputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
 {
     uint8_t *ret = NULL;
     JNIEnv *env = NULL;
-
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     jobject buffer = NULL;
     jobject input_buffers = NULL;
 
@@ -1577,11 +1596,11 @@  fail:
     return ret;
 }
 
-uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
+static uint8_t* mediacodec_jni_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
 {
     uint8_t *ret = NULL;
     JNIEnv *env = NULL;
-
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     jobject buffer = NULL;
     jobject output_buffers = NULL;
 
@@ -1625,10 +1644,11 @@  fail:
     return ret;
 }
 
-FFAMediaFormat* ff_AMediaCodec_getOutputFormat(FFAMediaCodec* codec)
+static FFAMediaFormat* mediacodec_jni_getOutputFormat(FFAMediaCodec* ctx)
 {
     FFAMediaFormat *ret = NULL;
     JNIEnv *env = NULL;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     jobject mediaformat = NULL;
 
@@ -1639,7 +1659,7 @@  FFAMediaFormat* ff_AMediaCodec_getOutputFormat(FFAMediaCodec* codec)
         goto fail;
     }
 
-    ret = ff_AMediaFormat_newFromObject(mediaformat);
+    ret = mediaformat_jni_newFromObject(mediaformat);
 fail:
     if (mediaformat) {
         (*env)->DeleteLocalRef(env, mediaformat);
@@ -1648,44 +1668,52 @@  fail:
     return ret;
 }
 
-int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
+static int mediacodec_jni_infoTryAgainLater(FFAMediaCodec *ctx, ssize_t idx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return idx == codec->INFO_TRY_AGAIN_LATER;
 }
 
-int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
+static int mediacodec_jni_infoOutputBuffersChanged(FFAMediaCodec *ctx, ssize_t idx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return idx == codec->INFO_OUTPUT_BUFFERS_CHANGED;
 }
 
-int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
+static int mediacodec_jni_infoOutputFormatChanged(FFAMediaCodec *ctx, ssize_t idx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return idx == codec->INFO_OUTPUT_FORMAT_CHANGED;
 }
 
-int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
+static int mediacodec_jni_getBufferFlagCodecConfig(FFAMediaCodec *ctx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return codec->BUFFER_FLAG_CODEC_CONFIG;
 }
 
-int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
+static int mediacodec_jni_getBufferFlagEndOfStream(FFAMediaCodec *ctx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return codec->BUFFER_FLAG_END_OF_STREAM;
 }
 
-int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
+static int mediacodec_jni_getBufferFlagKeyFrame(FFAMediaCodec *ctx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return codec->BUFFER_FLAG_KEY_FRAME;
 }
 
-int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
+static int mediacodec_jni_getConfigureFlagEncode(FFAMediaCodec *ctx)
 {
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
     return codec->CONFIGURE_FLAG_ENCODE;
 }
 
-int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
+static int mediacodec_jni_cleanOutputBuffers(FFAMediaCodec *ctx)
 {
     int ret = 0;
+    FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
 
     if (!codec->has_get_i_o_buffer) {
         if (codec->output_buffers) {
@@ -1706,6 +1734,86 @@  fail:
     return ret;
 }
 
+static const FFAMediaFormat media_format_jni = {
+    .class = &amediaformat_class,
+
+    .create = mediaformat_jni_new,
+    .delete = mediaformat_jni_delete,
+
+    .toString = mediaformat_jni_toString,
+
+    .getInt32 = mediaformat_jni_getInt32,
+    .getInt64 = mediaformat_jni_getInt64,
+    .getFloat = mediaformat_jni_getFloat,
+    .getBuffer = mediaformat_jni_getBuffer,
+    .getString = mediaformat_jni_getString,
+
+    .setInt32 = mediaformat_jni_setInt32,
+    .setInt64 = mediaformat_jni_setInt64,
+    .setFloat = mediaformat_jni_setFloat,
+    .setString = mediaformat_jni_setString,
+    .setBuffer = mediaformat_jni_setBuffer,
+};
+
+static const FFAMediaCodec media_codec_jni = {
+    .class = &amediacodec_class,
+
+    .getName = mediacodec_jni_getName,
+
+    .createCodecByName = mediacodec_jni_createCodecByName,
+    .createDecoderByType = mediacodec_jni_createDecoderByType,
+    .createEncoderByType = mediacodec_jni_createEncoderByType,
+    .delete = mediacodec_jni_delete,
+
+    .configure = mediacodec_jni_configure,
+    .start = mediacodec_jni_start,
+    .stop = mediacodec_jni_stop,
+    .flush = mediacodec_jni_flush,
+
+    .getInputBuffer = mediacodec_jni_getInputBuffer,
+    .getOutputBuffer = mediacodec_jni_getOutputBuffer,
+
+    .dequeueInputBuffer = mediacodec_jni_dequeueInputBuffer,
+    .queueInputBuffer = mediacodec_jni_queueInputBuffer,
+
+    .dequeueOutputBuffer = mediacodec_jni_dequeueOutputBuffer,
+    .getOutputFormat = mediacodec_jni_getOutputFormat,
+
+    .releaseOutputBuffer = mediacodec_jni_releaseOutputBuffer,
+    .releaseOutputBufferAtTime = mediacodec_jni_releaseOutputBufferAtTime,
+
+    .infoTryAgainLater = mediacodec_jni_infoTryAgainLater,
+    .infoOutputBuffersChanged = mediacodec_jni_infoOutputBuffersChanged,
+    .infoOutputFormatChanged = mediacodec_jni_infoOutputFormatChanged,
+
+    .getBufferFlagCodecConfig = mediacodec_jni_getBufferFlagCodecConfig,
+    .getBufferFlagEndOfStream = mediacodec_jni_getBufferFlagEndOfStream,
+    .getBufferFlagKeyFrame = mediacodec_jni_getBufferFlagKeyFrame,
+
+    .getConfigureFlagEncode = mediacodec_jni_getConfigureFlagEncode,
+    .cleanOutputBuffers = mediacodec_jni_cleanOutputBuffers,
+};
+
+FFAMediaFormat *ff_AMediaFormat_new(void)
+{
+    return media_format_jni.create();
+}
+
+FFAMediaCodec* ff_AMediaCodec_createCodecByName(const char *name)
+{
+    return media_codec_jni.createCodecByName(name);
+}
+
+FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type)
+{
+    return media_codec_jni.createDecoderByType(mime_type);
+}
+
+FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type)
+{
+    return media_codec_jni.createEncoderByType(mime_type);
+}
+
 int ff_Build_SDK_INT(AVCodecContext *avctx)
 {
     int ret = -1;
diff --git a/libavcodec/mediacodec_wrapper.h b/libavcodec/mediacodec_wrapper.h
index b106ff315a..606fdbede5 100644
--- a/libavcodec/mediacodec_wrapper.h
+++ b/libavcodec/mediacodec_wrapper.h
@@ -58,28 +58,90 @@  int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx);
 
 char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx);
 
-struct FFAMediaFormat;
 typedef struct FFAMediaFormat FFAMediaFormat;
+struct FFAMediaFormat {
+    const AVClass *class;
+
+    FFAMediaFormat *(*create)(void);
+    int (*delete)(FFAMediaFormat *);
+
+    char* (*toString)(FFAMediaFormat* format);
+
+    int (*getInt32)(FFAMediaFormat* format, const char *name, int32_t *out);
+    int (*getInt64)(FFAMediaFormat* format, const char *name, int64_t *out);
+    int (*getFloat)(FFAMediaFormat* format, const char *name, float *out);
+    int (*getBuffer)(FFAMediaFormat* format, const char *name, void** data, size_t *size);
+    int (*getString)(FFAMediaFormat* format, const char *name, const char **out);
+
+    void (*setInt32)(FFAMediaFormat* format, const char* name, int32_t value);
+    void (*setInt64)(FFAMediaFormat* format, const char* name, int64_t value);
+    void (*setFloat)(FFAMediaFormat* format, const char* name, float value);
+    void (*setString)(FFAMediaFormat* format, const char* name, const char* value);
+    void (*setBuffer)(FFAMediaFormat* format, const char* name, void* data, size_t size);
+};
 
 FFAMediaFormat *ff_AMediaFormat_new(void);
-int ff_AMediaFormat_delete(FFAMediaFormat* format);
 
-char* ff_AMediaFormat_toString(FFAMediaFormat* format);
+static inline int ff_AMediaFormat_delete(FFAMediaFormat* format)
+{
+    return format->delete(format);
+}
 
-int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *out);
-int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out);
-int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out);
-int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size);
-int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out);
+static inline char* ff_AMediaFormat_toString(FFAMediaFormat* format)
+{
+    return format->toString(format);
+}
 
-void ff_AMediaFormat_setInt32(FFAMediaFormat* format, const char* name, int32_t value);
-void ff_AMediaFormat_setInt64(FFAMediaFormat* format, const char* name, int64_t value);
-void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value);
-void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value);
-void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size);
+static inline int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *out)
+{
+    return format->getInt32(format, name, out);
+}
+
+static inline int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out)
+{
+    return format->getInt64(format, name, out);
+}
+
+static inline int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out)
+{
+    return format->getFloat(format, name, out);
+}
+
+static inline int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size)
+{
+    return format->getBuffer(format, name, data, size);
+}
+
+static inline int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out)
+{
+    return format->getString(format, name, out);
+}
+
+static inline void ff_AMediaFormat_setInt32(FFAMediaFormat* format, const char* name, int32_t value)
+{
+    format->setInt32(format, name, value);
+}
+
+static inline void ff_AMediaFormat_setInt64(FFAMediaFormat* format, const char* name, int64_t value)
+{
+    format->setInt64(format, name, value);
+}
+
+static inline void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value)
+{
+    format->setFloat(format, name, value);
+}
+
+static inline void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value)
+{
+    format->setString(format, name, value);
+}
+
+static inline void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size)
+{
+    format->setBuffer(format, name, data, size);
+}
 
-struct FFAMediaCodec;
-typedef struct FFAMediaCodec FFAMediaCodec;
 typedef struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo;
 
 struct FFAMediaCodecBufferInfo {
@@ -90,41 +152,160 @@  struct FFAMediaCodecBufferInfo {
 };
 typedef struct FFAMediaCodecBufferInfo FFAMediaCodecBufferInfo;
 
-char *ff_AMediaCodec_getName(FFAMediaCodec *codec);
+typedef struct FFAMediaCodec FFAMediaCodec;
+struct FFAMediaCodec {
+    const AVClass *class;
+
+    char *(*getName)(FFAMediaCodec *codec);
+
+    FFAMediaCodec* (*createCodecByName)(const char *name);
+    FFAMediaCodec* (*createDecoderByType)(const char *mime_type);
+    FFAMediaCodec* (*createEncoderByType)(const char *mime_type);
+    int (*delete)(FFAMediaCodec* codec);
+
+    int (*configure)(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags);
+    int (*start)(FFAMediaCodec* codec);
+    int (*stop)(FFAMediaCodec* codec);
+    int (*flush)(FFAMediaCodec* codec);
+
+    uint8_t* (*getInputBuffer)(FFAMediaCodec* codec, size_t idx, size_t *out_size);
+    uint8_t* (*getOutputBuffer)(FFAMediaCodec* codec, size_t idx, size_t *out_size);
+
+    ssize_t (*dequeueInputBuffer)(FFAMediaCodec* codec, int64_t timeoutUs);
+    int (*queueInputBuffer)(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
+
+    ssize_t (*dequeueOutputBuffer)(FFAMediaCodec* codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs);
+    FFAMediaFormat* (*getOutputFormat)(FFAMediaCodec* codec);
+
+    int (*releaseOutputBuffer)(FFAMediaCodec* codec, size_t idx, int render);
+    int (*releaseOutputBufferAtTime)(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
+
+    int (*infoTryAgainLater)(FFAMediaCodec *codec, ssize_t idx);
+    int (*infoOutputBuffersChanged)(FFAMediaCodec *codec, ssize_t idx);
+    int (*infoOutputFormatChanged)(FFAMediaCodec *codec, ssize_t indx);
+
+    int (*getBufferFlagCodecConfig)(FFAMediaCodec *codec);
+    int (*getBufferFlagEndOfStream)(FFAMediaCodec *codec);
+    int (*getBufferFlagKeyFrame)(FFAMediaCodec *codec);
+
+    int (*getConfigureFlagEncode)(FFAMediaCodec *codec);
+
+    int (*cleanOutputBuffers)(FFAMediaCodec *codec);
+};
+
+static inline char *ff_AMediaCodec_getName(FFAMediaCodec *codec)
+{
+    return codec->getName(codec);
+}
 
 FFAMediaCodec* ff_AMediaCodec_createCodecByName(const char *name);
 FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type);
 FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type);
 
-int ff_AMediaCodec_configure(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags);
-int ff_AMediaCodec_start(FFAMediaCodec* codec);
-int ff_AMediaCodec_stop(FFAMediaCodec* codec);
-int ff_AMediaCodec_flush(FFAMediaCodec* codec);
-int ff_AMediaCodec_delete(FFAMediaCodec* codec);
+static inline int ff_AMediaCodec_configure(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags)
+{
+    return codec->configure(codec, format, surface, crypto, flags);
+}
+
+static inline int ff_AMediaCodec_start(FFAMediaCodec* codec)
+{
+    return codec->start(codec);
+}
+
+static inline int ff_AMediaCodec_stop(FFAMediaCodec* codec)
+{
+    return codec->stop(codec);
+}
+
+static inline int ff_AMediaCodec_flush(FFAMediaCodec* codec)
+{
+    return codec->flush(codec);
+}
+
+static inline int ff_AMediaCodec_delete(FFAMediaCodec* codec)
+{
+    return codec->delete(codec);
+}
+
+static inline uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
+{
+    return codec->getInputBuffer(codec, idx, out_size);
+}
+
+static inline uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
+{
+    return codec->getOutputBuffer(codec, idx, out_size);
+}
+
+static inline ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs)
+{
+    return codec->dequeueInputBuffer(codec, timeoutUs);
+}
+
+static inline int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
+{
+    return codec->queueInputBuffer(codec, idx, offset, size, time, flags);
+}
+
+static inline ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec* codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
+{
+    return codec->dequeueOutputBuffer(codec, info, timeoutUs);
+}
+
+static inline FFAMediaFormat* ff_AMediaCodec_getOutputFormat(FFAMediaCodec* codec)
+{
+    return codec->getOutputFormat(codec);
+}
+
+static inline int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render)
+{
+    return codec->releaseOutputBuffer(codec, idx, render);
+}
+
+static inline int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
+{
+    return codec->releaseOutputBufferAtTime(codec, idx, timestampNs);
+}
 
-uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
-uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
+static inline int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
+{
+    return codec->infoTryAgainLater(codec, idx);
+}
 
-ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs);
-int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
+static inline int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
+{
+    return codec->infoOutputBuffersChanged(codec, idx);
+}
 
-ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec* codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs);
-FFAMediaFormat* ff_AMediaCodec_getOutputFormat(FFAMediaCodec* codec);
+static inline int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
+{
+    return codec->infoOutputFormatChanged(codec, idx);
+}
 
-int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render);
-int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
+static inline int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
+{
+    return codec->getBufferFlagCodecConfig(codec);
+}
 
-int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx);
-int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx);
-int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t indx);
+static inline int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
+{
+    return codec->getBufferFlagEndOfStream(codec);
+}
 
-int ff_AMediaCodec_getBufferFlagCodecConfig (FFAMediaCodec *codec);
-int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec);
-int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec);
+static inline int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
+{
+    return codec->getBufferFlagKeyFrame(codec);
+}
 
-int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec);
+static inline int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
+{
+    return codec->getConfigureFlagEncode(codec);
+}
 
-int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec);
+static inline int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
+{
+    return codec->cleanOutputBuffers(codec);
+}
 
 int ff_Build_SDK_INT(AVCodecContext *avctx);