From patchwork Thu Sep 16 13:46:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Shun Ho X-Patchwork-Id: 30276 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1261031iov; Thu, 16 Sep 2021 06:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpouwTneWB84kbi0lmzM6+Pj2OO7DsGFD9AgyCQ3IWPhpYJDHsLV/FEHeBO6PxwxjioeKw X-Received: by 2002:a17:906:7256:: with SMTP id n22mr6486102ejk.173.1631800039864; Thu, 16 Sep 2021 06:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631800039; cv=none; d=google.com; s=arc-20160816; b=bNU4tGwBJY5Acgw0UP3422zkmV+SQJRyko9NF/Ds3OfEh07JcdJ9wQkv2QyA7gSdym h+8qryDzuP9TPaQ5PL7v4Qb51AXfn8s1cB6QFuq1qVDiZYz90HlMg8GF7lpskxiWBcDC /s5EA0YjT/z26ndsfmw872Rq0IEsPyTvyGy3Bg29QxI1jpx82zGJCne+yrOmArod0xvd 4iGeaHY6uFe87WajY9ad4gBljAEfhaY0qJun8LGa/KrC/lL9bK/r+d8HyiKzthX4wUYX qTQq0aBBlYjenzXCsovdPg1bOuy2cNM9gLF0d7PniiTWci2bf6YlkMRT1yYv29vMbdGs 8HZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=Z02YR1xzAfFjgY0hZ7bq04pVJmScOJAViIrJ67A8RiI=; b=bQEECw9bYZBJVsiZzE4E3nGRFKAaajfhK9xzjLrVOAyWRJ2CmlMeCfLk/LbR3QWRmr dPeNAwCgFPtV+Nkef2hayzjKSttqO56c/1p3i+5DfXpfSz6N4wJ2WskXbyWBSfluqn3Q Xy5avjd0CyCRd0HkVVM6S9Ml8x6nI1fa0B4YxfYpRo4/qUP35SIZfihXfCENEl3NpMuy ymwiUSQnOM0pieZ4wwKfKwkOSBtk0gM6/pEhDjo03/dWG+L82gyB6xyb8UbKcewyFFyv gTBOvbtghM8FjV10Fj/P0ao0KhFg/tw+mpskT/LtUoAk/Yc3po8C73z2v6PWqkuQdvBP h9mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=L5h35JGm; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s13si3228663edh.555.2021.09.16.06.47.16; Thu, 16 Sep 2021 06:47:19 -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=@gmail.com header.s=20210112 header.b=L5h35JGm; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0570268AFF0; Thu, 16 Sep 2021 16:47:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 01E9568AA1F for ; Thu, 16 Sep 2021 16:47:06 +0300 (EEST) Received: by mail-pj1-f53.google.com with SMTP id t20so4572751pju.5 for ; Thu, 16 Sep 2021 06:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5atqlSqB7EbCCLFK4AoFsYYcZktMczIybyWHeuY6yec=; b=L5h35JGmJPr24bgaQaiLp4RCIBLPOL5Sb11C3ThC6OcEdc6Xm1lxv21bDKrHJguS3T sGQsuJVwNmmE3r8bwLEwpyCgmV/Qr10z4Pb5PsClduoNr0aQE1lpTOH26g3AFWlbwLT6 Ct35JyeaDb60bEqd/bx8eLnWcijFgLfmTjuQXvh3S1VFpHWQGry0+aTDTvQNPmp10rBQ MJlH7GMElr9ZOqY5Njy5ktC8e0uz8T5OntHQrHp7lGuMsBSmiijFRckP1QGn0FwbnM2t 289EMIjh/DHRD/pvtoWp4ynWrDzuIsCZzF2KOARLhUoHC8Vl8KMQZtJ5gWuD7aH0fbDW n7Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5atqlSqB7EbCCLFK4AoFsYYcZktMczIybyWHeuY6yec=; b=5xR0N5OFMVptyre7xFlR4GdAN4DL+IwV+anPpr2817+e77hL67Y7po2+0zSMeSS/Xn wjlLWiqy460CBgiQOdrdnOQ5QHhys2mqJu9V6ODNhcCBHfHP7/5X12Hs7DU/xW/xdwtE 1VGejxmrmMrzZE73/gxammyIG7fz6jEtLQvL0Js6j4dVVUj8QZsGdDki8XoKxVZ3ZC81 q2c8suKLAKDXFTA72nQZfzVMXzsxahMTGU6h6GNglSXWGCDY39xDM5uRuWTXogIVCn+Y Fbo7NOcMimwd23I09poE3SxznT6aTgxij63zzAowbkTj0cDgKT+ARohvnVV0adTVi0Q5 PNag== X-Gm-Message-State: AOAM531W8VkTqPyRhNS5ERwJ/j5mK5q57Lf3mRR8JAiUks6brchJWYQT kY3V4n76sUkdBHeyq6adpsl+QExrqR/GuA== X-Received: by 2002:a17:90a:6b01:: with SMTP id v1mr11011982pjj.6.1631800024824; Thu, 16 Sep 2021 06:47:04 -0700 (PDT) Received: from localhost.localdomain ([103.252.202.176]) by smtp.gmail.com with ESMTPSA id bv16sm2929244pjb.12.2021.09.16.06.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 06:47:04 -0700 (PDT) From: Ho Ming Shun To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Sep 2021 21:46:52 +0800 Message-Id: <20210916134652.22781-1-cyph1984@gmail.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/mmaldec: fix decoder freeze when flushing 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 Cc: Ho Ming Shun Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ageJM6WrI+CE When mmal_flush is called before any packets are sent, enabling/disabling the MMAL ports seems to cause the decoder to not output any packets after flushing. Bug is triggered when using 'mpv --hwdec=mmal --start=1 test.mp4'. Proposed workaround in MPV: https://github.com/mpv-player/mpv/pull/9189 Signed-off-by: Ho Ming Shun --- libavcodec/mmaldec.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c index 8c7d749742..6c3e5d99b6 100644 --- a/libavcodec/mmaldec.c +++ b/libavcodec/mmaldec.c @@ -145,19 +145,21 @@ static int ffmmal_set_ref(AVFrame *frame, FFPoolRef *pool, return 0; } -static void ffmmal_stop_decoder(AVCodecContext *avctx) +static void ffmmal_stop_decoder(AVCodecContext *avctx, int flush_ports) { MMALDecodeContext *ctx = avctx->priv_data; MMAL_COMPONENT_T *decoder = ctx->decoder; MMAL_BUFFER_HEADER_T *buffer; - mmal_port_disable(decoder->input[0]); - mmal_port_disable(decoder->output[0]); - mmal_port_disable(decoder->control); + if(flush_ports) { + mmal_port_disable(decoder->input[0]); + mmal_port_disable(decoder->output[0]); + mmal_port_disable(decoder->control); - mmal_port_flush(decoder->input[0]); - mmal_port_flush(decoder->output[0]); - mmal_port_flush(decoder->control); + mmal_port_flush(decoder->input[0]); + mmal_port_flush(decoder->output[0]); + mmal_port_flush(decoder->control); + } while ((buffer = mmal_queue_get(ctx->queue_decoded_frames))) mmal_buffer_header_release(buffer); @@ -185,7 +187,7 @@ static av_cold int ffmmal_close_decoder(AVCodecContext *avctx) MMALDecodeContext *ctx = avctx->priv_data; if (ctx->decoder) - ffmmal_stop_decoder(avctx); + ffmmal_stop_decoder(avctx, 1); mmal_component_destroy(ctx->decoder); ctx->decoder = NULL; @@ -456,14 +458,20 @@ static void ffmmal_flush(AVCodecContext *avctx) MMAL_COMPONENT_T *decoder = ctx->decoder; MMAL_STATUS_T status; - ffmmal_stop_decoder(avctx); + // MMAL will freeze if ports are enabled/disabled/flushed before + // buffers are sent + int flush_ports = ctx->packets_sent || ctx->extradata_sent; - if ((status = mmal_port_enable(decoder->control, control_port_cb))) - goto fail; - if ((status = mmal_port_enable(decoder->input[0], input_callback))) - goto fail; - if ((status = mmal_port_enable(decoder->output[0], output_callback))) - goto fail; + ffmmal_stop_decoder(avctx, flush_ports); + + if(flush_ports) { + if ((status = mmal_port_enable(decoder->control, control_port_cb))) + goto fail; + if ((status = mmal_port_enable(decoder->input[0], input_callback))) + goto fail; + if ((status = mmal_port_enable(decoder->output[0], output_callback))) + goto fail; + } return;