From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7469844022 for ; Wed, 23 Nov 2022 16:50:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9025068B607; Wed, 23 Nov 2022 18:50:03 +0200 (EET) Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB12968B103 for ; Wed, 23 Nov 2022 18:49:55 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1669222191; bh=DGq4GusJ7UaSv+8bvRicTF2GdY3s7xmKYlSSABbEQNs=; h=From:To:Cc:Subject:Date; b=b3wp7HNFoYkWW0GugsVW3x6w5E7Pfpu/x5l35rHVezjBLnAyRIyz5FYZPkAO28Jnl Uq0fL90KtKCrb7hXfFj0y0Bsj5FUZdYqWD3fjq/45m+F4A2KjR1Ps1xkbqtlt0DJcd 474AnRow1RaI+YPhD9lZ6DozQxHCXZRqX/IgzBLE= Received: from localhost.localdomain ([113.118.113.114]) by newxmesmtplogicsvrszc1-0.qq.com (NewEsmtp) with SMTP id C7281E6D; Thu, 24 Nov 2022 00:49:50 +0800 X-QQ-mid: xmsmtpt1669222190tegqd8ydd Message-ID: X-QQ-XMAILINFO: MK5U7QanZrCw8GyQ3q0yE+2wszmR36w8rUi/E6lg2Gdx2UZHr4FMKjJKFyHV+8 moRG0T7DzPd9ZodbhUquUiui1/x5tT02puIPo9kfkDB4+DzrS1RlYxNo4mefmmFjv1OW2cZdAoHI Si2+BLjJ2XuZyfPvWRRGmiphl6MeaKoNsc8Xh5EC4+etZalMsnO8iaCPhkvbn6VGCP6lVbh1uDB7 zFG7XvWNLSATQejDjxHdCxIlLVCMytAqsEH2LnfLBuF0qogW0Vziuwdktz03FrCy/UwtIfU8euBI qt13hKi7TDXSeDqXpTyaDKkZp4k/jrRiA4Meyi6sQezrtmDintOrFSBOk5jRtxgXOK0S9kBACqoN iEqqCA+VeKiKFMPWXSMM7UVKjqYXzylDImyAmY+LmBzsqw5AWLR4zSQPJbMqLv6KRDsHol5uJ+IF BMUzyanICruJFOXbTWE0q7jvI5yldcIBQmr+zpbcB38R2KAlMvwqEGZbIqsw7EkxJaV1gye+p/4h UXumsOWgu/ds2412oQOVPlS6Yr9/tpAPPNQhRq6o/hfihD4Kk+e8vzg6U6RXTDg9Dw4aGWkgWAhy 8h5RcbAlSBf5kZwhVrnFIfT5nBuOjYIM8Um1yivrZVLXjboM9ySYD9It5Gzxhl+EBUayO8XAVVWT mpijqtAQhYgHrhYCTonNNAtLdeNuIo1PqZIhTJkUAmy0eXY9JBLdCin+c3z6I5DZFAdUlxE3TZVZ nPBLFNeq6QWHMbI7EmNcUbRprf1qL741hfyNy8RJ6BoZ0W6id+RLq1xU8ZVG0l0wvaB5+8N/rD4U 60+iGYzk7LNACpZ04EF8S335IS1L8J/wYldvCyAGf7Q49I2oek3DAloV6Oo+RdO+kxyh1bB2BgCG hGuIXrOX0+CyhAYfX8cM2rV7WJaE+xB2KjxJG9Sy4OHFOY0FYC25V7OZxpATonZ1OJR3BsHJTUrW 6pztY2knVDzfqXEZqGtg== From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Nov 2022 00:49:25 +0800 X-OQ-MSGID: <20221123164926.25481-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/mediacodec: fix missing crop info when use NDK MediaCodec X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili --- libavcodec/mediacodec_wrapper.c | 38 ++++++++++++++++++++++++++++--- libavcodec/mediacodec_wrapper.h | 24 +++++++++++++++++++ libavcodec/mediacodecdec_common.c | 4 ++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c index 555058e907..193eac8da6 100644 --- a/libavcodec/mediacodec_wrapper.c +++ b/libavcodec/mediacodec_wrapper.c @@ -1861,12 +1861,16 @@ typedef struct FFAMediaFormatNdk { 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; typedef struct FFAMediaCodecNdk { @@ -1940,9 +1944,12 @@ static FFAMediaFormat *mediaformat_ndk_create(AMediaFormat *impl) if (!format->libmedia) goto error; -#define GET_SYMBOL(sym) \ - format->sym = dlsym(format->libmedia, "AMediaFormat_" #sym); \ - if (!format->sym) \ +#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) @@ -1956,14 +1963,17 @@ static FFAMediaFormat *mediaformat_ndk_create(AMediaFormat *impl) 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; @@ -2047,6 +2057,15 @@ static int mediaformat_ndk_getString(FFAMediaFormat* ctx, const char *name, cons return ret; } +static int mediaformat_ndk_getRect(FFAMediaFormat *ctx, const char *name, + int32_t *left, int32_t *top, int32_t *right, int32_t *bottom) +{ + FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx; + if (!format->getRect) + return AVERROR_EXTERNAL; + return format->getRect(format->impl, name, left, top, right, bottom); +} + static void mediaformat_ndk_setInt32(FFAMediaFormat* ctx, const char* name, int32_t value) { FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx; @@ -2077,6 +2096,17 @@ static void mediaformat_ndk_setBuffer(FFAMediaFormat* ctx, const char* name, voi format->setBuffer(format->impl, name, data, size); } +static void mediaformat_ndk_setRect(FFAMediaFormat *ctx, const char *name, + int32_t left, int32_t top, int32_t right, int32_t bottom) +{ + FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)ctx; + if (!format->setRect) { + av_log(ctx, AV_LOG_WARNING, "Doesn't support setRect\n"); + return; + } + format->setRect(format->impl, name, left, top, right, bottom); +} + static char *mediacodec_ndk_getName(FFAMediaCodec *ctx) { FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx; @@ -2433,12 +2463,14 @@ static const FFAMediaFormat media_format_ndk = { .getFloat = mediaformat_ndk_getFloat, .getBuffer = mediaformat_ndk_getBuffer, .getString = mediaformat_ndk_getString, + .getRect = mediaformat_ndk_getRect, .setInt32 = mediaformat_ndk_setInt32, .setInt64 = mediaformat_ndk_setInt64, .setFloat = mediaformat_ndk_setFloat, .setString = mediaformat_ndk_setString, .setBuffer = mediaformat_ndk_setBuffer, + .setRect = mediaformat_ndk_setRect, }; static const FFAMediaCodec media_codec_ndk = { diff --git a/libavcodec/mediacodec_wrapper.h b/libavcodec/mediacodec_wrapper.h index f15ad66d83..1b81e6db84 100644 --- a/libavcodec/mediacodec_wrapper.h +++ b/libavcodec/mediacodec_wrapper.h @@ -73,12 +73,18 @@ struct FFAMediaFormat { 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); + // NDK only, introduced in API level 28 + int (*getRect)(FFAMediaFormat *, const char *name, + int32_t *left, int32_t *top, int32_t *right, int32_t *bottom); 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); + // NDK only, introduced in API level 28 + void (*setRect)(FFAMediaFormat*, const char* name, + int32_t left, int32_t top, int32_t right, int32_t bottom); }; FFAMediaFormat *ff_AMediaFormat_new(int ndk); @@ -118,6 +124,14 @@ static inline int ff_AMediaFormat_getString(FFAMediaFormat* format, const char * return format->getString(format, name, out); } +static inline int ff_AMediaFormat_getRect(FFAMediaFormat *format, const char *name, + int32_t *left, int32_t *top, int32_t *right, int32_t *bottom) +{ + if (!format->getRect) + return AVERROR_EXTERNAL; + return format->getRect(format, name, left, top, right, bottom); +} + static inline void ff_AMediaFormat_setInt32(FFAMediaFormat* format, const char* name, int32_t value) { format->setInt32(format, name, value); @@ -143,6 +157,16 @@ static inline void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* format->setBuffer(format, name, data, size); } +static inline void ff_AMediaFormat_setRect(FFAMediaFormat* format, const char* name, + int32_t left, int32_t top, int32_t right, int32_t bottom) +{ + if (!format->setRect) { + av_log(format, AV_LOG_WARNING, "Doesn't support setRect\n"); + return; + } + format->setRect(format, name, left, top, right, bottom); +} + typedef struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo; struct FFAMediaCodecBufferInfo { diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 80089439ea..03bee11918 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -486,6 +486,10 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte AMEDIAFORMAT_GET_INT32(s->crop_left, "crop-left", 0); AMEDIAFORMAT_GET_INT32(s->crop_right, "crop-right", 0); + // Try "crop" for NDK + if (!(s->crop_right && s->crop_bottom) && s->use_ndk_codec) + ff_AMediaFormat_getRect(s->format, "crop", &s->crop_left, &s->crop_top, &s->crop_right, &s->crop_bottom); + if (s->crop_right && s->crop_bottom) { width = s->crop_right + 1 - s->crop_left; height = s->crop_bottom + 1 - s->crop_top; -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".