From patchwork Fri Feb 24 08:59:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 40489 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1074122pzk; Fri, 24 Feb 2023 00:59:51 -0800 (PST) X-Google-Smtp-Source: AK7set+0yw/oj+Jo5BGUCMXzK5NXnBOY6GU8NouOAyyqsgIj24BVryiSb11+5flE38qgvrP1tShV X-Received: by 2002:a17:907:2cd7:b0:8de:e66a:ece9 with SMTP id hg23-20020a1709072cd700b008dee66aece9mr11254817ejc.24.1677229190972; Fri, 24 Feb 2023 00:59:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677229190; cv=none; d=google.com; s=arc-20160816; b=tca8Dx0Q/9QXSez2Zkk86DnKcjbMiML32eHvVWi5GzgRfR5cp4xDAA7/JwenGuDngf jNCa7Dwnm3YWwMMrkFKTIFUx3M9qF22cgs3jMAWwuDTMD1+FRIk+xjKyw+K0bgvY8t8/ MPZMHoXnofgDupoZUWDoLyZkT01iKoQSncCdGeXIMibwrsz3Ky+xwBPQ0G5i/3/3eQAw akbHlFqTqw91ytHdvfFnWYz2dCuAUnDxECnvU/JE0U/PJyVOXHx+FpycVHtR4nthfNgp QN5p+LcDE9v5nWW+vvOqV4ruNAgrsaao7joVgQJp4YFCXWBGr+dclwwHDhl/XMfU6IEP 0Bhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:date:to:from:message-id:delivered-to; bh=PWmI66qNh8TlZzF/2lTsO/td89gFLGPxH5kFREZBpv4=; b=WsssfqXANVqKPXfhVgCKFkq0ycocT0Nj8FhfiSX+Sa1ow934/fmMKomwck+6+udC23 oZDLxLOM9iJH6kUQcf73JeD68IibGhTYBqZrCQiLPy8oe3oSebB4fODnukhqDKUjMuGs KSvb7WrZW7P1ec8+NVvIE1O5LVKfbg445o2lR4vgfS+kJWv5MtqMNOVkDCludpKHzf2y 1gbA77iSoQ2a39rshLjZguw4U5cJNxeu/WAC3dkIR27F1209jtTNbrNn3GSiMWYK9GYy 01IzQoLvDVGksSl9+W3QgsNPdeYhCEd5Ymz+FhsfVFfaCRb7bISI5C4vHeeT019JA0J7 Koug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id if9-20020a170906df4900b008c8f5756068si15661420ejc.766.2023.02.24.00.59.50; Fri, 24 Feb 2023 00:59:50 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B421468C10C; Fri, 24 Feb 2023 10:59:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.frobbit.se (mail.frobbit.se [85.30.129.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B19D368BED2 for ; Fri, 24 Feb 2023 10:59:39 +0200 (EET) Received: from [10.10.150.69] (1346516434.ip.84grams.net [134.65.164.34]) by mail.frobbit.se (Postfix) with ESMTPSA id 8301221BA9 for ; Fri, 24 Feb 2023 09:59:38 +0100 (CET) Message-ID: From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Fri, 24 Feb 2023 09:59:37 +0100 User-Agent: Evolution 3.38.3-1+deb11u1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] lavc/mediacodecenc: Add pix2color_fmt() and color2pix_fmt() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Mz/plo9wepSE From 7374dab21cb37dc14d2481c72d333b435e23a76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Tue, 10 Jan 2023 20:37:18 +0100 Subject: [PATCH 1/4] lavc/mediacodecenc: Add pix2color_fmt() and color2pix_fmt() This patch has been released by Epic Games' legal department. --- libavcodec/mediacodecenc.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c index a92a8dc5a9..03c80cbf99 100644 --- a/libavcodec/mediacodecenc.c +++ b/libavcodec/mediacodecenc.c @@ -2,6 +2,7 @@ * Android MediaCodec encoders * * Copyright (c) 2022 Zhao Zhili + * Modifications by Epic Games, Inc., 2023. * * This file is part of FFmpeg. * @@ -110,6 +111,26 @@ static void mediacodec_output_format(AVCodecContext *avctx) ff_AMediaFormat_delete(out_format); } +static int pix2color_fmt(AVCodecContext *avctx, enum AVPixelFormat pix_fmt) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) { + if (pix_fmt == color_formats[i].pix_fmt) { + return color_formats[i].color_format; + } + } + av_assert0(0); +} + +static enum AVPixelFormat color2pix_fmt(AVCodecContext *avctx, int color_format) +{ + for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) { + if (color_format == color_formats[i].color_format) { + return color_formats[i].pix_fmt; + } + } + av_assert0(0); +} + static int mediacodec_init_bsf(AVCodecContext *avctx) { MediaCodecEncContext *s = avctx->priv_data; @@ -235,13 +256,7 @@ static av_cold int mediacodec_init(AVCodecContext *avctx) } } - for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) { - if (avctx->pix_fmt == color_formats[i].pix_fmt) { - ff_AMediaFormat_setInt32(format, "color-format", - color_formats[i].color_format); - break; - } - } + ff_AMediaFormat_setInt32(format, "color-format", pix2color_fmt(avctx, avctx->pix_fmt)); if (avctx->bit_rate) ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate); -- 2.30.2