From patchwork Tue Mar 31 08:03:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 18525 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 23B26448C54 for ; Tue, 31 Mar 2020 11:03:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 06D7868AF8E; Tue, 31 Mar 2020 11:03:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40FEB68AF8E for ; Tue, 31 Mar 2020 11:03:35 +0300 (EEST) Received: by mail-wm1-f42.google.com with SMTP id g62so1488740wme.1 for ; Tue, 31 Mar 2020 01:03:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3YQvf+WK40gYFQASGcLey7RJpG9et+G/pMwf/oJWSMU=; b=isqQnRS/5GhG7j3FHFoZeSfGV9xSKPgShENg7gS1BA6XHxE6014gqQdRHzCdRLT//K GIBrw8JqHA4cxACCglRoiVPdSylkGiPnhNtclxYPE8RIXMfiefZ7TfytbHK3nwXXRZoJ mL4yip7/zx6dPC3Zje0zvoDIT0/hLtVamiK1kwCyiS1/v68Ncq3OQvv7GssDxDLpB8pT Mm4K+MFYUuuEdQfU/OBfatdpv0WyUmvLxtUTJ9qnomupg20MDlC7Mr8VVMH4Ptk89dNO bLeXVu0ggoSlMz9wO0GEP7sveEjOU2dcGUob/tBG01bEcRdnq04gZKMujfKcKrOwE/FD XmMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3YQvf+WK40gYFQASGcLey7RJpG9et+G/pMwf/oJWSMU=; b=Z1vjcc0zSJefA5GMAKs4+ud5jg1uoEJLxKf76WD+CN4qw7eEPtXq0WMXvE6WAcx3wD RcYr2LgwkBPM6r4i4CnZ3vGb03dcJwHexm69CBEzM1eRE6+fFLKduamA1ylxzxNWsXas DRPx9F0LEMcDtCfDamS1+cLe6aDRPYIGpbybwp8V8RYAYQJdSS94nR3/aOX3DNacx9ZQ 0hgjOzlZoIUJncfyEyP7loU+5GMPaew+8VmEbhJTRpO1GO0OT+GtAB+wJudxrGwaIzkb kNXYKm6CmIkjE6dU2gb80URj2JqeQwrPB2RqqFk258S/wI29POEcqiWNTFiouAfrwXWK xLUg== X-Gm-Message-State: ANhLgQ18luGCcsTAWYkNXMv6zpOZ5UcVxpEi70Zz2dUN9+hOK3ddqOHa lyz6xa++vQ383bgoMYAZfoP00vEl X-Google-Smtp-Source: ADFU+vuPAC9yiO5BHCSnEp5FSu7wwMIl/ixKK9GYV6lA/d6oNaTPAytMQsGwqZ608bFg/l3gE9NM2w== X-Received: by 2002:a7b:cde8:: with SMTP id p8mr2115371wmj.87.1585641814440; Tue, 31 Mar 2020 01:03:34 -0700 (PDT) Received: from localhost.localdomain (lfbn-idf2-1-500-105.w86-246.abo.wanadoo.fr. [86.246.201.105]) by smtp.gmail.com with ESMTPSA id y200sm2833103wmc.20.2020.03.31.01.03.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 01:03:33 -0700 (PDT) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 10:03:08 +0200 Message-Id: <20200331080308.3472-1-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/mediacodec_common: use MediaFormat to probe frame color characteristics X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Matthieu Bouron Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/mediacodecdec_common.c | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index f0752fa6261..404ed282275 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -85,6 +85,85 @@ #define OUTPUT_DEQUEUE_TIMEOUT_US 8000 #define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US 1000000 +enum { + COLOR_RANGE_FULL = 0x1, + COLOR_RANGE_LIMITED = 0x2, +}; + +static enum AVColorRange mcdec_get_color_range(int color_range) +{ + switch (color_range) { + case COLOR_RANGE_FULL: + return AVCOL_RANGE_JPEG; + case COLOR_RANGE_LIMITED: + return AVCOL_RANGE_MPEG; + default: + return AVCOL_RANGE_UNSPECIFIED; + } +} + +enum { + COLOR_STANDARD_BT709 = 0x1, + COLOR_STANDARD_BT601_PAL = 0x2, + COLOR_STANDARD_BT601_NTSC = 0x4, + COLOR_STANDARD_BT2020 = 0x6, +}; + +static enum AVColorSpace mcdec_get_color_space(int color_standard) +{ + switch (color_standard) { + case COLOR_STANDARD_BT709: + return AVCOL_SPC_BT709; + case COLOR_STANDARD_BT601_PAL: + return AVCOL_SPC_BT470BG; + case COLOR_STANDARD_BT601_NTSC: + return AVCOL_SPC_SMPTE170M; + case COLOR_STANDARD_BT2020: + return AVCOL_SPC_BT2020_NCL; + default: + return AVCOL_SPC_UNSPECIFIED; + } +} + +static enum AVColorPrimaries mcdec_get_color_pri(int color_standard) +{ + switch (color_standard) { + case COLOR_STANDARD_BT709: + return AVCOL_PRI_BT709; + case COLOR_STANDARD_BT601_PAL: + return AVCOL_PRI_BT470BG; + case COLOR_STANDARD_BT601_NTSC: + return AVCOL_PRI_SMPTE170M; + case COLOR_STANDARD_BT2020: + return AVCOL_PRI_BT2020; + default: + return AVCOL_PRI_UNSPECIFIED; + } +} + +enum { + COLOR_TRANSFER_LINEAR = 0x1, + COLOR_TRANSFER_SDR_VIDEO = 0x3, + COLOR_TRANSFER_ST2084 = 0x6, + COLOR_TRANSFER_HLG = 0x7, +}; + +static enum AVColorTransferCharacteristic mcdec_get_color_trc(int color_transfer) +{ + switch (color_transfer) { + case COLOR_TRANSFER_LINEAR: + return AVCOL_TRC_LINEAR; + case COLOR_TRANSFER_SDR_VIDEO: + return AVCOL_TRC_SMPTE170M; + case COLOR_TRANSFER_ST2084: + return AVCOL_TRC_SMPTEST2084; + case COLOR_TRANSFER_HLG: + return AVCOL_TRC_ARIB_STD_B67; + default: + return AVCOL_TRC_UNSPECIFIED; + } +} + enum { COLOR_FormatYUV420Planar = 0x13, COLOR_FormatYUV420SemiPlanar = 0x15, @@ -220,6 +299,10 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif frame->pkt_dts = AV_NOPTS_VALUE; + frame->color_range = avctx->color_range; + frame->color_primaries = avctx->color_primaries; + frame->color_trc = avctx->color_trc; + frame->colorspace = avctx->colorspace; buffer = av_mallocz(sizeof(AVMediaCodecBuffer)); if (!buffer) { @@ -368,6 +451,9 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte int ret = 0; int width = 0; int height = 0; + int color_range = 0; + int color_standard = 0; + int color_transfer = 0; char *format = NULL; if (!s->format) { @@ -426,6 +512,20 @@ static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte ff_set_sar(avctx, sar); } + AMEDIAFORMAT_GET_INT32(color_range, "color-range", 0); + if (color_range) + avctx->color_range = mcdec_get_color_range(color_range); + + AMEDIAFORMAT_GET_INT32(color_standard, "color-standard", 0); + if (color_standard) { + avctx->colorspace = mcdec_get_color_space(color_standard); + avctx->color_primaries = mcdec_get_color_pri(color_standard); + } + + AMEDIAFORMAT_GET_INT32(color_transfer, "color-transfer", 0); + if (color_transfer) + avctx->color_trc = mcdec_get_color_trc(color_transfer); + av_log(avctx, AV_LOG_INFO, "Output crop parameters top=%d bottom=%d left=%d right=%d, " "resulting dimensions width=%d height=%d\n",