From patchwork Wed Apr 29 13:25:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leozhang X-Patchwork-Id: 19370 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 2468244BA87 for ; Wed, 29 Apr 2020 16:25:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 09DCF68BFD5; Wed, 29 Apr 2020 16:25:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smg-bj-02.qiyi.com (unknown [202.108.14.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DCEBB68BE19 for ; Wed, 29 Apr 2020 16:25:09 +0300 (EEST) X-AuditID: ca6c0e64-3d7ff70000008de1-25-5ea9803176d3 Received: from mail.iqiyi.com (Unknown_Domain [10.16.130.3]) by smg-bj-02.qiyi.com (Qiyi mail Gateway) with SMTP id 81.3C.36321.13089AE5; Wed, 29 Apr 2020 21:25:05 +0800 (HKT) From: leozhang To: Date: Wed, 29 Apr 2020 21:25:00 +0800 Message-ID: <1588166700-76420-1-git-send-email-leozhang@qiyi.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.39.144.213] X-ClientProxiedBy: BJ-CAS31.iqiyi.pps (10.11.50.86) To EXCH28B.iqiyi.pps (10.16.148.55) Subject: [FFmpeg-devel] [PATCH 1/3] avformat/fifo: add option to delay output 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: leozhang --- doc/muxers.texi | 3 +++ libavformat/fifo.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/doc/muxers.texi b/doc/muxers.texi index cb2bb42..a74cbc4 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -2271,6 +2271,9 @@ certain (usually permanent) errors the recovery is not attempted even when Specify whether to wait for the keyframe after recovering from queue overflow or failure. This option is set to 0 (false) by default. +@item output_delay +Time to delay output, in microseconds. Default value is 0. + @end table @subsection Examples diff --git a/libavformat/fifo.c b/libavformat/fifo.c index d11dc66..bdecf2d 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -77,6 +77,8 @@ typedef struct FifoContext { /* Value > 0 signals queue overflow */ volatile uint8_t overflow_flag; + /* Time to delay output, in microseconds */ + uint64_t output_delay; } FifoContext; typedef struct FifoThreadContext { @@ -397,6 +399,8 @@ static void *fifo_consumer_thread(void *data) memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext)); fifo_thread_ctx.avf = avf; + av_usleep(fifo->output_delay); + while (1) { uint8_t just_flushed = 0; @@ -630,6 +634,9 @@ static const AVOption options[] = { {"recover_any_error", "Attempt recovery regardless of type of the error", OFFSET(recover_any_error), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, + {"output_delay", "Time to delay output, in microseconds", OFFSET(output_delay), + AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, + {NULL}, };