From patchwork Thu Aug 19 08:55:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 29614 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp107810iov; Thu, 19 Aug 2021 01:56:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr4QSMnX6Zr2AZWvu3DhrxGrMmJ+nORAVqowtZ/BNmJg6ra5BWQNPF8HASslMhcYYDhBGs X-Received: by 2002:a50:d4cf:: with SMTP id e15mr15169788edj.2.1629363383819; Thu, 19 Aug 2021 01:56:23 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f11si2475780edl.305.2021.08.19.01.56.21; Thu, 19 Aug 2021 01:56:23 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@nxp.com header.s=selector2 header.b=c4e9LqpP; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7DB0A68021B; Thu, 19 Aug 2021 11:56:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2076.outbound.protection.outlook.com [40.107.22.76]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44D3C68021B for ; Thu, 19 Aug 2021 11:55:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F/S+6G1yGvgs01ui/YTbPBl2eUO6PqDvJZarMdIE3wwTPPr74GMpchC6/WyGAXVtSta84ZkVjcPaL8O7mjuJw28JecPdKtEJU2RPx7bFMEJWtl2Mfufe61nA/bBOk+vqS0ClsdFJPhXGmEeTkMdhckAoOIGVxIQ8XAekuhNG6OLFseCQcURGIysWOkdDUTL3Mu2VYbWq6VjcZXB6EoWgHMxUwHjHwoJw5ABtpesRLD+klZMNYc8ONl+pKuMm91vwAWW/uVTkDGSh4cg8x43bOpXl+UMa0UnEX+IYeTvoMvx6/v7emQXnxUK7ixx2psxHAE6IXFeZzCQE6ucA3hdbZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qI1ucDM0lKq28ISOnN4u6O0mdX9bIdASDtFdjfMKbYo=; b=cInx5spmOnpS5sZGMzDNHl1a+gRlU2GCL6K6G7L4Oc6KC9qSWgcAULeBt8CWo5AKH+6FrzBoXdBKQuOJ21il2q+REVM7amiiNS2/81WCWJmbs8dmXlTzIcVMdRHCGdIstfb83W+ywQ+UnYmrArU73tgc+p8TGFA4GafS2AywLUCnPhvOHynAT8UfbX86J4KNHxWoSRymRBK/Lfld+Y6h6MJQtaw5MN4GldysvWhuc41iCeMIpu1lgp88nAMHLZffTNU0l3ziDReG0udJvoYzMPKRD1nioXRF6Td3a1LNm2cPyV+nBZOC2u9dyfZ3xUDV1JPlZ4snKWqUc7wf8W+Dng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qI1ucDM0lKq28ISOnN4u6O0mdX9bIdASDtFdjfMKbYo=; b=c4e9LqpPfdoJRC5u+PRSB5F3y1bi4KaUMAXVNO8kku49BmywVO4FUhihilvOHkMXDqF82B25efuASULJ/AI6lOc2AyOZYjpfoycDE0JlBPaZ2g8tgxetadK4XDCpQ0KegJAL/iTyC7fLIX9H3TnQW1BReEU7SfFVhHFaTcJoOng= Authentication-Results: ffmpeg.org; dkim=none (message not signed) header.d=none;ffmpeg.org; dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by AM6PR04MB4791.eurprd04.prod.outlook.com (2603:10a6:20b:3::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.21; Thu, 19 Aug 2021 08:55:52 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::9cb5:bd97:8500:2384]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::9cb5:bd97:8500:2384%6]) with mapi id 15.20.4415.024; Thu, 19 Aug 2021 08:55:52 +0000 From: Ming Qian To: ffmpeg-devel@ffmpeg.org Date: Thu, 19 Aug 2021 16:55:33 +0800 Message-Id: <20210819085533.1174-3-ming.qian@nxp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210819085533.1174-1-ming.qian@nxp.com> References: <20210819085533.1174-1-ming.qian@nxp.com> X-ClientProxiedBy: SG2PR02CA0006.apcprd02.prod.outlook.com (2603:1096:3:17::18) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv11149.swis.cn-sha01.nxp.com (119.31.174.70) by SG2PR02CA0006.apcprd02.prod.outlook.com (2603:1096:3:17::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Thu, 19 Aug 2021 08:55:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f566e03a-851f-4a3a-954e-08d962ef25b8 X-MS-TrafficTypeDiagnostic: AM6PR04MB4791: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2803; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tFc6xCluXLPNujRqZQxA/FzZ0AeasHUowqkR1rNTopySOWUgIKl9c1asFhQ6Sg7o8pfiGwwL/Oi4IgeKIa92Ch3FMc01Np1KJQ/ZGR/TRa4Ror1J9S+iB1KaySiupphS8os6+1yrTQ/KyrpvPHLAQ0BHStA0wXImPOn1PZi34dz3pedAP7XyeEkPkH8Ph92nMnGrd+GTP/zFnQoVvATzNcbazlQzBN0jJIaE2ZSXu3RVypFW3MEshAOiQSnnK6Nfl8jUsjBpTgJtcoIFLElLK5nkV4AF39BYcAIPaddo0mpS54VCcy8mmpAzgs6YSjrTsZR27GO77/XiXN039tbkVHJDE6npvxr1OiQIuT76Cb8MqHi16tmVradpnV5kR4a4M+msaYqXBLdUAovF++NvEsV+9pu5mFkUuC0cyya5iH/ORtqAbbe1iRppmbp2rFy7dkMB9RFXGQkdhKuteJ9CtdRMpmijw7sTKVvqKNST8e+8l8w5w9nK2SM4H7vXKrFQPy+t0vkMRLIptG4XRY5msRB8ZxUGyPERSuj0monjshtOl3EwSMBhtv6uPcWOQIW1a9SI1Uhu9bZE4Kep8HmyN+0oZfk6TreGWTi3XiC2SEd2A+/jcmnq6SzFhKuQEPdmS/V7P/EWekAsvC4PafbPpN5lP0LKrbNWavF2tw91P6gNmRS12AHYeuhAlNgLYnAfxKMIQwsEljKhKX+PQsFpdouirl9TGQD7I7KWp+DcLQ0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39860400002)(346002)(376002)(396003)(136003)(186003)(66476007)(66556008)(6666004)(1076003)(38100700002)(86362001)(8936002)(66946007)(6916009)(5660300002)(316002)(26005)(83380400001)(478600001)(2616005)(38350700002)(956004)(2906002)(44832011)(7696005)(8676002)(36756003)(52116002)(6486002)(70780200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YoYP+YKzzl0DnRWd8DTX6K4m3+ryoZ7TAPT3mhecMBrtlPMPaOFYhtxcK0/Eo4H75ULTXVg3qkhmYOsbU2rGHLRPdg2UJjYg0X23THKznBIOfwwKdCUVfSoj/O2ODr2cs4xkhiYumElof8OeRPNufyyhbXwXy5WM5XozBkjmXZ/skldHanRkjw/0rMDbckiueYerB6mxSNyqdKvqBcCmew/lXwx/Bnut7ekXqgjlnQTwPT2+kcaSp6CZmx20fvtCb4P/Al4uD7pIvfJmERk4wWUkVoHb6zbW3RP14WDIFTbE/H9XTKPz9QEnzYJgywWokWsf2Gbkrx8DjVafZ96DsEKIldzTdsGaF2TV2qCqZqt9sN6o7R+eseWEPHzQ6eheCBKyMTdBDBnlflMuRsaDOxSNwi82Ge/puadNmZWqNkI01gS5+eMVtxPvtM6LsYs6a0rdNmjrbFQSm+cx01GEzEKeP/UdZPsrtDAA827ZzBJLRD3ngfsdyZ5zP+LySOh2GaptPCkG6q1B18OwTzc1gUJsi20jtfJaZRZb9pZ1mqQ3BzOKpSr171fRsDNJHglplsXXZ4pQ6Y8N0Yq44Wvgmd/+2tFAjMFNVysXkBAdZYhD0FU9g6fqKMteLbYG9JHkbtbDYo2Pa4OlsHZOyghGH0KoSsg2Is4svh4kuToR/UEJ659wk814nIobj6BjTMAwZy9OR17sDLLtmE4iVNMcRvGuj1PIvILKZEG0eaBvgRMzjDVpNImVBfY/Idwvb5DIVcJ8YMsBgbCIPZqMY7l1NnRHiGsO0ULaGOjUrw9TWi9cmga/OB1riFw9iP5YFC8rzGbBFRgCjb1ONIjsvZnHkQ0dxgQFl++jR5/LzqfoBWnoiSZd1xzotaCijy42baLfZhvNAXUIGQcJ/0aqMfa0z0/fs+pxwXo9UGaxEBFCenAPd8tuSZeM1t9Ni0JK5JCXjhdj3VCMOlcrLKXOr0EHCwpOn07zoOD55oe31LaW+j8eavFBK857YwpKdcUxg/IYwfxhBXbSvh6RjivUm/e9GVeFhegW8VnlVnlLZxRWCjDlpJGRPbH4u/wWiTXPLsxfkB7NW5VKpjFxL8NK3PxYBwGqXwo8NzOeb8B5eQQu1lrBk4Vn7UDeNDf0yOUyNVhZ/dibfekWgcBSxbnry1prAdzJM0I7D4R1MQpYRYdDAxrekj4C0+HZZfYM18A4fnrzt0B+koAledMywKiDGlz0DncCmyP2HyUCKudF19CmriMYy6475QAe6TzlkJdr8pb2HJdU3REq0UcegndL7fN1kPlFxXstkUfcq9HbR/20cs4NSP8YVC+FuaQX/bShK2gR X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f566e03a-851f-4a3a-954e-08d962ef25b8 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2021 08:55:52.0644 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ikBEueJ1Qk7euNhT6cien2BnZVZ+ixjlSifK3flTeG2OQiDEsDsuiDKvtmKHiuo7l//WDi5eziZox5rCU7NaiA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4791 Subject: [FFmpeg-devel] [PATCH v4 3/3] avcodec/v4l2_m2m_dec: setup capture queue before enqueue the first frame 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: o6qESZMijMoZ there are two proper ways to setup capture queue. 1. client wait the source change event, then setup the capture queue and streamon 2. client setup the capture queue in advance, but to avoid time issues, client should start the capture queue before it enqueue the sequence header to decoder driver through output queue. and the sequence header is always in the first frame, so client should start capture before enqueue the first frame. ffmpeg use the method 2 to setup capture queue, but currently ffmpeg enqueue the first frame before starting the capture queue. so in driver side, there are time issues. when driver has parsed the resolution from sequence header, but the client may not finished setup the capture. so driver can't decide whether to notify a source change event to client. and the following flow may be chaotic. And it's OK that client setup capture queue first, then enqueue the first frame. Signed-off-by: Ming Qian --- libavcodec/v4l2_m2m_dec.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c index 224eb3d5e7be..6b936b6df2a9 100644 --- a/libavcodec/v4l2_m2m_dec.c +++ b/libavcodec/v4l2_m2m_dec.c @@ -149,6 +149,14 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (s->draining) goto dequeue; + ret = v4l2_try_start(avctx); + if (ret) { + /* can't recover */ + if (ret != AVERROR(ENOMEM)) + ret = 0; + goto fail; + } + ret = ff_v4l2_context_enqueue_packet(output, &s->buf_pkt); if (ret < 0 && ret != AVERROR(EAGAIN)) goto fail; @@ -157,16 +165,6 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (ret != AVERROR(EAGAIN)) av_packet_unref(&s->buf_pkt); - if (!s->draining) { - ret = v4l2_try_start(avctx); - if (ret) { - /* cant recover */ - if (ret != AVERROR(ENOMEM)) - ret = 0; - goto fail; - } - } - dequeue: return ff_v4l2_context_dequeue_frame(capture, frame, -1); fail: