avcodec/mediacodec_wrapper: link to NDK mediacodec API directly

Drop support of Android version before 5.0.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Zhao Zhili 2024-04-17 12:37:36 +08:00 committed by Paul B Mahol
parent 78e568a451
commit 142bbd9e90
2 changed files with 36 additions and 130 deletions

2
configure vendored
View File

@ -3128,7 +3128,7 @@ d3d11va_deps="dxva_h ID3D11VideoDecoder ID3D11VideoContext"
d3d12va_deps="dxva_h ID3D12Device ID3D12VideoDecoder"
dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
ffnvcodec_deps_any="libdl LoadLibrary"
mediacodec_deps="android"
mediacodec_deps="android mediandk"
nvdec_deps="ffnvcodec"
vaapi_x11_deps="xlib_x11"
videotoolbox_hwaccel_deps="videotoolbox pthreads"

View File

@ -1826,25 +1826,8 @@ typedef struct FFAMediaFormatNdk {
void *libmedia;
AMediaFormat *impl;
AMediaFormat *(*new)(void);
media_status_t (*delete)(AMediaFormat*);
const char* (*toString)(AMediaFormat*);
bool (*getInt32)(AMediaFormat*, const char *name, int32_t *out);
bool (*getInt64)(AMediaFormat*, const char *name, int64_t *out);
bool (*getFloat)(AMediaFormat*, const char *name, float *out);
bool (*getSize)(AMediaFormat*, const char *name, size_t *out);
bool (*getBuffer)(AMediaFormat*, const char *name, void** data, size_t *size);
bool (*getString)(AMediaFormat*, const char *name, const char **out);
bool (*getRect)(AMediaFormat *, const char *name,
int32_t *left, int32_t *top, int32_t *right, int32_t *bottom);
void (*setInt32)(AMediaFormat*, const char* name, int32_t value);
void (*setInt64)(AMediaFormat*, const char* name, int64_t value);
void (*setFloat)(AMediaFormat*, const char* name, float value);
void (*setString)(AMediaFormat*, const char* name, const char* value);
void (*setBuffer)(AMediaFormat*, const char* name, const void* data, size_t size);
void (*setRect)(AMediaFormat *, const char *name,
int32_t left, int32_t top, int32_t right, int32_t bottom);
} FFAMediaFormatNdk;
@ -1856,34 +1839,6 @@ typedef struct FFAMediaCodecNdk {
AMediaCodec *impl;
ANativeWindow *window;
AMediaCodec* (*createCodecByName)(const char *name);
AMediaCodec* (*createDecoderByType)(const char *mime_type);
AMediaCodec* (*createEncoderByType)(const char *mime_type);
media_status_t (*delete)(AMediaCodec*);
media_status_t (*configure)(AMediaCodec *,
const AMediaFormat *format,
ANativeWindow *surface,
AMediaCrypto *crypto,
uint32_t flags);
media_status_t (*start)(AMediaCodec*);
media_status_t (*stop)(AMediaCodec*);
media_status_t (*flush)(AMediaCodec*);
uint8_t* (*getInputBuffer)(AMediaCodec*, size_t idx, size_t *out_size);
uint8_t* (*getOutputBuffer)(AMediaCodec*, size_t idx, size_t *out_size);
ssize_t (*dequeueInputBuffer)(AMediaCodec*, int64_t timeoutUs);
media_status_t (*queueInputBuffer)(AMediaCodec*, size_t idx,
long offset, size_t size,
uint64_t time, uint32_t flags);
ssize_t (*dequeueOutputBuffer)(AMediaCodec*, AMediaCodecBufferInfo *info, int64_t timeoutUs);
AMediaFormat* (*getOutputFormat)(AMediaCodec*);
media_status_t (*releaseOutputBuffer)(AMediaCodec*, size_t idx, bool render);
media_status_t (*releaseOutputBufferAtTime)(AMediaCodec *mData, size_t idx, int64_t timestampNs);
// Available since API level 28.
media_status_t (*getName)(AMediaCodec*, char** out_name);
void (*releaseName)(AMediaCodec*, char* name);
@ -1921,38 +1876,15 @@ static FFAMediaFormat *mediaformat_ndk_create(AMediaFormat *impl)
#define GET_OPTIONAL_SYMBOL(sym) \
format->sym = dlsym(format->libmedia, "AMediaFormat_" #sym);
#define GET_SYMBOL(sym) \
GET_OPTIONAL_SYMBOL(sym) \
if (!format->sym) \
goto error;
GET_SYMBOL(new)
GET_SYMBOL(delete)
GET_SYMBOL(toString)
GET_SYMBOL(getInt32)
GET_SYMBOL(getInt64)
GET_SYMBOL(getFloat)
GET_SYMBOL(getSize)
GET_SYMBOL(getBuffer)
GET_SYMBOL(getString)
GET_OPTIONAL_SYMBOL(getRect)
GET_SYMBOL(setInt32)
GET_SYMBOL(setInt64)
GET_SYMBOL(setFloat)
GET_SYMBOL(setString)
GET_SYMBOL(setBuffer)
GET_OPTIONAL_SYMBOL(setRect)
#undef GET_SYMBOL
#undef GET_OPTIONAL_SYMBOL
if (impl) {
format->impl = impl;
} else {
format->impl = format->new();
format->impl = AMediaFormat_new();
if (!format->impl)
goto error;
}
@ -1980,7 +1912,7 @@ static int mediaformat_ndk_delete(FFAMediaFormat* ctx)
av_assert0(format->api.class == &amediaformat_ndk_class);
if (format->impl && (format->delete(format->impl) != AMEDIA_OK))
if (format->impl && (AMediaFormat_delete(format->impl) != AMEDIA_OK))
ret = AVERROR_EXTERNAL;
if (format->libmedia)
dlclose(format->libmedia);
@ -1992,39 +1924,39 @@ static int mediaformat_ndk_delete(FFAMediaFormat* ctx)
static char* mediaformat_ndk_toString(FFAMediaFormat* ctx)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
const char *str = format->toString(format->impl);
const char *str = AMediaFormat_toString(format->impl);
return av_strdup(str);
}
static int mediaformat_ndk_getInt32(FFAMediaFormat* ctx, const char *name, int32_t *out)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
return format->getInt32(format->impl, name, out);
return AMediaFormat_getInt32(format->impl, name, out);
}
static int mediaformat_ndk_getInt64(FFAMediaFormat* ctx, const char *name, int64_t *out)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
return format->getInt64(format->impl, name, out);
return AMediaFormat_getInt64(format->impl, name, out);
}
static int mediaformat_ndk_getFloat(FFAMediaFormat* ctx, const char *name, float *out)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
return format->getFloat(format->impl, name, out);
return AMediaFormat_getFloat(format->impl, name, out);
}
static int mediaformat_ndk_getBuffer(FFAMediaFormat* ctx, const char *name, void** data, size_t *size)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
return format->getBuffer(format->impl, name, data, size);
return AMediaFormat_getBuffer(format->impl, name, data, size);
}
static int mediaformat_ndk_getString(FFAMediaFormat* ctx, const char *name, const char **out)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
const char *tmp = NULL;
int ret = format->getString(format->impl, name, &tmp);
int ret = AMediaFormat_getString(format->impl, name, &tmp);
if (tmp)
*out = av_strdup(tmp);
@ -2043,31 +1975,31 @@ static int mediaformat_ndk_getRect(FFAMediaFormat *ctx, const char *name,
static void mediaformat_ndk_setInt32(FFAMediaFormat* ctx, const char* name, int32_t value)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
format->setInt32(format->impl, name, value);
AMediaFormat_setInt32(format->impl, name, value);
}
static void mediaformat_ndk_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
format->setInt64(format->impl, name, value);
AMediaFormat_setInt64(format->impl, name, value);
}
static void mediaformat_ndk_setFloat(FFAMediaFormat* ctx, const char* name, float value)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
format->setFloat(format->impl, name, value);
AMediaFormat_setFloat(format->impl, name, value);
}
static void mediaformat_ndk_setString(FFAMediaFormat* ctx, const char* name, const char* value)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
format->setString(format->impl, name, value);
AMediaFormat_setString(format->impl, name, value);
}
static void mediaformat_ndk_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
{
FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx;
format->setBuffer(format->impl, name, data, size);
AMediaFormat_setBuffer(format->impl, name, data, size);
}
static void mediaformat_ndk_setRect(FFAMediaFormat *ctx, const char *name,
@ -2113,54 +2045,28 @@ static inline FFAMediaCodec *ndk_codec_create(int method, const char *arg) {
if (!codec->libmedia)
goto error;
#define GET_SYMBOL(sym, required) \
#define GET_SYMBOL(sym) \
codec->sym = dlsym(codec->libmedia, "AMediaCodec_" #sym); \
if (!codec->sym) { \
av_log(codec, required ? AV_LOG_ERROR : AV_LOG_INFO, \
#sym "() unavailable from %s\n", lib_name); \
if (required) \
goto error; \
}
if (!codec->sym) \
av_log(codec, AV_LOG_INFO, #sym "() unavailable from %s\n", lib_name);
GET_SYMBOL(createCodecByName, 1)
GET_SYMBOL(createDecoderByType, 1)
GET_SYMBOL(createEncoderByType, 1)
GET_SYMBOL(delete, 1)
GET_SYMBOL(getName)
GET_SYMBOL(releaseName)
GET_SYMBOL(configure, 1)
GET_SYMBOL(start, 1)
GET_SYMBOL(stop, 1)
GET_SYMBOL(flush, 1)
GET_SYMBOL(getInputBuffer, 1)
GET_SYMBOL(getOutputBuffer, 1)
GET_SYMBOL(dequeueInputBuffer, 1)
GET_SYMBOL(queueInputBuffer, 1)
GET_SYMBOL(dequeueOutputBuffer, 1)
GET_SYMBOL(getOutputFormat, 1)
GET_SYMBOL(releaseOutputBuffer, 1)
GET_SYMBOL(releaseOutputBufferAtTime, 1)
GET_SYMBOL(getName, 0)
GET_SYMBOL(releaseName, 0)
GET_SYMBOL(setInputSurface, 0)
GET_SYMBOL(signalEndOfInputStream, 0)
GET_SYMBOL(setInputSurface)
GET_SYMBOL(signalEndOfInputStream)
#undef GET_SYMBOL
switch (method) {
case CREATE_CODEC_BY_NAME:
codec->impl = codec->createCodecByName(arg);
codec->impl = AMediaCodec_createCodecByName(arg);
break;
case CREATE_DECODER_BY_TYPE:
codec->impl = codec->createDecoderByType(arg);
codec->impl = AMediaCodec_createDecoderByType(arg);
break;
case CREATE_ENCODER_BY_TYPE:
codec->impl = codec->createEncoderByType(arg);
codec->impl = AMediaCodec_createEncoderByType(arg);
break;
default:
av_assert0(0);
@ -2197,7 +2103,7 @@ static int mediacodec_ndk_delete(FFAMediaCodec* ctx)
av_assert0(codec->api.class == &amediacodec_ndk_class);
if (codec->impl && (codec->delete(codec->impl) != AMEDIA_OK))
if (codec->impl && (AMediaCodec_delete(codec->impl) != AMEDIA_OK))
ret = AVERROR_EXTERNAL;
if (codec->window)
ANativeWindow_release(codec->window);
@ -2242,7 +2148,7 @@ static int mediacodec_ndk_configure(FFAMediaCodec* ctx,
return AVERROR_EXTERNAL;
}
status = codec->configure(codec->impl, format->impl, NULL, NULL, flags);
status = AMediaCodec_configure(codec->impl, format->impl, NULL, NULL, flags);
if (status != AMEDIA_OK) {
av_log(codec, AV_LOG_ERROR, "Encoder configure failed, %d\n", status);
return AVERROR_EXTERNAL;
@ -2257,7 +2163,7 @@ static int mediacodec_ndk_configure(FFAMediaCodec* ctx,
return AVERROR_EXTERNAL;
}
} else {
status = codec->configure(codec->impl, format->impl, native_window, NULL, flags);
status = AMediaCodec_configure(codec->impl, format->impl, native_window, NULL, flags);
if (status != AMEDIA_OK) {
av_log(codec, AV_LOG_ERROR, "Decoder configure failed, %d\n", status);
return AVERROR_EXTERNAL;
@ -2271,7 +2177,7 @@ static int mediacodec_ndk_configure(FFAMediaCodec* ctx,
static int mediacodec_ndk_ ## method(FFAMediaCodec* ctx) \
{ \
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx; \
media_status_t status = codec->method(codec->impl); \
media_status_t status = AMediaCodec_ ## method (codec->impl); \
\
if (status != AMEDIA_OK) { \
av_log(codec, AV_LOG_ERROR, #method " failed, %d\n", status); \
@ -2288,19 +2194,19 @@ MEDIACODEC_NDK_WRAPPER(flush)
static uint8_t* mediacodec_ndk_getInputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
{
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
return codec->getInputBuffer(codec->impl, idx, out_size);
return AMediaCodec_getInputBuffer(codec->impl, idx, out_size);
}
static uint8_t* mediacodec_ndk_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
{
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
return codec->getOutputBuffer(codec->impl, idx, out_size);
return AMediaCodec_getOutputBuffer(codec->impl, idx, out_size);
}
static ssize_t mediacodec_ndk_dequeueInputBuffer(FFAMediaCodec* ctx, int64_t timeoutUs)
{
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
return codec->dequeueInputBuffer(codec->impl, timeoutUs);
return AMediaCodec_dequeueInputBuffer(codec->impl, timeoutUs);
}
static int mediacodec_ndk_queueInputBuffer(FFAMediaCodec *ctx, size_t idx,
@ -2308,7 +2214,7 @@ static int mediacodec_ndk_queueInputBuffer(FFAMediaCodec *ctx, size_t idx,
uint64_t time, uint32_t flags)
{
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
return codec->queueInputBuffer(codec->impl, idx, offset, size, time, flags);
return AMediaCodec_queueInputBuffer(codec->impl, idx, offset, size, time, flags);
}
static ssize_t mediacodec_ndk_dequeueOutputBuffer(FFAMediaCodec* ctx, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
@ -2317,7 +2223,7 @@ static ssize_t mediacodec_ndk_dequeueOutputBuffer(FFAMediaCodec* ctx, FFAMediaCo
AMediaCodecBufferInfo buf_info = {0};
ssize_t ret;
ret = codec->dequeueOutputBuffer(codec->impl, &buf_info, timeoutUs);
ret = AMediaCodec_dequeueOutputBuffer(codec->impl, &buf_info, timeoutUs);
info->offset = buf_info.offset;
info->size = buf_info.size;
info->presentationTimeUs = buf_info.presentationTimeUs;
@ -2329,7 +2235,7 @@ static ssize_t mediacodec_ndk_dequeueOutputBuffer(FFAMediaCodec* ctx, FFAMediaCo
static FFAMediaFormat* mediacodec_ndk_getOutputFormat(FFAMediaCodec* ctx)
{
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
AMediaFormat *format = codec->getOutputFormat(codec->impl);
AMediaFormat *format = AMediaCodec_getOutputFormat(codec->impl);
if (!format)
return NULL;
@ -2341,7 +2247,7 @@ static int mediacodec_ndk_releaseOutputBuffer(FFAMediaCodec* ctx, size_t idx, in
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
media_status_t status;
status = codec->releaseOutputBuffer(codec->impl, idx, render);
status = AMediaCodec_releaseOutputBuffer(codec->impl, idx, render);
if (status != AMEDIA_OK) {
av_log(codec, AV_LOG_ERROR, "release output buffer failed, %d\n", status);
return AVERROR_EXTERNAL;
@ -2355,7 +2261,7 @@ static int mediacodec_ndk_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t i
FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
media_status_t status;
status = codec->releaseOutputBufferAtTime(codec->impl, idx, timestampNs);
status = AMediaCodec_releaseOutputBufferAtTime(codec->impl, idx, timestampNs);
if (status != AMEDIA_OK) {
av_log(codec, AV_LOG_ERROR, "releaseOutputBufferAtTime failed, %d\n", status);
return AVERROR_EXTERNAL;