From patchwork Fri Dec 27 23:38:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 17011 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 2FD2D4488B5 for ; Sat, 28 Dec 2019 01:38:57 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0ED2968AC2C; Sat, 28 Dec 2019 01:38:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 01E8568AB32 for ; Sat, 28 Dec 2019 01:38:49 +0200 (EET) Received: by mail-ot1-f66.google.com with SMTP id b18so16288019otp.0 for ; Fri, 27 Dec 2019 15:38:49 -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=fuUfojRz708hVYR9bSiV3fQ01P3mhkC0u0/roE4bUKE=; b=HWf32h6ttjvwkmZxQKC0bfiaVyUxljz9EQULZmmr5CTKnCmZiygoP/SjzkDLVkd4mk i1yERSbr77amjbglQAvBNmn4MyXIHh21GYM1kDUCeQxNXXS31MUoVmYU6BAs/J/VFUeA pT6H5aAaJu0VVIfg7fjzTz4slZwvzjfCikLGw/jGMoXAT/XChjEczwFp4UQMVofGnCH8 8d9+wSuqRVIz09o/hVuGd6ltGsSIpGySKpmKFBd/viWPeduBi/dgfPGGFKnbdXGX/Nlq 6wBky8K5WztTUcYHzSt8EgNiPgOo162noVzau8RCS0DUgOhcRhzjns3ybb4Ft9ftzS9H B5Fg== 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=fuUfojRz708hVYR9bSiV3fQ01P3mhkC0u0/roE4bUKE=; b=mo828GdXijNnFzkq5QwX9e890ScANuCT/DDJHVMVcHaIfe9pKy0Tk+Q0HHsrv9yIy1 vPOcWycnWhzUbBwn2m9mWG5cdehKcc6TyEnqjxjfWHvkRvbXwzqIZGZJ6nCrCl4gkZOM nIOGznp+jmj1gJvJFpJhA/DatmGOJqf6jSGGsTCAAiMIMURaL9nLHIrcALFY3y34ItkZ j+7PFDuLVW7ShyLXpP3XFG/QpY+DVy86iwjOJN0hiMSYtZ8M6cVSb/w0QlhOtGUgVE8z b1wp6JNaVckAotSk6iy0zPlNcxpmJbvzgafuKfTPI+dOZkUaDklYnX6Y24dKDU8kfdYl HaUA== X-Gm-Message-State: APjAAAVBMwiZpaANSeL5+VDD98YPnBGBL8HIUC6VYg5SDHTzVZvEUuqI qmy+nBGAQdeFwd+UlPDRpAkjJnPt X-Google-Smtp-Source: APXvYqyUMOwgU2nFVhajIsZFhCdZeBVqLzyXr8qeQ791GGSHGl72hRSd+fzV7TI+KhhSvh41FSxkyQ== X-Received: by 2002:a05:6830:4d9:: with SMTP id s25mr59749557otd.171.1577489928374; Fri, 27 Dec 2019 15:38:48 -0800 (PST) Received: from manj.guest.slb.com ([192.23.22.48]) by smtp.gmail.com with ESMTPSA id l82sm10735756oib.41.2019.12.27.15.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2019 15:38:47 -0800 (PST) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Dec 2019 18:38:35 -0500 Message-Id: <20191227233835.9391-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] 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(+) Changes in v3: - Use main encoder context for logging instead of the private one diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index 474e6bef897..8059e3bb48f 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(avctx, AV_LOG_ERROR, "Encoder requires %s pixel format.\n", desc->name); + return AVERROR(EINVAL); + } + return v4l2_prepare_encoder(s); }