From patchwork Tue Sep 3 01:02:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 14875 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 E2FF744A4A6 for ; Tue, 3 Sep 2019 04:10:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD4B0688048; Tue, 3 Sep 2019 04:10:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F56F687FD8 for ; Tue, 3 Sep 2019 04:10:14 +0300 (EEST) Received: by mail-ot1-f68.google.com with SMTP id y39so5048426ota.7 for ; Mon, 02 Sep 2019 18:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SpqswHecjCIICYR+xKjw+PcgWC3dKxQ2SjohzHvrcQc=; b=H/l3U6m0G9iQmkqXZEgRG3T9gFEMZ8AOTBlzA87iUMijC+TwMsvy+8EMgyw2KwzcwB iu1qPNbhXOuCxX5vtORUX9y6jjC6hMXoY+CV3vI5CdZPc+PybRhWcEqKXS8+jRbKCnmH zS+WWfry9MXJbKke/tC3WhGOy3sP0QG3vNtaXCXfnoXZRLFvCqM7hIBxsdj7I9IkiYhg H6IBSuLK0qwjzBRGwLuI140YKJb4JQbn6v8dcHCDlVGDFkhYrWVLfmtLwcp8Yqk7eeIz +aIlPg/QqxhI3jVsMf6OOEjTB1H+kbPNB6btKFkn3U4WhmgnvEuUnJdkruIFagUUu4xC frTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SpqswHecjCIICYR+xKjw+PcgWC3dKxQ2SjohzHvrcQc=; b=NpzqTDJaFyoUIepa5MH1XlsRHBJ+/tCeJHIFMq0Cb5w4sR8KZVX15cknsF77aSNjf5 0Q/07TJ9C2CeR8+jjixsNqzQJ0MW/5a5QX/D8Qp6TcGCq6PLEuYmgF5dqq/D0uWNU4La weAQnReqMmz+7LMKp7fYJq7RKwMvg+VYkukZmiaSeXxzdg8rfSoin56ldL4DV5dtYU+5 a+wPxFCJ2zUfTW7qCjkfX1TAyPsNBy58iBrqb8+txWXZQF+AXa+aqOLfJ2vqQR6cvJL2 v9xU0qS4qq5QKvgobXNjDci/IbrXUzZf0MEt1Vy5j4CEIZMfhkznVPRPsZE0eKRMo9YU rnbg== X-Gm-Message-State: APjAAAWpHI7JBHIBUlxR18vHMOKKm1HNT9W3HiRt02BQ0ghYw8nadMRs v9Op2tzliL1R60PXmoFQ/mL3SeDFO44= X-Google-Smtp-Source: APXvYqwhwCvi4MmRlL4rxnsxmTqah0n8evzKlCKpbGkT/5TMmKxj+syWZLU+nsbvxj4J/U3Wsy+y9w== X-Received: by 2002:a9d:6754:: with SMTP id w20mr20658349otm.82.1567472573849; Mon, 02 Sep 2019 18:02:53 -0700 (PDT) Received: from tmm1-imac.lan (ip184-189-221-177.sb.sd.cox.net. [184.189.221.177]) by smtp.gmail.com with ESMTPSA id a21sm4299633oie.9.2019.09.02.18.02.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Sep 2019 18:02:53 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Sep 2019 18:02:08 -0700 Message-Id: <20190903010230.96236-4-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190903010230.96236-1-ffmpeg@tmm1.net> References: <20190903010230.96236-1-ffmpeg@tmm1.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/25] avcodec/v4l2_m2m: fix av_pix_fmt changing when multiple /dev/video* devices are probed 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: lorusak@gmail.com, Aman Gupta , jorge.ramirez.ortiz@gmail.com, Aman Gupta Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta On the RPI, three different /dev/video devices exist (decoder, scaler, encoder). When probing the devices in order, the originally requested pix fmt would be mutated causing the wrong one to be chosen when a matching device was finally found. Signed-off-by: Aman Gupta --- libavcodec/v4l2_context.c | 4 ++-- libavcodec/v4l2_context.h | 3 ++- libavcodec/v4l2_m2m.c | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c index 070988b4c3..90356bb740 100644 --- a/libavcodec/v4l2_context.c +++ b/libavcodec/v4l2_context.c @@ -623,7 +623,7 @@ int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt) return ff_v4l2_buffer_buf_to_avpkt(pkt, avbuf); } -int ff_v4l2_context_get_format(V4L2Context* ctx) +int ff_v4l2_context_get_format(V4L2Context* ctx, int probe) { struct v4l2_format_update fmt = { 0 }; int ret; @@ -633,7 +633,7 @@ int ff_v4l2_context_get_format(V4L2Context* ctx) if (ret) return ret; - fmt.update_avfmt = 1; + fmt.update_avfmt = !probe; v4l2_save_to_context(ctx, &fmt); /* format has been tried already */ diff --git a/libavcodec/v4l2_context.h b/libavcodec/v4l2_context.h index 632f1d0aac..ee08f3de41 100644 --- a/libavcodec/v4l2_context.h +++ b/libavcodec/v4l2_context.h @@ -113,9 +113,10 @@ int ff_v4l2_context_set_format(V4L2Context* ctx); * Queries the driver for a valid v4l2 format and copies it to the context. * * @param[in] ctx A pointer to a V4L2Context. See V4L2Context description for required variables. + * @param[in] probe Probe only and ignore changes to the format. * @return 0 in case of success, a negative value representing the error otherwise. */ -int ff_v4l2_context_get_format(V4L2Context* ctx); +int ff_v4l2_context_get_format(V4L2Context* ctx, int probe); /** * Releases a V4L2Context. diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c index 0cf5db284a..827662b9a5 100644 --- a/libavcodec/v4l2_m2m.c +++ b/libavcodec/v4l2_m2m.c @@ -108,13 +108,13 @@ static int v4l2_probe_driver(V4L2m2mContext* s) if (ret < 0) goto done; - ret = ff_v4l2_context_get_format(&s->output); + ret = ff_v4l2_context_get_format(&s->output, 1); if (ret) { av_log(s->avctx, AV_LOG_DEBUG, "v4l2 output format not supported\n"); goto done; } - ret = ff_v4l2_context_get_format(&s->capture); + ret = ff_v4l2_context_get_format(&s->capture, 1); if (ret) { av_log(s->avctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n"); goto done; @@ -222,7 +222,7 @@ int ff_v4l2_m2m_codec_reinit(V4L2m2mContext* s) ff_v4l2_context_release(&s->capture); /* 3. get the new capture format */ - ret = ff_v4l2_context_get_format(&s->capture); + ret = ff_v4l2_context_get_format(&s->capture, 0); if (ret) { av_log(s->avctx, AV_LOG_ERROR, "query the new capture format\n"); return ret; @@ -273,13 +273,13 @@ int ff_v4l2_m2m_codec_full_reinit(V4L2m2mContext *s) s->draining = 0; s->reinit = 0; - ret = ff_v4l2_context_get_format(&s->output); + ret = ff_v4l2_context_get_format(&s->output, 0); if (ret) { av_log(log_ctx, AV_LOG_DEBUG, "v4l2 output format not supported\n"); goto error; } - ret = ff_v4l2_context_get_format(&s->capture); + ret = ff_v4l2_context_get_format(&s->capture, 0); if (ret) { av_log(log_ctx, AV_LOG_DEBUG, "v4l2 capture format not supported\n"); goto error;