From patchwork Wed Nov 13 03:46:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 16239 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 A4E1F4482D7 for ; Wed, 13 Nov 2019 05:46:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F71C68A9BE; Wed, 13 Nov 2019 05:46:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A89D368A5FA for ; Wed, 13 Nov 2019 05:46:19 +0200 (EET) Received: by mail-qt1-f194.google.com with SMTP id o49so1053046qta.7 for ; Tue, 12 Nov 2019 19:46:19 -0800 (PST) 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=NnVz0gJP12ZQyOQIYZZc6suA1cmHVRvWJ9ZDwZfMe5M=; b=sWJjbvTteRSgoSYvjBPpRdjMvqmq7hAUq74XOGTP2hZiDqih9bnE6tCkDUY07TQD15 CniHTOv1oFpHzQqDcw7gTRSV8NGNk2bJQxyWJ45XyqezxJgRxWCIi4vg9xfusxxUp3bU W4yM17m00W4e17hdwceqR4ODM43scZY4Bf81H7br59Gt1VQIrrisFzlIXG5NKWYpapEE Lywhuva8RHP/EslCAir8EZUj/Kg3rSBUOQaTl9QHQKT0hLc7g9SlNMBoUGFfgajE/59D tbZqH8Ey3SRz8pMMmr29adBh5GcmbNk+84H/mgzZEU2iLi5F/nfxnG3QIkxCTOh5oouj jrTw== 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=NnVz0gJP12ZQyOQIYZZc6suA1cmHVRvWJ9ZDwZfMe5M=; b=bojHh/MUs7psy0uOV9fxvCfEJAlfzgaXhnkCcYbPJWQE67a6NfQCqEgeEVvcfCEdLF dpcpQoXvexjgQktvqxd3qEk0W5OJES8g70TsoRoFWk692VeJWQUzr6KFsqKpBnXKNHFS /hL3lGk6ZI4KJ3LeqBJlSQFGy3J3EPpELPexkvTSfJkFS0GvCO6FQQQJ0JrHp9XKaVtI CDHuKCKgho9LPsF7uwVSP/QrvJFyGhmqXYWVLlOi2VYROYzxzX8VqyBgRsXPajUsSFVQ 9xtzbso5KRZDX7Tasc6Y0HlIFfGt9F56uybc6lEy5sAlVRhxKDI9/WxTa9TzV2CgHxog Brpw== X-Gm-Message-State: APjAAAVtG3ubM7Uido6mKqRElW4YXwRC2yftNihegvFiZD0HbO7gsVSE /Hv0cfZdk9U1XXNWPBpXpYOsKACC X-Google-Smtp-Source: APXvYqwd5DmtkJXNFXWojOcZVpQ2hLJaLaTTuICEDKSJGLNW5IEZSjY9v9vTdYacfmmnfgxRz0VRxQ== X-Received: by 2002:ac8:f6a:: with SMTP id l39mr731895qtk.145.1573616778009; Tue, 12 Nov 2019 19:46:18 -0800 (PST) Received: from localhost.localdomain (c-71-232-27-28.hsd1.ma.comcast.net. [71.232.27.28]) by smtp.gmail.com with ESMTPSA id t26sm566534qta.75.2019.11.12.19.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 19:46:17 -0800 (PST) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Nov 2019 22:46:02 -0500 Message-Id: <20191113034602.32578-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avcodec/v4l2_m2m_enc: Check encoder pix_fmt matches pix_fmt on device 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: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Fixes #8079 During initialization of a v4l2m2m device, the configured pix_fmt can be different to the pix_fmt of the encoder (i.e. avctx->pix_fmt). For example on the Odroid XU4: ./ffmpeg -f lavfi -i yuvtestsrc -codec:v h264_v4l2m2m out.h264 will configure the v4l2 encoder to pix_fmt nv21, whereas the input frames will be yuv444p. This commit checks that the configured v4l2 pix_fmt on device is the same as avctx->pix_fmt. If they are different the initialization fails and an error is returned. Tested on RPI4 and Odroid XU4. Signed-off-by: Andriy Gelman --- libavcodec/v4l2_m2m_enc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index 474e6bef897..c0e82afe354 100644 --- a/libavcodec/v4l2_m2m_enc.c +++ b/libavcodec/v4l2_m2m_enc.c @@ -30,6 +30,7 @@ #include "libavutil/opt.h" #include "v4l2_context.h" #include "v4l2_m2m.h" +#include "v4l2_fmt.h" #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x #define MPEG_VIDEO(x) V4L2_MPEG_VIDEO_##x @@ -288,6 +289,8 @@ static av_cold int v4l2_encode_init(AVCodecContext *avctx) V4L2Context *capture, *output; V4L2m2mContext *s; V4L2m2mPriv *priv = avctx->priv_data; + enum AVPixelFormat pix_fmt_output; + uint32_t v4l2_fmt_output; int ret; ret = ff_v4l2_m2m_create_context(priv, &s); @@ -316,6 +319,18 @@ static av_cold int v4l2_encode_init(AVCodecContext *avctx) } s->avctx = avctx; + if (V4L2_TYPE_IS_MULTIPLANAR(output->type)) + v4l2_fmt_output = output->format.fmt.pix_mp.pixelformat; + else + v4l2_fmt_output = output->format.fmt.pix.pixelformat; + + pix_fmt_output = ff_v4l2_format_v4l2_to_avfmt(v4l2_fmt_output, AV_CODEC_ID_RAWVIDEO); + if (pix_fmt_output != avctx->pix_fmt) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt_output); + av_log(priv, AV_LOG_ERROR, "Encoder requires %s pixel format.\n", desc->name); + return AVERROR(EINVAL); + } + return v4l2_prepare_encoder(s); }