From patchwork Thu Aug 22 21:50:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 14670 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 3D5D5448B8D for ; Fri, 23 Aug 2019 00:50:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2642F68ACFC; Fri, 23 Aug 2019 00:50:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E12BD68AC82 for ; Fri, 23 Aug 2019 00:50:18 +0300 (EEST) Received: by mail-ot1-f65.google.com with SMTP id j7so6900818ota.9 for ; Thu, 22 Aug 2019 14:50:18 -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=SEcUYOV3qUTvuNv9pJGxOMZCjnVb3pjmfyIz3Wq0GBc=; b=Ug821r7CW67wbT/+kny6dWLG2s0Tgh9YwKwqase734uN0ERgdO2vlTUux+5d7Zqy6o SSBUPr4tvAB5fUJ9AbGlFF4oZi2FuKxPctRSRkrgk+h+vhll3nzcKZ9EBRY/sr8M9uOt pDJBQeA6GEgW+7HJ41kz3FzgYJfAYFwvY4OBJToWrz2cOjf80tuZv0ABj3EcKtxzqzVe p/EYDfQ2LNmKxIllTLE4oTI4ZT7s365yB7lt93iHq0pTwVYbze/WdMvY8ADoR3j0OaQv 8liNq8zQabukwOF4quPrc1mPSNVUWMOpqfhtDEu0eUJ/wW0wzMSGAzWDiVYDcDCxbvew 0KJA== 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=SEcUYOV3qUTvuNv9pJGxOMZCjnVb3pjmfyIz3Wq0GBc=; b=kMzQcdY59KoDguFJbfxRQa6j1g5hCmPOttmFl8C1KP3laCI0rFzQyDbJ4kgk2Y1+33 Niz13Dwq3fsTY6mxUMRU1YQCiDAw+K4qCiQY2LoL6KGg0v0orSEUsa+83K+BSW5pCV5z 74kNhdAGetRSTRcMrBwcJqDwfphk7i6a303BjyPF8l4u/MD8P6XqXJdiFwZVgg1T4mzV dU8c5l7lMBa9VQIhfpjl9R50bDZsHvNY3gdWuKqeUpHmLToH1SaB7SsDX+Jxw9eOibxR mY3QYMGgxKTguiAmzYn8190JW0FSdNWC0pik5xFlzu7KeEpfYegtT9KeXMS+0zhL0z0j V7YA== X-Gm-Message-State: APjAAAVG448mBP2Ds5VidNUM0ahEeHHmAYZPhnRRDtFcy4RzCosOTSOw PbvS8NKjQS1bcY3XgIdUAk6OjnbkvHU= X-Google-Smtp-Source: APXvYqw9uRgWBqTz6BXyqzf43eh/fFwYFWZgzjPJOWpzeA2mkYM71Bxize9cVF8VmmQG43O2SqBxKA== X-Received: by 2002:a9d:7308:: with SMTP id e8mr1476495otk.285.1566510617259; Thu, 22 Aug 2019 14:50:17 -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 j189sm244910oih.30.2019.08.22.14.50.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Aug 2019 14:50:16 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Aug 2019 14:50:04 -0700 Message-Id: <20190822215004.12627-4-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822215004.12627-1-ffmpeg@tmm1.net> References: <20190822215004.12627-1-ffmpeg@tmm1.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/omx: Fix handling of fragmented buffers 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: martin@martin.st, Aman Gupta Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Dave Stevenson See https://trac.ffmpeg.org/ticket/7687 If an encoded frame is returned split over two or more IL buffers due to the size, then there is a race between whether get_buffer will fail, return NULL, and a truncated frame is passed on, or IL will return the remaining part of the encoded frame. If get_buffer returns NULL, part of the frame is left behind in the codec, and will be collected on the next call. That then leaves a frame stuck in the codec. Repeat enough times and the codec FIFO is full, and the pipeline stalls. A performance improvement in the Raspberry Pi firmware means that the timing has changed, and now frequently drops into the case where get_buffer returns NULL. Add code such that should a buffer be received without OMX_BUFFERFLAG_ENDOFFRAME that get_buffer is called with wait set, so we wait for the remainder of the frame. This code has been made conditional on the Pi build in case other IL implementations don't handle ENDOFFRAME correctly. Signed-off-by: Dave Stevenson Signed-off-by: Aman Gupta --- libavcodec/omx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/omx.c b/libavcodec/omx.c index 1a9a0715f8..837f5df666 100644 --- a/libavcodec/omx.c +++ b/libavcodec/omx.c @@ -735,6 +735,7 @@ static int omx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int ret = 0; OMX_BUFFERHEADERTYPE* buffer; OMX_ERRORTYPE err; + int had_partial = 0; if (frame) { uint8_t *dst[4]; @@ -846,7 +847,7 @@ static int omx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, // packet, or get EOS. buffer = get_buffer(&s->output_mutex, &s->output_cond, &s->num_done_out_buffers, s->done_out_buffers, - !frame); + !frame || had_partial); if (!buffer) break; @@ -881,6 +882,9 @@ static int omx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, s->output_buf = NULL; s->output_buf_size = 0; } +#if CONFIG_OMX_RPI + had_partial = 1; +#endif } else { // End of frame, and the caller provided a preallocated frame if ((ret = ff_alloc_packet2(avctx, pkt, s->output_buf_size + buffer->nFilledLen, 0)) < 0) {